1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
<?php /** * WPSEO plugin file. * * @package WPSEO\Admin */
/** * Class WPSEO_Admin_Pages. * * Class with functionality for the Yoast SEO admin pages. */ class WPSEO_Admin_Pages {
/** * The option in use for the current admin page. * * @var string */ public $currentoption = 'wpseo';
/** * Holds the asset manager. * * @var WPSEO_Admin_Asset_Manager */ private $asset_manager;
/** * Class constructor, which basically only hooks the init function on the init hook. */ public function __construct() { add_action( 'init', array( $this, 'init' ), 20 ); $this->asset_manager = new WPSEO_Admin_Asset_Manager(); }
/** * Make sure the needed scripts are loaded for admin pages. */ public function init() { if ( filter_input( INPUT_GET, 'wpseo_reset_defaults' ) && wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ), 'wpseo_reset_defaults' ) && current_user_can( 'manage_options' ) ) { WPSEO_Options::reset(); wp_redirect( admin_url( 'admin.php?page=' . WPSEO_Configuration_Page::PAGE_IDENTIFIER ) ); }
add_action( 'admin_enqueue_scripts', array( $this, 'config_page_scripts' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'config_page_styles' ) ); }
/** * Loads the required styles for the config page. */ public function config_page_styles() { wp_enqueue_style( 'dashboard' ); wp_enqueue_style( 'thickbox' ); wp_enqueue_style( 'global' ); wp_enqueue_style( 'wp-admin' ); $this->asset_manager->enqueue_style( 'select2' );
$this->asset_manager->enqueue_style( 'admin-css' ); }
/** * Loads the required scripts for the config page. */ public function config_page_scripts() { $this->asset_manager->enqueue_script( 'admin-script' ); $this->asset_manager->enqueue_script( 'help-center' );
$page = filter_input( INPUT_GET, 'page' );
if ( $page === 'wpseo_titles' ) { wp_localize_script( WPSEO_Admin_Asset_Manager::PREFIX . 'search-appearance', 'wpseoReplaceVarsL10n', $this->localize_replace_vars_script() ); wp_localize_script( WPSEO_Admin_Asset_Manager::PREFIX . 'search-appearance', 'wpseoSearchAppearance', $this->localize_search_appearance_script() ); $this->asset_manager->enqueue_script( 'search-appearance' ); $this->asset_manager->enqueue_style( 'search-appearance' ); /** * Remove the emoji script as it is incompatible with both React and any * contenteditable fields. */ remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
$yoast_components_l10n = new WPSEO_Admin_Asset_Yoast_Components_L10n(); $yoast_components_l10n->localize_script( 'search-appearance' ); }
wp_enqueue_script( 'dashboard' ); wp_enqueue_script( 'thickbox' );
wp_localize_script( WPSEO_Admin_Asset_Manager::PREFIX . 'admin-script', 'wpseoSelect2Locale', WPSEO_Language_Utils::get_language( WPSEO_Language_Utils::get_user_locale() ) );
if ( in_array( $page, array( 'wpseo_social', WPSEO_Admin::PAGE_IDENTIFIER, 'wpseo_titles' ), true ) ) { wp_enqueue_media();
$this->asset_manager->enqueue_script( 'admin-media' ); wp_localize_script( WPSEO_Admin_Asset_Manager::PREFIX . 'admin-media', 'wpseoMediaL10n', $this->localize_media_script() ); }
if ( 'wpseo_tools' === $page ) { $this->enqueue_tools_scripts(); } }
/** * Retrieves some variables that are needed for the upload module in JS. * * @return array The upload module variables. */ public function localize_media_script() { return array( 'choose_image' => __( 'Use Image', 'wordpress-seo' ), ); }
/** * Retrieves some variables that are needed for replacing variables in JS. * * @return array The replacement and recommended replacement variables. */ public function localize_replace_vars_script() { $replace_vars = new WPSEO_Replace_Vars(); $recommended_replace_vars = new WPSEO_Admin_Recommended_Replace_Vars(); $editor_specific_replace_vars = new WPSEO_Admin_Editor_Specific_Replace_Vars(); $replace_vars_list = $replace_vars->get_replacement_variables_list();
return array( 'replace_vars' => $replace_vars_list, 'recommended_replace_vars' => $recommended_replace_vars->get_recommended_replacevars(), 'editor_specific_replace_vars' => $editor_specific_replace_vars->get(), 'shared_replace_vars' => $editor_specific_replace_vars->get_generic( $replace_vars_list ), ); }
/** * Retrieves some variables that are needed for the search appearance in JS. * * @return array The search appearance variables. */ public function localize_search_appearance_script() { return array( 'isRtl' => is_rtl(), 'userEditUrl' => add_query_arg( 'user_id', '{user_id}', admin_url( 'user-edit.php' ) ), 'brushstrokeBackgroundURL' => plugins_url( 'images/brushstroke_background.svg', WPSEO_FILE ), 'showLocalSEOUpsell' => $this->should_show_local_seo_upsell(), 'localSEOUpsellURL' => WPSEO_Shortlinker::get( 'https://yoa.st/3mp' ), ); }
/** * Determines whether the Local SEO upsell should be shown. * * The Local SEO upsell should: * - Only be shown in Free, not when Premium is active. * - Not be shown when Local SEO is active. * * @return bool Whether the Local SEO upsell should be shown. */ private function should_show_local_seo_upsell() { $addon_manager = new WPSEO_Addon_Manager();
return ! WPSEO_Utils::is_yoast_seo_premium() && ! $addon_manager->has_valid_subscription( WPSEO_Addon_Manager::LOCAL_SLUG ); }
/** * Enqueues and handles all the tool dependencies. */ private function enqueue_tools_scripts() { $tool = filter_input( INPUT_GET, 'tool' );
if ( empty( $tool ) ) { $this->asset_manager->enqueue_script( 'yoast-seo' ); }
if ( 'bulk-editor' === $tool ) { $this->asset_manager->enqueue_script( 'bulk-editor' ); } } } /* End of class */
|