PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 19.0
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v19.0
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / admin / class-config.php

class-config.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 19.0, at admin/class-config.php

209 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPSEO plugin file.
4 *
5 * @package WPSEO\Admin
6 */
7
8 use Yoast\WP\SEO\Config\Schema_Types;
9
10 /**
11 * Class WPSEO_Admin_Pages.
12 *
13 * Class with functionality for the Yoast SEO admin pages.
14 */
15 class WPSEO_Admin_Pages {
16
17 /**
18 * The option in use for the current admin page.
19 *
20 * @var string
21 */
22 public $currentoption = 'wpseo';
23
24 /**
25 * Holds the asset manager.
26 *
27 * @var WPSEO_Admin_Asset_Manager
28 */
29 private $asset_manager;
30
31 /**
32 * Class constructor, which basically only hooks the init function on the init hook.
33 */
34 public function __construct() {
35 add_action( 'init', [ $this, 'init' ], 20 );
36 $this->asset_manager = new WPSEO_Admin_Asset_Manager();
37 }
38
39 /**
40 * Make sure the needed scripts are loaded for admin pages.
41 */
42 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();
45 }
46
47 add_action( 'admin_enqueue_scripts', [ $this, 'config_page_scripts' ] );
48 add_action( 'admin_enqueue_scripts', [ $this, 'config_page_styles' ] );
49 }
50
51 /**
52 * Loads the required styles for the config page.
53 */
54 public function config_page_styles() {
55 wp_enqueue_style( 'dashboard' );
56 wp_enqueue_style( 'thickbox' );
57 wp_enqueue_style( 'global' );
58 wp_enqueue_style( 'wp-admin' );
59 $this->asset_manager->enqueue_style( 'select2' );
60 $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 }
71 }
72
73 /**
74 * Loads the required scripts for the config page.
75 */
76 public function config_page_scripts() {
77 $this->asset_manager->enqueue_script( 'settings' );
78 wp_enqueue_script( 'dashboard' );
79 wp_enqueue_script( 'thickbox' );
80
81 $alert_dismissal_action = YoastSEO()->classes->get( \Yoast\WP\SEO\Actions\Alert_Dismissal_Action::class );
82 $dismissed_alerts = $alert_dismissal_action->all_dismissed();
83
84 $script_data = [
85 'userLanguageCode' => WPSEO_Language_Utils::get_language( \get_user_locale() ),
86 'dismissedAlerts' => $dismissed_alerts,
87 ];
88
89 $page = filter_input( INPUT_GET, 'page' );
90
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 ) ) {
120 wp_enqueue_media();
121
122 $script_data['media'] = [
123 'choose_image' => __( 'Use Image', 'wordpress-seo' ),
124 ];
125
126 $script_data['userEditUrl'] = add_query_arg( 'user_id', '{user_id}', admin_url( 'user-edit.php' ) );
127 }
128
129 if ( $page === 'wpseo_tools' ) {
130 $this->enqueue_tools_scripts();
131 }
132
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 $this->asset_manager->localize_script( 'settings', 'wpseoScriptData', $script_data );
157 $this->asset_manager->enqueue_user_language_script();
158 }
159
160 /**
161 * Retrieves some variables that are needed for replacing variables in JS.
162 *
163 * @return array The replacement and recommended replacement variables.
164 */
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();
170
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 ];
178 }
179
180 /**
181 * Determines whether the Local SEO upsell should be shown.
182 *
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.
188 */
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' );
202 }
203
204 if ( $tool === 'bulk-editor' ) {
205 $this->asset_manager->enqueue_script( 'bulk-editor' );
206 }
207 }
208 }
209