[ 'analytics_storage' ], 'marketing' => [ 'ad_storage', 'ad_user_data', 'ad_personalization' ], 'functional' => [ 'functionality_storage', 'personalization_storage' ], ]; public static function init() { // The settings are read inside the callback rather than here. Reading // them at plugin-load time would evaluate the translated defaults // before `init`, which WordPress rightly complains about. // // Negative priority so this beats anything hooked at 0 or 1, including // core's own head output. Being first is the whole requirement. add_action( 'wp_head', [ new self(), 'print_defaults' ], -9999 ); } /** * All signals, denied, except the one that is never optional. * * @return array */ public static function denied_defaults() { $defaults = []; foreach ( self::$signal_map as $signals ) { foreach ( $signals as $signal ) { $defaults[ $signal ] = 'denied'; } } $defaults['security_storage'] = 'granted'; return $defaults; } /** * @return array Category => signals, for the client to build its updates. */ public static function signal_map() { return apply_filters( 'ablocks/cookie_consent/consent_mode_signals', self::$signal_map ); } public function print_defaults() { if ( ! Helper::get( 'enabled', true ) || ! Helper::get( 'consent_mode', true ) ) { return; } if ( ! Helper::should_render_banner() ) { return; } $defaults = self::denied_defaults(); $wait = (int) Helper::get( 'consent_mode_wait', 500 ); if ( $wait > 0 ) { $defaults['wait_for_update'] = $wait; } // Both names, because this runs before the main script and has to find // the decision even on the first page view after a rename. $cookies = array_values( array_filter( [ Helper::get( 'cookie_name', 'ablocks_consent' ), Helper::get( 'cookie_name_previous', '' ), ] ) ); $map = self::signal_map(); $ads = (bool) Helper::get( 'consent_mode_ads', true ); ?>