| @@ -4,16 +4,10 @@ | ||
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmPersonalData { |
| 7 | 7 | |
| 8 | - /** | |
| 9 | - * @var int | |
| 10 | - */ | |
| 11 | 8 | private $limit = 200; |
| 12 | 9 | |
| 13 | - /** | |
| 14 | - * @var int | |
| 15 | - */ | |
| 16 | 10 | private $page = 1; |
| 17 | 11 | |
| 18 | 12 | public function __construct() { |
| 19 | 13 | add_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_data_eraser' ) ); |
| @@ -55,14 +49,8 @@ | ||
| 55 | 49 | |
| 56 | 50 | return $erasers; |
| 57 | 51 | } |
| 58 | 52 | |
| 59 | - /** | |
| 60 | - * @param string $email | |
| 61 | - * @param int $page | |
| 62 | - * | |
| 63 | - * @return array | |
| 64 | - */ | |
| 65 | 53 | public function export_data( $email, $page = 1 ) { |
| 66 | 54 | $this->page = absint( $page ); |
| 67 | 55 | |
| 68 | 56 | $data_to_export = array( |
| @@ -70,14 +58,13 @@ | ||
| 70 | 58 | 'done' => true, |
| 71 | 59 | ); |
| 72 | 60 | |
| 73 | 61 | $entries = $this->get_user_entries( $email ); |
| 74 | - | |
| 75 | 62 | if ( empty( $entries ) ) { |
| 76 | 63 | return $data_to_export; |
| 77 | 64 | } |
| 78 | 65 | |
| 79 | - foreach ( $entries as $entry ) { | |
| 66 | + foreach ( (array) $entries as $entry ) { | |
| 80 | 67 | $data_to_export['data'][] = array( |
| 81 | 68 | 'group_id' => 'formidable', |
| 82 | 69 | 'group_label' => __( 'Form Submissions', 'formidable' ), |
| 83 | 70 | 'item_id' => esc_attr( 'entry-' . $entry ), |
| @@ -90,11 +77,8 @@ | ||
| 90 | 77 | return $data_to_export; |
| 91 | 78 | } |
| 92 | 79 | |
| 93 | 80 | /** |
| 94 | - * @param string $email | |
| 95 | - * @param int $page | |
| 96 | - * | |
| 97 | 81 | * @return array |
| 98 | 82 | */ |
| 99 | 83 | public function erase_data( $email, $page = 1 ) { |
| 100 | 84 | $data_removed = array( |
| @@ -109,9 +93,8 @@ | ||
| 109 | 93 | } |
| 110 | 94 | |
| 111 | 95 | $this->page = absint( $page ); |
| 112 | 96 | $entries = $this->get_user_entries( $email ); |
| 113 | - | |
| 114 | 97 | if ( empty( $entries ) ) { |
| 115 | 98 | return $data_removed; |
| 116 | 99 | } |
| 117 | 100 | |
| @@ -116,9 +99,9 @@ | ||
| 116 | 99 | } |
| 117 | 100 | |
| 118 | 101 | // TODO: Add an option to anonymize the entries with wp_privacy_anonymize_data( 'email', 'e@e.com' ); |
| 119 | 102 | |
| 120 | - foreach ( $entries as $entry ) { | |
| 103 | + foreach ( (array) $entries as $entry ) { | |
| 121 | 104 | $removed = FrmEntry::destroy( $entry ); |
| 122 | 105 | |
| 123 | 106 | if ( $removed ) { |
| 124 | 107 | $data_removed['items_removed'] = true; |
| @@ -137,9 +120,9 @@ | ||
| 137 | 120 | * or with a field value that matches the email address |
| 138 | 121 | * |
| 139 | 122 | * @param string $email |
| 140 | 123 | * |
| 141 | - * @return array Entry ids | |
| 124 | + * @return array of entry ids | |
| 142 | 125 | */ |
| 143 | 126 | private function get_user_entries( $email ) { |
| 144 | 127 | $query_args = array( |
| 145 | 128 | 'order_by' => 'item_id ASC', |
| @@ -158,17 +141,14 @@ | ||
| 158 | 141 | $query_args['order_by'] = 'id ASC'; |
| 159 | 142 | |
| 160 | 143 | $entries_by_user = FrmDb::get_col( 'frm_items', array( 'user_id' => $user->ID ), 'id', $query_args ); |
| 161 | 144 | |
| 162 | - $entry_ids = array_merge( $entries_by_user, $entries_by_email ); | |
| 145 | + $entry_ids = array_merge( (array) $entries_by_user, (array) $entries_by_email ); | |
| 163 | 146 | $entry_ids = array_unique( array_filter( $entry_ids ) ); |
| 164 | 147 | |
| 165 | 148 | return $entry_ids; |
| 166 | 149 | } |
| 167 | 150 | |
| 168 | - /** | |
| 169 | - * @return string | |
| 170 | - */ | |
| 171 | 151 | private function get_current_page() { |
| 172 | 152 | $start = ( $this->page - 1 ) * $this->limit; |
| 173 | 153 | |
| 174 | 154 | return FrmDb::esc_limit( $start . ',' . $this->limit ); |
| @@ -182,9 +162,8 @@ | ||
| 182 | 162 | private function prepare_entry_data( $entry ) { |
| 183 | 163 | $entry = FrmEntry::getOne( $entry, true ); |
| 184 | 164 | |
| 185 | 165 | $entry_data = array(); |
| 186 | - | |
| 187 | 166 | foreach ( $entry->metas as $field_id => $meta ) { |
| 188 | 167 | $field = FrmField::getOne( $field_id ); |
| 189 | 168 | |
| 190 | 169 | $entry_data[] = array( |