|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Personal data exporters. |
|
4
|
|
|
* |
|
5
|
|
|
* @since 1.2.26 |
|
6
|
|
|
* @package GeoDirectory |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
defined( 'ABSPATH' ) || exit; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* GeoDir_Privacy_Exporters Class. |
|
13
|
|
|
*/ |
|
14
|
|
|
class GeoDir_Privacy_Exporters { |
|
15
|
|
|
/** |
|
16
|
|
|
* Finds and exports data which could be used to identify a person from GeoDirectory data associated with an email address. |
|
17
|
|
|
* |
|
18
|
|
|
* Posts are exported in blocks of 10 to avoid timeouts. |
|
19
|
|
|
* |
|
20
|
|
|
* @since 1.2.26 |
|
21
|
|
|
* @param string $email_address The user email address. |
|
22
|
|
|
* @param int $page Page. |
|
23
|
|
|
* @return array An array of personal data in name value pairs |
|
24
|
|
|
*/ |
|
25
|
|
|
public static function post_data_exporter( $email_address, $page ) { |
|
26
|
|
|
$done = false; |
|
|
|
|
|
|
27
|
|
|
$page = (int) $page; |
|
28
|
|
|
$user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data. |
|
29
|
|
|
$data_to_export = array(); |
|
30
|
|
|
|
|
31
|
|
|
$post_query = array( |
|
|
|
|
|
|
32
|
|
|
'limit' => 10, |
|
33
|
|
|
'page' => $page, |
|
34
|
|
|
'author' => array( $email_address ), |
|
35
|
|
|
); |
|
36
|
|
|
|
|
37
|
|
|
if ( $user instanceof WP_User ) { |
|
|
|
|
|
|
38
|
|
|
$order_query['author'][] = (int) $user->ID; |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$posts = array(); |
|
42
|
|
|
|
|
43
|
|
|
if ( 0 < count( $posts ) ) { |
|
44
|
|
|
foreach ( $posts as $post ) { |
|
45
|
|
|
$data_to_export[] = array( |
|
46
|
|
|
'group_id' => 'geodirectory_posts', |
|
47
|
|
|
'group_label' => __( 'Posts', 'geodirectory' ), |
|
48
|
|
|
'item_id' => 'post-' . $post->ID, |
|
49
|
|
|
'data' => self::get_post_personal_data( $post ), |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
$done = 10 > count( $posts ); |
|
53
|
|
|
} else { |
|
54
|
|
|
$done = true; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return array( |
|
58
|
|
|
'data' => $data_to_export, |
|
59
|
|
|
'done' => $done, |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Get personal data (key/value pairs) for an post object. |
|
65
|
|
|
* |
|
66
|
|
|
* @since 1.6.26 |
|
67
|
|
|
* @param WP_Post $post Post object. |
|
68
|
|
|
* @return array |
|
69
|
|
|
*/ |
|
70
|
|
|
protected static function get_post_personal_data( $post ) { |
|
71
|
|
|
$personal_data = array( |
|
72
|
|
|
array( |
|
73
|
|
|
'name' => __( 'Post ID', 'geodirectory' ), |
|
74
|
|
|
'value' => $post->ID, |
|
75
|
|
|
), |
|
76
|
|
|
array( |
|
77
|
|
|
'name' => __( 'Post Title', 'geodirectory' ), |
|
78
|
|
|
'value' => get_the_title( $post->ID ), |
|
79
|
|
|
), |
|
80
|
|
|
array( |
|
81
|
|
|
'name' => __( 'Post Date', 'geodirectory' ), |
|
82
|
|
|
'value' => date_i18n( get_option( 'date_format' ) . ', ' . get_option( 'time_format' ), strtotime( $post->post_date ) ), |
|
83
|
|
|
), |
|
84
|
|
|
// TODO more fields |
|
85
|
|
|
); |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Allow extensions to register their own personal data for this post for the export. |
|
89
|
|
|
* |
|
90
|
|
|
* @since 1.6.26 |
|
91
|
|
|
* @param array $personal_data Array of name value pairs to expose in the export. |
|
92
|
|
|
* @param WP_Post $post The post object. |
|
93
|
|
|
*/ |
|
94
|
|
|
$personal_data = apply_filters( 'geodir_privacy_export_post_personal_data', $personal_data, $post ); |
|
95
|
|
|
|
|
96
|
|
|
return $personal_data; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.