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-notice-integration.php +53 -132 19.0 → trunk View file →
@@ -3,15 +3,13 @@
3 3 namespace Yoast\WP\SEO\Integrations\Admin;
4 4
5 5 use WPSEO_Admin_Asset_Manager;
6 6 use Yoast\WP\SEO\Conditionals\Admin_Conditional;
7 -use Yoast\WP\SEO\Conditionals\No_Conditionals;
8 -use Yoast\WP\SEO\Helpers\Indexing_Helper;
7 +use Yoast\WP\SEO\Helpers\First_Time_Configuration_Notice_Helper;
9 8 use Yoast\WP\SEO\Helpers\Options_Helper;
10 9 use Yoast\WP\SEO\Integrations\Integration_Interface;
11 10 use Yoast\WP\SEO\Presenters\Admin\Notice_Presenter;
12 11
13 -// phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded -- First time configuration simply has a lot of words.
14 12 /**
15 13 * First_Time_Configuration_Notice_Integration class
16 14 */
17 15 class First_Time_Configuration_Notice_Integration implements Integration_Interface {
@@ -23,20 +21,20 @@
23 21 */
24 22 private $options_helper;
25 23
26 24 /**
27 - * The indexing helper.
25 + * The admin asset manager.
28 26 *
29 - * @var Indexing_Helper
27 + * @var WPSEO_Admin_Asset_Manager
30 28 */
31 - private $indexing_helper;
29 + private $admin_asset_manager;
32 30
33 31 /**
34 - * The admin asset manager.
32 + * The first time configuration notice helper.
35 33 *
36 - * @var WPSEO_Admin_Asset_Manager
34 + * @var First_Time_Configuration_Notice_Helper
37 35 */
38 - private $admin_asset_manager;
36 + private $first_time_configuration_notice_helper;
39 37
40 38 /**
41 39 * {@inheritDoc}
42 40 */
@@ -46,20 +44,20 @@
46 44
47 45 /**
48 46 * First_Time_Configuration_Notice_Integration constructor.
49 47 *
50 - * @param Options_Helper $options_helper The options helper.
51 - * @param Indexing_Helper $indexing_helper The indexing helper.
52 - * @param WPSEO_Admin_Asset_Manager $admin_asset_manager The admin asset manager.
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.
53 51 */
54 52 public function __construct(
55 53 Options_Helper $options_helper,
56 - Indexing_Helper $indexing_helper,
54 + First_Time_Configuration_Notice_Helper $first_time_configuration_notice_helper,
57 55 WPSEO_Admin_Asset_Manager $admin_asset_manager
58 56 ) {
59 - $this->options_helper = $options_helper;
60 - $this->indexing_helper = $indexing_helper;
61 - $this->admin_asset_manager = $admin_asset_manager;
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;
62 60 }
63 61
64 62 /**
65 63 * {@inheritDoc}
@@ -74,8 +72,12 @@
74 72 *
75 73 * @return bool
76 74 */
77 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 + }
78 80 return $this->options_helper->set( 'dismiss_configuration_workout_notice', true );
79 81 }
80 82
81 83 /**
@@ -83,29 +85,9 @@
83 85 *
84 86 * @return bool Whether the "First-time SEO Configuration" admin notice should be displayed.
85 87 */
86 88 public function should_display_first_time_configuration_notice() {
87 - if ( ! $this->options_helper->get( 'dismiss_configuration_workout_notice', false ) === false ) {
88 - return false;
89 - }
90 -
91 - if ( ! $this->user_can_do_first_time_configuration() ) {
92 - return false;
93 - }
94 -
95 - if ( ! $this->on_wpseo_admin_page_or_dashboard() ) {
96 - return false;
97 - }
98 -
99 - if ( $this->is_first_time_configuration_finished() ) {
100 - return false;
101 - }
102 -
103 - if ( $this->options_helper->get( 'first_time_install', false ) === false ) {
104 - return false;
105 - }
106 -
107 - return ! $this->are_site_representation_name_and_logo_set() || $this->indexing_helper->get_unindexed_count() > 0;
89 + return $this->first_time_configuration_notice_helper->should_display_first_time_configuration_notice();
108 90 }
109 91
110 92 /**
111 93 * Displays an admin notice when the first-time configuration has not been finished yet.
@@ -118,21 +100,36 @@
118 100 }
119 101
120 102 $this->admin_asset_manager->enqueue_style( 'monorepo' );
121 103
122 - $notice = new Notice_Presenter(
123 - \__( 'First-time SEO configuration', 'wordpress-seo' ),
124 - \sprintf(
125 - /* translators: 1: Link start tag to the first-time configuration, 2: Yoast SEO, 3: Link closing tag. */
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#/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. */
126 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' ),
127 - '<a href="' . \esc_url( \self_admin_url( 'admin.php?page=wpseo_dashboard#top#first-time-configuration' ) ) . '">',
111 + '<a href="' . $link_url . '">',
128 112 'Yoast SEO',
129 - '</a>'
130 - ),
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,
131 128 'mirrored_fit_bubble_woman_1_optim.svg',
132 129 null,
133 130 true,
134 - 'yoast-first-time-configuration-notice'
131 + 'yoast-first-time-configuration-notice',
135 132 );
136 133
137 134 //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output from present() is considered safe.
138 135 echo $notice->present();
@@ -137,94 +134,18 @@
137 134 //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output from present() is considered safe.
138 135 echo $notice->present();
139 136
140 137 // Enable permanently dismissing the notice.
141 - echo "<script>
142 - function dismiss_first_time_configuration_notice(){
143 - var data = {
144 - 'action': 'dismiss_first_time_configuration_notice',
145 - };
146 -
147 - jQuery.post( ajaxurl, data, function( response ) {
148 - jQuery( '#yoast-first-time-configuration-notice' ).hide();
149 - });
150 - }
151 -
152 - jQuery( document ).ready( function() {
153 - jQuery( 'body' ).on( 'click', '#yoast-first-time-configuration-notice .notice-dismiss', function() {
154 - dismiss_first_time_configuration_notice();
138 + echo '<script>
139 + jQuery( document ).ready( function() {
140 + jQuery( "body" ).on( "click", "#yoast-first-time-configuration-notice .notice-dismiss", function() {
141 + jQuery( "#yoast-first-time-configuration-notice" ).hide();
142 + const data = {
143 + "action": "dismiss_first_time_configuration_notice",
144 + "nonce": "' . \esc_js( \wp_create_nonce( 'wpseo-dismiss-first-time-configuration-notice' ) ) . '"
145 + };
146 + jQuery.post( ajaxurl, data, function( response ) {});
147 + } );
155 148 } );
156 - } );
157 - </script>";
158 - }
159 -
160 - /**
161 - * Whether the user can do the first-time configuration.
162 - *
163 - * @return bool Whether the current user can do the first-time configuration.
164 - */
165 - private function user_can_do_first_time_configuration() {
166 - return \current_user_can( 'wpseo_manage_options' );
167 - }
168 -
169 - /**
170 - * Whether the user is currently visiting one of our admin pages or the WordPress dashboard.
171 - *
172 - * @return bool Whether the current page is a Yoast SEO admin page
173 - */
174 - private function on_wpseo_admin_page_or_dashboard() {
175 - $pagenow = $GLOBALS['pagenow'];
176 -
177 - // Show on the WP Dashboard.
178 - if ( $pagenow === 'index.php' ) {
179 - return true;
180 - }
181 -
182 - $page_from_get = \filter_input( \INPUT_GET, 'page' );
183 -
184 - // Show on Yoast SEO pages, with some exceptions.
185 - if ( $pagenow === 'admin.php' && \strpos( $page_from_get, 'wpseo' ) === 0 ) {
186 - $exceptions = [
187 - 'wpseo_installation_successful',
188 - 'wpseo_installation_successful_free',
189 - ];
190 -
191 - if ( ! \in_array( $page_from_get, $exceptions, true ) ) {
192 - return true;
193 - }
194 - }
195 -
196 - return false;
197 - }
198 -
199 - /**
200 - * Whether all steps of the first-time configuration have been finished.
201 - *
202 - * @return bool Whether the first-time configuration has been finished.
203 - */
204 - private function is_first_time_configuration_finished() {
205 - $configuration_finished_steps = $this->options_helper->get( 'configuration_finished_steps', [] );
206 -
207 - return \count( $configuration_finished_steps ) === 3;
208 - }
209 -
210 - /**
211 - * Whether the site representation name and logo have been set.
212 - *
213 - * @return bool Whether the site representation name and logo have been set.
214 - */
215 - private function are_site_representation_name_and_logo_set() {
216 - $company_or_person = $this->options_helper->get( 'company_or_person', '' );
217 -
218 - if ( $company_or_person === '' ) {
219 - return false;
220 - }
221 -
222 - if ( $company_or_person === 'company' ) {
223 - return ! empty( $this->options_helper->get( 'company_name' ) )
224 - && ! empty( $this->options_helper->get( 'company_logo', '' ) );
225 - }
226 -
227 - return ! empty( $this->options_helper->get( 'company_or_person_user_id' ) )
228 - && ! empty( $this->options_helper->get( 'person_logo', '' ) );
149 + </script>';
229 150 }
230 151 }