Test Failed
Push — master ( b6268a...3d95f3 )
by Stiofan
59s queued 10s
created

GeoDir_Privacy::allow_erase_reviews_data()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Privacy/GDPR related functionality which ties into WordPress functionality.
4
 *
5
 * @since 1.6.26
6
 * @package GeoDirectory
7
 */
8
9
defined( 'ABSPATH' ) || exit;
10
11
/**
12
 * GeoDir_Privacy Class.
13
 */
14
class GeoDir_Privacy extends GeoDir_Abstract_Privacy {
15
16
	/**
17
	 * Background process to clean up orders.
18
	 *
19
	 * @var GeoDir_Privacy_Background_Process
20
	 */
21
	protected static $background_process;
22
23
	/**
24
	 * Init - hook into events.
25
	 */
26
	public function __construct() {
27
		parent::__construct( __( 'GeoDirectory', 'geodirectory' ) );
28
29
		if ( ! self::$background_process ) {
30
			self::$background_process = new GeoDir_Privacy_Background_Process();
31
		}
32
33
		// Include supporting classes.
34
		include_once( 'class-geodir-privacy-erasers.php' );
35
		include_once( 'class-geodir-privacy-exporters.php' );
36
37
		$gd_post_types = geodir_get_posttypes( 'object' );
38
39
		if ( ! empty( $gd_post_types ) ) {
40
			foreach ( $gd_post_types as $post_type => $info ) {
0 ignored issues
show
Bug introduced by
The expression $gd_post_types of type array|object|string is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
41
				$name = $info->labels->name;
42
43
				if ( self::allow_export_post_type_data( $post_type ) ) {
44
					// This hook registers GeoDirectory data exporters.
45
					$this->add_exporter( 'geodirectory-post-' . $post_type, wp_sprintf( __( 'User %s', 'geodirectory' ), $name ), array( 'GeoDir_Privacy_Exporters', 'post_data_exporter' ) );
0 ignored issues
show
Documentation introduced by
array('GeoDir_Privacy_Ex..., 'post_data_exporter') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
46
				}
47
			}
48
		}
49
50
		// Handles custom anonomization types not included in core.
51
		add_filter( 'wp_privacy_anonymize_data', array( $this, 'anonymize_custom_data_types' ), 10, 3 );
52
53
		if ( self::allow_export_reviews_data() ) {
54
			// Review data export
55
			add_filter( 'wp_privacy_personal_data_export_page', array( 'GeoDir_Privacy_Exporters', 'review_data_exporter' ), 10, 7 );
56
		}
57
58
		if ( self::allow_erase_reviews_data() ) {
59
			// Review data erase
60
			$this->add_eraser( 'geodirectory-post-reviews', __( 'User Listing Reviews', 'geodirectory' ), array( 'GeoDir_Privacy_Erasers', 'review_data_eraser' ) );
0 ignored issues
show
Documentation introduced by
array('GeoDir_Privacy_Er..., 'review_data_eraser') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
61
		}
62
	}
63
64
	/**
65
	 * Add privacy policy content for the privacy policy page.
66
	 *
67
	 * @since 1.6.26
68
	 *
69
	 * @return string The default policy content.
70
	 */
71
	public function get_privacy_message() {
72
		$content = '';
73
74
		// Start of the suggested privacy policy text.
75
		$content .=
76
			'<div class="geodir-privacy-text">';
77
		$content .=
78
			'<h2>' . __( 'Who we are' ) . '</h2>';
79
		$content .=
80
			'<p>' . __( 'GeoDirectory is the only WordPress directory plugin on the market that can scale to millions of listings and withstand the battering of traffic that comes along with that.' ) . '</p>';
81
82
			'<h2>' . __( 'What personal data we collect and why we collect it' ) . '</h2>';
83
		$content .=
84
			'<p>' . __( 'In this section you should note what personal data you collect from users and site visitors. This may include personal data, such as name, email address, personal account preferences; transactional data, such as purchase information; and technical data, such as information about cookies.' ) . '</p>' .
85
			'<p>' . __( 'You should also note any collection and retention of sensitive personal data, such as data concerning health.' ) . '</p>' .
86
			'<p>' . __( 'In addition to listing what personal data you collect, you need to note why you collect it. These explanations must note either the legal basis for your data collection and retention or the active consent the user has given.' ) . '</p>' .
87
			'<p>' . __( 'Personal data is not just created by a user&#8217;s interactions with your site. Personal data is also generated from technical processes such as contact forms, comments, cookies, analytics, and third party embeds.' ) . '</p>' .
88
			'<p>' . __( 'By default WordPress does not collect any personal data about visitors, and only collects the data shown on the User Profile screen from registered users. However some of your plugins may collect personal data. You should add the relevant information below.' ) . '</p>';
89
90
		$content .=
91
			'<h3>' . __( 'Posts' ) . '</h3>';
92
		$content .=
93
			'<p>' . __( 'In this subsection you should note what information is captured through posts. We have noted the data which WordPress collects by default.' ) . '</p>' . 
94
			'<p>' . __( 'When users add posts on the site we collect the data shown in the posts form, and also the visitor&#8217;s IP address and browser user agent string to help spam detection.' ) . '</p>' .
95
			'<p>' . __( 'An anonymized string created from your email address (also called a hash) may be provided to the Gravatar service to see if you are using it. The Gravatar service privacy policy is available here: https://automattic.com/privacy/. After approval of your post, your profile picture is visible to the public in the context of your post.' ) . '</p>';
96
97
		$content .=
98
			'<h3>' . __( 'Reviews' ) . '</h3>';
99
		$content .=
100
			'<p>' . __( 'In this subsection you should note what information is captured through reviews. We have noted the data which WordPress collects by default.' ) . '</p>' . 
101
			'<p>' . __( 'When visitors leave reviews on the site we collect the data shown in the reviews form, and also the visitor&#8217;s IP address and browser user agent string to help spam detection.' ) . '</p>' .
102
			'<p>' . __( 'An anonymized string created from your email address (also called a hash) may be provided to the Gravatar service to see if you are using it. The Gravatar service privacy policy is available here: https://automattic.com/privacy/. After approval of your review, your profile picture is visible to the public in the context of your review.' ) . '</p>';
103
104
		$content .=
105
			'<h3>' . __( 'Media' ) . '</h3>';
106
		$content .=
107
			'<p>' . __( 'In this subsection you should note what information may be disclosed by users who can upload media files. All uploaded files are usually publicly accessible.' ) . '</p>' . 
108
			'<p>' . __( 'If you upload images to the website, you should avoid uploading images with embedded location data (EXIF GPS) included. Visitors to the website can download and extract any location data from images on the website.' ) . '</p>';
109
110
		$content .=
111
			'<h2>' . __( 'How long we retain your data' ) . '</h2>';
112
		$content .=
113
			'<p>' . __( 'In this section you should explain how long you retain personal data collected or processed by the web site. While it is your responsibility to come up with the schedule of how long you keep each dataset for and why you keep it, that information does need to be listed here. For example, you may want to say that you keep contact form entries for six months, analytics records for a year, and customer purchase records for ten years.' ) . '</p>' . 
114
			'<p>' . __( 'If you leave a comment, the comment and its metadata are retained indefinitely. This is so we can recognize and approve any follow-up comments automatically instead of holding them in a moderation queue.' ) . '</p>' .
115
			'<p>' . __( 'For users that register on our website (if any), we also store the personal information they provide in their user profile. All users can see, edit, or delete their personal information at any time (except they cannot change their username). Website administrators can also see and edit that information.' ) . '</p>' .
116
117
			'<h2>' . __( 'What rights you have over your data' ) . '</h2>';
118
		$content .=
119
			'<p>' . __( 'In this section you should explain what rights your users have over their data and how they can invoke those rights.' ) . '</p>' . 
120
			'<p>' . __( 'If you have an account on this site, or have left comments, you can request to receive an exported file of the personal data we hold about you, including any data you have provided to us. You can also request that we erase any personal data we hold about you. This does not include any data we are obliged to keep for administrative, legal, or security purposes.' ) . '</p>';
121
122
		$content .=
123
			'<h2>' . __( 'Where we send your data' ) . '</h2>';
124
		$content .=
125
			'<p>' . __( 'In this section you should list all transfers of your site data outside the European Union and describe the means by which that data is safeguarded to European data protection standards. This could include your web hosting, cloud storage, or other third party services.' ) . '</p>' .
126
			'<p>' . __( 'European data protection law requires data about European residents which is transferred outside the European Union to be safeguarded to the same standards as if the data was in Europe. So in addition to listing where data goes, you should describe how you ensure that these standards are met either by yourself or by your third party providers, whether that is through an agreement such as Privacy Shield, model clauses in your contracts, or binding corporate rules.' ) . '</p>' . 
127
			'<p>' . __( 'Visitor comments may be checked through an automated spam detection service.' ) . '</p>';
128
129
		$content .=
130
			'<h2>' . __( 'Additional information' ) . '</h2>';
131
		$content .=
132
			'<p>' . __( 'If you use your site for commercial purposes and you engage in more complex collection or processing of personal data, you should note the following information in your privacy policy in addition to the information we have already discussed.' ) . '</p>';
133
134
		$content .=
135
			'<h3>' . __( 'How we protect your data' ) . '</h3>';
136
		$content .=
137
			'<p>' . __( 'In this section you should explain what measures you have taken to protect your users&#8217; data. This could include technical measures such as encryption; security measures such as two factor authentication; and measures such as staff training in data protection. If you have carried out a Privacy Impact Assessment, you can mention it here too.' ) . '</p>';
138
139
		$content .=
140
			'<h3>' . __( 'What data breach procedures we have in place' ) . '</h3>';
141
		$content .=
142
			'<p>' . __( 'In this section you should explain what procedures you have in place to deal with data breaches, either potential or real, such as internal reporting systems, contact mechanisms, or bug bounties.' ) . '</p>';
143
144
		$content .=
145
			'<h3>' . __( 'What third parties we receive data from' ) . '</h3>';
146
		$content .=
147
			'<p>' . __( 'If your web site receives data about users from third parties, including advertisers, this information must be included within the section of your privacy policy dealing with third party data.' ) . '</p>';
148
149
		$content .=
150
			'<h3>' . __( 'What automated decision making and/or profiling we do with user data' ) . '</h3>';
151
		$content .=
152
			'<p>' . __( 'If your web site provides a service which includes automated decision making - for example, allowing customers to apply for credit, or aggregating their data into an advertising profile - you must note that this is taking place, and include information about how that information is used, what decisions are made with that aggregated data, and what rights users have over decisions made without human intervention.' ) . '</p>';
153
154
		$content .=
155
			'<h3>' . __( 'Industry regulatory disclosure requirements' ) . '</h3>';
156
		$content .=
157
			'<p>' . __( 'If you are a member of a regulated industry, or if you are subject to additional privacy laws, you may be required to disclose that information here.' ) . '</p>' .
158
			'</div>';
159
160
		return apply_filters( 'geodir_privacy_policy_content', $content );
161
	}
162
163
	/**
164
	 * Handle some custom types of data and anonymize them.
165
	 *
166
	 * @param string $anonymous Anonymized string.
167
	 * @param string $type Type of data.
168
	 * @param string $data The data being anonymized.
169
	 * @return string Anonymized string.
170
	 */
171
	public function anonymize_custom_data_types( $anonymous, $type, $data ) {
172
		switch ( $type ) {
173
			case 'phone':
174
				$anonymous = preg_replace( '/\d/u', '0', $data );
175
				break;
176
			case 'numeric_id':
177
				$anonymous = 0;
178
				break;
179
			case 'gps':
180
				$anonymous = '0';
181
				break;
182
		}
183
		return $anonymous;
184
	}
185
186
	public static function personal_data_exporter_key() {
187
		if ( ! wp_doing_ajax() ) {
188
			return false;
189
		}
190
191
		if ( empty( $_POST['id'] ) ) {
192
			return false;
193
		}
194
		$request_id = (int) $_POST['id'];
195
196
		if ( $request_id < 1 ) {
197
			return false;
198
		}
199
200
		if ( ! current_user_can( 'export_others_personal_data' ) ) {
201
			return false;
202
		}
203
204
		// Get the request data.
205
		$request = wp_get_user_request_data( $request_id );
206
207
		if ( ! $request || 'export_personal_data' !== $request->action_name ) {
208
			return false;
209
		}
210
211
		$email_address = $request->email;
212
		if ( ! is_email( $email_address ) ) {
213
			return false;
214
		}
215
216
		if ( ! isset( $_POST['exporter'] ) ) {
217
			return false;
218
		}
219
		$exporter_index = (int) $_POST['exporter'];
220
221
		if ( ! isset( $_POST['page'] ) ) {
222
			return false;
223
		}
224
		$page = (int) $_POST['page'];
225
226
		$send_as_email = isset( $_POST['sendAsEmail'] ) ? ( 'true' === $_POST['sendAsEmail'] ) : false;
227
228
		/**
229
		 * Filters the array of exporter callbacks.
230
		 *
231
		 * @since 1.6.26
232
		 *
233
		 * @param array $args {
234
		 *     An array of callable exporters of personal data. Default empty array.
235
		 *
236
		 *     @type array {
237
		 *         Array of personal data exporters.
238
		 *
239
		 *         @type string $callback               Callable exporter function that accepts an
240
		 *                                              email address and a page and returns an array
241
		 *                                              of name => value pairs of personal data.
242
		 *         @type string $exporter_friendly_name Translated user facing friendly name for the
243
		 *                                              exporter.
244
		 *     }
245
		 * }
246
		 */
247
		$exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() );
248
249
		if ( ! is_array( $exporters ) ) {
250
			return false;
251
		}
252
253
		// Do we have any registered exporters?
254
		if ( 0 < count( $exporters ) ) {
255
			if ( $exporter_index < 1 ) {
256
				return false;
257
			}
258
259
			if ( $exporter_index > count( $exporters ) ) {
260
				return false;
261
			}
262
263
			if ( $page < 1 ) {
264
				return false;
265
			}
266
267
			$exporter_keys = array_keys( $exporters );
268
			$exporter_key  = $exporter_keys[ $exporter_index - 1 ];
269
			$exporter      = $exporters[ $exporter_key ];
270
			
271
			if ( ! is_array( $exporter ) || empty( $exporter_key ) ) {
272
				return false;
273
			}
274
			if ( ! array_key_exists( 'exporter_friendly_name', $exporter ) ) {
275
				return false;
276
			}
277
			if ( ! array_key_exists( 'callback', $exporter ) ) {
278
				return false;
279
			}
280
		}
281
282
		/**
283
		 * Filters a page of personal data exporter.
284
		 *
285
		 * @since 1.6.26
286
		 *
287
		 * @param array  $exporter_key    The key (slug) of the exporter that provided this data.
288
		 * @param array  $exporter        The personal data for the given exporter.
289
		 * @param int    $exporter_index  The index of the exporter that provided this data.
290
		 * @param string $email_address   The email address associated with this personal data.
291
		 * @param int    $page            The page for this response.
292
		 * @param int    $request_id      The privacy request post ID associated with this request.
293
		 * @param bool   $send_as_email   Whether the final results of the export should be emailed to the user.
294
		 */
295
		$exporter_key = apply_filters( 'geodir_privacy_personal_data_exporter', $exporter_key, $exporter, $exporter_index, $email_address, $page, $request_id, $send_as_email );
0 ignored issues
show
Bug introduced by
The variable $exporter_key does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $exporter does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
296
297
		return $exporter_key;
298
	}
299
300
	public static function exporter_post_type() {
301
		$exporter_key = self::personal_data_exporter_key();
302
303
		if ( empty( $exporter_key ) ) {
304
			return false;
305
		}
306
307
		if ( strpos( $exporter_key, 'geodirectory-post-' ) !== 0 ) {
308
			return false;
309
		}
310
311
		$post_type = str_replace( 'geodirectory-post-', '', $exporter_key );
312
313
		if ( $post_type != '' && in_array( $post_type, geodir_get_posttypes() ) ) {
314
			return $post_type;
315
		}
316
317
		return false;
318
	}
319
320
	public static function allow_export_post_type_data( $post_type ) {
321
		$allow = true;
322
323
		return apply_filters( 'geodir_privacy_allow_export_post_type_data', $allow, $post_type );
324
	}
325
326
	public static function allow_export_reviews_data() {
327
		$allow = true;
328
329
		return apply_filters( 'geodir_privacy_allow_export_reviews_data', $allow );
330
	}
331
332
	public static function allow_erase_reviews_data() {
333
		$allow = true;
334
335
		return apply_filters( 'geodir_privacy_allow_erase_reviews_data', $allow );
336
	}
337
}
338
339
new GeoDir_Privacy();
340