1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\core\services\privacy\policy; |
4
|
|
|
|
5
|
|
|
use EventEspresso\core\exceptions\InvalidClassException; |
6
|
|
|
use EventEspresso\core\exceptions\InvalidDataTypeException; |
7
|
|
|
use EventEspresso\core\exceptions\InvalidEntityException; |
8
|
|
|
use EventEspresso\core\exceptions\InvalidFilePathException; |
9
|
|
|
use EventEspresso\core\exceptions\InvalidIdentifierException; |
10
|
|
|
use EventEspresso\core\exceptions\InvalidInterfaceException; |
11
|
|
|
use EventEspresso\core\services\collections\CollectionDetails; |
12
|
|
|
use EventEspresso\core\services\collections\CollectionInterface; |
13
|
|
|
use EventEspresso\core\services\collections\CollectionLoader; |
14
|
|
|
use WP_Post; |
15
|
|
|
|
16
|
|
|
defined('EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed'); |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class PrivacyPolicyManager |
22
|
|
|
* Manages setting up the hooks to add the EE core and add-ons' privacy policies |
23
|
|
|
* |
24
|
|
|
* @package Event Espresso |
25
|
|
|
* @author Mike Nelson |
26
|
|
|
* @since $VID:$ |
27
|
|
|
*/ |
28
|
|
|
class PrivacyPolicyManager |
29
|
|
|
{ |
30
|
|
|
|
31
|
|
|
public function __construct() |
32
|
|
|
{ |
33
|
|
|
if (function_exists('wp_add_privacy_policy_content')) { |
34
|
|
|
add_action('edit_form_after_title', array($this, 'addPrivacyPolicy'), 9); |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* For all the registered `PrivacyPolicyInterface`s, add their privacy policy content |
42
|
|
|
* |
43
|
|
|
* @param WP_Post $post |
44
|
|
|
*/ |
45
|
|
|
public function addPrivacyPolicy($post) |
46
|
|
|
{ |
47
|
|
|
if (! ($post instanceof \WP_Post)) { |
|
|
|
|
48
|
|
|
return; |
49
|
|
|
} |
50
|
|
|
$policy_page_id = (int)get_option('wp_page_for_privacy_policy'); |
51
|
|
|
if (! $policy_page_id || $policy_page_id != $post->ID) { |
52
|
|
|
return; |
53
|
|
|
} |
54
|
|
|
//load all the privacy policy stuff |
55
|
|
|
//add post policy text |
56
|
|
|
foreach ($this->loadPrivacyPolicyCollection() as $privacy_policy) { |
|
|
|
|
57
|
|
|
wp_add_privacy_policy_content($privacy_policy->getName(), $privacy_policy->getContent()); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return CollectionInterface|PrivacyPolicyInterface[] |
65
|
|
|
* @throws InvalidIdentifierException |
66
|
|
|
* @throws InvalidInterfaceException |
67
|
|
|
* @throws InvalidFilePathException |
68
|
|
|
* @throws InvalidEntityException |
69
|
|
|
* @throws InvalidDataTypeException |
70
|
|
|
* @throws InvalidClassException |
71
|
|
|
*/ |
72
|
|
|
protected function loadPrivacyPolicyCollection() |
73
|
|
|
{ |
74
|
|
|
$loader = new CollectionLoader( |
75
|
|
|
new CollectionDetails( |
76
|
|
|
// collection name |
77
|
|
|
'privacy_policies', |
78
|
|
|
// collection interface |
79
|
|
|
'EventEspresso\core\services\privacy\policy\PrivacyPolicyInterface', |
80
|
|
|
// FQCNs for classes to add (all classes within that namespace will be loaded) |
81
|
|
|
apply_filters( |
82
|
|
|
'FHEE__EventEspresso_core_services_privacy_policy_PrivacyPolicyManager__privacy_policies', |
83
|
|
|
array('EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy') |
84
|
|
|
), |
85
|
|
|
// filepaths to classes to add |
86
|
|
|
array(), |
87
|
|
|
// file mask to use if parsing folder for files to add |
88
|
|
|
'', |
89
|
|
|
// what to use as identifier for collection entities |
90
|
|
|
// using CLASS NAME prevents duplicates (works like a singleton) |
91
|
|
|
CollectionDetails::ID_CLASS_NAME |
92
|
|
|
) |
93
|
|
|
); |
94
|
|
|
return $loader->getCollection(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
|
99
|
|
|
} |
100
|
|
|
// End of file PrivacyPolicyManager.php |
101
|
|
|
// Location: EventEspresso\core\domain\services\admin/PrivacyPolicyManager.php |