delete( $wpdb->postmeta, array( 'meta_key' => 'synthseo_post_id' ) ); $wpdb->delete( $wpdb->postmeta, array( 'meta_key' => 'synthseo_metadata' ) ); $wpdb->delete( $wpdb->postmeta, array( 'meta_key' => 'synthseo_content_metrics' ) ); $wpdb->delete( $wpdb->postmeta, array( 'meta_key' => 'synthseo_seo_metrics' ) ); $wpdb->delete( $wpdb->postmeta, array( 'meta_key' => 'synthseo_target_keywords' ) ); $wpdb->delete( $wpdb->postmeta, array( 'meta_key' => 'synthseo_keyword_strategy' ) ); // Remove custom tables if they exist $table_logs = $wpdb->prefix . 'synthseo_logs'; $table_rate_limits = $wpdb->prefix . 'synthseo_rate_limits'; // Check if tables exist before dropping // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.SchemaChange if ($wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table_logs)) == $table_logs) { $wpdb->query("DROP TABLE IF EXISTS $table_logs"); } if ($wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table_rate_limits)) == $table_rate_limits) { $wpdb->query("DROP TABLE IF EXISTS $table_rate_limits"); } // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.SchemaChange // Clean up user meta if any $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => 'synthseo_user_preferences' ) ); // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.SlowDBQuery.slow_db_query_meta_key // Clear any scheduled cron jobs wp_clear_scheduled_hook('synthseo_cleanup_logs'); wp_clear_scheduled_hook('synthseo_cleanup_rate_limits'); // Remove any capabilities added by the plugin $role = get_role('administrator'); if ($role) { $role->remove_cap('manage_synthseo'); $role->remove_cap('publish_synthseo_content'); } // Flush rewrite rules to clean up any custom endpoints flush_rewrite_rules(); // Clear object cache if available if (function_exists('wp_cache_flush')) { wp_cache_flush(); } } // Log the uninstall for debugging (only if debug mode is on) if (defined('WP_DEBUG') && WP_DEBUG && defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) { // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- gated behind WP_DEBUG_LOG error_log('SynthSEO Publisher: Plugin uninstalled. Data removed: ' . ($keep_data ? 'No' : 'Yes')); }