Completed
Branch Gutenberg/event-attendees-bloc... (e27df5)
by
unknown
56:20 queued 41:53
created

PrivacyPolicyManager   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 7
c 1
b 1
f 0
lcom 0
cbo 2
dl 0
loc 68
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B loadPrivacyPolicyCollection() 0 24 1
B addPrivacyPolicy() 0 12 5
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_Screen;
15
16
/**
17
 * Class PrivacyPolicyManager
18
 * Manages setting up the hooks to add the EE core and add-ons' privacy policies
19
 *
20
 * @package        Event Espresso
21
 * @author         Mike Nelson
22
 * @since          4.9.62.p
23
 */
24
class PrivacyPolicyManager
25
{
26
27
    public function __construct()
28
    {
29
        add_action('current_screen', array($this, 'addPrivacyPolicy'), 9);
30
    }
31
32
33
    /**
34
     * For all the registered `PrivacyPolicyInterface`s, add their privacy policy content
35
     *
36
     * @param WP_Screen $screen
37
     * @throws InvalidClassException
38
     * @throws InvalidDataTypeException
39
     * @throws InvalidEntityException
40
     * @throws InvalidFilePathException
41
     * @throws InvalidIdentifierException
42
     * @throws InvalidInterfaceException
43
     */
44
    public function addPrivacyPolicy(WP_Screen $screen)
45
    {
46
        if ($screen instanceof WP_Screen
0 ignored issues
show
Bug introduced by
The class WP_Screen does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
47
            && $screen->id === 'tools'
48
            && isset($_GET['wp-privacy-policy-guide'])) {
49
            // load all the privacy policy stuff
50
            // add post policy text
51
            foreach ($this->loadPrivacyPolicyCollection() as $privacy_policy) {
52
                wp_add_privacy_policy_content($privacy_policy->getName(), $privacy_policy->getContent());
53
            }
54
        }
55
    }
56
57
58
    /**
59
     * @return CollectionInterface|PrivacyPolicyInterface[]
60
     * @throws InvalidIdentifierException
61
     * @throws InvalidInterfaceException
62
     * @throws InvalidFilePathException
63
     * @throws InvalidEntityException
64
     * @throws InvalidDataTypeException
65
     * @throws InvalidClassException
66
     */
67
    protected function loadPrivacyPolicyCollection()
68
    {
69
        $loader = new CollectionLoader(
70
            new CollectionDetails(
71
                // collection name
72
                'privacy_policies',
73
                // collection interface
74
                'EventEspresso\core\services\privacy\policy\PrivacyPolicyInterface',
75
                // FQCNs for classes to add (all classes within that namespace will be loaded)
76
                apply_filters(
77
                    'FHEE__EventEspresso_core_services_privacy_policy_PrivacyPolicyManager__privacy_policies',
78
                    array('EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy')
79
                ),
80
                // filepaths to classes to add
81
                array(),
82
                // file mask to use if parsing folder for files to add
83
                '',
84
                // what to use as identifier for collection entities
85
                // using CLASS NAME prevents duplicates (works like a singleton)
86
                CollectionDetails::ID_CLASS_NAME
87
            )
88
        );
89
        return $loader->getCollection();
90
    }
91
}
92
// End of file PrivacyPolicyManager.php
93
// Location: EventEspresso\core\domain\services\admin/PrivacyPolicyManager.php
94