Add filter to apply Base64 encoding to order attribution cookies (#47597)

* Add filter to set Sourcebuster JS base64 configuration value

* Use Sourcebuster v1.2.0

* Changelog

* Reduce line length for linter
This commit is contained in:
Justin Palmer 2024-05-21 01:56:14 +02:00 committed by GitHub
parent 42cb91ae3c
commit 8541afa418
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 25 additions and 7 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Filter to apply Base64 encoding to order attribution cookies

View File

@ -82,6 +82,7 @@
sbjs.init( {
lifetime: Number( params.lifetime ),
session_length: Number( params.session ),
base64: Boolean( params.base64 ),
timezone_offset: '0', // utc
} );
}
@ -184,7 +185,10 @@
if( input ) {
input.value = stringifyFalsyInputValue( this.values[ fieldName ] );
} else {
console.warn( `Field "${fieldName}" not found. Most likely, the '<wc-order-attribution-inputs>' element was manipulated.`);
console.warn(
`Field "${fieldName}" not found. ` +
`Most likely, the '<wc-order-attribution-inputs>' element was manipulated.`
);
}
}
}

View File

@ -42,7 +42,7 @@
"wireit": "0.14.3"
},
"dependencies": {
"sourcebuster": "github:woocommerce/sourcebuster-js#v1.1.2"
"sourcebuster": "github:woocommerce/sourcebuster-js#v1.2.0"
},
"wireit": {
"build:project:assets": {

View File

@ -288,6 +288,15 @@ class OrderAttributionController implements RegisterHooksInterface {
*/
$session_length = (int) apply_filters( 'wc_order_attribution_session_length_minutes', 30 );
/**
* Filter to enable base64 encoding for cookie values.
*
* @since 9.0.0
*
* @param bool $use_base64_cookies True to enable base64 encoding, default is false.
*/
$use_base64_cookies = apply_filters( 'wc_order_attribution_use_base64_cookies', false );
/**
* Filter to allow tracking.
*
@ -302,6 +311,7 @@ class OrderAttributionController implements RegisterHooksInterface {
'params' => array(
'lifetime' => $lifetime,
'session' => $session_length,
'base64' => $use_base64_cookies,
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'prefix' => $this->field_prefix,
'allowTracking' => 'yes' === $allow_tracking,

View File

@ -4495,8 +4495,8 @@ importers:
plugins/woocommerce/client/legacy:
dependencies:
sourcebuster:
specifier: github:woocommerce/sourcebuster-js#v1.1.2
version: https://codeload.github.com/woocommerce/sourcebuster-js/tar.gz/411d8dffaa37d7602d678c2ec02baacee93c12d5
specifier: github:woocommerce/sourcebuster-js#v1.2.0
version: https://codeload.github.com/woocommerce/sourcebuster-js/tar.gz/d7f4616d5a17e17db925ca1842457f309379d861
devDependencies:
'@types/node':
specifier: ^16.18.68
@ -22426,8 +22426,8 @@ packages:
resolution: {integrity: sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA==}
engines: {node: '>= 8'}
sourcebuster@https://codeload.github.com/woocommerce/sourcebuster-js/tar.gz/411d8dffaa37d7602d678c2ec02baacee93c12d5:
resolution: {tarball: https://codeload.github.com/woocommerce/sourcebuster-js/tar.gz/411d8dffaa37d7602d678c2ec02baacee93c12d5}
sourcebuster@https://codeload.github.com/woocommerce/sourcebuster-js/tar.gz/d7f4616d5a17e17db925ca1842457f309379d861:
resolution: {tarball: https://codeload.github.com/woocommerce/sourcebuster-js/tar.gz/d7f4616d5a17e17db925ca1842457f309379d861}
version: 1.1.2
space-separated-tokens@1.1.5:
@ -58636,7 +58636,7 @@ snapshots:
source-map@0.7.4: {}
sourcebuster@https://codeload.github.com/woocommerce/sourcebuster-js/tar.gz/411d8dffaa37d7602d678c2ec02baacee93c12d5: {}
sourcebuster@https://codeload.github.com/woocommerce/sourcebuster-js/tar.gz/d7f4616d5a17e17db925ca1842457f309379d861: {}
space-separated-tokens@1.1.5: {}