PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.6 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 All 130 releases
← All changes | admin/class-admin.php +44 -79 18.4 → trunk View file →
@@ -4,9 +4,9 @@
4 4 *
5 5 * @package WPSEO\Admin
6 6 */
7 7
8 -use Yoast\WP\SEO\Helpers\Wordpress_Helper;
8 +use Yoast\WP\SEO\Integrations\Settings_Integration;
9 9
10 10 /**
11 11 * Class that holds most of the admin functionality for Yoast SEO.
12 12 */
@@ -18,9 +18,9 @@
18 18 * !DO NOT CHANGE THIS!
19 19 *
20 20 * @var string
21 21 */
22 - const PAGE_IDENTIFIER = 'wpseo_dashboard';
22 + public const PAGE_IDENTIFIER = 'wpseo_dashboard';
23 23
24 24 /**
25 25 * Array of classes that add admin functionality.
26 26 *
@@ -42,17 +42,13 @@
42 42 if ( is_multisite() ) {
43 43 WPSEO_Options::maybe_set_multisite_defaults( false );
44 44 }
45 45
46 - if ( WPSEO_Options::get( 'stripcategorybase' ) === true ) {
47 - add_action( 'created_category', [ $this, 'schedule_rewrite_flush' ] );
48 - add_action( 'edited_category', [ $this, 'schedule_rewrite_flush' ] );
49 - add_action( 'delete_category', [ $this, 'schedule_rewrite_flush' ] );
50 - }
46 + add_action( 'created_category', [ $this, 'schedule_rewrite_flush' ] );
47 + add_action( 'edited_category', [ $this, 'schedule_rewrite_flush' ] );
48 + add_action( 'delete_category', [ $this, 'schedule_rewrite_flush' ] );
51 49
52 - if ( WPSEO_Options::get( 'disable-attachment' ) === true ) {
53 - add_filter( 'wpseo_accessible_post_types', [ 'WPSEO_Post_Type', 'filter_attachment_post_type' ] );
54 - }
50 + add_filter( 'wpseo_accessible_post_types', [ 'WPSEO_Post_Type', 'filter_attachment_post_type' ] );
55 51
56 52 add_filter( 'plugin_action_links_' . WPSEO_BASENAME, [ $this, 'add_action_link' ], 10, 2 );
57 53 add_filter( 'network_admin_plugin_action_links_' . WPSEO_BASENAME, [ $this, 'add_action_link' ], 10, 2 );
58 54
@@ -58,10 +54,8 @@
58 54
59 55 add_action( 'admin_enqueue_scripts', [ $this, 'config_page_scripts' ] );
60 56 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_global_style' ] );
61 57
62 - add_filter( 'user_contactmethods', [ $this, 'update_contactmethods' ], 10, 1 );
63 -
64 58 add_action( 'after_switch_theme', [ $this, 'switch_theme' ] );
65 59 add_action( 'switch_theme', [ $this, 'switch_theme' ] );
66 60
67 61 add_filter( 'set-screen-option', [ $this, 'save_bulk_edit_options' ], 10, 3 );
@@ -72,14 +66,8 @@
72 66
73 67 WPSEO_Sitemaps_Cache::register_clear_on_option_update( 'wpseo' );
74 68 WPSEO_Sitemaps_Cache::register_clear_on_option_update( 'home' );
75 69
76 - if ( YoastSEO()->helpers->current_page->is_yoast_seo_page() ) {
77 - add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
78 - }
79 -
80 - $this->set_upsell_notice();
81 -
82 70 $this->initialize_cornerstone_content();
83 71
84 72 if ( WPSEO_Utils::is_plugin_network_active() ) {
85 73 $integrations[] = new Yoast_Network_Admin();
@@ -85,9 +73,10 @@
85 73 $integrations[] = new Yoast_Network_Admin();
86 74 }
87 75
88 76 $this->admin_features = [
89 - 'dashboard_widget' => new Yoast_Dashboard_Widget(),
77 + 'dashboard_widget' => new Yoast_Dashboard_Widget(),
78 + 'wincher_dashboard_widget' => new Wincher_Dashboard_Widget(),
90 79 ];
91 80
92 81 if ( WPSEO_Metabox::is_post_overview( $pagenow ) || WPSEO_Metabox::is_post_edit( $pagenow ) ) {
93 82 $this->admin_features['primary_category'] = new WPSEO_Primary_Term_Admin();
@@ -105,9 +94,9 @@
105 94
106 95 $integrations = array_merge(
107 96 $integrations,
108 97 $this->get_admin_features(),
109 - $this->initialize_cornerstone_content()
98 + $this->initialize_cornerstone_content(),
110 99 );
111 100
112 101 foreach ( $integrations as $integration ) {
113 102 $integration->register_hooks();
@@ -115,10 +104,16 @@
115 104 }
116 105
117 106 /**
118 107 * Schedules a rewrite flush to happen at shutdown.
108 + *
109 + * @return void
119 110 */
120 111 public function schedule_rewrite_flush() {
112 + if ( WPSEO_Options::get( 'stripcategorybase' ) !== true ) {
113 + return;
114 + }
115 +
121 116 // Bail if this is a multisite installation and the site has been switched.
122 117 if ( is_multisite() && ms_is_switched() ) {
123 118 return;
124 119 }
@@ -135,18 +130,8 @@
135 130 return $this->admin_features;
136 131 }
137 132
138 133 /**
139 - * Register assets needed on admin pages.
140 - */
141 - public function enqueue_assets() {
142 - if ( filter_input( INPUT_GET, 'page' ) === 'wpseo_licenses' ) {
143 - $asset_manager = new WPSEO_Admin_Asset_Manager();
144 - $asset_manager->enqueue_style( 'extensions' );
145 - }
146 - }
147 -
148 - /**
149 134 * Returns the manage_options capability.
150 135 *
151 136 * @return string The capability to use.
152 137 */
@@ -153,9 +138,9 @@
153 138 public function get_manage_options_cap() {
154 139 /**
155 140 * Filter: 'wpseo_manage_options_capability' - Allow changing the capability users need to view the settings pages.
156 141 *
157 - * @api string unsigned The capability.
142 + * @param string $capability The capability.
158 143 */
159 144 return apply_filters( 'wpseo_manage_options_capability', 'wpseo_manage_options' );
160 145 }
161 146
@@ -160,14 +145,16 @@
160 145 }
161 146
162 147 /**
163 148 * Maps the manage_options cap on saving an options page to wpseo_manage_options.
149 + *
150 + * @return void
164 151 */
165 152 public function map_manage_options_cap() {
166 153 // phpcs:ignore WordPress.Security -- The variable is only used in strpos and thus safe to not unslash or sanitize.
167 154 $option_page = ! empty( $_POST['option_page'] ) ? $_POST['option_page'] : '';
168 155
169 - if ( strpos( $option_page, 'yoast_wpseo' ) === 0 ) {
156 + if ( strpos( $option_page, 'yoast_wpseo' ) === 0 || strpos( $option_page, Settings_Integration::PAGE ) === 0 ) {
170 157 add_filter( 'option_page_capability_' . $option_page, [ $this, 'get_manage_options_cap' ] );
171 158 }
172 159 }
173 160
@@ -173,8 +160,10 @@
173 160
174 161 /**
175 162 * Adds the ability to choose how many posts are displayed per page
176 163 * on the bulk edit pages.
164 + *
165 + * @return void
177 166 */
178 167 public function bulk_edit_options() {
179 168 $option = 'per_page';
180 169 $args = [
@@ -210,8 +199,10 @@
210 199 *
211 200 * @return array
212 201 */
213 202 public function add_action_link( $links, $file ) {
203 + $first_time_configuration_notice_helper = YoastSEO()->helpers->first_time_configuration_notice;
204 +
214 205 if ( $file === WPSEO_BASENAME && WPSEO_Capability_Utils::current_user_can( 'wpseo_manage_options' ) ) {
215 206 if ( is_network_admin() ) {
216 207 $settings_url = network_admin_url( 'admin.php?page=' . self::PAGE_IDENTIFIER );
217 208 }
@@ -225,8 +216,17 @@
225 216 // Add link to docs.
226 217 $faq_link = '<a href="' . esc_url( WPSEO_Shortlinker::get( 'https://yoa.st/1yc' ) ) . '" target="_blank">' . __( 'FAQ', 'wordpress-seo' ) . '</a>';
227 218 array_unshift( $links, $faq_link );
228 219
220 + if ( $first_time_configuration_notice_helper->first_time_configuration_not_finished() && ! is_network_admin() ) {
221 + $configuration_title = ( ! $first_time_configuration_notice_helper->should_show_alternate_message() ) ? 'first-time configuration' : 'SEO configuration';
222 + /* translators: CTA to finish the first time configuration. %s: Either first-time SEO configuration or SEO configuration. */
223 + $message = sprintf( __( 'Finish your %s', 'wordpress-seo' ), $configuration_title );
224 + $ftc_page = 'admin.php?page=wpseo_dashboard#/first-time-configuration';
225 + $ftc_link = '<a href="' . esc_url( admin_url( $ftc_page ) ) . '" target="_blank">' . $message . '</a>';
226 + array_unshift( $links, $ftc_link );
227 + }
228 +
229 229 $addon_manager = new WPSEO_Addon_Manager();
230 230 if ( YoastSEO()->helpers->product->is_premium() ) {
231 231
232 232 // Remove Free 'deactivate' link if Premium is active as well. We don't want users to deactivate Free when Premium is active.
@@ -233,9 +233,9 @@
233 233 unset( $links['deactivate'] );
234 234 $no_deactivation_explanation = '<span style="color: #32373c">' . sprintf(
235 235 /* translators: %s expands to Yoast SEO Premium. */
236 236 __( 'Required by %s', 'wordpress-seo' ),
237 - 'Yoast SEO Premium'
237 + 'Yoast SEO Premium',
238 238 ) . '</span>';
239 239
240 240 array_unshift( $links, $no_deactivation_explanation );
241 241
@@ -250,9 +250,9 @@
250 250 return $links;
251 251 }
252 252
253 253 // Add link to premium landing page.
254 - $premium_link = '<a style="font-weight: bold;" href="' . esc_url( WPSEO_Shortlinker::get( 'https://yoa.st/1yb' ) ) . '" target="_blank">' . __( 'Get Premium', 'wordpress-seo' ) . '</a>';
254 + $premium_link = '<a style="font-weight: bold;" href="' . esc_url( WPSEO_Shortlinker::get( 'https://yoa.st/1yb' ) ) . '" target="_blank" data-action="load-nfd-ctb" data-ctb-id="f6a84663-465f-4cb5-8ba5-f7a6d72224b2">' . __( 'Get Premium', 'wordpress-seo' ) . '</a>';
255 255 array_unshift( $links, $premium_link );
256 256
257 257 return $links;
258 258 }
@@ -258,8 +258,10 @@
258 258 }
259 259
260 260 /**
261 261 * Enqueues the (tiny) global JS needed for the plugin.
262 + *
263 + * @return void
262 264 */
263 265 public function config_page_scripts() {
264 266 $asset_manager = new WPSEO_Admin_Asset_Manager();
265 267 $asset_manager->enqueue_script( 'admin-global' );
@@ -267,8 +269,10 @@
267 269 }
268 270
269 271 /**
270 272 * Enqueues the (tiny) global stylesheet needed for the plugin.
273 + *
274 + * @return void
271 275 */
272 276 public function enqueue_global_style() {
273 277 $asset_manager = new WPSEO_Admin_Asset_Manager();
274 278 $asset_manager->enqueue_style( 'admin-global' );
@@ -274,45 +278,15 @@
274 278 $asset_manager->enqueue_style( 'admin-global' );
275 279 }
276 280
277 281 /**
278 - * Filter the $contactmethods array and add a set of social profiles.
282 + * Log the updated timestamp for user profiles when theme is changed.
279 283 *
280 - * These are used with the Facebook author, rel="author" and Twitter cards implementation.
281 - *
282 - * @param array $contactmethods Currently set contactmethods.
283 - *
284 - * @return array Contactmethods with added contactmethods.
284 + * @return void
285 285 */
286 - public function update_contactmethods( $contactmethods ) {
287 - $contactmethods['facebook'] = __( 'Facebook profile URL', 'wordpress-seo' );
288 - $contactmethods['instagram'] = __( 'Instagram profile URL', 'wordpress-seo' );
289 - $contactmethods['linkedin'] = __( 'LinkedIn profile URL', 'wordpress-seo' );
290 - $contactmethods['myspace'] = __( 'MySpace profile URL', 'wordpress-seo' );
291 - $contactmethods['pinterest'] = __( 'Pinterest profile URL', 'wordpress-seo' );
292 - $contactmethods['soundcloud'] = __( 'SoundCloud profile URL', 'wordpress-seo' );
293 - $contactmethods['tumblr'] = __( 'Tumblr profile URL', 'wordpress-seo' );
294 - $contactmethods['twitter'] = __( 'Twitter username (without @)', 'wordpress-seo' );
295 - $contactmethods['youtube'] = __( 'YouTube profile URL', 'wordpress-seo' );
296 - $contactmethods['wikipedia'] = __( 'Wikipedia page about you', 'wordpress-seo' ) . '<br/><small>' . __( '(if one exists)', 'wordpress-seo' ) . '</small>';
297 -
298 - return $contactmethods;
299 - }
300 -
301 - /**
302 - * Log the updated timestamp for user profiles when theme is changed.
303 - */
304 286 public function switch_theme() {
305 - $wordpress_helper = new Wordpress_Helper();
306 - $wordpress_version = $wordpress_helper->get_wordpress_version();
307 287
308 - // Capability queries were only introduced in WP 5.9.
309 - if ( version_compare( $wordpress_version, '5.8.99', '<' ) ) {
310 - $users = get_users( [ 'who' => 'authors' ] );
311 - }
312 - else {
313 - $users = get_users( [ 'capability' => [ 'edit_posts' ] ] );
314 - }
288 + $users = get_users( [ 'capability' => [ 'edit_posts' ] ] );
315 289
316 290 if ( is_array( $users ) && $users !== [] ) {
317 291 foreach ( $users as $user ) {
318 292 update_user_meta( $user->ID, '_yoast_wpseo_profile_updated', time() );
@@ -329,12 +303,12 @@
329 303 return array_merge(
330 304 [
331 305 'isRtl' => is_rtl(),
332 306 'variable_warning' => sprintf(
333 - /* translators: %1$s: '%%term_title%%' variable used in titles and meta's template that's not compatible with the given template, %2$s: expands to 'HelpScout beacon' */
307 + /* translators: %1$s: '%%term_title%%' variable used in titles and meta's template that's not compatible with the given template, %2$s: expands to 'HelpScout beacon' */
334 308 __( 'Warning: the variable %1$s cannot be used in this template. See the %2$s for more info.', 'wordpress-seo' ),
335 309 '<code>%s</code>',
336 - 'HelpScout beacon'
310 + 'HelpScout beacon',
337 311 ),
338 312 /* translators: %s: expends to Yoast SEO */
339 313 'help_video_iframe_title' => sprintf( __( '%s video tutorial', 'wordpress-seo' ), 'Yoast SEO' ),
340 314 'scrollable_table_hint' => __( 'Scroll to see the table content.', 'wordpress-seo' ),
@@ -339,19 +313,10 @@
339 313 'help_video_iframe_title' => sprintf( __( '%s video tutorial', 'wordpress-seo' ), 'Yoast SEO' ),
340 314 'scrollable_table_hint' => __( 'Scroll to see the table content.', 'wordpress-seo' ),
341 315 'wincher_is_logged_in' => WPSEO_Options::get( 'wincher_integration_active', true ) ? YoastSEO()->helpers->wincher->login_status() : false,
342 316 ],
343 - YoastSEO()->helpers->wincher->get_admin_global_links()
317 + YoastSEO()->helpers->wincher->get_admin_global_links(),
344 318 );
345 - }
346 -
347 - /**
348 - * Sets the upsell notice.
349 - */
350 - protected function set_upsell_notice() {
351 - $upsell = new WPSEO_Product_Upsell_Notice();
352 - $upsell->dismiss_notice_listener();
353 - $upsell->initialize();
354 319 }
355 320
356 321 /**
357 322 * Whether we are on the admin dashboard page.