data-stores
3 years ago
legacy
4 years ago
widgets
4 years ago
class-yith-wcwl-admin.php
3 years ago
class-yith-wcwl-ajax-handler.php
3 years ago
class-yith-wcwl-cron.php
3 years ago
class-yith-wcwl-exception.php
4 years ago
class-yith-wcwl-form-handler.php
3 years ago
class-yith-wcwl-frontend.php
3 years ago
class-yith-wcwl-install.php
4 years ago
class-yith-wcwl-privacy.php
3 years ago
class-yith-wcwl-session.php
3 years ago
class-yith-wcwl-shortcode.php
3 years ago
class-yith-wcwl-wishlist-factory.php
3 years ago
class-yith-wcwl-wishlist-item.php
3 years ago
class-yith-wcwl-wishlist.php
3 years ago
class-yith-wcwl.php
3 years ago
functions-yith-wcwl.php
3 years ago
class-yith-wcwl-privacy.php
368 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Privacy class; added to let customer export personal data |
| 4 | * |
| 5 | * @author YITH |
| 6 | * @package YITH\Wishlist\Classes |
| 7 | * @version 3.0.0 |
| 8 | */ |
| 9 | |
| 10 | if ( ! defined( 'YITH_WCWL' ) ) { |
| 11 | exit; |
| 12 | } // Exit if accessed directly |
| 13 | |
| 14 | if ( ! class_exists( 'YITH_WCWL_Privacy' ) ) { |
| 15 | /** |
| 16 | * YITH WCWL Exporter |
| 17 | * |
| 18 | * @since 2.2.2 |
| 19 | */ |
| 20 | class YITH_WCWL_Privacy extends YITH_Privacy_Plugin_Abstract { |
| 21 | |
| 22 | /** |
| 23 | * Constructor method |
| 24 | * |
| 25 | * @return \YITH_WCWL_Privacy |
| 26 | * @since 2.2.2 |
| 27 | */ |
| 28 | public function __construct() { |
| 29 | |
| 30 | parent::__construct( 'YITH WooCommerce Wishlist' ); |
| 31 | |
| 32 | // set up wishlist data exporter. |
| 33 | add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'register_exporter' ) ); |
| 34 | |
| 35 | // set up wishlist data eraser. |
| 36 | add_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_eraser' ) ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Retrieves privacy example text for wishlist plugin |
| 41 | * |
| 42 | * @param string $section Section of the message to retrieve. |
| 43 | * |
| 44 | * @return string Privacy message |
| 45 | * @since 2.2.2 |
| 46 | */ |
| 47 | public function get_privacy_message( $section ) { |
| 48 | $content = ''; |
| 49 | |
| 50 | switch ( $section ) { |
| 51 | case 'collect_and_store': |
| 52 | $content = '<p>' . __( 'While you visit our site, we’ll track:', 'yith-woocommerce-wishlist' ) . '</p>' . |
| 53 | '<ul>' . |
| 54 | '<li>' . __( 'Products you’ve added to the wishlist: we’ll use this to show you and other users your favourite products, and to create targeted email campaigns.', 'yith-woocommerce-wishlist' ) . '</li>' . |
| 55 | '<li>' . __( 'Wishlists you’ve created: we’ll keep track of the wishlists you create, and make them visible to the store staff', 'yith-woocommerce-wishlist' ) . '</li>' . |
| 56 | '</ul>' . |
| 57 | '<p>' . __( 'We’ll also use cookies to keep track of wishlist contents while you’re browsing our site.', 'yith-woocommerce-wishlist' ) . '</p>'; |
| 58 | break; |
| 59 | case 'has_access': |
| 60 | $content = '<p>' . __( 'Members of our team have access to the information you provide us with. For example, both Administrators and Shop Managers can access:', 'yith-woocommerce-wishlist' ) . '</p>' . |
| 61 | '<ul>' . |
| 62 | '<li>' . __( 'Wishlist details, such as products added, date of addition, name and privacy settings of your wishlists', 'yith-woocommerce-wishlist' ) . '</li>' . |
| 63 | '</ul>' . |
| 64 | '<p>' . __( 'Our team members have access to this information to offer you better deals for the products you love.', 'yith-woocommerce-wishlist' ) . '</p>'; |
| 65 | break; |
| 66 | case 'share': |
| 67 | case 'payments': |
| 68 | default: |
| 69 | break; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * APPLY_FILTERS: yith_wcwl_privacy_policy_content |
| 74 | * |
| 75 | * Filter the content of the privacy policy. |
| 76 | * |
| 77 | * @param string $content Privacy policy content |
| 78 | * @param string $section Privacy policy section |
| 79 | * |
| 80 | * @return string |
| 81 | */ |
| 82 | return apply_filters( 'yith_wcwl_privacy_policy_content', $content, $section ); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Register exporters for wishlist plugin |
| 87 | * |
| 88 | * @param array $exporters Array of currently registered exporters. |
| 89 | * @return array Array of filtered exporters |
| 90 | * @since 2.2.2 |
| 91 | */ |
| 92 | public function register_exporter( $exporters ) { |
| 93 | $exporters['yith_wcwl_exporter'] = array( |
| 94 | 'exporter_friendly_name' => __( 'Customer wishlists', 'yith-woocommerce-wishlist' ), |
| 95 | 'callback' => array( $this, 'wishlist_data_exporter' ), |
| 96 | ); |
| 97 | |
| 98 | return $exporters; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Register eraser for wishlist plugin |
| 103 | * |
| 104 | * @param array $erasers Array of currently registered erasers. |
| 105 | * @return array Array of filtered erasers |
| 106 | * @since 2.2.2 |
| 107 | */ |
| 108 | public function register_eraser( $erasers ) { |
| 109 | $erasers['yith_wcwl_eraser'] = array( |
| 110 | 'eraser_friendly_name' => __( 'Customer wishlists', 'yith-woocommerce-wishlist' ), |
| 111 | 'callback' => array( $this, 'wishlist_data_eraser' ), |
| 112 | ); |
| 113 | |
| 114 | return $erasers; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Export user wishlists (only available for authenticated users' wishlist) |
| 119 | * |
| 120 | * @param string $email_address Email of the users that requested export. |
| 121 | * @param int $page Current page processed. |
| 122 | * @return array Array of data to export |
| 123 | * @since 2.2.2 |
| 124 | */ |
| 125 | public function wishlist_data_exporter( $email_address, $page ) { |
| 126 | $done = true; |
| 127 | $page = (int) $page; |
| 128 | $offset = 10 * ( $page - 1 ); |
| 129 | $user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data. |
| 130 | $data_to_export = array(); |
| 131 | |
| 132 | if ( $user instanceof WP_User ) { |
| 133 | $wishlists = YITH_WCWL()->get_wishlists( |
| 134 | array( |
| 135 | 'limit' => 10, |
| 136 | 'offset' => $offset, |
| 137 | 'user_id' => $user->ID, |
| 138 | 'orderby' => 'ID', |
| 139 | 'order' => 'ASC', |
| 140 | ) |
| 141 | ); |
| 142 | |
| 143 | if ( 0 < count( $wishlists ) ) { |
| 144 | foreach ( $wishlists as $wishlist ) { |
| 145 | $data_to_export[] = array( |
| 146 | 'group_id' => 'yith_wcwl_wishlist', |
| 147 | 'group_label' => __( 'Wishlists', 'yith-woocommerce-wishlist' ), |
| 148 | 'item_id' => 'wishlist-' . $wishlist->get_id(), |
| 149 | 'data' => $this->get_wishlist_personal_data( $wishlist ), |
| 150 | ); |
| 151 | } |
| 152 | $done = 10 > count( $wishlists ); |
| 153 | } else { |
| 154 | $done = true; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | return array( |
| 159 | 'data' => $data_to_export, |
| 160 | 'done' => $done, |
| 161 | ); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Deletes user wishlists (only available for authenticated users' wishlist) |
| 166 | * |
| 167 | * @param string $email_address Email of the users that requested export. |
| 168 | * @param int $page Current page processed. |
| 169 | * @return array Result of the operation |
| 170 | * @since 2.2.2 |
| 171 | */ |
| 172 | public function wishlist_data_eraser( $email_address, $page ) { |
| 173 | global $wpdb; |
| 174 | |
| 175 | $page = (int) $page; |
| 176 | $offset = 10 * ( $page - 1 ); |
| 177 | $user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data. |
| 178 | $response = array( |
| 179 | 'items_removed' => false, |
| 180 | 'items_retained' => false, |
| 181 | 'messages' => array(), |
| 182 | 'done' => true, |
| 183 | ); |
| 184 | |
| 185 | if ( ! $user instanceof WP_User ) { |
| 186 | return $response; |
| 187 | } |
| 188 | |
| 189 | $wishlists = YITH_WCWL()->get_wishlists( |
| 190 | array( |
| 191 | 'limit' => 10, |
| 192 | 'offset' => $offset, |
| 193 | 'user_id' => $user->ID, |
| 194 | 'orderby' => 'ID', |
| 195 | 'order' => 'ASC', |
| 196 | ) |
| 197 | ); |
| 198 | |
| 199 | if ( 0 < count( $wishlists ) ) { |
| 200 | foreach ( $wishlists as $wishlist ) { |
| 201 | /** |
| 202 | * APPLY_FILTERS: yith_wcwl_privacy_erase_wishlist_personal_data |
| 203 | * |
| 204 | * Filter whether to delete the personal data from the wishlist. |
| 205 | * |
| 206 | * @param bool $condition Whether to delete personal data or not |
| 207 | * @param YITH_WCWL_Wishlist $wishlist Wishlist object |
| 208 | * |
| 209 | * @return bool |
| 210 | */ |
| 211 | if ( apply_filters( 'yith_wcwl_privacy_erase_wishlist_personal_data', true, $wishlist ) ) { |
| 212 | /** |
| 213 | * DO_ACTION: yith_wcwl_privacy_before_remove_wishlist_personal_data |
| 214 | * |
| 215 | * Allows to fire some action before deleting the personal data from the wishlist. |
| 216 | * |
| 217 | * @param YITH_WCWL_Wishlist $wishlist Wishlist object |
| 218 | */ |
| 219 | do_action( 'yith_wcwl_privacy_before_remove_wishlist_personal_data', $wishlist ); |
| 220 | |
| 221 | $wishlist->delete(); |
| 222 | |
| 223 | /** |
| 224 | * DO_ACTION: yith_wcwl_privacy_remove_wishlist_personal_data |
| 225 | * |
| 226 | * Allows to fire some action when deleting the personal data from the wishlist. |
| 227 | * |
| 228 | * @param YITH_WCWL_Wishlist $wishlist Wishlist object |
| 229 | */ |
| 230 | do_action( 'yith_wcwl_privacy_remove_wishlist_personal_data', $wishlist ); |
| 231 | |
| 232 | /* Translators: %s Order number. */ |
| 233 | $response['messages'][] = sprintf( __( 'Removed wishlist %s.', 'yith-woocommerce-wishlist' ), $wishlist->get_token() ); |
| 234 | $response['items_removed'] = true; |
| 235 | } else { |
| 236 | /* Translators: %s Order number. */ |
| 237 | $response['messages'][] = sprintf( __( 'Wishlist %s has been retained.', 'yith-woocommerce-wishlist' ), $wishlist->get_token() ); |
| 238 | $response['items_retained'] = true; |
| 239 | } |
| 240 | } |
| 241 | $response['done'] = 10 > count( $wishlists ); |
| 242 | } else { |
| 243 | $response['done'] = true; |
| 244 | } |
| 245 | |
| 246 | return $response; |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * Retrieves data to export for each user's wishlist |
| 251 | * |
| 252 | * @param \YITH_WCWL_Wishlist $wishlist Wishlist. |
| 253 | * @return array Data to export |
| 254 | * @since 2.2.2 |
| 255 | */ |
| 256 | protected function get_wishlist_personal_data( $wishlist ) { |
| 257 | $personal_data = array(); |
| 258 | |
| 259 | /** |
| 260 | * APPLY_FILTERS: yith_wcwl_privacy_export_wishlist_personal_data_props |
| 261 | * |
| 262 | * Filter the personal data props to export from the wishlist. |
| 263 | * |
| 264 | * @param array $data_to_export Personal data to export |
| 265 | * @param YITH_WCWL_Wishlist $wishlist Wishlist object |
| 266 | * |
| 267 | * @return array |
| 268 | */ |
| 269 | $props_to_export = apply_filters( |
| 270 | 'yith_wcwl_privacy_export_wishlist_personal_data_props', |
| 271 | array( |
| 272 | 'wishlist_token' => __( 'Token', 'yith-woocommerce-wishlist' ), |
| 273 | 'wishlist_url' => __( 'Wishlist URL', 'yith-woocommerce-wishlist' ), |
| 274 | 'wishlist_name' => __( 'Title', 'yith-woocommerce-wishlist' ), |
| 275 | 'dateadded' => _x( 'Created on', 'date when wishlist was created', 'yith-woocommerce-wishlist' ), |
| 276 | 'wishlist_privacy' => __( 'Visibility', 'yith-woocommerce-wishlist' ), |
| 277 | 'items' => __( 'Items added', 'yith-woocommerce-wishlist' ), |
| 278 | ), |
| 279 | $wishlist |
| 280 | ); |
| 281 | |
| 282 | foreach ( $props_to_export as $prop => $name ) { |
| 283 | $value = ''; |
| 284 | |
| 285 | switch ( $prop ) { |
| 286 | case 'items': |
| 287 | $item_names = array(); |
| 288 | $items = $wishlist->get_items(); |
| 289 | |
| 290 | foreach ( $items as $item ) { |
| 291 | $product = $item->get_product(); |
| 292 | |
| 293 | if ( ! $product ) { |
| 294 | continue; |
| 295 | } |
| 296 | |
| 297 | $item_name = $product->get_name() . ' x ' . $item['quantity']; |
| 298 | |
| 299 | if ( $item->get_date_added() ) { |
| 300 | $item_name .= ' (on: ' . $item->get_date_added() . ')'; |
| 301 | } |
| 302 | |
| 303 | $item_names[] = $item_name; |
| 304 | } |
| 305 | |
| 306 | $value = implode( ', ', $item_names ); |
| 307 | break; |
| 308 | case 'wishlist_url': |
| 309 | $wishlist_url = $wishlist->get_url(); |
| 310 | |
| 311 | $value = sprintf( '<a href="%1$s">%1$s</a>', $wishlist_url ); |
| 312 | break; |
| 313 | case 'wishlist_name': |
| 314 | $wishlist_name = $wishlist->get_formatted_name(); |
| 315 | |
| 316 | $value = $wishlist_name ? $wishlist_name : get_option( 'yith_wcwl_wishlist_title' ); |
| 317 | break; |
| 318 | case 'dateadded': |
| 319 | $value = $wishlist->get_date_added(); |
| 320 | break; |
| 321 | case 'wishlist_privacy': |
| 322 | $value = $wishlist->get_formatted_privacy(); |
| 323 | break; |
| 324 | default: |
| 325 | if ( isset( $wishlist[ $prop ] ) ) { |
| 326 | $value = $wishlist[ $prop ]; |
| 327 | } |
| 328 | break; |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * APPLY_FILTERS: yith_wcwl_privacy_export_wishlist_personal_data_prop |
| 333 | * |
| 334 | * Filter the personal data value to export from the wishlist. |
| 335 | * |
| 336 | * @param string $value Value to export |
| 337 | * @param string $prop Prop data to export |
| 338 | * @param YITH_WCWL_Wishlist $wishlist Wishlist object |
| 339 | * |
| 340 | * @return string |
| 341 | */ |
| 342 | $value = apply_filters( 'yith_wcwl_privacy_export_wishlist_personal_data_prop', $value, $prop, $wishlist ); |
| 343 | |
| 344 | if ( $value ) { |
| 345 | $personal_data[] = array( |
| 346 | 'name' => $name, |
| 347 | 'value' => $value, |
| 348 | ); |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | /** |
| 353 | * APPLY_FILTERS: yith_wcwl_privacy_export_wishlist_personal_data |
| 354 | * |
| 355 | * Filter the personal data to export from the wishlist. |
| 356 | * |
| 357 | * @param array $personal_data Personal data to export |
| 358 | * @param YITH_WCWL_Wishlist $wishlist Wishlist object |
| 359 | * |
| 360 | * @return array |
| 361 | */ |
| 362 | $personal_data = apply_filters( 'yith_wcwl_privacy_export_wishlist_personal_data', $personal_data, $wishlist ); |
| 363 | |
| 364 | return $personal_data; |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 |