From 29f5968554cd8dfc667e954e92a66689e2ff0a41 Mon Sep 17 00:00:00 2001 From: pattonwebz Date: Fri, 23 Feb 2024 16:39:43 +0000 Subject: [PATCH 01/73] Add a new class to hold the purge methods that are being deprecated and shifted --- admin/class-purge-post-data.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 admin/class-purge-post-data.php diff --git a/admin/class-purge-post-data.php b/admin/class-purge-post-data.php new file mode 100755 index 00000000..cc40f492 --- /dev/null +++ b/admin/class-purge-post-data.php @@ -0,0 +1,15 @@ + Date: Fri, 23 Feb 2024 16:55:29 +0000 Subject: [PATCH 02/73] Move the purche functions to the new Purge_Posts_Data class Making them static and removing the edac prefix on the name in the process --- admin/class-purge-post-data.php | 67 +++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/admin/class-purge-post-data.php b/admin/class-purge-post-data.php index cc40f492..b9a2bb3d 100755 --- a/admin/class-purge-post-data.php +++ b/admin/class-purge-post-data.php @@ -12,4 +12,71 @@ */ class Purge_Post_Data { + /** + * Purge deleted posts + * + * @param init $post_id ID of the post. + * + * @return void + */ + public static function delete_post( $post_id ) { + global $wpdb; + $site_id = get_current_blog_id(); + $table_name = $wpdb->prefix . 'accessibility_checker'; + + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Safe variable used for table name, caching not required for one time operation. + $wpdb->query( $wpdb->prepare( 'DELETE FROM %i WHERE postid = %d and siteid = %d', $table_name, $post_id, $site_id ) ); + + self::delete_post_meta( $post_id ); + } + + /** + * Delete post meta + * + * @param int $post_id ID of the post. + * + * @return void + */ + public static function delete_post_meta( $post_id ) { + + if ( ! $post_id ) { + return; + } + + $post_meta = get_post_meta( $post_id ); + if ( $post_meta ) { + foreach ( $post_meta as $key => $value ) { + if ( substr( $key, 0, 5 ) === '_edac' || substr( $key, 0, 6 ) === '_edacp' ) { + delete_post_meta( $post_id, $key ); + } + } + } + } + + /** + * Purge issues by post type + * + * @param string $post_type Post Type. + * @return void + */ + public static function delete_cpt_posts( $post_type ) { + + if ( ! $post_type ) { + return; + } + + global $wpdb; + $site_id = get_current_blog_id(); + + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Safe variable used for table name, caching not required for one time operation. + return $wpdb->query( + $wpdb->prepare( + "DELETE T1,T2 from $wpdb->postmeta as T1 JOIN %i as T2 ON t1.post_id = T2.postid WHERE t1.meta_key like %s and T2.siteid=%d and T2.type=%s", + edac_get_valid_table_name( $wpdb->prefix . 'accessibility_checker' ), + '_edac%', + $site_id, + $post_type + ) + ); + } } From c0ced843dc246f581a8d9036a21a2b51bc86341b Mon Sep 17 00:00:00 2001 From: pattonwebz Date: Fri, 23 Feb 2024 16:57:00 +0000 Subject: [PATCH 03/73] Add type hints to the params in the new methods --- admin/class-purge-post-data.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/admin/class-purge-post-data.php b/admin/class-purge-post-data.php index b9a2bb3d..dee403ce 100755 --- a/admin/class-purge-post-data.php +++ b/admin/class-purge-post-data.php @@ -15,11 +15,11 @@ class Purge_Post_Data { /** * Purge deleted posts * - * @param init $post_id ID of the post. + * @param int $post_id ID of the post. * * @return void */ - public static function delete_post( $post_id ) { + public static function delete_post( int $post_id ) { global $wpdb; $site_id = get_current_blog_id(); $table_name = $wpdb->prefix . 'accessibility_checker'; @@ -37,7 +37,7 @@ public static function delete_post( $post_id ) { * * @return void */ - public static function delete_post_meta( $post_id ) { + public static function delete_post_meta( int $post_id ) { if ( ! $post_id ) { return; @@ -57,9 +57,10 @@ public static function delete_post_meta( $post_id ) { * Purge issues by post type * * @param string $post_type Post Type. + * * @return void */ - public static function delete_cpt_posts( $post_type ) { + public static function delete_cpt_posts( string $post_type ) { if ( ! $post_type ) { return; From 166a6f92a29f10db82328a9783abd5ffdafe2f8b Mon Sep 17 00:00:00 2001 From: pattonwebz Date: Fri, 23 Feb 2024 16:58:06 +0000 Subject: [PATCH 04/73] Fix the return types on delete_cpt_posts as it can return much more than `void` --- admin/class-purge-post-data.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/class-purge-post-data.php b/admin/class-purge-post-data.php index dee403ce..ead8a2f3 100755 --- a/admin/class-purge-post-data.php +++ b/admin/class-purge-post-data.php @@ -58,7 +58,7 @@ public static function delete_post_meta( int $post_id ) { * * @param string $post_type Post Type. * - * @return void + * @return bool|int|\mysqli_result|void */ public static function delete_cpt_posts( string $post_type ) { From cc43278b80f789d744e64c54a7cb74081b55ea10 Mon Sep 17 00:00:00 2001 From: pattonwebz Date: Fri, 23 Feb 2024 17:03:17 +0000 Subject: [PATCH 05/73] Swap to the migrated class method for deleting post data when called through wp_trash_post --- accessibility-checker.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) mode change 100644 => 100755 accessibility-checker.php diff --git a/accessibility-checker.php b/accessibility-checker.php old mode 100644 new mode 100755 index a17fca00..c3849c0c --- a/accessibility-checker.php +++ b/accessibility-checker.php @@ -20,6 +20,7 @@ */ use EDAC\Inc\Plugin; +use EDAC\Admin\Purge_Post_Data; // If this file is called directly, abort. if ( ! defined( 'WPINC' ) ) { @@ -137,7 +138,7 @@ add_action( 'admin_init', 'edac_register_setting' ); add_action( 'admin_head', 'edac_post_on_load' ); add_filter( 'save_post', 'edac_save_post', 10, 3 ); -add_action( 'wp_trash_post', 'edac_delete_post' ); +add_action( 'wp_trash_post', array( Purge_Post_Data::class, 'delete_post' ) ); add_action( 'pre_get_posts', 'edac_show_draft_posts' ); if ( is_plugin_active( 'oxygen/functions.php' ) ) { add_action( 'added_post_meta', 'edac_oxygen_builder_save_post', 10, 4 ); From caaa78acbe77b6e76c4720827a18ae19e0200b52 Mon Sep 17 00:00:00 2001 From: pattonwebz Date: Fri, 23 Feb 2024 17:05:36 +0000 Subject: [PATCH 06/73] Swap to the migrated class method delete_cpt_posts when purging data from deleted cpts --- includes/options-page.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/includes/options-page.php b/includes/options-page.php index fac85815..0c96571f 100644 --- a/includes/options-page.php +++ b/includes/options-page.php @@ -5,6 +5,8 @@ * @package Accessibility_Checker */ +use EDAC\Admin\Purge_Post_Data; + /** * Check if user can ignore or can manage options * @@ -338,7 +340,7 @@ function edac_post_types_cb() { $disabled = in_array( $post_type, $post_types, true ) ? '' : 'disabled'; ?>