plugin = $plugin; } /** * Registers hooks. */ public function register() { add_action( 'admin_menu', array( $this, 'menu' ), 17 ); add_action( 'admin_post_' . self::ACTION, array( $this, 'handle' ) ); } /** * Adds the submenu page. */ public function menu() { add_submenu_page( Admin::SLUG, __( 'Monitor', 'orbitstem-seo' ), __( 'Monitor', 'orbitstem-seo' ), Admin::capability(), self::SLUG, array( $this, 'render' ) ); } /** * Starts a snapshot or processes it now. */ public function handle() { if ( ! current_user_can( Admin::capability() ) ) { wp_die( esc_html__( 'You do not have permission to do this.', 'orbitstem-seo' ), 403 ); } check_admin_referer( self::ACTION ); $task = isset( $_POST['task'] ) ? sanitize_key( wp_unslash( $_POST['task'] ) ) : ''; if ( 'snapshot' === $task ) { $ok = $this->plugin->snapshots->start( 'manual' ); RedirectsPage::notice( $ok ? 'success' : 'error', $ok ? __( 'Snapshot started. It runs in the background; reload or use "Process now".', 'orbitstem-seo' ) : __( 'A snapshot is already running.', 'orbitstem-seo' ) ); } elseif ( 'process' === $task ) { $this->plugin->jobs->tick( 20 ); RedirectsPage::notice( 'success', __( 'Processed for up to 20 seconds.', 'orbitstem-seo' ) ); } wp_safe_redirect( admin_url( 'admin.php?page=' . self::SLUG ) ); exit; } /** * Renders the page. */ public function render() { if ( ! current_user_can( Admin::capability() ) ) { wp_die( esc_html__( 'You do not have permission to view this page.', 'orbitstem-seo' ) ); } // phpcs:disable WordPress.Security.NonceVerification.Recommended -- view state only. $a = isset( $_GET['a'] ) ? absint( $_GET['a'] ) : 0; $b = isset( $_GET['b'] ) ? absint( $_GET['b'] ) : 0; $only = ! empty( $_GET['unexplained'] ); // phpcs:enable $state = $this->plugin->jobs->status( Snapshotter::JOB ); $running = $state && 'running' === $state['status']; $list = $this->plugin->snapshots->all( 50 ); $alert = $this->plugin->monitor->alert(); $freq = (string) $this->plugin->settings->get( 'monitor_frequency' ); Ui::open( self::SLUG, __( 'Regression Monitor', 'orbitstem-seo' ), __( 'Snapshots of what your pages tell search engines, compared over time.', 'orbitstem-seo' ) ); ?>

Diagnostics).', 'orbitstem-seo' ) : sprintf( __( 'Automatic snapshots: %s.', 'orbitstem-seo' ), 'daily' === $freq ? __( 'daily', 'orbitstem-seo' ) : __( 'weekly', 'orbitstem-seo' ) ) ); ?>

button( 'snapshot', __( 'Take snapshot now', 'orbitstem-seo' ), $running, true ); ?> button( 'process', __( 'Process now', 'orbitstem-seo' ), false, false ); } ?>

render_compare( $a, $b, $only, $list ); } ?>

(' . esc_html( $s['status'] ) . ')' : ''; ?> self::SLUG, 'a' => (int) $sum['compared_with'], 'b' => (int) $s['id'], ), admin_url( 'admin.php' ) ) ) . '">' . esc_html__( 'Compare', 'orbitstem-seo' ) . ''; } else { echo '—'; } ?>
plugin->diff->compare( min( $a, $b ), max( $a, $b ) ); $changes = $only ? array_filter( $result['changes'], function ( $c ) { return ! $c['explained']; } ) : $result['changes']; $rank = array( 'error' => 0, 'warning' => 1, 'notice' => 2, ); usort( $changes, function ( $x, $y ) use ( $rank ) { return $rank[ $x['severity'] ] - $rank[ $y['severity'] ]; } ); $date = function ( $id ) use ( $snapshots ) { foreach ( $snapshots as $s ) { if ( (int) $s['id'] === (int) $id ) { return get_date_from_gmt( $s['created_at'], get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ); } } return '#' . (int) $id; }; ?>


' . esc_html( get_the_title( $c['object_id'] ) ) . '
'; } echo '' !== $c['url'] ? '' . esc_html( $c['url'] ) . '' : esc_html__( 'Whole site', 'orbitstem-seo' ); ?>