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

Yoast / wordpress-seo / a1a9bc98f6cb081fd9c260a818d31117ee95bbf9

13 Jul 2025 06:23PM UTC coverage: 53.514% (-0.03%) from 53.541%
a1a9bc98f6cb081fd9c260a818d31117ee95bbf9

Pull #22425

github

web-flow
Merge 81f2877f3 into ea61749e1
Pull Request #22425: 626 create the feature opt in in the yoast dashboard

8246 of 14449 branches covered (57.07%)

Branch coverage included in aggregate %.

7 of 37 new or added lines in 5 files covered. (18.92%)

1 existing line in 1 file now uncovered.

30500 of 57954 relevant lines covered (52.63%)

41199.25 hits per line

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

90.0
/src/general/user-interface/general-page-integration.php
1
<?php
2

3
namespace Yoast\WP\SEO\General\User_Interface;
4

5
use WPSEO_Admin_Asset_Manager;
6
use Yoast\WP\SEO\Actions\Alert_Dismissal_Action;
7
use Yoast\WP\SEO\Conditionals\Admin\Non_Network_Admin_Conditional;
8
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
9
use Yoast\WP\SEO\Dashboard\Application\Configuration\Dashboard_Configuration;
10
use Yoast\WP\SEO\Helpers\Current_Page_Helper;
11
use Yoast\WP\SEO\Helpers\Notification_Helper;
12
use Yoast\WP\SEO\Helpers\Product_Helper;
13
use Yoast\WP\SEO\Helpers\Short_Link_Helper;
14
use Yoast\WP\SEO\Helpers\User_Helper;
15
use Yoast\WP\SEO\Integrations\Integration_Interface;
16
use Yoast\WP\SEO\Promotions\Application\Promotion_Manager;
17

18
/**
19
 * Class General_Page_Integration.
20
 */
21
class General_Page_Integration implements Integration_Interface {
22

23
        /**
24
         * The page name.
25
         */
26
        public const PAGE = 'wpseo_dashboard';
27

28
        /**
29
         * The notification helper.
30
         *
31
         * @var Notification_Helper
32
         */
33
        protected $notification_helper;
34

35
        /**
36
         * The dashboard configuration.
37
         *
38
         * @var Dashboard_Configuration
39
         */
40
        private $dashboard_configuration;
41

42
        /**
43
         * Holds the WPSEO_Admin_Asset_Manager.
44
         *
45
         * @var WPSEO_Admin_Asset_Manager
46
         */
47
        private $asset_manager;
48

49
        /**
50
         * Holds the Current_Page_Helper.
51
         *
52
         * @var Current_Page_Helper
53
         */
54
        private $current_page_helper;
55

56
        /**
57
         * Holds the Product_Helper.
58
         *
59
         * @var Product_Helper
60
         */
61
        private $product_helper;
62

63
        /**
64
         * Holds the Short_Link_Helper.
65
         *
66
         * @var Short_Link_Helper
67
         */
68
        private $shortlink_helper;
69

70
        /**
71
         * The promotion manager.
72
         *
73
         * @var Promotion_Manager
74
         */
75
        private $promotion_manager;
76

77
        /**
78
         * The alert dismissal action.
79
         *
80
         * @var Alert_Dismissal_Action
81
         */
82
        private $alert_dismissal_action;
83

84
        /**
85
         * Holds the user helper.
86
         *
87
         * @var User_Helper
88
         */
89
        private $user_helper;
90

91
        /**
92
         * Constructs Academy_Integration.
93
         *
94
         * @param WPSEO_Admin_Asset_Manager $asset_manager           The WPSEO_Admin_Asset_Manager.
95
         * @param Current_Page_Helper       $current_page_helper     The Current_Page_Helper.
96
         * @param Product_Helper            $product_helper          The Product_Helper.
97
         * @param Short_Link_Helper         $shortlink_helper        The Short_Link_Helper.
98
         * @param Notification_Helper       $notification_helper     The Notification_Helper.
99
         * @param Alert_Dismissal_Action    $alert_dismissal_action  The alert dismissal action.
100
         * @param Promotion_Manager         $promotion_manager       The promotion manager.
101
         * @param Dashboard_Configuration   $dashboard_configuration The dashboard configuration.
102
         * @param User_Helper               $user_helper             The user helper.
103
         */
104
        public function __construct(
2✔
105
                WPSEO_Admin_Asset_Manager $asset_manager,
106
                Current_Page_Helper $current_page_helper,
107
                Product_Helper $product_helper,
108
                Short_Link_Helper $shortlink_helper,
109
                Notification_Helper $notification_helper,
110
                Alert_Dismissal_Action $alert_dismissal_action,
111
                Promotion_Manager $promotion_manager,
112
                Dashboard_Configuration $dashboard_configuration,
113
                User_Helper $user_helper
114
        ) {
115
                $this->asset_manager           = $asset_manager;
2✔
116
                $this->current_page_helper     = $current_page_helper;
2✔
117
                $this->product_helper          = $product_helper;
2✔
118
                $this->shortlink_helper        = $shortlink_helper;
2✔
119
                $this->notification_helper     = $notification_helper;
2✔
120
                $this->alert_dismissal_action  = $alert_dismissal_action;
2✔
121
                $this->promotion_manager       = $promotion_manager;
2✔
122
                $this->dashboard_configuration = $dashboard_configuration;
2✔
123
                $this->user_helper             = $user_helper;
2✔
124
        }
125

126
        /**
127
         * Returns the conditionals based on which this loadable should be active.
128
         *
129
         * @return array<string>
130
         */
131
        public static function get_conditionals() {
2✔
132
                return [ Admin_Conditional::class, Non_Network_Admin_Conditional::class ];
2✔
133
        }
134

135
        /**
136
         * Initializes the integration.
137
         *
138
         * This is the place to register hooks and filters.
139
         *
140
         * @return void
141
         */
142
        public function register_hooks() {
4✔
143

144
                // Add page.
145
                \add_filter( 'wpseo_submenu_pages', [ $this, 'add_page' ] );
4✔
146

147
                // Are we on the dashboard page?
148
                if ( $this->current_page_helper->get_current_yoast_seo_page() === self::PAGE ) {
4✔
149
                        \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
2✔
150
                }
151
        }
152

153
        /**
154
         * Adds the page.
155
         *
156
         * @param array<string, array<string>> $pages The pages.
157
         *
158
         * @return array<string, array<string>> The pages.
159
         */
160
        public function add_page( $pages ) {
2✔
161
                \array_splice(
2✔
162
                        $pages,
2✔
163
                        0,
2✔
164
                        0,
2✔
165
                        [
2✔
166
                                [
2✔
167
                                        self::PAGE,
2✔
168
                                        '',
2✔
169
                                        \__( 'General', 'wordpress-seo' ),
2✔
170
                                        'wpseo_manage_options',
2✔
171
                                        self::PAGE,
2✔
172
                                        [ $this, 'display_page' ],
2✔
173
                                ],
2✔
174
                        ]
2✔
175
                );
2✔
176

177
                return $pages;
2✔
178
        }
179

180
        /**
181
         * Displays the page.
182
         *
183
         * @return void
184
         */
185
        public function display_page() {
2✔
186
                echo '<div id="yoast-seo-general"></div>';
2✔
187
        }
188

189
        /**
190
         * Enqueues the assets.
191
         *
192
         * @return void
193
         */
194
        public function enqueue_assets() {
2✔
195
                // Remove the emoji script as it is incompatible with both React and any contenteditable fields.
196
                \remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
2✔
197
                \wp_enqueue_media();
2✔
198
                $this->asset_manager->enqueue_script( 'general-page' );
2✔
199
                $this->asset_manager->enqueue_style( 'general-page' );
2✔
200
                if ( $this->promotion_manager->is( 'black-friday-2024-promotion' ) ) {
2✔
201
                        $this->asset_manager->enqueue_style( 'black-friday-banner' );
2✔
202
                }
203
                $this->asset_manager->localize_script( 'general-page', 'wpseoScriptData', $this->get_script_data() );
2✔
204
        }
205

206
        /**
207
         * Creates the script data.
208
         *
209
         * @return array The script data.
210
         */
211
        private function get_script_data() {
2✔
212
                return [
2✔
213
                        'preferences'       => [
2✔
214
                                'isPremium'              => $this->product_helper->is_premium(),
2✔
215
                                'isRtl'                  => \is_rtl(),
2✔
216
                                'pluginUrl'              => \plugins_url( '', \WPSEO_FILE ),
2✔
217
                                'upsellSettings'         => [
2✔
218
                                        'actionId'     => 'load-nfd-ctb',
2✔
219
                                        'premiumCtbId' => 'f6a84663-465f-4cb5-8ba5-f7a6d72224b2',
2✔
220
                                ],
2✔
221
                                'llmTxtNotificationSeen' => $this->is_llm_notification_seen(),
2✔
222
                        ],
2✔
223
                        'adminUrl'          => \admin_url( 'admin.php' ),
2✔
224
                        'linkParams'        => $this->shortlink_helper->get_query_params(),
2✔
225
                        'userEditUrl'       => \add_query_arg( 'user_id', '{user_id}', \admin_url( 'user-edit.php' ) ),
2✔
226
                        'alerts'            => $this->notification_helper->get_alerts(),
2✔
227
                        'currentPromotions' => $this->promotion_manager->get_current_promotions(),
2✔
228
                        'dismissedAlerts'   => $this->alert_dismissal_action->all_dismissed(),
2✔
229
                        'dashboard'         => $this->dashboard_configuration->get_configuration(),
2✔
230
                ];
2✔
231
        }
232

233
        /**
234
         * Gets if the llm txt opt-in notification has been seen.
235
         * This is used to show the notification only once.
236
         *
237
         * @return bool True if the notification has been seen, false otherwise.
238
         */
NEW
239
        public function is_llm_notification_seen(): bool {
×
NEW
240
                $key             = 'wpseo_seen_llm_txt_opt_in_notification';
×
NEW
241
                $current_user_id = $this->user_helper->get_current_user_id();
×
NEW
242
                $seen            = (bool) $this->user_helper->get_meta( $current_user_id, $key, true );
×
NEW
243
                if ( ! $seen ) {
×
NEW
244
                        $this->user_helper->update_meta( $current_user_id, $key, true );
×
245
                }
NEW
246
                return $seen;
×
247
        }
248
}
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