• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / dd6e866a9e6d253114633104d9e3858d807178ba

19 Jun 2024 10:03AM UTC coverage: 48.628% (-4.3%) from 52.936%
dd6e866a9e6d253114633104d9e3858d807178ba

push

github

web-flow
Merge pull request #21431 from Yoast/21429-update-copy-in-the-introduction-and-consent-modals

Updates the copy for the introduction and consent modals

7441 of 13454 branches covered (55.31%)

Branch coverage included in aggregate %.

0 of 3 new or added lines in 2 files covered. (0.0%)

3718 existing lines in 107 files now uncovered.

25100 of 53464 relevant lines covered (46.95%)

62392.47 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/integrations/admin/first-time-configuration-integration.php
1
<?php
2

3
namespace Yoast\WP\SEO\Integrations\Admin;
4

5
use WP_User;
6
use WPSEO_Addon_Manager;
7
use WPSEO_Admin_Asset_Manager;
8
use WPSEO_Option_Tab;
9
use WPSEO_Shortlinker;
10
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
11
use Yoast\WP\SEO\Context\Meta_Tags_Context;
12
use Yoast\WP\SEO\Helpers\Options_Helper;
13
use Yoast\WP\SEO\Helpers\Product_Helper;
14
use Yoast\WP\SEO\Helpers\Social_Profiles_Helper;
15
use Yoast\WP\SEO\Integrations\Integration_Interface;
16
use Yoast\WP\SEO\Routes\Indexing_Route;
17

18
/**
19
 * First_Time_Configuration_Integration class
20
 */
21
class First_Time_Configuration_Integration implements Integration_Interface {
22

23
        /**
24
         * The admin asset manager.
25
         *
26
         * @var WPSEO_Admin_Asset_Manager
27
         */
28
        private $admin_asset_manager;
29

30
        /**
31
         * The addon manager.
32
         *
33
         * @var WPSEO_Addon_Manager
34
         */
35
        private $addon_manager;
36

37
        /**
38
         * The shortlinker.
39
         *
40
         * @var WPSEO_Shortlinker
41
         */
42
        private $shortlinker;
43

44
        /**
45
         * The options' helper.
46
         *
47
         * @var Options_Helper
48
         */
49
        private $options_helper;
50

51
        /**
52
         * The social profiles helper.
53
         *
54
         * @var Social_Profiles_Helper
55
         */
56
        private $social_profiles_helper;
57

58
        /**
59
         * The product helper.
60
         *
61
         * @var Product_Helper
62
         */
63
        private $product_helper;
64

65
        /**
66
         * The meta tags context helper.
67
         *
68
         * @var Meta_Tags_Context
69
         */
70
        private $meta_tags_context;
71

72
        /**
73
         * {@inheritDoc}
74
         */
75
        public static function get_conditionals() {
×
76
                return [ Admin_Conditional::class ];
×
77
        }
78

79
        /**
80
         * First_Time_Configuration_Integration constructor.
81
         *
82
         * @param WPSEO_Admin_Asset_Manager $admin_asset_manager    The admin asset manager.
83
         * @param WPSEO_Addon_Manager       $addon_manager          The addon manager.
84
         * @param WPSEO_Shortlinker         $shortlinker            The shortlinker.
85
         * @param Options_Helper            $options_helper         The options helper.
86
         * @param Social_Profiles_Helper    $social_profiles_helper The social profile helper.
87
         * @param Product_Helper            $product_helper         The product helper.
88
         * @param Meta_Tags_Context         $meta_tags_context      The meta tags context helper.
89
         */
90
        public function __construct(
×
91
                WPSEO_Admin_Asset_Manager $admin_asset_manager,
92
                WPSEO_Addon_Manager $addon_manager,
93
                WPSEO_Shortlinker $shortlinker,
94
                Options_Helper $options_helper,
95
                Social_Profiles_Helper $social_profiles_helper,
96
                Product_Helper $product_helper,
97
                Meta_Tags_Context $meta_tags_context
98
        ) {
99
                $this->admin_asset_manager    = $admin_asset_manager;
×
100
                $this->addon_manager          = $addon_manager;
×
101
                $this->shortlinker            = $shortlinker;
×
102
                $this->options_helper         = $options_helper;
×
103
                $this->social_profiles_helper = $social_profiles_helper;
×
104
                $this->product_helper         = $product_helper;
×
105
                $this->meta_tags_context      = $meta_tags_context;
×
106
        }
107

108
        /**
109
         * {@inheritDoc}
110
         */
111
        public function register_hooks() {
×
112
                \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
×
113
                \add_action( 'wpseo_settings_tabs_dashboard', [ $this, 'add_first_time_configuration_tab' ] );
×
114
        }
115

116
        /**
117
         * Adds a dedicated tab in the General sub-page.
118
         *
119
         * @param WPSEO_Options_Tabs $dashboard_tabs Object representing the tabs of the General sub-page.
120
         *
121
         * @return void
122
         */
123
        public function add_first_time_configuration_tab( $dashboard_tabs ) {
×
124
                $dashboard_tabs->add_tab(
×
125
                        new WPSEO_Option_Tab(
×
126
                                'first-time-configuration',
×
127
                                \__( 'First-time configuration', 'wordpress-seo' ),
×
128
                                [ 'save_button' => false ]
×
129
                        )
130
                );
131
        }
132

133
        /**
134
         * Adds the data for the first-time configuration to the wpseoFirstTimeConfigurationData object.
135
         *
136
         * @return void
137
         */
138
        public function enqueue_assets() {
×
139
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Date is not processed or saved.
140
                if ( ! isset( $_GET['page'] ) || $_GET['page'] !== 'wpseo_dashboard' || \is_network_admin() ) {
×
141
                        return;
×
142
                }
143

144
                $this->admin_asset_manager->enqueue_script( 'indexation' );
×
145
                $this->admin_asset_manager->enqueue_script( 'first-time-configuration' );
×
146
                $this->admin_asset_manager->enqueue_style( 'first-time-configuration' );
×
147
                $this->admin_asset_manager->enqueue_style( 'admin-css' );
×
148
                $this->admin_asset_manager->enqueue_style( 'monorepo' );
×
149

150
                $data = [
151
                        'disabled'     => ! \YoastSEO()->helpers->indexable->should_index_indexables(),
×
152
                        'amount'       => \YoastSEO()->helpers->indexing->get_filtered_unindexed_count(),
×
153
                        'firstTime'    => ( \YoastSEO()->helpers->indexing->is_initial_indexing() === true ),
×
154
                        'errorMessage' => '',
×
155
                        'restApi'      => [
156
                                'root'               => \esc_url_raw( \rest_url() ),
×
157
                                'indexing_endpoints' => $this->get_endpoints(),
×
158
                                'nonce'              => \wp_create_nonce( 'wp_rest' ),
×
159
                        ],
160
                ];
161

162
                /**
163
                 * Filter: 'wpseo_indexing_data' Filter to adapt the data used in the indexing process.
164
                 *
165
                 * @param array $data The indexing data to adapt.
166
                 */
167
                $data = \apply_filters( 'wpseo_indexing_data', $data );
×
168

169
                $this->admin_asset_manager->localize_script( 'indexation', 'yoastIndexingData', $data );
×
170

171
                $person_id       = $this->get_person_id();
×
172
                $social_profiles = $this->get_social_profiles();
×
173

174
                // This filter is documented in admin/views/tabs/metas/paper-content/general/knowledge-graph.php.
175
                $knowledge_graph_message = \apply_filters( 'wpseo_knowledge_graph_setting_msg', '' );
×
176

177
                $finished_steps        = $this->get_finished_steps();
×
178
                $options               = $this->get_company_or_person_options();
×
179
                $selected_option_label = '';
×
180
                $filtered_options      = \array_filter(
×
181
                        $options,
×
182
                        function ( $item ) {
183
                                return $item['value'] === $this->is_company_or_person();
×
184
                        }
UNCOV
185
                );
×
186
                $selected_option       = \reset( $filtered_options );
×
187
                if ( \is_array( $selected_option ) ) {
×
188
                        $selected_option_label = $selected_option['label'];
189
                }
190

UNCOV
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(),
UNCOV
209
                        'socialProfiles'             => [
×
210
                                'facebookUrl'     => $social_profiles['facebook_site'],
×
211
                                'twitterUsername' => $social_profiles['twitter_site'],
×
212
                                'otherSocialUrls' => $social_profiles['other_social_urls'],
UNCOV
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,
UNCOV
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( 'first-time-configuration', 'wpseoFirstTimeConfigurationData', $data_ftc );
×
229
        }
230

231
        /**
232
         * Retrieves a list of the endpoints to use.
233
         *
234
         * @return array The endpoints.
235
         */
236
        protected function get_endpoints() {
237
                $endpoints = [
238
                        'prepare'            => Indexing_Route::FULL_PREPARE_ROUTE,
239
                        'terms'              => Indexing_Route::FULL_TERMS_ROUTE,
240
                        'posts'              => Indexing_Route::FULL_POSTS_ROUTE,
241
                        'archives'           => Indexing_Route::FULL_POST_TYPE_ARCHIVES_ROUTE,
242
                        'general'            => Indexing_Route::FULL_GENERAL_ROUTE,
243
                        'indexablesComplete' => Indexing_Route::FULL_INDEXABLES_COMPLETE_ROUTE,
244
                        'post_link'          => Indexing_Route::FULL_POST_LINKS_INDEXING_ROUTE,
245
                        'term_link'          => Indexing_Route::FULL_TERM_LINKS_INDEXING_ROUTE,
246
                ];
247

248
                $endpoints = \apply_filters( 'wpseo_indexing_endpoints', $endpoints );
249

250
                $endpoints['complete'] = Indexing_Route::FULL_COMPLETE_ROUTE;
251

252
                return $endpoints;
253
        }
254

255
        // ** Private functions ** //
256

257
        /**
258
         * Returns the finished steps array.
259
         *
260
         * @return array An array with the finished steps.
261
         */
262
        private function get_finished_steps() {
263
                return $this->options_helper->get( 'configuration_finished_steps', [] );
264
        }
265

266
        /**
267
         * Returns the entity represented by the site.
268
         *
269
         * @return string The entity represented by the site.
270
         */
271
        private function is_company_or_person() {
272
                return $this->options_helper->get( 'company_or_person', '' );
273
        }
274

275
        /**
276
         * Gets the company name from the option in the database.
277
         *
278
         * @return string The company name.
279
         */
280
        private function get_company_name() {
281
                return $this->options_helper->get( 'company_name', '' );
282
        }
283

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
        /**
324
         * Gets the company logo from the option in the database.
325
         *
326
         * @return string The company logo.
327
         */
328
        private function get_company_logo() {
329
                return $this->options_helper->get( 'company_logo', '' );
330
        }
331

332
        /**
333
         * Gets the company logo id from the option in the database.
334
         *
335
         * @return string The company logo id.
336
         */
337
        private function get_company_logo_id() {
338
                return $this->options_helper->get( 'company_logo_id', '' );
339
        }
340

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
        /**
358
         * Gets the person id from the option in the database.
359
         *
360
         * @return int|null The person id, null if empty.
361
         */
362
        private function get_person_id() {
363
                return $this->options_helper->get( 'company_or_person_user_id' );
364
        }
365

366
        /**
367
         * Gets the person id from the option in the database.
368
         *
369
         * @return int|null The person id, null if empty.
370
         */
371
        private function get_person_name() {
×
372
                $user = \get_userdata( $this->get_person_id() );
×
373
                if ( $user instanceof WP_User ) {
×
374
                        return $user->get( 'display_name' );
375
                }
376

377
                return '';
378
        }
379

380
        /**
381
         * Gets the person avatar from the option in the database.
382
         *
383
         * @return string The person logo.
384
         */
385
        private function get_person_logo() {
386
                return $this->options_helper->get( 'person_logo', '' );
387
        }
388

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
        /**
406
         * Gets the person logo id from the option in the database.
407
         *
408
         * @return string The person logo id.
409
         */
410
        private function get_person_logo_id() {
411
                return $this->options_helper->get( 'person_logo_id', '' );
412
        }
413

414
        /**
415
         * Gets the site tagline.
416
         *
417
         * @return string The site tagline.
418
         */
419
        private function get_site_tagline() {
420
                return \get_bloginfo( 'description' );
421
        }
422

423
        /**
424
         * Gets the social profiles stored in the database.
425
         *
426
         * @return string[] The social profiles.
427
         */
428
        private function get_social_profiles() {
429
                return $this->social_profiles_helper->get_organization_social_profiles();
430
        }
431

432
        /**
433
         * Checks whether tracking is enabled.
434
         *
435
         * @return bool True if tracking is enabled, false otherwise, null if in Free and conf. workout step not finished.
436
         */
437
        private function has_tracking_enabled() {
×
438
                $default = false;
439

440
                if ( $this->product_helper->is_premium() ) {
×
441
                        $default = true;
442
                }
443

444
                return $this->options_helper->get( 'tracking', $default );
445
        }
446

447
        /**
448
         * Checks whether tracking option is allowed at network level.
449
         *
450
         * @return bool True if option change is allowed, false otherwise.
451
         */
452
        private function is_tracking_enabled_multisite() {
×
453
                $default = true;
454

455
                if ( ! \is_multisite() ) {
×
456
                        return $default;
457
                }
458

459
                return $this->options_helper->get( 'allow_tracking', $default );
460
        }
461

462
        /**
463
         * Checks whether we are in a main site.
464
         *
465
         * @return bool True if it's the main site or a single site, false if it's a subsite.
466
         */
467
        private function is_main_site() {
468
                return \is_main_site();
469
        }
470

471
        /**
472
         * Gets the options for the Company or Person select.
473
         * Returns only the company option if it is forced (by Local SEO), otherwise returns company and person option.
474
         *
475
         * @return array The options for the company-or-person select.
476
         */
477
        private function get_company_or_person_options() {
×
478
                $options = [
UNCOV
479
                        [
×
480
                                'label' => \__( 'Organization', 'wordpress-seo' ),
×
481
                                'value' => 'company',
×
482
                                'id'    => 'company',
483
                        ],
UNCOV
484
                        [
×
485
                                'label' => \__( 'Person', 'wordpress-seo' ),
×
486
                                'value' => 'person',
×
487
                                'id'    => 'person',
488
                        ],
UNCOV
489
                ];
×
490
                if ( $this->should_force_company() ) {
491
                        $options = [
UNCOV
492
                                [
×
493
                                        'label' => \__( 'Organization', 'wordpress-seo' ),
×
494
                                        'value' => 'company',
×
495
                                        'id'    => 'company',
496
                                ],
497
                        ];
498
                }
499

500
                return $options;
501
        }
502

503
        /**
504
         * Checks whether we should force "Organization".
505
         *
506
         * @return bool
507
         */
508
        private function should_force_company() {
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 );
521
        }
522
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc