Merge pull request #19943 from woocommerce/tweak/associative-array-gdpr-registration

Update GDPR abstract class to use associative arrays
This commit is contained in:
Mike Jolley 2018-05-03 09:51:03 +01:00 committed by GitHub
commit 6b8123cdf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 18 deletions

View File

@ -89,8 +89,8 @@ abstract class WC_Abstract_Privacy {
* @return array
*/
public function register_exporters( $exporters = array() ) {
foreach ( $this->exporters as $exporter ) {
$exporters[] = $exporter;
foreach ( $this->exporters as $id => $exporter ) {
$exporters[ $id ] = $exporter;
}
return $exporters;
}
@ -102,8 +102,8 @@ abstract class WC_Abstract_Privacy {
* @return array
*/
public function register_erasers( $erasers = array() ) {
foreach ( $this->erasers as $eraser ) {
$erasers[] = $eraser;
foreach ( $this->erasers as $id => $eraser ) {
$erasers[ $id ] = $eraser;
}
return $erasers;
}
@ -111,11 +111,12 @@ abstract class WC_Abstract_Privacy {
/**
* Add exporter to list of exporters.
*
* @param string $name Exporter name.
* @param string $id ID of the Exporter.
* @param string $name Exporter name.
* @param string $callback Exporter callback.
*/
public function add_exporter( $name, $callback ) {
$this->exporters[] = array(
public function add_exporter( $id, $name, $callback ) {
$this->exporters[ $id ] = array(
'exporter_friendly_name' => $name,
'callback' => $callback,
);
@ -123,13 +124,14 @@ abstract class WC_Abstract_Privacy {
}
/**
* Add eraser to list of exporters.
* Add eraser to list of erasers.
*
* @param string $name Exporter name.
* @param string $id ID of the Eraser.
* @param string $name Exporter name.
* @param string $callback Exporter callback.
*/
public function add_eraser( $name, $callback ) {
$this->erasers[] = array(
public function add_eraser( $id, $name, $callback ) {
$this->erasers[ $id ] = array(
'eraser_friendly_name' => $name,
'callback' => $callback,
);

View File

@ -24,7 +24,7 @@ class WC_Privacy extends WC_Abstract_Privacy {
* Init - hook into events.
*/
public function __construct() {
parent::__construct( 'WooCommerce' );
parent::__construct( __( 'WooCommerce', 'woocommerce' ) );
if ( ! self::$background_process ) {
self::$background_process = new WC_Privacy_Background_Process();
@ -35,14 +35,14 @@ class WC_Privacy extends WC_Abstract_Privacy {
include_once 'class-wc-privacy-exporters.php';
// This hook registers WooCommerce data exporters.
$this->add_exporter( __( 'Customer Data', 'woocommerce' ), array( 'WC_Privacy_Exporters', 'customer_data_exporter' ) );
$this->add_exporter( __( 'Customer Orders', 'woocommerce' ), array( 'WC_Privacy_Exporters', 'order_data_exporter' ) );
$this->add_exporter( __( 'Customer Downloads', 'woocommerce' ), array( 'WC_Privacy_Exporters', 'download_data_exporter' ) );
$this->add_exporter( 'woocommerce-customer-data', __( 'Customer Data', 'woocommerce' ), array( 'WC_Privacy_Exporters', 'customer_data_exporter' ) );
$this->add_exporter( 'woocommerce-customer-orders', __( 'Customer Orders', 'woocommerce' ), array( 'WC_Privacy_Exporters', 'order_data_exporter' ) );
$this->add_exporter( 'woocommerce-customer-downloads', __( 'Customer Downloads', 'woocommerce' ), array( 'WC_Privacy_Exporters', 'download_data_exporter' ) );
// This hook registers WooCommerce data erasers.
$this->add_eraser( __( 'Customer Data', 'woocommerce' ), array( 'WC_Privacy_Erasers', 'customer_data_eraser' ) );
$this->add_eraser( __( 'Customer Orders', 'woocommerce' ), array( 'WC_Privacy_Erasers', 'order_data_eraser' ) );
$this->add_eraser( __( 'Customer Downloads', 'woocommerce' ), array( 'WC_Privacy_Erasers', 'download_data_eraser' ) );
$this->add_eraser( 'woocommerce-customer-data', __( 'Customer Data', 'woocommerce' ), array( 'WC_Privacy_Erasers', 'customer_data_eraser' ) );
$this->add_eraser( 'woocommerce-customer-orders', __( 'Customer Orders', 'woocommerce' ), array( 'WC_Privacy_Erasers', 'order_data_eraser' ) );
$this->add_eraser( 'woocommerce-customer-downloads', __( 'Customer Downloads', 'woocommerce' ), array( 'WC_Privacy_Erasers', 'download_data_eraser' ) );
// Cleanup orders daily - this is a callback on a daily cron event.
add_action( 'woocommerce_cleanup_personal_data', array( $this, 'queue_cleanup_personal_data' ) );