From 0be2bfcb8af11e8d39ab72b98c8b250315900ca0 Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Tue, 19 Sep 2023 17:07:33 +0200 Subject: [PATCH 01/38] Move steps names here and introduce HIIVE_STEPS_NAMES --- .../tailwind-components/steps/constants.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 packages/js/src/first-time-configuration/tailwind-components/steps/constants.js diff --git a/packages/js/src/first-time-configuration/tailwind-components/steps/constants.js b/packages/js/src/first-time-configuration/tailwind-components/steps/constants.js new file mode 100644 index 00000000000..b21c1181f15 --- /dev/null +++ b/packages/js/src/first-time-configuration/tailwind-components/steps/constants.js @@ -0,0 +1,12 @@ +export const STEPS = { + optimizeSeoData: "optimizeSeoData", + siteRepresentation: "siteRepresentation", + socialProfiles: "socialProfiles", + personalPreferences: "personalPreferences", +}; +export const HIIVE_STEPS_NAMES = { + [ STEPS.optimizeSeoData ]: "data optimization", + [ STEPS.siteRepresentation ]: "Site representation", + [ STEPS.socialProfiles ]: "social profiles", + [ STEPS.personalPreferences ]: "personal preferences", +}; From 9b61693da82e40f3481fc22c452c0d84399ee551 Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Tue, 19 Sep 2023 17:08:11 +0200 Subject: [PATCH 02/38] Refactor to pass stepId and build id later in the buttons --- .../first-time-configuration-steps.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/packages/js/src/first-time-configuration/first-time-configuration-steps.js b/packages/js/src/first-time-configuration/first-time-configuration-steps.js index 9c6f937366a..a55f26c7caf 100644 --- a/packages/js/src/first-time-configuration/first-time-configuration-steps.js +++ b/packages/js/src/first-time-configuration/first-time-configuration-steps.js @@ -14,13 +14,7 @@ import IndexationStep from "./tailwind-components/steps/indexation/indexation-st import SiteRepresentationStep from "./tailwind-components/steps/site-representation/site-representation-step"; import PersonalPreferencesStep from "./tailwind-components/steps/personal-preferences/personal-preferences-step"; import FinishStep from "./tailwind-components/steps/finish/finish-step"; - -const STEPS = { - optimizeSeoData: "optimizeSeoData", - siteRepresentation: "siteRepresentation", - socialProfiles: "socialProfiles", - personalPreferences: "personalPreferences", -}; +import { STEPS } from "./tailwind-components/steps/constants"; /* eslint-disable complexity */ @@ -501,7 +495,7 @@ export default function FirstTimeConfigurationSteps() { isFinished={ isIndexationStepFinished } > Date: Tue, 19 Sep 2023 17:08:33 +0200 Subject: [PATCH 03/38] Refactor to build buttons ids and hiive attributes --- .../configuration-stepper-buttons.js | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js b/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js index 91b0d3e0dad..da5da67d8b0 100644 --- a/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js +++ b/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js @@ -4,6 +4,7 @@ import PropTypes from "prop-types"; import { Step } from "./stepper"; import { stepperTimingClasses } from "../stepper-helper"; import classNames from "classnames"; +import { HIIVE_STEPS_NAMES } from "../tailwind-components/steps/constants"; /** * A ContinueButton that always goes to the next step. @@ -13,11 +14,13 @@ import classNames from "classnames"; * * @returns {WPElement} The ContinueButton, that always goes to the next step. */ -export function ContinueButton( { beforeGo, children, additionalClasses, ...restProps } ) { +export function ContinueButton( { stepId, beforeGo, children, additionalClasses, ...restProps } ) { return ( { children } @@ -25,6 +28,7 @@ export function ContinueButton( { beforeGo, children, additionalClasses, ...rest } ContinueButton.propTypes = { + stepId: PropTypes.string.isRequired, additionalClasses: PropTypes.string, beforeGo: PropTypes.func, children: PropTypes.node, @@ -44,13 +48,14 @@ ContinueButton.defaultProps = { * * @returns {WPElement} The EditButton, that always goes to the step it is placed in. */ -export function EditButton( { beforeGo, isVisible, children, additionalClasses, ...restProps } ) { +export function EditButton( { stepId, beforeGo, isVisible, children, additionalClasses, ...restProps } ) { const transitionClasses = `yst-transition-opacity ${stepperTimingClasses.slideDuration} yst-ease-out ${ isVisible ? "yst-opacity-100" : `${stepperTimingClasses.delayBeforeOpening} yst-opacity-0 yst-pointer-events-none yst-hidden` }`; return ( { children } @@ -65,6 +71,7 @@ export function EditButton( { beforeGo, isVisible, children, additionalClasses, } EditButton.propTypes = { + stepId: PropTypes.string.isRequired, additionalClasses: PropTypes.string, isVisible: PropTypes.bool, beforeGo: PropTypes.func, @@ -123,8 +130,22 @@ BackButton.defaultProps = { */ export function StepButtons( { stepId, beforeContinue, continueLabel, beforeBack, backLabel } ) { return
- { continueLabel } - { backLabel } + + { continueLabel } + + + { backLabel } +
; } @@ -165,7 +186,12 @@ export function ConfigurationStepButtons( { stepId, stepperFinishedOnce, saveFun } ); if ( stepperFinishedOnce ) { - return + return { __( "Save changes", "wordpress-seo" ) } ; } From 42ec4c21d3ed50d553f9e0591edd5bb693151ac2 Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Tue, 19 Sep 2023 17:08:54 +0200 Subject: [PATCH 04/38] Add hiive data attributes --- .../tailwind-components/base/image-select.js | 1 + .../tailwind-components/steps/finish/finish-step.js | 2 ++ .../tailwind-components/steps/indexation/indexation.js | 1 + .../steps/personal-preferences/newsletter-signup.js | 2 ++ .../steps/social-profiles/social-field-array.js | 1 + 5 files changed, 7 insertions(+) diff --git a/packages/js/src/first-time-configuration/tailwind-components/base/image-select.js b/packages/js/src/first-time-configuration/tailwind-components/base/image-select.js index e6e1632b913..0a2206c672e 100644 --- a/packages/js/src/first-time-configuration/tailwind-components/base/image-select.js +++ b/packages/js/src/first-time-configuration/tailwind-components/base/image-select.js @@ -79,6 +79,7 @@ export default function ImageSelect( { id={ url ? id + "__replace-image" : id + "__select-image" } className="yst-button yst-button yst-button--secondary yst-mr-2" onClick={ onSelectImageClick } + data-hiive-event-name="clicked_select_image" > { url ? __( "Replace image", "admin-ui" ) : __( "Select image", "admin-ui" ) } diff --git a/packages/js/src/first-time-configuration/tailwind-components/steps/finish/finish-step.js b/packages/js/src/first-time-configuration/tailwind-components/steps/finish/finish-step.js index ba305a1b1f7..427cd5e3cc6 100644 --- a/packages/js/src/first-time-configuration/tailwind-components/steps/finish/finish-step.js +++ b/packages/js/src/first-time-configuration/tailwind-components/steps/finish/finish-step.js @@ -39,6 +39,7 @@ export default function FinishStep() { id="button-webinar-seo-dashboard" href={ webinarIntroFirstTimeConfigUrl } target="_blank" + data-hiive-event-name="clicked_to_onboarding_page" > { sprintf( /* translators: 1: Yoast SEO. */ @@ -51,6 +52,7 @@ export default function FinishStep() { { __( "Or go to your SEO dashboard", "wordpress-seo" ) } diff --git a/packages/js/src/first-time-configuration/tailwind-components/steps/indexation/indexation.js b/packages/js/src/first-time-configuration/tailwind-components/steps/indexation/indexation.js index bf5bcbb3792..68d15cfabbc 100644 --- a/packages/js/src/first-time-configuration/tailwind-components/steps/indexation/indexation.js +++ b/packages/js/src/first-time-configuration/tailwind-components/steps/indexation/indexation.js @@ -284,6 +284,7 @@ class Indexation extends Component { className="yst-button yst-button--secondary" onClick={ this.startIndexing } id="indexation-data-optimization" + data-hiive-event-name={ "clicked_start_data_optimization" } > { __( "Start SEO data optimization", "wordpress-seo" ) } ; diff --git a/packages/js/src/first-time-configuration/tailwind-components/steps/personal-preferences/newsletter-signup.js b/packages/js/src/first-time-configuration/tailwind-components/steps/personal-preferences/newsletter-signup.js index b81f2e1f7bf..9adad97293a 100644 --- a/packages/js/src/first-time-configuration/tailwind-components/steps/personal-preferences/newsletter-signup.js +++ b/packages/js/src/first-time-configuration/tailwind-components/steps/personal-preferences/newsletter-signup.js @@ -123,6 +123,8 @@ export function NewsletterSignup( { gdprLink } ) { className="yst-button yst-button--primary yst-h-[45px] yst-items-center yst-mt-[27.5px] yst-shrink-0" onClick={ onSignUpClick } disabled={ signUpState === "loading" } + data-hiive-event-name="clicked_signup | personal preferences" + > { __( "Sign up!", "wordpress-seo" ) } diff --git a/packages/js/src/first-time-configuration/tailwind-components/steps/social-profiles/social-field-array.js b/packages/js/src/first-time-configuration/tailwind-components/steps/social-profiles/social-field-array.js index ce9719814e7..7160a2b9ade 100644 --- a/packages/js/src/first-time-configuration/tailwind-components/steps/social-profiles/social-field-array.js +++ b/packages/js/src/first-time-configuration/tailwind-components/steps/social-profiles/social-field-array.js @@ -61,6 +61,7 @@ const SocialFieldArray = ( { items, onAddProfile, onRemoveProfile, onChangeProfi id="add-profile" className="yst-button yst-button--secondary yst-items-center yst-mt-8" onClick={ onAddProfile } + data-hiive-event-name="clicked_add_profile" > { addButtonChildren } From 04b6ccabe5242217547d1a789486af050ad28161 Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Fri, 22 Sep 2023 17:00:52 +0200 Subject: [PATCH 05/38] Add filters to trigger event dispatching --- .../first-time-configuration-action.php | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/actions/configuration/first-time-configuration-action.php b/src/actions/configuration/first-time-configuration-action.php index fc04bab966e..83494e80123 100644 --- a/src/actions/configuration/first-time-configuration-action.php +++ b/src/actions/configuration/first-time-configuration-action.php @@ -59,6 +59,7 @@ public function __construct( Options_Helper $options_helper, Social_Profiles_Hel */ public function set_site_representation( $params ) { $failures = []; + $old_values = $this->get_site_representation_old_values(); foreach ( self::SITE_REPRESENTATION_FIELDS as $field_name ) { if ( isset( $params[ $field_name ] ) ) { @@ -80,7 +81,9 @@ public function set_site_representation( $params ) { // Delete cached logos in the db. $this->options_helper->set( 'company_logo_meta', false ); $this->options_helper->set( 'person_logo_meta', false ); - + + \apply_filters( 'wpseo_post_update_site_representation', $params, $old_values, $failures ); + if ( \count( $failures ) === 0 ) { return (object) [ 'success' => true, @@ -105,6 +108,9 @@ public function set_site_representation( $params ) { */ public function set_social_profiles( $params ) { $failures = $this->social_profiles_helper->set_organization_social_profiles( $params ); + $old_values = $this->get_social_profiles_old_values(); + + \apply_filters( 'wpseo_post_update_social_profiles', $params, $old_values, $failures ); if ( empty( $failures ) ) { return (object) [ @@ -186,6 +192,8 @@ public function set_enable_tracking( $params ) { $success = $this->options_helper->set( 'tracking', $params['tracking'] ); } + \apply_filters( 'wpseo_post_update_enable_tracking', $params['tracking'], $option_value, $success ); + if ( $success ) { return (object) [ 'success' => true, @@ -295,4 +303,27 @@ public function get_configuration_state() { private function can_edit_profile( $person_id ) { return \current_user_can( 'edit_user', $person_id ); } + + private function get_site_representation_old_values() : array { + $old_values = []; + foreach ( self::SITE_REPRESENTATION_FIELDS as $field_name ) { + if ( $field_name === 'description' ) { + continue; + } + + $old_values[ $field_name ] = $this->options_helper->get( $field_name ); + } + + return $old_values; + } + + private function get_social_profiles_old_values() : array { + $social_profiles_fields = \array_keys( $this->social_profiles_helper->get_organization_social_profile_fields() ); + $old_values = []; + foreach ( $social_profiles_fields as $field_name ) { + $old_values[ $field_name ] = $this->options_helper->get( $field_name ); + } + + return $old_values; + } } From 6f57b119579af2791b2ce72d355e94548687e55d Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Mon, 25 Sep 2023 12:30:18 +0200 Subject: [PATCH 06/38] Refactor method to fetch old values. Add a mapping function to change param names --- .../first-time-configuration-action.php | 66 ++++++++++++++----- 1 file changed, 50 insertions(+), 16 deletions(-) diff --git a/src/actions/configuration/first-time-configuration-action.php b/src/actions/configuration/first-time-configuration-action.php index 83494e80123..994d784ca4c 100644 --- a/src/actions/configuration/first-time-configuration-action.php +++ b/src/actions/configuration/first-time-configuration-action.php @@ -59,7 +59,12 @@ public function __construct( Options_Helper $options_helper, Social_Profiles_Hel */ public function set_site_representation( $params ) { $failures = []; - $old_values = $this->get_site_representation_old_values(); + $old_values = $this->get_old_values( self::SITE_REPRESENTATION_FIELDS ); + + // This field seems to be not used anymore. + $old_values = \array_filter( $old_values, static function( $key, $value ) { + return $key !== 'description'; + } ); foreach ( self::SITE_REPRESENTATION_FIELDS as $field_name ) { if ( isset( $params[ $field_name ] ) ) { @@ -82,7 +87,11 @@ public function set_site_representation( $params ) { $this->options_helper->set( 'company_logo_meta', false ); $this->options_helper->set( 'person_logo_meta', false ); - \apply_filters( 'wpseo_post_update_site_representation', $params, $old_values, $failures ); + \do_action( 'wpseo_post_update_site_representation', + $this->map_social_profile_param_names_to_hiive_names( $params ), + $this->map_social_profile_param_names_to_hiive_names ( $old_values ), + $this->map_social_profile_param_names_to_hiive_names ( $failures ) + ); if ( \count( $failures ) === 0 ) { return (object) [ @@ -108,9 +117,9 @@ public function set_site_representation( $params ) { */ public function set_social_profiles( $params ) { $failures = $this->social_profiles_helper->set_organization_social_profiles( $params ); - $old_values = $this->get_social_profiles_old_values(); + $old_values = $this->get_old_values( \array_keys( $this->social_profiles_helper->get_organization_social_profile_fields() ) ); - \apply_filters( 'wpseo_post_update_social_profiles', $params, $old_values, $failures ); + \do_action( 'wpseo_post_update_social_profiles', $params, $old_values, $failures ); if ( empty( $failures ) ) { return (object) [ @@ -192,7 +201,7 @@ public function set_enable_tracking( $params ) { $success = $this->options_helper->set( 'tracking', $params['tracking'] ); } - \apply_filters( 'wpseo_post_update_enable_tracking', $params['tracking'], $option_value, $success ); + \do_action( 'wpseo_post_update_enable_tracking', $params['tracking'], $option_value, $success ); if ( $success ) { return (object) [ @@ -304,26 +313,51 @@ private function can_edit_profile( $person_id ) { return \current_user_can( 'edit_user', $person_id ); } - private function get_site_representation_old_values() : array { + /** + * Gets the old values for the given fields. + * + * @param array $fields_names The fields to get the old values for. + * + * @return array The old values. + */ + private function get_old_values( $fields_names ) : array { $old_values = []; - foreach ( self::SITE_REPRESENTATION_FIELDS as $field_name ) { - if ( $field_name === 'description' ) { - continue; - } + foreach ( $fields_names as $field_name ) { $old_values[ $field_name ] = $this->options_helper->get( $field_name ); } return $old_values; } - private function get_social_profiles_old_values() : array { - $social_profiles_fields = \array_keys( $this->social_profiles_helper->get_organization_social_profile_fields() ); - $old_values = []; - foreach ( $social_profiles_fields as $field_name ) { - $old_values[ $field_name ] = $this->options_helper->get( $field_name ); + /** + * Maps the param names to the names used for Hiive events tracking. + * + * @param array $params The params to map. + * + * @return array The mapped params. + */ + private function map_social_profile_param_names_to_hiive_names( $params ) { + $skip_fields = [ 'company_logo_id', 'person_logo_id' ]; + $map= [ + 'company_or_person' => 'site_representation', + 'company_name' => 'organization_name', + 'company_logo' => 'organization_logo', + 'person_logo' => 'logo', + 'company_or_person_user_id' => 'name', + 'website_name' => 'website_name', + + ]; + $mapped_params = []; + + foreach( $params as $param_name => $param_value ) { + if ( \in_array( $param_name, $skip_fields, true ) ) { + continue; + } + $new_name = $map[ $param_name ]; + $mapped_params[ $new_name ] = $param_value; } - return $old_values; + return $mapped_params; } } From 8b14974b607429e673bcd6e2e5161290397bc0e1 Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Mon, 25 Sep 2023 15:49:51 +0200 Subject: [PATCH 07/38] Add two new events --- packages/js/src/installation-success.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/js/src/installation-success.js b/packages/js/src/installation-success.js index e03dae47db8..5d01b6c1322 100644 --- a/packages/js/src/installation-success.js +++ b/packages/js/src/installation-success.js @@ -98,6 +98,7 @@ function InstallationSuccessPage() { id="installation-successful-configuration-link" href={ window.wpseoInstallationSuccess.firstTimeConfigurationUrl } className="yst-inline-flex yst-items-center yst-w-full yst-justify-center yst-no-underline yst-px-6 yst-py-3 yst-border yst-border-transparent yst-text-base yst-font-medium yst-rounded-md yst-shadow-none yst-text-primary-500 yst-bg-white hover:yst-bg-gray-50 focus:yst-outline-none focus:yst-ring-2 focus:yst-ring-offset-2 focus:yst-ring-white yst-ring-offset-2 yst-ring-offset-primary-500" + data-hiive-event-name="clicked_start_first_time_configuration" > { __( "Start first-time configuration!", "wordpress-seo" ) } - + { /* translators: %s expands to ' »'. */ sprintf( __( "Skip%s", "wordpress-seo" ), " »" ) From 9bb9a87184d237e349fb382166013ca86e5e2e5d Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Mon, 25 Sep 2023 15:50:15 +0200 Subject: [PATCH 08/38] Changed hook param value --- src/actions/configuration/first-time-configuration-action.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/actions/configuration/first-time-configuration-action.php b/src/actions/configuration/first-time-configuration-action.php index 994d784ca4c..6f2900abe1d 100644 --- a/src/actions/configuration/first-time-configuration-action.php +++ b/src/actions/configuration/first-time-configuration-action.php @@ -201,7 +201,8 @@ public function set_enable_tracking( $params ) { $success = $this->options_helper->set( 'tracking', $params['tracking'] ); } - \do_action( 'wpseo_post_update_enable_tracking', $params['tracking'], $option_value, $success ); + // $success is negated to be aligned with the other two actions which pass $failures. + \do_action( 'wpseo_post_update_enable_tracking', $params['tracking'], $option_value, ! $success ); if ( $success ) { return (object) [ From 7a39acd571f13f5de66d8240bf92e554003ed518 Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Mon, 25 Sep 2023 16:03:03 +0200 Subject: [PATCH 09/38] Add hooks documentation --- .../first-time-configuration-action.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/actions/configuration/first-time-configuration-action.php b/src/actions/configuration/first-time-configuration-action.php index 6f2900abe1d..1e558407d60 100644 --- a/src/actions/configuration/first-time-configuration-action.php +++ b/src/actions/configuration/first-time-configuration-action.php @@ -87,6 +87,13 @@ public function set_site_representation( $params ) { $this->options_helper->set( 'company_logo_meta', false ); $this->options_helper->set( 'person_logo_meta', false ); + /** + * Action: 'wpseo_post_update_site_representation' - Allows for Hiive event tracking. + * + * @api array The options new values. + * @api array The options old values. + * @api array The options that failed to be saved. + */ \do_action( 'wpseo_post_update_site_representation', $this->map_social_profile_param_names_to_hiive_names( $params ), $this->map_social_profile_param_names_to_hiive_names ( $old_values ), @@ -119,6 +126,13 @@ public function set_social_profiles( $params ) { $failures = $this->social_profiles_helper->set_organization_social_profiles( $params ); $old_values = $this->get_old_values( \array_keys( $this->social_profiles_helper->get_organization_social_profile_fields() ) ); + /** + * Action: 'wpseo_post_update_social_profiles' - Allows for Hiive event tracking. + * + * @api array The options new values. + * @api array The options old values. + * @api array The options that failed to be saved. + */ \do_action( 'wpseo_post_update_social_profiles', $params, $old_values, $failures ); if ( empty( $failures ) ) { @@ -201,6 +215,13 @@ public function set_enable_tracking( $params ) { $success = $this->options_helper->set( 'tracking', $params['tracking'] ); } + /** + * Action: 'wpseo_post_update_enable_tracking' - Allows for Hiive event tracking. + * + * @api array The new value. + * @api array The old value. + * @api bool Whether the option failed to be stored. + */ // $success is negated to be aligned with the other two actions which pass $failures. \do_action( 'wpseo_post_update_enable_tracking', $params['tracking'], $option_value, ! $success ); From 0041fb2ef3030e7e5afc5a9960caa54c11a1de67 Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Mon, 25 Sep 2023 16:42:39 +0200 Subject: [PATCH 10/38] Fix cs --- .../first-time-configuration-action.php | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/actions/configuration/first-time-configuration-action.php b/src/actions/configuration/first-time-configuration-action.php index 1e558407d60..cb01e830261 100644 --- a/src/actions/configuration/first-time-configuration-action.php +++ b/src/actions/configuration/first-time-configuration-action.php @@ -58,13 +58,17 @@ public function __construct( Options_Helper $options_helper, Social_Profiles_Hel * @return object The response object. */ public function set_site_representation( $params ) { - $failures = []; + $failures = []; $old_values = $this->get_old_values( self::SITE_REPRESENTATION_FIELDS ); // This field seems to be not used anymore. - $old_values = \array_filter( $old_values, static function( $key, $value ) { - return $key !== 'description'; - } ); + $old_values = \array_filter( + $old_values, + static function( $key ) { + return $key !== 'description'; + }, + \ARRAY_FILTER_USE_KEY + ); foreach ( self::SITE_REPRESENTATION_FIELDS as $field_name ) { if ( isset( $params[ $field_name ] ) ) { @@ -86,7 +90,7 @@ public function set_site_representation( $params ) { // Delete cached logos in the db. $this->options_helper->set( 'company_logo_meta', false ); $this->options_helper->set( 'person_logo_meta', false ); - + /** * Action: 'wpseo_post_update_site_representation' - Allows for Hiive event tracking. * @@ -94,12 +98,13 @@ public function set_site_representation( $params ) { * @api array The options old values. * @api array The options that failed to be saved. */ - \do_action( 'wpseo_post_update_site_representation', + \do_action( + 'wpseo_post_update_site_representation', $this->map_social_profile_param_names_to_hiive_names( $params ), - $this->map_social_profile_param_names_to_hiive_names ( $old_values ), - $this->map_social_profile_param_names_to_hiive_names ( $failures ) + $this->map_social_profile_param_names_to_hiive_names( $old_values ), + $this->map_social_profile_param_names_to_hiive_names( $failures ) ); - + if ( \count( $failures ) === 0 ) { return (object) [ 'success' => true, @@ -123,7 +128,7 @@ public function set_site_representation( $params ) { * @return object The response object. */ public function set_social_profiles( $params ) { - $failures = $this->social_profiles_helper->set_organization_social_profiles( $params ); + $failures = $this->social_profiles_helper->set_organization_social_profiles( $params ); $old_values = $this->get_old_values( \array_keys( $this->social_profiles_helper->get_organization_social_profile_fields() ) ); /** @@ -348,7 +353,7 @@ private function get_old_values( $fields_names ) : array { foreach ( $fields_names as $field_name ) { $old_values[ $field_name ] = $this->options_helper->get( $field_name ); } - + return $old_values; } @@ -361,22 +366,22 @@ private function get_old_values( $fields_names ) : array { */ private function map_social_profile_param_names_to_hiive_names( $params ) { $skip_fields = [ 'company_logo_id', 'person_logo_id' ]; - $map= [ + $map = [ 'company_or_person' => 'site_representation', 'company_name' => 'organization_name', 'company_logo' => 'organization_logo', 'person_logo' => 'logo', 'company_or_person_user_id' => 'name', 'website_name' => 'website_name', - + ]; $mapped_params = []; - foreach( $params as $param_name => $param_value ) { + foreach ( $params as $param_name => $param_value ) { if ( \in_array( $param_name, $skip_fields, true ) ) { continue; } - $new_name = $map[ $param_name ]; + $new_name = $map[ $param_name ]; $mapped_params[ $new_name ] = $param_value; } From 805aec5f2e425901d287e6c7bffe9ab4eaa77465 Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Tue, 26 Sep 2023 11:56:01 +0200 Subject: [PATCH 11/38] Move Hiive-specific code to Newfold data module plugin --- .../first-time-configuration-action.php | 38 +------------------ 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/src/actions/configuration/first-time-configuration-action.php b/src/actions/configuration/first-time-configuration-action.php index cb01e830261..8a7d2345422 100644 --- a/src/actions/configuration/first-time-configuration-action.php +++ b/src/actions/configuration/first-time-configuration-action.php @@ -98,12 +98,7 @@ static function( $key ) { * @api array The options old values. * @api array The options that failed to be saved. */ - \do_action( - 'wpseo_post_update_site_representation', - $this->map_social_profile_param_names_to_hiive_names( $params ), - $this->map_social_profile_param_names_to_hiive_names( $old_values ), - $this->map_social_profile_param_names_to_hiive_names( $failures ) - ); + \do_action( 'wpseo_post_update_site_representation', $params, $old_values, $failures ); if ( \count( $failures ) === 0 ) { return (object) [ @@ -356,35 +351,4 @@ private function get_old_values( $fields_names ) : array { return $old_values; } - - /** - * Maps the param names to the names used for Hiive events tracking. - * - * @param array $params The params to map. - * - * @return array The mapped params. - */ - private function map_social_profile_param_names_to_hiive_names( $params ) { - $skip_fields = [ 'company_logo_id', 'person_logo_id' ]; - $map = [ - 'company_or_person' => 'site_representation', - 'company_name' => 'organization_name', - 'company_logo' => 'organization_logo', - 'person_logo' => 'logo', - 'company_or_person_user_id' => 'name', - 'website_name' => 'website_name', - - ]; - $mapped_params = []; - - foreach ( $params as $param_name => $param_value ) { - if ( \in_array( $param_name, $skip_fields, true ) ) { - continue; - } - $new_name = $map[ $param_name ]; - $mapped_params[ $new_name ] = $param_value; - } - - return $mapped_params; - } } From 67da3e93de0bca9a7d2f752b0ddacd42ef2a6ec2 Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Tue, 26 Sep 2023 11:56:06 +0200 Subject: [PATCH 12/38] Fix tests --- .../first-time-configuration-action-test.php | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/unit/actions/configuration/first-time-configuration-action-test.php b/tests/unit/actions/configuration/first-time-configuration-action-test.php index daf5fb367a1..0fc22637003 100644 --- a/tests/unit/actions/configuration/first-time-configuration-action-test.php +++ b/tests/unit/actions/configuration/first-time-configuration-action-test.php @@ -87,6 +87,10 @@ public function test_set_site_representation( $params, $times, $yoast_options_re ->times( $times ) ->andReturn( ...$yoast_options_results ); + $this->options_helper + ->expects( 'get' ) + ->times( sizeof( $this->instance::SITE_REPRESENTATION_FIELDS) ); + Monkey\Functions\expect( 'current_user_can' ) ->with( 'manage_options' ) ->andReturnTrue(); @@ -197,7 +201,7 @@ public function site_representation_provider() { * @param array $set_profiles_results The expected results for set_organization_social_profiles(). * @param object $expected The expected result object. */ - public function test_set_social_profiles( $set_profiles_results, $expected ) { + public function test_set_social_profiles( $set_profiles_results, $get_profiles_results, $expected ) { $params = [ 'param1', 'param2', @@ -209,6 +213,15 @@ public function test_set_social_profiles( $set_profiles_results, $expected ) { ->once() ->andReturn( $set_profiles_results ); + $this->social_profiles_helper + ->expects( 'get_organization_social_profile_fields' ) + ->once() + ->andReturn( $get_profiles_results ); + + $this->options_helper + ->expects( 'get' ) + ->times( sizeof( $get_profiles_results ) ); + $this->assertEquals( $expected, $this->instance->set_social_profiles( $params ) @@ -223,6 +236,11 @@ public function test_set_social_profiles( $set_profiles_results, $expected ) { public function social_profiles_provider() { $success_all = [ 'set_profiles_results' => [], + 'get_profiles_results' => [ + 'facebook_site' => 'get_non_valid_url', + 'twitter_site' => 'get_non_valid_twitter', + 'other_social_urls' => 'get_non_valid_url_array' + ], 'expected' => (object) [ 'success' => true, 'status' => 200, @@ -231,6 +249,11 @@ public function social_profiles_provider() { $success_some = [ 'set_profiles_results' => [ 'param1' ], + 'get_profiles_results' => [ + 'facebook_site' => 'get_non_valid_url', + 'twitter_site' => 'get_non_valid_twitter', + 'other_social_urls' => 'get_non_valid_url_array' + ], 'expected' => (object) [ 'success' => false, 'status' => 200, @@ -241,6 +264,11 @@ public function social_profiles_provider() { $success_none = [ 'yoast_options_results' => [ 'param1', 'param2' ], + 'get_profiles_results' => [ + 'facebook_site' => 'get_non_valid_url', + 'twitter_site' => 'get_non_valid_twitter', + 'other_social_urls' => 'get_non_valid_url_array' + ], 'expected' => (object) [ 'success' => false, 'status' => 200, From 63659a623bad850756cd6c0de102c9a6aebae6a3 Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Tue, 26 Sep 2023 12:09:47 +0200 Subject: [PATCH 13/38] Fix cs --- .../first-time-configuration-action-test.php | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/unit/actions/configuration/first-time-configuration-action-test.php b/tests/unit/actions/configuration/first-time-configuration-action-test.php index 0fc22637003..15920fd5e4f 100644 --- a/tests/unit/actions/configuration/first-time-configuration-action-test.php +++ b/tests/unit/actions/configuration/first-time-configuration-action-test.php @@ -9,6 +9,8 @@ use Yoast\WP\SEO\Helpers\Social_Profiles_Helper; use Yoast\WP\SEO\Tests\Unit\TestCase; +use function parallel\count; + /** * Class First_Time_Configuration_Action_Test * @@ -88,8 +90,8 @@ public function test_set_site_representation( $params, $times, $yoast_options_re ->andReturn( ...$yoast_options_results ); $this->options_helper - ->expects( 'get' ) - ->times( sizeof( $this->instance::SITE_REPRESENTATION_FIELDS) ); + ->expects( 'get' ) + ->times( count( $this->instance::SITE_REPRESENTATION_FIELDS ) ); Monkey\Functions\expect( 'current_user_can' ) ->with( 'manage_options' ) @@ -199,6 +201,7 @@ public function site_representation_provider() { * @dataProvider social_profiles_provider * * @param array $set_profiles_results The expected results for set_organization_social_profiles(). + * @param array $get_profiles_results The expected results for get_organization_social_profile_fields(). * @param object $expected The expected result object. */ public function test_set_social_profiles( $set_profiles_results, $get_profiles_results, $expected ) { @@ -214,13 +217,13 @@ public function test_set_social_profiles( $set_profiles_results, $get_profiles_r ->andReturn( $set_profiles_results ); $this->social_profiles_helper - ->expects( 'get_organization_social_profile_fields' ) - ->once() - ->andReturn( $get_profiles_results ); + ->expects( 'get_organization_social_profile_fields' ) + ->once() + ->andReturn( $get_profiles_results ); $this->options_helper - ->expects( 'get' ) - ->times( sizeof( $get_profiles_results ) ); + ->expects( 'get' ) + ->times( count( $get_profiles_results ) ); $this->assertEquals( $expected, @@ -239,7 +242,7 @@ public function social_profiles_provider() { 'get_profiles_results' => [ 'facebook_site' => 'get_non_valid_url', 'twitter_site' => 'get_non_valid_twitter', - 'other_social_urls' => 'get_non_valid_url_array' + 'other_social_urls' => 'get_non_valid_url_array', ], 'expected' => (object) [ 'success' => true, @@ -252,7 +255,7 @@ public function social_profiles_provider() { 'get_profiles_results' => [ 'facebook_site' => 'get_non_valid_url', 'twitter_site' => 'get_non_valid_twitter', - 'other_social_urls' => 'get_non_valid_url_array' + 'other_social_urls' => 'get_non_valid_url_array', ], 'expected' => (object) [ 'success' => false, @@ -264,10 +267,10 @@ public function social_profiles_provider() { $success_none = [ 'yoast_options_results' => [ 'param1', 'param2' ], - 'get_profiles_results' => [ + 'get_profiles_results' => [ 'facebook_site' => 'get_non_valid_url', 'twitter_site' => 'get_non_valid_twitter', - 'other_social_urls' => 'get_non_valid_url_array' + 'other_social_urls' => 'get_non_valid_url_array', ], 'expected' => (object) [ 'success' => false, From 6c3064fb37f9239d3672bbbba80af88aaa999f3d Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Tue, 26 Sep 2023 13:52:40 +0200 Subject: [PATCH 14/38] Fix inwanted import --- .../configuration/first-time-configuration-action-test.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/unit/actions/configuration/first-time-configuration-action-test.php b/tests/unit/actions/configuration/first-time-configuration-action-test.php index 15920fd5e4f..c3ac5358ded 100644 --- a/tests/unit/actions/configuration/first-time-configuration-action-test.php +++ b/tests/unit/actions/configuration/first-time-configuration-action-test.php @@ -9,8 +9,6 @@ use Yoast\WP\SEO\Helpers\Social_Profiles_Helper; use Yoast\WP\SEO\Tests\Unit\TestCase; -use function parallel\count; - /** * Class First_Time_Configuration_Action_Test * @@ -91,7 +89,7 @@ public function test_set_site_representation( $params, $times, $yoast_options_re $this->options_helper ->expects( 'get' ) - ->times( count( $this->instance::SITE_REPRESENTATION_FIELDS ) ); + ->times( \count( $this->instance::SITE_REPRESENTATION_FIELDS ) ); Monkey\Functions\expect( 'current_user_can' ) ->with( 'manage_options' ) @@ -223,7 +221,7 @@ public function test_set_social_profiles( $set_profiles_results, $get_profiles_r $this->options_helper ->expects( 'get' ) - ->times( count( $get_profiles_results ) ); + ->times( \count( $get_profiles_results ) ); $this->assertEquals( $expected, From d8c0dd950e4bfa7e4ee4ff51349ba4000b8dc19f Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Fri, 6 Oct 2023 09:54:10 +0200 Subject: [PATCH 15/38] Fixed capitalisation --- .../tailwind-components/steps/constants.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/src/first-time-configuration/tailwind-components/steps/constants.js b/packages/js/src/first-time-configuration/tailwind-components/steps/constants.js index b21c1181f15..8a9b05505ed 100644 --- a/packages/js/src/first-time-configuration/tailwind-components/steps/constants.js +++ b/packages/js/src/first-time-configuration/tailwind-components/steps/constants.js @@ -6,7 +6,7 @@ export const STEPS = { }; export const HIIVE_STEPS_NAMES = { [ STEPS.optimizeSeoData ]: "data optimization", - [ STEPS.siteRepresentation ]: "Site representation", + [ STEPS.siteRepresentation ]: "site representation", [ STEPS.socialProfiles ]: "social profiles", [ STEPS.personalPreferences ]: "personal preferences", }; From cd3ab76c3315926e7364d8100f1b687a8dc4655a Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Fri, 6 Oct 2023 11:53:00 +0200 Subject: [PATCH 16/38] Add some more hiive attributes clicked_select_image has been added also to the image select box, and clicked_remove_image has been added to the remove image link. --- .../tailwind-components/base/image-select.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/js/src/first-time-configuration/tailwind-components/base/image-select.js b/packages/js/src/first-time-configuration/tailwind-components/base/image-select.js index 0a2206c672e..c9cd3390d4a 100644 --- a/packages/js/src/first-time-configuration/tailwind-components/base/image-select.js +++ b/packages/js/src/first-time-configuration/tailwind-components/base/image-select.js @@ -70,6 +70,7 @@ export default function ImageSelect( { className={ imageClassName } onClick={ onSelectImageClick } type="button" + data-hiive-event-name="clicked_select_image" > { renderPreview() } @@ -89,6 +90,7 @@ export default function ImageSelect( { id={ id + "__remove-image" } className="yst-button--remove" onClick={ onRemoveImageClick } + data-hiive-event-name="clicked_remove_image" > { __( "Remove image", "admin-ui" ) } From b3e5795e70c8f13dca8dbf40b2c0b8154352b8fd Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Fri, 6 Oct 2023 11:55:09 +0200 Subject: [PATCH 17/38] Remove useless curly brackets --- .../tailwind-components/steps/indexation/indexation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/src/first-time-configuration/tailwind-components/steps/indexation/indexation.js b/packages/js/src/first-time-configuration/tailwind-components/steps/indexation/indexation.js index 68d15cfabbc..f46b3065af8 100644 --- a/packages/js/src/first-time-configuration/tailwind-components/steps/indexation/indexation.js +++ b/packages/js/src/first-time-configuration/tailwind-components/steps/indexation/indexation.js @@ -284,7 +284,7 @@ class Indexation extends Component { className="yst-button yst-button--secondary" onClick={ this.startIndexing } id="indexation-data-optimization" - data-hiive-event-name={ "clicked_start_data_optimization" } + data-hiive-event-name="clicked_start_data_optimization" > { __( "Start SEO data optimization", "wordpress-seo" ) } ; From b8a9741d666b3a3d6907fea9f4216063800e40f7 Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Fri, 6 Oct 2023 11:57:06 +0200 Subject: [PATCH 18/38] Add missing Hiive attribute. Fixed also some indentation. --- .../steps/social-profiles/social-profiles-step.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/js/src/first-time-configuration/tailwind-components/steps/social-profiles/social-profiles-step.js b/packages/js/src/first-time-configuration/tailwind-components/steps/social-profiles/social-profiles-step.js index ddea8a067e3..fab3090fb67 100644 --- a/packages/js/src/first-time-configuration/tailwind-components/steps/social-profiles/social-profiles-step.js +++ b/packages/js/src/first-time-configuration/tailwind-components/steps/social-profiles/social-profiles-step.js @@ -44,11 +44,12 @@ export default function SocialProfilesStep( { state, dispatch, setErrorFields } "" ), - { // eslint-disable-next-line jsx-a11y/anchor-has-content + { // eslint-disable-next-line jsx-a11y/anchor-has-content a: , } ); From 19dba25ac9bd5be89cacf483aa93fd88ec664a04 Mon Sep 17 00:00:00 2001 From: "Paolo L. Scala" <68744851+pls78@users.noreply.github.com> Date: Mon, 9 Oct 2023 10:36:54 +0200 Subject: [PATCH 19/38] Update src/actions/configuration/first-time-configuration-action.php Co-authored-by: Enrico Battocchi --- .../configuration/first-time-configuration-action.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/actions/configuration/first-time-configuration-action.php b/src/actions/configuration/first-time-configuration-action.php index 8a7d2345422..142d4406bda 100644 --- a/src/actions/configuration/first-time-configuration-action.php +++ b/src/actions/configuration/first-time-configuration-action.php @@ -94,9 +94,9 @@ static function( $key ) { /** * Action: 'wpseo_post_update_site_representation' - Allows for Hiive event tracking. * - * @api array The options new values. - * @api array The options old values. - * @api array The options that failed to be saved. + * @param array The new values of the options. + * @param array The old values of the options. + * @param array The options that failed to be saved. */ \do_action( 'wpseo_post_update_site_representation', $params, $old_values, $failures ); From 447dab26c7086297bafe2e1a50cb53ea068866c2 Mon Sep 17 00:00:00 2001 From: "Paolo L. Scala" <68744851+pls78@users.noreply.github.com> Date: Mon, 9 Oct 2023 10:37:13 +0200 Subject: [PATCH 20/38] Update src/actions/configuration/first-time-configuration-action.php Co-authored-by: Enrico Battocchi --- .../configuration/first-time-configuration-action.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/actions/configuration/first-time-configuration-action.php b/src/actions/configuration/first-time-configuration-action.php index 142d4406bda..8a002d370de 100644 --- a/src/actions/configuration/first-time-configuration-action.php +++ b/src/actions/configuration/first-time-configuration-action.php @@ -129,9 +129,9 @@ public function set_social_profiles( $params ) { /** * Action: 'wpseo_post_update_social_profiles' - Allows for Hiive event tracking. * - * @api array The options new values. - * @api array The options old values. - * @api array The options that failed to be saved. + * @param array The new values of the options. + * @param array The old values of the options. + * @param array The options that failed to be saved. */ \do_action( 'wpseo_post_update_social_profiles', $params, $old_values, $failures ); From 7a93fca59b4c285534bb0772d2b2373b3d58cef3 Mon Sep 17 00:00:00 2001 From: "Paolo L. Scala" <68744851+pls78@users.noreply.github.com> Date: Mon, 9 Oct 2023 10:37:26 +0200 Subject: [PATCH 21/38] Update src/actions/configuration/first-time-configuration-action.php Co-authored-by: Enrico Battocchi --- .../configuration/first-time-configuration-action.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/actions/configuration/first-time-configuration-action.php b/src/actions/configuration/first-time-configuration-action.php index 8a002d370de..eb7427d255e 100644 --- a/src/actions/configuration/first-time-configuration-action.php +++ b/src/actions/configuration/first-time-configuration-action.php @@ -218,9 +218,9 @@ public function set_enable_tracking( $params ) { /** * Action: 'wpseo_post_update_enable_tracking' - Allows for Hiive event tracking. * - * @api array The new value. - * @api array The old value. - * @api bool Whether the option failed to be stored. + * @param array The new value. + * @param array The old value. + * @param bool Whether the option failed to be stored. */ // $success is negated to be aligned with the other two actions which pass $failures. \do_action( 'wpseo_post_update_enable_tracking', $params['tracking'], $option_value, ! $success ); From 5616de82478476260e5d455a90b47ff3d104efed Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Mon, 9 Oct 2023 11:29:36 +0200 Subject: [PATCH 22/38] Moved constants to FTC root folder --- .../{tailwind-components/steps => }/constants.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/js/src/first-time-configuration/{tailwind-components/steps => }/constants.js (100%) diff --git a/packages/js/src/first-time-configuration/tailwind-components/steps/constants.js b/packages/js/src/first-time-configuration/constants.js similarity index 100% rename from packages/js/src/first-time-configuration/tailwind-components/steps/constants.js rename to packages/js/src/first-time-configuration/constants.js From e7c703297b393bc4039eaeb808aa7ae011d4c983 Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Mon, 9 Oct 2023 11:29:52 +0200 Subject: [PATCH 23/38] Update constants import --- .../first-time-configuration/first-time-configuration-steps.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/src/first-time-configuration/first-time-configuration-steps.js b/packages/js/src/first-time-configuration/first-time-configuration-steps.js index a55f26c7caf..8b7e3e6cb92 100644 --- a/packages/js/src/first-time-configuration/first-time-configuration-steps.js +++ b/packages/js/src/first-time-configuration/first-time-configuration-steps.js @@ -14,7 +14,7 @@ import IndexationStep from "./tailwind-components/steps/indexation/indexation-st import SiteRepresentationStep from "./tailwind-components/steps/site-representation/site-representation-step"; import PersonalPreferencesStep from "./tailwind-components/steps/personal-preferences/personal-preferences-step"; import FinishStep from "./tailwind-components/steps/finish/finish-step"; -import { STEPS } from "./tailwind-components/steps/constants"; +import { STEPS } from "./constants"; /* eslint-disable complexity */ From 6247a507d412f19dc68e29bae3b6be23b3811411 Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Mon, 9 Oct 2023 11:31:43 +0200 Subject: [PATCH 24/38] Uniform buttons components props --- .../configuration-stepper-buttons.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js b/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js index da5da67d8b0..7a6a9aa23ef 100644 --- a/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js +++ b/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js @@ -4,7 +4,7 @@ import PropTypes from "prop-types"; import { Step } from "./stepper"; import { stepperTimingClasses } from "../stepper-helper"; import classNames from "classnames"; -import { HIIVE_STEPS_NAMES } from "../tailwind-components/steps/constants"; +import { HIIVE_STEPS_NAMES } from "../constants"; /** * A ContinueButton that always goes to the next step. @@ -93,11 +93,13 @@ EditButton.defaultProps = { * * @returns {WPElement} The BackButton, that always goes to the previous step. */ -export function BackButton( { beforeGo, children, additionalClasses, ...restProps } ) { +export function BackButton( { stepId, beforeGo, children, additionalClasses, ...restProps } ) { return ( { children } @@ -105,6 +107,7 @@ export function BackButton( { beforeGo, children, additionalClasses, ...restProp } BackButton.propTypes = { + stepId: PropTypes.string.isRequired, additionalClasses: PropTypes.string, beforeGo: PropTypes.func, children: PropTypes.node, @@ -131,18 +134,16 @@ BackButton.defaultProps = { export function StepButtons( { stepId, beforeContinue, continueLabel, beforeBack, backLabel } ) { return
{ continueLabel } { backLabel } From 73de8978bd0f1fe8badc276c4ec7ed8cc818eb94 Mon Sep 17 00:00:00 2001 From: "Paolo L. Scala" <68744851+pls78@users.noreply.github.com> Date: Tue, 10 Oct 2023 15:16:34 +0200 Subject: [PATCH 25/38] Update packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js Co-authored-by: Igor <35524806+igorschoester@users.noreply.github.com> --- .../tailwind-components/configuration-stepper-buttons.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js b/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js index 7a6a9aa23ef..70008a90b07 100644 --- a/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js +++ b/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js @@ -191,7 +191,7 @@ export function ConfigurationStepButtons( { stepId, stepperFinishedOnce, saveFun id={ `button-${ stepId }-go` } className="yst-button yst-button--primary yst-mt-12" destination="last"beforeGo={ onSaveClick } - data-hiive-event-name={ `clicked_save changes | ${ HIIVE_STEPS_NAMES[ stepId ] }` } + data-hiive-event-name={ `clicked_save_changes | ${ HIIVE_STEPS_NAMES[ stepId ] }` } > { __( "Save changes", "wordpress-seo" ) } ; From d881210475632e921855058fef28847caf2f7d57 Mon Sep 17 00:00:00 2001 From: "Paolo L. Scala" <68744851+pls78@users.noreply.github.com> Date: Tue, 10 Oct 2023 15:17:18 +0200 Subject: [PATCH 26/38] Update packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js Co-authored-by: Igor <35524806+igorschoester@users.noreply.github.com> --- .../tailwind-components/configuration-stepper-buttons.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js b/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js index 70008a90b07..304b7f38c70 100644 --- a/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js +++ b/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js @@ -190,7 +190,8 @@ export function ConfigurationStepButtons( { stepId, stepperFinishedOnce, saveFun return { __( "Save changes", "wordpress-seo" ) } From afeadbac384337bc6cacd291f5731a91bceefc07 Mon Sep 17 00:00:00 2001 From: "Paolo L. Scala" <68744851+pls78@users.noreply.github.com> Date: Tue, 10 Oct 2023 15:20:10 +0200 Subject: [PATCH 27/38] Update packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js Co-authored-by: Igor <35524806+igorschoester@users.noreply.github.com> --- .../tailwind-components/configuration-stepper-buttons.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js b/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js index 304b7f38c70..81a63cfb9e9 100644 --- a/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js +++ b/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js @@ -136,7 +136,6 @@ export function StepButtons( { stepId, beforeContinue, continueLabel, beforeBack { continueLabel } From 54811aff07f4745c3b34a6abcde602ed3e944193 Mon Sep 17 00:00:00 2001 From: "Paolo L. Scala" <68744851+pls78@users.noreply.github.com> Date: Tue, 10 Oct 2023 16:18:20 +0200 Subject: [PATCH 28/38] Update packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js Co-authored-by: Igor <35524806+igorschoester@users.noreply.github.com> --- .../tailwind-components/configuration-stepper-buttons.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js b/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js index 81a63cfb9e9..3506ca82ccf 100644 --- a/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js +++ b/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js @@ -183,7 +183,7 @@ export function ConfigurationStepButtons( { stepId, stepperFinishedOnce, saveFun // If save is not succesful: we are still editing setEditState( ! saveSuccesful ); return saveSuccesful; - } ); + }, [ saveFunction ] ); if ( stepperFinishedOnce ) { return Date: Tue, 10 Oct 2023 16:18:43 +0200 Subject: [PATCH 29/38] Update packages/js/src/first-time-configuration/tailwind-components/steps/personal-preferences/newsletter-signup.js Co-authored-by: Igor <35524806+igorschoester@users.noreply.github.com> --- .../steps/personal-preferences/newsletter-signup.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/js/src/first-time-configuration/tailwind-components/steps/personal-preferences/newsletter-signup.js b/packages/js/src/first-time-configuration/tailwind-components/steps/personal-preferences/newsletter-signup.js index 9adad97293a..9c9cec28e7d 100644 --- a/packages/js/src/first-time-configuration/tailwind-components/steps/personal-preferences/newsletter-signup.js +++ b/packages/js/src/first-time-configuration/tailwind-components/steps/personal-preferences/newsletter-signup.js @@ -124,7 +124,6 @@ export function NewsletterSignup( { gdprLink } ) { onClick={ onSignUpClick } disabled={ signUpState === "loading" } data-hiive-event-name="clicked_signup | personal preferences" - > { __( "Sign up!", "wordpress-seo" ) } From 042c33a7994ebb7e40f3e40936b5bc86c463ce17 Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Wed, 11 Oct 2023 09:10:58 +0200 Subject: [PATCH 30/38] Use the right hook name --- .../configuration/first-time-configuration-action.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/actions/configuration/first-time-configuration-action.php b/src/actions/configuration/first-time-configuration-action.php index eb7427d255e..ab2d6aaa3ba 100644 --- a/src/actions/configuration/first-time-configuration-action.php +++ b/src/actions/configuration/first-time-configuration-action.php @@ -98,7 +98,7 @@ static function( $key ) { * @param array The old values of the options. * @param array The options that failed to be saved. */ - \do_action( 'wpseo_post_update_site_representation', $params, $old_values, $failures ); + \do_action( 'wpseo_ftc_post_update_site_representation', $params, $old_values, $failures ); if ( \count( $failures ) === 0 ) { return (object) [ @@ -133,7 +133,7 @@ public function set_social_profiles( $params ) { * @param array The old values of the options. * @param array The options that failed to be saved. */ - \do_action( 'wpseo_post_update_social_profiles', $params, $old_values, $failures ); + \do_action( 'wpseo_ftc_post_update_social_profiles', $params, $old_values, $failures ); if ( empty( $failures ) ) { return (object) [ @@ -223,7 +223,7 @@ public function set_enable_tracking( $params ) { * @param bool Whether the option failed to be stored. */ // $success is negated to be aligned with the other two actions which pass $failures. - \do_action( 'wpseo_post_update_enable_tracking', $params['tracking'], $option_value, ! $success ); + \do_action( 'wpseo_ftc_post_update_enable_tracking', $params['tracking'], $option_value, ! $success ); if ( $success ) { return (object) [ From 565f3c8e667fcef6e6f2600df3cc5c89f4a4e122 Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Wed, 11 Oct 2023 09:48:00 +0200 Subject: [PATCH 31/38] Add @internal annotation to hooks --- .../configuration/first-time-configuration-action.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/actions/configuration/first-time-configuration-action.php b/src/actions/configuration/first-time-configuration-action.php index ab2d6aaa3ba..309439e39d9 100644 --- a/src/actions/configuration/first-time-configuration-action.php +++ b/src/actions/configuration/first-time-configuration-action.php @@ -97,6 +97,8 @@ static function( $key ) { * @param array The new values of the options. * @param array The old values of the options. * @param array The options that failed to be saved. + * + * @internal */ \do_action( 'wpseo_ftc_post_update_site_representation', $params, $old_values, $failures ); @@ -132,6 +134,8 @@ public function set_social_profiles( $params ) { * @param array The new values of the options. * @param array The old values of the options. * @param array The options that failed to be saved. + * + * @internal */ \do_action( 'wpseo_ftc_post_update_social_profiles', $params, $old_values, $failures ); @@ -221,6 +225,8 @@ public function set_enable_tracking( $params ) { * @param array The new value. * @param array The old value. * @param bool Whether the option failed to be stored. + * + * @internal */ // $success is negated to be aligned with the other two actions which pass $failures. \do_action( 'wpseo_ftc_post_update_enable_tracking', $params['tracking'], $option_value, ! $success ); From 388d8870c2b5ecd20142d9b14f62327e3e387b97 Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Wed, 11 Oct 2023 09:59:58 +0200 Subject: [PATCH 32/38] Do not filter $old_values. It is unnecessary because the 'description' field is not used anymore, so it's never gonna be there. --- .../configuration/first-time-configuration-action.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/actions/configuration/first-time-configuration-action.php b/src/actions/configuration/first-time-configuration-action.php index 309439e39d9..f6bf57040c4 100644 --- a/src/actions/configuration/first-time-configuration-action.php +++ b/src/actions/configuration/first-time-configuration-action.php @@ -61,15 +61,6 @@ public function set_site_representation( $params ) { $failures = []; $old_values = $this->get_old_values( self::SITE_REPRESENTATION_FIELDS ); - // This field seems to be not used anymore. - $old_values = \array_filter( - $old_values, - static function( $key ) { - return $key !== 'description'; - }, - \ARRAY_FILTER_USE_KEY - ); - foreach ( self::SITE_REPRESENTATION_FIELDS as $field_name ) { if ( isset( $params[ $field_name ] ) ) { if ( $field_name === 'description' && \current_user_can( 'manage_options' ) ) { From dbbaabb0d8668b174a1ad66e87d2f6656c66ca01 Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Wed, 11 Oct 2023 10:09:10 +0200 Subject: [PATCH 33/38] Simplify "Site representation step". The conditional about the "description" field has been removed because the field itself has been previously removed. --- .../configuration/first-time-configuration-action.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/actions/configuration/first-time-configuration-action.php b/src/actions/configuration/first-time-configuration-action.php index f6bf57040c4..f3b831c60b1 100644 --- a/src/actions/configuration/first-time-configuration-action.php +++ b/src/actions/configuration/first-time-configuration-action.php @@ -63,15 +63,8 @@ public function set_site_representation( $params ) { foreach ( self::SITE_REPRESENTATION_FIELDS as $field_name ) { if ( isset( $params[ $field_name ] ) ) { - if ( $field_name === 'description' && \current_user_can( 'manage_options' ) ) { - $result = \update_option( 'blogdescription', $params['description'] ); - if ( ! $result && $params['description'] === \get_option( 'blogdescription' ) ) { - $result = true; - } - } - else { - $result = $this->options_helper->set( $field_name, $params[ $field_name ] ); - } + $result = $this->options_helper->set( $field_name, $params[ $field_name ] ); + if ( ! $result ) { $failures[] = $field_name; } From 7ef5da3a9b84585cc89b198a92216365322079f6 Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Wed, 11 Oct 2023 14:49:01 +0200 Subject: [PATCH 34/38] Fix event name --- .../tailwind-components/configuration-stepper-buttons.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js b/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js index 3506ca82ccf..e61b427aeda 100644 --- a/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js +++ b/packages/js/src/first-time-configuration/tailwind-components/configuration-stepper-buttons.js @@ -99,7 +99,7 @@ export function BackButton( { stepId, beforeGo, children, additionalClasses, ... className={ `yst-button yst-button--secondary ${ additionalClasses }` } destination={ -1 } beforeGo={ beforeGo } - data-hiive-event-name={ `clicked_back | ${ HIIVE_STEPS_NAMES[ stepId ] }` } + data-hiive-event-name={ `clicked_go_back | ${ HIIVE_STEPS_NAMES[ stepId ] }` } { ...restProps } > { children } From 457253b731b2b6d66126846d199ff5b8da457b09 Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Wed, 11 Oct 2023 14:49:25 +0200 Subject: [PATCH 35/38] Fix event name in case of replaced image --- .../tailwind-components/base/image-select.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/src/first-time-configuration/tailwind-components/base/image-select.js b/packages/js/src/first-time-configuration/tailwind-components/base/image-select.js index c9cd3390d4a..506f70f254f 100644 --- a/packages/js/src/first-time-configuration/tailwind-components/base/image-select.js +++ b/packages/js/src/first-time-configuration/tailwind-components/base/image-select.js @@ -80,7 +80,7 @@ export default function ImageSelect( { id={ url ? id + "__replace-image" : id + "__select-image" } className="yst-button yst-button yst-button--secondary yst-mr-2" onClick={ onSelectImageClick } - data-hiive-event-name="clicked_select_image" + data-hiive-event-name={ url ? "clicked_replace_image" : "clicked_select_image" } > { url ? __( "Replace image", "admin-ui" ) : __( "Select image", "admin-ui" ) } From c9ee2d4f04771ae646bb898f28bb9952f63165d7 Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Wed, 11 Oct 2023 14:50:02 +0200 Subject: [PATCH 36/38] Enforce type checking --- src/actions/configuration/first-time-configuration-action.php | 2 +- src/helpers/social-profiles-helper.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/actions/configuration/first-time-configuration-action.php b/src/actions/configuration/first-time-configuration-action.php index f3b831c60b1..cb6dad2485a 100644 --- a/src/actions/configuration/first-time-configuration-action.php +++ b/src/actions/configuration/first-time-configuration-action.php @@ -332,7 +332,7 @@ private function can_edit_profile( $person_id ) { * * @return array The old values. */ - private function get_old_values( $fields_names ) : array { + private function get_old_values( array $fields_names ) : array { $old_values = []; foreach ( $fields_names as $field_name ) { diff --git a/src/helpers/social-profiles-helper.php b/src/helpers/social-profiles-helper.php index dca95b53457..5d2186658a1 100644 --- a/src/helpers/social-profiles-helper.php +++ b/src/helpers/social-profiles-helper.php @@ -65,7 +65,7 @@ public function get_person_social_profile_fields() { */ $person_social_profile_fields = \apply_filters( 'wpseo_person_social_profile_fields', $this->person_social_profile_fields ); - return $person_social_profile_fields; + return (array) $person_social_profile_fields; } /** @@ -81,7 +81,7 @@ public function get_organization_social_profile_fields() { */ $organization_social_profile_fields = \apply_filters( 'wpseo_organization_social_profile_fields', $this->organization_social_profile_fields ); - return $organization_social_profile_fields; + return (array) $organization_social_profile_fields; } /** From 576dd2316f1bae99f43b17e54be74d7e258c7465 Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Thu, 12 Oct 2023 10:56:40 +0200 Subject: [PATCH 37/38] Correct order of operations --- src/actions/configuration/first-time-configuration-action.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/configuration/first-time-configuration-action.php b/src/actions/configuration/first-time-configuration-action.php index cb6dad2485a..e9dc3c5ff60 100644 --- a/src/actions/configuration/first-time-configuration-action.php +++ b/src/actions/configuration/first-time-configuration-action.php @@ -109,8 +109,8 @@ public function set_site_representation( $params ) { * @return object The response object. */ public function set_social_profiles( $params ) { - $failures = $this->social_profiles_helper->set_organization_social_profiles( $params ); $old_values = $this->get_old_values( \array_keys( $this->social_profiles_helper->get_organization_social_profile_fields() ) ); + $failures = $this->social_profiles_helper->set_organization_social_profiles( $params ); /** * Action: 'wpseo_post_update_social_profiles' - Allows for Hiive event tracking. From a76b3ea97b3cf3d266395f26b10beed10832611c Mon Sep 17 00:00:00 2001 From: Paolo Luigi Scala Date: Fri, 13 Oct 2023 16:22:13 +0200 Subject: [PATCH 38/38] Fix tests --- .../first-time-configuration-action-test.php | 24 +------------------ 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/tests/unit/actions/configuration/first-time-configuration-action-test.php b/tests/unit/actions/configuration/first-time-configuration-action-test.php index c3ac5358ded..f09a7fd8676 100644 --- a/tests/unit/actions/configuration/first-time-configuration-action-test.php +++ b/tests/unit/actions/configuration/first-time-configuration-action-test.php @@ -117,7 +117,6 @@ public function site_representation_provider() { 'company_name' => 'Acme Inc.', 'company_logo' => 'https://acme.com/someimage.jpg', 'company_logo_id' => 123, - 'description' => 'A nice tagline', ], 'times' => 6, 'yoast_options_results' => [ true, true, true, true, true, true ], @@ -134,7 +133,6 @@ public function site_representation_provider() { 'person_logo' => 'https://acme.com/someimage.jpg', 'person_logo_id' => 123, 'company_or_person_user_id' => 321, - 'description' => 'A nice tagline', ], 'times' => 6, 'yoast_options_results' => [ true, true, true, true, true, true ], @@ -145,25 +143,6 @@ public function site_representation_provider() { ], ]; - $success_person_failure_tagline = [ - 'params' => [ - 'company_or_person' => 'person', - 'person_logo' => 'https://acme.com/someimage.jpg', - 'person_logo_id' => 123, - 'company_or_person_user_id' => 321, - 'description' => 'A tagline that will fail for some reason', - ], - 'times' => 6, - 'yoast_options_results' => [ true, true, true, true, true, true ], - 'wp_option_result' => false, - 'expected' => (object) [ - 'success' => false, - 'status' => 500, - 'error' => 'Could not save some options in the database', - 'failures' => [ 'description' ], - ], - ]; - $some_failures_company = [ 'params' => [ 'company_or_person' => 'company', @@ -172,7 +151,7 @@ public function site_representation_provider() { 'company_logo_id' => 123, 'description' => 'A nice tagline', ], - 'times' => 6, + 'times' => 7, 'yoast_options_results' => [ true, false, false, true, true, true ], 'wp_option_result' => true, 'expected' => (object) [ @@ -186,7 +165,6 @@ public function site_representation_provider() { return [ 'Successful call with company params' => $success_company, 'Successful call with person params' => $success_person, - 'Person params with failing description' => $success_person_failure_tagline, 'Company params with some failures' => $some_failures_company, ]; }