Code Duplication    Length = 109-113 lines in 2 locations

geodirectory-functions/privacy/class-geodir-privacy.php 2 locations

@@ 284-392 (lines=109) @@
281
		return $exporters;
282
	}
283
284
	public static function get_personal_data_exporter_key() {
285
		if ( empty( $_POST['id'] ) ) {
286
			return false;
287
		}
288
		$request_id = (int) $_POST['id'];
289
290
		if ( $request_id < 1 ) {
291
			return false;
292
		}
293
294
		if ( ! current_user_can( 'export_others_personal_data' ) ) {
295
			return false;
296
		}
297
298
		// Get the request data.
299
		$request = wp_get_user_request_data( $request_id );
300
301
		if ( ! $request || 'export_personal_data' !== $request->action_name ) {
302
			return false;
303
		}
304
305
		$email_address = $request->email;
306
		if ( ! is_email( $email_address ) ) {
307
			return false;
308
		}
309
310
		if ( ! isset( $_POST['exporter'] ) ) {
311
			return false;
312
		}
313
		$exporter_index = (int) $_POST['exporter'];
314
315
		if ( ! isset( $_POST['page'] ) ) {
316
			return false;
317
		}
318
		$page = (int) $_POST['page'];
319
320
		$send_as_email = isset( $_POST['sendAsEmail'] ) ? ( 'true' === $_POST['sendAsEmail'] ) : false;
321
322
		/**
323
		 * Filters the array of exporter callbacks.
324
		 *
325
		 * @since 1.6.26
326
		 *
327
		 * @param array $args {
328
		 *     An array of callable exporters of personal data. Default empty array.
329
		 *
330
		 *     @type array {
331
		 *         Array of personal data exporters.
332
		 *
333
		 *         @type string $callback               Callable exporter function that accepts an
334
		 *                                              email address and a page and returns an array
335
		 *                                              of name => value pairs of personal data.
336
		 *         @type string $exporter_friendly_name Translated user facing friendly name for the
337
		 *                                              exporter.
338
		 *     }
339
		 * }
340
		 */
341
		$exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() );
342
343
		if ( ! is_array( $exporters ) ) {
344
			return false;
345
		}
346
347
		// Do we have any registered exporters?
348
		if ( 0 < count( $exporters ) ) {
349
			if ( $exporter_index < 1 ) {
350
				return false;
351
			}
352
353
			if ( $exporter_index > count( $exporters ) ) {
354
				return false;
355
			}
356
357
			if ( $page < 1 ) {
358
				return false;
359
			}
360
361
			$exporter_keys = array_keys( $exporters );
362
			$exporter_key  = $exporter_keys[ $exporter_index - 1 ];
363
			$exporter      = $exporters[ $exporter_key ];
364
			
365
			if ( ! is_array( $exporter ) || empty( $exporter_key ) ) {
366
				return false;
367
			}
368
			if ( ! array_key_exists( 'exporter_friendly_name', $exporter ) ) {
369
				return false;
370
			}
371
			if ( ! array_key_exists( 'callback', $exporter ) ) {
372
				return false;
373
			}
374
		}
375
376
		/**
377
		 * Filters a page of personal data exporter.
378
		 *
379
		 * @since 1.6.26
380
		 *
381
		 * @param array  $exporter_key    The key (slug) of the exporter that provided this data.
382
		 * @param array  $exporter        The personal data for the given exporter.
383
		 * @param int    $exporter_index  The index of the exporter that provided this data.
384
		 * @param string $email_address   The email address associated with this personal data.
385
		 * @param int    $page            The page for this response.
386
		 * @param int    $request_id      The privacy request post ID associated with this request.
387
		 * @param bool   $send_as_email   Whether the final results of the export should be emailed to the user.
388
		 */
389
		$exporter_key = apply_filters( 'geodir_privacy_personal_data_exporter', $exporter_key, $exporter, $exporter_index, $email_address, $page, $request_id, $send_as_email );
390
391
		return $exporter_key;
392
	}
393
394
	public static function personal_data_exporter_key() {
395
		if ( ! wp_doing_ajax() ) {
@@ 394-506 (lines=113) @@
391
		return $exporter_key;
392
	}
393
394
	public static function personal_data_exporter_key() {
395
		if ( ! wp_doing_ajax() ) {
396
			return false;
397
		}
398
399
		if ( empty( $_POST['id'] ) ) {
400
			return false;
401
		}
402
		$request_id = (int) $_POST['id'];
403
404
		if ( $request_id < 1 ) {
405
			return false;
406
		}
407
408
		if ( ! current_user_can( 'export_others_personal_data' ) ) {
409
			return false;
410
		}
411
412
		// Get the request data.
413
		$request = wp_get_user_request_data( $request_id );
414
415
		if ( ! $request || 'export_personal_data' !== $request->action_name ) {
416
			return false;
417
		}
418
419
		$email_address = $request->email;
420
		if ( ! is_email( $email_address ) ) {
421
			return false;
422
		}
423
424
		if ( ! isset( $_POST['exporter'] ) ) {
425
			return false;
426
		}
427
		$exporter_index = (int) $_POST['exporter'];
428
429
		if ( ! isset( $_POST['page'] ) ) {
430
			return false;
431
		}
432
		$page = (int) $_POST['page'];
433
434
		$send_as_email = isset( $_POST['sendAsEmail'] ) ? ( 'true' === $_POST['sendAsEmail'] ) : false;
435
436
		/**
437
		 * Filters the array of exporter callbacks.
438
		 *
439
		 * @since 1.6.26
440
		 *
441
		 * @param array $args {
442
		 *     An array of callable exporters of personal data. Default empty array.
443
		 *
444
		 *     @type array {
445
		 *         Array of personal data exporters.
446
		 *
447
		 *         @type string $callback               Callable exporter function that accepts an
448
		 *                                              email address and a page and returns an array
449
		 *                                              of name => value pairs of personal data.
450
		 *         @type string $exporter_friendly_name Translated user facing friendly name for the
451
		 *                                              exporter.
452
		 *     }
453
		 * }
454
		 */
455
		$exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() );
456
457
		if ( ! is_array( $exporters ) ) {
458
			return false;
459
		}
460
461
		// Do we have any registered exporters?
462
		if ( 0 < count( $exporters ) ) {
463
			if ( $exporter_index < 1 ) {
464
				return false;
465
			}
466
467
			if ( $exporter_index > count( $exporters ) ) {
468
				return false;
469
			}
470
471
			if ( $page < 1 ) {
472
				return false;
473
			}
474
475
			$exporter_keys = array_keys( $exporters );
476
			$exporter_key  = $exporter_keys[ $exporter_index - 1 ];
477
			$exporter      = $exporters[ $exporter_key ];
478
			
479
			if ( ! is_array( $exporter ) || empty( $exporter_key ) ) {
480
				return false;
481
			}
482
			if ( ! array_key_exists( 'exporter_friendly_name', $exporter ) ) {
483
				return false;
484
			}
485
			if ( ! array_key_exists( 'callback', $exporter ) ) {
486
				return false;
487
			}
488
		}
489
490
		/**
491
		 * Filters a page of personal data exporter.
492
		 *
493
		 * @since 1.6.26
494
		 *
495
		 * @param array  $exporter_key    The key (slug) of the exporter that provided this data.
496
		 * @param array  $exporter        The personal data for the given exporter.
497
		 * @param int    $exporter_index  The index of the exporter that provided this data.
498
		 * @param string $email_address   The email address associated with this personal data.
499
		 * @param int    $page            The page for this response.
500
		 * @param int    $request_id      The privacy request post ID associated with this request.
501
		 * @param bool   $send_as_email   Whether the final results of the export should be emailed to the user.
502
		 */
503
		$exporter_key = apply_filters( 'geodir_privacy_personal_data_exporter', $exporter_key, $exporter, $exporter_index, $email_address, $page, $request_id, $send_as_email );
504
505
		return $exporter_key;
506
	}
507
508
	public static function exporter_post_type() {
509
		$exporter_key = self::personal_data_exporter_key();