verify_request() ) { return; } $plugin = isset( $_POST['plugin'] ) ? sanitize_key( wp_unslash( $_POST['plugin'] ) ) : ''; $choice = isset( $_POST['choice'] ) ? sanitize_key( wp_unslash( $_POST['choice'] ) ) : ''; $value = isset( $_POST['value'] ) ? sanitize_key( wp_unslash( $_POST['value'] ) ) : ''; if ( ! class_exists( 'AIEO_Recognised_Plugins' ) || ! AIEO_Recognised_Plugins::set_choice( $plugin, $choice, $value ) ) { wp_send_json_error( array( 'message' => __( 'Rooster One does not know that choice.', 'ai-eshop-optimizer' ) ) ); } do_action( 'aieo_purge_page_cache' ); wp_send_json_success( array( 'plugin' => $plugin, 'choice' => $choice, 'value' => AIEO_Recognised_Plugins::choice( $plugin, $choice ), 'message' => __( 'Saved.', 'ai-eshop-optimizer' ), ) ); } public function ajax_save_plugin() { if ( ! $this->verify_request() ) { return; } $plugin = isset( $_POST['plugin'] ) ? sanitize_key( wp_unslash( $_POST['plugin'] ) ) : ''; $on = isset( $_POST['on'] ) && '1' === sanitize_text_field( wp_unslash( $_POST['on'] ) ); if ( ! class_exists( 'AIEO_Recognised_Plugins' ) || ! array_key_exists( $plugin, AIEO_Recognised_Plugins::all() ) ) { wp_send_json_error( array( 'message' => __( 'Rooster One does not know that plugin.', 'ai-eshop-optimizer' ) ) ); } AIEO_Recognised_Plugins::set( $plugin, $on ); do_action( 'aieo_purge_page_cache' ); wp_send_json_success( array( 'plugin' => $plugin, 'on' => AIEO_Recognised_Plugins::on( $plugin ), 'message' => __( 'Saved.', 'ai-eshop-optimizer' ), ) ); } public function ajax_save() { if ( ! $this->verify_request() ) { return; } $surface = isset( $_POST['surface'] ) ? sanitize_key( wp_unslash( $_POST['surface'] ) ) : ''; $mode = isset( $_POST['mode'] ) ? sanitize_key( wp_unslash( $_POST['mode'] ) ) : ''; if ( '' === $surface ) { wp_send_json_error( array( 'message' => __( 'No surface given.', 'ai-eshop-optimizer' ) ) ); } if ( ! AIEO_Theme_Adapters::set_mode( $surface, $mode ) ) { wp_send_json_error( array( 'message' => __( 'That mode is not available for this surface.', 'ai-eshop-optimizer' ) ) ); } do_action( 'aieo_purge_page_cache' ); wp_send_json_success( array( 'surface' => $surface, 'mode' => AIEO_Theme_Adapters::mode( $surface ), 'message' => __( 'Saved.', 'ai-eshop-optimizer' ), ) ); } public function ajax_detect() { if ( ! $this->verify_request() ) { return; } $surface = isset( $_POST['surface'] ) ? sanitize_key( wp_unslash( $_POST['surface'] ) ) : ''; if ( 'swatches' !== $surface || ! class_exists( 'AIEO_Swatch_Type_Detector' ) ) { wp_send_json_error( array( 'message' => __( 'Nothing to detect for that surface.', 'ai-eshop-optimizer' ) ) ); } $rows = AIEO_Swatch_Type_Detector::detect_and_save(); wp_send_json_success( array( 'rows' => $rows, 'message' => sprintf( __( 'Inspected %d attributes and saved the result.', 'ai-eshop-optimizer' ), count( $rows ) ), ) ); } private function verify_request() { if ( ! current_user_can( 'manage_woocommerce' ) ) { wp_send_json_error( array( 'message' => __( 'Not allowed.', 'ai-eshop-optimizer' ) ) ); return false; } check_ajax_referer( 'aieo_dmm_nonce', 'nonce' ); return true; } public function render_subtab() { require AIEO_DIR . 'assets/pages/dmm/theme-compat.php'; } }