Changeset 3810059
- Timestamp:
- 11/18/2026 07:28:30 PM (3 days ago)
- Location:
- omea-consent/trunk
- Files:
-
- 8 edited
-
README.txt (modified) (2 diffs)
-
assets/js/omea-consent-manager.js (modified) (2 diffs)
-
includes/class-omea-consent-setup.php (modified) (1 diff)
-
includes/views/admin/settings.php (modified) (1 diff)
-
languages/omea-consent.pot (modified) (1 diff)
-
omea-consent.php (modified) (6 diffs)
-
source/package.json (modified) (1 diff)
-
source/src/assets/js/omea-consent-manager.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
omea-consent/trunk/README.txt
r3809572 r3810059 5 5 Tested up to: 7.1 6 6 Requires PHP: 7.4 7 Stable tag: 1.0. 97 Stable tag: 1.0.10 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 117 117 == Changelog == 118 118 119 = 1.0.10 = 120 - Works better with Omea Analytics and other plugins that read the WP Consent API: a visitor's choice now reaches them for as long as it is valid (before, they stopped seeing it after 30 days), on every subdomain that shares the choice, and not after it has expired. 121 - Google Consent Mode settings: the Advanced option is labelled "Better modelling", which is what Google's documentation says about it. 122 - For developers: settings export and import as a public API (used by Omea Consent Pro's settings profiles). 123 119 124 = 1.0.9 = 120 125 - Scripts: new category "Google tag – follows Consent Mode". Paste Google's gtag.js snippet once: in Advanced Consent Mode it loads for every visitor with consent denied by default, in Basic mode it waits for consent (Statistics for Google Analytics, Marketing for Google Ads). The Scripts list suggests it when a gtag.js snippet sits in another category. -
omea-consent/trunk/assets/js/omea-consent-manager.js
r3770287 r3810059 47 47 // different banner wording, so the visitor is asked again. 48 48 this._expireStaleConsent(); 49 50 // Keep the WP Consent API cookies in step with the stored choice. Its script 51 // may come after this one on the page: then once the page has parsed. 52 const syncWp = () => this._syncWpConsent(); 53 if (typeof window.wp_set_consent === 'function' || document.readyState !== 'loading') { 54 syncWp(); 55 } else { 56 document.addEventListener('DOMContentLoaded', syncWp, { once: true }); 57 } 49 58 50 59 this.createWrapper(); … … 993 1002 } 994 1003 1004 /** 1005 * WP Consent API cookies (wp_consent_<category>) are what Omea Analytics and 1006 * other plugins read. They were written only when the choice changed, so they 1007 * lapsed after the API's 30 days while the choice stayed valid (Analytics then 1008 * treated a consented visitor as new), never reached a subdomain that adopted a 1009 * shared choice, and outlived a choice that expired. On every page: write the 1010 * stored choice (refreshes the expiry; the API fires its change event only when 1011 * the value differs) or, once the choice is gone, remove them. 1012 * @private 1013 */ 1014 _syncWpConsent() { 1015 if (this.config.previewMode) return; 1016 const prefix = (window.consent_api && window.consent_api.cookie_prefix) || 'wp_consent'; 1017 const consented = this.getHasConsented(); 1018 (this.config.consentTypes || []).forEach((type) => { 1019 if (!type || !type.id || type.required) return; 1020 const wpType = type.wpConsentType || type.id; 1021 if (!wpType || wpType === 'necessary') return; 1022 if (consented) { 1023 this.updateWpConsent(type, !this._gpcLocks(type.id) && this.getConsentChoice(type.id) === true); 1024 return; 1025 } 1026 // No stored choice: GPC's Marketing "deny" stays; without localStorage the 1027 // cookie may be the only record, so it stays too. 1028 if (this._gpcLocks(type.id) || !this.localStorageAvailable) return; 1029 const name = prefix + '_' + wpType; 1030 if (new RegExp('(?:^|; )' + name + '=').test(document.cookie)) { 1031 document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/'; 1032 } 1033 }); 1034 } 1035 995 1036 setHasConsented() { 996 1037 const newKey = this._buildHasConsentedKey(); -
omea-consent/trunk/includes/class-omea-consent-setup.php
r3770287 r3810059 333 333 _x( 'Advanced', 'Google Consent Mode type', 'omea-consent' ), 334 334 __( 'Google tags load right away. Until the visitor allows them – also after “Reject all” – they send Google cookieless pings with the page address, browser type and IP address, so Google can model visits and conversions. Most advertisers use this.', 'omea-consent' ), 335 __( ' Google’s recommendation', 'omea-consent' )335 __( 'Better modelling', 'omea-consent' ) 336 336 ); 337 337 self::option( -
omea-consent/trunk/includes/views/admin/settings.php
r3770287 r3810059 442 442 <input type="radio" name="<?php echo esc_attr( self::OPTION_GOOGLE_CONSENT_MODE_TYPE ); ?>" value="advanced" <?php checked( 'advanced', $google_cm_type ); ?> /> 443 443 <span> 444 <strong><?php echo esc_html_x( 'Advanced', 'Google Consent Mode type', 'omea-consent' ); ?> <span class="omea-badge"><?php esc_html_e( ' Google’s recommendation', 'omea-consent' ); ?></span></strong>444 <strong><?php echo esc_html_x( 'Advanced', 'Google Consent Mode type', 'omea-consent' ); ?> <span class="omea-badge"><?php esc_html_e( 'Better modelling', 'omea-consent' ); ?></span></strong> 445 445 <span class="omea-help"><?php esc_html_e( 'Google tags load right away. While consent is missing or refused they set no cookies but send cookieless pings (page address, referrer, browser type, consent state; the IP address is part of every request), so visits and conversions can be modelled.', 'omea-consent' ); ?></span> 446 446 </span> -
omea-consent/trunk/languages/omea-consent.pot
r3801887 r3810059 1119 1119 #: includes/class-omea-consent-setup.php:335 1120 1120 #: includes/views/admin/settings.php:444 1121 msgid " Google’s recommendation"1121 msgid "Better modelling" 1122 1122 msgstr "" 1123 1123 -
omea-consent/trunk/omea-consent.php
r3801887 r3810059 3 3 * Plugin Name: Omea Consent – Cookie Banner, Consent Mode v2 & Conversions API 4 4 * Description: Frontend cookie consent banner and consent management. 5 * Version: 1.0. 95 * Version: 1.0.10 6 6 * Author: Cultmetrics 7 7 * License: GPLv2 or later … … 13 13 } 14 14 15 define( 'OMEA_CONSENT_VERSION', '1.0. 9' );15 define( 'OMEA_CONSENT_VERSION', '1.0.10' ); 16 16 define( 'OMEA_CONSENT_SLUG', 'omea-consent' ); 17 17 define( 'OMEA_CONSENT_PLUGIN_FILE', __FILE__ ); … … 306 306 307 307 private static function maybe_load_wp_consent_api() { 308 // The WP Consent API cookies (wp_consent_<category>, read by Omea Analytics and 309 // other plugins) last as long as the visitor's choice, not the API's 30 days; 310 // the banner also refreshes and clears them on every page (consent manager JS). 311 add_filter( 312 'wp_cookie_expiration', 313 static function () { 314 return (int) apply_filters( 'omea_consent_cookie_max_age_days', self::get_consent_valid_days() ); 315 } 316 ); 317 308 318 if ( class_exists( 'WP_Consent_API' ) ) { 309 319 return; … … 1717 1727 1718 1728 /** 1719 * Maintenance › Export: settings, scripts and cookie overrides as a JSON download. 1720 */ 1721 public static function handle_export_settings() { 1722 if ( ! current_user_can( 'manage_options' ) ) { 1723 wp_die( esc_html__( 'Unauthorized', 'omea-consent' ), 403 ); 1724 } 1725 check_admin_referer( 'omea_consent_export_settings', 'omea_consent_export_nonce' ); 1726 1729 * Settings, scripts and cookie overrides in the export format (Maintenance › Export, 1730 * and Omea Consent Pro's settings profiles). 1731 * 1732 * @param string[] $exclude Option names to leave out (e.g. site-specific page IDs). 1733 * @return array{plugin:string,version:string,exported:string,options:array,scripts:array} 1734 */ 1735 public static function get_settings_export( $exclude = array() ) { 1727 1736 $options = array(); 1728 1737 foreach ( self::settings_option_names() as $name ) { 1729 $options[ $name ] = get_option( $name ); 1730 } 1731 $payload = array( 1738 if ( ! in_array( $name, (array) $exclude, true ) ) { 1739 $options[ $name ] = get_option( $name ); 1740 } 1741 } 1742 return array( 1732 1743 'plugin' => 'omea-consent', 1733 1744 'version' => OMEA_CONSENT_VERSION, … … 1736 1747 'scripts' => self::get_scripts(), 1737 1748 ); 1738 1739 nocache_headers(); 1740 header( 'Content-Type: application/json; charset=utf-8' ); 1741 header( 'Content-Disposition: attachment; filename="omea-consent-settings-' . gmdate( 'Y-m-d' ) . '.json"' ); 1742 echo wp_json_encode( $payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); 1743 exit; 1744 } 1745 1746 /** 1747 * Maintenance › Import: applies a JSON export. Every value goes through the 1748 * same sanitizers as a normal save; unknown keys are ignored. 1749 */ 1750 public static function handle_import_settings() { 1751 if ( ! current_user_can( 'manage_options' ) ) { 1752 wp_die( esc_html__( 'Unauthorized', 'omea-consent' ), 403 ); 1753 } 1754 check_admin_referer( 'omea_consent_import_settings', 'omea_consent_import_nonce' ); 1755 1756 $tmp = isset( $_FILES['omea_consent_import_file']['tmp_name'] ) ? sanitize_text_field( wp_unslash( $_FILES['omea_consent_import_file']['tmp_name'] ) ) : ''; 1757 $size = isset( $_FILES['omea_consent_import_file']['size'] ) ? absint( $_FILES['omea_consent_import_file']['size'] ) : 0; 1758 $data = null; 1759 if ( $tmp && is_uploaded_file( $tmp ) && $size > 0 && $size <= MB_IN_BYTES ) { 1760 $data = json_decode( (string) file_get_contents( $tmp ), true ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Reading the uploaded temp file. 1761 } 1749 } 1750 1751 /** 1752 * Applies an export: every value goes through the same sanitizers as a normal save; 1753 * options not in the export and unknown keys are left alone. Scripts in the export 1754 * replace the site's scripts. 1755 * 1756 * @param mixed $data Decoded export. 1757 * @return bool False when it is not an Omea Consent export. 1758 */ 1759 public static function apply_settings_export( $data ) { 1762 1760 if ( ! is_array( $data ) || 'omea-consent' !== ( $data['plugin'] ?? '' ) || ! isset( $data['options'] ) || ! is_array( $data['options'] ) ) { 1763 self::settings_redirect( 'import_failed', 'maintenance' );1761 return false; 1764 1762 } 1765 1763 … … 1796 1794 } 1797 1795 self::update_scripts( $scripts ); 1796 } 1797 return true; 1798 } 1799 1800 /** 1801 * Maintenance › Export: settings, scripts and cookie overrides as a JSON download. 1802 */ 1803 public static function handle_export_settings() { 1804 if ( ! current_user_can( 'manage_options' ) ) { 1805 wp_die( esc_html__( 'Unauthorized', 'omea-consent' ), 403 ); 1806 } 1807 check_admin_referer( 'omea_consent_export_settings', 'omea_consent_export_nonce' ); 1808 1809 $payload = self::get_settings_export(); 1810 1811 nocache_headers(); 1812 header( 'Content-Type: application/json; charset=utf-8' ); 1813 header( 'Content-Disposition: attachment; filename="omea-consent-settings-' . gmdate( 'Y-m-d' ) . '.json"' ); 1814 echo wp_json_encode( $payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); 1815 exit; 1816 } 1817 1818 /** 1819 * Maintenance › Import: applies a JSON export (apply_settings_export()). 1820 */ 1821 public static function handle_import_settings() { 1822 if ( ! current_user_can( 'manage_options' ) ) { 1823 wp_die( esc_html__( 'Unauthorized', 'omea-consent' ), 403 ); 1824 } 1825 check_admin_referer( 'omea_consent_import_settings', 'omea_consent_import_nonce' ); 1826 1827 $tmp = isset( $_FILES['omea_consent_import_file']['tmp_name'] ) ? sanitize_text_field( wp_unslash( $_FILES['omea_consent_import_file']['tmp_name'] ) ) : ''; 1828 $size = isset( $_FILES['omea_consent_import_file']['size'] ) ? absint( $_FILES['omea_consent_import_file']['size'] ) : 0; 1829 $data = null; 1830 if ( $tmp && is_uploaded_file( $tmp ) && $size > 0 && $size <= MB_IN_BYTES ) { 1831 $data = json_decode( (string) file_get_contents( $tmp ), true ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Reading the uploaded temp file. 1832 } 1833 if ( ! self::apply_settings_export( $data ) ) { 1834 self::settings_redirect( 'import_failed', 'maintenance' ); 1798 1835 } 1799 1836 -
omea-consent/trunk/source/package.json
r3801887 r3810059 1 1 { 2 2 "name": "omea-consent", 3 "version": "1.0. 9",3 "version": "1.0.10", 4 4 "private": true, 5 5 "scripts": { -
omea-consent/trunk/source/src/assets/js/omea-consent-manager.js
r3770287 r3810059 47 47 // different banner wording, so the visitor is asked again. 48 48 this._expireStaleConsent(); 49 50 // Keep the WP Consent API cookies in step with the stored choice. Its script 51 // may come after this one on the page: then once the page has parsed. 52 const syncWp = () => this._syncWpConsent(); 53 if (typeof window.wp_set_consent === 'function' || document.readyState !== 'loading') { 54 syncWp(); 55 } else { 56 document.addEventListener('DOMContentLoaded', syncWp, { once: true }); 57 } 49 58 50 59 this.createWrapper(); … … 993 1002 } 994 1003 1004 /** 1005 * WP Consent API cookies (wp_consent_<category>) are what Omea Analytics and 1006 * other plugins read. They were written only when the choice changed, so they 1007 * lapsed after the API's 30 days while the choice stayed valid (Analytics then 1008 * treated a consented visitor as new), never reached a subdomain that adopted a 1009 * shared choice, and outlived a choice that expired. On every page: write the 1010 * stored choice (refreshes the expiry; the API fires its change event only when 1011 * the value differs) or, once the choice is gone, remove them. 1012 * @private 1013 */ 1014 _syncWpConsent() { 1015 if (this.config.previewMode) return; 1016 const prefix = (window.consent_api && window.consent_api.cookie_prefix) || 'wp_consent'; 1017 const consented = this.getHasConsented(); 1018 (this.config.consentTypes || []).forEach((type) => { 1019 if (!type || !type.id || type.required) return; 1020 const wpType = type.wpConsentType || type.id; 1021 if (!wpType || wpType === 'necessary') return; 1022 if (consented) { 1023 this.updateWpConsent(type, !this._gpcLocks(type.id) && this.getConsentChoice(type.id) === true); 1024 return; 1025 } 1026 // No stored choice: GPC's Marketing "deny" stays; without localStorage the 1027 // cookie may be the only record, so it stays too. 1028 if (this._gpcLocks(type.id) || !this.localStorageAvailable) return; 1029 const name = prefix + '_' + wpType; 1030 if (new RegExp('(?:^|; )' + name + '=').test(document.cookie)) { 1031 document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/'; 1032 } 1033 }); 1034 } 1035 995 1036 setHasConsented() { 996 1037 const newKey = this._buildHasConsentedKey();
Note:
See TracChangeset
for help on using the changeset viewer.