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.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
← All changes | src/integrations/admin/first-time-configuration-integration.php +150 -82 19.0 → trunk View file →
@@ -1,22 +1,22 @@
1 1 <?php
2 2
3 3 namespace Yoast\WP\SEO\Integrations\Admin;
4 4
5 +use WP_User;
5 6 use WPSEO_Addon_Manager;
6 7 use WPSEO_Admin_Asset_Manager;
8 +use WPSEO_Option_Tab;
7 9 use WPSEO_Shortlinker;
8 -use WPSEO_Utils;
9 -use WPSEO_Option_Tab;
10 -
11 10 use Yoast\WP\SEO\Conditionals\Admin_Conditional;
11 +use Yoast\WP\SEO\Context\Meta_Tags_Context;
12 +use Yoast\WP\SEO\General\User_Interface\General_Page_Integration;
12 13 use Yoast\WP\SEO\Helpers\Options_Helper;
13 14 use Yoast\WP\SEO\Helpers\Product_Helper;
15 +use Yoast\WP\SEO\Helpers\Social_Profiles_Helper;
14 16 use Yoast\WP\SEO\Integrations\Integration_Interface;
15 -use Yoast\WP\SEO\Integrations\Admin\Social_Profiles_Helper;
16 17 use Yoast\WP\SEO\Routes\Indexing_Route;
17 18
18 -// phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded -- First time configuration simply has a lot of words.
19 19 /**
20 20 * First_Time_Configuration_Integration class
21 21 */
22 22 class First_Time_Configuration_Integration implements Integration_Interface {
@@ -63,8 +63,15 @@
63 63 */
64 64 private $product_helper;
65 65
66 66 /**
67 + * The meta tags context helper.
68 + *
69 + * @var Meta_Tags_Context
70 + */
71 + private $meta_tags_context;
72 +
73 + /**
67 74 * {@inheritDoc}
68 75 */
69 76 public static function get_conditionals() {
70 77 return [ Admin_Conditional::class ];
@@ -70,9 +77,9 @@
70 77 return [ Admin_Conditional::class ];
71 78 }
72 79
73 80 /**
74 - * Configuration_Workout_Integration constructor.
81 + * First_Time_Configuration_Integration constructor.
75 82 *
76 83 * @param WPSEO_Admin_Asset_Manager $admin_asset_manager The admin asset manager.
77 84 * @param WPSEO_Addon_Manager $addon_manager The addon manager.
78 85 * @param WPSEO_Shortlinker $shortlinker The shortlinker.
@@ -78,8 +85,9 @@
78 85 * @param WPSEO_Shortlinker $shortlinker The shortlinker.
79 86 * @param Options_Helper $options_helper The options helper.
80 87 * @param Social_Profiles_Helper $social_profiles_helper The social profile helper.
81 88 * @param Product_Helper $product_helper The product helper.
89 + * @param Meta_Tags_Context $meta_tags_context The meta tags context helper.
82 90 */
83 91 public function __construct(
84 92 WPSEO_Admin_Asset_Manager $admin_asset_manager,
85 93 WPSEO_Addon_Manager $addon_manager,
@@ -85,9 +93,10 @@
85 93 WPSEO_Addon_Manager $addon_manager,
86 94 WPSEO_Shortlinker $shortlinker,
87 95 Options_Helper $options_helper,
88 96 Social_Profiles_Helper $social_profiles_helper,
89 - Product_Helper $product_helper
97 + Product_Helper $product_helper,
98 + Meta_Tags_Context $meta_tags_context
90 99 ) {
91 100 $this->admin_asset_manager = $admin_asset_manager;
92 101 $this->addon_manager = $addon_manager;
93 102 $this->shortlinker = $shortlinker;
@@ -93,8 +102,9 @@
93 102 $this->shortlinker = $shortlinker;
94 103 $this->options_helper = $options_helper;
95 104 $this->social_profiles_helper = $social_profiles_helper;
96 105 $this->product_helper = $product_helper;
106 + $this->meta_tags_context = $meta_tags_context;
97 107 }
98 108
99 109 /**
100 110 * {@inheritDoc}
@@ -107,32 +117,35 @@
107 117 /**
108 118 * Adds a dedicated tab in the General sub-page.
109 119 *
110 120 * @param WPSEO_Options_Tabs $dashboard_tabs Object representing the tabs of the General sub-page.
121 + *
122 + * @return void
111 123 */
112 124 public function add_first_time_configuration_tab( $dashboard_tabs ) {
113 125 $dashboard_tabs->add_tab(
114 126 new WPSEO_Option_Tab(
115 127 'first-time-configuration',
116 - __( 'First-time configuration', 'wordpress-seo' ),
117 - [ 'save_button' => false ]
118 - )
128 + \__( 'First-time configuration', 'wordpress-seo' ),
129 + [ 'save_button' => false ],
130 + ),
119 131 );
120 132 }
121 133
122 134 /**
123 135 * Adds the data for the first-time configuration to the wpseoFirstTimeConfigurationData object.
136 + *
137 + * @return void
124 138 */
125 139 public function enqueue_assets() {
126 140 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Date is not processed or saved.
127 - if ( ! isset( $_GET['page'] ) || $_GET['page'] !== 'wpseo_dashboard' || \is_network_admin() ) {
141 + if ( ! isset( $_GET['page'] ) || ( $_GET['page'] !== 'wpseo_dashboard' && $_GET['page'] !== General_Page_Integration::PAGE ) || \is_network_admin() ) {
128 142 return;
129 143 }
130 144
131 145 $this->admin_asset_manager->enqueue_script( 'indexation' );
132 - $this->admin_asset_manager->enqueue_script( 'first-time-configuration' );
146 + $this->admin_asset_manager->enqueue_style( 'first-time-configuration' );
133 147 $this->admin_asset_manager->enqueue_style( 'admin-css' );
134 - $this->admin_asset_manager->enqueue_style( 'tailwind' );
135 148 $this->admin_asset_manager->enqueue_style( 'monorepo' );
136 149
137 150 $data = [
138 151 'disabled' => ! \YoastSEO()->helpers->indexable->should_index_indexables(),
@@ -167,9 +180,9 @@
167 180 $filtered_options = \array_filter(
168 181 $options,
169 182 function ( $item ) {
170 183 return $item['value'] === $this->is_company_or_person();
171 - }
184 + },
172 185 );
173 186 $selected_option = \reset( $filtered_options );
174 187 if ( \is_array( $selected_option ) ) {
175 188 $selected_option_label = $selected_option['label'];
@@ -174,70 +187,46 @@
174 187 if ( \is_array( $selected_option ) ) {
175 188 $selected_option_label = $selected_option['label'];
176 189 }
177 190
178 - $this->admin_asset_manager->add_inline_script(
179 - 'first-time-configuration',
180 - \sprintf(
181 - 'window.wpseoFirstTimeConfigurationData = {
182 - "canEditUser": %d,
183 - "companyOrPerson": "%s",
184 - "companyOrPersonLabel": "%s",
185 - "companyName": "%s",
186 - "companyLogo": "%s",
187 - "companyLogoId": %d,
188 - "finishedSteps": %s,
189 - "personId": %d,
190 - "personName": "%s",
191 - "personLogo": "%s",
192 - "personLogoId": %d,
193 - "siteTagline": "%s",
194 - "socialProfiles": {
195 - "facebookUrl": "%s",
196 - "twitterUsername": "%s",
197 - "otherSocialUrls": %s,
198 - },
199 - "isPremium": %d,
200 - "tracking": %d,
201 - "isTrackingAllowedMultisite": %d,
202 - "isMainSite": %d,
203 - "companyOrPersonOptions": %s,
204 - "shouldForceCompany": %d,
205 - "knowledgeGraphMessage": "%s",
206 - "shortlinks": {
207 - "gdpr": "%s",
208 - "configIndexables": "%s",
209 - "configIndexablesBenefits": "%s",
210 - },
211 - };',
212 - $this->social_profiles_helper->can_edit_profile( $person_id ),
213 - $this->is_company_or_person(),
214 - $selected_option_label,
215 - $this->get_company_name(),
216 - $this->get_company_logo(),
217 - $this->get_company_logo_id(),
218 - WPSEO_Utils::format_json_encode( $finished_steps ),
219 - $person_id,
220 - $this->get_person_name(),
221 - $this->get_person_logo(),
222 - $this->get_person_logo_id(),
223 - $this->get_site_tagline(),
224 - $social_profiles['facebook_url'],
225 - $social_profiles['twitter_username'],
226 - WPSEO_Utils::format_json_encode( $social_profiles['other_social_urls'] ),
227 - $this->product_helper->is_premium(),
228 - $this->has_tracking_enabled(),
229 - $this->is_tracking_enabled_multisite(),
230 - $this->is_main_site(),
231 - WPSEO_Utils::format_json_encode( $options ),
232 - $this->should_force_company(),
233 - $knowledge_graph_message,
234 - $this->shortlinker->build_shortlink( 'https://yoa.st/gdpr-config-workout' ),
235 - $this->shortlinker->build_shortlink( 'https://yoa.st/config-indexables' ),
236 - $this->shortlinker->build_shortlink( 'https://yoa.st/config-indexables-benefits' )
237 - ),
238 - 'before'
239 - );
191 + $data_ftc = [
192 + 'canEditUser' => $this->can_edit_profile( $person_id ),
193 + 'companyOrPerson' => $this->is_company_or_person(),
194 + 'companyOrPersonLabel' => $selected_option_label,
195 + 'companyName' => $this->get_company_name(),
196 + 'fallbackCompanyName' => $this->get_fallback_company_name( $this->get_company_name() ),
197 + 'websiteName' => $this->get_website_name(),
198 + 'fallbackWebsiteName' => $this->get_fallback_website_name( $this->get_website_name() ),
199 + 'companyLogo' => $this->get_company_logo(),
200 + 'companyLogoFallback' => $this->get_company_fallback_logo( $this->get_company_logo() ),
201 + 'companyLogoId' => $this->get_person_logo_id(),
202 + 'finishedSteps' => $finished_steps,
203 + 'personId' => (int) $person_id,
204 + 'personName' => $this->get_person_name(),
205 + 'personLogo' => $this->get_person_logo(),
206 + 'personLogoFallback' => $this->get_person_fallback_logo( $this->get_person_logo() ),
207 + 'personLogoId' => $this->get_person_logo_id(),
208 + 'siteTagline' => $this->get_site_tagline(),
209 + 'socialProfiles' => [
210 + 'facebookUrl' => $social_profiles['facebook_site'],
211 + 'twitterUsername' => $social_profiles['twitter_site'],
212 + 'otherSocialUrls' => $social_profiles['other_social_urls'],
213 + ],
214 + 'isPremium' => $this->product_helper->is_premium(),
215 + 'tracking' => $this->has_tracking_enabled(),
216 + 'isTrackingAllowedMultisite' => $this->is_tracking_enabled_multisite(),
217 + 'isMainSite' => $this->is_main_site(),
218 + 'companyOrPersonOptions' => $options,
219 + 'shouldForceCompany' => $this->should_force_company(),
220 + 'knowledgeGraphMessage' => $knowledge_graph_message,
221 + 'shortlinks' => [
222 + 'gdpr' => $this->shortlinker->build_shortlink( 'https://yoa.st/gdpr-config-workout' ),
223 + 'configIndexables' => $this->shortlinker->build_shortlink( 'https://yoa.st/config-indexables' ),
224 + 'configIndexablesBenefits' => $this->shortlinker->build_shortlink( 'https://yoa.st/config-indexables-benefits' ),
225 + ],
226 + ];
227 +
228 + $this->admin_asset_manager->localize_script( 'general-page', 'wpseoFirstTimeConfigurationData', $data_ftc );
240 229 }
241 230
242 231 /**
243 232 * Retrieves a list of the endpoints to use.
@@ -292,8 +281,47 @@
292 281 return $this->options_helper->get( 'company_name', '' );
293 282 }
294 283
295 284 /**
285 + * Gets the fallback company name from the option in the database if there is no company name.
286 + *
287 + * @param string $company_name The given company name by the user, default empty string.
288 + *
289 + * @return string|false The company name.
290 + */
291 + private function get_fallback_company_name( $company_name ) {
292 + if ( $company_name ) {
293 + return false;
294 + }
295 +
296 + return \get_bloginfo( 'name' );
297 + }
298 +
299 + /**
300 + * Gets the website name from the option in the database.
301 + *
302 + * @return string The website name.
303 + */
304 + private function get_website_name() {
305 + return $this->options_helper->get( 'website_name', '' );
306 + }
307 +
308 + /**
309 + * Gets the fallback website name from the option in the database if there is no website name.
310 + *
311 + * @param string $website_name The given website name by the user, default empty string.
312 + *
313 + * @return string|false The website name.
314 + */
315 + private function get_fallback_website_name( $website_name ) {
316 + if ( $website_name ) {
317 + return false;
318 + }
319 +
320 + return \get_bloginfo( 'name' );
321 + }
322 +
323 + /**
296 324 * Gets the company logo from the option in the database.
297 325 *
298 326 * @return string The company logo.
299 327 */
@@ -310,8 +338,24 @@
310 338 return $this->options_helper->get( 'company_logo_id', '' );
311 339 }
312 340
313 341 /**
342 + * Gets the company logo url from the option in the database.
343 + *
344 + * @param string $company_logo The given company logo by the user, default empty.
345 + *
346 + * @return string|false The company logo URL.
347 + */
348 + private function get_company_fallback_logo( $company_logo ) {
349 + if ( $company_logo ) {
350 + return false;
351 + }
352 + $logo_id = $this->meta_tags_context->fallback_to_site_logo();
353 +
354 + return \esc_url( \wp_get_attachment_url( $logo_id ) );
355 + }
356 +
357 + /**
314 358 * Gets the person id from the option in the database.
315 359 *
316 360 * @return int|null The person id, null if empty.
317 361 */
@@ -325,11 +369,12 @@
325 369 * @return int|null The person id, null if empty.
326 370 */
327 371 private function get_person_name() {
328 372 $user = \get_userdata( $this->get_person_id() );
329 - if ( $user instanceof \WP_User ) {
373 + if ( $user instanceof WP_User ) {
330 374 return $user->get( 'display_name' );
331 375 }
376 +
332 377 return '';
333 378 }
334 379
335 380 /**
@@ -341,8 +386,24 @@
341 386 return $this->options_helper->get( 'person_logo', '' );
342 387 }
343 388
344 389 /**
390 + * Gets the person logo url from the option in the database.
391 + *
392 + * @param string $person_logo The given person logo by the user, default empty.
393 + *
394 + * @return string|false The person logo URL.
395 + */
396 + private function get_person_fallback_logo( $person_logo ) {
397 + if ( $person_logo ) {
398 + return false;
399 + }
400 + $logo_id = $this->meta_tags_context->fallback_to_site_logo();
401 +
402 + return \esc_url( \wp_get_attachment_url( $logo_id ) );
403 + }
404 +
405 + /**
345 406 * Gets the person logo id from the option in the database.
346 407 *
347 408 * @return string The person logo id.
348 409 */
@@ -364,13 +425,9 @@
364 425 *
365 426 * @return string[] The social profiles.
366 427 */
367 428 private function get_social_profiles() {
368 - return [
369 - 'facebook_url' => $this->options_helper->get( 'facebook_site', '' ),
370 - 'twitter_username' => $this->options_helper->get( 'twitter_site', '' ),
371 - 'other_social_urls' => $this->options_helper->get( 'other_social_urls', [] ),
372 - ];
429 + return $this->social_profiles_helper->get_organization_social_profiles();
373 430 }
374 431
375 432 /**
376 433 * Checks whether tracking is enabled.
@@ -449,6 +506,17 @@
449 506 * @return bool
450 507 */
451 508 private function should_force_company() {
452 509 return $this->addon_manager->is_installed( WPSEO_Addon_Manager::LOCAL_SLUG );
510 + }
511 +
512 + /**
513 + * Checks if the current user has the capability to edit a specific user.
514 + *
515 + * @param int $person_id The id of the person to edit.
516 + *
517 + * @return bool
518 + */
519 + private function can_edit_profile( $person_id ) {
520 + return \current_user_can( 'edit_user', $person_id );
453 521 }
454 522 }