2018-04-25 01:13:59 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* WooCommerce abstract privacy class.
|
|
|
|
*
|
2018-04-26 10:29:51 +00:00
|
|
|
* @since 3.4.0
|
2018-04-25 01:13:59 +00:00
|
|
|
* @package WooCommerce/Abstracts
|
|
|
|
*/
|
|
|
|
|
2018-04-26 10:29:51 +00:00
|
|
|
defined( 'ABSPATH' ) || exit;
|
2018-04-25 01:13:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract class that is intended to be extended by
|
|
|
|
* specific privacy class. It handles the display
|
|
|
|
* of the privacy message of the privacy id to the admin,
|
|
|
|
* privacy data to be exported and privacy data to be deleted.
|
|
|
|
*
|
|
|
|
* @version 3.4.0
|
|
|
|
* @package WooCommerce/Abstracts
|
|
|
|
*/
|
|
|
|
abstract class WC_Abstract_Privacy {
|
|
|
|
/**
|
|
|
|
* This is the name of this object type.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2018-04-26 10:29:51 +00:00
|
|
|
public $name;
|
2018-04-25 01:13:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a list of exporters.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2018-04-26 10:29:51 +00:00
|
|
|
protected $exporters = array();
|
2018-04-25 01:13:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a list of erasers.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2018-04-26 10:29:51 +00:00
|
|
|
protected $erasers = array();
|
2018-04-25 01:13:59 +00:00
|
|
|
|
2018-05-18 15:07:36 +00:00
|
|
|
/**
|
|
|
|
* This is a priority for the wp_privacy_personal_data_exporters filter
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $export_priority;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a priority for the wp_privacy_personal_data_erasers filter
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $erase_priority;
|
|
|
|
|
2018-04-25 01:13:59 +00:00
|
|
|
/**
|
2018-06-05 12:29:20 +00:00
|
|
|
* WC_Abstract_Privacy Constructor.
|
2018-04-25 01:13:59 +00:00
|
|
|
*
|
2018-06-05 12:29:20 +00:00
|
|
|
* @param string $name Plugin identifier.
|
|
|
|
* @param int $export_priority Export priority.
|
|
|
|
* @param int $erase_priority Erase priority.
|
2018-04-25 01:13:59 +00:00
|
|
|
*/
|
2018-05-18 15:07:36 +00:00
|
|
|
public function __construct( $name = '', $export_priority = 5, $erase_priority = 10 ) {
|
2018-04-26 10:29:51 +00:00
|
|
|
$this->name = $name;
|
2018-05-18 15:07:36 +00:00
|
|
|
$this->export_priority = $export_priority;
|
|
|
|
$this->erase_priority = $erase_priority;
|
2018-04-26 10:29:51 +00:00
|
|
|
$this->init();
|
|
|
|
}
|
2018-04-25 01:13:59 +00:00
|
|
|
|
2018-04-26 10:29:51 +00:00
|
|
|
/**
|
|
|
|
* Hook in events.
|
|
|
|
*/
|
|
|
|
protected function init() {
|
2018-04-25 01:13:59 +00:00
|
|
|
add_action( 'admin_init', array( $this, 'add_privacy_message' ) );
|
2018-05-01 12:46:53 +00:00
|
|
|
// We set priority to 5 to help WooCommerce's findings appear before those from extensions in exported items.
|
2018-05-18 15:07:36 +00:00
|
|
|
add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'register_exporters' ), $this->export_priority );
|
|
|
|
add_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_erasers' ), $this->erase_priority );
|
2018-04-25 01:13:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the privacy message on WC privacy page.
|
|
|
|
*/
|
|
|
|
public function add_privacy_message() {
|
|
|
|
if ( function_exists( 'wp_add_privacy_policy_content' ) ) {
|
2018-04-26 10:29:51 +00:00
|
|
|
$content = $this->get_privacy_message();
|
|
|
|
|
|
|
|
if ( $content ) {
|
|
|
|
wp_add_privacy_policy_content( $this->name, $this->get_privacy_message() );
|
|
|
|
}
|
2018-04-25 01:13:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the message of the privacy to display.
|
|
|
|
* To be overloaded by the implementor.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-04-26 10:29:51 +00:00
|
|
|
public function get_privacy_message() {
|
|
|
|
return '';
|
|
|
|
}
|
2018-04-25 01:13:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Integrate this exporter implementation within the WordPress core exporters.
|
|
|
|
*
|
|
|
|
* @param array $exporters List of exporter callbacks.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function register_exporters( $exporters = array() ) {
|
2018-05-03 08:36:11 +00:00
|
|
|
foreach ( $this->exporters as $id => $exporter ) {
|
|
|
|
$exporters[ $id ] = $exporter;
|
2018-05-02 10:45:02 +00:00
|
|
|
}
|
|
|
|
return $exporters;
|
2018-04-25 01:13:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Integrate this eraser implementation within the WordPress core erasers.
|
|
|
|
*
|
|
|
|
* @param array $erasers List of eraser callbacks.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function register_erasers( $erasers = array() ) {
|
2018-05-03 08:36:11 +00:00
|
|
|
foreach ( $this->erasers as $id => $eraser ) {
|
|
|
|
$erasers[ $id ] = $eraser;
|
2018-05-02 10:45:02 +00:00
|
|
|
}
|
|
|
|
return $erasers;
|
2018-04-25 01:13:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add exporter to list of exporters.
|
|
|
|
*
|
2018-06-05 12:29:20 +00:00
|
|
|
* @param string $id ID of the Exporter.
|
|
|
|
* @param string $name Exporter name.
|
|
|
|
* @param string|array $callback Exporter callback.
|
|
|
|
*
|
|
|
|
* @return array
|
2018-04-25 01:13:59 +00:00
|
|
|
*/
|
2018-05-03 08:36:11 +00:00
|
|
|
public function add_exporter( $id, $name, $callback ) {
|
2018-05-03 08:47:30 +00:00
|
|
|
$this->exporters[ $id ] = array(
|
2018-04-25 01:13:59 +00:00
|
|
|
'exporter_friendly_name' => $name,
|
|
|
|
'callback' => $callback,
|
|
|
|
);
|
|
|
|
return $this->exporters;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-05-03 08:36:11 +00:00
|
|
|
* Add eraser to list of erasers.
|
2018-04-25 01:13:59 +00:00
|
|
|
*
|
2018-06-05 12:29:20 +00:00
|
|
|
* @param string $id ID of the Eraser.
|
|
|
|
* @param string $name Exporter name.
|
|
|
|
* @param string|array $callback Exporter callback.
|
|
|
|
*
|
|
|
|
* @return array
|
2018-04-25 01:13:59 +00:00
|
|
|
*/
|
2018-05-03 08:36:11 +00:00
|
|
|
public function add_eraser( $id, $name, $callback ) {
|
2018-05-03 08:47:30 +00:00
|
|
|
$this->erasers[ $id ] = array(
|
2018-04-25 01:13:59 +00:00
|
|
|
'eraser_friendly_name' => $name,
|
|
|
|
'callback' => $callback,
|
|
|
|
);
|
|
|
|
return $this->erasers;
|
|
|
|
}
|
|
|
|
}
|