Update abstract class to use associative arrays

This commit is contained in:
Boro Sitnikovski 2018-05-03 10:08:29 +02:00
parent d584ed72b9
commit 0d981a000a
1 changed files with 20 additions and 2 deletions

View File

@ -39,6 +39,13 @@ abstract class WC_Abstract_Privacy {
*/
protected $erasers = array();
/**
* Track ordering for adding export/erase to WP array.
*
* @var int
*/
protected $count = 0;
/**
* Constructor
*
@ -49,6 +56,17 @@ abstract class WC_Abstract_Privacy {
$this->init();
}
/**
* Get next key to be added to the exporters/erasures list.
* Maintain order since the array is associative.
*
* @return string
*/
protected function get_next_key() {
$this->count++;
return sanitize_title( $this->name . '-' . $this->count );
}
/**
* Hook in events.
*/
@ -90,7 +108,7 @@ abstract class WC_Abstract_Privacy {
*/
public function register_exporters( $exporters = array() ) {
foreach ( $this->exporters as $exporter ) {
$exporters[] = $exporter;
$exporters[ $this->get_next_key() ] = $exporter;
}
return $exporters;
}
@ -103,7 +121,7 @@ abstract class WC_Abstract_Privacy {
*/
public function register_erasers( $erasers = array() ) {
foreach ( $this->erasers as $eraser ) {
$erasers[] = $eraser;
$erasers[ $this->get_next_key() ] = $eraser;
}
return $erasers;
}