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/actions/configuration/first-time-configuration-action.php +84 -19 18.9 → trunk View file →
@@ -2,11 +2,10 @@
2 2
3 3 namespace Yoast\WP\SEO\Actions\Configuration;
4 4
5 5 use Yoast\WP\SEO\Helpers\Options_Helper;
6 -use Yoast\WP\SEO\Integrations\Admin\Social_Profiles_Helper;
6 +use Yoast\WP\SEO\Helpers\Social_Profiles_Helper;
7 7
8 -// phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded -- First time configuration simply has a lot of words.
9 8 /**
10 9 * Class First_Time_Configuration_Action.
11 10 */
12 11 class First_Time_Configuration_Action {
@@ -13,11 +12,12 @@
13 12
14 13 /**
15 14 * The fields for the site representation payload.
16 15 */
17 - const SITE_REPRESENTATION_FIELDS = [
16 + public const SITE_REPRESENTATION_FIELDS = [
18 17 'company_or_person',
19 18 'company_name',
19 + 'website_name',
20 20 'company_logo',
21 21 'company_logo_id',
22 22 'person_logo',
23 23 'person_logo_id',
@@ -57,21 +57,15 @@
57 57 *
58 58 * @return object The response object.
59 59 */
60 60 public function set_site_representation( $params ) {
61 - $failures = [];
61 + $failures = [];
62 + $old_values = $this->get_old_values( self::SITE_REPRESENTATION_FIELDS );
62 63
63 64 foreach ( self::SITE_REPRESENTATION_FIELDS as $field_name ) {
64 65 if ( isset( $params[ $field_name ] ) ) {
65 - if ( $field_name === 'description' && \current_user_can( 'manage_options' ) ) {
66 - $result = \update_option( 'blogdescription', $params['description'] );
67 - if ( ! $result && $params['description'] === \get_option( 'blogdescription' ) ) {
68 - $result = true;
69 - }
70 - }
71 - else {
72 - $result = $this->options_helper->set( $field_name, $params[ $field_name ] );
73 - }
66 + $result = $this->options_helper->set( $field_name, $params[ $field_name ] );
67 +
74 68 if ( ! $result ) {
75 69 $failures[] = $field_name;
76 70 }
77 71 }
@@ -76,8 +70,23 @@
76 70 }
77 71 }
78 72 }
79 73
74 + // Delete cached logos in the db.
75 + $this->options_helper->set( 'company_logo_meta', false );
76 + $this->options_helper->set( 'person_logo_meta', false );
77 +
78 + /**
79 + * Action: 'wpseo_post_update_site_representation' - Allows for Hiive event tracking.
80 + *
81 + * @param array $params The new values of the options.
82 + * @param array $old_values The old values of the options.
83 + * @param array $failures The options that failed to be saved.
84 + *
85 + * @internal
86 + */
87 + \do_action( 'wpseo_ftc_post_update_site_representation', $params, $old_values, $failures );
88 +
80 89 if ( \count( $failures ) === 0 ) {
81 90 return (object) [
82 91 'success' => true,
83 92 'status' => 200,
@@ -82,8 +91,9 @@
82 91 'success' => true,
83 92 'status' => 200,
84 93 ];
85 94 }
95 +
86 96 return (object) [
87 97 'success' => false,
88 98 'status' => 500,
89 99 'error' => 'Could not save some options in the database',
@@ -98,10 +108,22 @@
98 108 *
99 109 * @return object The response object.
100 110 */
101 111 public function set_social_profiles( $params ) {
102 - $failures = $this->social_profiles_helper->set_organization_social_profiles( $params );
112 + $old_values = $this->get_old_values( \array_keys( $this->social_profiles_helper->get_organization_social_profile_fields() ) );
113 + $failures = $this->social_profiles_helper->set_organization_social_profiles( $params );
103 114
115 + /**
116 + * Action: 'wpseo_post_update_social_profiles' - Allows for Hiive event tracking.
117 + *
118 + * @param array $params The new values of the options.
119 + * @param array $old_values The old values of the options.
120 + * @param array $failures The options that failed to be saved.
121 + *
122 + * @internal
123 + */
124 + \do_action( 'wpseo_ftc_post_update_social_profiles', $params, $old_values, $failures );
125 +
104 126 if ( empty( $failures ) ) {
105 127 return (object) [
106 128 'success' => true,
107 129 'status' => 200,
@@ -125,12 +147,12 @@
125 147 */
126 148 public function set_person_social_profiles( $params ) {
127 149 $social_profiles = \array_filter(
128 150 $params,
129 - function ( $key ) {
151 + static function ( $key ) {
130 152 return $key !== 'user_id';
131 153 },
132 - ARRAY_FILTER_USE_KEY
154 + \ARRAY_FILTER_USE_KEY,
133 155 );
134 156
135 157 $failures = $this->social_profiles_helper->set_person_social_profiles( $params['user_id'], $social_profiles );
136 158
@@ -139,8 +161,9 @@
139 161 'success' => true,
140 162 'status' => 200,
141 163 ];
142 164 }
165 +
143 166 return (object) [
144 167 'success' => false,
145 168 'status' => 200,
146 169 'error' => 'Could not save some options in the database',
@@ -150,9 +173,9 @@
150 173
151 174 /**
152 175 * Gets the values for the social profiles.
153 176 *
154 - * @param int $user_id the person id.
177 + * @param int $user_id The person ID.
155 178 *
156 179 * @return object The response object.
157 180 */
158 181 public function get_person_social_profiles( $user_id ) {
@@ -175,11 +198,24 @@
175 198 $success = true;
176 199 $option_value = $this->options_helper->get( 'tracking' );
177 200
178 201 if ( $option_value !== $params['tracking'] ) {
202 + $this->options_helper->set( 'toggled_tracking', true );
179 203 $success = $this->options_helper->set( 'tracking', $params['tracking'] );
180 204 }
181 205
206 + /**
207 + * Action: 'wpseo_post_update_enable_tracking' - Allows for Hiive event tracking.
208 + *
209 + * @param array $new_value The new value.
210 + * @param array $old_value The old value.
211 + * @param bool $failure Whether the option failed to be stored.
212 + *
213 + * @internal
214 + */
215 + // $success is negated to be aligned with the other two actions which pass $failures.
216 + \do_action( 'wpseo_ftc_post_update_enable_tracking', $params['tracking'], $option_value, ! $success );
217 +
182 218 if ( $success ) {
183 219 return (object) [
184 220 'success' => true,
185 221 'status' => 200,
@@ -184,8 +220,9 @@
184 220 'success' => true,
185 221 'status' => 200,
186 222 ];
187 223 }
224 +
188 225 return (object) [
189 226 'success' => false,
190 227 'status' => 500,
191 228 'error' => 'Could not save the option in the database',
@@ -199,9 +236,9 @@
199 236 *
200 237 * @return object The response object.
201 238 */
202 239 public function check_capability( $user_id ) {
203 - if ( $this->social_profiles_helper->can_edit_profile( $user_id ) ) {
240 + if ( $this->can_edit_profile( $user_id ) ) {
204 241 return (object) [
205 242 'success' => true,
206 243 'status' => 200,
207 244 ];
@@ -261,9 +298,9 @@
261 298 */
262 299 public function get_configuration_state() {
263 300 $configuration_option = $this->options_helper->get( 'configuration_finished_steps' );
264 301
265 - if ( ! is_null( $configuration_option ) ) {
302 + if ( $configuration_option !== null ) {
266 303 return (object) [
267 304 'success' => true,
268 305 'status' => 200,
269 306 'data' => $configuration_option,
@@ -274,6 +311,34 @@
274 311 'success' => false,
275 312 'status' => 500,
276 313 'error' => 'Could not get data from the database',
277 314 ];
315 + }
316 +
317 + /**
318 + * Checks if the current user has the capability to edit a specific user.
319 + *
320 + * @param int $person_id The id of the person to edit.
321 + *
322 + * @return bool
323 + */
324 + private function can_edit_profile( $person_id ) {
325 + return \current_user_can( 'edit_user', $person_id );
326 + }
327 +
328 + /**
329 + * Gets the old values for the given fields.
330 + *
331 + * @param array $fields_names The fields to get the old values for.
332 + *
333 + * @return array The old values.
334 + */
335 + private function get_old_values( array $fields_names ): array {
336 + $old_values = [];
337 +
338 + foreach ( $fields_names as $field_name ) {
339 + $old_values[ $field_name ] = $this->options_helper->get( $field_name );
340 + }
341 +
342 + return $old_values;
278 343 }
279 344 }