[Enhancement]: Add Tracks event recording to Emails settings (#38834)

* Add possibility to track select and checkbox values for non_option settings

* Track select and checkboxes in abstract-wc-settings-api

* Add changelog

* Add hook comment and ignore phpcs for actions that were already called before
This commit is contained in:
Nathan Silveira 2023-06-23 09:44:57 -03:00 committed by GitHub
parent e6eda7fce5
commit 066974538c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 8 deletions

View File

@ -0,0 +1,5 @@
Significance: patch
Type: add
Comment: Track checkboxes and selects in Settings > Emails settings

View File

@ -212,6 +212,21 @@ abstract class WC_Settings_API {
if ( 'title' !== $this->get_field_type( $field ) ) {
try {
$this->settings[ $key ] = $this->get_field_value( $key, $field, $post_data );
if ( 'select' === $field['type'] || 'checkbox' === $field['type'] ) {
/**
* Notify that a non-option setting has been updated.
*
* @since 7.8.0
*/
do_action(
'woocommerce_update_non_option_setting',
array(
'id' => $key,
'type' => $field['type'],
'value' => $this->settings[ $key ],
)
);
}
} catch ( Exception $e ) {
$this->add_error( $e->getMessage() );
}
@ -219,8 +234,8 @@ abstract class WC_Settings_API {
}
$option_key = $this->get_option_key();
do_action( 'woocommerce_update_option', array( 'id' => $option_key ) );
return update_option( $option_key, apply_filters( 'woocommerce_settings_api_sanitized_fields_' . $this->id, $this->settings ), 'yes' );
do_action( 'woocommerce_update_option', array( 'id' => $option_key ) ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
return update_option( $option_key, apply_filters( 'woocommerce_settings_api_sanitized_fields_' . $this->id, $this->settings ), 'yes' ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
}
/**
@ -729,7 +744,7 @@ abstract class WC_Settings_API {
'options' => array(),
);
$data = wp_parse_args( $data, $defaults );
$data = wp_parse_args( $data, $defaults );
$value = $this->get_option( $key );
ob_start();

View File

@ -89,13 +89,25 @@ class WC_Settings_Tracking {
if ( ! in_array( $option['id'], $this->allowed_options, true ) ) {
$this->allowed_options[] = $option['id'];
}
if ( 'add' === $option['action'] ) {
$this->added_options[] = $option['id'];
} elseif ( 'delete' === $option['action'] ) {
$this->deleted_options[] = $option['id'];
} elseif ( ! in_array( $option['id'], $this->updated_options, true ) ) {
if ( isset( $option['action'] ) ) {
if ( 'add' === $option['action'] ) {
$this->added_options[] = $option['id'];
} elseif ( 'delete' === $option['action'] ) {
$this->deleted_options[] = $option['id'];
} elseif ( ! in_array( $option['id'], $this->updated_options, true ) ) {
$this->updated_options[] = $option['id'];
}
} elseif ( isset( $option['value'] ) ) {
if ( 'select' === $option['type'] ) {
$this->modified_options[ $option['id'] ] = $option['value'];
} elseif ( 'checkbox' === $option['type'] ) {
$option_state = 'yes' === $option['value'] ? 'enabled' : 'disabled';
$this->toggled_options[ $option_state ][] = $option['id'];
}
$this->updated_options[] = $option['id'];
}
}
/**