Skip to content

Commit ce24deb

Browse files
authored
Merge pull request #18 from NeilWJames/master
Review and clean debugging statements
2 parents 7557cde + fdd7fab commit ce24deb

1 file changed

Lines changed: 2 additions & 23 deletions

File tree

wpdr-revisionary/includes/class-wpdr-revisionary.php

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function admin_init(): void {
161161
add_action( 'template_redirect', array( &$this, 'revision_redirect' ), 15 );
162162

163163
// Make sure reject.
164-
add_filter( 'wp_redirect', array( &$this, 'redirect_from_revision' ), 10, 2 );
164+
add_filter( 'wp_redirect', array( &$this, 'redirect_from_revision' ), 99, 2 );
165165

166166
// Change the preview link format.
167167
add_filter( 'revisionary_preview_link_type', array( &$this, 'preview_link_type' ), 10, 2 );
@@ -341,7 +341,7 @@ private function is_plugin_active( string $plugin ): bool {
341341
private function log( string $message, $data = null ): void {
342342
if ( $this->debug ) {
343343
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log,WordPress.PHP.DevelopmentFunctions.error_log_print_r
344-
write_log( 'WPDR_RVY: ' . $message . ' ' . print_r( $data, true ) );
344+
error_log( 'WPDR_RVY: ' . $message . ' ' . print_r( $data, true ) );
345345
}
346346
}
347347

@@ -593,7 +593,6 @@ public function revision_redirect(): void {
593593
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
594594
$p = ( isset( $_GET['p'] ) ? (int) $_GET['p'] : (int) $_GET['post'] );
595595
$post = get_post( $p );
596-
$this->log( 'Post: ', $post );
597596
if ( 'revision' === $post->post_type && 0 !== $post->post_parent ) {
598597
$parent = get_post( $post->post_parent );
599598
if ( 'document' === $parent->post_type ) {
@@ -609,7 +608,6 @@ public function revision_redirect(): void {
609608

610609
// If the new url is different from the input url, redirect.
611610
if ( $input_url !== $current_url ) {
612-
$this->log( 'Redirecting to ', $current_url );
613611
wp_safe_redirect( $current_url );
614612
exit;
615613
}
@@ -624,7 +622,6 @@ public function revision_redirect(): void {
624622
* @param WP_Post $post The post object.
625623
*/
626624
public function possibly_delete_revision( $allow_delete, $post ): bool {
627-
$this->log( 'del_revn', $post );
628625
// is this a PP_Revision post.
629626
if ( (bool) $post->comment_count && array_key_exists( $post->post_mime_type, $this->rvy_revision_statuses() ) ) {
630627
return $allow_delete;
@@ -647,20 +644,17 @@ public function possibly_delete_revision( $allow_delete, $post ): bool {
647644
);
648645
foreach ( array_reverse( $traces ) as $trace ) {
649646
if ( in_array( $trace['function'], $allow, true ) ) {
650-
$this->log( 'delete:', $trace['function'] );
651647
return true;
652648
}
653649
if ( in_array( $trace['function'], $block, true ) ) {
654650
// Dont want standard plugin processing.
655-
$this->log( 'keep:' . $trace['function'] );
656651
return false;
657652
}
658653
}
659654
if ( 9 === count( $traces ) && 'wp_delete_post' === $traces[8]['function'] ) {
660655
// WP Core process to delete post and its revisions. OK to delete.
661656
return true;
662657
}
663-
$this->log( 'trace', $traces );
664658
return $allow_delete;
665659
}
666660

@@ -679,8 +673,6 @@ public function wpdr_revision_published( $published, $revision ): void {
679673
// Only for documents.
680674
return;
681675
}
682-
$this->log( 'published', $published );
683-
$this->log( 'revision', $revision );
684676
$parent = null;
685677
// Ensure that the published post is a document and the revision is no longer a document.
686678
if ( 'revision' === $revision->post_type ) {
@@ -719,7 +711,6 @@ public function wpdr_revision_published( $published, $revision ): void {
719711
// There is a Document Revision created after the PP Revision and we can bump up its ID.
720712
global $wpdb;
721713
if ( ! is_null( self::$revn ) ) {
722-
$this->log( 'update ' . $revision->ID . ' to ' . self::$revn );
723714
// if records have been deleted, update the key of the revision to the highest by SQL.
724715
$guid = str_replace( 'p=' . $revision->ID, 'p=' . self::$revn, $revision->guid );
725716
// phpcs:ignore WordPress.DB.DirectDatabaseQuery
@@ -767,11 +758,6 @@ public function revision_data( $update, $revision, $published ) {
767758
if ( 'document' !== $published->post_type ) {
768759
return $update;
769760
}
770-
$this->log( 'data: ' . $published->post_type );
771-
$this->log( 'update: ' . $update['ID'] . ' Pub: ' . $published->ID );
772-
$this->log( 'Uex: ' . $update['post_excerpt'] );
773-
$this->log( 'Rex: ' . $revision->post_excerpt );
774-
$this->log( 'Pex: ' . $published->post_excerpt );
775761

776762
// Add fields to list.
777763
$update['post_name'] = $published->ID . '-revision-v1';
@@ -795,18 +781,15 @@ public function revision_data( $update, $revision, $published ) {
795781
* @return mixed[]
796782
*/
797783
public function revision_fields( $update_fields, $revision, $published, $actual_revision_status ) { //phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
798-
$this->log( 'fields: ' . $published->post_type );
799784
if ( 'document' !== $published->post_type ) {
800785
return $update_fields;
801786
}
802787

803788
// The attachment on the revision document needs to have the original document as parent.
804789
global $wpdr;
805790
$attach = $wpdr->extract_document_id( $revision->post_content );
806-
$this->log( 'attach', $attach );
807791
if ( get_post_field( 'post_parent', $attach ) !== $published->ID ) {
808792
// Update attachment post in the database.
809-
$this->log( 'update parent to ' . $published->ID );
810793
wp_update_post(
811794
array(
812795
'ID' => $attach,
@@ -820,7 +803,6 @@ public function revision_fields( $update_fields, $revision, $published, $actual_
820803
// Check if there is any residual revision or attachments with revision as parent and delete them.
821804
// Need to do it here as the revision children would otherwise be deleted by SQL (and will ignore any redundant attachments).
822805
global $wpdr;
823-
$this->log( 'Revision:' . $revision->ID );
824806
$children = get_children(
825807
array(
826808
'post_parent' => $revision->ID,
@@ -832,7 +814,6 @@ public function revision_fields( $update_fields, $revision, $published, $actual_
832814
self::$revn = $revision->ID;
833815
foreach ( $children as $child ) {
834816
$id = $child->ID;
835-
$this->log( 'Post:' . $id . ' Type:' . $child->post_type );
836817
// Find the maximum post being deleted.
837818
if ( $id > self::$revn ) {
838819
self::$revn = $id;
@@ -874,7 +855,6 @@ public function revision_fields( $update_fields, $revision, $published, $actual_
874855

875856
// If there is a value, then it is useful to bump up the revision ID as it will improve revision ordering.
876857
if ( $rev_exist ) {
877-
$this->log( 'WPDR rev exist: ', self::$revn );
878858
// Suppress the Published Document SQL later revision Deletes; and also switch off the filter.
879859
add_filter( 'query', array( &$this, 'delete_query' ) );
880860
add_action( 'revision_applied', array( &$this, 'remove_delete_query' ), 99, 2 );
@@ -901,7 +881,6 @@ public function delete_query( $query ): string {
901881
// SQL to change.
902882
if ( 0 === strpos( $query, "DELETE FROM $wpdb->posts " ) ) {
903883
$query .= ' AND 1=0';
904-
$this->log( 'query:', $query );
905884
// now stop looking and can switch off belt and braces.
906885
remove_filter( 'query', array( &$this, 'delete_query' ) );
907886
remove_action( 'revision_applied', array( &$this, 'remove_delete_query' ), 99, 2 );

0 commit comments

Comments
 (0)