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

Yoast / wordpress-seo / 71db95f8070e6804205202f4e913d8bcd6292885

29 Jul 2026 02:11PM UTC coverage: 55.582% (+0.2%) from 55.427%
71db95f8070e6804205202f4e913d8bcd6292885

Pull #23509

github

web-flow
Merge 0ac425ce8 into c54064247
Pull Request #23509: Bulk editor: add in-app tour for first-time users

10641 of 18889 branches covered (56.33%)

Branch coverage included in aggregate %.

199 of 225 new or added lines in 11 files covered. (88.44%)

1 existing line in 1 file now uncovered.

40282 of 72728 relevant lines covered (55.39%)

41381.71 hits per line

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

92.42
/src/bulk-editor/user-interface/bulk-editor-integration.php
1
<?php
2

3
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
4
namespace Yoast\WP\SEO\Bulk_Editor\User_Interface;
5

6
use WPSEO_Admin_Asset_Manager;
7
use Yoast\WP\SEO\Bulk_Editor\Application\Content_Types\Content_Types_Repository;
8
use Yoast\WP\SEO\Bulk_Editor\Application\Endpoints\Endpoints_Repository;
9
use Yoast\WP\SEO\Bulk_Editor\Infrastructure\Nonces\Nonce_Repository;
10
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
11
use Yoast\WP\SEO\General\User_Interface\General_Page_Integration;
12
use Yoast\WP\SEO\Helpers\Current_Page_Helper;
13
use Yoast\WP\SEO\Helpers\Options_Helper;
14
use Yoast\WP\SEO\Helpers\Product_Helper;
15
use Yoast\WP\SEO\Helpers\Short_Link_Helper;
16
use Yoast\WP\SEO\Helpers\User_Helper;
17
use Yoast\WP\SEO\Integrations\Integration_Interface;
18

19
/**
20
 * Adds the bulk editor page to the Yoast admin menu.
21
 */
22
class Bulk_Editor_Integration implements Integration_Interface {
23

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

29
        /**
30
         * The assets name.
31
         */
32
        public const ASSETS_NAME = 'bulk-editor-page';
33

34
        /**
35
         * Holds the WPSEO_Admin_Asset_Manager.
36
         *
37
         * @var WPSEO_Admin_Asset_Manager
38
         */
39
        private $asset_manager;
40

41
        /**
42
         * Holds the Current_Page_Helper.
43
         *
44
         * @var Current_Page_Helper
45
         */
46
        private $current_page_helper;
47

48
        /**
49
         * Holds the Product_Helper.
50
         *
51
         * @var Product_Helper
52
         */
53
        private $product_helper;
54

55
        /**
56
         * Holds the Short_Link_Helper.
57
         *
58
         * @var Short_Link_Helper
59
         */
60
        private $short_link_helper;
61

62
        /**
63
         * Holds the Content_Types_Repository.
64
         *
65
         * @var Content_Types_Repository
66
         */
67
        private $content_types_repository;
68

69
        /**
70
         * Holds the Nonce_Repository.
71
         *
72
         * @var Nonce_Repository
73
         */
74
        private $nonce_repository;
75

76
        /**
77
         * Holds the Endpoints_Repository.
78
         *
79
         * @var Endpoints_Repository
80
         */
81
        private $endpoints_repository;
82

83
        /**
84
         * Holds the Options_Helper.
85
         *
86
         * @var Options_Helper
87
         */
88
        private $options_helper;
89

90
        /**
91
         * Holds the User_Helper.
92
         *
93
         * @var User_Helper
94
         */
95
        private $user_helper;
96

97
        /**
98
         * Constructs the instance.
99
         *
100
         * @param WPSEO_Admin_Asset_Manager $asset_manager            The WPSEO_Admin_Asset_Manager.
101
         * @param Current_Page_Helper       $current_page_helper      The Current_Page_Helper.
102
         * @param Product_Helper            $product_helper           The Product_Helper.
103
         * @param Short_Link_Helper         $short_link_helper        The Short_Link_Helper.
104
         * @param Content_Types_Repository  $content_types_repository The Content_Types_Repository.
105
         * @param Nonce_Repository          $nonce_repository         The Nonce_Repository.
106
         * @param Endpoints_Repository      $endpoints_repository     The Endpoints_Repository.
107
         * @param Options_Helper            $options_helper           The Options_Helper.
108
         * @param User_Helper               $user_helper              The User_Helper.
109
         */
110
        public function __construct(
2✔
111
                WPSEO_Admin_Asset_Manager $asset_manager,
112
                Current_Page_Helper $current_page_helper,
113
                Product_Helper $product_helper,
114
                Short_Link_Helper $short_link_helper,
115
                Content_Types_Repository $content_types_repository,
116
                Nonce_Repository $nonce_repository,
117
                Endpoints_Repository $endpoints_repository,
118
                Options_Helper $options_helper,
119
                User_Helper $user_helper
120
        ) {
121
                $this->asset_manager            = $asset_manager;
2✔
122
                $this->current_page_helper      = $current_page_helper;
2✔
123
                $this->product_helper           = $product_helper;
2✔
124
                $this->short_link_helper        = $short_link_helper;
2✔
125
                $this->content_types_repository = $content_types_repository;
2✔
126
                $this->nonce_repository         = $nonce_repository;
2✔
127
                $this->endpoints_repository     = $endpoints_repository;
2✔
128
                $this->options_helper           = $options_helper;
2✔
129
                $this->user_helper              = $user_helper;
2✔
130
        }
131

132
        /**
133
         * Returns the conditionals based on which this loadable should be active.
134
         *
135
         * @return array<string> The conditionals.
136
         */
137
        public static function get_conditionals() {
2✔
138
                return [ Admin_Conditional::class ];
2✔
139
        }
140

141
        /**
142
         * Initializes the integration.
143
         *
144
         * This is the place to register hooks and filters.
145
         *
146
         * @return void
147
         */
148
        public function register_hooks() {
4✔
149
                \add_filter( 'wpseo_submenu_pages', [ $this, 'add_page' ] );
4✔
150

151
                // Hide the menu item without losing the page. See remove_menu_item() for why this runs on admin_head.
152
                \add_action( 'admin_head', [ $this, 'remove_menu_item' ] );
4✔
153

154
                // Are we on our page?
155
                if ( $this->current_page_helper->get_current_yoast_seo_page() === self::PAGE ) {
4✔
156
                        \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
2✔
157
                        \add_action( 'in_admin_header', [ $this, 'remove_notices' ], \PHP_INT_MAX );
2✔
158
                }
159
        }
160

161
        /**
162
         * Removes the bulk editor's submenu item from the Yoast SEO menu while keeping the page reachable by URL.
163
         *
164
         * Runs on admin_head rather than admin_menu on purpose: by then WordPress has already resolved the page's
165
         * parent and capability (so the page stays accessible and keeps its `seo_page_wpseo_page_bulk_edit` body
166
         * class, which its styles depend on), but the menu HTML has not been rendered yet, so the item is hidden.
167
         * The page is opened from the Tools page instead of its own menu item.
168
         *
169
         * @return void
170
         */
171
        public function remove_menu_item() {
×
172
                \remove_submenu_page( 'wpseo_dashboard', self::PAGE );
×
173
        }
174

175
        /**
176
         * Adds the page to the (currently) last position in the array.
177
         *
178
         * @param array<array<string|callable|null>> $pages The pages.
179
         *
180
         * @return array<array<string|callable|null>> The pages.
181
         */
182
        public function add_page( $pages ) {
2✔
183
                $pages[] = [
2✔
184
                        'wpseo_dashboard',
2✔
185
                        '',
2✔
186
                        \__( 'Bulk editor', 'wordpress-seo' ),
2✔
187
                        'wpseo_manage_options',
2✔
188
                        self::PAGE,
2✔
189
                        [ $this, 'display_page' ],
2✔
190
                ];
2✔
191

192
                return $pages;
2✔
193
        }
194

195
        /**
196
         * Displays the page.
197
         *
198
         * @return void
199
         */
200
        public function display_page() {
2✔
201
                echo '<div id="yoast-seo-bulk-editor"></div>';
2✔
202
        }
203

204
        /**
205
         * Enqueues the assets.
206
         *
207
         * @return void
208
         */
209
        public function enqueue_assets() {
2✔
210
                // Remove the emoji script as it is incompatible with both React and any contenteditable fields.
211
                \remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
2✔
212
                $this->asset_manager->enqueue_script( self::ASSETS_NAME );
2✔
213
                $this->asset_manager->enqueue_style( self::ASSETS_NAME );
2✔
214
                $this->asset_manager->localize_script( self::ASSETS_NAME, 'wpseoBulkEditorData', $this->get_script_data() );
2✔
215
        }
216

217
        /**
218
         * Creates the script data.
219
         *
220
         * @return array<string, string|array<string, string|bool>|array<array<string, string>>> The script data.
221
         */
222
        public function get_script_data() {
2✔
223
                return [
2✔
224
                        'contentTypes'          => $this->content_types_repository->get_content_types(),
2✔
225
                        'endpoints'             => $this->endpoints_repository->get_all_endpoints()->to_array(),
2✔
226
                        // These must stay server-generated URLs: the bulk editor assigns them to window.location.href for its
227
                        // "Back to Tools" / logo navigation. If a link ever derives from request input, validate it with
228
                        // wp_validate_redirect() here before exposing it, to avoid an open redirect on the front-end.
229
                        'links'                 => [
2✔
230
                                'dashboard' => \admin_url( 'admin.php?page=' . General_Page_Integration::PAGE ),
2✔
231
                                'tools'     => \admin_url( 'admin.php?page=wpseo_tools' ),
2✔
232
                        ],
2✔
233
                        'nonce'                 => $this->nonce_repository->get_rest_nonce(),
2✔
234
                        'restRoot'              => \esc_url_raw( \rest_url() ),
2✔
235
                        'preferences'           => [
2✔
236
                                'isPremium'   => $this->product_helper->is_premium(),
2✔
237
                                'isAiEnabled' => $this->options_helper->get( 'enable_ai_generator' ) === true,
2✔
238
                                'isRtl'       => \is_rtl(),
2✔
239
                                'pluginUrl'   => \plugins_url( '', \WPSEO_FILE ),
2✔
240
                        ],
2✔
241
                        'linkParams'            => $this->short_link_helper->get_query_params(),
2✔
242
                        // Whether the first-run guided tour has already been seen, so it only shows once per user.
243
                        'optInNotificationSeen' => [
2✔
244
                                'bulk_editor_tour' => $this->is_tour_opt_in_notification_seen(),
2✔
245
                        ],
2✔
246
                ];
2✔
247
        }
248

249
        /**
250
         * Gets whether the bulk editor guided tour has been seen by the current user.
251
         *
252
         * @return bool True when the tour has been seen, false otherwise.
253
         */
NEW
254
        private function is_tour_opt_in_notification_seen(): bool {
×
NEW
255
                $current_user_id = $this->user_helper->get_current_user_id();
×
256

NEW
257
                return (bool) $this->user_helper->get_meta( $current_user_id, '_yoast_wpseo_bulk_editor_tour_opt_in_notification_seen', true );
×
258
        }
259

260
        /**
261
         * Removes all current WP notices.
262
         *
263
         * @return void
264
         */
265
        public function remove_notices() {
2✔
266
                \remove_all_actions( 'admin_notices' );
2✔
267
                \remove_all_actions( 'user_admin_notices' );
2✔
268
                \remove_all_actions( 'network_admin_notices' );
2✔
269
                \remove_all_actions( 'all_admin_notices' );
2✔
270
        }
271
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc