8889841cPKH_[rKP. Tracking.phpnu[screens = $screens ?: new Screens( $context ); $this->consent = new Tracking_Consent( $user_options ); $this->rest_controller = new REST_Tracking_Consent_Controller( $this->consent ); } /** * Registers functionality through WordPress hooks. * * @since 1.49.0 */ public function register() { $this->consent->register(); $this->rest_controller->register(); add_filter( 'googlesitekit_inline_tracking_data', $this->get_method_proxy( 'inline_js_tracking_data' ) ); } /** * Is tracking active for the current user? * * @since 1.49.0 * * @return bool True if tracking enabled, and False if not. */ public function is_active() { return (bool) $this->consent->get(); } /** * Adds / modifies tracking relevant data to pass to JS. * * @since 1.78.0 * * @param array $data Inline JS data. * @return array Filtered $data. */ private function inline_js_tracking_data( $data ) { global $hook_suffix; $data['isSiteKitScreen'] = $this->screens->get_screen( $hook_suffix ) instanceof Screen; $data['trackingEnabled'] = $this->is_active(); $data['trackingID'] = self::TRACKING_ID; return $data; } } PKH_[c $REST_Tracking_Consent_Controller.phpnu[consent = $tracking_consent; } /** * Registers functionality through WordPress hooks. * * @since 1.49.0 */ public function register() { add_filter( 'googlesitekit_rest_routes', $this->get_method_proxy( 'get_rest_routes' ) ); add_filter( 'googlesitekit_apifetch_preload_paths', function ( $routes ) { return array_merge( $routes, array( '/' . REST_Routes::REST_ROOT . '/core/user/data/tracking', ) ); } ); } /** * Is tracking active for the current user? * * @since 1.49.0 * * @return bool True if tracking enabled, and False if not. */ public function is_active() { return (bool) $this->consent->get(); } /** * Gets tracking routes. * * @since 1.49.0 * * @param array $routes Array of routes. * @return array Modified array of routes that contains tracking related routes. */ private function get_rest_routes( $routes ) { $can_access_tracking = function() { return current_user_can( Permissions::VIEW_SPLASH ) || current_user_can( Permissions::VIEW_DASHBOARD ); }; $tracking_callback = function ( WP_REST_Request $request ) { return new WP_REST_Response( array( 'enabled' => $this->is_active(), ) ); }; return array_merge( $routes, array( new REST_Route( 'core/user/data/tracking', array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => $tracking_callback, 'permission_callback' => $can_access_tracking, ), array( 'methods' => WP_REST_Server::CREATABLE, 'callback' => function ( WP_REST_Request $request ) use ( $tracking_callback ) { $data = $request->get_param( 'data' ); $enabled = ! empty( $data['enabled'] ); $this->consent->set( $enabled ); return $tracking_callback( $request ); }, 'permission_callback' => $can_access_tracking, 'args' => array( 'data' => array( 'type' => 'object', 'required' => true, 'properties' => array( 'enabled' => array( 'type' => 'boolean', 'required' => true, ), ), ), ), ), ) ), ) ); } } PKH_[~,Tracking_Consent.phpnu[user_options->get( static::OPTION ); } /** * Gets the expected value type. * * @since 1.49.0 * * @return string The type name. */ protected function get_type() { return 'boolean'; } /** * Gets the default value. * * @since 1.49.0 * * @return bool The default value. */ protected function get_default() { return false; } } PKH_[rKP. Tracking.phpnu[PKH_[c $ REST_Tracking_Consent_Controller.phpnu[PKH_[~,8Tracking_Consent.phpnu[PK2