| @@ -1,14 +1,11 @@ | ||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | - die( 'You are not allowed to call this page directly.' ); | |
| 4 | -} | |
| 5 | 2 | |
| 6 | 3 | class FrmPersonalData { |
| 7 | 4 | |
| 8 | 5 | private $limit = 200; |
| 9 | 6 | |
| 10 | - private $page = 1; | |
| 7 | + private $page = 1; | |
| 11 | 8 | |
| 12 | 9 | public function __construct() { |
| 13 | 10 | add_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_data_eraser' ) ); |
| 14 | 11 | add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'register_exporter' ) ); |
| @@ -17,11 +14,9 @@ | ||
| 17 | 14 | /** |
| 18 | 15 | * Add options to the WordPress personal data exporter |
| 19 | 16 | * |
| 20 | 17 | * @since 3.02 |
| 21 | - * | |
| 22 | 18 | * @param array $exporters |
| 23 | - * | |
| 24 | 19 | * @return array |
| 25 | 20 | */ |
| 26 | 21 | public function register_exporter( $exporters ) { |
| 27 | 22 | $exporters['formidable-exporter'] = array( |
| @@ -27,9 +22,8 @@ | ||
| 27 | 22 | $exporters['formidable-exporter'] = array( |
| 28 | 23 | 'exporter_friendly_name' => __( 'Formidable Forms Exporter', 'formidable' ), |
| 29 | 24 | 'callback' => array( $this, 'export_data' ), |
| 30 | 25 | ); |
| 31 | - | |
| 32 | 26 | return $exporters; |
| 33 | 27 | } |
| 34 | 28 | |
| 35 | 29 | /** |
| @@ -35,11 +29,9 @@ | ||
| 35 | 29 | /** |
| 36 | 30 | * Add options to the WordPress personal data eraser |
| 37 | 31 | * |
| 38 | 32 | * @since 3.02 |
| 39 | - * | |
| 40 | 33 | * @param array $erasers |
| 41 | - * | |
| 42 | 34 | * @return array |
| 43 | 35 | */ |
| 44 | 36 | public function register_data_eraser( $erasers ) { |
| 45 | 37 | $erasers['formidable-eraser'] = array( |
| @@ -49,11 +41,8 @@ | ||
| 49 | 41 | |
| 50 | 42 | return $erasers; |
| 51 | 43 | } |
| 52 | 44 | |
| 53 | - /** | |
| 54 | - * @return array | |
| 55 | - */ | |
| 56 | 45 | public function export_data( $email, $page = 1 ) { |
| 57 | 46 | $this->page = absint( $page ); |
| 58 | 47 | |
| 59 | 48 | $data_to_export = array( |
| @@ -75,9 +64,8 @@ | ||
| 75 | 64 | ); |
| 76 | 65 | } |
| 77 | 66 | |
| 78 | 67 | $data_to_export['done'] = count( $entries ) < $this->limit; |
| 79 | - | |
| 80 | 68 | return $data_to_export; |
| 81 | 69 | } |
| 82 | 70 | |
| 83 | 71 | /** |
| @@ -95,9 +83,9 @@ | ||
| 95 | 83 | return $data_removed; |
| 96 | 84 | } |
| 97 | 85 | |
| 98 | 86 | $this->page = absint( $page ); |
| 99 | - $entries = $this->get_user_entries( $email ); | |
| 87 | + $entries = $this->get_user_entries( $email ); | |
| 100 | 88 | if ( empty( $entries ) ) { |
| 101 | 89 | return $data_removed; |
| 102 | 90 | } |
| 103 | 91 | |
| @@ -122,9 +110,8 @@ | ||
| 122 | 110 | * Get all entries that were submitted by this user while logged in, |
| 123 | 111 | * or with a field value that matches the email address |
| 124 | 112 | * |
| 125 | 113 | * @param string $email |
| 126 | - * | |
| 127 | 114 | * @return array of entry ids |
| 128 | 115 | */ |
| 129 | 116 | private function get_user_entries( $email ) { |
| 130 | 117 | $query_args = array( |
| @@ -132,9 +119,8 @@ | ||
| 132 | 119 | 'limit' => $this->get_current_page(), |
| 133 | 120 | ); |
| 134 | 121 | |
| 135 | 122 | $user = get_user_by( 'email', $email ); |
| 136 | - | |
| 137 | 123 | $entries_by_email = FrmDb::get_col( 'frm_item_metas', array( 'meta_value' => $email ), 'item_id', $query_args ); |
| 138 | 124 | |
| 139 | 125 | if ( empty( $user ) ) { |
| 140 | 126 | // no matching user, so return the entry ids we have |
| @@ -146,21 +132,18 @@ | ||
| 146 | 132 | $entries_by_user = FrmDb::get_col( 'frm_items', array( 'user_id' => $user->ID ), 'id', $query_args ); |
| 147 | 133 | |
| 148 | 134 | $entry_ids = array_merge( (array) $entries_by_user, (array) $entries_by_email ); |
| 149 | 135 | $entry_ids = array_unique( array_filter( $entry_ids ) ); |
| 150 | - | |
| 151 | 136 | return $entry_ids; |
| 152 | 137 | } |
| 153 | 138 | |
| 154 | 139 | private function get_current_page() { |
| 155 | 140 | $start = ( $this->page - 1 ) * $this->limit; |
| 156 | - | |
| 157 | 141 | return FrmDb::esc_limit( $start . ',' . $this->limit ); |
| 158 | 142 | } |
| 159 | 143 | |
| 160 | 144 | /** |
| 161 | 145 | * @param int $entry |
| 162 | - * | |
| 163 | 146 | * @return array |
| 164 | 147 | */ |
| 165 | 148 | private function prepare_entry_data( $entry ) { |
| 166 | 149 | $entry = FrmEntry::getOne( $entry, true ); |