plugin = $plugin; } /** * Registers hooks. */ public function register() { add_action( 'admin_menu', array( $this, 'menu' ), 30 ); add_action( 'admin_head', array( $this, 'hide_menu_item' ) ); add_filter( 'admin_title', array( $this, 'admin_title' ), 10, 2 ); add_action( 'admin_post_' . self::ACTION, array( $this, 'handle' ) ); } /** * Adds the page (reached from the dashboard). It is registered under the * plugin's menu, as an empty parent logs a PHP "Deprecated" notice on * recent PHP versions, and its menu item is removed again in admin_head. */ public function menu() { add_submenu_page( Admin::SLUG, __( 'Set up Orbitstem SEO', 'orbitstem-seo' ), __( 'Setup', 'orbitstem-seo' ), Admin::capability(), self::SLUG, array( $this, 'render' ) ); } /** * Keeps the setup page out of the menu (after the page title was set). */ public function hide_menu_item() { remove_submenu_page( Admin::SLUG, self::SLUG ); } /** * Browser title for the setup page. * * @param string $admin_title Full title. * @param string $title Page title. * @return string */ public function admin_title( $admin_title, $title ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- view state only. if ( isset( $_GET['page'] ) && self::SLUG === $_GET['page'] && '' === trim( (string) $title ) ) { /* translators: %s: site name */ return sprintf( __( 'Set up Orbitstem SEO ‹ %s — WordPress', 'orbitstem-seo' ), get_bloginfo( 'name' ) ); } return $admin_title; } /** * Whether setup was finished or skipped. * * @return bool */ public static function done() { return (bool) get_option( self::DONE ); } /** * Saves one step and moves to the next. */ 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 ); $step = isset( $_POST['step'] ) ? absint( $_POST['step'] ) : 1; $all = $this->plugin->settings->all(); if ( isset( $_POST['skip'] ) ) { update_option( self::DONE, time(), false ); wp_safe_redirect( admin_url( 'admin.php?page=' . Admin::SLUG ) ); exit; } if ( 1 === $step ) { $kind = isset( $_POST['site_kind'] ) ? sanitize_key( wp_unslash( $_POST['site_kind'] ) ) : 'blog'; $all['knowledge_type'] = 'personal' === $kind ? 'person' : 'organization'; $all['local'] = array_merge( (array) $all['local'], array( 'enabled' => 'local' === $kind ) ); $all['noindex_empty_terms'] = ! empty( $_POST['noindex_empty_terms'] ); // Shown as a ticked-or-not box on this step, never changed silently. update_option( Settings::OPTION, $all ); } elseif ( 2 === $step ) { // Settings::sanitize() cleans every value on update_option(). // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $all['knowledge_name'] = isset( $_POST['knowledge_name'] ) ? wp_unslash( $_POST['knowledge_name'] ) : ''; $all['knowledge_logo'] = isset( $_POST['knowledge_logo'] ) ? wp_unslash( $_POST['knowledge_logo'] ) : ''; $all['knowledge_same_as'] = isset( $_POST['knowledge_same_as'] ) ? wp_unslash( $_POST['knowledge_same_as'] ) : ''; $all['twitter_site'] = isset( $_POST['twitter_site'] ) ? wp_unslash( $_POST['twitter_site'] ) : ''; // phpcs:enable update_option( Settings::OPTION, $all ); } elseif ( 4 === $step ) { $this->plugin->scanner->start(); update_option( self::DONE, time(), false ); RedirectsPage::notice( 'success', __( 'Setup finished. The first scan is running in the background; the dashboard fills in as it goes.', 'orbitstem-seo' ) ); wp_safe_redirect( admin_url( 'admin.php?page=' . Admin::SLUG ) ); exit; } wp_safe_redirect( admin_url( 'admin.php?page=' . self::SLUG . '&step=' . min( 4, $step + 1 ) ) ); exit; } /** * Renders the current step. */ 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:ignore WordPress.Security.NonceVerification.Recommended -- view state only. $step = isset( $_GET['step'] ) ? min( 4, max( 1, absint( $_GET['step'] ) ) ) : 1; $s = $this->plugin->settings; $steps = array( 1 => __( 'Your site', 'orbitstem-seo' ), 2 => __( 'Name and logo', 'orbitstem-seo' ), 3 => __( 'Switching', 'orbitstem-seo' ), 4 => __( 'First scan', 'orbitstem-seo' ), ); Ui::open( Admin::SLUG, __( 'Set up Orbitstem SEO', 'orbitstem-seo' ), __( 'Four short steps. Everything can be changed later in Settings.', 'orbitstem-seo' ) ); ?>
    $label ) : ?>

array( __( 'Blog or magazine', 'orbitstem-seo' ), __( 'Articles and news.', 'orbitstem-seo' ) ), 'shop' => array( __( 'Online shop', 'orbitstem-seo' ), __( 'Products; WooCommerce products get full Product schema.', 'orbitstem-seo' ) ), 'local' => array( __( 'Local business', 'orbitstem-seo' ), __( 'A place customers visit; you can add your address and hours next.', 'orbitstem-seo' ) ), 'company' => array( __( 'Company or organization', 'orbitstem-seo' ), __( 'Services, team, contact.', 'orbitstem-seo' ) ), 'personal' => array( __( 'Personal site or portfolio', 'orbitstem-seo' ), __( 'About one person.', 'orbitstem-seo' ) ), ); $current = 'person' === $s->get( 'knowledge_type' ) ? 'personal' : ( ! empty( $s->get( 'local' )['enabled'] ) ? 'local' : 'blog' ); ?>
$kind ) : ?>





plugin->importer->sources(), function ( $source ) { return $source->has_data(); } ); ?>