| @@ -4,9 +4,16 @@ | ||
| 4 | 4 | * |
| 5 | 5 | * @package WPSEO\Admin |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -use Yoast\WP\SEO\Config\Schema_Types; | |
| 8 | +use Yoast\WP\SEO\Actions\Alert_Dismissal_Action; | |
| 9 | +use Yoast\WP\SEO\General\User_Interface\General_Page_Integration; | |
| 10 | +use Yoast\WP\SEO\Integrations\Academy_Integration; | |
| 11 | +use Yoast\WP\SEO\Integrations\Admin\Redirects_Page_Integration; | |
| 12 | +use Yoast\WP\SEO\Integrations\Settings_Integration; | |
| 13 | +use Yoast\WP\SEO\Integrations\Support_Integration; | |
| 14 | +use Yoast\WP\SEO\Plans\User_Interface\Plans_Page_Integration; | |
| 15 | +use Yoast\WP\SEO\Promotions\Application\Promotion_Manager; | |
| 9 | 16 | |
| 10 | 17 | /** |
| 11 | 18 | * Class WPSEO_Admin_Pages. |
| 12 | 19 | * |
| @@ -32,19 +39,38 @@ | ||
| 32 | 39 | * Class constructor, which basically only hooks the init function on the init hook. |
| 33 | 40 | */ |
| 34 | 41 | public function __construct() { |
| 35 | 42 | add_action( 'init', [ $this, 'init' ], 20 ); |
| 43 | + | |
| 36 | 44 | $this->asset_manager = new WPSEO_Admin_Asset_Manager(); |
| 37 | 45 | } |
| 38 | 46 | |
| 39 | 47 | /** |
| 40 | 48 | * Make sure the needed scripts are loaded for admin pages. |
| 49 | + * | |
| 50 | + * @return void | |
| 41 | 51 | */ |
| 42 | 52 | public function init() { |
| 43 | - if ( filter_input( INPUT_GET, 'wpseo_reset_defaults' ) && wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ), 'wpseo_reset_defaults' ) && current_user_can( 'manage_options' ) ) { | |
| 44 | - WPSEO_Options::reset(); | |
| 53 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. | |
| 54 | + $page = isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; | |
| 55 | + | |
| 56 | + // Don't load the scripts for the following pages. | |
| 57 | + $page_exceptions = in_array( | |
| 58 | + $page, | |
| 59 | + [ | |
| 60 | + Settings_Integration::PAGE, | |
| 61 | + Academy_Integration::PAGE, | |
| 62 | + Support_Integration::PAGE, | |
| 63 | + Plans_Page_Integration::PAGE, | |
| 64 | + Redirects_Page_Integration::PAGE, | |
| 65 | + ], | |
| 66 | + true, | |
| 67 | + ); | |
| 68 | + $new_dashboard_page = ( $page === General_Page_Integration::PAGE && ! is_network_admin() ); | |
| 69 | + if ( $page_exceptions || $new_dashboard_page ) { | |
| 70 | + // Bail, this is managed in the applicable integration. | |
| 71 | + return; | |
| 45 | 72 | } |
| 46 | - | |
| 47 | 73 | add_action( 'admin_enqueue_scripts', [ $this, 'config_page_scripts' ] ); |
| 48 | 74 | add_action( 'admin_enqueue_scripts', [ $this, 'config_page_styles' ] ); |
| 49 | 75 | } |
| 50 | 76 | |
| @@ -49,8 +75,10 @@ | ||
| 49 | 75 | } |
| 50 | 76 | |
| 51 | 77 | /** |
| 52 | 78 | * Loads the required styles for the config page. |
| 79 | + * | |
| 80 | + * @return void | |
| 53 | 81 | */ |
| 54 | 82 | public function config_page_styles() { |
| 55 | 83 | wp_enqueue_style( 'dashboard' ); |
| 56 | 84 | wp_enqueue_style( 'thickbox' ); |
| @@ -55,24 +83,16 @@ | ||
| 55 | 83 | wp_enqueue_style( 'dashboard' ); |
| 56 | 84 | wp_enqueue_style( 'thickbox' ); |
| 57 | 85 | wp_enqueue_style( 'global' ); |
| 58 | 86 | wp_enqueue_style( 'wp-admin' ); |
| 59 | - $this->asset_manager->enqueue_style( 'select2' ); | |
| 60 | 87 | $this->asset_manager->enqueue_style( 'admin-css' ); |
| 61 | - | |
| 62 | - $page = filter_input( INPUT_GET, 'page' ); | |
| 63 | - if ( $page === 'wpseo_titles' ) { | |
| 64 | - $this->asset_manager->enqueue_style( 'search-appearance' ); | |
| 65 | - } | |
| 66 | - | |
| 67 | - if ( $page === 'wpseo_social' || $page === 'wpseo_licenses' ) { | |
| 68 | - $this->asset_manager->enqueue_style( 'monorepo' ); | |
| 69 | - $this->asset_manager->enqueue_style( 'tailwind' ); | |
| 70 | - } | |
| 88 | + $this->asset_manager->enqueue_style( 'monorepo' ); | |
| 71 | 89 | } |
| 72 | 90 | |
| 73 | 91 | /** |
| 74 | 92 | * Loads the required scripts for the config page. |
| 93 | + * | |
| 94 | + * @return void | |
| 75 | 95 | */ |
| 76 | 96 | public function config_page_scripts() { |
| 77 | 97 | $this->asset_manager->enqueue_script( 'settings' ); |
| 78 | 98 | wp_enqueue_script( 'dashboard' ); |
| @@ -77,53 +97,28 @@ | ||
| 77 | 97 | $this->asset_manager->enqueue_script( 'settings' ); |
| 78 | 98 | wp_enqueue_script( 'dashboard' ); |
| 79 | 99 | wp_enqueue_script( 'thickbox' ); |
| 80 | 100 | |
| 81 | - $alert_dismissal_action = YoastSEO()->classes->get( \Yoast\WP\SEO\Actions\Alert_Dismissal_Action::class ); | |
| 101 | + $alert_dismissal_action = YoastSEO()->classes->get( Alert_Dismissal_Action::class ); | |
| 82 | 102 | $dismissed_alerts = $alert_dismissal_action->all_dismissed(); |
| 83 | 103 | |
| 84 | 104 | $script_data = [ |
| 85 | - 'userLanguageCode' => WPSEO_Language_Utils::get_language( \get_user_locale() ), | |
| 86 | - 'dismissedAlerts' => $dismissed_alerts, | |
| 105 | + 'dismissedAlerts' => $dismissed_alerts, | |
| 106 | + 'isRtl' => is_rtl(), | |
| 107 | + 'isPremium' => YoastSEO()->helpers->product->is_premium(), | |
| 108 | + 'currentPromotions' => YoastSEO()->classes->get( Promotion_Manager::class ) | |
| 109 | + ->get_current_promotions(), | |
| 110 | + 'webinarIntroFirstTimeConfigUrl' => $this->get_webinar_shortlink(), | |
| 111 | + 'linkParams' => WPSEO_Shortlinker::get_query_params(), | |
| 112 | + 'pluginUrl' => plugins_url( '', WPSEO_FILE ), | |
| 87 | 113 | ]; |
| 88 | 114 | |
| 89 | - $page = filter_input( INPUT_GET, 'page' ); | |
| 115 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. | |
| 116 | + $page = isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; | |
| 90 | 117 | |
| 91 | - if ( $page === 'wpseo_titles' ) { | |
| 92 | - $script_data['analysis'] = [ | |
| 93 | - 'plugins' => [ | |
| 94 | - 'replaceVars' => $this->get_replace_vars_script_data(), | |
| 95 | - ], | |
| 96 | - ]; | |
| 97 | - | |
| 98 | - $schema_types = new Schema_Types(); | |
| 99 | - $script_data['searchAppearance'] = [ | |
| 100 | - 'isRtl' => is_rtl(), | |
| 101 | - 'userEditUrl' => add_query_arg( 'user_id', '{user_id}', admin_url( 'user-edit.php' ) ), | |
| 102 | - 'brushstrokeBackgroundURL' => plugins_url( 'images/brushstroke_background.svg', WPSEO_FILE ), | |
| 103 | - 'showLocalSEOUpsell' => $this->should_show_local_seo_upsell(), | |
| 104 | - 'localSEOUpsellURL' => WPSEO_Shortlinker::get( 'https://yoa.st/3mp' ), | |
| 105 | - 'knowledgeGraphCompanyInfoMissing' => WPSEO_Language_Utils::get_knowledge_graph_company_info_missing_l10n(), | |
| 106 | - 'schema' => [ | |
| 107 | - 'pageTypeOptions' => $schema_types->get_page_type_options(), | |
| 108 | - 'articleTypeOptions' => $schema_types->get_article_type_options(), | |
| 109 | - ], | |
| 110 | - ]; | |
| 111 | - | |
| 112 | - /** | |
| 113 | - * Remove the emoji script as it is incompatible with both React and any | |
| 114 | - * contenteditable fields. | |
| 115 | - */ | |
| 116 | - remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); | |
| 117 | - } | |
| 118 | - | |
| 119 | - if ( in_array( $page, [ 'wpseo_social', WPSEO_Admin::PAGE_IDENTIFIER, 'wpseo_titles', 'wpseo_workouts' ], true ) ) { | |
| 118 | + if ( in_array( $page, [ WPSEO_Admin::PAGE_IDENTIFIER, 'wpseo_workouts' ], true ) ) { | |
| 120 | 119 | wp_enqueue_media(); |
| 121 | 120 | |
| 122 | - $script_data['media'] = [ | |
| 123 | - 'choose_image' => __( 'Use Image', 'wordpress-seo' ), | |
| 124 | - ]; | |
| 125 | - | |
| 126 | 121 | $script_data['userEditUrl'] = add_query_arg( 'user_id', '{user_id}', admin_url( 'user-edit.php' ) ); |
| 127 | 122 | } |
| 128 | 123 | |
| 129 | 124 | if ( $page === 'wpseo_tools' ) { |
| @@ -129,80 +124,34 @@ | ||
| 129 | 124 | if ( $page === 'wpseo_tools' ) { |
| 130 | 125 | $this->enqueue_tools_scripts(); |
| 131 | 126 | } |
| 132 | 127 | |
| 133 | - if ( $page === 'wpseo_social' ) { | |
| 134 | - $user_id = WPSEO_Options::get( 'company_or_person_user_id', '' ); | |
| 135 | - $user = \get_userdata( $user_id ); | |
| 136 | - | |
| 137 | - $user_name = ''; | |
| 138 | - if ( $user instanceof \WP_User ) { | |
| 139 | - $user_name = $user->get( 'display_name' ); | |
| 140 | - } | |
| 141 | - | |
| 142 | - $script_data['social'] = [ | |
| 143 | - 'facebook_url' => WPSEO_Options::get( 'facebook_site', '' ), | |
| 144 | - 'twitter_username' => WPSEO_Options::get( 'twitter_site', '' ), | |
| 145 | - 'other_social_urls' => WPSEO_Options::get( 'other_social_urls', [] ), | |
| 146 | - 'company_or_person' => WPSEO_Options::get( 'company_or_person', '' ), | |
| 147 | - 'user_id' => $user_id, | |
| 148 | - 'user_name' => $user_name | |
| 149 | - ]; | |
| 150 | - | |
| 151 | - $script_data['search_appearance_link'] = admin_url( 'admin.php?page=wpseo_titles' ); | |
| 152 | - | |
| 153 | - $script_data['force_organization'] = ( defined( 'WPSEO_LOCAL_FILE' ) ); | |
| 154 | - } | |
| 155 | - | |
| 156 | 128 | $this->asset_manager->localize_script( 'settings', 'wpseoScriptData', $script_data ); |
| 157 | - $this->asset_manager->enqueue_user_language_script(); | |
| 158 | 129 | } |
| 159 | 130 | |
| 160 | 131 | /** |
| 161 | - * Retrieves some variables that are needed for replacing variables in JS. | |
| 132 | + * Enqueues and handles all the tool dependencies. | |
| 162 | 133 | * |
| 163 | - * @return array The replacement and recommended replacement variables. | |
| 134 | + * @return void | |
| 164 | 135 | */ |
| 165 | - public function get_replace_vars_script_data() { | |
| 166 | - $replace_vars = new WPSEO_Replace_Vars(); | |
| 167 | - $recommended_replace_vars = new WPSEO_Admin_Recommended_Replace_Vars(); | |
| 168 | - $editor_specific_replace_vars = new WPSEO_Admin_Editor_Specific_Replace_Vars(); | |
| 169 | - $replace_vars_list = $replace_vars->get_replacement_variables_list(); | |
| 136 | + private function enqueue_tools_scripts() { | |
| 137 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. | |
| 138 | + $tool = isset( $_GET['tool'] ) && is_string( $_GET['tool'] ) ? sanitize_text_field( wp_unslash( $_GET['tool'] ) ) : ''; | |
| 170 | 139 | |
| 171 | - return [ | |
| 172 | - 'replace_vars' => $replace_vars_list, | |
| 173 | - 'recommended_replace_vars' => $recommended_replace_vars->get_recommended_replacevars(), | |
| 174 | - 'editor_specific_replace_vars' => $editor_specific_replace_vars->get(), | |
| 175 | - 'shared_replace_vars' => $editor_specific_replace_vars->get_generic( $replace_vars_list ), | |
| 176 | - 'hidden_replace_vars' => $replace_vars->get_hidden_replace_vars(), | |
| 177 | - ]; | |
| 140 | + if ( empty( $tool ) ) { | |
| 141 | + $this->asset_manager->enqueue_script( 'yoast-seo' ); | |
| 142 | + } | |
| 178 | 143 | } |
| 179 | 144 | |
| 180 | 145 | /** |
| 181 | - * Determines whether the Local SEO upsell should be shown. | |
| 146 | + * Returns the appropriate shortlink for the Webinar. | |
| 182 | 147 | * |
| 183 | - * The Local SEO upsell should: | |
| 184 | - * - Only be shown in Free, not when Premium is active. | |
| 185 | - * - Not be shown when Local SEO is active. | |
| 186 | - * | |
| 187 | - * @return bool Whether the Local SEO upsell should be shown. | |
| 148 | + * @return string The shortlink for the Webinar. | |
| 188 | 149 | */ |
| 189 | - private function should_show_local_seo_upsell() { | |
| 190 | - return ! YoastSEO()->helpers->product->is_premium() | |
| 191 | - && ! ( defined( 'WPSEO_LOCAL_FILE' ) ); | |
| 192 | - } | |
| 193 | - | |
| 194 | - /** | |
| 195 | - * Enqueues and handles all the tool dependencies. | |
| 196 | - */ | |
| 197 | - private function enqueue_tools_scripts() { | |
| 198 | - $tool = filter_input( INPUT_GET, 'tool' ); | |
| 199 | - | |
| 200 | - if ( empty( $tool ) ) { | |
| 201 | - $this->asset_manager->enqueue_script( 'yoast-seo' ); | |
| 150 | + private function get_webinar_shortlink() { | |
| 151 | + if ( YoastSEO()->helpers->product->is_premium() ) { | |
| 152 | + return WPSEO_Shortlinker::get( 'https://yoa.st/webinar-intro-first-time-config-premium' ); | |
| 202 | 153 | } |
| 203 | 154 | |
| 204 | - if ( $tool === 'bulk-editor' ) { | |
| 205 | - $this->asset_manager->enqueue_script( 'bulk-editor' ); | |
| 206 | - } | |
| 155 | + return WPSEO_Shortlinker::get( 'https://yoa.st/webinar-intro-first-time-config' ); | |
| 207 | 156 | } |
| 208 | 157 | } |