Completed
Branch FET/11400/gutenberg-block-mana... (713a0a)
by
unknown
45:29 queued 32:15
created
core/middleware/EE_Detect_File_Editor_Request.core.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -14,28 +14,28 @@
 block discarded – undo
14 14
 class EE_Detect_File_Editor_Request extends EE_Middleware
15 15
 {
16 16
 
17
-    /**
18
-     * @deprecated
19
-     * @param EE_Request  $request
20
-     * @param EE_Response $response
21
-     * @return EE_Response
22
-     */
23
-    public function handle_request(EE_Request $request, EE_Response $response)
24
-    {
25
-        EE_Error::doing_it_wrong(
26
-            __METHOD__,
27
-            sprintf(
28
-                esc_html__(
29
-                    'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace',
30
-                    'event_espresso'
31
-                ),
32
-                'EventEspresso\core\services\request\middleware\DetectFileEditorRequest',
33
-                '\core\services\request',
34
-                'EventEspresso\core\services\request'
35
-            ),
36
-            '4.9.52'
37
-        );
38
-        return $response;
39
-    }
17
+	/**
18
+	 * @deprecated
19
+	 * @param EE_Request  $request
20
+	 * @param EE_Response $response
21
+	 * @return EE_Response
22
+	 */
23
+	public function handle_request(EE_Request $request, EE_Response $response)
24
+	{
25
+		EE_Error::doing_it_wrong(
26
+			__METHOD__,
27
+			sprintf(
28
+				esc_html__(
29
+					'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace',
30
+					'event_espresso'
31
+				),
32
+				'EventEspresso\core\services\request\middleware\DetectFileEditorRequest',
33
+				'\core\services\request',
34
+				'EventEspresso\core\services\request'
35
+			),
36
+			'4.9.52'
37
+		);
38
+		return $response;
39
+	}
40 40
 
41 41
 }
Please login to merge, or discard this patch.
core/services/request/middleware/DetectFileEditorRequest.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -21,45 +21,45 @@
 block discarded – undo
21 21
 class DetectFileEditorRequest extends Middleware
22 22
 {
23 23
 
24
-    /**
25
-     * converts a Request to a Response
26
-     *
27
-     * @param RequestInterface  $request
28
-     * @param ResponseInterface $response
29
-     * @return ResponseInterface
30
-     */
31
-    public function handleRequest(RequestInterface $request, ResponseInterface $response)
32
-    {
33
-        $this->request  = $request;
34
-        $this->response = $response;
35
-        if ($this->isFileEditorRequest()) {
36
-            $this->setFiltersForRequest();
37
-        }
38
-        $this->response = $this->processRequestStack($this->request, $this->response);
39
-        return $this->response;
40
-    }
24
+	/**
25
+	 * converts a Request to a Response
26
+	 *
27
+	 * @param RequestInterface  $request
28
+	 * @param ResponseInterface $response
29
+	 * @return ResponseInterface
30
+	 */
31
+	public function handleRequest(RequestInterface $request, ResponseInterface $response)
32
+	{
33
+		$this->request  = $request;
34
+		$this->response = $response;
35
+		if ($this->isFileEditorRequest()) {
36
+			$this->setFiltersForRequest();
37
+		}
38
+		$this->response = $this->processRequestStack($this->request, $this->response);
39
+		return $this->response;
40
+	}
41 41
 
42 42
 
43
-    /**
44
-     * This sets any filters that need set on this request.
45
-     */
46
-    protected function setFiltersForRequest()
47
-    {
48
-        add_filter('FHEE_load_EE_Session', '__return_false', 999);
49
-    }
43
+	/**
44
+	 * This sets any filters that need set on this request.
45
+	 */
46
+	protected function setFiltersForRequest()
47
+	{
48
+		add_filter('FHEE_load_EE_Session', '__return_false', 999);
49
+	}
50 50
 
51 51
 
52
-    /**
53
-     * Conditions for a "file editor request"
54
-     *
55
-     * @see wp-admin/includes/file.php
56
-     *      The file editor does a loopback request to the admin AND to the frontend when checking active theme or
57
-     *      active plugin edits.  So these conditions consider that.
58
-     * @return bool
59
-     */
60
-    protected function isFileEditorRequest()
61
-    {
62
-        return $this->request->getRequestParam('wp_scrape_key')
63
-               && $this->request->getRequestParam('wp_scrape_nonce');
64
-    }
52
+	/**
53
+	 * Conditions for a "file editor request"
54
+	 *
55
+	 * @see wp-admin/includes/file.php
56
+	 *      The file editor does a loopback request to the admin AND to the frontend when checking active theme or
57
+	 *      active plugin edits.  So these conditions consider that.
58
+	 * @return bool
59
+	 */
60
+	protected function isFileEditorRequest()
61
+	{
62
+		return $this->request->getRequestParam('wp_scrape_key')
63
+			   && $this->request->getRequestParam('wp_scrape_nonce');
64
+	}
65 65
 }
Please login to merge, or discard this patch.
core/services/editor/EditorBlockManager.php 1 patch
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -40,120 +40,120 @@
 block discarded – undo
40 40
 class EditorBlockManager
41 41
 {
42 42
 
43
-    /**
44
-     * @var CollectionInterface|EditorBlockInterface[] $blocks
45
-     */
46
-    private $blocks;
47
-
48
-    /**
49
-     * @var RequestInterface $request
50
-     */
51
-    protected $request;
52
-
53
-
54
-    /**
55
-     * EditorBlockManager constructor.
56
-     *
57
-     * @param EditorBlockCollection $blocks
58
-     * @param RequestInterface         $request
59
-     */
60
-    public function __construct(EditorBlockCollection $blocks, RequestInterface $request)
61
-    {
62
-        $this->blocks  = $blocks;
63
-        $this->request = $request;
64
-        //  populates the EditorBlockCollection and calls initialize() on all installed blocks
65
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'loadEditorBlocks'));
66
-        //  call initialize() and load assets for all installed blocks
67
-        add_action('AHEE__EE_System__initialize', array($this, 'registerEditorBlocks'));
68
-    }
69
-
70
-
71
-    /**
72
-     * @return CollectionInterface|EditorBlockInterface[]
73
-     * @throws ReflectionException
74
-     * @throws InvalidArgumentException
75
-     * @throws EE_Error
76
-     * @throws InvalidClassException
77
-     * @throws InvalidDataTypeException
78
-     * @throws InvalidEntityException
79
-     * @throws InvalidFilePathException
80
-     * @throws InvalidIdentifierException
81
-     * @throws InvalidInterfaceException
82
-     */
83
-    protected function populateEditorBlockCollection()
84
-    {
85
-        $loader = new CollectionLoader(
86
-            new CollectionDetails(
87
-            // collection name
88
-                'shortcodes',
89
-                // collection interface
90
-                'EventEspresso\core\domain\entities\editor\EditorBlockInterface',
91
-                // FQCNs for classes to add (all classes within each namespace will be loaded)
92
-                apply_filters(
93
-                    'FHEE__EventEspresso_core_services_editor_EditorBlockManager__populateEditorBlockCollection__collection_FQCNs',
94
-                    array('EventEspresso\core\domain\entities\editor\blocks')
95
-                ),
96
-                // filepaths to classes to add
97
-                array(),
98
-                // file mask to use if parsing folder for files to add
99
-                '',
100
-                // what to use as identifier for collection entities
101
-                // using CLASS NAME prevents duplicates (works like a singleton)
102
-                CollectionDetails::ID_CLASS_NAME
103
-            ),
104
-            $this->blocks
105
-        );
106
-        return $loader->getCollection();
107
-    }
108
-
109
-
110
-    /**
111
-     * @return void
112
-     * @throws Exception
113
-     */
114
-    public function loadEditorBlocks()
115
-    {
116
-        try {
117
-            $this->populateEditorBlockCollection();
118
-            // cycle thru block loaders and initialize each loader
119
-            foreach ($this->blocks as $block) {
120
-                $block->initialize();
121
-            }
122
-        } catch (Exception $exception) {
123
-            new ExceptionStackTraceDisplay($exception);
124
-        }
125
-    }
126
-
127
-
128
-    /**
129
-     * @return void
130
-     * @throws Exception
131
-     */
132
-    public function registerEditorBlocks()
133
-    {
134
-        try {
135
-            // cycle thru block loader folders
136
-            foreach ($this->blocks as $block) {
137
-                // perform any setup required for the block
138
-                $block_type = $block->registerBlock();
139
-                if (! $block_type instanceof WP_Block_Type) {
140
-                    throw new InvalidEntityException($block_type, 'WP_Block_Type');
141
-                }
142
-                do_action(
143
-                    'FHEE__EventEspresso_core_services_editor_EditorBlockManager__registerEditorBlocks__block_type_registered',
144
-                    $block,
145
-                    $block_type
146
-                );
147
-                if ($block instanceof EnqueueAssetsInterface) {
148
-                    // the following can be refactored in whatever way works best,
149
-                    // but it should be self evident that controlling asset loading from here
150
-                    // avoids having to add the following lines of code in every EditorBlock class
151
-                    add_action('enqueue_block_assets', array($block, 'registerScripts'));
152
-                    add_action('enqueue_block_assets', array($block, 'registerStyles'));
153
-                }
154
-            }
155
-        } catch (Exception $exception) {
156
-            new ExceptionStackTraceDisplay($exception);
157
-        }
158
-    }
43
+	/**
44
+	 * @var CollectionInterface|EditorBlockInterface[] $blocks
45
+	 */
46
+	private $blocks;
47
+
48
+	/**
49
+	 * @var RequestInterface $request
50
+	 */
51
+	protected $request;
52
+
53
+
54
+	/**
55
+	 * EditorBlockManager constructor.
56
+	 *
57
+	 * @param EditorBlockCollection $blocks
58
+	 * @param RequestInterface         $request
59
+	 */
60
+	public function __construct(EditorBlockCollection $blocks, RequestInterface $request)
61
+	{
62
+		$this->blocks  = $blocks;
63
+		$this->request = $request;
64
+		//  populates the EditorBlockCollection and calls initialize() on all installed blocks
65
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'loadEditorBlocks'));
66
+		//  call initialize() and load assets for all installed blocks
67
+		add_action('AHEE__EE_System__initialize', array($this, 'registerEditorBlocks'));
68
+	}
69
+
70
+
71
+	/**
72
+	 * @return CollectionInterface|EditorBlockInterface[]
73
+	 * @throws ReflectionException
74
+	 * @throws InvalidArgumentException
75
+	 * @throws EE_Error
76
+	 * @throws InvalidClassException
77
+	 * @throws InvalidDataTypeException
78
+	 * @throws InvalidEntityException
79
+	 * @throws InvalidFilePathException
80
+	 * @throws InvalidIdentifierException
81
+	 * @throws InvalidInterfaceException
82
+	 */
83
+	protected function populateEditorBlockCollection()
84
+	{
85
+		$loader = new CollectionLoader(
86
+			new CollectionDetails(
87
+			// collection name
88
+				'shortcodes',
89
+				// collection interface
90
+				'EventEspresso\core\domain\entities\editor\EditorBlockInterface',
91
+				// FQCNs for classes to add (all classes within each namespace will be loaded)
92
+				apply_filters(
93
+					'FHEE__EventEspresso_core_services_editor_EditorBlockManager__populateEditorBlockCollection__collection_FQCNs',
94
+					array('EventEspresso\core\domain\entities\editor\blocks')
95
+				),
96
+				// filepaths to classes to add
97
+				array(),
98
+				// file mask to use if parsing folder for files to add
99
+				'',
100
+				// what to use as identifier for collection entities
101
+				// using CLASS NAME prevents duplicates (works like a singleton)
102
+				CollectionDetails::ID_CLASS_NAME
103
+			),
104
+			$this->blocks
105
+		);
106
+		return $loader->getCollection();
107
+	}
108
+
109
+
110
+	/**
111
+	 * @return void
112
+	 * @throws Exception
113
+	 */
114
+	public function loadEditorBlocks()
115
+	{
116
+		try {
117
+			$this->populateEditorBlockCollection();
118
+			// cycle thru block loaders and initialize each loader
119
+			foreach ($this->blocks as $block) {
120
+				$block->initialize();
121
+			}
122
+		} catch (Exception $exception) {
123
+			new ExceptionStackTraceDisplay($exception);
124
+		}
125
+	}
126
+
127
+
128
+	/**
129
+	 * @return void
130
+	 * @throws Exception
131
+	 */
132
+	public function registerEditorBlocks()
133
+	{
134
+		try {
135
+			// cycle thru block loader folders
136
+			foreach ($this->blocks as $block) {
137
+				// perform any setup required for the block
138
+				$block_type = $block->registerBlock();
139
+				if (! $block_type instanceof WP_Block_Type) {
140
+					throw new InvalidEntityException($block_type, 'WP_Block_Type');
141
+				}
142
+				do_action(
143
+					'FHEE__EventEspresso_core_services_editor_EditorBlockManager__registerEditorBlocks__block_type_registered',
144
+					$block,
145
+					$block_type
146
+				);
147
+				if ($block instanceof EnqueueAssetsInterface) {
148
+					// the following can be refactored in whatever way works best,
149
+					// but it should be self evident that controlling asset loading from here
150
+					// avoids having to add the following lines of code in every EditorBlock class
151
+					add_action('enqueue_block_assets', array($block, 'registerScripts'));
152
+					add_action('enqueue_block_assets', array($block, 'registerStyles'));
153
+				}
154
+			}
155
+		} catch (Exception $exception) {
156
+			new ExceptionStackTraceDisplay($exception);
157
+		}
158
+	}
159 159
 }
Please login to merge, or discard this patch.
core/domain/entities/editor/EditorBlockCollection.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -20,55 +20,55 @@
 block discarded – undo
20 20
 class EditorBlockCollection extends Collection
21 21
 {
22 22
 
23
-    /**
24
-     * Collection constructor
25
-     *
26
-     * @throws InvalidInterfaceException
27
-     */
28
-    public function __construct()
29
-    {
30
-        parent::__construct('EventEspresso\core\domain\entities\editor\EditorBlockInterface');
31
-    }
23
+	/**
24
+	 * Collection constructor
25
+	 *
26
+	 * @throws InvalidInterfaceException
27
+	 */
28
+	public function __construct()
29
+	{
30
+		parent::__construct('EventEspresso\core\domain\entities\editor\EditorBlockInterface');
31
+	}
32 32
 
33 33
 
34
-    /**
35
-     * unRegisterBlock
36
-     * finds block in the Collection based on the identifier that was set using addObject()
37
-     * and calls unRegisterBlock() on it. Returns block if successful and false if block was not found.
38
-     * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards
39
-     *
40
-     * @param mixed $identifier
41
-     * @return boolean
42
-     */
43
-    public function unRegisterBlock($identifier)
44
-    {
45
-        $this->rewind();
46
-        while ($this->valid()) {
47
-            if ($identifier === $this->getInfo()) {
48
-                $object = $this->current();
49
-                $this->rewind();
50
-                return $object->unRegisterBlock();
51
-            }
52
-            $this->next();
53
-        }
54
-        return false;
55
-    }
34
+	/**
35
+	 * unRegisterBlock
36
+	 * finds block in the Collection based on the identifier that was set using addObject()
37
+	 * and calls unRegisterBlock() on it. Returns block if successful and false if block was not found.
38
+	 * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards
39
+	 *
40
+	 * @param mixed $identifier
41
+	 * @return boolean
42
+	 */
43
+	public function unRegisterBlock($identifier)
44
+	{
45
+		$this->rewind();
46
+		while ($this->valid()) {
47
+			if ($identifier === $this->getInfo()) {
48
+				$object = $this->current();
49
+				$this->rewind();
50
+				return $object->unRegisterBlock();
51
+			}
52
+			$this->next();
53
+		}
54
+		return false;
55
+	}
56 56
 
57 57
 
58
-    /**
59
-     * unRegisterAllBlocks
60
-     * calls unRegisterBlock() on all blocks in Collection.
61
-     * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards
62
-     *
63
-     * @return void
64
-     */
65
-    public function unRegisterAllBlocks()
66
-    {
67
-        $this->rewind();
68
-        while ($this->valid()) {
69
-            $this->current()->unRegisterBlock();
70
-            $this->next();
71
-        }
72
-        $this->rewind();
73
-    }
58
+	/**
59
+	 * unRegisterAllBlocks
60
+	 * calls unRegisterBlock() on all blocks in Collection.
61
+	 * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards
62
+	 *
63
+	 * @return void
64
+	 */
65
+	public function unRegisterAllBlocks()
66
+	{
67
+		$this->rewind();
68
+		while ($this->valid()) {
69
+			$this->current()->unRegisterBlock();
70
+			$this->next();
71
+		}
72
+		$this->rewind();
73
+	}
74 74
 }
Please login to merge, or discard this patch.
core/domain/entities/editor/blocks/EventsList.php 1 patch
Indentation   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -25,149 +25,149 @@
 block discarded – undo
25 25
 class EventsList extends EditorBlock
26 26
 {
27 27
 
28
-    const EDITOR_BLOCK_TYPE = 'ee-shortcodes/events-list';
29
-
30
-
31
-    /**
32
-     * Perform any early setup required by the block
33
-     *
34
-     * @return void
35
-     */
36
-    public function initialize()
37
-    {
38
-    }
39
-
40
-
41
-    /**
42
-     * @return WP_Block_Type|false The registered block type on success, or false on failure.
43
-     */
44
-    public function registerBlock()
45
-    {
46
-        $this->block_type = register_block_type(
47
-            new WP_Block_Type(
48
-                EventsList::EDITOR_BLOCK_TYPE,
49
-                array(
50
-                    'editor_script'   => 'ee-shortcode-blocks',
51
-                    'editor_style'    => 'ee-block-styles',
52
-                    'render_callback' => array($this, 'renderEventsList'),
53
-                    'attributes'      => array(
54
-                        'title'        => array(
55
-                            'type' => 'string',
56
-                        ),
57
-                        'limit'        => array(
58
-                            'type'    => 'integer',
59
-                            'default' => 10,
60
-                        ),
61
-                        'cssClass'     => array(
62
-                            'type' => 'string',
63
-                        ),
64
-                        'showExpired'  => array(
65
-                            'type'    => 'boolean',
66
-                            'default' => false,
67
-                        ),
68
-                        'month'        => array(
69
-                            'type' => 'string',
70
-                        ),
71
-                        'categorySlug' => array(
72
-                            'type' => 'string',
73
-                        ),
74
-                        'orderBy'      => array(
75
-                            'type'    => 'string',
76
-                            'enum'    => array(
77
-                                'start_date',
78
-                                'ticket_start',
79
-                                'ticket_end',
80
-                                'venue_title',
81
-                                'city',
82
-                                'state',
83
-                            ),
84
-                            'default' => 'start_date',
85
-                        ),
86
-                        'order'        => array(
87
-                            'type'    => 'string',
88
-                            'default' => 'ASC',
89
-                            'enum'    => array('ASC', 'DESC'),
90
-                        ),
91
-                        'showTitle'    => array(
92
-                            'type'    => 'boolean',
93
-                            'default' => true,
94
-                        ),
95
-                    ),
96
-                )
97
-            )
98
-        );
99
-        return $this->block_type;
100
-    }
101
-
102
-
103
-    /**
104
-     * @return WP_Block_Type|false The registered block type on success, or false on failure.
105
-     */
106
-    public function unRegisterBlock()
107
-    {
108
-        return unregister_block_type(EventsList::EDITOR_BLOCK_TYPE);
109
-    }
110
-
111
-
112
-    /**
113
-     * @return  void
114
-     */
115
-    public function registerScripts()
116
-    {
117
-    }
118
-
119
-
120
-    /**
121
-     * @return void
122
-     */
123
-    public function registerStyles()
124
-    {
125
-    }
126
-
127
-
128
-    /**
129
-     * @param array $attributes
130
-     * @return string
131
-     * @throws InvalidArgumentException
132
-     * @throws InvalidDataTypeException
133
-     * @throws InvalidInterfaceException
134
-     * @throws EE_Error
135
-     */
136
-    public function renderEventsList(array $attributes = array())
137
-    {
138
-        /** @var EspressoEvents $shortcode */
139
-        $shortcode  = $this->loader->getShared('EventEspresso\core\domain\entities\shortcodes\EspressoEvents');
140
-        $attributes = $this->mapAttributes($attributes);
141
-        return $shortcode->processShortcodeCallback($attributes);
142
-    }
143
-
144
-
145
-    /**
146
-     * Maps new style block attributes to old style shortcode attribute keys.
147
-     *
148
-     * @param array $attributes
149
-     * @return array
150
-     */
151
-    private function mapAttributes(array $attributes)
152
-    {
153
-        $replacements   = array(
154
-            'cssClass'     => 'css_class',
155
-            'showExpired'  => 'show_expired',
156
-            'categorySlug' => 'category_slug',
157
-            'orderBy'      => 'order_by',
158
-            'order'        => 'sort',
159
-            'showTitle'    => 'show_title',
160
-        );
161
-        $new_attributes = array();
162
-        array_walk(
163
-            $attributes,
164
-            function ($value, $key) use (&$new_attributes, $replacements)
165
-            {
166
-                $new_key                    = isset($replacements[ $key ]) ? $replacements[ $key ] : $key;
167
-                $value                      = $value === 'none' ? null : $value;
168
-                $new_attributes[ $new_key ] = $value;
169
-            }
170
-        );
171
-        return $new_attributes;
172
-    }
28
+	const EDITOR_BLOCK_TYPE = 'ee-shortcodes/events-list';
29
+
30
+
31
+	/**
32
+	 * Perform any early setup required by the block
33
+	 *
34
+	 * @return void
35
+	 */
36
+	public function initialize()
37
+	{
38
+	}
39
+
40
+
41
+	/**
42
+	 * @return WP_Block_Type|false The registered block type on success, or false on failure.
43
+	 */
44
+	public function registerBlock()
45
+	{
46
+		$this->block_type = register_block_type(
47
+			new WP_Block_Type(
48
+				EventsList::EDITOR_BLOCK_TYPE,
49
+				array(
50
+					'editor_script'   => 'ee-shortcode-blocks',
51
+					'editor_style'    => 'ee-block-styles',
52
+					'render_callback' => array($this, 'renderEventsList'),
53
+					'attributes'      => array(
54
+						'title'        => array(
55
+							'type' => 'string',
56
+						),
57
+						'limit'        => array(
58
+							'type'    => 'integer',
59
+							'default' => 10,
60
+						),
61
+						'cssClass'     => array(
62
+							'type' => 'string',
63
+						),
64
+						'showExpired'  => array(
65
+							'type'    => 'boolean',
66
+							'default' => false,
67
+						),
68
+						'month'        => array(
69
+							'type' => 'string',
70
+						),
71
+						'categorySlug' => array(
72
+							'type' => 'string',
73
+						),
74
+						'orderBy'      => array(
75
+							'type'    => 'string',
76
+							'enum'    => array(
77
+								'start_date',
78
+								'ticket_start',
79
+								'ticket_end',
80
+								'venue_title',
81
+								'city',
82
+								'state',
83
+							),
84
+							'default' => 'start_date',
85
+						),
86
+						'order'        => array(
87
+							'type'    => 'string',
88
+							'default' => 'ASC',
89
+							'enum'    => array('ASC', 'DESC'),
90
+						),
91
+						'showTitle'    => array(
92
+							'type'    => 'boolean',
93
+							'default' => true,
94
+						),
95
+					),
96
+				)
97
+			)
98
+		);
99
+		return $this->block_type;
100
+	}
101
+
102
+
103
+	/**
104
+	 * @return WP_Block_Type|false The registered block type on success, or false on failure.
105
+	 */
106
+	public function unRegisterBlock()
107
+	{
108
+		return unregister_block_type(EventsList::EDITOR_BLOCK_TYPE);
109
+	}
110
+
111
+
112
+	/**
113
+	 * @return  void
114
+	 */
115
+	public function registerScripts()
116
+	{
117
+	}
118
+
119
+
120
+	/**
121
+	 * @return void
122
+	 */
123
+	public function registerStyles()
124
+	{
125
+	}
126
+
127
+
128
+	/**
129
+	 * @param array $attributes
130
+	 * @return string
131
+	 * @throws InvalidArgumentException
132
+	 * @throws InvalidDataTypeException
133
+	 * @throws InvalidInterfaceException
134
+	 * @throws EE_Error
135
+	 */
136
+	public function renderEventsList(array $attributes = array())
137
+	{
138
+		/** @var EspressoEvents $shortcode */
139
+		$shortcode  = $this->loader->getShared('EventEspresso\core\domain\entities\shortcodes\EspressoEvents');
140
+		$attributes = $this->mapAttributes($attributes);
141
+		return $shortcode->processShortcodeCallback($attributes);
142
+	}
143
+
144
+
145
+	/**
146
+	 * Maps new style block attributes to old style shortcode attribute keys.
147
+	 *
148
+	 * @param array $attributes
149
+	 * @return array
150
+	 */
151
+	private function mapAttributes(array $attributes)
152
+	{
153
+		$replacements   = array(
154
+			'cssClass'     => 'css_class',
155
+			'showExpired'  => 'show_expired',
156
+			'categorySlug' => 'category_slug',
157
+			'orderBy'      => 'order_by',
158
+			'order'        => 'sort',
159
+			'showTitle'    => 'show_title',
160
+		);
161
+		$new_attributes = array();
162
+		array_walk(
163
+			$attributes,
164
+			function ($value, $key) use (&$new_attributes, $replacements)
165
+			{
166
+				$new_key                    = isset($replacements[ $key ]) ? $replacements[ $key ] : $key;
167
+				$value                      = $value === 'none' ? null : $value;
168
+				$new_attributes[ $new_key ] = $value;
169
+			}
170
+		);
171
+		return $new_attributes;
172
+	}
173 173
 }
Please login to merge, or discard this patch.
core/domain/entities/editor/EditorBlock.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -26,24 +26,24 @@
 block discarded – undo
26 26
 abstract class EditorBlock implements EditorBlockInterface
27 27
 {
28 28
 
29
-    /**
30
-     * @var WP_Block_Type $block_type
31
-     */
32
-    protected $block_type;
33
-
34
-    /**
35
-     * @var LoaderInterface $loader
36
-     */
37
-    protected $loader;
38
-
39
-
40
-    /**
41
-     * EditorBlockLoader constructor.
42
-     *
43
-     * @param LoaderInterface $loader
44
-     */
45
-    public function __construct(LoaderInterface $loader)
46
-    {
47
-        $this->loader = $loader;
48
-    }
29
+	/**
30
+	 * @var WP_Block_Type $block_type
31
+	 */
32
+	protected $block_type;
33
+
34
+	/**
35
+	 * @var LoaderInterface $loader
36
+	 */
37
+	protected $loader;
38
+
39
+
40
+	/**
41
+	 * EditorBlockLoader constructor.
42
+	 *
43
+	 * @param LoaderInterface $loader
44
+	 */
45
+	public function __construct(LoaderInterface $loader)
46
+	{
47
+		$this->loader = $loader;
48
+	}
49 49
 }
Please login to merge, or discard this patch.
core/domain/entities/editor/EditorBlockInterface.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -25,34 +25,34 @@
 block discarded – undo
25 25
 interface EditorBlockInterface
26 26
 {
27 27
 
28
-    /**
29
-     * Perform any early setup required by the block
30
-     *
31
-     * @return void
32
-     */
33
-    public function initialize();
28
+	/**
29
+	 * Perform any early setup required by the block
30
+	 *
31
+	 * @return void
32
+	 */
33
+	public function initialize();
34 34
 
35 35
 
36
-    /**
37
-     * @return WP_Block_Type|false The registered block type on success, or false on failure.
38
-     */
39
-    public function registerBlock();
36
+	/**
37
+	 * @return WP_Block_Type|false The registered block type on success, or false on failure.
38
+	 */
39
+	public function registerBlock();
40 40
 
41 41
 
42
-    /**
43
-     * @return WP_Block_Type|false The registered block type on success, or false on failure.
44
-     */
45
-    public function unRegisterBlock();
42
+	/**
43
+	 * @return WP_Block_Type|false The registered block type on success, or false on failure.
44
+	 */
45
+	public function unRegisterBlock();
46 46
 
47 47
 
48
-    /**
49
-     * @return  void
50
-     */
51
-    public function registerScripts();
48
+	/**
49
+	 * @return  void
50
+	 */
51
+	public function registerScripts();
52 52
 
53 53
 
54
-    /**
55
-     * @return void
56
-     */
57
-    public function registerStyles();
54
+	/**
55
+	 * @return void
56
+	 */
57
+	public function registerStyles();
58 58
 }
Please login to merge, or discard this patch.
core/EE_System.core.php 2 patches
Indentation   +1265 added lines, -1265 removed lines patch added patch discarded remove patch
@@ -24,1271 +24,1271 @@
 block discarded – undo
24 24
 {
25 25
 
26 26
 
27
-    /**
28
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
29
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
30
-     */
31
-    const req_type_normal = 0;
32
-
33
-    /**
34
-     * Indicates this is a brand new installation of EE so we should install
35
-     * tables and default data etc
36
-     */
37
-    const req_type_new_activation = 1;
38
-
39
-    /**
40
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
41
-     * and we just exited maintenance mode). We MUST check the database is setup properly
42
-     * and that default data is setup too
43
-     */
44
-    const req_type_reactivation = 2;
45
-
46
-    /**
47
-     * indicates that EE has been upgraded since its previous request.
48
-     * We may have data migration scripts to call and will want to trigger maintenance mode
49
-     */
50
-    const req_type_upgrade = 3;
51
-
52
-    /**
53
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
54
-     */
55
-    const req_type_downgrade = 4;
56
-
57
-    /**
58
-     * @deprecated since version 4.6.0.dev.006
59
-     * Now whenever a new_activation is detected the request type is still just
60
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
61
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
62
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
63
-     * (Specifically, when the migration manager indicates migrations are finished
64
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
65
-     */
66
-    const req_type_activation_but_not_installed = 5;
67
-
68
-    /**
69
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
70
-     */
71
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
72
-
73
-
74
-    /**
75
-     * @var EE_System $_instance
76
-     */
77
-    private static $_instance;
78
-
79
-    /**
80
-     * @var EE_Registry $registry
81
-     */
82
-    private $registry;
83
-
84
-    /**
85
-     * @var LoaderInterface $loader
86
-     */
87
-    private $loader;
88
-
89
-    /**
90
-     * @var EE_Capabilities $capabilities
91
-     */
92
-    private $capabilities;
93
-
94
-    /**
95
-     * @var RequestInterface $request
96
-     */
97
-    private $request;
98
-
99
-    /**
100
-     * @var EE_Maintenance_Mode $maintenance_mode
101
-     */
102
-    private $maintenance_mode;
103
-
104
-    /**
105
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
106
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
107
-     *
108
-     * @var int $_req_type
109
-     */
110
-    private $_req_type;
111
-
112
-    /**
113
-     * Whether or not there was a non-micro version change in EE core version during this request
114
-     *
115
-     * @var boolean $_major_version_change
116
-     */
117
-    private $_major_version_change = false;
118
-
119
-    /**
120
-     * A Context DTO dedicated solely to identifying the current request type.
121
-     *
122
-     * @var RequestTypeContextCheckerInterface $request_type
123
-     */
124
-    private $request_type;
125
-
126
-
127
-
128
-    /**
129
-     * @singleton method used to instantiate class object
130
-     * @param EE_Registry|null         $registry
131
-     * @param LoaderInterface|null     $loader
132
-     * @param RequestInterface|null          $request
133
-     * @param EE_Maintenance_Mode|null $maintenance_mode
134
-     * @return EE_System
135
-     */
136
-    public static function instance(
137
-        EE_Registry $registry = null,
138
-        LoaderInterface $loader = null,
139
-        RequestInterface $request = null,
140
-        EE_Maintenance_Mode $maintenance_mode = null
141
-    ) {
142
-        // check if class object is instantiated
143
-        if (! self::$_instance instanceof EE_System) {
144
-            self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
145
-        }
146
-        return self::$_instance;
147
-    }
148
-
149
-
150
-
151
-    /**
152
-     * resets the instance and returns it
153
-     *
154
-     * @return EE_System
155
-     */
156
-    public static function reset()
157
-    {
158
-        self::$_instance->_req_type = null;
159
-        //make sure none of the old hooks are left hanging around
160
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
161
-        //we need to reset the migration manager in order for it to detect DMSs properly
162
-        EE_Data_Migration_Manager::reset();
163
-        self::instance()->detect_activations_or_upgrades();
164
-        self::instance()->perform_activations_upgrades_and_migrations();
165
-        return self::instance();
166
-    }
167
-
168
-
169
-
170
-    /**
171
-     * sets hooks for running rest of system
172
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
173
-     * starting EE Addons from any other point may lead to problems
174
-     *
175
-     * @param EE_Registry         $registry
176
-     * @param LoaderInterface     $loader
177
-     * @param RequestInterface          $request
178
-     * @param EE_Maintenance_Mode $maintenance_mode
179
-     */
180
-    private function __construct(
181
-        EE_Registry $registry,
182
-        LoaderInterface $loader,
183
-        RequestInterface $request,
184
-        EE_Maintenance_Mode $maintenance_mode
185
-    ) {
186
-        $this->registry         = $registry;
187
-        $this->loader           = $loader;
188
-        $this->request          = $request;
189
-        $this->maintenance_mode = $maintenance_mode;
190
-        do_action('AHEE__EE_System__construct__begin', $this);
191
-        add_action(
192
-            'AHEE__EE_Bootstrap__load_espresso_addons',
193
-            array($this, 'loadCapabilities'),
194
-            5
195
-        );
196
-        add_action(
197
-            'AHEE__EE_Bootstrap__load_espresso_addons',
198
-            array($this, 'loadCommandBus'),
199
-            7
200
-        );
201
-        add_action(
202
-            'AHEE__EE_Bootstrap__load_espresso_addons',
203
-            array($this, 'loadPluginApi'),
204
-            9
205
-        );
206
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
207
-        add_action(
208
-            'AHEE__EE_Bootstrap__load_espresso_addons',
209
-            array($this, 'load_espresso_addons')
210
-        );
211
-        // when an ee addon is activated, we want to call the core hook(s) again
212
-        // because the newly-activated addon didn't get a chance to run at all
213
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
214
-        // detect whether install or upgrade
215
-        add_action(
216
-            'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
217
-            array($this, 'detect_activations_or_upgrades'),
218
-            3
219
-        );
220
-        // load EE_Config, EE_Textdomain, etc
221
-        add_action(
222
-            'AHEE__EE_Bootstrap__load_core_configuration',
223
-            array($this, 'load_core_configuration'),
224
-            5
225
-        );
226
-        // load EE_Config, EE_Textdomain, etc
227
-        add_action(
228
-            'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
229
-            array($this, 'register_shortcodes_modules_and_widgets'),
230
-            7
231
-        );
232
-        // you wanna get going? I wanna get going... let's get going!
233
-        add_action(
234
-            'AHEE__EE_Bootstrap__brew_espresso',
235
-            array($this, 'brew_espresso'),
236
-            9
237
-        );
238
-        //other housekeeping
239
-        //exclude EE critical pages from wp_list_pages
240
-        add_filter(
241
-            'wp_list_pages_excludes',
242
-            array($this, 'remove_pages_from_wp_list_pages'),
243
-            10
244
-        );
245
-        // ALL EE Addons should use the following hook point to attach their initial setup too
246
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
247
-        do_action('AHEE__EE_System__construct__complete', $this);
248
-    }
249
-
250
-
251
-    /**
252
-     * load and setup EE_Capabilities
253
-     *
254
-     * @return void
255
-     * @throws EE_Error
256
-     */
257
-    public function loadCapabilities()
258
-    {
259
-        $this->capabilities = $this->loader->getShared('EE_Capabilities');
260
-        add_action(
261
-            'AHEE__EE_Capabilities__init_caps__before_initialization',
262
-            function ()
263
-            {
264
-                LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
265
-            }
266
-        );
267
-    }
268
-
269
-
270
-
271
-    /**
272
-     * create and cache the CommandBus, and also add middleware
273
-     * The CapChecker middleware requires the use of EE_Capabilities
274
-     * which is why we need to load the CommandBus after Caps are set up
275
-     *
276
-     * @return void
277
-     * @throws EE_Error
278
-     */
279
-    public function loadCommandBus()
280
-    {
281
-        $this->loader->getShared(
282
-            'CommandBusInterface',
283
-            array(
284
-                null,
285
-                apply_filters(
286
-                    'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
287
-                    array(
288
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
289
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
290
-                    )
291
-                ),
292
-            )
293
-        );
294
-    }
295
-
296
-
297
-
298
-    /**
299
-     * @return void
300
-     * @throws EE_Error
301
-     */
302
-    public function loadPluginApi()
303
-    {
304
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
305
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
306
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
307
-        $this->loader->getShared('EE_Request_Handler');
308
-    }
309
-
310
-
311
-    /**
312
-     * @param string $addon_name
313
-     * @param string $version_constant
314
-     * @param string $min_version_required
315
-     * @param string $load_callback
316
-     * @param string $plugin_file_constant
317
-     * @return void
318
-     */
319
-    private function deactivateIncompatibleAddon(
320
-        $addon_name,
321
-        $version_constant,
322
-        $min_version_required,
323
-        $load_callback,
324
-        $plugin_file_constant
325
-    ) {
326
-        if (! defined($version_constant)) {
327
-            return;
328
-        }
329
-        $addon_version = constant($version_constant);
330
-        if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
331
-            remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
332
-            if (! function_exists('deactivate_plugins')) {
333
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
334
-            }
335
-            deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
336
-            unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
337
-            EE_Error::add_error(
338
-                sprintf(
339
-                    esc_html__(
340
-                        'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
341
-                        'event_espresso'
342
-                    ),
343
-                    $addon_name,
344
-                    $min_version_required
345
-                ),
346
-                __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
347
-            );
348
-            EE_Error::get_notices(false, true);
349
-        }
350
-    }
351
-
352
-
353
-    /**
354
-     * load_espresso_addons
355
-     * allow addons to load first so that they can set hooks for running DMS's, etc
356
-     * this is hooked into both:
357
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
358
-     *        which runs during the WP 'plugins_loaded' action at priority 5
359
-     *    and the WP 'activate_plugin' hook point
360
-     *
361
-     * @access public
362
-     * @return void
363
-     */
364
-    public function load_espresso_addons()
365
-    {
366
-        $this->deactivateIncompatibleAddon(
367
-            'Wait Lists',
368
-            'EE_WAIT_LISTS_VERSION',
369
-            '1.0.0.beta.074',
370
-            'load_espresso_wait_lists',
371
-            'EE_WAIT_LISTS_PLUGIN_FILE'
372
-        );
373
-        $this->deactivateIncompatibleAddon(
374
-            'Automated Upcoming Event Notifications',
375
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
376
-            '1.0.0.beta.091',
377
-            'load_espresso_automated_upcoming_event_notification',
378
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
379
-        );
380
-        do_action('AHEE__EE_System__load_espresso_addons');
381
-        //if the WP API basic auth plugin isn't already loaded, load it now.
382
-        //We want it for mobile apps. Just include the entire plugin
383
-        //also, don't load the basic auth when a plugin is getting activated, because
384
-        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
385
-        //and causes a fatal error
386
-        if (
387
-            $this->request->getRequestParam('activate') !== 'true'
388
-            && ! function_exists('json_basic_auth_handler')
389
-            && ! function_exists('json_basic_auth_error')
390
-            && ! in_array(
391
-                $this->request->getRequestParam('action'),
392
-                array('activate', 'activate-selected'),
393
-                true
394
-            )
395
-        ) {
396
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
397
-        }
398
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
399
-    }
400
-
401
-
402
-
403
-    /**
404
-     * detect_activations_or_upgrades
405
-     * Checks for activation or upgrade of core first;
406
-     * then also checks if any registered addons have been activated or upgraded
407
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
408
-     * which runs during the WP 'plugins_loaded' action at priority 3
409
-     *
410
-     * @access public
411
-     * @return void
412
-     */
413
-    public function detect_activations_or_upgrades()
414
-    {
415
-        //first off: let's make sure to handle core
416
-        $this->detect_if_activation_or_upgrade();
417
-        foreach ($this->registry->addons as $addon) {
418
-            if ($addon instanceof EE_Addon) {
419
-                //detect teh request type for that addon
420
-                $addon->detect_activation_or_upgrade();
421
-            }
422
-        }
423
-    }
424
-
425
-
426
-
427
-    /**
428
-     * detect_if_activation_or_upgrade
429
-     * Takes care of detecting whether this is a brand new install or code upgrade,
430
-     * and either setting up the DB or setting up maintenance mode etc.
431
-     *
432
-     * @access public
433
-     * @return void
434
-     */
435
-    public function detect_if_activation_or_upgrade()
436
-    {
437
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
438
-        // check if db has been updated, or if its a brand-new installation
439
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
440
-        $request_type       = $this->detect_req_type($espresso_db_update);
441
-        //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
442
-        switch ($request_type) {
443
-            case EE_System::req_type_new_activation:
444
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
445
-                $this->_handle_core_version_change($espresso_db_update);
446
-                break;
447
-            case EE_System::req_type_reactivation:
448
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
449
-                $this->_handle_core_version_change($espresso_db_update);
450
-                break;
451
-            case EE_System::req_type_upgrade:
452
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
453
-                //migrations may be required now that we've upgraded
454
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
455
-                $this->_handle_core_version_change($espresso_db_update);
456
-                //				echo "done upgrade";die;
457
-                break;
458
-            case EE_System::req_type_downgrade:
459
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
460
-                //its possible migrations are no longer required
461
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
462
-                $this->_handle_core_version_change($espresso_db_update);
463
-                break;
464
-            case EE_System::req_type_normal:
465
-            default:
466
-                break;
467
-        }
468
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
469
-    }
470
-
471
-
472
-
473
-    /**
474
-     * Updates the list of installed versions and sets hooks for
475
-     * initializing the database later during the request
476
-     *
477
-     * @param array $espresso_db_update
478
-     */
479
-    private function _handle_core_version_change($espresso_db_update)
480
-    {
481
-        $this->update_list_of_installed_versions($espresso_db_update);
482
-        //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
483
-        add_action(
484
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
485
-            array($this, 'initialize_db_if_no_migrations_required')
486
-        );
487
-    }
488
-
489
-
490
-
491
-    /**
492
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
493
-     * information about what versions of EE have been installed and activated,
494
-     * NOT necessarily the state of the database
495
-     *
496
-     * @param mixed $espresso_db_update           the value of the WordPress option.
497
-     *                                            If not supplied, fetches it from the options table
498
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
499
-     */
500
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
501
-    {
502
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
503
-        if (! $espresso_db_update) {
504
-            $espresso_db_update = get_option('espresso_db_update');
505
-        }
506
-        // check that option is an array
507
-        if (! is_array($espresso_db_update)) {
508
-            // if option is FALSE, then it never existed
509
-            if ($espresso_db_update === false) {
510
-                // make $espresso_db_update an array and save option with autoload OFF
511
-                $espresso_db_update = array();
512
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
513
-            } else {
514
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
515
-                $espresso_db_update = array($espresso_db_update => array());
516
-                update_option('espresso_db_update', $espresso_db_update);
517
-            }
518
-        } else {
519
-            $corrected_db_update = array();
520
-            //if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
521
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
522
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
523
-                    //the key is an int, and the value IS NOT an array
524
-                    //so it must be numerically-indexed, where values are versions installed...
525
-                    //fix it!
526
-                    $version_string                         = $should_be_array;
527
-                    $corrected_db_update[ $version_string ] = array('unknown-date');
528
-                } else {
529
-                    //ok it checks out
530
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
531
-                }
532
-            }
533
-            $espresso_db_update = $corrected_db_update;
534
-            update_option('espresso_db_update', $espresso_db_update);
535
-        }
536
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
537
-        return $espresso_db_update;
538
-    }
539
-
540
-
541
-
542
-    /**
543
-     * Does the traditional work of setting up the plugin's database and adding default data.
544
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
545
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
546
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
547
-     * so that it will be done when migrations are finished
548
-     *
549
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
550
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
551
-     *                                       This is a resource-intensive job
552
-     *                                       so we prefer to only do it when necessary
553
-     * @return void
554
-     * @throws EE_Error
555
-     */
556
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
557
-    {
558
-        $request_type = $this->detect_req_type();
559
-        //only initialize system if we're not in maintenance mode.
560
-        if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
561
-            update_option('ee_flush_rewrite_rules', true);
562
-            if ($verify_schema) {
563
-                EEH_Activation::initialize_db_and_folders();
564
-            }
565
-            EEH_Activation::initialize_db_content();
566
-            EEH_Activation::system_initialization();
567
-            if ($initialize_addons_too) {
568
-                $this->initialize_addons();
569
-            }
570
-        } else {
571
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
572
-        }
573
-        if ($request_type === EE_System::req_type_new_activation
574
-            || $request_type === EE_System::req_type_reactivation
575
-            || (
576
-                $request_type === EE_System::req_type_upgrade
577
-                && $this->is_major_version_change()
578
-            )
579
-        ) {
580
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
581
-        }
582
-    }
583
-
584
-
585
-
586
-    /**
587
-     * Initializes the db for all registered addons
588
-     *
589
-     * @throws EE_Error
590
-     */
591
-    public function initialize_addons()
592
-    {
593
-        //foreach registered addon, make sure its db is up-to-date too
594
-        foreach ($this->registry->addons as $addon) {
595
-            if ($addon instanceof EE_Addon) {
596
-                $addon->initialize_db_if_no_migrations_required();
597
-            }
598
-        }
599
-    }
600
-
601
-
602
-
603
-    /**
604
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
605
-     *
606
-     * @param    array  $version_history
607
-     * @param    string $current_version_to_add version to be added to the version history
608
-     * @return    boolean success as to whether or not this option was changed
609
-     */
610
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
611
-    {
612
-        if (! $version_history) {
613
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
614
-        }
615
-        if ($current_version_to_add === null) {
616
-            $current_version_to_add = espresso_version();
617
-        }
618
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
619
-        // re-save
620
-        return update_option('espresso_db_update', $version_history);
621
-    }
622
-
623
-
624
-
625
-    /**
626
-     * Detects if the current version indicated in the has existed in the list of
627
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
628
-     *
629
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
630
-     *                                  If not supplied, fetches it from the options table.
631
-     *                                  Also, caches its result so later parts of the code can also know whether
632
-     *                                  there's been an update or not. This way we can add the current version to
633
-     *                                  espresso_db_update, but still know if this is a new install or not
634
-     * @return int one of the constants on EE_System::req_type_
635
-     */
636
-    public function detect_req_type($espresso_db_update = null)
637
-    {
638
-        if ($this->_req_type === null) {
639
-            $espresso_db_update          = ! empty($espresso_db_update)
640
-                ? $espresso_db_update
641
-                : $this->fix_espresso_db_upgrade_option();
642
-            $this->_req_type             = EE_System::detect_req_type_given_activation_history(
643
-                $espresso_db_update,
644
-                'ee_espresso_activation', espresso_version()
645
-            );
646
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
647
-            $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
648
-        }
649
-        return $this->_req_type;
650
-    }
651
-
652
-
653
-
654
-    /**
655
-     * Returns whether or not there was a non-micro version change (ie, change in either
656
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
657
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
658
-     *
659
-     * @param $activation_history
660
-     * @return bool
661
-     */
662
-    private function _detect_major_version_change($activation_history)
663
-    {
664
-        $previous_version       = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
665
-        $previous_version_parts = explode('.', $previous_version);
666
-        $current_version_parts  = explode('.', espresso_version());
667
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
668
-               && ($previous_version_parts[0] !== $current_version_parts[0]
669
-                   || $previous_version_parts[1] !== $current_version_parts[1]
670
-               );
671
-    }
672
-
673
-
674
-
675
-    /**
676
-     * Returns true if either the major or minor version of EE changed during this request.
677
-     * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
678
-     *
679
-     * @return bool
680
-     */
681
-    public function is_major_version_change()
682
-    {
683
-        return $this->_major_version_change;
684
-    }
685
-
686
-
687
-
688
-    /**
689
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
690
-     * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
691
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
692
-     * just activated to (for core that will always be espresso_version())
693
-     *
694
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
695
-     *                                                 ee plugin. for core that's 'espresso_db_update'
696
-     * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
697
-     *                                                 indicate that this plugin was just activated
698
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
699
-     *                                                 espresso_version())
700
-     * @return int one of the constants on EE_System::req_type_*
701
-     */
702
-    public static function detect_req_type_given_activation_history(
703
-        $activation_history_for_addon,
704
-        $activation_indicator_option_name,
705
-        $version_to_upgrade_to
706
-    ) {
707
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
708
-        if ($activation_history_for_addon) {
709
-            //it exists, so this isn't a completely new install
710
-            //check if this version already in that list of previously installed versions
711
-            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
712
-                //it a version we haven't seen before
713
-                if ($version_is_higher === 1) {
714
-                    $req_type = EE_System::req_type_upgrade;
715
-                } else {
716
-                    $req_type = EE_System::req_type_downgrade;
717
-                }
718
-                delete_option($activation_indicator_option_name);
719
-            } else {
720
-                // its not an update. maybe a reactivation?
721
-                if (get_option($activation_indicator_option_name, false)) {
722
-                    if ($version_is_higher === -1) {
723
-                        $req_type = EE_System::req_type_downgrade;
724
-                    } elseif ($version_is_higher === 0) {
725
-                        //we've seen this version before, but it's an activation. must be a reactivation
726
-                        $req_type = EE_System::req_type_reactivation;
727
-                    } else {//$version_is_higher === 1
728
-                        $req_type = EE_System::req_type_upgrade;
729
-                    }
730
-                    delete_option($activation_indicator_option_name);
731
-                } else {
732
-                    //we've seen this version before and the activation indicate doesn't show it was just activated
733
-                    if ($version_is_higher === -1) {
734
-                        $req_type = EE_System::req_type_downgrade;
735
-                    } elseif ($version_is_higher === 0) {
736
-                        //we've seen this version before and it's not an activation. its normal request
737
-                        $req_type = EE_System::req_type_normal;
738
-                    } else {//$version_is_higher === 1
739
-                        $req_type = EE_System::req_type_upgrade;
740
-                    }
741
-                }
742
-            }
743
-        } else {
744
-            //brand new install
745
-            $req_type = EE_System::req_type_new_activation;
746
-            delete_option($activation_indicator_option_name);
747
-        }
748
-        return $req_type;
749
-    }
750
-
751
-
752
-
753
-    /**
754
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
755
-     * the $activation_history_for_addon
756
-     *
757
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
758
-     *                                             sometimes containing 'unknown-date'
759
-     * @param string $version_to_upgrade_to        (current version)
760
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
761
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
762
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
763
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
764
-     */
765
-    private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
766
-    {
767
-        //find the most recently-activated version
768
-        $most_recently_active_version =
769
-            EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
770
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
771
-    }
772
-
773
-
774
-
775
-    /**
776
-     * Gets the most recently active version listed in the activation history,
777
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
778
-     *
779
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
780
-     *                                   sometimes containing 'unknown-date'
781
-     * @return string
782
-     */
783
-    private static function _get_most_recently_active_version_from_activation_history($activation_history)
784
-    {
785
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
786
-        $most_recently_active_version            = '0.0.0.dev.000';
787
-        if (is_array($activation_history)) {
788
-            foreach ($activation_history as $version => $times_activated) {
789
-                //check there is a record of when this version was activated. Otherwise,
790
-                //mark it as unknown
791
-                if (! $times_activated) {
792
-                    $times_activated = array('unknown-date');
793
-                }
794
-                if (is_string($times_activated)) {
795
-                    $times_activated = array($times_activated);
796
-                }
797
-                foreach ($times_activated as $an_activation) {
798
-                    if ($an_activation !== 'unknown-date'
799
-                        && $an_activation
800
-                           > $most_recently_active_version_activation) {
801
-                        $most_recently_active_version            = $version;
802
-                        $most_recently_active_version_activation = $an_activation === 'unknown-date'
803
-                            ? '1970-01-01 00:00:00'
804
-                            : $an_activation;
805
-                    }
806
-                }
807
-            }
808
-        }
809
-        return $most_recently_active_version;
810
-    }
811
-
812
-
813
-
814
-    /**
815
-     * This redirects to the about EE page after activation
816
-     *
817
-     * @return void
818
-     */
819
-    public function redirect_to_about_ee()
820
-    {
821
-        $notices = EE_Error::get_notices(false);
822
-        //if current user is an admin and it's not an ajax or rest request
823
-        if (
824
-            ! isset($notices['errors'])
825
-            && $this->request->isAdmin()
826
-            && apply_filters(
827
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
828
-                $this->capabilities->current_user_can('manage_options', 'espresso_about_default')
829
-            )
830
-        ) {
831
-            $query_params = array('page' => 'espresso_about');
832
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
833
-                $query_params['new_activation'] = true;
834
-            }
835
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
836
-                $query_params['reactivation'] = true;
837
-            }
838
-            $url = add_query_arg($query_params, admin_url('admin.php'));
839
-            wp_safe_redirect($url);
840
-            exit();
841
-        }
842
-    }
843
-
844
-
845
-
846
-    /**
847
-     * load_core_configuration
848
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
849
-     * which runs during the WP 'plugins_loaded' action at priority 5
850
-     *
851
-     * @return void
852
-     * @throws ReflectionException
853
-     */
854
-    public function load_core_configuration()
855
-    {
856
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
857
-        $this->loader->getShared('EE_Load_Textdomain');
858
-        //load textdomain
859
-        EE_Load_Textdomain::load_textdomain();
860
-        // load and setup EE_Config and EE_Network_Config
861
-        $config = $this->loader->getShared('EE_Config');
862
-        $this->loader->getShared('EE_Network_Config');
863
-        // setup autoloaders
864
-        // enable logging?
865
-        if ($config->admin->use_full_logging) {
866
-            $this->loader->getShared('EE_Log');
867
-        }
868
-        // check for activation errors
869
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
870
-        if ($activation_errors) {
871
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
872
-            update_option('ee_plugin_activation_errors', false);
873
-        }
874
-        // get model names
875
-        $this->_parse_model_names();
876
-        //load caf stuff a chance to play during the activation process too.
877
-        $this->_maybe_brew_regular();
878
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
879
-    }
880
-
881
-
882
-
883
-    /**
884
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
885
-     *
886
-     * @return void
887
-     * @throws ReflectionException
888
-     */
889
-    private function _parse_model_names()
890
-    {
891
-        //get all the files in the EE_MODELS folder that end in .model.php
892
-        $models                 = glob(EE_MODELS . '*.model.php');
893
-        $model_names            = array();
894
-        $non_abstract_db_models = array();
895
-        foreach ($models as $model) {
896
-            // get model classname
897
-            $classname       = EEH_File::get_classname_from_filepath_with_standard_filename($model);
898
-            $short_name      = str_replace('EEM_', '', $classname);
899
-            $reflectionClass = new ReflectionClass($classname);
900
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
901
-                $non_abstract_db_models[ $short_name ] = $classname;
902
-            }
903
-            $model_names[ $short_name ] = $classname;
904
-        }
905
-        $this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
906
-        $this->registry->non_abstract_db_models = apply_filters(
907
-            'FHEE__EE_System__parse_implemented_model_names',
908
-            $non_abstract_db_models
909
-        );
910
-    }
911
-
912
-
913
-
914
-    /**
915
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
916
-     * that need to be setup before our EE_System launches.
917
-     *
918
-     * @return void
919
-     */
920
-    private function _maybe_brew_regular()
921
-    {
922
-        if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
923
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
924
-        }
925
-    }
926
-
927
-
928
-
929
-    /**
930
-     * register_shortcodes_modules_and_widgets
931
-     * generate lists of shortcodes and modules, then verify paths and classes
932
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
933
-     * which runs during the WP 'plugins_loaded' action at priority 7
934
-     *
935
-     * @access public
936
-     * @return void
937
-     * @throws Exception
938
-     */
939
-    public function register_shortcodes_modules_and_widgets()
940
-    {
941
-        if ($this->request->isFrontend() || $this->request->isIframe()) {
942
-            try {
943
-                // load, register, and add shortcodes the new way
944
-                $this->loader->getShared(
945
-                    'EventEspresso\core\services\shortcodes\ShortcodesManager',
946
-                    array(
947
-                        // and the old way, but we'll put it under control of the new system
948
-                        EE_Config::getLegacyShortcodesManager(),
949
-                    )
950
-                );
951
-                // or the even newer newer new way
952
-                if(function_exists('register_block_type')) {
953
-                    $this->loader->getShared(
954
-                        'EventEspresso\core\services\editor\EditorBlockManager',
955
-                        array(
956
-                            $this->loader->getShared(
957
-                                'EventEspresso\core\domain\entities\editor\EditorBlockCollection'
958
-                            ),
959
-                            $this->request,
960
-                        )
961
-                    );
962
-                }
963
-            } catch (Exception $exception) {
964
-                new ExceptionStackTraceDisplay($exception);
965
-            }
966
-        }
967
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
968
-        // check for addons using old hook point
969
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
970
-            $this->_incompatible_addon_error();
971
-        }
972
-    }
973
-
974
-
975
-
976
-    /**
977
-     * _incompatible_addon_error
978
-     *
979
-     * @access public
980
-     * @return void
981
-     */
982
-    private function _incompatible_addon_error()
983
-    {
984
-        // get array of classes hooking into here
985
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
986
-            'AHEE__EE_System__register_shortcodes_modules_and_addons'
987
-        );
988
-        if (! empty($class_names)) {
989
-            $msg = __(
990
-                'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
991
-                'event_espresso'
992
-            );
993
-            $msg .= '<ul>';
994
-            foreach ($class_names as $class_name) {
995
-                $msg .= '<li><b>Event Espresso - ' . str_replace(
996
-                        array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
997
-                        $class_name
998
-                    ) . '</b></li>';
999
-            }
1000
-            $msg .= '</ul>';
1001
-            $msg .= __(
1002
-                'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1003
-                'event_espresso'
1004
-            );
1005
-            // save list of incompatible addons to wp-options for later use
1006
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
1007
-            if (is_admin()) {
1008
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1009
-            }
1010
-        }
1011
-    }
1012
-
1013
-
1014
-
1015
-    /**
1016
-     * brew_espresso
1017
-     * begins the process of setting hooks for initializing EE in the correct order
1018
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1019
-     * which runs during the WP 'plugins_loaded' action at priority 9
1020
-     *
1021
-     * @return void
1022
-     */
1023
-    public function brew_espresso()
1024
-    {
1025
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
1026
-        // load some final core systems
1027
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
1028
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1029
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
1030
-        add_action('init', array($this, 'load_controllers'), 7);
1031
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
1032
-        add_action('init', array($this, 'initialize'), 10);
1033
-        add_action('init', array($this, 'initialize_last'), 100);
1034
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1035
-            // pew pew pew
1036
-            $this->loader->getShared('EE_PUE');
1037
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1038
-        }
1039
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
1040
-    }
1041
-
1042
-
1043
-
1044
-    /**
1045
-     *    set_hooks_for_core
1046
-     *
1047
-     * @access public
1048
-     * @return    void
1049
-     * @throws EE_Error
1050
-     */
1051
-    public function set_hooks_for_core()
1052
-    {
1053
-        $this->_deactivate_incompatible_addons();
1054
-        do_action('AHEE__EE_System__set_hooks_for_core');
1055
-        //caps need to be initialized on every request so that capability maps are set.
1056
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1057
-        $this->registry->CAP->init_caps();
1058
-    }
1059
-
1060
-
1061
-
1062
-    /**
1063
-     * Using the information gathered in EE_System::_incompatible_addon_error,
1064
-     * deactivates any addons considered incompatible with the current version of EE
1065
-     */
1066
-    private function _deactivate_incompatible_addons()
1067
-    {
1068
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
1069
-        if (! empty($incompatible_addons)) {
1070
-            $active_plugins = get_option('active_plugins', array());
1071
-            foreach ($active_plugins as $active_plugin) {
1072
-                foreach ($incompatible_addons as $incompatible_addon) {
1073
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
1074
-                        unset($_GET['activate']);
1075
-                        espresso_deactivate_plugin($active_plugin);
1076
-                    }
1077
-                }
1078
-            }
1079
-        }
1080
-    }
1081
-
1082
-
1083
-
1084
-    /**
1085
-     *    perform_activations_upgrades_and_migrations
1086
-     *
1087
-     * @access public
1088
-     * @return    void
1089
-     */
1090
-    public function perform_activations_upgrades_and_migrations()
1091
-    {
1092
-        //first check if we had previously attempted to setup EE's directories but failed
1093
-        if ($this->request->isActivation() && EEH_Activation::upload_directories_incomplete()) {
1094
-            EEH_Activation::create_upload_directories();
1095
-        }
1096
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1097
-    }
1098
-
1099
-
1100
-
1101
-    /**
1102
-     *    load_CPTs_and_session
1103
-     *
1104
-     * @access public
1105
-     * @return    void
1106
-     */
1107
-    public function load_CPTs_and_session()
1108
-    {
1109
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
1110
-        // register Custom Post Types
1111
-        $this->loader->getShared('EE_Register_CPTs');
1112
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1113
-    }
1114
-
1115
-
1116
-
1117
-    /**
1118
-     * load_controllers
1119
-     * this is the best place to load any additional controllers that needs access to EE core.
1120
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1121
-     * time
1122
-     *
1123
-     * @access public
1124
-     * @return void
1125
-     */
1126
-    public function load_controllers()
1127
-    {
1128
-        do_action('AHEE__EE_System__load_controllers__start');
1129
-        // let's get it started
1130
-        if (
1131
-            ! $this->maintenance_mode->level()
1132
-            && ($this->request->isFrontend() || $this->request->isFrontAjax())
1133
-        ) {
1134
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1135
-            $this->loader->getShared('EE_Front_Controller');
1136
-        } elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1137
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1138
-            $this->loader->getShared('EE_Admin');
1139
-        }
1140
-        do_action('AHEE__EE_System__load_controllers__complete');
1141
-    }
1142
-
1143
-
1144
-
1145
-    /**
1146
-     * core_loaded_and_ready
1147
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1148
-     *
1149
-     * @access public
1150
-     * @return void
1151
-     */
1152
-    public function core_loaded_and_ready()
1153
-    {
1154
-        if (
1155
-            $this->request->isAdmin()
1156
-            || $this->request->isEeAjax()
1157
-            || $this->request->isFrontend()
1158
-        ) {
1159
-            $this->loader->getShared('EE_Session');
1160
-        }
1161
-        do_action('AHEE__EE_System__core_loaded_and_ready');
1162
-        // load_espresso_template_tags
1163
-        if (
1164
-            is_readable(EE_PUBLIC . 'template_tags.php')
1165
-            && ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isFeed())
1166
-        ) {
1167
-            require_once EE_PUBLIC . 'template_tags.php';
1168
-        }
1169
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1170
-        if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
1171
-            $this->loader->getShared('EventEspresso\core\services\assets\Registry');
1172
-        }
1173
-    }
1174
-
1175
-
1176
-
1177
-    /**
1178
-     * initialize
1179
-     * this is the best place to begin initializing client code
1180
-     *
1181
-     * @access public
1182
-     * @return void
1183
-     */
1184
-    public function initialize()
1185
-    {
1186
-        do_action('AHEE__EE_System__initialize');
1187
-    }
1188
-
1189
-
1190
-
1191
-    /**
1192
-     * initialize_last
1193
-     * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1194
-     * initialize has done so
1195
-     *
1196
-     * @access public
1197
-     * @return void
1198
-     */
1199
-    public function initialize_last()
1200
-    {
1201
-        do_action('AHEE__EE_System__initialize_last');
1202
-        add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1203
-    }
1204
-
1205
-
1206
-
1207
-    /**
1208
-     * @return void
1209
-     * @throws EE_Error
1210
-     */
1211
-    public function addEspressoToolbar()
1212
-    {
1213
-        $this->loader->getShared(
1214
-            'EventEspresso\core\domain\services\admin\AdminToolBar',
1215
-            array($this->registry->CAP)
1216
-        );
1217
-    }
1218
-
1219
-
1220
-
1221
-    /**
1222
-     * do_not_cache
1223
-     * sets no cache headers and defines no cache constants for WP plugins
1224
-     *
1225
-     * @access public
1226
-     * @return void
1227
-     */
1228
-    public static function do_not_cache()
1229
-    {
1230
-        // set no cache constants
1231
-        if (! defined('DONOTCACHEPAGE')) {
1232
-            define('DONOTCACHEPAGE', true);
1233
-        }
1234
-        if (! defined('DONOTCACHCEOBJECT')) {
1235
-            define('DONOTCACHCEOBJECT', true);
1236
-        }
1237
-        if (! defined('DONOTCACHEDB')) {
1238
-            define('DONOTCACHEDB', true);
1239
-        }
1240
-        // add no cache headers
1241
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1242
-        // plus a little extra for nginx and Google Chrome
1243
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1244
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1245
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1246
-    }
1247
-
1248
-
1249
-
1250
-    /**
1251
-     *    extra_nocache_headers
1252
-     *
1253
-     * @access    public
1254
-     * @param $headers
1255
-     * @return    array
1256
-     */
1257
-    public static function extra_nocache_headers($headers)
1258
-    {
1259
-        // for NGINX
1260
-        $headers['X-Accel-Expires'] = 0;
1261
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1262
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1263
-        return $headers;
1264
-    }
1265
-
1266
-
1267
-
1268
-    /**
1269
-     *    nocache_headers
1270
-     *
1271
-     * @access    public
1272
-     * @return    void
1273
-     */
1274
-    public static function nocache_headers()
1275
-    {
1276
-        nocache_headers();
1277
-    }
1278
-
1279
-
1280
-
1281
-    /**
1282
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1283
-     * never returned with the function.
1284
-     *
1285
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1286
-     * @return array
1287
-     */
1288
-    public function remove_pages_from_wp_list_pages($exclude_array)
1289
-    {
1290
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1291
-    }
27
+	/**
28
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
29
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
30
+	 */
31
+	const req_type_normal = 0;
32
+
33
+	/**
34
+	 * Indicates this is a brand new installation of EE so we should install
35
+	 * tables and default data etc
36
+	 */
37
+	const req_type_new_activation = 1;
38
+
39
+	/**
40
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
41
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
42
+	 * and that default data is setup too
43
+	 */
44
+	const req_type_reactivation = 2;
45
+
46
+	/**
47
+	 * indicates that EE has been upgraded since its previous request.
48
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
49
+	 */
50
+	const req_type_upgrade = 3;
51
+
52
+	/**
53
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
54
+	 */
55
+	const req_type_downgrade = 4;
56
+
57
+	/**
58
+	 * @deprecated since version 4.6.0.dev.006
59
+	 * Now whenever a new_activation is detected the request type is still just
60
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
61
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
62
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
63
+	 * (Specifically, when the migration manager indicates migrations are finished
64
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
65
+	 */
66
+	const req_type_activation_but_not_installed = 5;
67
+
68
+	/**
69
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
70
+	 */
71
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
72
+
73
+
74
+	/**
75
+	 * @var EE_System $_instance
76
+	 */
77
+	private static $_instance;
78
+
79
+	/**
80
+	 * @var EE_Registry $registry
81
+	 */
82
+	private $registry;
83
+
84
+	/**
85
+	 * @var LoaderInterface $loader
86
+	 */
87
+	private $loader;
88
+
89
+	/**
90
+	 * @var EE_Capabilities $capabilities
91
+	 */
92
+	private $capabilities;
93
+
94
+	/**
95
+	 * @var RequestInterface $request
96
+	 */
97
+	private $request;
98
+
99
+	/**
100
+	 * @var EE_Maintenance_Mode $maintenance_mode
101
+	 */
102
+	private $maintenance_mode;
103
+
104
+	/**
105
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
106
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
107
+	 *
108
+	 * @var int $_req_type
109
+	 */
110
+	private $_req_type;
111
+
112
+	/**
113
+	 * Whether or not there was a non-micro version change in EE core version during this request
114
+	 *
115
+	 * @var boolean $_major_version_change
116
+	 */
117
+	private $_major_version_change = false;
118
+
119
+	/**
120
+	 * A Context DTO dedicated solely to identifying the current request type.
121
+	 *
122
+	 * @var RequestTypeContextCheckerInterface $request_type
123
+	 */
124
+	private $request_type;
125
+
126
+
127
+
128
+	/**
129
+	 * @singleton method used to instantiate class object
130
+	 * @param EE_Registry|null         $registry
131
+	 * @param LoaderInterface|null     $loader
132
+	 * @param RequestInterface|null          $request
133
+	 * @param EE_Maintenance_Mode|null $maintenance_mode
134
+	 * @return EE_System
135
+	 */
136
+	public static function instance(
137
+		EE_Registry $registry = null,
138
+		LoaderInterface $loader = null,
139
+		RequestInterface $request = null,
140
+		EE_Maintenance_Mode $maintenance_mode = null
141
+	) {
142
+		// check if class object is instantiated
143
+		if (! self::$_instance instanceof EE_System) {
144
+			self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
145
+		}
146
+		return self::$_instance;
147
+	}
148
+
149
+
150
+
151
+	/**
152
+	 * resets the instance and returns it
153
+	 *
154
+	 * @return EE_System
155
+	 */
156
+	public static function reset()
157
+	{
158
+		self::$_instance->_req_type = null;
159
+		//make sure none of the old hooks are left hanging around
160
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
161
+		//we need to reset the migration manager in order for it to detect DMSs properly
162
+		EE_Data_Migration_Manager::reset();
163
+		self::instance()->detect_activations_or_upgrades();
164
+		self::instance()->perform_activations_upgrades_and_migrations();
165
+		return self::instance();
166
+	}
167
+
168
+
169
+
170
+	/**
171
+	 * sets hooks for running rest of system
172
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
173
+	 * starting EE Addons from any other point may lead to problems
174
+	 *
175
+	 * @param EE_Registry         $registry
176
+	 * @param LoaderInterface     $loader
177
+	 * @param RequestInterface          $request
178
+	 * @param EE_Maintenance_Mode $maintenance_mode
179
+	 */
180
+	private function __construct(
181
+		EE_Registry $registry,
182
+		LoaderInterface $loader,
183
+		RequestInterface $request,
184
+		EE_Maintenance_Mode $maintenance_mode
185
+	) {
186
+		$this->registry         = $registry;
187
+		$this->loader           = $loader;
188
+		$this->request          = $request;
189
+		$this->maintenance_mode = $maintenance_mode;
190
+		do_action('AHEE__EE_System__construct__begin', $this);
191
+		add_action(
192
+			'AHEE__EE_Bootstrap__load_espresso_addons',
193
+			array($this, 'loadCapabilities'),
194
+			5
195
+		);
196
+		add_action(
197
+			'AHEE__EE_Bootstrap__load_espresso_addons',
198
+			array($this, 'loadCommandBus'),
199
+			7
200
+		);
201
+		add_action(
202
+			'AHEE__EE_Bootstrap__load_espresso_addons',
203
+			array($this, 'loadPluginApi'),
204
+			9
205
+		);
206
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
207
+		add_action(
208
+			'AHEE__EE_Bootstrap__load_espresso_addons',
209
+			array($this, 'load_espresso_addons')
210
+		);
211
+		// when an ee addon is activated, we want to call the core hook(s) again
212
+		// because the newly-activated addon didn't get a chance to run at all
213
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
214
+		// detect whether install or upgrade
215
+		add_action(
216
+			'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
217
+			array($this, 'detect_activations_or_upgrades'),
218
+			3
219
+		);
220
+		// load EE_Config, EE_Textdomain, etc
221
+		add_action(
222
+			'AHEE__EE_Bootstrap__load_core_configuration',
223
+			array($this, 'load_core_configuration'),
224
+			5
225
+		);
226
+		// load EE_Config, EE_Textdomain, etc
227
+		add_action(
228
+			'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
229
+			array($this, 'register_shortcodes_modules_and_widgets'),
230
+			7
231
+		);
232
+		// you wanna get going? I wanna get going... let's get going!
233
+		add_action(
234
+			'AHEE__EE_Bootstrap__brew_espresso',
235
+			array($this, 'brew_espresso'),
236
+			9
237
+		);
238
+		//other housekeeping
239
+		//exclude EE critical pages from wp_list_pages
240
+		add_filter(
241
+			'wp_list_pages_excludes',
242
+			array($this, 'remove_pages_from_wp_list_pages'),
243
+			10
244
+		);
245
+		// ALL EE Addons should use the following hook point to attach their initial setup too
246
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
247
+		do_action('AHEE__EE_System__construct__complete', $this);
248
+	}
249
+
250
+
251
+	/**
252
+	 * load and setup EE_Capabilities
253
+	 *
254
+	 * @return void
255
+	 * @throws EE_Error
256
+	 */
257
+	public function loadCapabilities()
258
+	{
259
+		$this->capabilities = $this->loader->getShared('EE_Capabilities');
260
+		add_action(
261
+			'AHEE__EE_Capabilities__init_caps__before_initialization',
262
+			function ()
263
+			{
264
+				LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
265
+			}
266
+		);
267
+	}
268
+
269
+
270
+
271
+	/**
272
+	 * create and cache the CommandBus, and also add middleware
273
+	 * The CapChecker middleware requires the use of EE_Capabilities
274
+	 * which is why we need to load the CommandBus after Caps are set up
275
+	 *
276
+	 * @return void
277
+	 * @throws EE_Error
278
+	 */
279
+	public function loadCommandBus()
280
+	{
281
+		$this->loader->getShared(
282
+			'CommandBusInterface',
283
+			array(
284
+				null,
285
+				apply_filters(
286
+					'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
287
+					array(
288
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
289
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
290
+					)
291
+				),
292
+			)
293
+		);
294
+	}
295
+
296
+
297
+
298
+	/**
299
+	 * @return void
300
+	 * @throws EE_Error
301
+	 */
302
+	public function loadPluginApi()
303
+	{
304
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
305
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
306
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
307
+		$this->loader->getShared('EE_Request_Handler');
308
+	}
309
+
310
+
311
+	/**
312
+	 * @param string $addon_name
313
+	 * @param string $version_constant
314
+	 * @param string $min_version_required
315
+	 * @param string $load_callback
316
+	 * @param string $plugin_file_constant
317
+	 * @return void
318
+	 */
319
+	private function deactivateIncompatibleAddon(
320
+		$addon_name,
321
+		$version_constant,
322
+		$min_version_required,
323
+		$load_callback,
324
+		$plugin_file_constant
325
+	) {
326
+		if (! defined($version_constant)) {
327
+			return;
328
+		}
329
+		$addon_version = constant($version_constant);
330
+		if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
331
+			remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
332
+			if (! function_exists('deactivate_plugins')) {
333
+				require_once ABSPATH . 'wp-admin/includes/plugin.php';
334
+			}
335
+			deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
336
+			unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
337
+			EE_Error::add_error(
338
+				sprintf(
339
+					esc_html__(
340
+						'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
341
+						'event_espresso'
342
+					),
343
+					$addon_name,
344
+					$min_version_required
345
+				),
346
+				__FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
347
+			);
348
+			EE_Error::get_notices(false, true);
349
+		}
350
+	}
351
+
352
+
353
+	/**
354
+	 * load_espresso_addons
355
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
356
+	 * this is hooked into both:
357
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
358
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
359
+	 *    and the WP 'activate_plugin' hook point
360
+	 *
361
+	 * @access public
362
+	 * @return void
363
+	 */
364
+	public function load_espresso_addons()
365
+	{
366
+		$this->deactivateIncompatibleAddon(
367
+			'Wait Lists',
368
+			'EE_WAIT_LISTS_VERSION',
369
+			'1.0.0.beta.074',
370
+			'load_espresso_wait_lists',
371
+			'EE_WAIT_LISTS_PLUGIN_FILE'
372
+		);
373
+		$this->deactivateIncompatibleAddon(
374
+			'Automated Upcoming Event Notifications',
375
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
376
+			'1.0.0.beta.091',
377
+			'load_espresso_automated_upcoming_event_notification',
378
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
379
+		);
380
+		do_action('AHEE__EE_System__load_espresso_addons');
381
+		//if the WP API basic auth plugin isn't already loaded, load it now.
382
+		//We want it for mobile apps. Just include the entire plugin
383
+		//also, don't load the basic auth when a plugin is getting activated, because
384
+		//it could be the basic auth plugin, and it doesn't check if its methods are already defined
385
+		//and causes a fatal error
386
+		if (
387
+			$this->request->getRequestParam('activate') !== 'true'
388
+			&& ! function_exists('json_basic_auth_handler')
389
+			&& ! function_exists('json_basic_auth_error')
390
+			&& ! in_array(
391
+				$this->request->getRequestParam('action'),
392
+				array('activate', 'activate-selected'),
393
+				true
394
+			)
395
+		) {
396
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
397
+		}
398
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
399
+	}
400
+
401
+
402
+
403
+	/**
404
+	 * detect_activations_or_upgrades
405
+	 * Checks for activation or upgrade of core first;
406
+	 * then also checks if any registered addons have been activated or upgraded
407
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
408
+	 * which runs during the WP 'plugins_loaded' action at priority 3
409
+	 *
410
+	 * @access public
411
+	 * @return void
412
+	 */
413
+	public function detect_activations_or_upgrades()
414
+	{
415
+		//first off: let's make sure to handle core
416
+		$this->detect_if_activation_or_upgrade();
417
+		foreach ($this->registry->addons as $addon) {
418
+			if ($addon instanceof EE_Addon) {
419
+				//detect teh request type for that addon
420
+				$addon->detect_activation_or_upgrade();
421
+			}
422
+		}
423
+	}
424
+
425
+
426
+
427
+	/**
428
+	 * detect_if_activation_or_upgrade
429
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
430
+	 * and either setting up the DB or setting up maintenance mode etc.
431
+	 *
432
+	 * @access public
433
+	 * @return void
434
+	 */
435
+	public function detect_if_activation_or_upgrade()
436
+	{
437
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
438
+		// check if db has been updated, or if its a brand-new installation
439
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
440
+		$request_type       = $this->detect_req_type($espresso_db_update);
441
+		//EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
442
+		switch ($request_type) {
443
+			case EE_System::req_type_new_activation:
444
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
445
+				$this->_handle_core_version_change($espresso_db_update);
446
+				break;
447
+			case EE_System::req_type_reactivation:
448
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
449
+				$this->_handle_core_version_change($espresso_db_update);
450
+				break;
451
+			case EE_System::req_type_upgrade:
452
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
453
+				//migrations may be required now that we've upgraded
454
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
455
+				$this->_handle_core_version_change($espresso_db_update);
456
+				//				echo "done upgrade";die;
457
+				break;
458
+			case EE_System::req_type_downgrade:
459
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
460
+				//its possible migrations are no longer required
461
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
462
+				$this->_handle_core_version_change($espresso_db_update);
463
+				break;
464
+			case EE_System::req_type_normal:
465
+			default:
466
+				break;
467
+		}
468
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
469
+	}
470
+
471
+
472
+
473
+	/**
474
+	 * Updates the list of installed versions and sets hooks for
475
+	 * initializing the database later during the request
476
+	 *
477
+	 * @param array $espresso_db_update
478
+	 */
479
+	private function _handle_core_version_change($espresso_db_update)
480
+	{
481
+		$this->update_list_of_installed_versions($espresso_db_update);
482
+		//get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
483
+		add_action(
484
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
485
+			array($this, 'initialize_db_if_no_migrations_required')
486
+		);
487
+	}
488
+
489
+
490
+
491
+	/**
492
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
493
+	 * information about what versions of EE have been installed and activated,
494
+	 * NOT necessarily the state of the database
495
+	 *
496
+	 * @param mixed $espresso_db_update           the value of the WordPress option.
497
+	 *                                            If not supplied, fetches it from the options table
498
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
499
+	 */
500
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
501
+	{
502
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
503
+		if (! $espresso_db_update) {
504
+			$espresso_db_update = get_option('espresso_db_update');
505
+		}
506
+		// check that option is an array
507
+		if (! is_array($espresso_db_update)) {
508
+			// if option is FALSE, then it never existed
509
+			if ($espresso_db_update === false) {
510
+				// make $espresso_db_update an array and save option with autoload OFF
511
+				$espresso_db_update = array();
512
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
513
+			} else {
514
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
515
+				$espresso_db_update = array($espresso_db_update => array());
516
+				update_option('espresso_db_update', $espresso_db_update);
517
+			}
518
+		} else {
519
+			$corrected_db_update = array();
520
+			//if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
521
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
522
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
523
+					//the key is an int, and the value IS NOT an array
524
+					//so it must be numerically-indexed, where values are versions installed...
525
+					//fix it!
526
+					$version_string                         = $should_be_array;
527
+					$corrected_db_update[ $version_string ] = array('unknown-date');
528
+				} else {
529
+					//ok it checks out
530
+					$corrected_db_update[ $should_be_version_string ] = $should_be_array;
531
+				}
532
+			}
533
+			$espresso_db_update = $corrected_db_update;
534
+			update_option('espresso_db_update', $espresso_db_update);
535
+		}
536
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
537
+		return $espresso_db_update;
538
+	}
539
+
540
+
541
+
542
+	/**
543
+	 * Does the traditional work of setting up the plugin's database and adding default data.
544
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
545
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
546
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
547
+	 * so that it will be done when migrations are finished
548
+	 *
549
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
550
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
551
+	 *                                       This is a resource-intensive job
552
+	 *                                       so we prefer to only do it when necessary
553
+	 * @return void
554
+	 * @throws EE_Error
555
+	 */
556
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
557
+	{
558
+		$request_type = $this->detect_req_type();
559
+		//only initialize system if we're not in maintenance mode.
560
+		if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
561
+			update_option('ee_flush_rewrite_rules', true);
562
+			if ($verify_schema) {
563
+				EEH_Activation::initialize_db_and_folders();
564
+			}
565
+			EEH_Activation::initialize_db_content();
566
+			EEH_Activation::system_initialization();
567
+			if ($initialize_addons_too) {
568
+				$this->initialize_addons();
569
+			}
570
+		} else {
571
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
572
+		}
573
+		if ($request_type === EE_System::req_type_new_activation
574
+			|| $request_type === EE_System::req_type_reactivation
575
+			|| (
576
+				$request_type === EE_System::req_type_upgrade
577
+				&& $this->is_major_version_change()
578
+			)
579
+		) {
580
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
581
+		}
582
+	}
583
+
584
+
585
+
586
+	/**
587
+	 * Initializes the db for all registered addons
588
+	 *
589
+	 * @throws EE_Error
590
+	 */
591
+	public function initialize_addons()
592
+	{
593
+		//foreach registered addon, make sure its db is up-to-date too
594
+		foreach ($this->registry->addons as $addon) {
595
+			if ($addon instanceof EE_Addon) {
596
+				$addon->initialize_db_if_no_migrations_required();
597
+			}
598
+		}
599
+	}
600
+
601
+
602
+
603
+	/**
604
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
605
+	 *
606
+	 * @param    array  $version_history
607
+	 * @param    string $current_version_to_add version to be added to the version history
608
+	 * @return    boolean success as to whether or not this option was changed
609
+	 */
610
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
611
+	{
612
+		if (! $version_history) {
613
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
614
+		}
615
+		if ($current_version_to_add === null) {
616
+			$current_version_to_add = espresso_version();
617
+		}
618
+		$version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
619
+		// re-save
620
+		return update_option('espresso_db_update', $version_history);
621
+	}
622
+
623
+
624
+
625
+	/**
626
+	 * Detects if the current version indicated in the has existed in the list of
627
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
628
+	 *
629
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
630
+	 *                                  If not supplied, fetches it from the options table.
631
+	 *                                  Also, caches its result so later parts of the code can also know whether
632
+	 *                                  there's been an update or not. This way we can add the current version to
633
+	 *                                  espresso_db_update, but still know if this is a new install or not
634
+	 * @return int one of the constants on EE_System::req_type_
635
+	 */
636
+	public function detect_req_type($espresso_db_update = null)
637
+	{
638
+		if ($this->_req_type === null) {
639
+			$espresso_db_update          = ! empty($espresso_db_update)
640
+				? $espresso_db_update
641
+				: $this->fix_espresso_db_upgrade_option();
642
+			$this->_req_type             = EE_System::detect_req_type_given_activation_history(
643
+				$espresso_db_update,
644
+				'ee_espresso_activation', espresso_version()
645
+			);
646
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
647
+			$this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
648
+		}
649
+		return $this->_req_type;
650
+	}
651
+
652
+
653
+
654
+	/**
655
+	 * Returns whether or not there was a non-micro version change (ie, change in either
656
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
657
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
658
+	 *
659
+	 * @param $activation_history
660
+	 * @return bool
661
+	 */
662
+	private function _detect_major_version_change($activation_history)
663
+	{
664
+		$previous_version       = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
665
+		$previous_version_parts = explode('.', $previous_version);
666
+		$current_version_parts  = explode('.', espresso_version());
667
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
668
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
669
+				   || $previous_version_parts[1] !== $current_version_parts[1]
670
+			   );
671
+	}
672
+
673
+
674
+
675
+	/**
676
+	 * Returns true if either the major or minor version of EE changed during this request.
677
+	 * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
678
+	 *
679
+	 * @return bool
680
+	 */
681
+	public function is_major_version_change()
682
+	{
683
+		return $this->_major_version_change;
684
+	}
685
+
686
+
687
+
688
+	/**
689
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
690
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
691
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
692
+	 * just activated to (for core that will always be espresso_version())
693
+	 *
694
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
695
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
696
+	 * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
697
+	 *                                                 indicate that this plugin was just activated
698
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
699
+	 *                                                 espresso_version())
700
+	 * @return int one of the constants on EE_System::req_type_*
701
+	 */
702
+	public static function detect_req_type_given_activation_history(
703
+		$activation_history_for_addon,
704
+		$activation_indicator_option_name,
705
+		$version_to_upgrade_to
706
+	) {
707
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
708
+		if ($activation_history_for_addon) {
709
+			//it exists, so this isn't a completely new install
710
+			//check if this version already in that list of previously installed versions
711
+			if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
712
+				//it a version we haven't seen before
713
+				if ($version_is_higher === 1) {
714
+					$req_type = EE_System::req_type_upgrade;
715
+				} else {
716
+					$req_type = EE_System::req_type_downgrade;
717
+				}
718
+				delete_option($activation_indicator_option_name);
719
+			} else {
720
+				// its not an update. maybe a reactivation?
721
+				if (get_option($activation_indicator_option_name, false)) {
722
+					if ($version_is_higher === -1) {
723
+						$req_type = EE_System::req_type_downgrade;
724
+					} elseif ($version_is_higher === 0) {
725
+						//we've seen this version before, but it's an activation. must be a reactivation
726
+						$req_type = EE_System::req_type_reactivation;
727
+					} else {//$version_is_higher === 1
728
+						$req_type = EE_System::req_type_upgrade;
729
+					}
730
+					delete_option($activation_indicator_option_name);
731
+				} else {
732
+					//we've seen this version before and the activation indicate doesn't show it was just activated
733
+					if ($version_is_higher === -1) {
734
+						$req_type = EE_System::req_type_downgrade;
735
+					} elseif ($version_is_higher === 0) {
736
+						//we've seen this version before and it's not an activation. its normal request
737
+						$req_type = EE_System::req_type_normal;
738
+					} else {//$version_is_higher === 1
739
+						$req_type = EE_System::req_type_upgrade;
740
+					}
741
+				}
742
+			}
743
+		} else {
744
+			//brand new install
745
+			$req_type = EE_System::req_type_new_activation;
746
+			delete_option($activation_indicator_option_name);
747
+		}
748
+		return $req_type;
749
+	}
750
+
751
+
752
+
753
+	/**
754
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
755
+	 * the $activation_history_for_addon
756
+	 *
757
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
758
+	 *                                             sometimes containing 'unknown-date'
759
+	 * @param string $version_to_upgrade_to        (current version)
760
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
761
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
762
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
763
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
764
+	 */
765
+	private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
766
+	{
767
+		//find the most recently-activated version
768
+		$most_recently_active_version =
769
+			EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
770
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
771
+	}
772
+
773
+
774
+
775
+	/**
776
+	 * Gets the most recently active version listed in the activation history,
777
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
778
+	 *
779
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
780
+	 *                                   sometimes containing 'unknown-date'
781
+	 * @return string
782
+	 */
783
+	private static function _get_most_recently_active_version_from_activation_history($activation_history)
784
+	{
785
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
786
+		$most_recently_active_version            = '0.0.0.dev.000';
787
+		if (is_array($activation_history)) {
788
+			foreach ($activation_history as $version => $times_activated) {
789
+				//check there is a record of when this version was activated. Otherwise,
790
+				//mark it as unknown
791
+				if (! $times_activated) {
792
+					$times_activated = array('unknown-date');
793
+				}
794
+				if (is_string($times_activated)) {
795
+					$times_activated = array($times_activated);
796
+				}
797
+				foreach ($times_activated as $an_activation) {
798
+					if ($an_activation !== 'unknown-date'
799
+						&& $an_activation
800
+						   > $most_recently_active_version_activation) {
801
+						$most_recently_active_version            = $version;
802
+						$most_recently_active_version_activation = $an_activation === 'unknown-date'
803
+							? '1970-01-01 00:00:00'
804
+							: $an_activation;
805
+					}
806
+				}
807
+			}
808
+		}
809
+		return $most_recently_active_version;
810
+	}
811
+
812
+
813
+
814
+	/**
815
+	 * This redirects to the about EE page after activation
816
+	 *
817
+	 * @return void
818
+	 */
819
+	public function redirect_to_about_ee()
820
+	{
821
+		$notices = EE_Error::get_notices(false);
822
+		//if current user is an admin and it's not an ajax or rest request
823
+		if (
824
+			! isset($notices['errors'])
825
+			&& $this->request->isAdmin()
826
+			&& apply_filters(
827
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
828
+				$this->capabilities->current_user_can('manage_options', 'espresso_about_default')
829
+			)
830
+		) {
831
+			$query_params = array('page' => 'espresso_about');
832
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
833
+				$query_params['new_activation'] = true;
834
+			}
835
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
836
+				$query_params['reactivation'] = true;
837
+			}
838
+			$url = add_query_arg($query_params, admin_url('admin.php'));
839
+			wp_safe_redirect($url);
840
+			exit();
841
+		}
842
+	}
843
+
844
+
845
+
846
+	/**
847
+	 * load_core_configuration
848
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
849
+	 * which runs during the WP 'plugins_loaded' action at priority 5
850
+	 *
851
+	 * @return void
852
+	 * @throws ReflectionException
853
+	 */
854
+	public function load_core_configuration()
855
+	{
856
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
857
+		$this->loader->getShared('EE_Load_Textdomain');
858
+		//load textdomain
859
+		EE_Load_Textdomain::load_textdomain();
860
+		// load and setup EE_Config and EE_Network_Config
861
+		$config = $this->loader->getShared('EE_Config');
862
+		$this->loader->getShared('EE_Network_Config');
863
+		// setup autoloaders
864
+		// enable logging?
865
+		if ($config->admin->use_full_logging) {
866
+			$this->loader->getShared('EE_Log');
867
+		}
868
+		// check for activation errors
869
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
870
+		if ($activation_errors) {
871
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
872
+			update_option('ee_plugin_activation_errors', false);
873
+		}
874
+		// get model names
875
+		$this->_parse_model_names();
876
+		//load caf stuff a chance to play during the activation process too.
877
+		$this->_maybe_brew_regular();
878
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
879
+	}
880
+
881
+
882
+
883
+	/**
884
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
885
+	 *
886
+	 * @return void
887
+	 * @throws ReflectionException
888
+	 */
889
+	private function _parse_model_names()
890
+	{
891
+		//get all the files in the EE_MODELS folder that end in .model.php
892
+		$models                 = glob(EE_MODELS . '*.model.php');
893
+		$model_names            = array();
894
+		$non_abstract_db_models = array();
895
+		foreach ($models as $model) {
896
+			// get model classname
897
+			$classname       = EEH_File::get_classname_from_filepath_with_standard_filename($model);
898
+			$short_name      = str_replace('EEM_', '', $classname);
899
+			$reflectionClass = new ReflectionClass($classname);
900
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
901
+				$non_abstract_db_models[ $short_name ] = $classname;
902
+			}
903
+			$model_names[ $short_name ] = $classname;
904
+		}
905
+		$this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
906
+		$this->registry->non_abstract_db_models = apply_filters(
907
+			'FHEE__EE_System__parse_implemented_model_names',
908
+			$non_abstract_db_models
909
+		);
910
+	}
911
+
912
+
913
+
914
+	/**
915
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
916
+	 * that need to be setup before our EE_System launches.
917
+	 *
918
+	 * @return void
919
+	 */
920
+	private function _maybe_brew_regular()
921
+	{
922
+		if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
923
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
924
+		}
925
+	}
926
+
927
+
928
+
929
+	/**
930
+	 * register_shortcodes_modules_and_widgets
931
+	 * generate lists of shortcodes and modules, then verify paths and classes
932
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
933
+	 * which runs during the WP 'plugins_loaded' action at priority 7
934
+	 *
935
+	 * @access public
936
+	 * @return void
937
+	 * @throws Exception
938
+	 */
939
+	public function register_shortcodes_modules_and_widgets()
940
+	{
941
+		if ($this->request->isFrontend() || $this->request->isIframe()) {
942
+			try {
943
+				// load, register, and add shortcodes the new way
944
+				$this->loader->getShared(
945
+					'EventEspresso\core\services\shortcodes\ShortcodesManager',
946
+					array(
947
+						// and the old way, but we'll put it under control of the new system
948
+						EE_Config::getLegacyShortcodesManager(),
949
+					)
950
+				);
951
+				// or the even newer newer new way
952
+				if(function_exists('register_block_type')) {
953
+					$this->loader->getShared(
954
+						'EventEspresso\core\services\editor\EditorBlockManager',
955
+						array(
956
+							$this->loader->getShared(
957
+								'EventEspresso\core\domain\entities\editor\EditorBlockCollection'
958
+							),
959
+							$this->request,
960
+						)
961
+					);
962
+				}
963
+			} catch (Exception $exception) {
964
+				new ExceptionStackTraceDisplay($exception);
965
+			}
966
+		}
967
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
968
+		// check for addons using old hook point
969
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
970
+			$this->_incompatible_addon_error();
971
+		}
972
+	}
973
+
974
+
975
+
976
+	/**
977
+	 * _incompatible_addon_error
978
+	 *
979
+	 * @access public
980
+	 * @return void
981
+	 */
982
+	private function _incompatible_addon_error()
983
+	{
984
+		// get array of classes hooking into here
985
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
986
+			'AHEE__EE_System__register_shortcodes_modules_and_addons'
987
+		);
988
+		if (! empty($class_names)) {
989
+			$msg = __(
990
+				'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
991
+				'event_espresso'
992
+			);
993
+			$msg .= '<ul>';
994
+			foreach ($class_names as $class_name) {
995
+				$msg .= '<li><b>Event Espresso - ' . str_replace(
996
+						array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
997
+						$class_name
998
+					) . '</b></li>';
999
+			}
1000
+			$msg .= '</ul>';
1001
+			$msg .= __(
1002
+				'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1003
+				'event_espresso'
1004
+			);
1005
+			// save list of incompatible addons to wp-options for later use
1006
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
1007
+			if (is_admin()) {
1008
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1009
+			}
1010
+		}
1011
+	}
1012
+
1013
+
1014
+
1015
+	/**
1016
+	 * brew_espresso
1017
+	 * begins the process of setting hooks for initializing EE in the correct order
1018
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1019
+	 * which runs during the WP 'plugins_loaded' action at priority 9
1020
+	 *
1021
+	 * @return void
1022
+	 */
1023
+	public function brew_espresso()
1024
+	{
1025
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
1026
+		// load some final core systems
1027
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
1028
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1029
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
1030
+		add_action('init', array($this, 'load_controllers'), 7);
1031
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
1032
+		add_action('init', array($this, 'initialize'), 10);
1033
+		add_action('init', array($this, 'initialize_last'), 100);
1034
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1035
+			// pew pew pew
1036
+			$this->loader->getShared('EE_PUE');
1037
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1038
+		}
1039
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
1040
+	}
1041
+
1042
+
1043
+
1044
+	/**
1045
+	 *    set_hooks_for_core
1046
+	 *
1047
+	 * @access public
1048
+	 * @return    void
1049
+	 * @throws EE_Error
1050
+	 */
1051
+	public function set_hooks_for_core()
1052
+	{
1053
+		$this->_deactivate_incompatible_addons();
1054
+		do_action('AHEE__EE_System__set_hooks_for_core');
1055
+		//caps need to be initialized on every request so that capability maps are set.
1056
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1057
+		$this->registry->CAP->init_caps();
1058
+	}
1059
+
1060
+
1061
+
1062
+	/**
1063
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
1064
+	 * deactivates any addons considered incompatible with the current version of EE
1065
+	 */
1066
+	private function _deactivate_incompatible_addons()
1067
+	{
1068
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
1069
+		if (! empty($incompatible_addons)) {
1070
+			$active_plugins = get_option('active_plugins', array());
1071
+			foreach ($active_plugins as $active_plugin) {
1072
+				foreach ($incompatible_addons as $incompatible_addon) {
1073
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
1074
+						unset($_GET['activate']);
1075
+						espresso_deactivate_plugin($active_plugin);
1076
+					}
1077
+				}
1078
+			}
1079
+		}
1080
+	}
1081
+
1082
+
1083
+
1084
+	/**
1085
+	 *    perform_activations_upgrades_and_migrations
1086
+	 *
1087
+	 * @access public
1088
+	 * @return    void
1089
+	 */
1090
+	public function perform_activations_upgrades_and_migrations()
1091
+	{
1092
+		//first check if we had previously attempted to setup EE's directories but failed
1093
+		if ($this->request->isActivation() && EEH_Activation::upload_directories_incomplete()) {
1094
+			EEH_Activation::create_upload_directories();
1095
+		}
1096
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1097
+	}
1098
+
1099
+
1100
+
1101
+	/**
1102
+	 *    load_CPTs_and_session
1103
+	 *
1104
+	 * @access public
1105
+	 * @return    void
1106
+	 */
1107
+	public function load_CPTs_and_session()
1108
+	{
1109
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
1110
+		// register Custom Post Types
1111
+		$this->loader->getShared('EE_Register_CPTs');
1112
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1113
+	}
1114
+
1115
+
1116
+
1117
+	/**
1118
+	 * load_controllers
1119
+	 * this is the best place to load any additional controllers that needs access to EE core.
1120
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1121
+	 * time
1122
+	 *
1123
+	 * @access public
1124
+	 * @return void
1125
+	 */
1126
+	public function load_controllers()
1127
+	{
1128
+		do_action('AHEE__EE_System__load_controllers__start');
1129
+		// let's get it started
1130
+		if (
1131
+			! $this->maintenance_mode->level()
1132
+			&& ($this->request->isFrontend() || $this->request->isFrontAjax())
1133
+		) {
1134
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1135
+			$this->loader->getShared('EE_Front_Controller');
1136
+		} elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1137
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1138
+			$this->loader->getShared('EE_Admin');
1139
+		}
1140
+		do_action('AHEE__EE_System__load_controllers__complete');
1141
+	}
1142
+
1143
+
1144
+
1145
+	/**
1146
+	 * core_loaded_and_ready
1147
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1148
+	 *
1149
+	 * @access public
1150
+	 * @return void
1151
+	 */
1152
+	public function core_loaded_and_ready()
1153
+	{
1154
+		if (
1155
+			$this->request->isAdmin()
1156
+			|| $this->request->isEeAjax()
1157
+			|| $this->request->isFrontend()
1158
+		) {
1159
+			$this->loader->getShared('EE_Session');
1160
+		}
1161
+		do_action('AHEE__EE_System__core_loaded_and_ready');
1162
+		// load_espresso_template_tags
1163
+		if (
1164
+			is_readable(EE_PUBLIC . 'template_tags.php')
1165
+			&& ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isFeed())
1166
+		) {
1167
+			require_once EE_PUBLIC . 'template_tags.php';
1168
+		}
1169
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1170
+		if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
1171
+			$this->loader->getShared('EventEspresso\core\services\assets\Registry');
1172
+		}
1173
+	}
1174
+
1175
+
1176
+
1177
+	/**
1178
+	 * initialize
1179
+	 * this is the best place to begin initializing client code
1180
+	 *
1181
+	 * @access public
1182
+	 * @return void
1183
+	 */
1184
+	public function initialize()
1185
+	{
1186
+		do_action('AHEE__EE_System__initialize');
1187
+	}
1188
+
1189
+
1190
+
1191
+	/**
1192
+	 * initialize_last
1193
+	 * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1194
+	 * initialize has done so
1195
+	 *
1196
+	 * @access public
1197
+	 * @return void
1198
+	 */
1199
+	public function initialize_last()
1200
+	{
1201
+		do_action('AHEE__EE_System__initialize_last');
1202
+		add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1203
+	}
1204
+
1205
+
1206
+
1207
+	/**
1208
+	 * @return void
1209
+	 * @throws EE_Error
1210
+	 */
1211
+	public function addEspressoToolbar()
1212
+	{
1213
+		$this->loader->getShared(
1214
+			'EventEspresso\core\domain\services\admin\AdminToolBar',
1215
+			array($this->registry->CAP)
1216
+		);
1217
+	}
1218
+
1219
+
1220
+
1221
+	/**
1222
+	 * do_not_cache
1223
+	 * sets no cache headers and defines no cache constants for WP plugins
1224
+	 *
1225
+	 * @access public
1226
+	 * @return void
1227
+	 */
1228
+	public static function do_not_cache()
1229
+	{
1230
+		// set no cache constants
1231
+		if (! defined('DONOTCACHEPAGE')) {
1232
+			define('DONOTCACHEPAGE', true);
1233
+		}
1234
+		if (! defined('DONOTCACHCEOBJECT')) {
1235
+			define('DONOTCACHCEOBJECT', true);
1236
+		}
1237
+		if (! defined('DONOTCACHEDB')) {
1238
+			define('DONOTCACHEDB', true);
1239
+		}
1240
+		// add no cache headers
1241
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1242
+		// plus a little extra for nginx and Google Chrome
1243
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1244
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1245
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1246
+	}
1247
+
1248
+
1249
+
1250
+	/**
1251
+	 *    extra_nocache_headers
1252
+	 *
1253
+	 * @access    public
1254
+	 * @param $headers
1255
+	 * @return    array
1256
+	 */
1257
+	public static function extra_nocache_headers($headers)
1258
+	{
1259
+		// for NGINX
1260
+		$headers['X-Accel-Expires'] = 0;
1261
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1262
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1263
+		return $headers;
1264
+	}
1265
+
1266
+
1267
+
1268
+	/**
1269
+	 *    nocache_headers
1270
+	 *
1271
+	 * @access    public
1272
+	 * @return    void
1273
+	 */
1274
+	public static function nocache_headers()
1275
+	{
1276
+		nocache_headers();
1277
+	}
1278
+
1279
+
1280
+
1281
+	/**
1282
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1283
+	 * never returned with the function.
1284
+	 *
1285
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1286
+	 * @return array
1287
+	 */
1288
+	public function remove_pages_from_wp_list_pages($exclude_array)
1289
+	{
1290
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1291
+	}
1292 1292
 
1293 1293
 
1294 1294
 
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
         EE_Maintenance_Mode $maintenance_mode = null
141 141
     ) {
142 142
         // check if class object is instantiated
143
-        if (! self::$_instance instanceof EE_System) {
143
+        if ( ! self::$_instance instanceof EE_System) {
144 144
             self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
145 145
         }
146 146
         return self::$_instance;
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
         $this->capabilities = $this->loader->getShared('EE_Capabilities');
260 260
         add_action(
261 261
             'AHEE__EE_Capabilities__init_caps__before_initialization',
262
-            function ()
262
+            function()
263 263
             {
264 264
                 LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
265 265
             }
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
     {
304 304
         // set autoloaders for all of the classes implementing EEI_Plugin_API
305 305
         // which provide helpers for EE plugin authors to more easily register certain components with EE.
306
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
306
+        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api');
307 307
         $this->loader->getShared('EE_Request_Handler');
308 308
     }
309 309
 
@@ -323,14 +323,14 @@  discard block
 block discarded – undo
323 323
         $load_callback,
324 324
         $plugin_file_constant
325 325
     ) {
326
-        if (! defined($version_constant)) {
326
+        if ( ! defined($version_constant)) {
327 327
             return;
328 328
         }
329 329
         $addon_version = constant($version_constant);
330 330
         if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
331 331
             remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
332
-            if (! function_exists('deactivate_plugins')) {
333
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
332
+            if ( ! function_exists('deactivate_plugins')) {
333
+                require_once ABSPATH.'wp-admin/includes/plugin.php';
334 334
             }
335 335
             deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
336 336
             unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
                     $addon_name,
344 344
                     $min_version_required
345 345
                 ),
346
-                __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
346
+                __FILE__, __FUNCTION__."({$addon_name})", __LINE__
347 347
             );
348 348
             EE_Error::get_notices(false, true);
349 349
         }
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
                 true
394 394
             )
395 395
         ) {
396
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
396
+            include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php';
397 397
         }
398 398
         do_action('AHEE__EE_System__load_espresso_addons__complete');
399 399
     }
@@ -500,11 +500,11 @@  discard block
 block discarded – undo
500 500
     private function fix_espresso_db_upgrade_option($espresso_db_update = null)
501 501
     {
502 502
         do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
503
-        if (! $espresso_db_update) {
503
+        if ( ! $espresso_db_update) {
504 504
             $espresso_db_update = get_option('espresso_db_update');
505 505
         }
506 506
         // check that option is an array
507
-        if (! is_array($espresso_db_update)) {
507
+        if ( ! is_array($espresso_db_update)) {
508 508
             // if option is FALSE, then it never existed
509 509
             if ($espresso_db_update === false) {
510 510
                 // make $espresso_db_update an array and save option with autoload OFF
@@ -524,10 +524,10 @@  discard block
 block discarded – undo
524 524
                     //so it must be numerically-indexed, where values are versions installed...
525 525
                     //fix it!
526 526
                     $version_string                         = $should_be_array;
527
-                    $corrected_db_update[ $version_string ] = array('unknown-date');
527
+                    $corrected_db_update[$version_string] = array('unknown-date');
528 528
                 } else {
529 529
                     //ok it checks out
530
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
530
+                    $corrected_db_update[$should_be_version_string] = $should_be_array;
531 531
                 }
532 532
             }
533 533
             $espresso_db_update = $corrected_db_update;
@@ -609,13 +609,13 @@  discard block
 block discarded – undo
609 609
      */
610 610
     public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
611 611
     {
612
-        if (! $version_history) {
612
+        if ( ! $version_history) {
613 613
             $version_history = $this->fix_espresso_db_upgrade_option($version_history);
614 614
         }
615 615
         if ($current_version_to_add === null) {
616 616
             $current_version_to_add = espresso_version();
617 617
         }
618
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
618
+        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
619 619
         // re-save
620 620
         return update_option('espresso_db_update', $version_history);
621 621
     }
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
         if ($activation_history_for_addon) {
709 709
             //it exists, so this isn't a completely new install
710 710
             //check if this version already in that list of previously installed versions
711
-            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
711
+            if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
712 712
                 //it a version we haven't seen before
713 713
                 if ($version_is_higher === 1) {
714 714
                     $req_type = EE_System::req_type_upgrade;
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
             foreach ($activation_history as $version => $times_activated) {
789 789
                 //check there is a record of when this version was activated. Otherwise,
790 790
                 //mark it as unknown
791
-                if (! $times_activated) {
791
+                if ( ! $times_activated) {
792 792
                     $times_activated = array('unknown-date');
793 793
                 }
794 794
                 if (is_string($times_activated)) {
@@ -889,7 +889,7 @@  discard block
 block discarded – undo
889 889
     private function _parse_model_names()
890 890
     {
891 891
         //get all the files in the EE_MODELS folder that end in .model.php
892
-        $models                 = glob(EE_MODELS . '*.model.php');
892
+        $models                 = glob(EE_MODELS.'*.model.php');
893 893
         $model_names            = array();
894 894
         $non_abstract_db_models = array();
895 895
         foreach ($models as $model) {
@@ -898,9 +898,9 @@  discard block
 block discarded – undo
898 898
             $short_name      = str_replace('EEM_', '', $classname);
899 899
             $reflectionClass = new ReflectionClass($classname);
900 900
             if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
901
-                $non_abstract_db_models[ $short_name ] = $classname;
901
+                $non_abstract_db_models[$short_name] = $classname;
902 902
             }
903
-            $model_names[ $short_name ] = $classname;
903
+            $model_names[$short_name] = $classname;
904 904
         }
905 905
         $this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
906 906
         $this->registry->non_abstract_db_models = apply_filters(
@@ -919,8 +919,8 @@  discard block
 block discarded – undo
919 919
      */
920 920
     private function _maybe_brew_regular()
921 921
     {
922
-        if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
923
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
922
+        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) {
923
+            require_once EE_CAFF_PATH.'brewing_regular.php';
924 924
         }
925 925
     }
926 926
 
@@ -949,7 +949,7 @@  discard block
 block discarded – undo
949 949
                     )
950 950
                 );
951 951
                 // or the even newer newer new way
952
-                if(function_exists('register_block_type')) {
952
+                if (function_exists('register_block_type')) {
953 953
                     $this->loader->getShared(
954 954
                         'EventEspresso\core\services\editor\EditorBlockManager',
955 955
                         array(
@@ -985,17 +985,17 @@  discard block
 block discarded – undo
985 985
         $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
986 986
             'AHEE__EE_System__register_shortcodes_modules_and_addons'
987 987
         );
988
-        if (! empty($class_names)) {
988
+        if ( ! empty($class_names)) {
989 989
             $msg = __(
990 990
                 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
991 991
                 'event_espresso'
992 992
             );
993 993
             $msg .= '<ul>';
994 994
             foreach ($class_names as $class_name) {
995
-                $msg .= '<li><b>Event Espresso - ' . str_replace(
995
+                $msg .= '<li><b>Event Espresso - '.str_replace(
996 996
                         array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
997 997
                         $class_name
998
-                    ) . '</b></li>';
998
+                    ).'</b></li>';
999 999
             }
1000 1000
             $msg .= '</ul>';
1001 1001
             $msg .= __(
@@ -1066,7 +1066,7 @@  discard block
 block discarded – undo
1066 1066
     private function _deactivate_incompatible_addons()
1067 1067
     {
1068 1068
         $incompatible_addons = get_option('ee_incompatible_addons', array());
1069
-        if (! empty($incompatible_addons)) {
1069
+        if ( ! empty($incompatible_addons)) {
1070 1070
             $active_plugins = get_option('active_plugins', array());
1071 1071
             foreach ($active_plugins as $active_plugin) {
1072 1072
                 foreach ($incompatible_addons as $incompatible_addon) {
@@ -1161,10 +1161,10 @@  discard block
 block discarded – undo
1161 1161
         do_action('AHEE__EE_System__core_loaded_and_ready');
1162 1162
         // load_espresso_template_tags
1163 1163
         if (
1164
-            is_readable(EE_PUBLIC . 'template_tags.php')
1164
+            is_readable(EE_PUBLIC.'template_tags.php')
1165 1165
             && ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isFeed())
1166 1166
         ) {
1167
-            require_once EE_PUBLIC . 'template_tags.php';
1167
+            require_once EE_PUBLIC.'template_tags.php';
1168 1168
         }
1169 1169
         do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1170 1170
         if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
@@ -1228,13 +1228,13 @@  discard block
 block discarded – undo
1228 1228
     public static function do_not_cache()
1229 1229
     {
1230 1230
         // set no cache constants
1231
-        if (! defined('DONOTCACHEPAGE')) {
1231
+        if ( ! defined('DONOTCACHEPAGE')) {
1232 1232
             define('DONOTCACHEPAGE', true);
1233 1233
         }
1234
-        if (! defined('DONOTCACHCEOBJECT')) {
1234
+        if ( ! defined('DONOTCACHCEOBJECT')) {
1235 1235
             define('DONOTCACHCEOBJECT', true);
1236 1236
         }
1237
-        if (! defined('DONOTCACHEDB')) {
1237
+        if ( ! defined('DONOTCACHEDB')) {
1238 1238
             define('DONOTCACHEDB', true);
1239 1239
         }
1240 1240
         // add no cache headers
Please login to merge, or discard this patch.