> **/ protected static array $config = array(); /** * Wire up all POST actions for this class in one place. * * @return void */ public static function register(): void { $map = array( // action => [method, required_cap, nonce_action, nonce_field]. 'ai_content_by_parallax_restore_all_originals' => array( 'handle_restore_all_originals', 'manage_options', 'ai_content_by_parallax_restore_all_originals', '_wpnonce' ), 'ai_content_by_parallax_restore_products_originals' => array( 'handle_restore_products_originals', 'manage_options', 'ai_content_by_parallax_restore_products_originals', '_wpnonce' ), 'ai_content_by_parallax_restore_categories_originals' => array( 'handle_restore_categories_originals', 'manage_options', 'ai_content_by_parallax_restore_categories_originals', '_wpnonce' ), 'ai_content_by_parallax_retake_original_snapshots' => array( 'handle_retake_original_snapshots', 'manage_options', 'ai_content_by_parallax_retake_original_snapshots', '_wpnonce' ), ); foreach ( $map as $action => [$method, $cap, $nonce_action, $nonce_field] ) { add_action( "admin_post_{$action}", array( self::class, $method ) ); self::$config[ $action ] = compact( 'cap', 'nonce_action', 'nonce_field' ); } } /** * Handle the "Reset to Originals" button click * * @return void */ public static function handle_restore_all_originals() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html( Messages::get( 'ajax.insufficient_perms' ) ) ); } check_admin_referer( 'ai_content_by_parallax_restore_all_originals' ); if ( function_exists( 'wp_raise_memory_limit' ) ) { wp_raise_memory_limit( 'admin' ); } // Run restore. [$restored_products, $restored_terms] = OriginalSnapshot::restore_all_from_originals(); // Set transient to show notice on next page load. update_option( 'ai_content_by_parallax_show_reset_notice', 1, false ); $nonce = wp_create_nonce( 'parallax_restore_notice' ); // Redirect with result counts. $redirect = wp_get_referer(); if ( $redirect ) { $redirect = remove_query_arg( array( 'ai_content_by_parallax_restored', 'p', 't' ), $redirect ); } else { $redirect = admin_url( 'index.php' ); } wp_safe_redirect( add_query_arg( array( 'ai_content_by_parallax_restored' => 1, 'p' => $restored_products, 't' => $restored_terms, '_wpnonce' => $nonce, ), $redirect ) ); exit; } /** * Handle the "Reset to Originals (Products)" button click. * * @return void */ public static function handle_restore_products_originals() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html( Messages::get( 'ajax.insufficient_perms' ) ) ); } check_admin_referer( 'ai_content_by_parallax_restore_products_originals' ); if ( function_exists( 'wp_raise_memory_limit' ) ) { wp_raise_memory_limit( 'admin' ); } $restored_products = OriginalSnapshot::restore_products_from_originals(); update_option( 'ai_content_by_parallax_show_reset_notice', 1, false ); $redirect = wp_get_referer(); if ( $redirect ) { $redirect = remove_query_arg( array( 'ai_content_by_parallax_restored', 'p', 't' ), $redirect ); } else { $redirect = admin_url( 'index.php' ); } wp_safe_redirect( add_query_arg( array( 'ai_content_by_parallax_restored' => 1, 'p' => $restored_products, 't' => 0, '_wpnonce' => wp_create_nonce( 'parallax_restore_notice' ), ), $redirect ) ); exit; } /** * Handle the "Reset to Originals (Categories)" button click. * * @return void */ public static function handle_restore_categories_originals() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html( Messages::get( 'ajax.insufficient_perms' ) ) ); } check_admin_referer( 'ai_content_by_parallax_restore_categories_originals' ); if ( function_exists( 'wp_raise_memory_limit' ) ) { wp_raise_memory_limit( 'admin' ); } $restored_terms = OriginalSnapshot::restore_categories_from_originals(); update_option( 'ai_content_by_parallax_show_reset_notice', 1, false ); $redirect = wp_get_referer(); if ( $redirect ) { $redirect = remove_query_arg( array( 'ai_content_by_parallax_restored', 'p', 't' ), $redirect ); } else { $redirect = admin_url( 'index.php' ); } wp_safe_redirect( add_query_arg( array( 'ai_content_by_parallax_restored' => 1, 'p' => 0, 't' => $restored_terms, '_wpnonce' => wp_create_nonce( 'parallax_restore_notice' ), ), $redirect ) ); exit; } /** * Handle the "Retake Product Data Snapshot" button click * * @return void */ public static function handle_retake_original_snapshots() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html( Messages::get( 'ajax.insufficient_perms' ) ) ); } check_admin_referer( 'ai_content_by_parallax_retake_original_snapshots' ); if ( function_exists( 'wp_raise_memory_limit' ) ) { wp_raise_memory_limit( 'admin' ); } [$products, $terms] = OriginalSnapshot::retake_original_snapshots(); // Show the reset banner again so admins know snapshots are fresh. update_option( 'ai_content_by_parallax_show_reset_notice', 1, false ); $redirect = wp_get_referer(); if ( $redirect ) { $redirect = remove_query_arg( array( 'ai_content_by_parallax_retake', 'rp', 'rt' ), $redirect ); } else { $redirect = admin_url( 'index.php' ); } wp_safe_redirect( add_query_arg( array( 'ai_content_by_parallax_retake' => 1, 'rp' => $products, 'rt' => $terms, '_wpnonce' => wp_create_nonce( 'parallax_retake_notice' ), ), $redirect ) ); exit; } }