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

Yoast / wordpress-seo / 5066322038

pending completion
5066322038

push

github

GitHub
Merge pull request #20316 from Yoast/JRF/ghactions-run-more-selectively

2550 of 29012 relevant lines covered (8.79%)

0.32 hits per line

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

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

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

5
use WPSEO_Admin_Asset_Manager;
6
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
7
use Yoast\WP\SEO\Helpers\First_Time_Configuration_Notice_Helper;
8
use Yoast\WP\SEO\Helpers\Options_Helper;
9
use Yoast\WP\SEO\Integrations\Integration_Interface;
10
use Yoast\WP\SEO\Presenters\Admin\Notice_Presenter;
11

12
/**
13
 * First_Time_Configuration_Notice_Integration class
14
 */
15
class First_Time_Configuration_Notice_Integration implements Integration_Interface {
16

17
        /**
18
         * The options' helper.
19
         *
20
         * @var Options_Helper
21
         */
22
        private $options_helper;
23

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

31
        /**
32
         * The first time configuration notice helper.
33
         *
34
         * @var First_Time_Configuration_Notice_Helper
35
         */
36
        private $first_time_configuration_notice_helper;
37

38
        /**
39
         * {@inheritDoc}
40
         */
41
        public static function get_conditionals() {
42
                return [ Admin_Conditional::class ];
×
43
        }
44

45
        /**
46
         * First_Time_Configuration_Notice_Integration constructor.
47
         *
48
         * @param Options_Helper                         $options_helper                         The options helper.
49
         * @param First_Time_Configuration_Notice_Helper $first_time_configuration_notice_helper The first time configuration notice helper.
50
         * @param WPSEO_Admin_Asset_Manager              $admin_asset_manager                    The admin asset manager.
51
         */
52
        public function __construct(
53
                Options_Helper $options_helper,
54
                First_Time_Configuration_Notice_Helper $first_time_configuration_notice_helper,
55
                WPSEO_Admin_Asset_Manager $admin_asset_manager
56
        ) {
57
                $this->options_helper                         = $options_helper;
×
58
                $this->admin_asset_manager                    = $admin_asset_manager;
×
59
                $this->first_time_configuration_notice_helper = $first_time_configuration_notice_helper;
×
60
        }
61

62
        /**
63
         * {@inheritDoc}
64
         */
65
        public function register_hooks() {
66
                \add_action( 'wp_ajax_dismiss_first_time_configuration_notice', [ $this, 'dismiss_first_time_configuration_notice' ] );
×
67
                \add_action( 'admin_notices', [ $this, 'first_time_configuration_notice' ] );
×
68
        }
69

70
        /**
71
         * Dismisses the First-time configuration notice.
72
         *
73
         * @return bool
74
         */
75
        public function dismiss_first_time_configuration_notice() {
76
                // Check for nonce.
77
                if ( ! \check_ajax_referer( 'wpseo-dismiss-first-time-configuration-notice', 'nonce', false ) ) {
×
78
                        return false;
×
79
                }
80
                return $this->options_helper->set( 'dismiss_configuration_workout_notice', true );
×
81
        }
82

83
        /**
84
         * Determines whether and where the "First-time SEO Configuration" admin notice should be displayed.
85
         *
86
         * @return bool Whether the "First-time SEO Configuration" admin notice should be displayed.
87
         */
88
        public function should_display_first_time_configuration_notice() {
89
                return $this->first_time_configuration_notice_helper->should_display_first_time_configuration_notice();
×
90
        }
91

92
        /**
93
         * Displays an admin notice when the first-time configuration has not been finished yet.
94
         *
95
         * @return void
96
         */
97
        public function first_time_configuration_notice() {
98
                if ( ! $this->should_display_first_time_configuration_notice() ) {
×
99
                        return;
×
100
                }
101

102
                $this->admin_asset_manager->enqueue_style( 'monorepo' );
×
103

104
                $title    = $this->first_time_configuration_notice_helper->get_first_time_configuration_title();
×
105
                $link_url = \esc_url( \self_admin_url( 'admin.php?page=wpseo_dashboard#top#first-time-configuration' ) );
×
106

107
                if ( ! $this->first_time_configuration_notice_helper->should_show_alternate_message() ) {
×
108
                        $content = \sprintf(
×
109
                                /* translators: 1: Link start tag to the first-time configuration, 2: Yoast SEO, 3: Link closing tag. */
110
                                \__( 'Get started quickly with the %1$s%2$s First-time configuration%3$s and configure Yoast SEO with the optimal SEO settings for your site!', 'wordpress-seo' ),
×
111
                                '<a href="' . $link_url . '">',
×
112
                                'Yoast SEO',
×
113
                                '</a>'
×
114
                        );
×
115
                }
116
                else {
117
                        $content = \sprintf(
×
118
                                /* translators: 1: Link start tag to the first-time configuration, 2: Link closing tag. */
119
                                \__( 'We noticed that you haven\'t fully configured Yoast SEO yet. Optimize your SEO settings even further by using our improved %1$s First-time configuration%2$s.', 'wordpress-seo' ),
×
120
                                '<a href="' . $link_url . '">',
×
121
                                '</a>'
×
122
                        );
×
123
                }
124

125
                $notice = new Notice_Presenter(
×
126
                        $title,
×
127
                        $content,
×
128
                        'mirrored_fit_bubble_woman_1_optim.svg',
×
129
                        null,
×
130
                        true,
×
131
                        'yoast-first-time-configuration-notice'
×
132
                );
×
133

134
                //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output from present() is considered safe.
135
                echo $notice->present();
×
136

137
                // Enable permanently dismissing the notice.
138
                echo '<script>
×
139
                                jQuery( document ).ready( function() {
140
                                        jQuery( "body" ).on( "click", "#yoast-first-time-configuration-notice .notice-dismiss", function() {
141
                                                const data = {
142
                                                        "action": "dismiss_first_time_configuration_notice",
143
                                                        "nonce": "' . \esc_js( \wp_create_nonce( 'wpseo-dismiss-first-time-configuration-notice' ) ) . '"
×
144
                                                };
145
                                                jQuery.post( ajaxurl, data, function( response ) {
146
                                                        jQuery( this ).parent( "#yoast-first-time-configuration-notice" ).hide();
147
                                                });
148
                                        } );
149
                                } );
150
                                </script>';
×
151
        }
152
}
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

© 2026 Coveralls, Inc