database
5 months ago
importers
2 weeks ago
metabox
6 days ago
notifications
5 months ago
views
4 months ago
watcher
2 weeks ago
wizard
2 weeks ago
class-admin-bar-menu.php
2 weeks ago
class-admin-breadcrumbs.php
2 weeks ago
class-admin-dashboard-nav.php
2 weeks ago
class-admin-header.php
2 weeks ago
class-admin-helper.php
2 weeks ago
class-admin-init.php
8 months ago
class-admin-menu.php
2 weeks ago
class-admin.php
6 days ago
class-api.php
1 year ago
class-ask-review.php
2 weeks ago
class-assets.php
2 weeks ago
class-bulk-actions.php
2 weeks ago
class-cmb2-fields.php
2 weeks ago
class-cmb2-options.php
2 weeks ago
class-dashboard-widget.php
2 weeks ago
class-import-export.php
2 weeks ago
class-list-table.php
2 weeks ago
class-lock-modified-date.php
1 year ago
class-notices.php
2 weeks ago
class-option-center.php
2 weeks ago
class-options.php
2 weeks ago
class-page.php
2 weeks ago
class-post-columns.php
2 weeks ago
class-post-filters.php
2 weeks ago
class-pro-notice.php
2 weeks ago
class-register-options-page.php
9 months ago
class-registration.php
2 weeks ago
class-sanitize-settings.php
2 weeks ago
class-setup-wizard.php
2 weeks ago
index.php
7 years ago
class-setup-wizard.php
207 lines
| 1 | <?php |
| 2 | /** |
| 3 | * The Setup Wizard - configure the SEO settings in just a few steps. |
| 4 | * |
| 5 | * @since 0.9.0 |
| 6 | * @package RankMath |
| 7 | * @subpackage RankMath\Admin |
| 8 | * @author Rank Math <support@rankmath.com> |
| 9 | */ |
| 10 | |
| 11 | namespace RankMath\Admin; |
| 12 | |
| 13 | use RankMath\Helper; |
| 14 | use RankMath\Traits\Hooker; |
| 15 | use RankMath\Traits\Wizard; |
| 16 | use RankMath\Admin\Importers\Detector; |
| 17 | use RankMath\Helpers\Param; |
| 18 | |
| 19 | defined( 'ABSPATH' ) || exit; |
| 20 | |
| 21 | /** |
| 22 | * Setup_Wizard class. |
| 23 | */ |
| 24 | class Setup_Wizard { |
| 25 | |
| 26 | use Hooker; |
| 27 | use Wizard; |
| 28 | |
| 29 | /** |
| 30 | * Top level admin page. |
| 31 | * |
| 32 | * @var string |
| 33 | */ |
| 34 | protected $slug = 'rank-math-wizard'; |
| 35 | |
| 36 | /** |
| 37 | * Hook suffix. |
| 38 | * |
| 39 | * @var string |
| 40 | */ |
| 41 | public $hook_suffix = ''; |
| 42 | |
| 43 | /** |
| 44 | * The Constructor. |
| 45 | */ |
| 46 | public function __construct() { |
| 47 | $this->action( 'admin_menu', 'add_admin_menu' ); |
| 48 | |
| 49 | // If the page is not this page stop here. |
| 50 | if ( ! $this->is_current_page() ) { |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | $this->action( 'admin_init', 'admin_page', 30 ); |
| 55 | $this->filter( 'user_has_cap', 'filter_user_has_cap' ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Add the admin menu item, under Appearance. |
| 60 | */ |
| 61 | public function add_admin_menu() { |
| 62 | if ( Param::get( 'page' ) !== $this->slug ) { |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | $this->hook_suffix = add_submenu_page( |
| 67 | '', |
| 68 | esc_html__( 'Setup Wizard', 'seo-by-rank-math' ), |
| 69 | esc_html__( 'Setup Wizard', 'seo-by-rank-math' ), |
| 70 | 'manage_options', |
| 71 | $this->slug, |
| 72 | [ $this, 'admin_page' ] |
| 73 | ); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Output the admin page. |
| 78 | */ |
| 79 | public function admin_page() { |
| 80 | |
| 81 | // Do not proceed if we're not on the right page. |
| 82 | if ( Param::get( 'page' ) !== $this->slug ) { |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | if ( ob_get_length() ) { |
| 87 | ob_end_clean(); |
| 88 | } |
| 89 | |
| 90 | // Enqueue styles. |
| 91 | rank_math()->admin_assets->register(); |
| 92 | wp_enqueue_style( 'rank-math-wizard', rank_math()->plugin_url() . 'assets/admin/css/setup-wizard.css', [ 'wp-admin', 'buttons', 'select2-rm', 'rank-math-common', 'rank-math-cmb2', 'wp-components' ], rank_math()->version ); |
| 93 | |
| 94 | // Enqueue scripts for the SEO Score Updater tool. |
| 95 | \RankMath\Tools\Update_Score::get()->enqueue(); |
| 96 | |
| 97 | // Enqueue javascript. |
| 98 | wp_enqueue_media(); |
| 99 | wp_enqueue_script( 'rank-math-wizard', rank_math()->plugin_url() . 'assets/admin/js/wizard.js', [ 'media-editor', 'select2-rm', 'lodash', 'rank-math-common', 'rank-math-components' ], rank_math()->version, true ); |
| 100 | wp_set_script_translations( 'rank-math-wizard', 'seo-by-rank-math' ); |
| 101 | |
| 102 | Helper::add_json( 'logo', esc_url( rank_math()->plugin_url() . 'assets/admin/img/logo.svg' ) ); |
| 103 | |
| 104 | ob_start(); |
| 105 | |
| 106 | /** |
| 107 | * Start the actual page content. |
| 108 | */ |
| 109 | include_once $this->get_view( 'content' ); |
| 110 | exit; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Get view file to display. |
| 115 | * |
| 116 | * @param string $view View to display. |
| 117 | * @return string |
| 118 | */ |
| 119 | public function get_view( $view ) { |
| 120 | return rank_math()->admin_dir() . "wizard/views/{$view}.php"; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Get Localized data for the given step. |
| 125 | * |
| 126 | * @param string $step Current Setup Wizard step. |
| 127 | */ |
| 128 | public static function get_localized_data( $step ) { |
| 129 | $steps = self::get_steps(); |
| 130 | if ( ! isset( $steps[ $step ] ) ) { |
| 131 | return ''; |
| 132 | } |
| 133 | |
| 134 | $data = [ |
| 135 | 'isWhitelabel' => Helper::is_whitelabel(), |
| 136 | 'isConfigured' => Helper::is_configured(), |
| 137 | 'setup_mode' => Helper::get_settings( 'general.setup_mode', 'advanced' ), |
| 138 | 'addImport' => ! self::maybe_remove_import(), |
| 139 | ]; |
| 140 | |
| 141 | return apply_filters( |
| 142 | "rank_math/setup_wizard/$step/localized_data", |
| 143 | array_merge( |
| 144 | $data, |
| 145 | $steps[ $step ]::get_localized_data() |
| 146 | ) |
| 147 | ); |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Get Localized data for the given step. |
| 152 | * |
| 153 | * @param string $step Current Setup Wizard step. |
| 154 | * @param array $values Values to update. |
| 155 | */ |
| 156 | public static function save_data( $step, $values ) { |
| 157 | $steps = self::get_steps(); |
| 158 | if ( ! isset( $steps[ $step ] ) ) { |
| 159 | return ''; |
| 160 | } |
| 161 | |
| 162 | do_action( "rank_math/setup_wizard/$step/save_data", $values ); |
| 163 | |
| 164 | return $steps[ $step ]::save( $values ); |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Get Setup Wizard step class. |
| 169 | */ |
| 170 | private static function get_steps() { |
| 171 | return [ |
| 172 | 'compatibility' => '\\RankMath\\Wizard\\Compatibility', |
| 173 | 'import' => '\\RankMath\\Wizard\\Import', |
| 174 | 'yoursite' => '\\RankMath\\Wizard\\Your_Site', |
| 175 | 'analytics' => '\\RankMath\\Wizard\\Search_Console', |
| 176 | 'sitemaps' => '\\RankMath\\Wizard\\Sitemap', |
| 177 | 'optimization' => '\\RankMath\\Wizard\\Optimization', |
| 178 | 'ready' => '\\RankMath\\Wizard\\Ready', |
| 179 | 'role' => '\\RankMath\\Wizard\\Role', |
| 180 | 'redirection' => '\\RankMath\\Wizard\\Monitor_Redirection', |
| 181 | 'schema-markup' => '\\RankMath\\Wizard\\Schema_Markup', |
| 182 | ]; |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Maybe remove import step. |
| 187 | * |
| 188 | * @return bool |
| 189 | */ |
| 190 | private static function maybe_remove_import() { |
| 191 | $pre = apply_filters( 'rank_math/wizard/pre_remove_import_step', null ); |
| 192 | if ( ! is_null( $pre ) ) { |
| 193 | return $pre; |
| 194 | } |
| 195 | |
| 196 | if ( false === get_option( 'rank_math_is_configured' ) ) { |
| 197 | $detector = new Detector(); |
| 198 | $plugins = $detector->detect(); |
| 199 | if ( ! empty( $plugins ) ) { |
| 200 | return false; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | return true; |
| 205 | } |
| 206 | } |
| 207 |