__( 'You do not have permission to do this.', '360-orbit-speed-optimizer' ) ), 403 ); } } /** * Check starten: misst die gewaehlte Seite per Selbstaufruf und liefert das Ergebnis. */ public static function run() { self::check_request(); $home = home_url( '/' ); $target = isset( $_POST['target'] ) && is_string( $_POST['target'] ) ? esc_url_raw( wp_unslash( $_POST['target'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing $target = '' === $target ? $home : $target; $slot = trailingslashit( $target ) === $home ? 'home' : 'page'; $result = Wp360_Speed_Optimizer_Doctor_Runner::run( $target ); if ( empty( $result['ok'] ) ) { $error = $result['error']; $text = Wp360_Speed_Optimizer_Doctor_Texts::error_text( $error['kind'], $error['status'] ); wp_send_json_error( array( 'kind' => $error['kind'], 'message' => $text['message'], 'hint' => $text['hint'], ) ); } Wp360_Speed_Optimizer_Doctor_Runner::save_result( $slot, $result['measurement'] ); // "Erledigt" faellt weg, wenn die Empfehlung in der neuen Messung wieder auftaucht. $analysis = Wp360_Speed_Optimizer_Doctor_Page::analyze( $slot, $result['measurement'] ); update_option( Wp360_Speed_Optimizer_Doctor_Page::DISMISS_OPTION, Wp360_Speed_Optimizer_Doctor_Dismissals::reconcile( get_option( Wp360_Speed_Optimizer_Doctor_Page::DISMISS_OPTION, array() ), $analysis['findings'], time() ), false ); wp_send_json_success( array( 'html' => Wp360_Speed_Optimizer_Doctor_Page::results_html() ) ); } /** * Erledigt / Spaeter / wieder anzeigen, je Regel und Quelle. */ public static function dismiss() { self::check_request(); $rule = isset( $_POST['rule'] ) && is_string( $_POST['rule'] ) ? sanitize_key( wp_unslash( $_POST['rule'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing $source = isset( $_POST['source'] ) && is_string( $_POST['source'] ) ? sanitize_text_field( wp_unslash( $_POST['source'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing $state = isset( $_POST['state'] ) && is_string( $_POST['state'] ) ? sanitize_key( wp_unslash( $_POST['state'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing if ( ! in_array( $state, array( 'done', 'later', 'restore' ), true ) || '' === $rule ) { wp_send_json_error( array( 'message' => __( 'Invalid data.', '360-orbit-speed-optimizer' ) ), 400 ); } update_option( Wp360_Speed_Optimizer_Doctor_Page::DISMISS_OPTION, Wp360_Speed_Optimizer_Doctor_Dismissals::set( get_option( Wp360_Speed_Optimizer_Doctor_Page::DISMISS_OPTION, array() ), $rule . '|' . $source, $state, time() ), false ); wp_send_json_success( array( 'html' => Wp360_Speed_Optimizer_Doctor_Page::results_html(), 'backend' => Wp360_Speed_Optimizer_Doctor_Page::backend_html(), ) ); } /** * Jetzt beheben. Nur bekannte Massnahmen; geaendert wird nach Klick. */ public static function fix() { self::check_request(); $fix = isset( $_POST['fix'] ) && is_string( $_POST['fix'] ) ? sanitize_key( wp_unslash( $_POST['fix'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing if ( ! Wp360_Speed_Optimizer_Doctor_Fixes::is_known( $fix ) ) { wp_send_json_error( array( 'message' => __( 'Unknown action.', '360-orbit-speed-optimizer' ) ), 400 ); } $result =Wp360_Speed_Optimizer_Doctor_Fixes::apply( $fix ); if ( empty( $result['ok'] ) ) { wp_send_json_error( array( 'message' => $result['message'] ) ); } wp_send_json_success( array( 'message' => $result['message'] ) ); } /** * Backend auswerten: fasst die mitgeschnittenen Aufrufe zusammen. */ public static function evaluate() { self::check_request(); wp_send_json_success( array( 'html' => Wp360_Speed_Optimizer_Doctor_Page::backend_html(), 'empty' => null === Wp360_Speed_Optimizer_Doctor_Browser_Capture::summarize(), 'notice' => __( 'No page views recorded yet. Switch measuring on, click through some admin pages, then evaluate again.', '360-orbit-speed-optimizer' ), ) ); } }