post_type ) { return; } $content = (string) $page->post_content; $shortcode_pattern = '~' . get_shortcode_regex( array( 'acceguru_statement' ) ) . '~s'; $shortcode_matches = array(); preg_match_all( $shortcode_pattern, $content, $shortcode_matches, PREG_SET_ORDER ); $has_statement_shortcode = false; foreach ( $shortcode_matches as $shortcode_match ) { // [[acceguru_statement]] is escaped text, not a live shortcode. if ( '[' !== $shortcode_match[1] || ']' !== $shortcode_match[6] ) { $has_statement_shortcode = true; break; } } if ( ! $has_statement_shortcode ) { return; } if ( $delete_data ) { wp_trash_post( $page_id ); return; } // The plugin itself is not loaded during uninstall, so load only the two // classes needed to render the final statement before its data disappears. if ( ! class_exists( 'Acceguru_Scanner', false ) ) { require_once __DIR__ . '/includes/class-acceguru-scanner.php'; } if ( ! class_exists( 'Acceguru_Admin', false ) ) { require_once __DIR__ . '/includes/class-acceguru-admin.php'; } $statement_html = Acceguru_Admin::build_statement_html(); if ( '' === trim( $statement_html ) ) { return; } $static_content = preg_replace_callback( $shortcode_pattern, static function ( array $matches ) use ( $statement_html ): string { // Preserve an intentionally escaped [[acceguru_statement]]. if ( '[' === $matches[1] && ']' === $matches[6] ) { return $matches[0]; } return $statement_html; }, $content ); if ( ! is_string( $static_content ) || $static_content === $content ) { return; } wp_update_post( array( 'ID' => $page_id, 'post_content' => wp_slash( $static_content ), ), true ); } /** * Wipe all AcceGuru data from the current site. */ function acceguru_uninstall_purge_site(): void { global $wpdb; $delete_data = 1 === absint( get_option( 'acceguru_delete_on_uninstall', 0 ) ); // Handle the statement while its page ID and rendering data still exist. acceguru_uninstall_handle_statement_page( $delete_data ); // Honor opt-in. If the option is missing or 0, leave plugin data intact. if ( ! $delete_data ) { return; } // Bulk uninstall purges - cache layer is moot at uninstall time. // Options (covers settings + the AI API key). $wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- Bulk uninstall cleanup; core has no delete-options-by-prefix API and caching is moot at uninstall time. $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s", $wpdb->esc_like( 'acceguru_' ) . '%' ) ); // Post meta created by AcceGuru and compatible add-ons. $wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- Bulk uninstall cleanup; core has no delete-post-meta-by-prefix API and caching is moot at uninstall time. $wpdb->prepare( "DELETE FROM {$wpdb->postmeta} WHERE meta_key LIKE %s", $wpdb->esc_like( '_acceguru_' ) . '%' ) ); // Transients. $wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- Bulk uninstall cleanup of the plugin's transients; core has no delete-by-prefix API and caching is moot at uninstall time. $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s", $wpdb->esc_like( '_transient_acceguru_' ) . '%', $wpdb->esc_like( '_transient_timeout_acceguru_' ) . '%' ) ); // Scheduled cron events registered by the plugin. $crons = _get_cron_array(); if ( is_array( $crons ) ) { foreach ( $crons as $timestamp => $hooks ) { if ( ! is_array( $hooks ) ) { continue; } foreach ( array_keys( $hooks ) as $hook ) { if ( is_string( $hook ) && 0 === strpos( $hook, 'acceguru_' ) ) { wp_clear_scheduled_hook( $hook ); } } } } } if ( is_multisite() ) { // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound $site_ids = get_sites( array( 'fields' => 'ids', 'number' => 0 ) ); foreach ( $site_ids as $site_id ) { switch_to_blog( (int) $site_id ); acceguru_uninstall_purge_site(); restore_current_blog(); } // phpcs:enable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound } else { acceguru_uninstall_purge_site(); }