1 | <?php |
||
15 | class WordAds_California_Privacy { |
||
16 | |||
17 | /** |
||
18 | * Initializes required scripts and shortcode. |
||
19 | */ |
||
20 | public static function init() { |
||
21 | // Initialize shortcode. |
||
22 | add_shortcode( 'ccpa-do-not-sell-link', array( __CLASS__, 'do_not_sell_link_shortcode' ) ); |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * Enqueue required CCPA JavaScript on the frontend. |
||
27 | */ |
||
28 | public static function enqueue_scripts() { |
||
29 | wp_enqueue_script( |
||
30 | 'wordads_ccpa', |
||
31 | Assets::get_file_url_for_environment( |
||
32 | '_inc/build/wordads/js/wordads-ccpa.min.js', |
||
33 | 'modules/wordads/js/wordads-ccpa.js' |
||
34 | ), |
||
35 | array(), |
||
36 | JETPACK__VERSION, |
||
37 | true |
||
38 | ); |
||
39 | |||
40 | wp_localize_script( |
||
41 | 'wordads_ccpa', |
||
42 | 'ccpaSettings', |
||
43 | array( |
||
44 | 'defaultOptinCookieString' => esc_html( self::get_optin_cookie_string() ), |
||
45 | 'ccpaCssUrl' => esc_url( Assets::get_file_url_for_environment( '/css/wordads-ccpa.min.css', '/css/wordads-ccpa.css' ) . '?ver=' . JETPACK__VERSION ), |
||
46 | 'ajaxUrl' => esc_url( admin_url( 'admin-ajax.php' ) ), |
||
47 | 'ajaxNonce' => wp_create_nonce( 'ccpa_optout' ), |
||
48 | 'forceApplies' => wp_json_encode( is_user_logged_in() && current_user_can( 'manage_options' ) ), |
||
49 | 'strings' => array( |
||
50 | 'pleaseWait' => esc_html__( 'Please Wait', 'jetpack' ), |
||
51 | ), |
||
52 | ) |
||
53 | ); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Initializes handlers for admin AJAX. |
||
58 | */ |
||
59 | public static function init_ajax_actions() { |
||
60 | add_action( 'wp_ajax_privacy_optout', array( __CLASS__, 'handle_optout_request' ) ); |
||
61 | add_action( 'wp_ajax_nopriv_privacy_optout', array( __CLASS__, 'handle_optout_request' ) ); |
||
62 | |||
63 | add_action( 'wp_ajax_privacy_optout_markup', array( __CLASS__, 'handle_optout_markup' ) ); |
||
64 | add_action( 'wp_ajax_nopriv_privacy_optout_markup', array( __CLASS__, 'handle_optout_markup' ) ); |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * Outputs [ccpa-do-not-sell-link] shortcode markup. |
||
69 | * |
||
70 | * @param array $attributes The shortcode attributes. |
||
71 | * @param string $content The shortcode content. |
||
72 | * |
||
73 | * @return string The generated shortcode markup. |
||
74 | */ |
||
75 | public static function do_not_sell_link_shortcode( $attributes, $content ) { |
||
76 | |||
77 | // If in the customizer always display the link. |
||
78 | if ( is_customize_preview() ) { |
||
79 | return '<a href="#" class="ccpa-do-not-sell">' . self::get_optout_link_text() . '</a>'; |
||
80 | } |
||
81 | |||
82 | // Load required scripts if the shortcode/widget is loaded on the page. |
||
83 | self::enqueue_scripts(); |
||
84 | |||
85 | return '<a href="#" class="ccpa-do-not-sell" style="display: none;">' . self::get_optout_link_text() . '</a>'; |
||
86 | } |
||
87 | |||
88 | |||
89 | /** |
||
90 | * Gets the text used to link to the opt-out page. By law must read 'Do Not Sell My Personal Information'. |
||
91 | * |
||
92 | * @return mixed|string|void The text of the opt-out link. |
||
93 | */ |
||
94 | private static function get_optout_link_text() { |
||
97 | |||
98 | /** |
||
99 | * Builds the value of the opt-out cookie. |
||
100 | * Format matches spec of [IAB U.S. Privacy String](https://github.com/InteractiveAdvertisingBureau/USPrivacy/blob/master/CCPA/US%20Privacy%20String.md). |
||
101 | * |
||
102 | * @param bool $optout True if setting an opt-out cookie. |
||
103 | * |
||
104 | * @return string The value to be stored in the opt-out cookie. |
||
105 | */ |
||
106 | private static function build_iab_privacy_string( $optout ) { |
||
116 | |||
117 | /** |
||
118 | * Gets the name to be used for the opt-out cookie. |
||
119 | * Name matches spec of [IAB U.S. Privacy String](https://github.com/InteractiveAdvertisingBureau/USPrivacy/blob/master/CCPA/US%20Privacy%20String.md). |
||
120 | * |
||
121 | * @return string The name of the opt-out cookie. |
||
122 | */ |
||
123 | private static function get_cookie_name() { |
||
126 | |||
127 | /** |
||
128 | * Gets the domain to be used for the opt-out cookie. |
||
129 | * Use the site's custom domain, or if the site has a wordpress.com subdomain, use .wordpress.com to share the cookie. |
||
130 | * |
||
131 | * @return string The domain to set for the opt-out cookie. |
||
132 | */ |
||
133 | public static function get_cookie_domain() { |
||
142 | |||
143 | /** |
||
144 | * Gets the value to be used when an opt-out cookie is set. |
||
145 | * |
||
146 | * @return string The value to store in the opt-out cookie. |
||
147 | */ |
||
148 | private static function get_optout_cookie_string() { |
||
151 | |||
152 | /** |
||
153 | * Gets the value to be used when an opt-in cookie is set. |
||
154 | * |
||
155 | * @return string The value to store in the opt-in cookie. |
||
156 | */ |
||
157 | private static function get_optin_cookie_string() { |
||
160 | |||
161 | /** |
||
162 | * Sets a cookie in the HTTP response to opt-out visitors from data sales. |
||
163 | * |
||
164 | * @return bool True if the cookie could be set. |
||
165 | */ |
||
166 | private static function set_optout_cookie() { |
||
169 | |||
170 | /** |
||
171 | * Sets a cookie in the HTTP response to opt-in visitors from data sales. |
||
172 | * |
||
173 | * @return bool True if the cookie could be set. |
||
174 | */ |
||
175 | private static function set_optin_cookie() { |
||
178 | |||
179 | /** |
||
180 | * Handler for opt-in/opt-out AJAX request. |
||
181 | */ |
||
182 | public static function handle_optout_request() { |
||
190 | |||
191 | /** |
||
192 | * Handler for modal popup notice markup. |
||
193 | */ |
||
194 | public static function handle_optout_markup() { |
||
280 | } |
||
281 |