Completed
Branch FET/extract-admin-menu (26a1ca)
by
unknown
25:33 queued 18:45
created
core/domain/entities/routing/handlers/admin/EspressoLegacyAdmin.php 1 patch
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -17,119 +17,119 @@
 block discarded – undo
17 17
  */
18 18
 class EspressoLegacyAdmin extends AdminRoute
19 19
 {
20
-    /**
21
-     * @var LegacyAccountingAssetManager $asset_manager
22
-     */
23
-    protected $asset_manager;
20
+	/**
21
+	 * @var LegacyAccountingAssetManager $asset_manager
22
+	 */
23
+	protected $asset_manager;
24 24
 
25 25
 
26
-    /**
27
-     * returns true if the current request matches this route
28
-     *
29
-     * @return bool
30
-     * @since   $VID:$
31
-     */
32
-    public function matchesCurrentRequest(): bool
33
-    {
34
-        global $pagenow;
35
-        return $pagenow === 'admin.php' && parent::matchesCurrentRequest();
36
-    }
26
+	/**
27
+	 * returns true if the current request matches this route
28
+	 *
29
+	 * @return bool
30
+	 * @since   $VID:$
31
+	 */
32
+	public function matchesCurrentRequest(): bool
33
+	{
34
+		global $pagenow;
35
+		return $pagenow === 'admin.php' && parent::matchesCurrentRequest();
36
+	}
37 37
 
38 38
 
39
-    /**
40
-     * @since $VID:$
41
-     */
42
-    protected function registerDependencies()
43
-    {
44
-        $asset_manger_dependencies = [
45
-            'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
46
-            'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_new_object,
47
-            'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
48
-        ];
49
-        $this->dependency_map->registerDependencies(JqueryAssetManager::class, $asset_manger_dependencies);
50
-        $this->dependency_map->registerDependencies(EspressoLegacyAdminAssetManager::class, $asset_manger_dependencies);
51
-        $this->dependency_map->registerDependencies(
52
-            LegacyAccountingAssetManager::class,
53
-            ['EE_Currency_Config' => EE_Dependency_Map::load_from_cache] + $asset_manger_dependencies
54
-        );
55
-        $this->dependency_map->registerDependencies(
56
-            'EE_Admin_Transactions_List_Table',
57
-            [
58
-                null,
59
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
60
-            ]
61
-        );
62
-        $this->dependency_map->registerDependencies(
63
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings',
64
-            ['EE_Registration_Config' => EE_Dependency_Map::load_from_cache]
65
-        );
66
-        $this->dependency_map->registerDependencies(
67
-            'EventEspresso\admin_pages\general_settings\OrganizationSettings',
68
-            [
69
-                'EE_Registry'                                             => EE_Dependency_Map::load_from_cache,
70
-                'EE_Organization_Config'                                  => EE_Dependency_Map::load_from_cache,
71
-                'EE_Core_Config'                                          => EE_Dependency_Map::load_from_cache,
72
-                'EE_Network_Core_Config'                                  => EE_Dependency_Map::load_from_cache,
73
-                'EventEspresso\core\services\address\CountrySubRegionDao' => EE_Dependency_Map::load_from_cache,
74
-            ]
75
-        );
76
-        $this->dependency_map->registerDependencies(
77
-            'EventEspresso\core\services\address\CountrySubRegionDao',
78
-            [
79
-                'EEM_State'                                            => EE_Dependency_Map::load_from_cache,
80
-                'EventEspresso\core\services\validators\JsonValidator' => EE_Dependency_Map::load_from_cache
81
-            ]
82
-        );
83
-        $this->dependency_map->registerDependencies(
84
-            'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
85
-            [
86
-                null,
87
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
88
-                'EEM_Registration'                            => EE_Dependency_Map::load_from_cache,
89
-            ]
90
-        );
91
-        $this->dependency_map->registerDependencies(
92
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
93
-            [
94
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
95
-                'EEM_Attendee'                                => EE_Dependency_Map::load_from_cache,
96
-            ]
97
-        );
98
-        $this->dependency_map->registerDependencies(
99
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
100
-            [
101
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
102
-                'EEM_Datetime'                                => EE_Dependency_Map::load_from_cache,
103
-            ]
104
-        );
105
-        $this->dependency_map->registerDependencies(
106
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
107
-            [
108
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
109
-                'EEM_Event'                                   => EE_Dependency_Map::load_from_cache,
110
-            ]
111
-        );
112
-        $this->dependency_map->registerDependencies(
113
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
114
-            [
115
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
116
-                'EEM_Ticket'                                  => EE_Dependency_Map::load_from_cache,
117
-            ]
118
-        );
119
-    }
39
+	/**
40
+	 * @since $VID:$
41
+	 */
42
+	protected function registerDependencies()
43
+	{
44
+		$asset_manger_dependencies = [
45
+			'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
46
+			'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_new_object,
47
+			'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
48
+		];
49
+		$this->dependency_map->registerDependencies(JqueryAssetManager::class, $asset_manger_dependencies);
50
+		$this->dependency_map->registerDependencies(EspressoLegacyAdminAssetManager::class, $asset_manger_dependencies);
51
+		$this->dependency_map->registerDependencies(
52
+			LegacyAccountingAssetManager::class,
53
+			['EE_Currency_Config' => EE_Dependency_Map::load_from_cache] + $asset_manger_dependencies
54
+		);
55
+		$this->dependency_map->registerDependencies(
56
+			'EE_Admin_Transactions_List_Table',
57
+			[
58
+				null,
59
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
60
+			]
61
+		);
62
+		$this->dependency_map->registerDependencies(
63
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings',
64
+			['EE_Registration_Config' => EE_Dependency_Map::load_from_cache]
65
+		);
66
+		$this->dependency_map->registerDependencies(
67
+			'EventEspresso\admin_pages\general_settings\OrganizationSettings',
68
+			[
69
+				'EE_Registry'                                             => EE_Dependency_Map::load_from_cache,
70
+				'EE_Organization_Config'                                  => EE_Dependency_Map::load_from_cache,
71
+				'EE_Core_Config'                                          => EE_Dependency_Map::load_from_cache,
72
+				'EE_Network_Core_Config'                                  => EE_Dependency_Map::load_from_cache,
73
+				'EventEspresso\core\services\address\CountrySubRegionDao' => EE_Dependency_Map::load_from_cache,
74
+			]
75
+		);
76
+		$this->dependency_map->registerDependencies(
77
+			'EventEspresso\core\services\address\CountrySubRegionDao',
78
+			[
79
+				'EEM_State'                                            => EE_Dependency_Map::load_from_cache,
80
+				'EventEspresso\core\services\validators\JsonValidator' => EE_Dependency_Map::load_from_cache
81
+			]
82
+		);
83
+		$this->dependency_map->registerDependencies(
84
+			'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
85
+			[
86
+				null,
87
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
88
+				'EEM_Registration'                            => EE_Dependency_Map::load_from_cache,
89
+			]
90
+		);
91
+		$this->dependency_map->registerDependencies(
92
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
93
+			[
94
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
95
+				'EEM_Attendee'                                => EE_Dependency_Map::load_from_cache,
96
+			]
97
+		);
98
+		$this->dependency_map->registerDependencies(
99
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
100
+			[
101
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
102
+				'EEM_Datetime'                                => EE_Dependency_Map::load_from_cache,
103
+			]
104
+		);
105
+		$this->dependency_map->registerDependencies(
106
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
107
+			[
108
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
109
+				'EEM_Event'                                   => EE_Dependency_Map::load_from_cache,
110
+			]
111
+		);
112
+		$this->dependency_map->registerDependencies(
113
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
114
+			[
115
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
116
+				'EEM_Ticket'                                  => EE_Dependency_Map::load_from_cache,
117
+			]
118
+		);
119
+	}
120 120
 
121 121
 
122
-    /**
123
-     * implements logic required to run during request
124
-     *
125
-     * @return bool
126
-     * @since   $VID:$
127
-     */
128
-    protected function requestHandler(): bool
129
-    {
130
-        $this->loader->getShared(JqueryAssetManager::class);
131
-        $this->loader->getShared(EspressoLegacyAdminAssetManager::class);
132
-        $this->loader->getShared(LegacyAccountingAssetManager::class);
133
-        return true;
134
-    }
122
+	/**
123
+	 * implements logic required to run during request
124
+	 *
125
+	 * @return bool
126
+	 * @since   $VID:$
127
+	 */
128
+	protected function requestHandler(): bool
129
+	{
130
+		$this->loader->getShared(JqueryAssetManager::class);
131
+		$this->loader->getShared(EspressoLegacyAdminAssetManager::class);
132
+		$this->loader->getShared(LegacyAccountingAssetManager::class);
133
+		return true;
134
+	}
135 135
 }
Please login to merge, or discard this patch.
core/domain/entities/routing/handlers/shared/RegularRequests.php 1 patch
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -16,149 +16,149 @@
 block discarded – undo
16 16
  */
17 17
 class RegularRequests extends PrimaryRoute
18 18
 {
19
-    /**
20
-     * called just before matchesCurrentRequest()
21
-     * and allows Route to perform any setup required such as calling setSpecification()
22
-     *
23
-     * @since $VID:$
24
-     */
25
-    public function initialize()
26
-    {
27
-        $basic_nodes = [
28
-            'EventEspresso\core\domain\entities\routing\data_nodes\core\Api',
29
-            'EventEspresso\core\domain\entities\routing\data_nodes\core\Capabilities',
30
-            'EventEspresso\core\domain\entities\routing\data_nodes\core\Locale',
31
-            'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteUrls',
32
-        ];
33
-        foreach ($basic_nodes as $basic_node) {
34
-            $this->dependency_map->registerDependencies(
35
-                $basic_node,
36
-                ['EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache]
37
-            );
38
-        }
39
-        $this->dependency_map->registerDependencies(
40
-            'EventEspresso\core\domain\entities\routing\data_nodes\core\SitePermissions',
41
-            [
42
-                'EventEspresso\core\domain\services\capabilities\FeatureFlags' => EE_Dependency_Map::load_from_cache,
43
-                'EventEspresso\core\services\json\JsonDataNodeValidator'       => EE_Dependency_Map::load_from_cache,
44
-            ]
45
-        );
46
-        $this->dependency_map->registerDependencies(
47
-            'EventEspresso\core\domain\entities\routing\data_nodes\core\GeneralSettings',
48
-            [
49
-                'EventEspresso\core\services\json\JsonDataNodeValidator'                => EE_Dependency_Map::load_from_cache,
50
-                'EventEspresso\core\services\converters\date_time_formats\PhpToUnicode' => EE_Dependency_Map::load_from_cache,
51
-            ]
52
-        );
53
-        $this->dependency_map->registerDependencies(
54
-            'EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData',
55
-            [
56
-                'EventEspresso\core\domain\entities\routing\data_nodes\core\Api'    => EE_Dependency_Map::load_from_cache,
57
-                'EventEspresso\core\domain\entities\routing\data_nodes\core\Config' => EE_Dependency_Map::load_from_cache,
58
-                'EventEspresso\core\services\assets\JedLocaleData'                  => EE_Dependency_Map::load_from_cache,
59
-                'EventEspresso\core\services\json\JsonDataNodeValidator'            => EE_Dependency_Map::load_from_cache,
60
-            ]
61
-        );
62
-        $this->dependency_map->registerDependencies(
63
-            'EventEspresso\core\domain\entities\routing\data_nodes\core\Config',
64
-            [
65
-                'EventEspresso\core\domain\entities\routing\data_nodes\core\CurrentUser'        => EE_Dependency_Map::load_from_cache,
66
-                'EventEspresso\core\domain\entities\routing\data_nodes\core\EspressoCoreDomain' => EE_Dependency_Map::load_from_cache,
67
-                'EventEspresso\core\domain\entities\routing\data_nodes\core\GeneralSettings'    => EE_Dependency_Map::load_from_cache,
68
-                'EventEspresso\core\domain\entities\routing\data_nodes\core\Locale'             => EE_Dependency_Map::load_from_cache,
69
-                'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteCurrency'       => EE_Dependency_Map::load_from_cache,
70
-                'EventEspresso\core\domain\entities\routing\data_nodes\core\SitePermissions'    => EE_Dependency_Map::load_from_cache,
71
-                'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteUrls'           => EE_Dependency_Map::load_from_cache,
72
-                'EventEspresso\core\services\json\JsonDataNodeValidator'                        => EE_Dependency_Map::load_from_cache,
73
-            ]
74
-        );
75
-        $this->dependency_map->registerDependencies(
76
-            'EventEspresso\core\domain\entities\routing\data_nodes\core\CurrentUser',
77
-            [
78
-                'EventEspresso\core\domain\entities\routing\data_nodes\core\Capabilities' => EE_Dependency_Map::load_from_cache,
79
-                'EventEspresso\core\services\json\JsonDataNodeValidator'                  => EE_Dependency_Map::load_from_cache,
80
-            ]
81
-        );
82
-        $this->dependency_map->registerDependencies(
83
-            'EventEspresso\core\domain\entities\routing\data_nodes\core\EspressoCoreDomain',
84
-            [
85
-                'EventEspresso\core\domain\Domain'                       => EE_Dependency_Map::load_from_cache,
86
-                'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache,
87
-            ]
88
-        );
89
-        $this->dependency_map->registerDependencies(
90
-            'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteCurrency',
91
-            [
92
-                'EE_Currency_Config'                                     => EE_Dependency_Map::load_from_cache,
93
-                'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache,
94
-            ]
95
-        );
96
-        $this->setDataNode(
97
-            $this->loader->getShared('EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData')
98
-        );
99
-    }
19
+	/**
20
+	 * called just before matchesCurrentRequest()
21
+	 * and allows Route to perform any setup required such as calling setSpecification()
22
+	 *
23
+	 * @since $VID:$
24
+	 */
25
+	public function initialize()
26
+	{
27
+		$basic_nodes = [
28
+			'EventEspresso\core\domain\entities\routing\data_nodes\core\Api',
29
+			'EventEspresso\core\domain\entities\routing\data_nodes\core\Capabilities',
30
+			'EventEspresso\core\domain\entities\routing\data_nodes\core\Locale',
31
+			'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteUrls',
32
+		];
33
+		foreach ($basic_nodes as $basic_node) {
34
+			$this->dependency_map->registerDependencies(
35
+				$basic_node,
36
+				['EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache]
37
+			);
38
+		}
39
+		$this->dependency_map->registerDependencies(
40
+			'EventEspresso\core\domain\entities\routing\data_nodes\core\SitePermissions',
41
+			[
42
+				'EventEspresso\core\domain\services\capabilities\FeatureFlags' => EE_Dependency_Map::load_from_cache,
43
+				'EventEspresso\core\services\json\JsonDataNodeValidator'       => EE_Dependency_Map::load_from_cache,
44
+			]
45
+		);
46
+		$this->dependency_map->registerDependencies(
47
+			'EventEspresso\core\domain\entities\routing\data_nodes\core\GeneralSettings',
48
+			[
49
+				'EventEspresso\core\services\json\JsonDataNodeValidator'                => EE_Dependency_Map::load_from_cache,
50
+				'EventEspresso\core\services\converters\date_time_formats\PhpToUnicode' => EE_Dependency_Map::load_from_cache,
51
+			]
52
+		);
53
+		$this->dependency_map->registerDependencies(
54
+			'EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData',
55
+			[
56
+				'EventEspresso\core\domain\entities\routing\data_nodes\core\Api'    => EE_Dependency_Map::load_from_cache,
57
+				'EventEspresso\core\domain\entities\routing\data_nodes\core\Config' => EE_Dependency_Map::load_from_cache,
58
+				'EventEspresso\core\services\assets\JedLocaleData'                  => EE_Dependency_Map::load_from_cache,
59
+				'EventEspresso\core\services\json\JsonDataNodeValidator'            => EE_Dependency_Map::load_from_cache,
60
+			]
61
+		);
62
+		$this->dependency_map->registerDependencies(
63
+			'EventEspresso\core\domain\entities\routing\data_nodes\core\Config',
64
+			[
65
+				'EventEspresso\core\domain\entities\routing\data_nodes\core\CurrentUser'        => EE_Dependency_Map::load_from_cache,
66
+				'EventEspresso\core\domain\entities\routing\data_nodes\core\EspressoCoreDomain' => EE_Dependency_Map::load_from_cache,
67
+				'EventEspresso\core\domain\entities\routing\data_nodes\core\GeneralSettings'    => EE_Dependency_Map::load_from_cache,
68
+				'EventEspresso\core\domain\entities\routing\data_nodes\core\Locale'             => EE_Dependency_Map::load_from_cache,
69
+				'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteCurrency'       => EE_Dependency_Map::load_from_cache,
70
+				'EventEspresso\core\domain\entities\routing\data_nodes\core\SitePermissions'    => EE_Dependency_Map::load_from_cache,
71
+				'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteUrls'           => EE_Dependency_Map::load_from_cache,
72
+				'EventEspresso\core\services\json\JsonDataNodeValidator'                        => EE_Dependency_Map::load_from_cache,
73
+			]
74
+		);
75
+		$this->dependency_map->registerDependencies(
76
+			'EventEspresso\core\domain\entities\routing\data_nodes\core\CurrentUser',
77
+			[
78
+				'EventEspresso\core\domain\entities\routing\data_nodes\core\Capabilities' => EE_Dependency_Map::load_from_cache,
79
+				'EventEspresso\core\services\json\JsonDataNodeValidator'                  => EE_Dependency_Map::load_from_cache,
80
+			]
81
+		);
82
+		$this->dependency_map->registerDependencies(
83
+			'EventEspresso\core\domain\entities\routing\data_nodes\core\EspressoCoreDomain',
84
+			[
85
+				'EventEspresso\core\domain\Domain'                       => EE_Dependency_Map::load_from_cache,
86
+				'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache,
87
+			]
88
+		);
89
+		$this->dependency_map->registerDependencies(
90
+			'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteCurrency',
91
+			[
92
+				'EE_Currency_Config'                                     => EE_Dependency_Map::load_from_cache,
93
+				'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache,
94
+			]
95
+		);
96
+		$this->setDataNode(
97
+			$this->loader->getShared('EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData')
98
+		);
99
+	}
100 100
 
101 101
 
102
-    /**
103
-     * returns true if the current request matches this route
104
-     *
105
-     * @return bool
106
-     * @since   $VID:$
107
-     */
108
-    public function matchesCurrentRequest(): bool
109
-    {
110
-        return ! $this->request->isActivation() || $this->request->isUnitTesting();
111
-    }
102
+	/**
103
+	 * returns true if the current request matches this route
104
+	 *
105
+	 * @return bool
106
+	 * @since   $VID:$
107
+	 */
108
+	public function matchesCurrentRequest(): bool
109
+	{
110
+		return ! $this->request->isActivation() || $this->request->isUnitTesting();
111
+	}
112 112
 
113 113
 
114
-    /**
115
-     * @since $VID:$
116
-     */
117
-    protected function registerDependencies()
118
-    {
119
-        $admin_dependencies = ['EE_Admin_Config' => EE_Dependency_Map::load_from_cache] + Route::$default_dependencies;
120
-        $public_dependencies = ['EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache] + Route::$default_dependencies;
121
-        $default_with_barista = [
122
-                                    'EventEspresso\core\services\assets\BaristaFactory' => EE_Dependency_Map::load_from_cache,
123
-                                ] + Route::$default_dependencies;
124
-        $default_with_manifest = [
125
-                                     'EventEspresso\core\services\assets\AssetManifestFactory' => EE_Dependency_Map::load_from_cache,
126
-                                 ] + Route::$default_dependencies;
127
-        $default_routes = [
128
-            // default dependencies
129
-            'EventEspresso\core\domain\entities\routing\handlers\admin\PueRequests'          => Route::$default_dependencies,
130
-            'EventEspresso\core\domain\entities\routing\handlers\frontend\ShortcodeRequests' => Route::$default_dependencies,
131
-            'EventEspresso\core\domain\entities\routing\handlers\shared\RestApiRequests'     => Route::$default_dependencies,
132
-            'EventEspresso\core\domain\entities\routing\handlers\shared\SessionRequests'     => Route::$default_dependencies,
133
-            'EventEspresso\core\domain\entities\routing\handlers\shared\WordPressHeartbeat'  => Route::$default_dependencies,
134
-            'EventEspresso\core\domain\entities\routing\handlers\shared\AssetRequests'       => $default_with_barista,
135
-            'EventEspresso\core\domain\entities\routing\handlers\shared\GQLRequests'         => $default_with_manifest,
136
-            // admin dependencies
137
-            'EventEspresso\core\domain\entities\routing\handlers\admin\AdminRoute'           => $admin_dependencies,
138
-            'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoEventsAdmin'  => $admin_dependencies,
139
-            'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoEventEditor'  => $admin_dependencies,
140
-            'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoLegacyAdmin'  => $admin_dependencies,
141
-            'EventEspresso\core\domain\entities\routing\handlers\admin\GutenbergEditor'      => $admin_dependencies,
142
-            'EventEspresso\core\domain\entities\routing\handlers\admin\WordPressPluginsPage' => $admin_dependencies,
143
-            // public dependencies
144
-            'EventEspresso\core\domain\entities\routing\handlers\admin\PersonalDataRequests' => $public_dependencies,
145
-            'EventEspresso\core\domain\entities\routing\handlers\frontend\FrontendRequests'  => $public_dependencies,
146
-        ];
147
-        foreach ($default_routes as $route => $dependencies) {
148
-            $this->dependency_map->registerDependencies($route, $dependencies);
149
-        }
150
-    }
114
+	/**
115
+	 * @since $VID:$
116
+	 */
117
+	protected function registerDependencies()
118
+	{
119
+		$admin_dependencies = ['EE_Admin_Config' => EE_Dependency_Map::load_from_cache] + Route::$default_dependencies;
120
+		$public_dependencies = ['EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache] + Route::$default_dependencies;
121
+		$default_with_barista = [
122
+									'EventEspresso\core\services\assets\BaristaFactory' => EE_Dependency_Map::load_from_cache,
123
+								] + Route::$default_dependencies;
124
+		$default_with_manifest = [
125
+									 'EventEspresso\core\services\assets\AssetManifestFactory' => EE_Dependency_Map::load_from_cache,
126
+								 ] + Route::$default_dependencies;
127
+		$default_routes = [
128
+			// default dependencies
129
+			'EventEspresso\core\domain\entities\routing\handlers\admin\PueRequests'          => Route::$default_dependencies,
130
+			'EventEspresso\core\domain\entities\routing\handlers\frontend\ShortcodeRequests' => Route::$default_dependencies,
131
+			'EventEspresso\core\domain\entities\routing\handlers\shared\RestApiRequests'     => Route::$default_dependencies,
132
+			'EventEspresso\core\domain\entities\routing\handlers\shared\SessionRequests'     => Route::$default_dependencies,
133
+			'EventEspresso\core\domain\entities\routing\handlers\shared\WordPressHeartbeat'  => Route::$default_dependencies,
134
+			'EventEspresso\core\domain\entities\routing\handlers\shared\AssetRequests'       => $default_with_barista,
135
+			'EventEspresso\core\domain\entities\routing\handlers\shared\GQLRequests'         => $default_with_manifest,
136
+			// admin dependencies
137
+			'EventEspresso\core\domain\entities\routing\handlers\admin\AdminRoute'           => $admin_dependencies,
138
+			'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoEventsAdmin'  => $admin_dependencies,
139
+			'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoEventEditor'  => $admin_dependencies,
140
+			'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoLegacyAdmin'  => $admin_dependencies,
141
+			'EventEspresso\core\domain\entities\routing\handlers\admin\GutenbergEditor'      => $admin_dependencies,
142
+			'EventEspresso\core\domain\entities\routing\handlers\admin\WordPressPluginsPage' => $admin_dependencies,
143
+			// public dependencies
144
+			'EventEspresso\core\domain\entities\routing\handlers\admin\PersonalDataRequests' => $public_dependencies,
145
+			'EventEspresso\core\domain\entities\routing\handlers\frontend\FrontendRequests'  => $public_dependencies,
146
+		];
147
+		foreach ($default_routes as $route => $dependencies) {
148
+			$this->dependency_map->registerDependencies($route, $dependencies);
149
+		}
150
+	}
151 151
 
152 152
 
153
-    /**
154
-     * implements logic required to run during request
155
-     *
156
-     * @return bool
157
-     * @since   $VID:$
158
-     */
159
-    protected function requestHandler(): bool
160
-    {
161
-        $this->setRouteRequestType(PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR);
162
-        return true;
163
-    }
153
+	/**
154
+	 * implements logic required to run during request
155
+	 *
156
+	 * @return bool
157
+	 * @since   $VID:$
158
+	 */
159
+	protected function requestHandler(): bool
160
+	{
161
+		$this->setRouteRequestType(PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR);
162
+		return true;
163
+	}
164 164
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Activation.helper.php 2 patches
Indentation   +1590 added lines, -1590 removed lines patch added patch discarded remove patch
@@ -16,239 +16,239 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class EEH_Activation implements ResettableInterface
18 18
 {
19
-    /**
20
-     * constant used to indicate a cron task is no longer in use
21
-     */
22
-    const cron_task_no_longer_in_use = 'no_longer_in_use';
23
-
24
-    /**
25
-     * WP_User->ID
26
-     *
27
-     * @var int
28
-     */
29
-    private static $_default_creator_id;
30
-
31
-    /**
32
-     * indicates whether or not we've already verified core's default data during this request,
33
-     * because after migrations are done, any addons activated while in maintenance mode
34
-     * will want to setup their own default data, and they might hook into core's default data
35
-     * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
36
-     * This prevents doing that for EVERY single addon.
37
-     *
38
-     * @var boolean
39
-     */
40
-    protected static $_initialized_db_content_already_in_this_request = false;
41
-
42
-    /**
43
-     * @var TableAnalysis $table_analysis
44
-     */
45
-    private static $table_analysis;
46
-
47
-    /**
48
-     * @var TableManager $table_manager
49
-     */
50
-    private static $table_manager;
51
-
52
-
53
-    /**
54
-     * @return TableAnalysis
55
-     * @throws EE_Error
56
-     * @throws ReflectionException
57
-     */
58
-    public static function getTableAnalysis()
59
-    {
60
-        if (! self::$table_analysis instanceof TableAnalysis) {
61
-            self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', [], true);
62
-        }
63
-        return self::$table_analysis;
64
-    }
65
-
66
-
67
-    /**
68
-     * @return TableManager
69
-     * @throws EE_Error
70
-     * @throws ReflectionException
71
-     */
72
-    public static function getTableManager()
73
-    {
74
-        if (! self::$table_manager instanceof TableManager) {
75
-            self::$table_manager = EE_Registry::instance()->create('TableManager', [], true);
76
-        }
77
-        return self::$table_manager;
78
-    }
79
-
80
-
81
-    /**
82
-     * @param $table_name
83
-     * @return string
84
-     * @throws EE_Error
85
-     * @throws ReflectionException
86
-     * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
87
-     */
88
-    public static function ensure_table_name_has_prefix($table_name)
89
-    {
90
-        return EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
91
-    }
92
-
93
-
94
-    /**
95
-     * ensures the EE configuration settings are loaded with at least default options set
96
-     * and that all critical EE pages have been generated with the appropriate shortcodes in place
97
-     *
98
-     * @return void
99
-     */
100
-    public static function system_initialization()
101
-    {
102
-        EEH_Activation::reset_and_update_config();
103
-        // which is fired BEFORE activation of plugin anyways
104
-        EEH_Activation::verify_default_pages_exist();
105
-    }
106
-
107
-
108
-    /**
109
-     * Sets the database schema and creates folders. This should
110
-     * be called on plugin activation and reactivation
111
-     *
112
-     * @return boolean success, whether the database and folders are setup properly
113
-     * @throws EE_Error
114
-     * @throws ReflectionException
115
-     */
116
-    public static function initialize_db_and_folders()
117
-    {
118
-        EEH_File::ensure_folder_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR);
119
-        EEH_File::ensure_folder_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR . 'logs');
120
-        return EEH_Activation::create_database_tables();
121
-    }
122
-
123
-
124
-    /**
125
-     * assuming we have an up-to-date database schema, this will populate it
126
-     * with default and initial data. This should be called
127
-     * upon activation of a new plugin, reactivation, and at the end
128
-     * of running migration scripts
129
-     *
130
-     * @throws EE_Error
131
-     * @throws ReflectionException
132
-     */
133
-    public static function initialize_db_content()
134
-    {
135
-        // let's avoid doing all this logic repeatedly, especially when addons are requesting it
136
-        if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
137
-            return;
138
-        }
139
-        EEH_Activation::$_initialized_db_content_already_in_this_request = true;
140
-
141
-        EEH_Activation::initialize_system_questions();
142
-        EEH_Activation::insert_default_status_codes();
143
-        EEH_Activation::generate_default_message_templates();
144
-        EEH_Activation::create_no_ticket_prices_array();
145
-        EEH_Activation::removeEmailConfirmFromAddressGroup();
146
-
147
-        EEH_Activation::validate_messages_system();
148
-        EEH_Activation::insert_default_payment_methods();
149
-        // in case we've
150
-        EEH_Activation::remove_cron_tasks();
151
-        EEH_Activation::create_cron_tasks();
152
-        // remove all TXN locks since that is being done via extra meta now
153
-        delete_option('ee_locked_transactions');
154
-        // also, check for CAF default db content
155
-        do_action('AHEE__EEH_Activation__initialize_db_content');
156
-        // also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
157
-        // which users really won't care about on initial activation
158
-        EE_Error::overwrite_success();
159
-    }
160
-
161
-
162
-    /**
163
-     * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
164
-     * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
165
-     * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
166
-     * (null)
167
-     *
168
-     * @param string $which_to_include can be 'current' (ones that are currently in use),
169
-     *                                 'old' (only returns ones that should no longer be used),or 'all',
170
-     * @return array
171
-     * @throws EE_Error
172
-     */
173
-    public static function get_cron_tasks($which_to_include)
174
-    {
175
-        $cron_tasks = apply_filters(
176
-            'FHEE__EEH_Activation__get_cron_tasks',
177
-            [
178
-                'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
179
-                // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' =>
180
-                // EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
181
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
182
-                // there may have been a bug which prevented from these cron tasks from getting unscheduled,
183
-                // so we might want to remove these for a few updates
184
-                'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
185
-            ]
186
-        );
187
-        if ($which_to_include === 'old') {
188
-            $cron_tasks = array_filter(
189
-                $cron_tasks,
190
-                function ($value) {
191
-                    return $value === EEH_Activation::cron_task_no_longer_in_use;
192
-                }
193
-            );
194
-        } elseif ($which_to_include === 'current') {
195
-            $cron_tasks = array_filter($cron_tasks);
196
-        } elseif (WP_DEBUG && $which_to_include !== 'all') {
197
-            throw new EE_Error(
198
-                sprintf(
199
-                    esc_html__(
200
-                        'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
201
-                        'event_espresso'
202
-                    ),
203
-                    $which_to_include
204
-                )
205
-            );
206
-        }
207
-        return $cron_tasks;
208
-    }
209
-
210
-
211
-    /**
212
-     * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
213
-     *
214
-     * @throws EE_Error
215
-     */
216
-    public static function create_cron_tasks()
217
-    {
218
-
219
-        foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
220
-            if (! wp_next_scheduled($hook_name)) {
221
-                /**
222
-                 * This allows client code to define the initial start timestamp for this schedule.
223
-                 */
224
-                if (
225
-                    is_array($frequency)
226
-                    && count($frequency) === 2
227
-                    && isset($frequency[0], $frequency[1])
228
-                ) {
229
-                    $start_timestamp = $frequency[0];
230
-                    $frequency       = $frequency[1];
231
-                } else {
232
-                    $start_timestamp = time();
233
-                }
234
-                wp_schedule_event($start_timestamp, $frequency, $hook_name);
235
-            }
236
-        }
237
-    }
238
-
239
-
240
-    /**
241
-     * Remove the currently-existing and now-removed cron tasks.
242
-     *
243
-     * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
244
-     * @throws EE_Error
245
-     */
246
-    public static function remove_cron_tasks($remove_all = true)
247
-    {
248
-        $cron_tasks_to_remove = $remove_all ? 'all' : 'old';
249
-        $crons                = _get_cron_array();
250
-        $crons                = is_array($crons) ? $crons : [];
251
-        /* reminder of what $crons look like:
19
+	/**
20
+	 * constant used to indicate a cron task is no longer in use
21
+	 */
22
+	const cron_task_no_longer_in_use = 'no_longer_in_use';
23
+
24
+	/**
25
+	 * WP_User->ID
26
+	 *
27
+	 * @var int
28
+	 */
29
+	private static $_default_creator_id;
30
+
31
+	/**
32
+	 * indicates whether or not we've already verified core's default data during this request,
33
+	 * because after migrations are done, any addons activated while in maintenance mode
34
+	 * will want to setup their own default data, and they might hook into core's default data
35
+	 * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
36
+	 * This prevents doing that for EVERY single addon.
37
+	 *
38
+	 * @var boolean
39
+	 */
40
+	protected static $_initialized_db_content_already_in_this_request = false;
41
+
42
+	/**
43
+	 * @var TableAnalysis $table_analysis
44
+	 */
45
+	private static $table_analysis;
46
+
47
+	/**
48
+	 * @var TableManager $table_manager
49
+	 */
50
+	private static $table_manager;
51
+
52
+
53
+	/**
54
+	 * @return TableAnalysis
55
+	 * @throws EE_Error
56
+	 * @throws ReflectionException
57
+	 */
58
+	public static function getTableAnalysis()
59
+	{
60
+		if (! self::$table_analysis instanceof TableAnalysis) {
61
+			self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', [], true);
62
+		}
63
+		return self::$table_analysis;
64
+	}
65
+
66
+
67
+	/**
68
+	 * @return TableManager
69
+	 * @throws EE_Error
70
+	 * @throws ReflectionException
71
+	 */
72
+	public static function getTableManager()
73
+	{
74
+		if (! self::$table_manager instanceof TableManager) {
75
+			self::$table_manager = EE_Registry::instance()->create('TableManager', [], true);
76
+		}
77
+		return self::$table_manager;
78
+	}
79
+
80
+
81
+	/**
82
+	 * @param $table_name
83
+	 * @return string
84
+	 * @throws EE_Error
85
+	 * @throws ReflectionException
86
+	 * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
87
+	 */
88
+	public static function ensure_table_name_has_prefix($table_name)
89
+	{
90
+		return EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
91
+	}
92
+
93
+
94
+	/**
95
+	 * ensures the EE configuration settings are loaded with at least default options set
96
+	 * and that all critical EE pages have been generated with the appropriate shortcodes in place
97
+	 *
98
+	 * @return void
99
+	 */
100
+	public static function system_initialization()
101
+	{
102
+		EEH_Activation::reset_and_update_config();
103
+		// which is fired BEFORE activation of plugin anyways
104
+		EEH_Activation::verify_default_pages_exist();
105
+	}
106
+
107
+
108
+	/**
109
+	 * Sets the database schema and creates folders. This should
110
+	 * be called on plugin activation and reactivation
111
+	 *
112
+	 * @return boolean success, whether the database and folders are setup properly
113
+	 * @throws EE_Error
114
+	 * @throws ReflectionException
115
+	 */
116
+	public static function initialize_db_and_folders()
117
+	{
118
+		EEH_File::ensure_folder_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR);
119
+		EEH_File::ensure_folder_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR . 'logs');
120
+		return EEH_Activation::create_database_tables();
121
+	}
122
+
123
+
124
+	/**
125
+	 * assuming we have an up-to-date database schema, this will populate it
126
+	 * with default and initial data. This should be called
127
+	 * upon activation of a new plugin, reactivation, and at the end
128
+	 * of running migration scripts
129
+	 *
130
+	 * @throws EE_Error
131
+	 * @throws ReflectionException
132
+	 */
133
+	public static function initialize_db_content()
134
+	{
135
+		// let's avoid doing all this logic repeatedly, especially when addons are requesting it
136
+		if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
137
+			return;
138
+		}
139
+		EEH_Activation::$_initialized_db_content_already_in_this_request = true;
140
+
141
+		EEH_Activation::initialize_system_questions();
142
+		EEH_Activation::insert_default_status_codes();
143
+		EEH_Activation::generate_default_message_templates();
144
+		EEH_Activation::create_no_ticket_prices_array();
145
+		EEH_Activation::removeEmailConfirmFromAddressGroup();
146
+
147
+		EEH_Activation::validate_messages_system();
148
+		EEH_Activation::insert_default_payment_methods();
149
+		// in case we've
150
+		EEH_Activation::remove_cron_tasks();
151
+		EEH_Activation::create_cron_tasks();
152
+		// remove all TXN locks since that is being done via extra meta now
153
+		delete_option('ee_locked_transactions');
154
+		// also, check for CAF default db content
155
+		do_action('AHEE__EEH_Activation__initialize_db_content');
156
+		// also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
157
+		// which users really won't care about on initial activation
158
+		EE_Error::overwrite_success();
159
+	}
160
+
161
+
162
+	/**
163
+	 * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
164
+	 * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
165
+	 * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
166
+	 * (null)
167
+	 *
168
+	 * @param string $which_to_include can be 'current' (ones that are currently in use),
169
+	 *                                 'old' (only returns ones that should no longer be used),or 'all',
170
+	 * @return array
171
+	 * @throws EE_Error
172
+	 */
173
+	public static function get_cron_tasks($which_to_include)
174
+	{
175
+		$cron_tasks = apply_filters(
176
+			'FHEE__EEH_Activation__get_cron_tasks',
177
+			[
178
+				'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
179
+				// 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' =>
180
+				// EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
181
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
182
+				// there may have been a bug which prevented from these cron tasks from getting unscheduled,
183
+				// so we might want to remove these for a few updates
184
+				'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
185
+			]
186
+		);
187
+		if ($which_to_include === 'old') {
188
+			$cron_tasks = array_filter(
189
+				$cron_tasks,
190
+				function ($value) {
191
+					return $value === EEH_Activation::cron_task_no_longer_in_use;
192
+				}
193
+			);
194
+		} elseif ($which_to_include === 'current') {
195
+			$cron_tasks = array_filter($cron_tasks);
196
+		} elseif (WP_DEBUG && $which_to_include !== 'all') {
197
+			throw new EE_Error(
198
+				sprintf(
199
+					esc_html__(
200
+						'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
201
+						'event_espresso'
202
+					),
203
+					$which_to_include
204
+				)
205
+			);
206
+		}
207
+		return $cron_tasks;
208
+	}
209
+
210
+
211
+	/**
212
+	 * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
213
+	 *
214
+	 * @throws EE_Error
215
+	 */
216
+	public static function create_cron_tasks()
217
+	{
218
+
219
+		foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
220
+			if (! wp_next_scheduled($hook_name)) {
221
+				/**
222
+				 * This allows client code to define the initial start timestamp for this schedule.
223
+				 */
224
+				if (
225
+					is_array($frequency)
226
+					&& count($frequency) === 2
227
+					&& isset($frequency[0], $frequency[1])
228
+				) {
229
+					$start_timestamp = $frequency[0];
230
+					$frequency       = $frequency[1];
231
+				} else {
232
+					$start_timestamp = time();
233
+				}
234
+				wp_schedule_event($start_timestamp, $frequency, $hook_name);
235
+			}
236
+		}
237
+	}
238
+
239
+
240
+	/**
241
+	 * Remove the currently-existing and now-removed cron tasks.
242
+	 *
243
+	 * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
244
+	 * @throws EE_Error
245
+	 */
246
+	public static function remove_cron_tasks($remove_all = true)
247
+	{
248
+		$cron_tasks_to_remove = $remove_all ? 'all' : 'old';
249
+		$crons                = _get_cron_array();
250
+		$crons                = is_array($crons) ? $crons : [];
251
+		/* reminder of what $crons look like:
252 252
          * Top-level keys are timestamps, and their values are arrays.
253 253
          * The 2nd level arrays have keys with each of the cron task hook names to run at that time
254 254
          * and their values are arrays.
@@ -265,893 +265,893 @@  discard block
 block discarded – undo
265 265
          *                  ...
266 266
          *      ...
267 267
          */
268
-        $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
269
-        foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
270
-            if (is_array($hooks_to_fire_at_time)) {
271
-                foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
272
-                    if (
273
-                        isset($ee_cron_tasks_to_remove[ $hook_name ])
274
-                        && is_array($ee_cron_tasks_to_remove[ $hook_name ])
275
-                    ) {
276
-                        unset($crons[ $timestamp ][ $hook_name ]);
277
-                    }
278
-                }
279
-                // also take care of any empty cron timestamps.
280
-                if (empty($hooks_to_fire_at_time)) {
281
-                    unset($crons[ $timestamp ]);
282
-                }
283
-            }
284
-        }
285
-        _set_cron_array($crons);
286
-    }
287
-
288
-
289
-    /**
290
-     * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
291
-     *
292
-     * @return void
293
-     * @throws EE_Error
294
-     * @throws ReflectionException
295
-     */
296
-    public static function CPT_initialization()
297
-    {
298
-        // register Custom Post Types
299
-        EE_Registry::instance()->load_core('Register_CPTs');
300
-        flush_rewrite_rules();
301
-    }
302
-
303
-
304
-    /**
305
-     * The following code was moved over from EE_Config so that it will no longer run on every request.
306
-     * If there is old calendar config data saved, then it will get converted on activation.
307
-     * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
308
-     *
309
-     * @return void
310
-     */
311
-    public static function reset_and_update_config()
312
-    {
313
-        do_action('AHEE__EE_Config___load_core_config__start', ['EEH_Activation', 'load_calendar_config']);
314
-        add_filter(
315
-            'FHEE__EE_Config___load_core_config__config_settings',
316
-            ['EEH_Activation', 'migrate_old_config_data'],
317
-            10,
318
-            3
319
-        );
320
-        if (! EE_Config::logging_enabled()) {
321
-            delete_option(EE_Config::LOG_NAME);
322
-        }
323
-    }
324
-
325
-
326
-    /**
327
-     * @return    void
328
-     */
329
-    public static function load_calendar_config()
330
-    {
331
-        // grab array of all plugin folders and loop thru it
332
-        $plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR);
333
-        if (empty($plugins)) {
334
-            return;
335
-        }
336
-        foreach ($plugins as $plugin_path) {
337
-            // grab plugin folder name from path
338
-            $plugin = basename($plugin_path);
339
-            // drill down to Espresso plugins
340
-            // then to calendar related plugins
341
-            if (
342
-                strpos($plugin, 'espresso') !== false
343
-                || strpos($plugin, 'Espresso') !== false
344
-                || strpos($plugin, 'ee4') !== false
345
-                || strpos($plugin, 'EE4') !== false
346
-                || strpos($plugin, 'calendar') !== false
347
-            ) {
348
-                // this is what we are looking for
349
-                $calendar_config = $plugin_path . '/EE_Calendar_Config.php';
350
-                // does it exist in this folder ?
351
-                if (is_readable($calendar_config)) {
352
-                    // YEAH! let's load it
353
-                    require_once($calendar_config);
354
-                }
355
-            }
356
-        }
357
-    }
358
-
359
-
360
-    /**
361
-     * @param array|stdClass $settings
362
-     * @param string         $config
363
-     * @param EE_Config      $EE_Config
364
-     * @return stdClass
365
-     */
366
-    public static function migrate_old_config_data($settings = [], $config = '', EE_Config $EE_Config)
367
-    {
368
-        $convert_from_array = ['addons'];
369
-        // in case old settings were saved as an array
370
-        if (is_array($settings) && in_array($config, $convert_from_array)) {
371
-            // convert existing settings to an object
372
-            $config_array = $settings;
373
-            $settings     = new stdClass();
374
-            foreach ($config_array as $key => $value) {
375
-                if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
376
-                    $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
377
-                } else {
378
-                    $settings->{$key} = $value;
379
-                }
380
-            }
381
-            add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
382
-        }
383
-        return $settings;
384
-    }
385
-
386
-
387
-    /**
388
-     * @return void
389
-     */
390
-    public static function deactivate_event_espresso()
391
-    {
392
-        // check permissions
393
-        if (current_user_can('activate_plugins')) {
394
-            deactivate_plugins(EE_PLUGIN_BASENAME, true);
395
-        }
396
-    }
397
-
398
-
399
-    /**
400
-     * @return void
401
-     * @throws InvalidDataTypeException
402
-     */
403
-    public static function verify_default_pages_exist()
404
-    {
405
-        $critical_page_problem = false;
406
-        $critical_pages        = [
407
-            [
408
-                'id'   => 'reg_page_id',
409
-                'name' => esc_html__('Registration Checkout', 'event_espresso'),
410
-                'post' => null,
411
-                'code' => 'ESPRESSO_CHECKOUT',
412
-            ],
413
-            [
414
-                'id'   => 'txn_page_id',
415
-                'name' => esc_html__('Transactions', 'event_espresso'),
416
-                'post' => null,
417
-                'code' => 'ESPRESSO_TXN_PAGE',
418
-            ],
419
-            [
420
-                'id'   => 'thank_you_page_id',
421
-                'name' => esc_html__('Thank You', 'event_espresso'),
422
-                'post' => null,
423
-                'code' => 'ESPRESSO_THANK_YOU',
424
-            ],
425
-            [
426
-                'id'   => 'cancel_page_id',
427
-                'name' => esc_html__('Registration Cancelled', 'event_espresso'),
428
-                'post' => null,
429
-                'code' => 'ESPRESSO_CANCELLED',
430
-            ],
431
-        ];
432
-        $EE_Core_Config        = EE_Registry::instance()->CFG->core;
433
-        foreach ($critical_pages as $critical_page) {
434
-            // is critical page ID set in config ?
435
-            if ($EE_Core_Config->{$critical_page['id']} !== false) {
436
-                // attempt to find post by ID
437
-                $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
438
-            }
439
-            // no dice?
440
-            if ($critical_page['post'] === null) {
441
-                // attempt to find post by title
442
-                $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
443
-                // still nothing?
444
-                if ($critical_page['post'] === null) {
445
-                    $critical_page = EEH_Activation::create_critical_page($critical_page);
446
-                    // REALLY? Still nothing ??!?!?
447
-                    if ($critical_page['post'] === null) {
448
-                        $msg = esc_html__(
449
-                            'The Event Espresso critical page configuration settings could not be updated.',
450
-                            'event_espresso'
451
-                        );
452
-                        EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
453
-                        break;
454
-                    }
455
-                }
456
-            }
457
-            // check that Post ID matches critical page ID in config
458
-            if (
459
-                isset($critical_page['post']->ID)
460
-                && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
461
-            ) {
462
-                // update Config with post ID
463
-                $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
464
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
465
-                    $msg = esc_html__(
466
-                        'The Event Espresso critical page configuration settings could not be updated.',
467
-                        'event_espresso'
468
-                    );
469
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
470
-                }
471
-            }
472
-            $critical_page_problem =
473
-                ! isset($critical_page['post']->post_status)
474
-                || $critical_page['post']->post_status !== 'publish'
475
-                || strpos($critical_page['post']->post_content, $critical_page['code']) === false
476
-                    ? true
477
-                    : $critical_page_problem;
478
-        }
479
-        if ($critical_page_problem) {
480
-            new PersistentAdminNotice(
481
-                'critical_page_problem',
482
-                sprintf(
483
-                    esc_html__(
484
-                        'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
485
-                        'event_espresso'
486
-                    ),
487
-                    '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
488
-                    . esc_html__('Event Espresso Critical Pages Settings', 'event_espresso')
489
-                    . '</a>'
490
-                )
491
-            );
492
-        }
493
-        if (EE_Error::has_notices()) {
494
-            EE_Error::get_notices(false, true);
495
-        }
496
-    }
497
-
498
-
499
-    /**
500
-     * Returns the first post which uses the specified shortcode
501
-     *
502
-     * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
503
-     *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
504
-     *                             "[ESPRESSO_THANK_YOU"
505
-     *                             (we don't search for the closing shortcode bracket because they might have added
506
-     *                             parameter to the shortcode
507
-     * @return WP_Post or NULl
508
-     */
509
-    public static function get_page_by_ee_shortcode($ee_shortcode)
510
-    {
511
-        global $wpdb;
512
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
513
-        $post_id                       =
514
-            $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
515
-        if ($post_id) {
516
-            return get_post($post_id);
517
-        } else {
518
-            return null;
519
-        }
520
-    }
521
-
522
-
523
-    /**
524
-     * This function generates a post for critical espresso pages
525
-     *
526
-     * @param array $critical_page
527
-     * @return array
528
-     */
529
-    public static function create_critical_page($critical_page)
530
-    {
531
-
532
-        $post_args = [
533
-            'post_title'     => $critical_page['name'],
534
-            'post_status'    => 'publish',
535
-            'post_type'      => 'page',
536
-            'comment_status' => 'closed',
537
-            'post_content'   => '[' . $critical_page['code'] . ']',
538
-        ];
539
-
540
-        $post_id = wp_insert_post($post_args);
541
-        if (! $post_id) {
542
-            $msg = sprintf(
543
-                esc_html__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
544
-                $critical_page['name']
545
-            );
546
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
547
-            return $critical_page;
548
-        }
549
-        // get newly created post's details
550
-        if (! $critical_page['post'] = get_post($post_id)) {
551
-            $msg = sprintf(
552
-                esc_html__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
553
-                $critical_page['name']
554
-            );
555
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
556
-        }
557
-
558
-        return $critical_page;
559
-    }
560
-
561
-
562
-    /**
563
-     * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
564
-     * The role being used to check is filterable.
565
-     *
566
-     * @return int|null WP_user ID or NULL
567
-     * @throws EE_Error
568
-     * @throws ReflectionException
569
-     * @since  4.6.0
570
-     * @global WPDB $wpdb
571
-     */
572
-    public static function get_default_creator_id()
573
-    {
574
-        global $wpdb;
575
-        if (! empty(self::$_default_creator_id)) {
576
-            return self::$_default_creator_id;
577
-        }/**/
578
-        $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
579
-        // let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
580
-        $pre_filtered_id = apply_filters(
581
-            'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
582
-            false,
583
-            $role_to_check
584
-        );
585
-        if ($pre_filtered_id !== false) {
586
-            return (int) $pre_filtered_id;
587
-        }
588
-        $capabilities_key = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
589
-        $query            = $wpdb->prepare(
590
-            "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
591
-            '%' . $role_to_check . '%'
592
-        );
593
-        $user_id          = $wpdb->get_var($query);
594
-        $user_id          = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
595
-        if ($user_id && (int) $user_id) {
596
-            self::$_default_creator_id = (int) $user_id;
597
-            return self::$_default_creator_id;
598
-        } else {
599
-            return null;
600
-        }
601
-    }
602
-
603
-
604
-    /**
605
-     * used by EE and EE addons during plugin activation to create tables.
606
-     * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
607
-     * but includes extra logic regarding activations.
608
-     *
609
-     * @param string  $table_name              without the $wpdb->prefix
610
-     * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
611
-     *                                         table query)
612
-     * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
613
-     * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
614
-     *                                         and new once this function is done (ie, you really do want to CREATE a
615
-     *                                         table, and expect it to be empty once you're done) leave as FALSE when
616
-     *                                         you just want to verify the table exists and matches this definition
617
-     *                                         (and if it HAS data in it you want to leave it be)
618
-     * @return void
619
-     * @throws EE_Error if there are database errors
620
-     * @throws ReflectionException
621
-     */
622
-    public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
623
-    {
624
-        if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
625
-            return;
626
-        }
627
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
628
-        if (! function_exists('dbDelta')) {
629
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
630
-        }
631
-        $tableAnalysis = EEH_Activation::getTableAnalysis();
632
-        $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
633
-        // do we need to first delete an existing version of this table ?
634
-        if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
635
-            // ok, delete the table... but ONLY if it's empty
636
-            $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
637
-            // table is NOT empty, are you SURE you want to delete this table ???
638
-            if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
639
-                EEH_Activation::getTableManager()->dropTable($wp_table_name);
640
-            } elseif (! $deleted_safely) {
641
-                // so we should be more cautious rather than just dropping tables so easily
642
-                error_log(
643
-                    sprintf(
644
-                        esc_html__(
645
-                            'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
646
-                            'event_espresso'
647
-                        ),
648
-                        $wp_table_name,
649
-                        '<br/>',
650
-                        'espresso_db_update'
651
-                    )
652
-                );
653
-            }
654
-        }
655
-        $engine = str_replace('ENGINE=', '', $engine);
656
-        EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
657
-    }
658
-
659
-
660
-    /**
661
-     * Checks if this column already exists on the specified table. Handy for addons which want to add a column
662
-     *
663
-     * @param string $table_name  (without "wp_", eg "esp_attendee"
664
-     * @param string $column_name
665
-     * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
666
-     *                            'VARCHAR(10)'
667
-     * @return bool|int
668
-     * @throws EE_Error
669
-     * @throws ReflectionException
670
-     * @deprecated instead use TableManager::addColumn()
671
-     */
672
-    public static function add_column_if_it_doesnt_exist(
673
-        $table_name,
674
-        $column_name,
675
-        $column_info = 'INT UNSIGNED NOT NULL'
676
-    ) {
677
-        return EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
678
-    }
679
-
680
-
681
-    /**
682
-     * Gets all the fields on the database table.
683
-     *
684
-     * @param string $table_name , without prefixed $wpdb->prefix
685
-     * @return array of database column names
686
-     * @throws EE_Error
687
-     * @throws ReflectionException
688
-     * @deprecated instead use TableManager::getTableColumns()
689
-     */
690
-    public static function get_fields_on_table($table_name = null)
691
-    {
692
-        return EEH_Activation::getTableManager()->getTableColumns($table_name);
693
-    }
694
-
695
-
696
-    /**
697
-     * @param string $table_name
698
-     * @return bool
699
-     * @throws EE_Error
700
-     * @throws ReflectionException
701
-     * @deprecated instead use TableAnalysis::tableIsEmpty()
702
-     */
703
-    public static function db_table_is_empty($table_name)
704
-    {
705
-        return EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
706
-    }
707
-
708
-
709
-    /**
710
-     * @param string $table_name
711
-     * @return bool | int
712
-     * @throws EE_Error
713
-     * @throws ReflectionException
714
-     */
715
-    public static function delete_db_table_if_empty($table_name)
716
-    {
717
-        if (EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
718
-            return EEH_Activation::getTableManager()->dropTable($table_name);
719
-        }
720
-        return false;
721
-    }
722
-
723
-
724
-    /**
725
-     * @param string $table_name
726
-     * @return int
727
-     * @throws EE_Error
728
-     * @throws ReflectionException
729
-     * @deprecated instead use TableManager::dropTable()
730
-     */
731
-    public static function delete_unused_db_table($table_name)
732
-    {
733
-        return EEH_Activation::getTableManager()->dropTable($table_name);
734
-    }
735
-
736
-
737
-    /**
738
-     * @param string $table_name
739
-     * @param string $index_name
740
-     * @return int
741
-     * @throws EE_Error
742
-     * @throws ReflectionException
743
-     * @deprecated instead use TableManager::dropIndex()
744
-     */
745
-    public static function drop_index($table_name, $index_name)
746
-    {
747
-        return EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
748
-    }
749
-
750
-
751
-    /**
752
-     * @return boolean success (whether database is setup properly or not)
753
-     * @throws EE_Error
754
-     * @throws ReflectionException
755
-     */
756
-    public static function create_database_tables()
757
-    {
758
-        EE_Registry::instance()->load_core('Data_Migration_Manager');
759
-        // find the migration script that sets the database to be compatible with the code
760
-        $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
761
-        if (! $dms_name) {
762
-            EE_Error::add_error(
763
-                esc_html__(
764
-                    'Could not determine most up-to-date data migration script from which to pull database schema
268
+		$ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
269
+		foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
270
+			if (is_array($hooks_to_fire_at_time)) {
271
+				foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
272
+					if (
273
+						isset($ee_cron_tasks_to_remove[ $hook_name ])
274
+						&& is_array($ee_cron_tasks_to_remove[ $hook_name ])
275
+					) {
276
+						unset($crons[ $timestamp ][ $hook_name ]);
277
+					}
278
+				}
279
+				// also take care of any empty cron timestamps.
280
+				if (empty($hooks_to_fire_at_time)) {
281
+					unset($crons[ $timestamp ]);
282
+				}
283
+			}
284
+		}
285
+		_set_cron_array($crons);
286
+	}
287
+
288
+
289
+	/**
290
+	 * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
291
+	 *
292
+	 * @return void
293
+	 * @throws EE_Error
294
+	 * @throws ReflectionException
295
+	 */
296
+	public static function CPT_initialization()
297
+	{
298
+		// register Custom Post Types
299
+		EE_Registry::instance()->load_core('Register_CPTs');
300
+		flush_rewrite_rules();
301
+	}
302
+
303
+
304
+	/**
305
+	 * The following code was moved over from EE_Config so that it will no longer run on every request.
306
+	 * If there is old calendar config data saved, then it will get converted on activation.
307
+	 * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
308
+	 *
309
+	 * @return void
310
+	 */
311
+	public static function reset_and_update_config()
312
+	{
313
+		do_action('AHEE__EE_Config___load_core_config__start', ['EEH_Activation', 'load_calendar_config']);
314
+		add_filter(
315
+			'FHEE__EE_Config___load_core_config__config_settings',
316
+			['EEH_Activation', 'migrate_old_config_data'],
317
+			10,
318
+			3
319
+		);
320
+		if (! EE_Config::logging_enabled()) {
321
+			delete_option(EE_Config::LOG_NAME);
322
+		}
323
+	}
324
+
325
+
326
+	/**
327
+	 * @return    void
328
+	 */
329
+	public static function load_calendar_config()
330
+	{
331
+		// grab array of all plugin folders and loop thru it
332
+		$plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR);
333
+		if (empty($plugins)) {
334
+			return;
335
+		}
336
+		foreach ($plugins as $plugin_path) {
337
+			// grab plugin folder name from path
338
+			$plugin = basename($plugin_path);
339
+			// drill down to Espresso plugins
340
+			// then to calendar related plugins
341
+			if (
342
+				strpos($plugin, 'espresso') !== false
343
+				|| strpos($plugin, 'Espresso') !== false
344
+				|| strpos($plugin, 'ee4') !== false
345
+				|| strpos($plugin, 'EE4') !== false
346
+				|| strpos($plugin, 'calendar') !== false
347
+			) {
348
+				// this is what we are looking for
349
+				$calendar_config = $plugin_path . '/EE_Calendar_Config.php';
350
+				// does it exist in this folder ?
351
+				if (is_readable($calendar_config)) {
352
+					// YEAH! let's load it
353
+					require_once($calendar_config);
354
+				}
355
+			}
356
+		}
357
+	}
358
+
359
+
360
+	/**
361
+	 * @param array|stdClass $settings
362
+	 * @param string         $config
363
+	 * @param EE_Config      $EE_Config
364
+	 * @return stdClass
365
+	 */
366
+	public static function migrate_old_config_data($settings = [], $config = '', EE_Config $EE_Config)
367
+	{
368
+		$convert_from_array = ['addons'];
369
+		// in case old settings were saved as an array
370
+		if (is_array($settings) && in_array($config, $convert_from_array)) {
371
+			// convert existing settings to an object
372
+			$config_array = $settings;
373
+			$settings     = new stdClass();
374
+			foreach ($config_array as $key => $value) {
375
+				if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
376
+					$EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
377
+				} else {
378
+					$settings->{$key} = $value;
379
+				}
380
+			}
381
+			add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
382
+		}
383
+		return $settings;
384
+	}
385
+
386
+
387
+	/**
388
+	 * @return void
389
+	 */
390
+	public static function deactivate_event_espresso()
391
+	{
392
+		// check permissions
393
+		if (current_user_can('activate_plugins')) {
394
+			deactivate_plugins(EE_PLUGIN_BASENAME, true);
395
+		}
396
+	}
397
+
398
+
399
+	/**
400
+	 * @return void
401
+	 * @throws InvalidDataTypeException
402
+	 */
403
+	public static function verify_default_pages_exist()
404
+	{
405
+		$critical_page_problem = false;
406
+		$critical_pages        = [
407
+			[
408
+				'id'   => 'reg_page_id',
409
+				'name' => esc_html__('Registration Checkout', 'event_espresso'),
410
+				'post' => null,
411
+				'code' => 'ESPRESSO_CHECKOUT',
412
+			],
413
+			[
414
+				'id'   => 'txn_page_id',
415
+				'name' => esc_html__('Transactions', 'event_espresso'),
416
+				'post' => null,
417
+				'code' => 'ESPRESSO_TXN_PAGE',
418
+			],
419
+			[
420
+				'id'   => 'thank_you_page_id',
421
+				'name' => esc_html__('Thank You', 'event_espresso'),
422
+				'post' => null,
423
+				'code' => 'ESPRESSO_THANK_YOU',
424
+			],
425
+			[
426
+				'id'   => 'cancel_page_id',
427
+				'name' => esc_html__('Registration Cancelled', 'event_espresso'),
428
+				'post' => null,
429
+				'code' => 'ESPRESSO_CANCELLED',
430
+			],
431
+		];
432
+		$EE_Core_Config        = EE_Registry::instance()->CFG->core;
433
+		foreach ($critical_pages as $critical_page) {
434
+			// is critical page ID set in config ?
435
+			if ($EE_Core_Config->{$critical_page['id']} !== false) {
436
+				// attempt to find post by ID
437
+				$critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
438
+			}
439
+			// no dice?
440
+			if ($critical_page['post'] === null) {
441
+				// attempt to find post by title
442
+				$critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
443
+				// still nothing?
444
+				if ($critical_page['post'] === null) {
445
+					$critical_page = EEH_Activation::create_critical_page($critical_page);
446
+					// REALLY? Still nothing ??!?!?
447
+					if ($critical_page['post'] === null) {
448
+						$msg = esc_html__(
449
+							'The Event Espresso critical page configuration settings could not be updated.',
450
+							'event_espresso'
451
+						);
452
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
453
+						break;
454
+					}
455
+				}
456
+			}
457
+			// check that Post ID matches critical page ID in config
458
+			if (
459
+				isset($critical_page['post']->ID)
460
+				&& $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
461
+			) {
462
+				// update Config with post ID
463
+				$EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
464
+				if (! EE_Config::instance()->update_espresso_config(false, false)) {
465
+					$msg = esc_html__(
466
+						'The Event Espresso critical page configuration settings could not be updated.',
467
+						'event_espresso'
468
+					);
469
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
470
+				}
471
+			}
472
+			$critical_page_problem =
473
+				! isset($critical_page['post']->post_status)
474
+				|| $critical_page['post']->post_status !== 'publish'
475
+				|| strpos($critical_page['post']->post_content, $critical_page['code']) === false
476
+					? true
477
+					: $critical_page_problem;
478
+		}
479
+		if ($critical_page_problem) {
480
+			new PersistentAdminNotice(
481
+				'critical_page_problem',
482
+				sprintf(
483
+					esc_html__(
484
+						'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
485
+						'event_espresso'
486
+					),
487
+					'<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
488
+					. esc_html__('Event Espresso Critical Pages Settings', 'event_espresso')
489
+					. '</a>'
490
+				)
491
+			);
492
+		}
493
+		if (EE_Error::has_notices()) {
494
+			EE_Error::get_notices(false, true);
495
+		}
496
+	}
497
+
498
+
499
+	/**
500
+	 * Returns the first post which uses the specified shortcode
501
+	 *
502
+	 * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
503
+	 *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
504
+	 *                             "[ESPRESSO_THANK_YOU"
505
+	 *                             (we don't search for the closing shortcode bracket because they might have added
506
+	 *                             parameter to the shortcode
507
+	 * @return WP_Post or NULl
508
+	 */
509
+	public static function get_page_by_ee_shortcode($ee_shortcode)
510
+	{
511
+		global $wpdb;
512
+		$shortcode_and_opening_bracket = '[' . $ee_shortcode;
513
+		$post_id                       =
514
+			$wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
515
+		if ($post_id) {
516
+			return get_post($post_id);
517
+		} else {
518
+			return null;
519
+		}
520
+	}
521
+
522
+
523
+	/**
524
+	 * This function generates a post for critical espresso pages
525
+	 *
526
+	 * @param array $critical_page
527
+	 * @return array
528
+	 */
529
+	public static function create_critical_page($critical_page)
530
+	{
531
+
532
+		$post_args = [
533
+			'post_title'     => $critical_page['name'],
534
+			'post_status'    => 'publish',
535
+			'post_type'      => 'page',
536
+			'comment_status' => 'closed',
537
+			'post_content'   => '[' . $critical_page['code'] . ']',
538
+		];
539
+
540
+		$post_id = wp_insert_post($post_args);
541
+		if (! $post_id) {
542
+			$msg = sprintf(
543
+				esc_html__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
544
+				$critical_page['name']
545
+			);
546
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
547
+			return $critical_page;
548
+		}
549
+		// get newly created post's details
550
+		if (! $critical_page['post'] = get_post($post_id)) {
551
+			$msg = sprintf(
552
+				esc_html__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
553
+				$critical_page['name']
554
+			);
555
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
556
+		}
557
+
558
+		return $critical_page;
559
+	}
560
+
561
+
562
+	/**
563
+	 * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
564
+	 * The role being used to check is filterable.
565
+	 *
566
+	 * @return int|null WP_user ID or NULL
567
+	 * @throws EE_Error
568
+	 * @throws ReflectionException
569
+	 * @since  4.6.0
570
+	 * @global WPDB $wpdb
571
+	 */
572
+	public static function get_default_creator_id()
573
+	{
574
+		global $wpdb;
575
+		if (! empty(self::$_default_creator_id)) {
576
+			return self::$_default_creator_id;
577
+		}/**/
578
+		$role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
579
+		// let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
580
+		$pre_filtered_id = apply_filters(
581
+			'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
582
+			false,
583
+			$role_to_check
584
+		);
585
+		if ($pre_filtered_id !== false) {
586
+			return (int) $pre_filtered_id;
587
+		}
588
+		$capabilities_key = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
589
+		$query            = $wpdb->prepare(
590
+			"SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
591
+			'%' . $role_to_check . '%'
592
+		);
593
+		$user_id          = $wpdb->get_var($query);
594
+		$user_id          = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
595
+		if ($user_id && (int) $user_id) {
596
+			self::$_default_creator_id = (int) $user_id;
597
+			return self::$_default_creator_id;
598
+		} else {
599
+			return null;
600
+		}
601
+	}
602
+
603
+
604
+	/**
605
+	 * used by EE and EE addons during plugin activation to create tables.
606
+	 * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
607
+	 * but includes extra logic regarding activations.
608
+	 *
609
+	 * @param string  $table_name              without the $wpdb->prefix
610
+	 * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
611
+	 *                                         table query)
612
+	 * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
613
+	 * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
614
+	 *                                         and new once this function is done (ie, you really do want to CREATE a
615
+	 *                                         table, and expect it to be empty once you're done) leave as FALSE when
616
+	 *                                         you just want to verify the table exists and matches this definition
617
+	 *                                         (and if it HAS data in it you want to leave it be)
618
+	 * @return void
619
+	 * @throws EE_Error if there are database errors
620
+	 * @throws ReflectionException
621
+	 */
622
+	public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
623
+	{
624
+		if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
625
+			return;
626
+		}
627
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
628
+		if (! function_exists('dbDelta')) {
629
+			require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
630
+		}
631
+		$tableAnalysis = EEH_Activation::getTableAnalysis();
632
+		$wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
633
+		// do we need to first delete an existing version of this table ?
634
+		if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
635
+			// ok, delete the table... but ONLY if it's empty
636
+			$deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
637
+			// table is NOT empty, are you SURE you want to delete this table ???
638
+			if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
639
+				EEH_Activation::getTableManager()->dropTable($wp_table_name);
640
+			} elseif (! $deleted_safely) {
641
+				// so we should be more cautious rather than just dropping tables so easily
642
+				error_log(
643
+					sprintf(
644
+						esc_html__(
645
+							'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
646
+							'event_espresso'
647
+						),
648
+						$wp_table_name,
649
+						'<br/>',
650
+						'espresso_db_update'
651
+					)
652
+				);
653
+			}
654
+		}
655
+		$engine = str_replace('ENGINE=', '', $engine);
656
+		EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
657
+	}
658
+
659
+
660
+	/**
661
+	 * Checks if this column already exists on the specified table. Handy for addons which want to add a column
662
+	 *
663
+	 * @param string $table_name  (without "wp_", eg "esp_attendee"
664
+	 * @param string $column_name
665
+	 * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
666
+	 *                            'VARCHAR(10)'
667
+	 * @return bool|int
668
+	 * @throws EE_Error
669
+	 * @throws ReflectionException
670
+	 * @deprecated instead use TableManager::addColumn()
671
+	 */
672
+	public static function add_column_if_it_doesnt_exist(
673
+		$table_name,
674
+		$column_name,
675
+		$column_info = 'INT UNSIGNED NOT NULL'
676
+	) {
677
+		return EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
678
+	}
679
+
680
+
681
+	/**
682
+	 * Gets all the fields on the database table.
683
+	 *
684
+	 * @param string $table_name , without prefixed $wpdb->prefix
685
+	 * @return array of database column names
686
+	 * @throws EE_Error
687
+	 * @throws ReflectionException
688
+	 * @deprecated instead use TableManager::getTableColumns()
689
+	 */
690
+	public static function get_fields_on_table($table_name = null)
691
+	{
692
+		return EEH_Activation::getTableManager()->getTableColumns($table_name);
693
+	}
694
+
695
+
696
+	/**
697
+	 * @param string $table_name
698
+	 * @return bool
699
+	 * @throws EE_Error
700
+	 * @throws ReflectionException
701
+	 * @deprecated instead use TableAnalysis::tableIsEmpty()
702
+	 */
703
+	public static function db_table_is_empty($table_name)
704
+	{
705
+		return EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
706
+	}
707
+
708
+
709
+	/**
710
+	 * @param string $table_name
711
+	 * @return bool | int
712
+	 * @throws EE_Error
713
+	 * @throws ReflectionException
714
+	 */
715
+	public static function delete_db_table_if_empty($table_name)
716
+	{
717
+		if (EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
718
+			return EEH_Activation::getTableManager()->dropTable($table_name);
719
+		}
720
+		return false;
721
+	}
722
+
723
+
724
+	/**
725
+	 * @param string $table_name
726
+	 * @return int
727
+	 * @throws EE_Error
728
+	 * @throws ReflectionException
729
+	 * @deprecated instead use TableManager::dropTable()
730
+	 */
731
+	public static function delete_unused_db_table($table_name)
732
+	{
733
+		return EEH_Activation::getTableManager()->dropTable($table_name);
734
+	}
735
+
736
+
737
+	/**
738
+	 * @param string $table_name
739
+	 * @param string $index_name
740
+	 * @return int
741
+	 * @throws EE_Error
742
+	 * @throws ReflectionException
743
+	 * @deprecated instead use TableManager::dropIndex()
744
+	 */
745
+	public static function drop_index($table_name, $index_name)
746
+	{
747
+		return EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
748
+	}
749
+
750
+
751
+	/**
752
+	 * @return boolean success (whether database is setup properly or not)
753
+	 * @throws EE_Error
754
+	 * @throws ReflectionException
755
+	 */
756
+	public static function create_database_tables()
757
+	{
758
+		EE_Registry::instance()->load_core('Data_Migration_Manager');
759
+		// find the migration script that sets the database to be compatible with the code
760
+		$dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
761
+		if (! $dms_name) {
762
+			EE_Error::add_error(
763
+				esc_html__(
764
+					'Could not determine most up-to-date data migration script from which to pull database schema
765 765
                      structure. So database is probably not setup properly',
766
-                    'event_espresso'
767
-                ),
768
-                __FILE__,
769
-                __FUNCTION__,
770
-                __LINE__
771
-            );
772
-            return false;
773
-        }
774
-        $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
775
-        $current_data_migration_script->set_migrating(false);
776
-        $current_data_migration_script->schema_changes_before_migration();
777
-        $current_data_migration_script->schema_changes_after_migration();
778
-        if ($current_data_migration_script->get_errors()) {
779
-            if (WP_DEBUG) {
780
-                foreach ($current_data_migration_script->get_errors() as $error) {
781
-                    EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
782
-                }
783
-            } else {
784
-                EE_Error::add_error(
785
-                    esc_html__(
786
-                        'There were errors creating the Event Espresso database tables and Event Espresso has been
766
+					'event_espresso'
767
+				),
768
+				__FILE__,
769
+				__FUNCTION__,
770
+				__LINE__
771
+			);
772
+			return false;
773
+		}
774
+		$current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
775
+		$current_data_migration_script->set_migrating(false);
776
+		$current_data_migration_script->schema_changes_before_migration();
777
+		$current_data_migration_script->schema_changes_after_migration();
778
+		if ($current_data_migration_script->get_errors()) {
779
+			if (WP_DEBUG) {
780
+				foreach ($current_data_migration_script->get_errors() as $error) {
781
+					EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
782
+				}
783
+			} else {
784
+				EE_Error::add_error(
785
+					esc_html__(
786
+						'There were errors creating the Event Espresso database tables and Event Espresso has been
787 787
                             deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.',
788
-                        'event_espresso'
789
-                    )
790
-                );
791
-            }
792
-            return false;
793
-        }
794
-        EE_Data_Migration_Manager::instance()->update_current_database_state_to();
795
-        return true;
796
-    }
797
-
798
-
799
-    /**
800
-     * @return void
801
-     * @throws EE_Error
802
-     * @throws ReflectionException
803
-     */
804
-    public static function initialize_system_questions()
805
-    {
806
-        // QUESTION GROUPS
807
-        global $wpdb;
808
-        $table_name = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
809
-        $SQL        = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
810
-        // what we have
811
-        $question_groups = $wpdb->get_col($SQL);
812
-        // check the response
813
-        $question_groups = is_array($question_groups) ? $question_groups : [];
814
-        // what we should have
815
-        $QSG_systems = [1, 2];
816
-        // loop thru what we should have and compare to what we have
817
-        foreach ($QSG_systems as $QSG_system) {
818
-            // reset values array
819
-            $QSG_values = [];
820
-            // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
821
-            if (! in_array("$QSG_system", $question_groups)) {
822
-                // add it
823
-                switch ($QSG_system) {
824
-                    case 1:
825
-                        $QSG_values = [
826
-                            'QSG_name'            => esc_html__('Personal Information', 'event_espresso'),
827
-                            'QSG_identifier'      => 'personal-information-' . time(),
828
-                            'QSG_desc'            => '',
829
-                            'QSG_order'           => 1,
830
-                            'QSG_show_group_name' => 1,
831
-                            'QSG_show_group_desc' => 1,
832
-                            'QSG_system'          => EEM_Question_Group::system_personal,
833
-                            'QSG_deleted'         => 0,
834
-                        ];
835
-                        break;
836
-                    case 2:
837
-                        $QSG_values = [
838
-                            'QSG_name'            => esc_html__('Address Information', 'event_espresso'),
839
-                            'QSG_identifier'      => 'address-information-' . time(),
840
-                            'QSG_desc'            => '',
841
-                            'QSG_order'           => 2,
842
-                            'QSG_show_group_name' => 1,
843
-                            'QSG_show_group_desc' => 1,
844
-                            'QSG_system'          => EEM_Question_Group::system_address,
845
-                            'QSG_deleted'         => 0,
846
-                        ];
847
-                        break;
848
-                }
849
-                // make sure we have some values before inserting them
850
-                if (! empty($QSG_values)) {
851
-                    // insert system question
852
-                    $wpdb->insert(
853
-                        $table_name,
854
-                        $QSG_values,
855
-                        ['%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d']
856
-                    );
857
-                    $QSG_IDs[ $QSG_system ] = $wpdb->insert_id;
858
-                }
859
-            }
860
-        }
861
-        // QUESTIONS
862
-        global $wpdb;
863
-        $table_name = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
864
-        $SQL        = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
865
-        // what we have
866
-        $questions = $wpdb->get_col($SQL);
867
-        // all system questions
868
-        $personal_system_group_questions = ['fname', 'lname', 'email'];
869
-        $address_system_group_questions  = ['address', 'address2', 'city', 'country', 'state', 'zip', 'phone'];
870
-        $system_questions_not_in_group   = ['email_confirm'];
871
-        // merge all of the system questions we should have
872
-        $QST_systems       = array_merge(
873
-            $personal_system_group_questions,
874
-            $address_system_group_questions,
875
-            $system_questions_not_in_group
876
-        );
877
-        $order_for_group_1 = 1;
878
-        $order_for_group_2 = 1;
879
-        // loop thru what we should have and compare to what we have
880
-        foreach ($QST_systems as $QST_system) {
881
-            // reset values array
882
-            $QST_values = [];
883
-            // if we don't have what we should have
884
-            if (! in_array($QST_system, $questions)) {
885
-                // add it
886
-                switch ($QST_system) {
887
-                    case 'fname':
888
-                        $QST_values = [
889
-                            'QST_display_text'  => esc_html__('First Name', 'event_espresso'),
890
-                            'QST_admin_label'   => esc_html__('First Name - System Question', 'event_espresso'),
891
-                            'QST_system'        => 'fname',
892
-                            'QST_type'          => 'TEXT',
893
-                            'QST_required'      => 1,
894
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
895
-                            'QST_order'         => 1,
896
-                            'QST_admin_only'    => 0,
897
-                            'QST_max'           => EEM_Question::instance()
898
-                                                               ->absolute_max_for_system_question($QST_system),
899
-                            'QST_wp_user'       => self::get_default_creator_id(),
900
-                            'QST_deleted'       => 0,
901
-                        ];
902
-                        break;
903
-                    case 'lname':
904
-                        $QST_values = [
905
-                            'QST_display_text'  => esc_html__('Last Name', 'event_espresso'),
906
-                            'QST_admin_label'   => esc_html__('Last Name - System Question', 'event_espresso'),
907
-                            'QST_system'        => 'lname',
908
-                            'QST_type'          => 'TEXT',
909
-                            'QST_required'      => 1,
910
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
911
-                            'QST_order'         => 2,
912
-                            'QST_admin_only'    => 0,
913
-                            'QST_max'           => EEM_Question::instance()
914
-                                                               ->absolute_max_for_system_question($QST_system),
915
-                            'QST_wp_user'       => self::get_default_creator_id(),
916
-                            'QST_deleted'       => 0,
917
-                        ];
918
-                        break;
919
-                    case 'email':
920
-                        $QST_values = [
921
-                            'QST_display_text'  => esc_html__('Email Address', 'event_espresso'),
922
-                            'QST_admin_label'   => esc_html__('Email Address - System Question', 'event_espresso'),
923
-                            'QST_system'        => 'email',
924
-                            'QST_type'          => 'EMAIL',
925
-                            'QST_required'      => 1,
926
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
927
-                            'QST_order'         => 3,
928
-                            'QST_admin_only'    => 0,
929
-                            'QST_max'           => EEM_Question::instance()
930
-                                                               ->absolute_max_for_system_question($QST_system),
931
-                            'QST_wp_user'       => self::get_default_creator_id(),
932
-                            'QST_deleted'       => 0,
933
-                        ];
934
-                        break;
935
-                    case 'email_confirm':
936
-                        $QST_values = [
937
-                            'QST_display_text'  => esc_html__('Confirm Email Address', 'event_espresso'),
938
-                            'QST_admin_label'   => esc_html__('Confirm Email Address - System Question', 'event_espresso'),
939
-                            'QST_system'        => 'email_confirm',
940
-                            'QST_type'          => 'EMAIL_CONFIRM',
941
-                            'QST_required'      => 1,
942
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
943
-                            'QST_order'         => 4,
944
-                            'QST_admin_only'    => 0,
945
-                            'QST_max'           => EEM_Question::instance()
946
-                                                               ->absolute_max_for_system_question($QST_system),
947
-                            'QST_wp_user'       => self::get_default_creator_id(),
948
-                            'QST_deleted'       => 0,
949
-                        ];
950
-                        break;
951
-                    case 'address':
952
-                        $QST_values = [
953
-                            'QST_display_text'  => esc_html__('Address', 'event_espresso'),
954
-                            'QST_admin_label'   => esc_html__('Address - System Question', 'event_espresso'),
955
-                            'QST_system'        => 'address',
956
-                            'QST_type'          => 'TEXT',
957
-                            'QST_required'      => 0,
958
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
959
-                            'QST_order'         => 5,
960
-                            'QST_admin_only'    => 0,
961
-                            'QST_max'           => EEM_Question::instance()
962
-                                                               ->absolute_max_for_system_question($QST_system),
963
-                            'QST_wp_user'       => self::get_default_creator_id(),
964
-                            'QST_deleted'       => 0,
965
-                        ];
966
-                        break;
967
-                    case 'address2':
968
-                        $QST_values = [
969
-                            'QST_display_text'  => esc_html__('Address2', 'event_espresso'),
970
-                            'QST_admin_label'   => esc_html__('Address2 - System Question', 'event_espresso'),
971
-                            'QST_system'        => 'address2',
972
-                            'QST_type'          => 'TEXT',
973
-                            'QST_required'      => 0,
974
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
975
-                            'QST_order'         => 6,
976
-                            'QST_admin_only'    => 0,
977
-                            'QST_max'           => EEM_Question::instance()
978
-                                                               ->absolute_max_for_system_question($QST_system),
979
-                            'QST_wp_user'       => self::get_default_creator_id(),
980
-                            'QST_deleted'       => 0,
981
-                        ];
982
-                        break;
983
-                    case 'city':
984
-                        $QST_values = [
985
-                            'QST_display_text'  => esc_html__('City', 'event_espresso'),
986
-                            'QST_admin_label'   => esc_html__('City - System Question', 'event_espresso'),
987
-                            'QST_system'        => 'city',
988
-                            'QST_type'          => 'TEXT',
989
-                            'QST_required'      => 0,
990
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
991
-                            'QST_order'         => 7,
992
-                            'QST_admin_only'    => 0,
993
-                            'QST_max'           => EEM_Question::instance()
994
-                                                               ->absolute_max_for_system_question($QST_system),
995
-                            'QST_wp_user'       => self::get_default_creator_id(),
996
-                            'QST_deleted'       => 0,
997
-                        ];
998
-                        break;
999
-                    case 'country':
1000
-                        $QST_values = [
1001
-                            'QST_display_text'  => esc_html__('Country', 'event_espresso'),
1002
-                            'QST_admin_label'   => esc_html__('Country - System Question', 'event_espresso'),
1003
-                            'QST_system'        => 'country',
1004
-                            'QST_type'          => 'COUNTRY',
1005
-                            'QST_required'      => 0,
1006
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1007
-                            'QST_order'         => 8,
1008
-                            'QST_admin_only'    => 0,
1009
-                            'QST_wp_user'       => self::get_default_creator_id(),
1010
-                            'QST_deleted'       => 0,
1011
-                        ];
1012
-                        break;
1013
-                    case 'state':
1014
-                        $QST_values = [
1015
-                            'QST_display_text'  => esc_html__('State/Province', 'event_espresso'),
1016
-                            'QST_admin_label'   => esc_html__('State/Province - System Question', 'event_espresso'),
1017
-                            'QST_system'        => 'state',
1018
-                            'QST_type'          => 'STATE',
1019
-                            'QST_required'      => 0,
1020
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1021
-                            'QST_order'         => 9,
1022
-                            'QST_admin_only'    => 0,
1023
-                            'QST_wp_user'       => self::get_default_creator_id(),
1024
-                            'QST_deleted'       => 0,
1025
-                        ];
1026
-                        break;
1027
-                    case 'zip':
1028
-                        $QST_values = [
1029
-                            'QST_display_text'  => esc_html__('Zip/Postal Code', 'event_espresso'),
1030
-                            'QST_admin_label'   => esc_html__('Zip/Postal Code - System Question', 'event_espresso'),
1031
-                            'QST_system'        => 'zip',
1032
-                            'QST_type'          => 'TEXT',
1033
-                            'QST_required'      => 0,
1034
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1035
-                            'QST_order'         => 10,
1036
-                            'QST_admin_only'    => 0,
1037
-                            'QST_max'           => EEM_Question::instance()
1038
-                                                               ->absolute_max_for_system_question($QST_system),
1039
-                            'QST_wp_user'       => self::get_default_creator_id(),
1040
-                            'QST_deleted'       => 0,
1041
-                        ];
1042
-                        break;
1043
-                    case 'phone':
1044
-                        $QST_values = [
1045
-                            'QST_display_text'  => esc_html__('Phone Number', 'event_espresso'),
1046
-                            'QST_admin_label'   => esc_html__('Phone Number - System Question', 'event_espresso'),
1047
-                            'QST_system'        => 'phone',
1048
-                            'QST_type'          => 'TEXT',
1049
-                            'QST_required'      => 0,
1050
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1051
-                            'QST_order'         => 11,
1052
-                            'QST_admin_only'    => 0,
1053
-                            'QST_max'           => EEM_Question::instance()
1054
-                                                               ->absolute_max_for_system_question($QST_system),
1055
-                            'QST_wp_user'       => self::get_default_creator_id(),
1056
-                            'QST_deleted'       => 0,
1057
-                        ];
1058
-                        break;
1059
-                }
1060
-                if (! empty($QST_values)) {
1061
-                    // insert system question
1062
-                    $wpdb->insert(
1063
-                        $table_name,
1064
-                        $QST_values,
1065
-                        ['%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d']
1066
-                    );
1067
-                    $QST_ID = $wpdb->insert_id;
1068
-
1069
-                    // QUESTION GROUP QUESTIONS
1070
-                    if (in_array($QST_system, $personal_system_group_questions)) {
1071
-                        $system_question_we_want = EEM_Question_Group::system_personal;
1072
-                    } elseif (in_array($QST_system, $address_system_group_questions)) {
1073
-                        $system_question_we_want = EEM_Question_Group::system_address;
1074
-                    } else {
1075
-                        // QST_system should not be assigned to any group
1076
-                        continue;
1077
-                    }
1078
-                    if (isset($QSG_IDs[ $system_question_we_want ])) {
1079
-                        $QSG_ID = $QSG_IDs[ $system_question_we_want ];
1080
-                    } else {
1081
-                        $id_col = EEM_Question_Group::instance()
1082
-                                                    ->get_col([['QSG_system' => $system_question_we_want]]);
1083
-                        if (is_array($id_col)) {
1084
-                            $QSG_ID = reset($id_col);
1085
-                        } else {
1086
-                            // ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1087
-                            EE_Log::instance()->log(
1088
-                                __FILE__,
1089
-                                __FUNCTION__,
1090
-                                sprintf(
1091
-                                    esc_html__(
1092
-                                        'Could not associate question %1$s to a question group because no system question
788
+						'event_espresso'
789
+					)
790
+				);
791
+			}
792
+			return false;
793
+		}
794
+		EE_Data_Migration_Manager::instance()->update_current_database_state_to();
795
+		return true;
796
+	}
797
+
798
+
799
+	/**
800
+	 * @return void
801
+	 * @throws EE_Error
802
+	 * @throws ReflectionException
803
+	 */
804
+	public static function initialize_system_questions()
805
+	{
806
+		// QUESTION GROUPS
807
+		global $wpdb;
808
+		$table_name = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
809
+		$SQL        = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
810
+		// what we have
811
+		$question_groups = $wpdb->get_col($SQL);
812
+		// check the response
813
+		$question_groups = is_array($question_groups) ? $question_groups : [];
814
+		// what we should have
815
+		$QSG_systems = [1, 2];
816
+		// loop thru what we should have and compare to what we have
817
+		foreach ($QSG_systems as $QSG_system) {
818
+			// reset values array
819
+			$QSG_values = [];
820
+			// if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
821
+			if (! in_array("$QSG_system", $question_groups)) {
822
+				// add it
823
+				switch ($QSG_system) {
824
+					case 1:
825
+						$QSG_values = [
826
+							'QSG_name'            => esc_html__('Personal Information', 'event_espresso'),
827
+							'QSG_identifier'      => 'personal-information-' . time(),
828
+							'QSG_desc'            => '',
829
+							'QSG_order'           => 1,
830
+							'QSG_show_group_name' => 1,
831
+							'QSG_show_group_desc' => 1,
832
+							'QSG_system'          => EEM_Question_Group::system_personal,
833
+							'QSG_deleted'         => 0,
834
+						];
835
+						break;
836
+					case 2:
837
+						$QSG_values = [
838
+							'QSG_name'            => esc_html__('Address Information', 'event_espresso'),
839
+							'QSG_identifier'      => 'address-information-' . time(),
840
+							'QSG_desc'            => '',
841
+							'QSG_order'           => 2,
842
+							'QSG_show_group_name' => 1,
843
+							'QSG_show_group_desc' => 1,
844
+							'QSG_system'          => EEM_Question_Group::system_address,
845
+							'QSG_deleted'         => 0,
846
+						];
847
+						break;
848
+				}
849
+				// make sure we have some values before inserting them
850
+				if (! empty($QSG_values)) {
851
+					// insert system question
852
+					$wpdb->insert(
853
+						$table_name,
854
+						$QSG_values,
855
+						['%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d']
856
+					);
857
+					$QSG_IDs[ $QSG_system ] = $wpdb->insert_id;
858
+				}
859
+			}
860
+		}
861
+		// QUESTIONS
862
+		global $wpdb;
863
+		$table_name = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
864
+		$SQL        = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
865
+		// what we have
866
+		$questions = $wpdb->get_col($SQL);
867
+		// all system questions
868
+		$personal_system_group_questions = ['fname', 'lname', 'email'];
869
+		$address_system_group_questions  = ['address', 'address2', 'city', 'country', 'state', 'zip', 'phone'];
870
+		$system_questions_not_in_group   = ['email_confirm'];
871
+		// merge all of the system questions we should have
872
+		$QST_systems       = array_merge(
873
+			$personal_system_group_questions,
874
+			$address_system_group_questions,
875
+			$system_questions_not_in_group
876
+		);
877
+		$order_for_group_1 = 1;
878
+		$order_for_group_2 = 1;
879
+		// loop thru what we should have and compare to what we have
880
+		foreach ($QST_systems as $QST_system) {
881
+			// reset values array
882
+			$QST_values = [];
883
+			// if we don't have what we should have
884
+			if (! in_array($QST_system, $questions)) {
885
+				// add it
886
+				switch ($QST_system) {
887
+					case 'fname':
888
+						$QST_values = [
889
+							'QST_display_text'  => esc_html__('First Name', 'event_espresso'),
890
+							'QST_admin_label'   => esc_html__('First Name - System Question', 'event_espresso'),
891
+							'QST_system'        => 'fname',
892
+							'QST_type'          => 'TEXT',
893
+							'QST_required'      => 1,
894
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
895
+							'QST_order'         => 1,
896
+							'QST_admin_only'    => 0,
897
+							'QST_max'           => EEM_Question::instance()
898
+															   ->absolute_max_for_system_question($QST_system),
899
+							'QST_wp_user'       => self::get_default_creator_id(),
900
+							'QST_deleted'       => 0,
901
+						];
902
+						break;
903
+					case 'lname':
904
+						$QST_values = [
905
+							'QST_display_text'  => esc_html__('Last Name', 'event_espresso'),
906
+							'QST_admin_label'   => esc_html__('Last Name - System Question', 'event_espresso'),
907
+							'QST_system'        => 'lname',
908
+							'QST_type'          => 'TEXT',
909
+							'QST_required'      => 1,
910
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
911
+							'QST_order'         => 2,
912
+							'QST_admin_only'    => 0,
913
+							'QST_max'           => EEM_Question::instance()
914
+															   ->absolute_max_for_system_question($QST_system),
915
+							'QST_wp_user'       => self::get_default_creator_id(),
916
+							'QST_deleted'       => 0,
917
+						];
918
+						break;
919
+					case 'email':
920
+						$QST_values = [
921
+							'QST_display_text'  => esc_html__('Email Address', 'event_espresso'),
922
+							'QST_admin_label'   => esc_html__('Email Address - System Question', 'event_espresso'),
923
+							'QST_system'        => 'email',
924
+							'QST_type'          => 'EMAIL',
925
+							'QST_required'      => 1,
926
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
927
+							'QST_order'         => 3,
928
+							'QST_admin_only'    => 0,
929
+							'QST_max'           => EEM_Question::instance()
930
+															   ->absolute_max_for_system_question($QST_system),
931
+							'QST_wp_user'       => self::get_default_creator_id(),
932
+							'QST_deleted'       => 0,
933
+						];
934
+						break;
935
+					case 'email_confirm':
936
+						$QST_values = [
937
+							'QST_display_text'  => esc_html__('Confirm Email Address', 'event_espresso'),
938
+							'QST_admin_label'   => esc_html__('Confirm Email Address - System Question', 'event_espresso'),
939
+							'QST_system'        => 'email_confirm',
940
+							'QST_type'          => 'EMAIL_CONFIRM',
941
+							'QST_required'      => 1,
942
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
943
+							'QST_order'         => 4,
944
+							'QST_admin_only'    => 0,
945
+							'QST_max'           => EEM_Question::instance()
946
+															   ->absolute_max_for_system_question($QST_system),
947
+							'QST_wp_user'       => self::get_default_creator_id(),
948
+							'QST_deleted'       => 0,
949
+						];
950
+						break;
951
+					case 'address':
952
+						$QST_values = [
953
+							'QST_display_text'  => esc_html__('Address', 'event_espresso'),
954
+							'QST_admin_label'   => esc_html__('Address - System Question', 'event_espresso'),
955
+							'QST_system'        => 'address',
956
+							'QST_type'          => 'TEXT',
957
+							'QST_required'      => 0,
958
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
959
+							'QST_order'         => 5,
960
+							'QST_admin_only'    => 0,
961
+							'QST_max'           => EEM_Question::instance()
962
+															   ->absolute_max_for_system_question($QST_system),
963
+							'QST_wp_user'       => self::get_default_creator_id(),
964
+							'QST_deleted'       => 0,
965
+						];
966
+						break;
967
+					case 'address2':
968
+						$QST_values = [
969
+							'QST_display_text'  => esc_html__('Address2', 'event_espresso'),
970
+							'QST_admin_label'   => esc_html__('Address2 - System Question', 'event_espresso'),
971
+							'QST_system'        => 'address2',
972
+							'QST_type'          => 'TEXT',
973
+							'QST_required'      => 0,
974
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
975
+							'QST_order'         => 6,
976
+							'QST_admin_only'    => 0,
977
+							'QST_max'           => EEM_Question::instance()
978
+															   ->absolute_max_for_system_question($QST_system),
979
+							'QST_wp_user'       => self::get_default_creator_id(),
980
+							'QST_deleted'       => 0,
981
+						];
982
+						break;
983
+					case 'city':
984
+						$QST_values = [
985
+							'QST_display_text'  => esc_html__('City', 'event_espresso'),
986
+							'QST_admin_label'   => esc_html__('City - System Question', 'event_espresso'),
987
+							'QST_system'        => 'city',
988
+							'QST_type'          => 'TEXT',
989
+							'QST_required'      => 0,
990
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
991
+							'QST_order'         => 7,
992
+							'QST_admin_only'    => 0,
993
+							'QST_max'           => EEM_Question::instance()
994
+															   ->absolute_max_for_system_question($QST_system),
995
+							'QST_wp_user'       => self::get_default_creator_id(),
996
+							'QST_deleted'       => 0,
997
+						];
998
+						break;
999
+					case 'country':
1000
+						$QST_values = [
1001
+							'QST_display_text'  => esc_html__('Country', 'event_espresso'),
1002
+							'QST_admin_label'   => esc_html__('Country - System Question', 'event_espresso'),
1003
+							'QST_system'        => 'country',
1004
+							'QST_type'          => 'COUNTRY',
1005
+							'QST_required'      => 0,
1006
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1007
+							'QST_order'         => 8,
1008
+							'QST_admin_only'    => 0,
1009
+							'QST_wp_user'       => self::get_default_creator_id(),
1010
+							'QST_deleted'       => 0,
1011
+						];
1012
+						break;
1013
+					case 'state':
1014
+						$QST_values = [
1015
+							'QST_display_text'  => esc_html__('State/Province', 'event_espresso'),
1016
+							'QST_admin_label'   => esc_html__('State/Province - System Question', 'event_espresso'),
1017
+							'QST_system'        => 'state',
1018
+							'QST_type'          => 'STATE',
1019
+							'QST_required'      => 0,
1020
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1021
+							'QST_order'         => 9,
1022
+							'QST_admin_only'    => 0,
1023
+							'QST_wp_user'       => self::get_default_creator_id(),
1024
+							'QST_deleted'       => 0,
1025
+						];
1026
+						break;
1027
+					case 'zip':
1028
+						$QST_values = [
1029
+							'QST_display_text'  => esc_html__('Zip/Postal Code', 'event_espresso'),
1030
+							'QST_admin_label'   => esc_html__('Zip/Postal Code - System Question', 'event_espresso'),
1031
+							'QST_system'        => 'zip',
1032
+							'QST_type'          => 'TEXT',
1033
+							'QST_required'      => 0,
1034
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1035
+							'QST_order'         => 10,
1036
+							'QST_admin_only'    => 0,
1037
+							'QST_max'           => EEM_Question::instance()
1038
+															   ->absolute_max_for_system_question($QST_system),
1039
+							'QST_wp_user'       => self::get_default_creator_id(),
1040
+							'QST_deleted'       => 0,
1041
+						];
1042
+						break;
1043
+					case 'phone':
1044
+						$QST_values = [
1045
+							'QST_display_text'  => esc_html__('Phone Number', 'event_espresso'),
1046
+							'QST_admin_label'   => esc_html__('Phone Number - System Question', 'event_espresso'),
1047
+							'QST_system'        => 'phone',
1048
+							'QST_type'          => 'TEXT',
1049
+							'QST_required'      => 0,
1050
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1051
+							'QST_order'         => 11,
1052
+							'QST_admin_only'    => 0,
1053
+							'QST_max'           => EEM_Question::instance()
1054
+															   ->absolute_max_for_system_question($QST_system),
1055
+							'QST_wp_user'       => self::get_default_creator_id(),
1056
+							'QST_deleted'       => 0,
1057
+						];
1058
+						break;
1059
+				}
1060
+				if (! empty($QST_values)) {
1061
+					// insert system question
1062
+					$wpdb->insert(
1063
+						$table_name,
1064
+						$QST_values,
1065
+						['%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d']
1066
+					);
1067
+					$QST_ID = $wpdb->insert_id;
1068
+
1069
+					// QUESTION GROUP QUESTIONS
1070
+					if (in_array($QST_system, $personal_system_group_questions)) {
1071
+						$system_question_we_want = EEM_Question_Group::system_personal;
1072
+					} elseif (in_array($QST_system, $address_system_group_questions)) {
1073
+						$system_question_we_want = EEM_Question_Group::system_address;
1074
+					} else {
1075
+						// QST_system should not be assigned to any group
1076
+						continue;
1077
+					}
1078
+					if (isset($QSG_IDs[ $system_question_we_want ])) {
1079
+						$QSG_ID = $QSG_IDs[ $system_question_we_want ];
1080
+					} else {
1081
+						$id_col = EEM_Question_Group::instance()
1082
+													->get_col([['QSG_system' => $system_question_we_want]]);
1083
+						if (is_array($id_col)) {
1084
+							$QSG_ID = reset($id_col);
1085
+						} else {
1086
+							// ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1087
+							EE_Log::instance()->log(
1088
+								__FILE__,
1089
+								__FUNCTION__,
1090
+								sprintf(
1091
+									esc_html__(
1092
+										'Could not associate question %1$s to a question group because no system question
1093 1093
                                          group existed',
1094
-                                        'event_espresso'
1095
-                                    ),
1096
-                                    $QST_ID
1097
-                                ),
1098
-                                'error'
1099
-                            );
1100
-                            continue;
1101
-                        }
1102
-                    }
1103
-                    // add system questions to groups
1104
-                    $wpdb->insert(
1105
-                        EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1106
-                        [
1107
-                            'QSG_ID'    => $QSG_ID,
1108
-                            'QST_ID'    => $QST_ID,
1109
-                            'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1110
-                        ],
1111
-                        ['%d', '%d', '%d']
1112
-                    );
1113
-                }
1114
-            }
1115
-        }
1116
-    }
1117
-
1118
-
1119
-    /**
1120
-     * Makes sure the default payment method (Invoice) is active.
1121
-     * This used to be done automatically as part of constructing the old gateways config
1122
-     *
1123
-     * @throws EE_Error
1124
-     * @throws ReflectionException
1125
-     */
1126
-    public static function insert_default_payment_methods()
1127
-    {
1128
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1129
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
1130
-            EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1131
-        } else {
1132
-            EEM_Payment_Method::instance()->verify_button_urls();
1133
-        }
1134
-    }
1135
-
1136
-
1137
-    /**
1138
-     * @return void
1139
-     * @throws EE_Error
1140
-     * @throws ReflectionException
1141
-     */
1142
-    public static function insert_default_status_codes()
1143
-    {
1144
-
1145
-        global $wpdb;
1146
-
1147
-        if (EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1148
-            $table_name = EEM_Status::instance()->table();
1149
-
1150
-            $SQL =
1151
-                "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1152
-            $wpdb->query($SQL);
1153
-
1154
-            $SQL = "INSERT INTO $table_name
1094
+										'event_espresso'
1095
+									),
1096
+									$QST_ID
1097
+								),
1098
+								'error'
1099
+							);
1100
+							continue;
1101
+						}
1102
+					}
1103
+					// add system questions to groups
1104
+					$wpdb->insert(
1105
+						EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1106
+						[
1107
+							'QSG_ID'    => $QSG_ID,
1108
+							'QST_ID'    => $QST_ID,
1109
+							'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1110
+						],
1111
+						['%d', '%d', '%d']
1112
+					);
1113
+				}
1114
+			}
1115
+		}
1116
+	}
1117
+
1118
+
1119
+	/**
1120
+	 * Makes sure the default payment method (Invoice) is active.
1121
+	 * This used to be done automatically as part of constructing the old gateways config
1122
+	 *
1123
+	 * @throws EE_Error
1124
+	 * @throws ReflectionException
1125
+	 */
1126
+	public static function insert_default_payment_methods()
1127
+	{
1128
+		if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1129
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
1130
+			EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1131
+		} else {
1132
+			EEM_Payment_Method::instance()->verify_button_urls();
1133
+		}
1134
+	}
1135
+
1136
+
1137
+	/**
1138
+	 * @return void
1139
+	 * @throws EE_Error
1140
+	 * @throws ReflectionException
1141
+	 */
1142
+	public static function insert_default_status_codes()
1143
+	{
1144
+
1145
+		global $wpdb;
1146
+
1147
+		if (EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1148
+			$table_name = EEM_Status::instance()->table();
1149
+
1150
+			$SQL =
1151
+				"DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1152
+			$wpdb->query($SQL);
1153
+
1154
+			$SQL = "INSERT INTO $table_name
1155 1155
 					(STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES
1156 1156
 					('ACT', 'ACTIVE', 'event', 0, NULL, 1),
1157 1157
 					('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0),
@@ -1191,480 +1191,480 @@  discard block
 block discarded – undo
1191 1191
 					('MID', 'IDLE', 'message', 0, NULL, 1),
1192 1192
 					('MRS', 'RESEND', 'message', 0, NULL, 1),
1193 1193
 					('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);";
1194
-            $wpdb->query($SQL);
1195
-        }
1196
-    }
1197
-
1198
-
1199
-    /**
1200
-     * @return bool     true means new templates were created.
1201
-     *                  false means no templates were created.
1202
-     *                  This is NOT an error flag. To check for errors you will want
1203
-     *                  to use either EE_Error or a try catch for an EE_Error exception.
1204
-     * @throws EE_Error
1205
-     * @throws ReflectionException
1206
-     */
1207
-    public static function generate_default_message_templates()
1208
-    {
1209
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1210
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1211
-        /*
1194
+			$wpdb->query($SQL);
1195
+		}
1196
+	}
1197
+
1198
+
1199
+	/**
1200
+	 * @return bool     true means new templates were created.
1201
+	 *                  false means no templates were created.
1202
+	 *                  This is NOT an error flag. To check for errors you will want
1203
+	 *                  to use either EE_Error or a try catch for an EE_Error exception.
1204
+	 * @throws EE_Error
1205
+	 * @throws ReflectionException
1206
+	 */
1207
+	public static function generate_default_message_templates()
1208
+	{
1209
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1210
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1211
+		/*
1212 1212
          * This first method is taking care of ensuring any default messengers
1213 1213
          * that should be made active and have templates generated are done.
1214 1214
          */
1215
-        $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1216
-            $message_resource_manager
1217
-        );
1218
-        /**
1219
-         * This method is verifying there are no NEW default message types
1220
-         * for ACTIVE messengers that need activated (and corresponding templates setup).
1221
-         */
1222
-        $new_templates_created_for_message_type =
1223
-            self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1224
-                $message_resource_manager
1225
-            );
1226
-        // after all is done, let's persist these changes to the db.
1227
-        $message_resource_manager->update_has_activated_messengers_option();
1228
-        $message_resource_manager->update_active_messengers_option();
1229
-        // will return true if either of these are true.  Otherwise will return false.
1230
-        return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1231
-    }
1232
-
1233
-
1234
-    /**
1235
-     * @param EE_Message_Resource_Manager $message_resource_manager
1236
-     * @return array|bool
1237
-     * @throws EE_Error
1238
-     * @throws ReflectionException
1239
-     */
1240
-    protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1241
-        EE_Message_Resource_Manager $message_resource_manager
1242
-    ) {
1243
-        $active_messengers       = $message_resource_manager->active_messengers();
1244
-        $installed_message_types = $message_resource_manager->installed_message_types();
1245
-        $templates_created       = false;
1246
-        foreach ($active_messengers as $active_messenger) {
1247
-            $default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1248
-            $default_message_type_names_to_activate   = [];
1249
-            // looping through each default message type reported by the messenger
1250
-            // and setup the actual message types to activate.
1251
-            foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1252
-                // if already active or has already been activated before we skip
1253
-                // (otherwise we might reactivate something user's intentionally deactivated.)
1254
-                // we also skip if the message type is not installed.
1255
-                if (
1256
-                    $message_resource_manager->has_message_type_been_activated_for_messenger(
1257
-                        $default_message_type_name_for_messenger,
1258
-                        $active_messenger->name
1259
-                    )
1260
-                    || $message_resource_manager->is_message_type_active_for_messenger(
1261
-                        $active_messenger->name,
1262
-                        $default_message_type_name_for_messenger
1263
-                    )
1264
-                    || ! isset($installed_message_types[ $default_message_type_name_for_messenger ])
1265
-                ) {
1266
-                    continue;
1267
-                }
1268
-                $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1269
-            }
1270
-            // let's activate!
1271
-            $message_resource_manager->ensure_message_types_are_active(
1272
-                $default_message_type_names_to_activate,
1273
-                $active_messenger->name,
1274
-                false
1275
-            );
1276
-            // activate the templates for these message types
1277
-            if (! empty($default_message_type_names_to_activate)) {
1278
-                $templates_created = EEH_MSG_Template::generate_new_templates(
1279
-                    $active_messenger->name,
1280
-                    $default_message_type_names_for_messenger,
1281
-                    '',
1282
-                    true
1283
-                );
1284
-            }
1285
-        }
1286
-        return $templates_created;
1287
-    }
1288
-
1289
-
1290
-    /**
1291
-     * This will activate and generate default messengers and default message types for those messengers.
1292
-     *
1293
-     * @param EE_message_Resource_Manager $message_resource_manager
1294
-     * @return array|bool  True means there were default messengers and message type templates generated.
1295
-     *                     False means that there were no templates generated
1296
-     *                     (which could simply mean there are no default message types for a messenger).
1297
-     * @throws EE_Error
1298
-     * @throws ReflectionException
1299
-     */
1300
-    protected static function _activate_and_generate_default_messengers_and_message_templates(
1301
-        EE_Message_Resource_Manager $message_resource_manager
1302
-    ) {
1303
-        $messengers_to_generate  = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1304
-        $installed_message_types = $message_resource_manager->installed_message_types();
1305
-        $templates_generated     = false;
1306
-        foreach ($messengers_to_generate as $messenger_to_generate) {
1307
-            $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1308
-            // verify the default message types match an installed message type.
1309
-            foreach ($default_message_type_names_for_messenger as $key => $name) {
1310
-                if (
1311
-                    ! isset($installed_message_types[ $name ])
1312
-                    || $message_resource_manager->has_message_type_been_activated_for_messenger(
1313
-                        $name,
1314
-                        $messenger_to_generate->name
1315
-                    )
1316
-                ) {
1317
-                    unset($default_message_type_names_for_messenger[ $key ]);
1318
-                }
1319
-            }
1320
-            // in previous iterations, the active_messengers option in the db
1321
-            // needed updated before calling create templates. however with the changes this may not be necessary.
1322
-            // This comment is left here just in case we discover that we _do_ need to update before
1323
-            // passing off to create templates (after the refactor is done).
1324
-            // @todo remove this comment when determined not necessary.
1325
-            $message_resource_manager->activate_messenger(
1326
-                $messenger_to_generate,
1327
-                $default_message_type_names_for_messenger,
1328
-                false
1329
-            );
1330
-            // create any templates needing created (or will reactivate templates already generated as necessary).
1331
-            if (! empty($default_message_type_names_for_messenger)) {
1332
-                $templates_generated = EEH_MSG_Template::generate_new_templates(
1333
-                    $messenger_to_generate->name,
1334
-                    $default_message_type_names_for_messenger,
1335
-                    '',
1336
-                    true
1337
-                );
1338
-            }
1339
-        }
1340
-        return $templates_generated;
1341
-    }
1342
-
1343
-
1344
-    /**
1345
-     * This returns the default messengers to generate templates for on activation of EE.
1346
-     * It considers:
1347
-     * - whether a messenger is already active in the db.
1348
-     * - whether a messenger has been made active at any time in the past.
1349
-     *
1350
-     * @param EE_Message_Resource_Manager $message_resource_manager
1351
-     * @return EE_messenger[]
1352
-     */
1353
-    protected static function _get_default_messengers_to_generate_on_activation(
1354
-        EE_Message_Resource_Manager $message_resource_manager
1355
-    ) {
1356
-        $active_messengers    = $message_resource_manager->active_messengers();
1357
-        $installed_messengers = $message_resource_manager->installed_messengers();
1358
-        $has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1359
-
1360
-        $messengers_to_generate = [];
1361
-        foreach ($installed_messengers as $installed_messenger) {
1362
-            // if installed messenger is a messenger that should be activated on install
1363
-            // and is not already active
1364
-            // and has never been activated
1365
-            if (
1366
-                ! $installed_messenger->activate_on_install
1367
-                || isset($active_messengers[ $installed_messenger->name ])
1368
-                || isset($has_activated[ $installed_messenger->name ])
1369
-            ) {
1370
-                continue;
1371
-            }
1372
-            $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger;
1373
-        }
1374
-        return $messengers_to_generate;
1375
-    }
1376
-
1377
-
1378
-    /**
1379
-     * This simply validates active message types to ensure they actually match installed
1380
-     * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1381
-     * rows are set inactive.
1382
-     * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1383
-     * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1384
-     * are still handled in here.
1385
-     *
1386
-     * @return void
1387
-     * @throws EE_Error
1388
-     * @throws ReflectionException
1389
-     * @since 4.3.1
1390
-     */
1391
-    public static function validate_messages_system()
1392
-    {
1393
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1394
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1395
-        $message_resource_manager->validate_active_message_types_are_installed();
1396
-        do_action('AHEE__EEH_Activation__validate_messages_system');
1397
-    }
1398
-
1399
-
1400
-    /**
1401
-     * @return void
1402
-     */
1403
-    public static function create_no_ticket_prices_array()
1404
-    {
1405
-        // this creates an array for tracking events that have no active ticket prices created
1406
-        // this allows us to warn admins of the situation so that it can be corrected
1407
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1408
-        if (! $espresso_no_ticket_prices) {
1409
-            add_option('ee_no_ticket_prices', [], '', false);
1410
-        }
1411
-    }
1412
-
1413
-
1414
-    /**
1415
-     * @return void
1416
-     */
1417
-    public static function plugin_deactivation()
1418
-    {
1419
-    }
1420
-
1421
-
1422
-    /**
1423
-     * Finds all our EE4 custom post types, and deletes them and their associated data
1424
-     * (like post meta or term relations)
1425
-     *
1426
-     * @throws EE_Error
1427
-     * @global wpdb $wpdb
1428
-     */
1429
-    public static function delete_all_espresso_cpt_data()
1430
-    {
1431
-        global $wpdb;
1432
-        // get all the CPT post_types
1433
-        $ee_post_types = [];
1434
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1435
-            if (method_exists($model_name, 'instance')) {
1436
-                $model_obj = call_user_func([$model_name, 'instance']);
1437
-                if ($model_obj instanceof EEM_CPT_Base) {
1438
-                    $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1439
-                }
1440
-            }
1441
-        }
1442
-        // get all our CPTs
1443
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1444
-        $cpt_ids = $wpdb->get_col($query);
1445
-        // delete each post meta and term relations too
1446
-        foreach ($cpt_ids as $post_id) {
1447
-            wp_delete_post($post_id, true);
1448
-        }
1449
-    }
1450
-
1451
-
1452
-    /**
1453
-     * Deletes all EE custom tables
1454
-     *
1455
-     * @return array
1456
-     * @throws EE_Error
1457
-     * @throws ReflectionException
1458
-     */
1459
-    public static function drop_espresso_tables()
1460
-    {
1461
-        $tables = [];
1462
-        // load registry
1463
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1464
-            if (method_exists($model_name, 'instance')) {
1465
-                $model_obj = call_user_func([$model_name, 'instance']);
1466
-                if ($model_obj instanceof EEM_Base) {
1467
-                    foreach ($model_obj->get_tables() as $table) {
1468
-                        if (
1469
-                            strpos($table->get_table_name(), 'esp_')
1470
-                            && (
1471
-                                is_main_site()// main site? nuke them all
1472
-                                || ! $table->is_global()// not main site,but not global either. nuke it
1473
-                            )
1474
-                        ) {
1475
-                            $tables[ $table->get_table_name() ] = $table->get_table_name();
1476
-                        }
1477
-                    }
1478
-                }
1479
-            }
1480
-        }
1481
-
1482
-        // there are some tables whose models were removed.
1483
-        // they should be removed when removing all EE core's data
1484
-        $tables_without_models = [
1485
-            'esp_promotion',
1486
-            'esp_promotion_applied',
1487
-            'esp_promotion_object',
1488
-            'esp_promotion_rule',
1489
-            'esp_rule',
1490
-        ];
1491
-        foreach ($tables_without_models as $table) {
1492
-            $tables[ $table ] = $table;
1493
-        }
1494
-        return EEH_Activation::getTableManager()->dropTables($tables);
1495
-    }
1496
-
1497
-
1498
-    /**
1499
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
1500
-     * each table name provided has a wpdb prefix attached, and that it exists.
1501
-     * Returns the list actually deleted
1502
-     *
1503
-     * @param array $table_names
1504
-     * @return array of table names which we deleted
1505
-     * @throws EE_Error
1506
-     * @throws ReflectionException
1507
-     * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1508
-     * @global WPDB $wpdb
1509
-     */
1510
-    public static function drop_tables($table_names)
1511
-    {
1512
-        return EEH_Activation::getTableManager()->dropTables($table_names);
1513
-    }
1514
-
1515
-
1516
-    /**
1517
-     * plugin_uninstall
1518
-     *
1519
-     * @param bool $remove_all
1520
-     * @return void
1521
-     * @throws EE_Error
1522
-     * @throws ReflectionException
1523
-     */
1524
-    public static function delete_all_espresso_tables_and_data($remove_all = true)
1525
-    {
1526
-        global $wpdb;
1527
-        self::drop_espresso_tables();
1528
-        $wp_options_to_delete = [
1529
-            'ee_no_ticket_prices'                        => true,
1530
-            'ee_active_messengers'                       => true,
1531
-            'ee_has_activated_messenger'                 => true,
1532
-            RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true,
1533
-            'ee_config'                                  => false,
1534
-            'ee_data_migration_current_db_state'         => true,
1535
-            'ee_data_migration_mapping_'                 => false,
1536
-            'ee_data_migration_script_'                  => false,
1537
-            'ee_data_migrations'                         => true,
1538
-            'ee_dms_map'                                 => false,
1539
-            'ee_notices'                                 => true,
1540
-            'lang_file_check_'                           => false,
1541
-            'ee_maintenance_mode'                        => true,
1542
-            'ee_ueip_optin'                              => true,
1543
-            'ee_ueip_has_notified'                       => true,
1544
-            'ee_plugin_activation_errors'                => true,
1545
-            'ee_id_mapping_from'                         => false,
1546
-            'espresso_persistent_admin_notices'          => true,
1547
-            'ee_encryption_key'                          => true,
1548
-            'pue_force_upgrade_'                         => false,
1549
-            'pue_json_error_'                            => false,
1550
-            'pue_install_key_'                           => false,
1551
-            'pue_verification_error_'                    => false,
1552
-            'pu_dismissed_upgrade_'                      => false,
1553
-            'external_updates-'                          => false,
1554
-            'ee_extra_data'                              => true,
1555
-            'ee_ssn_'                                    => false,
1556
-            'ee_rss_'                                    => false,
1557
-            'ee_rte_n_tx_'                               => false,
1558
-            'ee_pers_admin_notices'                      => true,
1559
-            'ee_job_parameters_'                         => false,
1560
-            'ee_upload_directories_incomplete'           => true,
1561
-            'ee_verified_db_collations'                  => true,
1562
-        ];
1563
-        if (is_main_site()) {
1564
-            $wp_options_to_delete['ee_network_config'] = true;
1565
-        }
1566
-        $undeleted_options = [];
1567
-        foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1568
-            if ($no_wildcard) {
1569
-                if (! delete_option($option_name)) {
1570
-                    $undeleted_options[] = $option_name;
1571
-                }
1572
-            } else {
1573
-                $option_names_to_delete_from_wildcard =
1574
-                    $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1575
-                foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1576
-                    if (! delete_option($option_name_from_wildcard)) {
1577
-                        $undeleted_options[] = $option_name_from_wildcard;
1578
-                    }
1579
-                }
1580
-            }
1581
-        }
1582
-        // also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1583
-        remove_action('shutdown', [EE_Config::instance(), 'shutdown']);
1584
-        if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1585
-            $db_update_sans_ee4 = [];
1586
-            foreach ($espresso_db_update as $version => $times_activated) {
1587
-                if ((string) $version[0] === '3') {// if its NON EE4
1588
-                    $db_update_sans_ee4[ $version ] = $times_activated;
1589
-                }
1590
-            }
1591
-            update_option('espresso_db_update', $db_update_sans_ee4);
1592
-        }
1593
-        $errors = '';
1594
-        if (! empty($undeleted_options)) {
1595
-            $errors .= sprintf(
1596
-                esc_html__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1597
-                '<br/>',
1598
-                implode(',<br/>', $undeleted_options)
1599
-            );
1600
-        }
1601
-        if (! empty($errors)) {
1602
-            EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1603
-        }
1604
-    }
1605
-
1606
-
1607
-    /**
1608
-     * Gets the mysql error code from the last used query by wpdb
1609
-     *
1610
-     * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1611
-     */
1612
-    public static function last_wpdb_error_code()
1613
-    {
1614
-        // phpcs:disable PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
1615
-        global $wpdb;
1616
-        return $wpdb->use_mysqli ? mysqli_errno($wpdb->dbh) : 0;
1617
-        // phpcs:enable
1618
-    }
1619
-
1620
-
1621
-    /**
1622
-     * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1623
-     *
1624
-     * @param string $table_name with or without $wpdb->prefix
1625
-     * @return boolean
1626
-     * @throws EE_Error
1627
-     * @throws ReflectionException
1628
-     * @global wpdb  $wpdb
1629
-     * @deprecated instead use TableAnalysis::tableExists()
1630
-     */
1631
-    public static function table_exists($table_name)
1632
-    {
1633
-        return EEH_Activation::getTableAnalysis()->tableExists($table_name);
1634
-    }
1635
-
1636
-
1637
-    /**
1638
-     * Resets the cache on EEH_Activation
1639
-     */
1640
-    public static function reset()
1641
-    {
1642
-        self::$_default_creator_id                             = null;
1643
-        self::$_initialized_db_content_already_in_this_request = false;
1644
-    }
1645
-
1646
-
1647
-    /**
1648
-     * Removes 'email_confirm' from the Address info question group on activation
1649
-     *
1650
-     * @return void
1651
-     * @throws EE_Error
1652
-     */
1653
-    public static function removeEmailConfirmFromAddressGroup()
1654
-    {
1655
-
1656
-        // Pull the email_confirm question ID.
1657
-        $email_confirm_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(
1658
-            EEM_Attendee::system_question_email_confirm
1659
-        );
1660
-        // Remove the email_confirm question group from the address group questions.
1661
-        EEM_Question_Group_Question::instance()->delete(
1662
-            [
1663
-                [
1664
-                    'QST_ID'                    => $email_confirm_question_id,
1665
-                    'Question_Group.QSG_system' => EEM_Question_Group::system_address,
1666
-                ],
1667
-            ]
1668
-        );
1669
-    }
1215
+		$new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1216
+			$message_resource_manager
1217
+		);
1218
+		/**
1219
+		 * This method is verifying there are no NEW default message types
1220
+		 * for ACTIVE messengers that need activated (and corresponding templates setup).
1221
+		 */
1222
+		$new_templates_created_for_message_type =
1223
+			self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1224
+				$message_resource_manager
1225
+			);
1226
+		// after all is done, let's persist these changes to the db.
1227
+		$message_resource_manager->update_has_activated_messengers_option();
1228
+		$message_resource_manager->update_active_messengers_option();
1229
+		// will return true if either of these are true.  Otherwise will return false.
1230
+		return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1231
+	}
1232
+
1233
+
1234
+	/**
1235
+	 * @param EE_Message_Resource_Manager $message_resource_manager
1236
+	 * @return array|bool
1237
+	 * @throws EE_Error
1238
+	 * @throws ReflectionException
1239
+	 */
1240
+	protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1241
+		EE_Message_Resource_Manager $message_resource_manager
1242
+	) {
1243
+		$active_messengers       = $message_resource_manager->active_messengers();
1244
+		$installed_message_types = $message_resource_manager->installed_message_types();
1245
+		$templates_created       = false;
1246
+		foreach ($active_messengers as $active_messenger) {
1247
+			$default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1248
+			$default_message_type_names_to_activate   = [];
1249
+			// looping through each default message type reported by the messenger
1250
+			// and setup the actual message types to activate.
1251
+			foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1252
+				// if already active or has already been activated before we skip
1253
+				// (otherwise we might reactivate something user's intentionally deactivated.)
1254
+				// we also skip if the message type is not installed.
1255
+				if (
1256
+					$message_resource_manager->has_message_type_been_activated_for_messenger(
1257
+						$default_message_type_name_for_messenger,
1258
+						$active_messenger->name
1259
+					)
1260
+					|| $message_resource_manager->is_message_type_active_for_messenger(
1261
+						$active_messenger->name,
1262
+						$default_message_type_name_for_messenger
1263
+					)
1264
+					|| ! isset($installed_message_types[ $default_message_type_name_for_messenger ])
1265
+				) {
1266
+					continue;
1267
+				}
1268
+				$default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1269
+			}
1270
+			// let's activate!
1271
+			$message_resource_manager->ensure_message_types_are_active(
1272
+				$default_message_type_names_to_activate,
1273
+				$active_messenger->name,
1274
+				false
1275
+			);
1276
+			// activate the templates for these message types
1277
+			if (! empty($default_message_type_names_to_activate)) {
1278
+				$templates_created = EEH_MSG_Template::generate_new_templates(
1279
+					$active_messenger->name,
1280
+					$default_message_type_names_for_messenger,
1281
+					'',
1282
+					true
1283
+				);
1284
+			}
1285
+		}
1286
+		return $templates_created;
1287
+	}
1288
+
1289
+
1290
+	/**
1291
+	 * This will activate and generate default messengers and default message types for those messengers.
1292
+	 *
1293
+	 * @param EE_message_Resource_Manager $message_resource_manager
1294
+	 * @return array|bool  True means there were default messengers and message type templates generated.
1295
+	 *                     False means that there were no templates generated
1296
+	 *                     (which could simply mean there are no default message types for a messenger).
1297
+	 * @throws EE_Error
1298
+	 * @throws ReflectionException
1299
+	 */
1300
+	protected static function _activate_and_generate_default_messengers_and_message_templates(
1301
+		EE_Message_Resource_Manager $message_resource_manager
1302
+	) {
1303
+		$messengers_to_generate  = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1304
+		$installed_message_types = $message_resource_manager->installed_message_types();
1305
+		$templates_generated     = false;
1306
+		foreach ($messengers_to_generate as $messenger_to_generate) {
1307
+			$default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1308
+			// verify the default message types match an installed message type.
1309
+			foreach ($default_message_type_names_for_messenger as $key => $name) {
1310
+				if (
1311
+					! isset($installed_message_types[ $name ])
1312
+					|| $message_resource_manager->has_message_type_been_activated_for_messenger(
1313
+						$name,
1314
+						$messenger_to_generate->name
1315
+					)
1316
+				) {
1317
+					unset($default_message_type_names_for_messenger[ $key ]);
1318
+				}
1319
+			}
1320
+			// in previous iterations, the active_messengers option in the db
1321
+			// needed updated before calling create templates. however with the changes this may not be necessary.
1322
+			// This comment is left here just in case we discover that we _do_ need to update before
1323
+			// passing off to create templates (after the refactor is done).
1324
+			// @todo remove this comment when determined not necessary.
1325
+			$message_resource_manager->activate_messenger(
1326
+				$messenger_to_generate,
1327
+				$default_message_type_names_for_messenger,
1328
+				false
1329
+			);
1330
+			// create any templates needing created (or will reactivate templates already generated as necessary).
1331
+			if (! empty($default_message_type_names_for_messenger)) {
1332
+				$templates_generated = EEH_MSG_Template::generate_new_templates(
1333
+					$messenger_to_generate->name,
1334
+					$default_message_type_names_for_messenger,
1335
+					'',
1336
+					true
1337
+				);
1338
+			}
1339
+		}
1340
+		return $templates_generated;
1341
+	}
1342
+
1343
+
1344
+	/**
1345
+	 * This returns the default messengers to generate templates for on activation of EE.
1346
+	 * It considers:
1347
+	 * - whether a messenger is already active in the db.
1348
+	 * - whether a messenger has been made active at any time in the past.
1349
+	 *
1350
+	 * @param EE_Message_Resource_Manager $message_resource_manager
1351
+	 * @return EE_messenger[]
1352
+	 */
1353
+	protected static function _get_default_messengers_to_generate_on_activation(
1354
+		EE_Message_Resource_Manager $message_resource_manager
1355
+	) {
1356
+		$active_messengers    = $message_resource_manager->active_messengers();
1357
+		$installed_messengers = $message_resource_manager->installed_messengers();
1358
+		$has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1359
+
1360
+		$messengers_to_generate = [];
1361
+		foreach ($installed_messengers as $installed_messenger) {
1362
+			// if installed messenger is a messenger that should be activated on install
1363
+			// and is not already active
1364
+			// and has never been activated
1365
+			if (
1366
+				! $installed_messenger->activate_on_install
1367
+				|| isset($active_messengers[ $installed_messenger->name ])
1368
+				|| isset($has_activated[ $installed_messenger->name ])
1369
+			) {
1370
+				continue;
1371
+			}
1372
+			$messengers_to_generate[ $installed_messenger->name ] = $installed_messenger;
1373
+		}
1374
+		return $messengers_to_generate;
1375
+	}
1376
+
1377
+
1378
+	/**
1379
+	 * This simply validates active message types to ensure they actually match installed
1380
+	 * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1381
+	 * rows are set inactive.
1382
+	 * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1383
+	 * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1384
+	 * are still handled in here.
1385
+	 *
1386
+	 * @return void
1387
+	 * @throws EE_Error
1388
+	 * @throws ReflectionException
1389
+	 * @since 4.3.1
1390
+	 */
1391
+	public static function validate_messages_system()
1392
+	{
1393
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1394
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1395
+		$message_resource_manager->validate_active_message_types_are_installed();
1396
+		do_action('AHEE__EEH_Activation__validate_messages_system');
1397
+	}
1398
+
1399
+
1400
+	/**
1401
+	 * @return void
1402
+	 */
1403
+	public static function create_no_ticket_prices_array()
1404
+	{
1405
+		// this creates an array for tracking events that have no active ticket prices created
1406
+		// this allows us to warn admins of the situation so that it can be corrected
1407
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1408
+		if (! $espresso_no_ticket_prices) {
1409
+			add_option('ee_no_ticket_prices', [], '', false);
1410
+		}
1411
+	}
1412
+
1413
+
1414
+	/**
1415
+	 * @return void
1416
+	 */
1417
+	public static function plugin_deactivation()
1418
+	{
1419
+	}
1420
+
1421
+
1422
+	/**
1423
+	 * Finds all our EE4 custom post types, and deletes them and their associated data
1424
+	 * (like post meta or term relations)
1425
+	 *
1426
+	 * @throws EE_Error
1427
+	 * @global wpdb $wpdb
1428
+	 */
1429
+	public static function delete_all_espresso_cpt_data()
1430
+	{
1431
+		global $wpdb;
1432
+		// get all the CPT post_types
1433
+		$ee_post_types = [];
1434
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1435
+			if (method_exists($model_name, 'instance')) {
1436
+				$model_obj = call_user_func([$model_name, 'instance']);
1437
+				if ($model_obj instanceof EEM_CPT_Base) {
1438
+					$ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1439
+				}
1440
+			}
1441
+		}
1442
+		// get all our CPTs
1443
+		$query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1444
+		$cpt_ids = $wpdb->get_col($query);
1445
+		// delete each post meta and term relations too
1446
+		foreach ($cpt_ids as $post_id) {
1447
+			wp_delete_post($post_id, true);
1448
+		}
1449
+	}
1450
+
1451
+
1452
+	/**
1453
+	 * Deletes all EE custom tables
1454
+	 *
1455
+	 * @return array
1456
+	 * @throws EE_Error
1457
+	 * @throws ReflectionException
1458
+	 */
1459
+	public static function drop_espresso_tables()
1460
+	{
1461
+		$tables = [];
1462
+		// load registry
1463
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1464
+			if (method_exists($model_name, 'instance')) {
1465
+				$model_obj = call_user_func([$model_name, 'instance']);
1466
+				if ($model_obj instanceof EEM_Base) {
1467
+					foreach ($model_obj->get_tables() as $table) {
1468
+						if (
1469
+							strpos($table->get_table_name(), 'esp_')
1470
+							&& (
1471
+								is_main_site()// main site? nuke them all
1472
+								|| ! $table->is_global()// not main site,but not global either. nuke it
1473
+							)
1474
+						) {
1475
+							$tables[ $table->get_table_name() ] = $table->get_table_name();
1476
+						}
1477
+					}
1478
+				}
1479
+			}
1480
+		}
1481
+
1482
+		// there are some tables whose models were removed.
1483
+		// they should be removed when removing all EE core's data
1484
+		$tables_without_models = [
1485
+			'esp_promotion',
1486
+			'esp_promotion_applied',
1487
+			'esp_promotion_object',
1488
+			'esp_promotion_rule',
1489
+			'esp_rule',
1490
+		];
1491
+		foreach ($tables_without_models as $table) {
1492
+			$tables[ $table ] = $table;
1493
+		}
1494
+		return EEH_Activation::getTableManager()->dropTables($tables);
1495
+	}
1496
+
1497
+
1498
+	/**
1499
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
1500
+	 * each table name provided has a wpdb prefix attached, and that it exists.
1501
+	 * Returns the list actually deleted
1502
+	 *
1503
+	 * @param array $table_names
1504
+	 * @return array of table names which we deleted
1505
+	 * @throws EE_Error
1506
+	 * @throws ReflectionException
1507
+	 * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1508
+	 * @global WPDB $wpdb
1509
+	 */
1510
+	public static function drop_tables($table_names)
1511
+	{
1512
+		return EEH_Activation::getTableManager()->dropTables($table_names);
1513
+	}
1514
+
1515
+
1516
+	/**
1517
+	 * plugin_uninstall
1518
+	 *
1519
+	 * @param bool $remove_all
1520
+	 * @return void
1521
+	 * @throws EE_Error
1522
+	 * @throws ReflectionException
1523
+	 */
1524
+	public static function delete_all_espresso_tables_and_data($remove_all = true)
1525
+	{
1526
+		global $wpdb;
1527
+		self::drop_espresso_tables();
1528
+		$wp_options_to_delete = [
1529
+			'ee_no_ticket_prices'                        => true,
1530
+			'ee_active_messengers'                       => true,
1531
+			'ee_has_activated_messenger'                 => true,
1532
+			RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true,
1533
+			'ee_config'                                  => false,
1534
+			'ee_data_migration_current_db_state'         => true,
1535
+			'ee_data_migration_mapping_'                 => false,
1536
+			'ee_data_migration_script_'                  => false,
1537
+			'ee_data_migrations'                         => true,
1538
+			'ee_dms_map'                                 => false,
1539
+			'ee_notices'                                 => true,
1540
+			'lang_file_check_'                           => false,
1541
+			'ee_maintenance_mode'                        => true,
1542
+			'ee_ueip_optin'                              => true,
1543
+			'ee_ueip_has_notified'                       => true,
1544
+			'ee_plugin_activation_errors'                => true,
1545
+			'ee_id_mapping_from'                         => false,
1546
+			'espresso_persistent_admin_notices'          => true,
1547
+			'ee_encryption_key'                          => true,
1548
+			'pue_force_upgrade_'                         => false,
1549
+			'pue_json_error_'                            => false,
1550
+			'pue_install_key_'                           => false,
1551
+			'pue_verification_error_'                    => false,
1552
+			'pu_dismissed_upgrade_'                      => false,
1553
+			'external_updates-'                          => false,
1554
+			'ee_extra_data'                              => true,
1555
+			'ee_ssn_'                                    => false,
1556
+			'ee_rss_'                                    => false,
1557
+			'ee_rte_n_tx_'                               => false,
1558
+			'ee_pers_admin_notices'                      => true,
1559
+			'ee_job_parameters_'                         => false,
1560
+			'ee_upload_directories_incomplete'           => true,
1561
+			'ee_verified_db_collations'                  => true,
1562
+		];
1563
+		if (is_main_site()) {
1564
+			$wp_options_to_delete['ee_network_config'] = true;
1565
+		}
1566
+		$undeleted_options = [];
1567
+		foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1568
+			if ($no_wildcard) {
1569
+				if (! delete_option($option_name)) {
1570
+					$undeleted_options[] = $option_name;
1571
+				}
1572
+			} else {
1573
+				$option_names_to_delete_from_wildcard =
1574
+					$wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1575
+				foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1576
+					if (! delete_option($option_name_from_wildcard)) {
1577
+						$undeleted_options[] = $option_name_from_wildcard;
1578
+					}
1579
+				}
1580
+			}
1581
+		}
1582
+		// also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1583
+		remove_action('shutdown', [EE_Config::instance(), 'shutdown']);
1584
+		if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1585
+			$db_update_sans_ee4 = [];
1586
+			foreach ($espresso_db_update as $version => $times_activated) {
1587
+				if ((string) $version[0] === '3') {// if its NON EE4
1588
+					$db_update_sans_ee4[ $version ] = $times_activated;
1589
+				}
1590
+			}
1591
+			update_option('espresso_db_update', $db_update_sans_ee4);
1592
+		}
1593
+		$errors = '';
1594
+		if (! empty($undeleted_options)) {
1595
+			$errors .= sprintf(
1596
+				esc_html__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1597
+				'<br/>',
1598
+				implode(',<br/>', $undeleted_options)
1599
+			);
1600
+		}
1601
+		if (! empty($errors)) {
1602
+			EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1603
+		}
1604
+	}
1605
+
1606
+
1607
+	/**
1608
+	 * Gets the mysql error code from the last used query by wpdb
1609
+	 *
1610
+	 * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1611
+	 */
1612
+	public static function last_wpdb_error_code()
1613
+	{
1614
+		// phpcs:disable PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
1615
+		global $wpdb;
1616
+		return $wpdb->use_mysqli ? mysqli_errno($wpdb->dbh) : 0;
1617
+		// phpcs:enable
1618
+	}
1619
+
1620
+
1621
+	/**
1622
+	 * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1623
+	 *
1624
+	 * @param string $table_name with or without $wpdb->prefix
1625
+	 * @return boolean
1626
+	 * @throws EE_Error
1627
+	 * @throws ReflectionException
1628
+	 * @global wpdb  $wpdb
1629
+	 * @deprecated instead use TableAnalysis::tableExists()
1630
+	 */
1631
+	public static function table_exists($table_name)
1632
+	{
1633
+		return EEH_Activation::getTableAnalysis()->tableExists($table_name);
1634
+	}
1635
+
1636
+
1637
+	/**
1638
+	 * Resets the cache on EEH_Activation
1639
+	 */
1640
+	public static function reset()
1641
+	{
1642
+		self::$_default_creator_id                             = null;
1643
+		self::$_initialized_db_content_already_in_this_request = false;
1644
+	}
1645
+
1646
+
1647
+	/**
1648
+	 * Removes 'email_confirm' from the Address info question group on activation
1649
+	 *
1650
+	 * @return void
1651
+	 * @throws EE_Error
1652
+	 */
1653
+	public static function removeEmailConfirmFromAddressGroup()
1654
+	{
1655
+
1656
+		// Pull the email_confirm question ID.
1657
+		$email_confirm_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(
1658
+			EEM_Attendee::system_question_email_confirm
1659
+		);
1660
+		// Remove the email_confirm question group from the address group questions.
1661
+		EEM_Question_Group_Question::instance()->delete(
1662
+			[
1663
+				[
1664
+					'QST_ID'                    => $email_confirm_question_id,
1665
+					'Question_Group.QSG_system' => EEM_Question_Group::system_address,
1666
+				],
1667
+			]
1668
+		);
1669
+	}
1670 1670
 }
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      */
58 58
     public static function getTableAnalysis()
59 59
     {
60
-        if (! self::$table_analysis instanceof TableAnalysis) {
60
+        if ( ! self::$table_analysis instanceof TableAnalysis) {
61 61
             self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', [], true);
62 62
         }
63 63
         return self::$table_analysis;
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
      */
72 72
     public static function getTableManager()
73 73
     {
74
-        if (! self::$table_manager instanceof TableManager) {
74
+        if ( ! self::$table_manager instanceof TableManager) {
75 75
             self::$table_manager = EE_Registry::instance()->create('TableManager', [], true);
76 76
         }
77 77
         return self::$table_manager;
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
     public static function initialize_db_and_folders()
117 117
     {
118 118
         EEH_File::ensure_folder_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR);
119
-        EEH_File::ensure_folder_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR . 'logs');
119
+        EEH_File::ensure_folder_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR.'logs');
120 120
         return EEH_Activation::create_database_tables();
121 121
     }
122 122
 
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
         if ($which_to_include === 'old') {
188 188
             $cron_tasks = array_filter(
189 189
                 $cron_tasks,
190
-                function ($value) {
190
+                function($value) {
191 191
                     return $value === EEH_Activation::cron_task_no_longer_in_use;
192 192
                 }
193 193
             );
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
     {
218 218
 
219 219
         foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
220
-            if (! wp_next_scheduled($hook_name)) {
220
+            if ( ! wp_next_scheduled($hook_name)) {
221 221
                 /**
222 222
                  * This allows client code to define the initial start timestamp for this schedule.
223 223
                  */
@@ -270,15 +270,15 @@  discard block
 block discarded – undo
270 270
             if (is_array($hooks_to_fire_at_time)) {
271 271
                 foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
272 272
                     if (
273
-                        isset($ee_cron_tasks_to_remove[ $hook_name ])
274
-                        && is_array($ee_cron_tasks_to_remove[ $hook_name ])
273
+                        isset($ee_cron_tasks_to_remove[$hook_name])
274
+                        && is_array($ee_cron_tasks_to_remove[$hook_name])
275 275
                     ) {
276
-                        unset($crons[ $timestamp ][ $hook_name ]);
276
+                        unset($crons[$timestamp][$hook_name]);
277 277
                     }
278 278
                 }
279 279
                 // also take care of any empty cron timestamps.
280 280
                 if (empty($hooks_to_fire_at_time)) {
281
-                    unset($crons[ $timestamp ]);
281
+                    unset($crons[$timestamp]);
282 282
                 }
283 283
             }
284 284
         }
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
             10,
318 318
             3
319 319
         );
320
-        if (! EE_Config::logging_enabled()) {
320
+        if ( ! EE_Config::logging_enabled()) {
321 321
             delete_option(EE_Config::LOG_NAME);
322 322
         }
323 323
     }
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
     public static function load_calendar_config()
330 330
     {
331 331
         // grab array of all plugin folders and loop thru it
332
-        $plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR);
332
+        $plugins = glob(WP_PLUGIN_DIR.'/*', GLOB_ONLYDIR);
333 333
         if (empty($plugins)) {
334 334
             return;
335 335
         }
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
                 || strpos($plugin, 'calendar') !== false
347 347
             ) {
348 348
                 // this is what we are looking for
349
-                $calendar_config = $plugin_path . '/EE_Calendar_Config.php';
349
+                $calendar_config = $plugin_path.'/EE_Calendar_Config.php';
350 350
                 // does it exist in this folder ?
351 351
                 if (is_readable($calendar_config)) {
352 352
                     // YEAH! let's load it
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
                 'code' => 'ESPRESSO_CANCELLED',
430 430
             ],
431 431
         ];
432
-        $EE_Core_Config        = EE_Registry::instance()->CFG->core;
432
+        $EE_Core_Config = EE_Registry::instance()->CFG->core;
433 433
         foreach ($critical_pages as $critical_page) {
434 434
             // is critical page ID set in config ?
435 435
             if ($EE_Core_Config->{$critical_page['id']} !== false) {
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
             ) {
462 462
                 // update Config with post ID
463 463
                 $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
464
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
464
+                if ( ! EE_Config::instance()->update_espresso_config(false, false)) {
465 465
                     $msg = esc_html__(
466 466
                         'The Event Espresso critical page configuration settings could not be updated.',
467 467
                         'event_espresso'
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
                         'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
485 485
                         'event_espresso'
486 486
                     ),
487
-                    '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
487
+                    '<a href="'.admin_url('admin.php?page=espresso_general_settings&action=critical_pages').'">'
488 488
                     . esc_html__('Event Espresso Critical Pages Settings', 'event_espresso')
489 489
                     . '</a>'
490 490
                 )
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
     public static function get_page_by_ee_shortcode($ee_shortcode)
510 510
     {
511 511
         global $wpdb;
512
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
512
+        $shortcode_and_opening_bracket = '['.$ee_shortcode;
513 513
         $post_id                       =
514 514
             $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
515 515
         if ($post_id) {
@@ -534,11 +534,11 @@  discard block
 block discarded – undo
534 534
             'post_status'    => 'publish',
535 535
             'post_type'      => 'page',
536 536
             'comment_status' => 'closed',
537
-            'post_content'   => '[' . $critical_page['code'] . ']',
537
+            'post_content'   => '['.$critical_page['code'].']',
538 538
         ];
539 539
 
540 540
         $post_id = wp_insert_post($post_args);
541
-        if (! $post_id) {
541
+        if ( ! $post_id) {
542 542
             $msg = sprintf(
543 543
                 esc_html__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
544 544
                 $critical_page['name']
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
             return $critical_page;
548 548
         }
549 549
         // get newly created post's details
550
-        if (! $critical_page['post'] = get_post($post_id)) {
550
+        if ( ! $critical_page['post'] = get_post($post_id)) {
551 551
             $msg = sprintf(
552 552
                 esc_html__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
553 553
                 $critical_page['name']
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
     public static function get_default_creator_id()
573 573
     {
574 574
         global $wpdb;
575
-        if (! empty(self::$_default_creator_id)) {
575
+        if ( ! empty(self::$_default_creator_id)) {
576 576
             return self::$_default_creator_id;
577 577
         }/**/
578 578
         $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
         $capabilities_key = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
589 589
         $query            = $wpdb->prepare(
590 590
             "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
591
-            '%' . $role_to_check . '%'
591
+            '%'.$role_to_check.'%'
592 592
         );
593 593
         $user_id          = $wpdb->get_var($query);
594 594
         $user_id          = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
@@ -625,8 +625,8 @@  discard block
 block discarded – undo
625 625
             return;
626 626
         }
627 627
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
628
-        if (! function_exists('dbDelta')) {
629
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
628
+        if ( ! function_exists('dbDelta')) {
629
+            require_once(ABSPATH.'wp-admin/includes/upgrade.php');
630 630
         }
631 631
         $tableAnalysis = EEH_Activation::getTableAnalysis();
632 632
         $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
@@ -635,9 +635,9 @@  discard block
 block discarded – undo
635 635
             // ok, delete the table... but ONLY if it's empty
636 636
             $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
637 637
             // table is NOT empty, are you SURE you want to delete this table ???
638
-            if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
638
+            if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
639 639
                 EEH_Activation::getTableManager()->dropTable($wp_table_name);
640
-            } elseif (! $deleted_safely) {
640
+            } elseif ( ! $deleted_safely) {
641 641
                 // so we should be more cautious rather than just dropping tables so easily
642 642
                 error_log(
643 643
                     sprintf(
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
         EE_Registry::instance()->load_core('Data_Migration_Manager');
759 759
         // find the migration script that sets the database to be compatible with the code
760 760
         $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
761
-        if (! $dms_name) {
761
+        if ( ! $dms_name) {
762 762
             EE_Error::add_error(
763 763
                 esc_html__(
764 764
                     'Could not determine most up-to-date data migration script from which to pull database schema
@@ -818,13 +818,13 @@  discard block
 block discarded – undo
818 818
             // reset values array
819 819
             $QSG_values = [];
820 820
             // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
821
-            if (! in_array("$QSG_system", $question_groups)) {
821
+            if ( ! in_array("$QSG_system", $question_groups)) {
822 822
                 // add it
823 823
                 switch ($QSG_system) {
824 824
                     case 1:
825 825
                         $QSG_values = [
826 826
                             'QSG_name'            => esc_html__('Personal Information', 'event_espresso'),
827
-                            'QSG_identifier'      => 'personal-information-' . time(),
827
+                            'QSG_identifier'      => 'personal-information-'.time(),
828 828
                             'QSG_desc'            => '',
829 829
                             'QSG_order'           => 1,
830 830
                             'QSG_show_group_name' => 1,
@@ -836,7 +836,7 @@  discard block
 block discarded – undo
836 836
                     case 2:
837 837
                         $QSG_values = [
838 838
                             'QSG_name'            => esc_html__('Address Information', 'event_espresso'),
839
-                            'QSG_identifier'      => 'address-information-' . time(),
839
+                            'QSG_identifier'      => 'address-information-'.time(),
840 840
                             'QSG_desc'            => '',
841 841
                             'QSG_order'           => 2,
842 842
                             'QSG_show_group_name' => 1,
@@ -847,14 +847,14 @@  discard block
 block discarded – undo
847 847
                         break;
848 848
                 }
849 849
                 // make sure we have some values before inserting them
850
-                if (! empty($QSG_values)) {
850
+                if ( ! empty($QSG_values)) {
851 851
                     // insert system question
852 852
                     $wpdb->insert(
853 853
                         $table_name,
854 854
                         $QSG_values,
855 855
                         ['%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d']
856 856
                     );
857
-                    $QSG_IDs[ $QSG_system ] = $wpdb->insert_id;
857
+                    $QSG_IDs[$QSG_system] = $wpdb->insert_id;
858 858
                 }
859 859
             }
860 860
         }
@@ -869,7 +869,7 @@  discard block
 block discarded – undo
869 869
         $address_system_group_questions  = ['address', 'address2', 'city', 'country', 'state', 'zip', 'phone'];
870 870
         $system_questions_not_in_group   = ['email_confirm'];
871 871
         // merge all of the system questions we should have
872
-        $QST_systems       = array_merge(
872
+        $QST_systems = array_merge(
873 873
             $personal_system_group_questions,
874 874
             $address_system_group_questions,
875 875
             $system_questions_not_in_group
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
             // reset values array
882 882
             $QST_values = [];
883 883
             // if we don't have what we should have
884
-            if (! in_array($QST_system, $questions)) {
884
+            if ( ! in_array($QST_system, $questions)) {
885 885
                 // add it
886 886
                 switch ($QST_system) {
887 887
                     case 'fname':
@@ -1057,7 +1057,7 @@  discard block
 block discarded – undo
1057 1057
                         ];
1058 1058
                         break;
1059 1059
                 }
1060
-                if (! empty($QST_values)) {
1060
+                if ( ! empty($QST_values)) {
1061 1061
                     // insert system question
1062 1062
                     $wpdb->insert(
1063 1063
                         $table_name,
@@ -1075,8 +1075,8 @@  discard block
 block discarded – undo
1075 1075
                         // QST_system should not be assigned to any group
1076 1076
                         continue;
1077 1077
                     }
1078
-                    if (isset($QSG_IDs[ $system_question_we_want ])) {
1079
-                        $QSG_ID = $QSG_IDs[ $system_question_we_want ];
1078
+                    if (isset($QSG_IDs[$system_question_we_want])) {
1079
+                        $QSG_ID = $QSG_IDs[$system_question_we_want];
1080 1080
                     } else {
1081 1081
                         $id_col = EEM_Question_Group::instance()
1082 1082
                                                     ->get_col([['QSG_system' => $system_question_we_want]]);
@@ -1125,7 +1125,7 @@  discard block
 block discarded – undo
1125 1125
      */
1126 1126
     public static function insert_default_payment_methods()
1127 1127
     {
1128
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1128
+        if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1129 1129
             EE_Registry::instance()->load_lib('Payment_Method_Manager');
1130 1130
             EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1131 1131
         } else {
@@ -1261,7 +1261,7 @@  discard block
 block discarded – undo
1261 1261
                         $active_messenger->name,
1262 1262
                         $default_message_type_name_for_messenger
1263 1263
                     )
1264
-                    || ! isset($installed_message_types[ $default_message_type_name_for_messenger ])
1264
+                    || ! isset($installed_message_types[$default_message_type_name_for_messenger])
1265 1265
                 ) {
1266 1266
                     continue;
1267 1267
                 }
@@ -1274,7 +1274,7 @@  discard block
 block discarded – undo
1274 1274
                 false
1275 1275
             );
1276 1276
             // activate the templates for these message types
1277
-            if (! empty($default_message_type_names_to_activate)) {
1277
+            if ( ! empty($default_message_type_names_to_activate)) {
1278 1278
                 $templates_created = EEH_MSG_Template::generate_new_templates(
1279 1279
                     $active_messenger->name,
1280 1280
                     $default_message_type_names_for_messenger,
@@ -1308,13 +1308,13 @@  discard block
 block discarded – undo
1308 1308
             // verify the default message types match an installed message type.
1309 1309
             foreach ($default_message_type_names_for_messenger as $key => $name) {
1310 1310
                 if (
1311
-                    ! isset($installed_message_types[ $name ])
1311
+                    ! isset($installed_message_types[$name])
1312 1312
                     || $message_resource_manager->has_message_type_been_activated_for_messenger(
1313 1313
                         $name,
1314 1314
                         $messenger_to_generate->name
1315 1315
                     )
1316 1316
                 ) {
1317
-                    unset($default_message_type_names_for_messenger[ $key ]);
1317
+                    unset($default_message_type_names_for_messenger[$key]);
1318 1318
                 }
1319 1319
             }
1320 1320
             // in previous iterations, the active_messengers option in the db
@@ -1328,7 +1328,7 @@  discard block
 block discarded – undo
1328 1328
                 false
1329 1329
             );
1330 1330
             // create any templates needing created (or will reactivate templates already generated as necessary).
1331
-            if (! empty($default_message_type_names_for_messenger)) {
1331
+            if ( ! empty($default_message_type_names_for_messenger)) {
1332 1332
                 $templates_generated = EEH_MSG_Template::generate_new_templates(
1333 1333
                     $messenger_to_generate->name,
1334 1334
                     $default_message_type_names_for_messenger,
@@ -1364,12 +1364,12 @@  discard block
 block discarded – undo
1364 1364
             // and has never been activated
1365 1365
             if (
1366 1366
                 ! $installed_messenger->activate_on_install
1367
-                || isset($active_messengers[ $installed_messenger->name ])
1368
-                || isset($has_activated[ $installed_messenger->name ])
1367
+                || isset($active_messengers[$installed_messenger->name])
1368
+                || isset($has_activated[$installed_messenger->name])
1369 1369
             ) {
1370 1370
                 continue;
1371 1371
             }
1372
-            $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger;
1372
+            $messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1373 1373
         }
1374 1374
         return $messengers_to_generate;
1375 1375
     }
@@ -1405,7 +1405,7 @@  discard block
 block discarded – undo
1405 1405
         // this creates an array for tracking events that have no active ticket prices created
1406 1406
         // this allows us to warn admins of the situation so that it can be corrected
1407 1407
         $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1408
-        if (! $espresso_no_ticket_prices) {
1408
+        if ( ! $espresso_no_ticket_prices) {
1409 1409
             add_option('ee_no_ticket_prices', [], '', false);
1410 1410
         }
1411 1411
     }
@@ -1440,7 +1440,7 @@  discard block
 block discarded – undo
1440 1440
             }
1441 1441
         }
1442 1442
         // get all our CPTs
1443
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1443
+        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")";
1444 1444
         $cpt_ids = $wpdb->get_col($query);
1445 1445
         // delete each post meta and term relations too
1446 1446
         foreach ($cpt_ids as $post_id) {
@@ -1472,7 +1472,7 @@  discard block
 block discarded – undo
1472 1472
                                 || ! $table->is_global()// not main site,but not global either. nuke it
1473 1473
                             )
1474 1474
                         ) {
1475
-                            $tables[ $table->get_table_name() ] = $table->get_table_name();
1475
+                            $tables[$table->get_table_name()] = $table->get_table_name();
1476 1476
                         }
1477 1477
                     }
1478 1478
                 }
@@ -1489,7 +1489,7 @@  discard block
 block discarded – undo
1489 1489
             'esp_rule',
1490 1490
         ];
1491 1491
         foreach ($tables_without_models as $table) {
1492
-            $tables[ $table ] = $table;
1492
+            $tables[$table] = $table;
1493 1493
         }
1494 1494
         return EEH_Activation::getTableManager()->dropTables($tables);
1495 1495
     }
@@ -1566,14 +1566,14 @@  discard block
 block discarded – undo
1566 1566
         $undeleted_options = [];
1567 1567
         foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1568 1568
             if ($no_wildcard) {
1569
-                if (! delete_option($option_name)) {
1569
+                if ( ! delete_option($option_name)) {
1570 1570
                     $undeleted_options[] = $option_name;
1571 1571
                 }
1572 1572
             } else {
1573 1573
                 $option_names_to_delete_from_wildcard =
1574 1574
                     $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1575 1575
                 foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1576
-                    if (! delete_option($option_name_from_wildcard)) {
1576
+                    if ( ! delete_option($option_name_from_wildcard)) {
1577 1577
                         $undeleted_options[] = $option_name_from_wildcard;
1578 1578
                     }
1579 1579
                 }
@@ -1585,20 +1585,20 @@  discard block
 block discarded – undo
1585 1585
             $db_update_sans_ee4 = [];
1586 1586
             foreach ($espresso_db_update as $version => $times_activated) {
1587 1587
                 if ((string) $version[0] === '3') {// if its NON EE4
1588
-                    $db_update_sans_ee4[ $version ] = $times_activated;
1588
+                    $db_update_sans_ee4[$version] = $times_activated;
1589 1589
                 }
1590 1590
             }
1591 1591
             update_option('espresso_db_update', $db_update_sans_ee4);
1592 1592
         }
1593 1593
         $errors = '';
1594
-        if (! empty($undeleted_options)) {
1594
+        if ( ! empty($undeleted_options)) {
1595 1595
             $errors .= sprintf(
1596 1596
                 esc_html__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1597 1597
                 '<br/>',
1598 1598
                 implode(',<br/>', $undeleted_options)
1599 1599
             );
1600 1600
         }
1601
-        if (! empty($errors)) {
1601
+        if ( ! empty($errors)) {
1602 1602
             EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1603 1603
         }
1604 1604
     }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Admin_Page.lib.php 2 patches
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -10,123 +10,123 @@
 block discarded – undo
10 10
  */
11 11
 class EE_Register_Admin_Page implements EEI_Plugin_API
12 12
 {
13
-    /**
14
-     * Holds registered EE_Admin_Pages
15
-     *
16
-     * @var array
17
-     */
18
-    protected static $_ee_admin_page_registry = [];
13
+	/**
14
+	 * Holds registered EE_Admin_Pages
15
+	 *
16
+	 * @var array
17
+	 */
18
+	protected static $_ee_admin_page_registry = [];
19 19
 
20 20
 
21
-    /**
22
-     * The purpose of this method is to provide an easy way for addons to register their admin pages (using the EE
23
-     * Admin Page loader system).
24
-     *
25
-     * @param string $addon_name                                      This string represents the basename of the Admin
26
-     *                                                                Page init. The init file must use this basename
27
-     *                                                                in its name and class (i.e.
28
-     *                                                                {page_basename}_Admin_Page_Init.core.php).
29
-     * @param array  $setup_args                                      {              An array of configuration options
30
-     *                                                                that will be used in different circumstances
31
-     *
32
-     * @type  string $page_path                                       This is the path where the registered admin pages
33
-     *        reside ( used to setup autoloaders).
34
-     *
35
-     *    }
36
-     * @return bool
37
-     * @throws EE_Error
38
-     * @since 4.3.0
39
-     *
40
-     */
41
-    public static function register(string $addon_name = '', array $setup_args = []): bool
42
-    {
21
+	/**
22
+	 * The purpose of this method is to provide an easy way for addons to register their admin pages (using the EE
23
+	 * Admin Page loader system).
24
+	 *
25
+	 * @param string $addon_name                                      This string represents the basename of the Admin
26
+	 *                                                                Page init. The init file must use this basename
27
+	 *                                                                in its name and class (i.e.
28
+	 *                                                                {page_basename}_Admin_Page_Init.core.php).
29
+	 * @param array  $setup_args                                      {              An array of configuration options
30
+	 *                                                                that will be used in different circumstances
31
+	 *
32
+	 * @type  string $page_path                                       This is the path where the registered admin pages
33
+	 *        reside ( used to setup autoloaders).
34
+	 *
35
+	 *    }
36
+	 * @return bool
37
+	 * @throws EE_Error
38
+	 * @since 4.3.0
39
+	 *
40
+	 */
41
+	public static function register(string $addon_name = '', array $setup_args = []): bool
42
+	{
43 43
 
44
-        // check that an admin_page has not already been registered with that name
45
-        if (isset(self::$_ee_admin_page_registry[ $addon_name ])) {
46
-            throw new EE_Error(
47
-                sprintf(
48
-                    esc_html__(
49
-                        'An Admin Page with the name "%s" has already been registered and each Admin Page requires a unique name.',
50
-                        'event_espresso'
51
-                    ),
52
-                    $addon_name
53
-                )
54
-            );
55
-        }
44
+		// check that an admin_page has not already been registered with that name
45
+		if (isset(self::$_ee_admin_page_registry[ $addon_name ])) {
46
+			throw new EE_Error(
47
+				sprintf(
48
+					esc_html__(
49
+						'An Admin Page with the name "%s" has already been registered and each Admin Page requires a unique name.',
50
+						'event_espresso'
51
+					),
52
+					$addon_name
53
+				)
54
+			);
55
+		}
56 56
 
57
-        // required fields MUST be present, so let's make sure they are.
58
-        if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['page_path'])) {
59
-            throw new EE_Error(
60
-                esc_html__(
61
-                    'In order to register an Admin Page with EE_Register_Admin_Page::register(), you must include the "page_basename" (the class name of the page), and an array containing the following keys: "page_path" (the path where the registered admin pages reside)',
62
-                    'event_espresso'
63
-                )
64
-            );
65
-        }
57
+		// required fields MUST be present, so let's make sure they are.
58
+		if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['page_path'])) {
59
+			throw new EE_Error(
60
+				esc_html__(
61
+					'In order to register an Admin Page with EE_Register_Admin_Page::register(), you must include the "page_basename" (the class name of the page), and an array containing the following keys: "page_path" (the path where the registered admin pages reside)',
62
+					'event_espresso'
63
+				)
64
+			);
65
+		}
66 66
 
67
-        // make sure we don't register twice
68
-        if (isset(self::$_ee_admin_page_registry[ $addon_name ])) {
69
-            return true;
70
-        }
67
+		// make sure we don't register twice
68
+		if (isset(self::$_ee_admin_page_registry[ $addon_name ])) {
69
+			return true;
70
+		}
71 71
 
72
-        if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) {
73
-            EE_Error::doing_it_wrong(
74
-                __METHOD__,
75
-                sprintf(
76
-                    esc_html__(
77
-                        'An attempt was made to register "%s" as an EE Admin page has failed because it was not registered at the correct time.  Please use the "AHEE__EE_Admin__loaded" hook to register Admin pages.',
78
-                        'event_espresso'
79
-                    ),
80
-                    $addon_name
81
-                ),
82
-                '4.3'
83
-            );
84
-        }
72
+		if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) {
73
+			EE_Error::doing_it_wrong(
74
+				__METHOD__,
75
+				sprintf(
76
+					esc_html__(
77
+						'An attempt was made to register "%s" as an EE Admin page has failed because it was not registered at the correct time.  Please use the "AHEE__EE_Admin__loaded" hook to register Admin pages.',
78
+						'event_espresso'
79
+					),
80
+					$addon_name
81
+				),
82
+				'4.3'
83
+			);
84
+		}
85 85
 
86
-        // add incoming stuff to our registry property
87
-        self::$_ee_admin_page_registry[ $addon_name ] = [
88
-            'page_path' => $setup_args['page_path'],
89
-            'config'    => $setup_args,
90
-        ];
86
+		// add incoming stuff to our registry property
87
+		self::$_ee_admin_page_registry[ $addon_name ] = [
88
+			'page_path' => $setup_args['page_path'],
89
+			'config'    => $setup_args,
90
+		];
91 91
 
92
-        // add filters
93
-        add_filter(
94
-            'FHEE__EE_Admin_Page_Loader__findAdminPages__admin_page_folders',
95
-            ['EE_Register_Admin_Page', 'set_page_path']
96
-        );
92
+		// add filters
93
+		add_filter(
94
+			'FHEE__EE_Admin_Page_Loader__findAdminPages__admin_page_folders',
95
+			['EE_Register_Admin_Page', 'set_page_path']
96
+		);
97 97
 
98
-        return true;
99
-    }
98
+		return true;
99
+	}
100 100
 
101 101
 
102
-    /**
103
-     * This deregisters a EE_Admin page that is already registered.  Note, this MUST be loaded after the
104
-     * page being deregistered is loaded.
105
-     *
106
-     * @param string $addon_name Use whatever string was used to register the admin page.
107
-     * @return  void
108
-     * @since    4.3.0
109
-     *
110
-     */
111
-    public static function deregister(string $addon_name = '')
112
-    {
113
-        unset(self::$_ee_admin_page_registry[ $addon_name ]);
114
-    }
102
+	/**
103
+	 * This deregisters a EE_Admin page that is already registered.  Note, this MUST be loaded after the
104
+	 * page being deregistered is loaded.
105
+	 *
106
+	 * @param string $addon_name Use whatever string was used to register the admin page.
107
+	 * @return  void
108
+	 * @since    4.3.0
109
+	 *
110
+	 */
111
+	public static function deregister(string $addon_name = '')
112
+	{
113
+		unset(self::$_ee_admin_page_registry[ $addon_name ]);
114
+	}
115 115
 
116 116
 
117
-    /**
118
-     * set_page_path
119
-     *
120
-     * @param array $paths
121
-     * @return mixed
122
-     * @throws EE_Error
123
-     */
124
-    public static function set_page_path(array $paths): array
125
-    {
126
-        foreach (self::$_ee_admin_page_registry as $basename => $args) {
127
-            EEH_Autoloader::register_autoloaders_for_each_file_in_folder($args['page_path']);
128
-            $paths[ $basename ] = $args['page_path'];
129
-        }
130
-        return $paths;
131
-    }
117
+	/**
118
+	 * set_page_path
119
+	 *
120
+	 * @param array $paths
121
+	 * @return mixed
122
+	 * @throws EE_Error
123
+	 */
124
+	public static function set_page_path(array $paths): array
125
+	{
126
+		foreach (self::$_ee_admin_page_registry as $basename => $args) {
127
+			EEH_Autoloader::register_autoloaders_for_each_file_in_folder($args['page_path']);
128
+			$paths[ $basename ] = $args['page_path'];
129
+		}
130
+		return $paths;
131
+	}
132 132
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
     {
43 43
 
44 44
         // check that an admin_page has not already been registered with that name
45
-        if (isset(self::$_ee_admin_page_registry[ $addon_name ])) {
45
+        if (isset(self::$_ee_admin_page_registry[$addon_name])) {
46 46
             throw new EE_Error(
47 47
                 sprintf(
48 48
                     esc_html__(
@@ -65,11 +65,11 @@  discard block
 block discarded – undo
65 65
         }
66 66
 
67 67
         // make sure we don't register twice
68
-        if (isset(self::$_ee_admin_page_registry[ $addon_name ])) {
68
+        if (isset(self::$_ee_admin_page_registry[$addon_name])) {
69 69
             return true;
70 70
         }
71 71
 
72
-        if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) {
72
+        if ( ! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) {
73 73
             EE_Error::doing_it_wrong(
74 74
                 __METHOD__,
75 75
                 sprintf(
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
         }
85 85
 
86 86
         // add incoming stuff to our registry property
87
-        self::$_ee_admin_page_registry[ $addon_name ] = [
87
+        self::$_ee_admin_page_registry[$addon_name] = [
88 88
             'page_path' => $setup_args['page_path'],
89 89
             'config'    => $setup_args,
90 90
         ];
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
      */
111 111
     public static function deregister(string $addon_name = '')
112 112
     {
113
-        unset(self::$_ee_admin_page_registry[ $addon_name ]);
113
+        unset(self::$_ee_admin_page_registry[$addon_name]);
114 114
     }
115 115
 
116 116
 
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
     {
126 126
         foreach (self::$_ee_admin_page_registry as $basename => $args) {
127 127
             EEH_Autoloader::register_autoloaders_for_each_file_in_folder($args['page_path']);
128
-            $paths[ $basename ] = $args['page_path'];
128
+            $paths[$basename] = $args['page_path'];
129 129
         }
130 130
         return $paths;
131 131
     }
Please login to merge, or discard this patch.
core/admin/EE_Admin.core.php 2 patches
Indentation   +999 added lines, -999 removed lines patch added patch discarded remove patch
@@ -20,1003 +20,1003 @@
 block discarded – undo
20 20
  */
21 21
 final class EE_Admin implements InterminableInterface
22 22
 {
23
-    /**
24
-     * @var EE_Admin $_instance
25
-     */
26
-    private static $_instance;
27
-
28
-    /**
29
-     * @var PersistentAdminNoticeManager $persistent_admin_notice_manager
30
-     */
31
-    private $persistent_admin_notice_manager;
32
-
33
-    /**
34
-     * @var LoaderInterface $loader
35
-     */
36
-    protected $loader;
37
-
38
-    /**
39
-     * @var RequestInterface
40
-     */
41
-    protected $request;
42
-
43
-
44
-    /**
45
-     * @singleton method used to instantiate class object
46
-     * @param LoaderInterface  $loader
47
-     * @param RequestInterface $request
48
-     * @return EE_Admin
49
-     * @throws EE_Error
50
-     */
51
-    public static function instance(LoaderInterface $loader = null, RequestInterface $request = null)
52
-    {
53
-        // check if class object is instantiated
54
-        if (! EE_Admin::$_instance instanceof EE_Admin) {
55
-            EE_Admin::$_instance = new EE_Admin($loader, $request);
56
-        }
57
-        return EE_Admin::$_instance;
58
-    }
59
-
60
-
61
-    /**
62
-     * @return EE_Admin
63
-     * @throws EE_Error
64
-     */
65
-    public static function reset()
66
-    {
67
-        EE_Admin::$_instance = null;
68
-        $loader = LoaderFactory::getLoader();
69
-        $request = $loader->getShared('EventEspresso\core\services\request\Request');
70
-        return EE_Admin::instance($loader, $request);
71
-    }
72
-
73
-
74
-    /**
75
-     * @param LoaderInterface  $loader
76
-     * @param RequestInterface $request
77
-     * @throws EE_Error
78
-     * @throws InvalidDataTypeException
79
-     * @throws InvalidInterfaceException
80
-     * @throws InvalidArgumentException
81
-     */
82
-    protected function __construct(LoaderInterface $loader, RequestInterface $request)
83
-    {
84
-        $this->loader = $loader;
85
-        $this->request = $request;
86
-        // define global EE_Admin constants
87
-        $this->_define_all_constants();
88
-        // set autoloaders for our admin page classes based on included path information
89
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_ADMIN);
90
-        // reset Environment config (we only do this on admin page loads);
91
-        EE_Registry::instance()->CFG->environment->recheck_values();
92
-        // load EE_Request_Handler early
93
-        add_action('AHEE__EE_System__initialize_last', [$this, 'init']);
94
-        add_action('admin_init', [$this, 'admin_init'], 100);
95
-        if (! $this->request->isAjax()) {
96
-            // admin hooks
97
-            add_action('admin_notices', [$this, 'display_admin_notices'], 10);
98
-            add_action('network_admin_notices', [$this, 'display_admin_notices'], 10);
99
-            add_filter('pre_update_option', [$this, 'check_for_invalid_datetime_formats'], 100, 2);
100
-            add_filter('plugin_action_links', [$this, 'filter_plugin_actions'], 10, 2);
101
-            add_filter('admin_footer_text', [$this, 'espresso_admin_footer']);
102
-            add_action('display_post_states', [$this, 'displayStateForCriticalPages'], 10, 2);
103
-            add_filter('plugin_row_meta', [$this, 'addLinksToPluginRowMeta'], 10, 2);
104
-        }
105
-        do_action('AHEE__EE_Admin__loaded');
106
-    }
107
-
108
-
109
-    /**
110
-     * _define_all_constants
111
-     * define constants that are set globally for all admin pages
112
-     *
113
-     * @return void
114
-     */
115
-    private function _define_all_constants()
116
-    {
117
-        if (! defined('EE_ADMIN_URL')) {
118
-            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
119
-            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
120
-            define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates/');
121
-            define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
122
-            define('WP_AJAX_URL', admin_url('admin-ajax.php'));
123
-        }
124
-    }
125
-
126
-
127
-    /**
128
-     * filter_plugin_actions - adds links to the Plugins page listing
129
-     *
130
-     * @param array  $links
131
-     * @param string $plugin
132
-     * @return    array
133
-     */
134
-    public function filter_plugin_actions($links, $plugin)
135
-    {
136
-        // set $main_file in stone
137
-        static $main_file;
138
-        // if $main_file is not set yet
139
-        if (! $main_file) {
140
-            $main_file = EE_PLUGIN_BASENAME;
141
-        }
142
-        if ($plugin === $main_file) {
143
-            // compare current plugin to this one
144
-            if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
145
-                $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"'
146
-                                    . ' title="Event Espresso is in maintenance mode.  Click this link to learn why.">'
147
-                                    . esc_html__('Maintenance Mode Active', 'event_espresso')
148
-                                    . '</a>';
149
-                array_unshift($links, $maintenance_link);
150
-            } else {
151
-                $org_settings_link = '<a href="admin.php?page=espresso_general_settings">'
152
-                                     . esc_html__('Settings', 'event_espresso')
153
-                                     . '</a>';
154
-                $events_link       = '<a href="admin.php?page=espresso_events">'
155
-                                     . esc_html__('Events', 'event_espresso')
156
-                                     . '</a>';
157
-                // add before other links
158
-                array_unshift($links, $org_settings_link, $events_link);
159
-            }
160
-        }
161
-        return $links;
162
-    }
163
-
164
-
165
-    /**
166
-     * hide_admin_pages_except_maintenance_mode
167
-     *
168
-     * @param array $admin_page_folder_names
169
-     * @return array
170
-     */
171
-    public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = [])
172
-    {
173
-        return [
174
-            'maintenance' => EE_ADMIN_PAGES . 'maintenance/',
175
-            'about'       => EE_ADMIN_PAGES . 'about/',
176
-            'support'     => EE_ADMIN_PAGES . 'support/',
177
-        ];
178
-    }
179
-
180
-
181
-    /**
182
-     * init- should fire after shortcode, module,  addon, other plugin (default priority), and even
183
-     * EE_Front_Controller's init phases have run
184
-     *
185
-     * @return void
186
-     * @throws EE_Error
187
-     * @throws InvalidArgumentException
188
-     * @throws InvalidDataTypeException
189
-     * @throws InvalidInterfaceException
190
-     * @throws ReflectionException
191
-     * @throws ServiceNotFoundException
192
-     */
193
-    public function init()
194
-    {
195
-        // only enable most of the EE_Admin IF we're not in full maintenance mode
196
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
197
-            $this->initModelsReady();
198
-        }
199
-        // run the admin page factory but ONLY if:
200
-        // - it is a regular non ajax admin request
201
-        // - we are doing an ee admin ajax request
202
-        if ($this->request->isAdmin() || $this->request->isAdminAjax() || $this->request->isActivation()) {
203
-            try {
204
-                // this loads the controller for the admin pages which will setup routing etc
205
-                $admin_page_loader = $this->loader->getShared('EE_Admin_Page_Loader', [$this->loader]);
206
-                /** @var EE_Admin_Page_Loader $admin_page_loader */
207
-                $admin_page_loader->init();
208
-            } catch (EE_Error $e) {
209
-                $e->get_error();
210
-            }
211
-        }
212
-        if ($this->request->isAjax()) {
213
-            return;
214
-        }
215
-        add_filter('content_save_pre', [$this, 'its_eSpresso'], 10, 1);
216
-        // make sure our CPTs and custom taxonomy metaboxes get shown for first time users
217
-        add_action('admin_head', [$this, 'enable_hidden_ee_nav_menu_metaboxes'], 10);
218
-        add_action('admin_head', [$this, 'register_custom_nav_menu_boxes'], 10);
219
-        // exclude EE critical pages from all nav menus and wp_list_pages
220
-        add_filter('nav_menu_meta_box_object', [$this, 'remove_pages_from_nav_menu'], 10);
221
-    }
222
-
223
-
224
-    /**
225
-     * Gets the loader (and if it wasn't previously set, sets it)
226
-     *
227
-     * @return LoaderInterface
228
-     * @throws InvalidArgumentException
229
-     * @throws InvalidDataTypeException
230
-     * @throws InvalidInterfaceException
231
-     */
232
-    protected function getLoader()
233
-    {
234
-        return $this->loader;
235
-    }
236
-
237
-
238
-    /**
239
-     * Method that's fired on admin requests (including admin ajax) but only when the models are usable
240
-     * (ie, the site isn't in maintenance mode)
241
-     *
242
-     * @return void
243
-     * @throws EE_Error
244
-     * @since 4.9.63.p
245
-     */
246
-    protected function initModelsReady()
247
-    {
248
-        // ok so we want to enable the entire admin
249
-        $this->persistent_admin_notice_manager = $this->loader->getShared(
250
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
251
-        );
252
-        $this->persistent_admin_notice_manager->setReturnUrl(
253
-            EE_Admin_Page::add_query_args_and_nonce(
254
-                [
255
-                    'page'   => $this->request->getRequestParam('page', ''),
256
-                    'action' => $this->request->getRequestParam('action', ''),
257
-                ],
258
-                EE_ADMIN_URL
259
-            )
260
-        );
261
-        $this->maybeSetDatetimeWarningNotice();
262
-        // at a glance dashboard widget
263
-        add_filter('dashboard_glance_items', [$this, 'dashboard_glance_items'], 10);
264
-        // filter for get_edit_post_link used on comments for custom post types
265
-        add_filter('get_edit_post_link', [$this, 'modify_edit_post_link'], 10, 2);
266
-    }
267
-
268
-
269
-    /**
270
-     *    get_persistent_admin_notices
271
-     *
272
-     * @access    public
273
-     * @return void
274
-     * @throws EE_Error
275
-     * @throws InvalidArgumentException
276
-     * @throws InvalidDataTypeException
277
-     * @throws InvalidInterfaceException
278
-     */
279
-    public function maybeSetDatetimeWarningNotice()
280
-    {
281
-        // add dismissible notice for datetime changes.  Only valid if site does not have a timezone_string set.
282
-        // @todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version
283
-        // with this.  But after enough time (indeterminate at this point) we can just remove this notice.
284
-        // this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626
285
-        if (
286
-            apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true)
287
-            && ! get_option('timezone_string')
288
-            && EEM_Event::instance()->count() > 0
289
-        ) {
290
-            new PersistentAdminNotice(
291
-                'datetime_fix_notice',
292
-                sprintf(
293
-                    esc_html__(
294
-                        '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times.  Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.',
295
-                        'event_espresso'
296
-                    ),
297
-                    '<strong>',
298
-                    '</strong>',
299
-                    '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
300
-                    '</a>',
301
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
302
-                        [
303
-                            'page'   => 'espresso_maintenance_settings',
304
-                            'action' => 'datetime_tools',
305
-                        ],
306
-                        admin_url('admin.php')
307
-                    ) . '">'
308
-                ),
309
-                false,
310
-                'manage_options',
311
-                'datetime_fix_persistent_notice'
312
-            );
313
-        }
314
-    }
315
-
316
-
317
-    /**
318
-     * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
319
-     * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
320
-     * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
321
-     * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
322
-     * normal property on the post_type object.  It's found ONLY in this particular context.
323
-     *
324
-     * @param WP_Post $post_type WP post type object
325
-     * @return WP_Post
326
-     * @throws InvalidArgumentException
327
-     * @throws InvalidDataTypeException
328
-     * @throws InvalidInterfaceException
329
-     */
330
-    public function remove_pages_from_nav_menu($post_type)
331
-    {
332
-        // if this isn't the "pages" post type let's get out
333
-        if ($post_type->name !== 'page') {
334
-            return $post_type;
335
-        }
336
-        $critical_pages            = EE_Registry::instance()->CFG->core->get_critical_pages_array();
337
-        $post_type->_default_query = [
338
-            'post__not_in' => $critical_pages,
339
-        ];
340
-        return $post_type;
341
-    }
342
-
343
-
344
-    /**
345
-     * WP by default only shows three metaboxes in "nav-menus.php" for first times users.
346
-     * We want to make sure our metaboxes get shown as well
347
-     *
348
-     * @return void
349
-     */
350
-    public function enable_hidden_ee_nav_menu_metaboxes()
351
-    {
352
-        global $wp_meta_boxes, $pagenow;
353
-        if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
354
-            return;
355
-        }
356
-        $user = wp_get_current_user();
357
-        // has this been done yet?
358
-        if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
359
-            return;
360
-        }
361
-
362
-        $hidden_meta_boxes  = get_user_option('metaboxhidden_nav-menus', $user->ID);
363
-        $initial_meta_boxes = apply_filters(
364
-            'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
365
-            [
366
-                'nav-menu-theme-locations',
367
-                'add-page',
368
-                'add-custom-links',
369
-                'add-category',
370
-                'add-espresso_events',
371
-                'add-espresso_venues',
372
-                'add-espresso_event_categories',
373
-                'add-espresso_venue_categories',
374
-                'add-post-type-post',
375
-                'add-post-type-page',
376
-            ]
377
-        );
378
-
379
-        if (is_array($hidden_meta_boxes)) {
380
-            foreach ($hidden_meta_boxes as $key => $meta_box_id) {
381
-                if (in_array($meta_box_id, $initial_meta_boxes, true)) {
382
-                    unset($hidden_meta_boxes[ $key ]);
383
-                }
384
-            }
385
-        }
386
-        update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
387
-        update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
388
-    }
389
-
390
-
391
-    /**
392
-     * This method simply registers custom nav menu boxes for "nav_menus.php route"
393
-     * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
394
-     *
395
-     * @return void
396
-     * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
397
-     *         addons etc.
398
-     */
399
-    public function register_custom_nav_menu_boxes()
400
-    {
401
-        add_meta_box(
402
-            'add-extra-nav-menu-pages',
403
-            esc_html__('Event Espresso Pages', 'event_espresso'),
404
-            [$this, 'ee_cpt_archive_pages'],
405
-            'nav-menus',
406
-            'side',
407
-            'core'
408
-        );
409
-        add_filter(
410
-            "postbox_classes_nav-menus_add-extra-nav-menu-pages",
411
-            function ($classes) {
412
-                array_push($classes, 'ee-admin-container');
413
-                return $classes;
414
-            }
415
-        );
416
-    }
417
-
418
-
419
-    /**
420
-     * Use this to edit the post link for our cpts so that the edit link points to the correct page.
421
-     *
422
-     * @param string $link the original link generated by wp
423
-     * @param int    $id   post id
424
-     * @return string  the (maybe) modified link
425
-     * @since   4.3.0
426
-     */
427
-    public function modify_edit_post_link($link, $id)
428
-    {
429
-        if (! $post = get_post($id)) {
430
-            return $link;
431
-        }
432
-        if ($post->post_type === 'espresso_attendees') {
433
-            $query_args = [
434
-                'action' => 'edit_attendee',
435
-                'post'   => $id,
436
-            ];
437
-            return EEH_URL::add_query_args_and_nonce(
438
-                $query_args,
439
-                admin_url('admin.php?page=espresso_registrations')
440
-            );
441
-        }
442
-        return $link;
443
-    }
444
-
445
-
446
-    public function ee_cpt_archive_pages()
447
-    {
448
-        global $nav_menu_selected_id;
449
-        $removed_args = [
450
-            'action',
451
-            'customlink-tab',
452
-            'edit-menu-item',
453
-            'menu-item',
454
-            'page-tab',
455
-            '_wpnonce',
456
-        ];
457
-        $nav_tab_link = $nav_menu_selected_id
458
-            ? esc_url(
459
-                add_query_arg(
460
-                    'extra-nav-menu-pages-tab',
461
-                    'event-archives',
462
-                    remove_query_arg($removed_args)
463
-                )
464
-            )
465
-            : '';
466
-        $select_all_link = esc_url(
467
-            add_query_arg(
468
-                [
469
-                    'extra-nav-menu-pages-tab' => 'event-archives',
470
-                    'selectall'                => 1,
471
-                ],
472
-                remove_query_arg($removed_args)
473
-            )
474
-        );
475
-        $pages = $this->_get_extra_nav_menu_pages_items();
476
-        $args['walker'] = new Walker_Nav_Menu_Checklist(false);
477
-        ;
478
-        $nav_menu_pages_items = walk_nav_menu_tree(
479
-            array_map(
480
-                [$this, '_setup_extra_nav_menu_pages_items'],
481
-                $pages
482
-            ),
483
-            0,
484
-            (object) $args
485
-        );
486
-
487
-        EEH_Template::display_template(
488
-            EE_ADMIN_TEMPLATE . 'cpt_archive_page.template.php',
489
-            [
490
-                $nav_menu_pages_items,
491
-                $nav_tab_link,
492
-                $select_all_link,
493
-            ]
494
-        );
495
-    }
496
-
497
-
498
-    /**
499
-     * Returns an array of event archive nav items.
500
-     *
501
-     * @return array
502
-     * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
503
-     *        method we use for getting the extra nav menu items
504
-     */
505
-    private function _get_extra_nav_menu_pages_items()
506
-    {
507
-        $menuitems[] = [
508
-            'title'       => esc_html__('Event List', 'event_espresso'),
509
-            'url'         => get_post_type_archive_link('espresso_events'),
510
-            'description' => esc_html__('Archive page for all events.', 'event_espresso'),
511
-        ];
512
-        return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
513
-    }
514
-
515
-
516
-    /**
517
-     * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
518
-     * the properties and converts it to the menu item object.
519
-     *
520
-     * @param $menu_item_values
521
-     * @return stdClass
522
-     * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
523
-     */
524
-    private function _setup_extra_nav_menu_pages_items($menu_item_values)
525
-    {
526
-        $menu_item = new stdClass();
527
-        $keys      = [
528
-            'ID'               => 0,
529
-            'db_id'            => 0,
530
-            'menu_item_parent' => 0,
531
-            'object_id'        => -1,
532
-            'post_parent'      => 0,
533
-            'type'             => 'custom',
534
-            'object'           => '',
535
-            'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
536
-            'title'            => '',
537
-            'url'              => '',
538
-            'target'           => '',
539
-            'attr_title'       => '',
540
-            'description'      => '',
541
-            'classes'          => [],
542
-            'xfn'              => '',
543
-        ];
544
-
545
-        foreach ($keys as $key => $value) {
546
-            $menu_item->{$key} = isset($menu_item_values[ $key ]) ? $menu_item_values[ $key ] : $value;
547
-        }
548
-        return $menu_item;
549
-    }
550
-
551
-
552
-    /**
553
-     * admin_init
554
-     *
555
-     * @return void
556
-     * @throws InvalidArgumentException
557
-     * @throws InvalidDataTypeException
558
-     * @throws InvalidInterfaceException
559
-     */
560
-    public function admin_init()
561
-    {
562
-        /**
563
-         * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
564
-         * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
565
-         * - check if doing post processing.
566
-         * - check if doing post processing of one of EE CPTs
567
-         * - instantiate the corresponding EE CPT model for the post_type being processed.
568
-         */
569
-        $action    = $this->request->getRequestParam('action');
570
-        $post_type = $this->request->getRequestParam('post_type');
571
-        if ($post_type && $action === 'editpost') {
572
-            /** @var CustomPostTypeDefinitions $custom_post_types */
573
-            $custom_post_types = $this->loader->getShared(CustomPostTypeDefinitions::class);
574
-            $custom_post_types->getCustomPostTypeModels($post_type);
575
-        }
576
-
577
-
578
-        if (! $this->request->isAjax()) {
579
-            /**
580
-             * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
581
-             * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
582
-             * Pages" tab in the EE General Settings Admin page.
583
-             * This is for user-proofing.
584
-             */
585
-            add_filter('wp_dropdown_pages', [$this, 'modify_dropdown_pages']);
586
-            if (EE_Maintenance_Mode::instance()->models_can_query()) {
587
-                $this->adminInitModelsReady();
588
-            }
589
-        }
590
-    }
591
-
592
-
593
-    /**
594
-     * Runs on admin_init but only if models are usable (ie, we're not in maintenance mode)
595
-     */
596
-    protected function adminInitModelsReady()
597
-    {
598
-        if (function_exists('wp_add_privacy_policy_content')) {
599
-            $this->loader->getShared('EventEspresso\core\services\privacy\policy\PrivacyPolicyManager');
600
-        }
601
-    }
602
-
603
-
604
-    /**
605
-     * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
606
-     *
607
-     * @param string $output Current output.
608
-     * @return string
609
-     * @throws InvalidArgumentException
610
-     * @throws InvalidDataTypeException
611
-     * @throws InvalidInterfaceException
612
-     */
613
-    public function modify_dropdown_pages($output)
614
-    {
615
-        // get critical pages
616
-        $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
617
-
618
-        // split current output by line break for easier parsing.
619
-        $split_output = explode("\n", $output);
620
-
621
-        // loop through to remove any critical pages from the array.
622
-        foreach ($critical_pages as $page_id) {
623
-            $needle = 'value="' . $page_id . '"';
624
-            foreach ($split_output as $key => $haystack) {
625
-                if (strpos($haystack, $needle) !== false) {
626
-                    unset($split_output[ $key ]);
627
-                }
628
-            }
629
-        }
630
-        // replace output with the new contents
631
-        return implode("\n", $split_output);
632
-    }
633
-
634
-
635
-    /**
636
-     * display_admin_notices
637
-     *
638
-     * @return void
639
-     */
640
-    public function display_admin_notices()
641
-    {
642
-        echo EE_Error::get_notices(); // already escaped
643
-    }
644
-
645
-
646
-    /**
647
-     * @param array $elements
648
-     * @return array
649
-     * @throws EE_Error
650
-     * @throws InvalidArgumentException
651
-     * @throws InvalidDataTypeException
652
-     * @throws InvalidInterfaceException
653
-     */
654
-    public function dashboard_glance_items($elements)
655
-    {
656
-        $elements                        = is_array($elements) ? $elements : [$elements];
657
-        $events                          = EEM_Event::instance()->count();
658
-        $items['events']['url']          = EE_Admin_Page::add_query_args_and_nonce(
659
-            ['page' => 'espresso_events'],
660
-            admin_url('admin.php')
661
-        );
662
-        $items['events']['text']         = sprintf(
663
-            esc_html(
664
-                _n('%s Event', '%s Events', $events, 'event_espresso')
665
-            ),
666
-            number_format_i18n($events)
667
-        );
668
-        $items['events']['title']        = esc_html__('Click to view all Events', 'event_espresso');
669
-        $registrations                   = EEM_Registration::instance()->count(
670
-            [
671
-                [
672
-                    'STS_ID' => ['!=', EEM_Registration::status_id_incomplete],
673
-                ],
674
-            ]
675
-        );
676
-        $items['registrations']['url']   = EE_Admin_Page::add_query_args_and_nonce(
677
-            ['page' => 'espresso_registrations'],
678
-            admin_url('admin.php')
679
-        );
680
-        $items['registrations']['text']  = sprintf(
681
-            esc_html(
682
-                _n('%s Registration', '%s Registrations', $registrations, 'event_espresso')
683
-            ),
684
-            number_format_i18n($registrations)
685
-        );
686
-        $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
687
-
688
-        $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
689
-
690
-        foreach ($items as $type => $item_properties) {
691
-            $elements[] = sprintf(
692
-                '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
693
-                $item_properties['url'],
694
-                $item_properties['title'],
695
-                $item_properties['text']
696
-            );
697
-        }
698
-        return $elements;
699
-    }
700
-
701
-
702
-    /**
703
-     * check_for_invalid_datetime_formats
704
-     * if an admin changes their date or time format settings on the WP General Settings admin page, verify that
705
-     * their selected format can be parsed by PHP
706
-     *
707
-     * @param    $value
708
-     * @param    $option
709
-     * @return    string
710
-     */
711
-    public function check_for_invalid_datetime_formats($value, $option)
712
-    {
713
-        // check for date_format or time_format
714
-        switch ($option) {
715
-            case 'date_format':
716
-                $date_time_format = $value . ' ' . get_option('time_format');
717
-                break;
718
-            case 'time_format':
719
-                $date_time_format = get_option('date_format') . ' ' . $value;
720
-                break;
721
-            default:
722
-                $date_time_format = false;
723
-        }
724
-        // do we have a date_time format to check ?
725
-        if ($date_time_format) {
726
-            $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
727
-
728
-            if (is_array($error_msg)) {
729
-                $msg = '<p>'
730
-                       . sprintf(
731
-                           esc_html__(
732
-                               'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
733
-                               'event_espresso'
734
-                           ),
735
-                           date($date_time_format),
736
-                           $date_time_format
737
-                       )
738
-                       . '</p><p><ul>';
739
-
740
-
741
-                foreach ($error_msg as $error) {
742
-                    $msg .= '<li>' . $error . '</li>';
743
-                }
744
-
745
-                $msg .= '</ul></p><p>'
746
-                        . sprintf(
747
-                            esc_html__(
748
-                                '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
749
-                                'event_espresso'
750
-                            ),
751
-                            '<span style="color:#D54E21;">',
752
-                            '</span>'
753
-                        )
754
-                        . '</p>';
755
-
756
-                // trigger WP settings error
757
-                add_settings_error(
758
-                    'date_format',
759
-                    'date_format',
760
-                    $msg
761
-                );
762
-
763
-                // set format to something valid
764
-                switch ($option) {
765
-                    case 'date_format':
766
-                        $value = 'F j, Y';
767
-                        break;
768
-                    case 'time_format':
769
-                        $value = 'g:i a';
770
-                        break;
771
-                }
772
-            }
773
-        }
774
-        return $value;
775
-    }
776
-
777
-
778
-    /**
779
-     * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
780
-     *
781
-     * @param $content
782
-     * @return    string
783
-     */
784
-    public function its_eSpresso($content)
785
-    {
786
-        return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
787
-    }
788
-
789
-
790
-    /**
791
-     * espresso_admin_footer
792
-     *
793
-     * @return    string
794
-     */
795
-    public function espresso_admin_footer()
796
-    {
797
-        return EEH_Template::powered_by_event_espresso('aln-cntr', '', ['utm_content' => 'admin_footer']);
798
-    }
799
-
800
-
801
-    /**
802
-     * Hooks into the "post states" filter in a wp post type list table.
803
-     *
804
-     * @param array   $post_states
805
-     * @param WP_Post $post
806
-     * @return array
807
-     * @throws InvalidArgumentException
808
-     * @throws InvalidDataTypeException
809
-     * @throws InvalidInterfaceException
810
-     */
811
-    public function displayStateForCriticalPages($post_states, $post)
812
-    {
813
-        $post_states = (array) $post_states;
814
-        if (! $post instanceof WP_Post || $post->post_type !== 'page') {
815
-            return $post_states;
816
-        }
817
-        /** @var EE_Core_Config $config */
818
-        $config = $this->loader->getShared('EE_Config')->core;
819
-        if (in_array($post->ID, $config->get_critical_pages_array(), true)) {
820
-            $post_states[] = sprintf(
821
-            /* Translators: Using company name - Event Espresso Critical Page */
822
-                esc_html__('%s Critical Page', 'event_espresso'),
823
-                'Event Espresso'
824
-            );
825
-        }
826
-        return $post_states;
827
-    }
828
-
829
-
830
-    /**
831
-     * Show documentation links on the plugins page
832
-     *
833
-     * @param mixed $meta Plugin Row Meta
834
-     * @param mixed $file Plugin Base file
835
-     * @return array
836
-     */
837
-    public function addLinksToPluginRowMeta($meta, $file)
838
-    {
839
-        if (EE_PLUGIN_BASENAME === $file) {
840
-            $row_meta = [
841
-                'docs' => '<a href="https://eventespresso.com/support/documentation/versioned-docs/?doc_ver=ee4"'
842
-                          . ' aria-label="'
843
-                          . esc_attr__('View Event Espresso documentation', 'event_espresso')
844
-                          . '">'
845
-                          . esc_html__('Docs', 'event_espresso')
846
-                          . '</a>',
847
-                'api'  => '<a href="https://github.com/eventespresso/event-espresso-core/tree/master/docs/C--REST-API"'
848
-                          . ' aria-label="'
849
-                          . esc_attr__('View Event Espresso API docs', 'event_espresso')
850
-                          . '">'
851
-                          . esc_html__('API docs', 'event_espresso')
852
-                          . '</a>',
853
-            ];
854
-            return array_merge($meta, $row_meta);
855
-        }
856
-        return (array) $meta;
857
-    }
858
-
859
-     /**************************************************************************************/
860
-     /************************************* DEPRECATED *************************************/
861
-     /**************************************************************************************/
862
-
863
-
864
-    /**
865
-     * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
866
-     * EE_Admin_Page route is called.
867
-     *
868
-     * @return void
869
-     */
870
-    public function route_admin_request()
871
-    {
872
-    }
873
-
874
-
875
-    /**
876
-     * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
877
-     *
878
-     * @return void
879
-     */
880
-    public function wp_loaded()
881
-    {
882
-    }
883
-
884
-
885
-    /**
886
-     * static method for registering ee admin page.
887
-     * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
888
-     *
889
-     * @param       $page_basename
890
-     * @param       $page_path
891
-     * @param array $config
892
-     * @return void
893
-     * @throws EE_Error
894
-     * @see        EE_Register_Admin_Page::register()
895
-     * @since      4.3.0
896
-     * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
897
-     */
898
-    public static function register_ee_admin_page($page_basename, $page_path, $config = [])
899
-    {
900
-        EE_Error::doing_it_wrong(
901
-            __METHOD__,
902
-            sprintf(
903
-                esc_html__(
904
-                    'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
905
-                    'event_espresso'
906
-                ),
907
-                $page_basename
908
-            ),
909
-            '4.3'
910
-        );
911
-        if (class_exists('EE_Register_Admin_Page')) {
912
-            $config['page_path'] = $page_path;
913
-        }
914
-        EE_Register_Admin_Page::register($page_basename, $config);
915
-    }
916
-
917
-
918
-    /**
919
-     * @param int      $post_ID
920
-     * @param \WP_Post $post
921
-     * @return void
922
-     * @deprecated 4.8.41
923
-     */
924
-    public static function parse_post_content_on_save($post_ID, $post)
925
-    {
926
-        EE_Error::doing_it_wrong(
927
-            __METHOD__,
928
-            esc_html__('Usage is deprecated', 'event_espresso'),
929
-            '4.8.41'
930
-        );
931
-    }
932
-
933
-
934
-    /**
935
-     * @param  $option
936
-     * @param  $old_value
937
-     * @param  $value
938
-     * @return void
939
-     * @deprecated 4.8.41
940
-     */
941
-    public function reset_page_for_posts_on_change($option, $old_value, $value)
942
-    {
943
-        EE_Error::doing_it_wrong(
944
-            __METHOD__,
945
-            esc_html__('Usage is deprecated', 'event_espresso'),
946
-            '4.8.41'
947
-        );
948
-    }
949
-
950
-
951
-    /**
952
-     * @return void
953
-     * @deprecated 4.9.27
954
-     */
955
-    public function get_persistent_admin_notices()
956
-    {
957
-        EE_Error::doing_it_wrong(
958
-            __METHOD__,
959
-            sprintf(
960
-                esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
961
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
962
-            ),
963
-            '4.9.27'
964
-        );
965
-    }
966
-
967
-
968
-    /**
969
-     * @throws InvalidInterfaceException
970
-     * @throws InvalidDataTypeException
971
-     * @throws DomainException
972
-     * @deprecated 4.9.27
973
-     */
974
-    public function dismiss_ee_nag_notice_callback()
975
-    {
976
-        EE_Error::doing_it_wrong(
977
-            __METHOD__,
978
-            sprintf(
979
-                esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
980
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
981
-            ),
982
-            '4.9.27'
983
-        );
984
-        $this->persistent_admin_notice_manager->dismissNotice();
985
-    }
986
-
987
-
988
-    /**
989
-     * @return void
990
-     * @deprecated $VID:$
991
-     */
992
-    public function enqueue_admin_scripts()
993
-    {
994
-    }
995
-
996
-
997
-
998
-    /**
999
-     * @return RequestInterface
1000
-     * @deprecated $VID:$
1001
-     */
1002
-    public function get_request()
1003
-    {
1004
-        EE_Error::doing_it_wrong(
1005
-            __METHOD__,
1006
-            sprintf(
1007
-                esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1008
-                'EventEspresso\core\services\request\Request'
1009
-            ),
1010
-            '$VID:$'
1011
-        );
1012
-        return $this->request;
1013
-    }
1014
-
1015
-
1016
-    /**
1017
-     * @deprecated $VID:$
1018
-     */
1019
-    public function hookIntoWpPluginsPage()
1020
-    {
1021
-    }
23
+	/**
24
+	 * @var EE_Admin $_instance
25
+	 */
26
+	private static $_instance;
27
+
28
+	/**
29
+	 * @var PersistentAdminNoticeManager $persistent_admin_notice_manager
30
+	 */
31
+	private $persistent_admin_notice_manager;
32
+
33
+	/**
34
+	 * @var LoaderInterface $loader
35
+	 */
36
+	protected $loader;
37
+
38
+	/**
39
+	 * @var RequestInterface
40
+	 */
41
+	protected $request;
42
+
43
+
44
+	/**
45
+	 * @singleton method used to instantiate class object
46
+	 * @param LoaderInterface  $loader
47
+	 * @param RequestInterface $request
48
+	 * @return EE_Admin
49
+	 * @throws EE_Error
50
+	 */
51
+	public static function instance(LoaderInterface $loader = null, RequestInterface $request = null)
52
+	{
53
+		// check if class object is instantiated
54
+		if (! EE_Admin::$_instance instanceof EE_Admin) {
55
+			EE_Admin::$_instance = new EE_Admin($loader, $request);
56
+		}
57
+		return EE_Admin::$_instance;
58
+	}
59
+
60
+
61
+	/**
62
+	 * @return EE_Admin
63
+	 * @throws EE_Error
64
+	 */
65
+	public static function reset()
66
+	{
67
+		EE_Admin::$_instance = null;
68
+		$loader = LoaderFactory::getLoader();
69
+		$request = $loader->getShared('EventEspresso\core\services\request\Request');
70
+		return EE_Admin::instance($loader, $request);
71
+	}
72
+
73
+
74
+	/**
75
+	 * @param LoaderInterface  $loader
76
+	 * @param RequestInterface $request
77
+	 * @throws EE_Error
78
+	 * @throws InvalidDataTypeException
79
+	 * @throws InvalidInterfaceException
80
+	 * @throws InvalidArgumentException
81
+	 */
82
+	protected function __construct(LoaderInterface $loader, RequestInterface $request)
83
+	{
84
+		$this->loader = $loader;
85
+		$this->request = $request;
86
+		// define global EE_Admin constants
87
+		$this->_define_all_constants();
88
+		// set autoloaders for our admin page classes based on included path information
89
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_ADMIN);
90
+		// reset Environment config (we only do this on admin page loads);
91
+		EE_Registry::instance()->CFG->environment->recheck_values();
92
+		// load EE_Request_Handler early
93
+		add_action('AHEE__EE_System__initialize_last', [$this, 'init']);
94
+		add_action('admin_init', [$this, 'admin_init'], 100);
95
+		if (! $this->request->isAjax()) {
96
+			// admin hooks
97
+			add_action('admin_notices', [$this, 'display_admin_notices'], 10);
98
+			add_action('network_admin_notices', [$this, 'display_admin_notices'], 10);
99
+			add_filter('pre_update_option', [$this, 'check_for_invalid_datetime_formats'], 100, 2);
100
+			add_filter('plugin_action_links', [$this, 'filter_plugin_actions'], 10, 2);
101
+			add_filter('admin_footer_text', [$this, 'espresso_admin_footer']);
102
+			add_action('display_post_states', [$this, 'displayStateForCriticalPages'], 10, 2);
103
+			add_filter('plugin_row_meta', [$this, 'addLinksToPluginRowMeta'], 10, 2);
104
+		}
105
+		do_action('AHEE__EE_Admin__loaded');
106
+	}
107
+
108
+
109
+	/**
110
+	 * _define_all_constants
111
+	 * define constants that are set globally for all admin pages
112
+	 *
113
+	 * @return void
114
+	 */
115
+	private function _define_all_constants()
116
+	{
117
+		if (! defined('EE_ADMIN_URL')) {
118
+			define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
119
+			define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
120
+			define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates/');
121
+			define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
122
+			define('WP_AJAX_URL', admin_url('admin-ajax.php'));
123
+		}
124
+	}
125
+
126
+
127
+	/**
128
+	 * filter_plugin_actions - adds links to the Plugins page listing
129
+	 *
130
+	 * @param array  $links
131
+	 * @param string $plugin
132
+	 * @return    array
133
+	 */
134
+	public function filter_plugin_actions($links, $plugin)
135
+	{
136
+		// set $main_file in stone
137
+		static $main_file;
138
+		// if $main_file is not set yet
139
+		if (! $main_file) {
140
+			$main_file = EE_PLUGIN_BASENAME;
141
+		}
142
+		if ($plugin === $main_file) {
143
+			// compare current plugin to this one
144
+			if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
145
+				$maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"'
146
+									. ' title="Event Espresso is in maintenance mode.  Click this link to learn why.">'
147
+									. esc_html__('Maintenance Mode Active', 'event_espresso')
148
+									. '</a>';
149
+				array_unshift($links, $maintenance_link);
150
+			} else {
151
+				$org_settings_link = '<a href="admin.php?page=espresso_general_settings">'
152
+									 . esc_html__('Settings', 'event_espresso')
153
+									 . '</a>';
154
+				$events_link       = '<a href="admin.php?page=espresso_events">'
155
+									 . esc_html__('Events', 'event_espresso')
156
+									 . '</a>';
157
+				// add before other links
158
+				array_unshift($links, $org_settings_link, $events_link);
159
+			}
160
+		}
161
+		return $links;
162
+	}
163
+
164
+
165
+	/**
166
+	 * hide_admin_pages_except_maintenance_mode
167
+	 *
168
+	 * @param array $admin_page_folder_names
169
+	 * @return array
170
+	 */
171
+	public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = [])
172
+	{
173
+		return [
174
+			'maintenance' => EE_ADMIN_PAGES . 'maintenance/',
175
+			'about'       => EE_ADMIN_PAGES . 'about/',
176
+			'support'     => EE_ADMIN_PAGES . 'support/',
177
+		];
178
+	}
179
+
180
+
181
+	/**
182
+	 * init- should fire after shortcode, module,  addon, other plugin (default priority), and even
183
+	 * EE_Front_Controller's init phases have run
184
+	 *
185
+	 * @return void
186
+	 * @throws EE_Error
187
+	 * @throws InvalidArgumentException
188
+	 * @throws InvalidDataTypeException
189
+	 * @throws InvalidInterfaceException
190
+	 * @throws ReflectionException
191
+	 * @throws ServiceNotFoundException
192
+	 */
193
+	public function init()
194
+	{
195
+		// only enable most of the EE_Admin IF we're not in full maintenance mode
196
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
197
+			$this->initModelsReady();
198
+		}
199
+		// run the admin page factory but ONLY if:
200
+		// - it is a regular non ajax admin request
201
+		// - we are doing an ee admin ajax request
202
+		if ($this->request->isAdmin() || $this->request->isAdminAjax() || $this->request->isActivation()) {
203
+			try {
204
+				// this loads the controller for the admin pages which will setup routing etc
205
+				$admin_page_loader = $this->loader->getShared('EE_Admin_Page_Loader', [$this->loader]);
206
+				/** @var EE_Admin_Page_Loader $admin_page_loader */
207
+				$admin_page_loader->init();
208
+			} catch (EE_Error $e) {
209
+				$e->get_error();
210
+			}
211
+		}
212
+		if ($this->request->isAjax()) {
213
+			return;
214
+		}
215
+		add_filter('content_save_pre', [$this, 'its_eSpresso'], 10, 1);
216
+		// make sure our CPTs and custom taxonomy metaboxes get shown for first time users
217
+		add_action('admin_head', [$this, 'enable_hidden_ee_nav_menu_metaboxes'], 10);
218
+		add_action('admin_head', [$this, 'register_custom_nav_menu_boxes'], 10);
219
+		// exclude EE critical pages from all nav menus and wp_list_pages
220
+		add_filter('nav_menu_meta_box_object', [$this, 'remove_pages_from_nav_menu'], 10);
221
+	}
222
+
223
+
224
+	/**
225
+	 * Gets the loader (and if it wasn't previously set, sets it)
226
+	 *
227
+	 * @return LoaderInterface
228
+	 * @throws InvalidArgumentException
229
+	 * @throws InvalidDataTypeException
230
+	 * @throws InvalidInterfaceException
231
+	 */
232
+	protected function getLoader()
233
+	{
234
+		return $this->loader;
235
+	}
236
+
237
+
238
+	/**
239
+	 * Method that's fired on admin requests (including admin ajax) but only when the models are usable
240
+	 * (ie, the site isn't in maintenance mode)
241
+	 *
242
+	 * @return void
243
+	 * @throws EE_Error
244
+	 * @since 4.9.63.p
245
+	 */
246
+	protected function initModelsReady()
247
+	{
248
+		// ok so we want to enable the entire admin
249
+		$this->persistent_admin_notice_manager = $this->loader->getShared(
250
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
251
+		);
252
+		$this->persistent_admin_notice_manager->setReturnUrl(
253
+			EE_Admin_Page::add_query_args_and_nonce(
254
+				[
255
+					'page'   => $this->request->getRequestParam('page', ''),
256
+					'action' => $this->request->getRequestParam('action', ''),
257
+				],
258
+				EE_ADMIN_URL
259
+			)
260
+		);
261
+		$this->maybeSetDatetimeWarningNotice();
262
+		// at a glance dashboard widget
263
+		add_filter('dashboard_glance_items', [$this, 'dashboard_glance_items'], 10);
264
+		// filter for get_edit_post_link used on comments for custom post types
265
+		add_filter('get_edit_post_link', [$this, 'modify_edit_post_link'], 10, 2);
266
+	}
267
+
268
+
269
+	/**
270
+	 *    get_persistent_admin_notices
271
+	 *
272
+	 * @access    public
273
+	 * @return void
274
+	 * @throws EE_Error
275
+	 * @throws InvalidArgumentException
276
+	 * @throws InvalidDataTypeException
277
+	 * @throws InvalidInterfaceException
278
+	 */
279
+	public function maybeSetDatetimeWarningNotice()
280
+	{
281
+		// add dismissible notice for datetime changes.  Only valid if site does not have a timezone_string set.
282
+		// @todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version
283
+		// with this.  But after enough time (indeterminate at this point) we can just remove this notice.
284
+		// this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626
285
+		if (
286
+			apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true)
287
+			&& ! get_option('timezone_string')
288
+			&& EEM_Event::instance()->count() > 0
289
+		) {
290
+			new PersistentAdminNotice(
291
+				'datetime_fix_notice',
292
+				sprintf(
293
+					esc_html__(
294
+						'%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times.  Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.',
295
+						'event_espresso'
296
+					),
297
+					'<strong>',
298
+					'</strong>',
299
+					'<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
300
+					'</a>',
301
+					'<a href="' . EE_Admin_Page::add_query_args_and_nonce(
302
+						[
303
+							'page'   => 'espresso_maintenance_settings',
304
+							'action' => 'datetime_tools',
305
+						],
306
+						admin_url('admin.php')
307
+					) . '">'
308
+				),
309
+				false,
310
+				'manage_options',
311
+				'datetime_fix_persistent_notice'
312
+			);
313
+		}
314
+	}
315
+
316
+
317
+	/**
318
+	 * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
319
+	 * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
320
+	 * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
321
+	 * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
322
+	 * normal property on the post_type object.  It's found ONLY in this particular context.
323
+	 *
324
+	 * @param WP_Post $post_type WP post type object
325
+	 * @return WP_Post
326
+	 * @throws InvalidArgumentException
327
+	 * @throws InvalidDataTypeException
328
+	 * @throws InvalidInterfaceException
329
+	 */
330
+	public function remove_pages_from_nav_menu($post_type)
331
+	{
332
+		// if this isn't the "pages" post type let's get out
333
+		if ($post_type->name !== 'page') {
334
+			return $post_type;
335
+		}
336
+		$critical_pages            = EE_Registry::instance()->CFG->core->get_critical_pages_array();
337
+		$post_type->_default_query = [
338
+			'post__not_in' => $critical_pages,
339
+		];
340
+		return $post_type;
341
+	}
342
+
343
+
344
+	/**
345
+	 * WP by default only shows three metaboxes in "nav-menus.php" for first times users.
346
+	 * We want to make sure our metaboxes get shown as well
347
+	 *
348
+	 * @return void
349
+	 */
350
+	public function enable_hidden_ee_nav_menu_metaboxes()
351
+	{
352
+		global $wp_meta_boxes, $pagenow;
353
+		if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
354
+			return;
355
+		}
356
+		$user = wp_get_current_user();
357
+		// has this been done yet?
358
+		if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
359
+			return;
360
+		}
361
+
362
+		$hidden_meta_boxes  = get_user_option('metaboxhidden_nav-menus', $user->ID);
363
+		$initial_meta_boxes = apply_filters(
364
+			'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
365
+			[
366
+				'nav-menu-theme-locations',
367
+				'add-page',
368
+				'add-custom-links',
369
+				'add-category',
370
+				'add-espresso_events',
371
+				'add-espresso_venues',
372
+				'add-espresso_event_categories',
373
+				'add-espresso_venue_categories',
374
+				'add-post-type-post',
375
+				'add-post-type-page',
376
+			]
377
+		);
378
+
379
+		if (is_array($hidden_meta_boxes)) {
380
+			foreach ($hidden_meta_boxes as $key => $meta_box_id) {
381
+				if (in_array($meta_box_id, $initial_meta_boxes, true)) {
382
+					unset($hidden_meta_boxes[ $key ]);
383
+				}
384
+			}
385
+		}
386
+		update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
387
+		update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
388
+	}
389
+
390
+
391
+	/**
392
+	 * This method simply registers custom nav menu boxes for "nav_menus.php route"
393
+	 * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
394
+	 *
395
+	 * @return void
396
+	 * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
397
+	 *         addons etc.
398
+	 */
399
+	public function register_custom_nav_menu_boxes()
400
+	{
401
+		add_meta_box(
402
+			'add-extra-nav-menu-pages',
403
+			esc_html__('Event Espresso Pages', 'event_espresso'),
404
+			[$this, 'ee_cpt_archive_pages'],
405
+			'nav-menus',
406
+			'side',
407
+			'core'
408
+		);
409
+		add_filter(
410
+			"postbox_classes_nav-menus_add-extra-nav-menu-pages",
411
+			function ($classes) {
412
+				array_push($classes, 'ee-admin-container');
413
+				return $classes;
414
+			}
415
+		);
416
+	}
417
+
418
+
419
+	/**
420
+	 * Use this to edit the post link for our cpts so that the edit link points to the correct page.
421
+	 *
422
+	 * @param string $link the original link generated by wp
423
+	 * @param int    $id   post id
424
+	 * @return string  the (maybe) modified link
425
+	 * @since   4.3.0
426
+	 */
427
+	public function modify_edit_post_link($link, $id)
428
+	{
429
+		if (! $post = get_post($id)) {
430
+			return $link;
431
+		}
432
+		if ($post->post_type === 'espresso_attendees') {
433
+			$query_args = [
434
+				'action' => 'edit_attendee',
435
+				'post'   => $id,
436
+			];
437
+			return EEH_URL::add_query_args_and_nonce(
438
+				$query_args,
439
+				admin_url('admin.php?page=espresso_registrations')
440
+			);
441
+		}
442
+		return $link;
443
+	}
444
+
445
+
446
+	public function ee_cpt_archive_pages()
447
+	{
448
+		global $nav_menu_selected_id;
449
+		$removed_args = [
450
+			'action',
451
+			'customlink-tab',
452
+			'edit-menu-item',
453
+			'menu-item',
454
+			'page-tab',
455
+			'_wpnonce',
456
+		];
457
+		$nav_tab_link = $nav_menu_selected_id
458
+			? esc_url(
459
+				add_query_arg(
460
+					'extra-nav-menu-pages-tab',
461
+					'event-archives',
462
+					remove_query_arg($removed_args)
463
+				)
464
+			)
465
+			: '';
466
+		$select_all_link = esc_url(
467
+			add_query_arg(
468
+				[
469
+					'extra-nav-menu-pages-tab' => 'event-archives',
470
+					'selectall'                => 1,
471
+				],
472
+				remove_query_arg($removed_args)
473
+			)
474
+		);
475
+		$pages = $this->_get_extra_nav_menu_pages_items();
476
+		$args['walker'] = new Walker_Nav_Menu_Checklist(false);
477
+		;
478
+		$nav_menu_pages_items = walk_nav_menu_tree(
479
+			array_map(
480
+				[$this, '_setup_extra_nav_menu_pages_items'],
481
+				$pages
482
+			),
483
+			0,
484
+			(object) $args
485
+		);
486
+
487
+		EEH_Template::display_template(
488
+			EE_ADMIN_TEMPLATE . 'cpt_archive_page.template.php',
489
+			[
490
+				$nav_menu_pages_items,
491
+				$nav_tab_link,
492
+				$select_all_link,
493
+			]
494
+		);
495
+	}
496
+
497
+
498
+	/**
499
+	 * Returns an array of event archive nav items.
500
+	 *
501
+	 * @return array
502
+	 * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
503
+	 *        method we use for getting the extra nav menu items
504
+	 */
505
+	private function _get_extra_nav_menu_pages_items()
506
+	{
507
+		$menuitems[] = [
508
+			'title'       => esc_html__('Event List', 'event_espresso'),
509
+			'url'         => get_post_type_archive_link('espresso_events'),
510
+			'description' => esc_html__('Archive page for all events.', 'event_espresso'),
511
+		];
512
+		return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
513
+	}
514
+
515
+
516
+	/**
517
+	 * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
518
+	 * the properties and converts it to the menu item object.
519
+	 *
520
+	 * @param $menu_item_values
521
+	 * @return stdClass
522
+	 * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
523
+	 */
524
+	private function _setup_extra_nav_menu_pages_items($menu_item_values)
525
+	{
526
+		$menu_item = new stdClass();
527
+		$keys      = [
528
+			'ID'               => 0,
529
+			'db_id'            => 0,
530
+			'menu_item_parent' => 0,
531
+			'object_id'        => -1,
532
+			'post_parent'      => 0,
533
+			'type'             => 'custom',
534
+			'object'           => '',
535
+			'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
536
+			'title'            => '',
537
+			'url'              => '',
538
+			'target'           => '',
539
+			'attr_title'       => '',
540
+			'description'      => '',
541
+			'classes'          => [],
542
+			'xfn'              => '',
543
+		];
544
+
545
+		foreach ($keys as $key => $value) {
546
+			$menu_item->{$key} = isset($menu_item_values[ $key ]) ? $menu_item_values[ $key ] : $value;
547
+		}
548
+		return $menu_item;
549
+	}
550
+
551
+
552
+	/**
553
+	 * admin_init
554
+	 *
555
+	 * @return void
556
+	 * @throws InvalidArgumentException
557
+	 * @throws InvalidDataTypeException
558
+	 * @throws InvalidInterfaceException
559
+	 */
560
+	public function admin_init()
561
+	{
562
+		/**
563
+		 * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
564
+		 * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
565
+		 * - check if doing post processing.
566
+		 * - check if doing post processing of one of EE CPTs
567
+		 * - instantiate the corresponding EE CPT model for the post_type being processed.
568
+		 */
569
+		$action    = $this->request->getRequestParam('action');
570
+		$post_type = $this->request->getRequestParam('post_type');
571
+		if ($post_type && $action === 'editpost') {
572
+			/** @var CustomPostTypeDefinitions $custom_post_types */
573
+			$custom_post_types = $this->loader->getShared(CustomPostTypeDefinitions::class);
574
+			$custom_post_types->getCustomPostTypeModels($post_type);
575
+		}
576
+
577
+
578
+		if (! $this->request->isAjax()) {
579
+			/**
580
+			 * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
581
+			 * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
582
+			 * Pages" tab in the EE General Settings Admin page.
583
+			 * This is for user-proofing.
584
+			 */
585
+			add_filter('wp_dropdown_pages', [$this, 'modify_dropdown_pages']);
586
+			if (EE_Maintenance_Mode::instance()->models_can_query()) {
587
+				$this->adminInitModelsReady();
588
+			}
589
+		}
590
+	}
591
+
592
+
593
+	/**
594
+	 * Runs on admin_init but only if models are usable (ie, we're not in maintenance mode)
595
+	 */
596
+	protected function adminInitModelsReady()
597
+	{
598
+		if (function_exists('wp_add_privacy_policy_content')) {
599
+			$this->loader->getShared('EventEspresso\core\services\privacy\policy\PrivacyPolicyManager');
600
+		}
601
+	}
602
+
603
+
604
+	/**
605
+	 * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
606
+	 *
607
+	 * @param string $output Current output.
608
+	 * @return string
609
+	 * @throws InvalidArgumentException
610
+	 * @throws InvalidDataTypeException
611
+	 * @throws InvalidInterfaceException
612
+	 */
613
+	public function modify_dropdown_pages($output)
614
+	{
615
+		// get critical pages
616
+		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
617
+
618
+		// split current output by line break for easier parsing.
619
+		$split_output = explode("\n", $output);
620
+
621
+		// loop through to remove any critical pages from the array.
622
+		foreach ($critical_pages as $page_id) {
623
+			$needle = 'value="' . $page_id . '"';
624
+			foreach ($split_output as $key => $haystack) {
625
+				if (strpos($haystack, $needle) !== false) {
626
+					unset($split_output[ $key ]);
627
+				}
628
+			}
629
+		}
630
+		// replace output with the new contents
631
+		return implode("\n", $split_output);
632
+	}
633
+
634
+
635
+	/**
636
+	 * display_admin_notices
637
+	 *
638
+	 * @return void
639
+	 */
640
+	public function display_admin_notices()
641
+	{
642
+		echo EE_Error::get_notices(); // already escaped
643
+	}
644
+
645
+
646
+	/**
647
+	 * @param array $elements
648
+	 * @return array
649
+	 * @throws EE_Error
650
+	 * @throws InvalidArgumentException
651
+	 * @throws InvalidDataTypeException
652
+	 * @throws InvalidInterfaceException
653
+	 */
654
+	public function dashboard_glance_items($elements)
655
+	{
656
+		$elements                        = is_array($elements) ? $elements : [$elements];
657
+		$events                          = EEM_Event::instance()->count();
658
+		$items['events']['url']          = EE_Admin_Page::add_query_args_and_nonce(
659
+			['page' => 'espresso_events'],
660
+			admin_url('admin.php')
661
+		);
662
+		$items['events']['text']         = sprintf(
663
+			esc_html(
664
+				_n('%s Event', '%s Events', $events, 'event_espresso')
665
+			),
666
+			number_format_i18n($events)
667
+		);
668
+		$items['events']['title']        = esc_html__('Click to view all Events', 'event_espresso');
669
+		$registrations                   = EEM_Registration::instance()->count(
670
+			[
671
+				[
672
+					'STS_ID' => ['!=', EEM_Registration::status_id_incomplete],
673
+				],
674
+			]
675
+		);
676
+		$items['registrations']['url']   = EE_Admin_Page::add_query_args_and_nonce(
677
+			['page' => 'espresso_registrations'],
678
+			admin_url('admin.php')
679
+		);
680
+		$items['registrations']['text']  = sprintf(
681
+			esc_html(
682
+				_n('%s Registration', '%s Registrations', $registrations, 'event_espresso')
683
+			),
684
+			number_format_i18n($registrations)
685
+		);
686
+		$items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
687
+
688
+		$items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
689
+
690
+		foreach ($items as $type => $item_properties) {
691
+			$elements[] = sprintf(
692
+				'<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
693
+				$item_properties['url'],
694
+				$item_properties['title'],
695
+				$item_properties['text']
696
+			);
697
+		}
698
+		return $elements;
699
+	}
700
+
701
+
702
+	/**
703
+	 * check_for_invalid_datetime_formats
704
+	 * if an admin changes their date or time format settings on the WP General Settings admin page, verify that
705
+	 * their selected format can be parsed by PHP
706
+	 *
707
+	 * @param    $value
708
+	 * @param    $option
709
+	 * @return    string
710
+	 */
711
+	public function check_for_invalid_datetime_formats($value, $option)
712
+	{
713
+		// check for date_format or time_format
714
+		switch ($option) {
715
+			case 'date_format':
716
+				$date_time_format = $value . ' ' . get_option('time_format');
717
+				break;
718
+			case 'time_format':
719
+				$date_time_format = get_option('date_format') . ' ' . $value;
720
+				break;
721
+			default:
722
+				$date_time_format = false;
723
+		}
724
+		// do we have a date_time format to check ?
725
+		if ($date_time_format) {
726
+			$error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
727
+
728
+			if (is_array($error_msg)) {
729
+				$msg = '<p>'
730
+					   . sprintf(
731
+						   esc_html__(
732
+							   'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
733
+							   'event_espresso'
734
+						   ),
735
+						   date($date_time_format),
736
+						   $date_time_format
737
+					   )
738
+					   . '</p><p><ul>';
739
+
740
+
741
+				foreach ($error_msg as $error) {
742
+					$msg .= '<li>' . $error . '</li>';
743
+				}
744
+
745
+				$msg .= '</ul></p><p>'
746
+						. sprintf(
747
+							esc_html__(
748
+								'%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
749
+								'event_espresso'
750
+							),
751
+							'<span style="color:#D54E21;">',
752
+							'</span>'
753
+						)
754
+						. '</p>';
755
+
756
+				// trigger WP settings error
757
+				add_settings_error(
758
+					'date_format',
759
+					'date_format',
760
+					$msg
761
+				);
762
+
763
+				// set format to something valid
764
+				switch ($option) {
765
+					case 'date_format':
766
+						$value = 'F j, Y';
767
+						break;
768
+					case 'time_format':
769
+						$value = 'g:i a';
770
+						break;
771
+				}
772
+			}
773
+		}
774
+		return $value;
775
+	}
776
+
777
+
778
+	/**
779
+	 * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
780
+	 *
781
+	 * @param $content
782
+	 * @return    string
783
+	 */
784
+	public function its_eSpresso($content)
785
+	{
786
+		return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
787
+	}
788
+
789
+
790
+	/**
791
+	 * espresso_admin_footer
792
+	 *
793
+	 * @return    string
794
+	 */
795
+	public function espresso_admin_footer()
796
+	{
797
+		return EEH_Template::powered_by_event_espresso('aln-cntr', '', ['utm_content' => 'admin_footer']);
798
+	}
799
+
800
+
801
+	/**
802
+	 * Hooks into the "post states" filter in a wp post type list table.
803
+	 *
804
+	 * @param array   $post_states
805
+	 * @param WP_Post $post
806
+	 * @return array
807
+	 * @throws InvalidArgumentException
808
+	 * @throws InvalidDataTypeException
809
+	 * @throws InvalidInterfaceException
810
+	 */
811
+	public function displayStateForCriticalPages($post_states, $post)
812
+	{
813
+		$post_states = (array) $post_states;
814
+		if (! $post instanceof WP_Post || $post->post_type !== 'page') {
815
+			return $post_states;
816
+		}
817
+		/** @var EE_Core_Config $config */
818
+		$config = $this->loader->getShared('EE_Config')->core;
819
+		if (in_array($post->ID, $config->get_critical_pages_array(), true)) {
820
+			$post_states[] = sprintf(
821
+			/* Translators: Using company name - Event Espresso Critical Page */
822
+				esc_html__('%s Critical Page', 'event_espresso'),
823
+				'Event Espresso'
824
+			);
825
+		}
826
+		return $post_states;
827
+	}
828
+
829
+
830
+	/**
831
+	 * Show documentation links on the plugins page
832
+	 *
833
+	 * @param mixed $meta Plugin Row Meta
834
+	 * @param mixed $file Plugin Base file
835
+	 * @return array
836
+	 */
837
+	public function addLinksToPluginRowMeta($meta, $file)
838
+	{
839
+		if (EE_PLUGIN_BASENAME === $file) {
840
+			$row_meta = [
841
+				'docs' => '<a href="https://eventespresso.com/support/documentation/versioned-docs/?doc_ver=ee4"'
842
+						  . ' aria-label="'
843
+						  . esc_attr__('View Event Espresso documentation', 'event_espresso')
844
+						  . '">'
845
+						  . esc_html__('Docs', 'event_espresso')
846
+						  . '</a>',
847
+				'api'  => '<a href="https://github.com/eventespresso/event-espresso-core/tree/master/docs/C--REST-API"'
848
+						  . ' aria-label="'
849
+						  . esc_attr__('View Event Espresso API docs', 'event_espresso')
850
+						  . '">'
851
+						  . esc_html__('API docs', 'event_espresso')
852
+						  . '</a>',
853
+			];
854
+			return array_merge($meta, $row_meta);
855
+		}
856
+		return (array) $meta;
857
+	}
858
+
859
+	 /**************************************************************************************/
860
+	 /************************************* DEPRECATED *************************************/
861
+	 /**************************************************************************************/
862
+
863
+
864
+	/**
865
+	 * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
866
+	 * EE_Admin_Page route is called.
867
+	 *
868
+	 * @return void
869
+	 */
870
+	public function route_admin_request()
871
+	{
872
+	}
873
+
874
+
875
+	/**
876
+	 * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
877
+	 *
878
+	 * @return void
879
+	 */
880
+	public function wp_loaded()
881
+	{
882
+	}
883
+
884
+
885
+	/**
886
+	 * static method for registering ee admin page.
887
+	 * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
888
+	 *
889
+	 * @param       $page_basename
890
+	 * @param       $page_path
891
+	 * @param array $config
892
+	 * @return void
893
+	 * @throws EE_Error
894
+	 * @see        EE_Register_Admin_Page::register()
895
+	 * @since      4.3.0
896
+	 * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
897
+	 */
898
+	public static function register_ee_admin_page($page_basename, $page_path, $config = [])
899
+	{
900
+		EE_Error::doing_it_wrong(
901
+			__METHOD__,
902
+			sprintf(
903
+				esc_html__(
904
+					'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
905
+					'event_espresso'
906
+				),
907
+				$page_basename
908
+			),
909
+			'4.3'
910
+		);
911
+		if (class_exists('EE_Register_Admin_Page')) {
912
+			$config['page_path'] = $page_path;
913
+		}
914
+		EE_Register_Admin_Page::register($page_basename, $config);
915
+	}
916
+
917
+
918
+	/**
919
+	 * @param int      $post_ID
920
+	 * @param \WP_Post $post
921
+	 * @return void
922
+	 * @deprecated 4.8.41
923
+	 */
924
+	public static function parse_post_content_on_save($post_ID, $post)
925
+	{
926
+		EE_Error::doing_it_wrong(
927
+			__METHOD__,
928
+			esc_html__('Usage is deprecated', 'event_espresso'),
929
+			'4.8.41'
930
+		);
931
+	}
932
+
933
+
934
+	/**
935
+	 * @param  $option
936
+	 * @param  $old_value
937
+	 * @param  $value
938
+	 * @return void
939
+	 * @deprecated 4.8.41
940
+	 */
941
+	public function reset_page_for_posts_on_change($option, $old_value, $value)
942
+	{
943
+		EE_Error::doing_it_wrong(
944
+			__METHOD__,
945
+			esc_html__('Usage is deprecated', 'event_espresso'),
946
+			'4.8.41'
947
+		);
948
+	}
949
+
950
+
951
+	/**
952
+	 * @return void
953
+	 * @deprecated 4.9.27
954
+	 */
955
+	public function get_persistent_admin_notices()
956
+	{
957
+		EE_Error::doing_it_wrong(
958
+			__METHOD__,
959
+			sprintf(
960
+				esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
961
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
962
+			),
963
+			'4.9.27'
964
+		);
965
+	}
966
+
967
+
968
+	/**
969
+	 * @throws InvalidInterfaceException
970
+	 * @throws InvalidDataTypeException
971
+	 * @throws DomainException
972
+	 * @deprecated 4.9.27
973
+	 */
974
+	public function dismiss_ee_nag_notice_callback()
975
+	{
976
+		EE_Error::doing_it_wrong(
977
+			__METHOD__,
978
+			sprintf(
979
+				esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
980
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
981
+			),
982
+			'4.9.27'
983
+		);
984
+		$this->persistent_admin_notice_manager->dismissNotice();
985
+	}
986
+
987
+
988
+	/**
989
+	 * @return void
990
+	 * @deprecated $VID:$
991
+	 */
992
+	public function enqueue_admin_scripts()
993
+	{
994
+	}
995
+
996
+
997
+
998
+	/**
999
+	 * @return RequestInterface
1000
+	 * @deprecated $VID:$
1001
+	 */
1002
+	public function get_request()
1003
+	{
1004
+		EE_Error::doing_it_wrong(
1005
+			__METHOD__,
1006
+			sprintf(
1007
+				esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1008
+				'EventEspresso\core\services\request\Request'
1009
+			),
1010
+			'$VID:$'
1011
+		);
1012
+		return $this->request;
1013
+	}
1014
+
1015
+
1016
+	/**
1017
+	 * @deprecated $VID:$
1018
+	 */
1019
+	public function hookIntoWpPluginsPage()
1020
+	{
1021
+	}
1022 1022
 }
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
     public static function instance(LoaderInterface $loader = null, RequestInterface $request = null)
52 52
     {
53 53
         // check if class object is instantiated
54
-        if (! EE_Admin::$_instance instanceof EE_Admin) {
54
+        if ( ! EE_Admin::$_instance instanceof EE_Admin) {
55 55
             EE_Admin::$_instance = new EE_Admin($loader, $request);
56 56
         }
57 57
         return EE_Admin::$_instance;
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
         // load EE_Request_Handler early
93 93
         add_action('AHEE__EE_System__initialize_last', [$this, 'init']);
94 94
         add_action('admin_init', [$this, 'admin_init'], 100);
95
-        if (! $this->request->isAjax()) {
95
+        if ( ! $this->request->isAjax()) {
96 96
             // admin hooks
97 97
             add_action('admin_notices', [$this, 'display_admin_notices'], 10);
98 98
             add_action('network_admin_notices', [$this, 'display_admin_notices'], 10);
@@ -114,11 +114,11 @@  discard block
 block discarded – undo
114 114
      */
115 115
     private function _define_all_constants()
116 116
     {
117
-        if (! defined('EE_ADMIN_URL')) {
118
-            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
119
-            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
120
-            define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates/');
121
-            define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
117
+        if ( ! defined('EE_ADMIN_URL')) {
118
+            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL.'core/admin/');
119
+            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL.'admin_pages/');
120
+            define('EE_ADMIN_TEMPLATE', EE_ADMIN.'templates/');
121
+            define('WP_ADMIN_PATH', ABSPATH.'wp-admin/');
122 122
             define('WP_AJAX_URL', admin_url('admin-ajax.php'));
123 123
         }
124 124
     }
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
         // set $main_file in stone
137 137
         static $main_file;
138 138
         // if $main_file is not set yet
139
-        if (! $main_file) {
139
+        if ( ! $main_file) {
140 140
             $main_file = EE_PLUGIN_BASENAME;
141 141
         }
142 142
         if ($plugin === $main_file) {
@@ -171,9 +171,9 @@  discard block
 block discarded – undo
171 171
     public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = [])
172 172
     {
173 173
         return [
174
-            'maintenance' => EE_ADMIN_PAGES . 'maintenance/',
175
-            'about'       => EE_ADMIN_PAGES . 'about/',
176
-            'support'     => EE_ADMIN_PAGES . 'support/',
174
+            'maintenance' => EE_ADMIN_PAGES.'maintenance/',
175
+            'about'       => EE_ADMIN_PAGES.'about/',
176
+            'support'     => EE_ADMIN_PAGES.'support/',
177 177
         ];
178 178
     }
179 179
 
@@ -298,13 +298,13 @@  discard block
 block discarded – undo
298 298
                     '</strong>',
299 299
                     '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
300 300
                     '</a>',
301
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
301
+                    '<a href="'.EE_Admin_Page::add_query_args_and_nonce(
302 302
                         [
303 303
                             'page'   => 'espresso_maintenance_settings',
304 304
                             'action' => 'datetime_tools',
305 305
                         ],
306 306
                         admin_url('admin.php')
307
-                    ) . '">'
307
+                    ).'">'
308 308
                 ),
309 309
                 false,
310 310
                 'manage_options',
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
     public function enable_hidden_ee_nav_menu_metaboxes()
351 351
     {
352 352
         global $wp_meta_boxes, $pagenow;
353
-        if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
353
+        if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
354 354
             return;
355 355
         }
356 356
         $user = wp_get_current_user();
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
         if (is_array($hidden_meta_boxes)) {
380 380
             foreach ($hidden_meta_boxes as $key => $meta_box_id) {
381 381
                 if (in_array($meta_box_id, $initial_meta_boxes, true)) {
382
-                    unset($hidden_meta_boxes[ $key ]);
382
+                    unset($hidden_meta_boxes[$key]);
383 383
                 }
384 384
             }
385 385
         }
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
         );
409 409
         add_filter(
410 410
             "postbox_classes_nav-menus_add-extra-nav-menu-pages",
411
-            function ($classes) {
411
+            function($classes) {
412 412
                 array_push($classes, 'ee-admin-container');
413 413
                 return $classes;
414 414
             }
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
      */
427 427
     public function modify_edit_post_link($link, $id)
428 428
     {
429
-        if (! $post = get_post($id)) {
429
+        if ( ! $post = get_post($id)) {
430 430
             return $link;
431 431
         }
432 432
         if ($post->post_type === 'espresso_attendees') {
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
         );
486 486
 
487 487
         EEH_Template::display_template(
488
-            EE_ADMIN_TEMPLATE . 'cpt_archive_page.template.php',
488
+            EE_ADMIN_TEMPLATE.'cpt_archive_page.template.php',
489 489
             [
490 490
                 $nav_menu_pages_items,
491 491
                 $nav_tab_link,
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
         ];
544 544
 
545 545
         foreach ($keys as $key => $value) {
546
-            $menu_item->{$key} = isset($menu_item_values[ $key ]) ? $menu_item_values[ $key ] : $value;
546
+            $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value;
547 547
         }
548 548
         return $menu_item;
549 549
     }
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
         }
576 576
 
577 577
 
578
-        if (! $this->request->isAjax()) {
578
+        if ( ! $this->request->isAjax()) {
579 579
             /**
580 580
              * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
581 581
              * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
@@ -620,10 +620,10 @@  discard block
 block discarded – undo
620 620
 
621 621
         // loop through to remove any critical pages from the array.
622 622
         foreach ($critical_pages as $page_id) {
623
-            $needle = 'value="' . $page_id . '"';
623
+            $needle = 'value="'.$page_id.'"';
624 624
             foreach ($split_output as $key => $haystack) {
625 625
                 if (strpos($haystack, $needle) !== false) {
626
-                    unset($split_output[ $key ]);
626
+                    unset($split_output[$key]);
627 627
                 }
628 628
             }
629 629
         }
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
             ['page' => 'espresso_events'],
660 660
             admin_url('admin.php')
661 661
         );
662
-        $items['events']['text']         = sprintf(
662
+        $items['events']['text'] = sprintf(
663 663
             esc_html(
664 664
                 _n('%s Event', '%s Events', $events, 'event_espresso')
665 665
             ),
@@ -673,11 +673,11 @@  discard block
 block discarded – undo
673 673
                 ],
674 674
             ]
675 675
         );
676
-        $items['registrations']['url']   = EE_Admin_Page::add_query_args_and_nonce(
676
+        $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(
677 677
             ['page' => 'espresso_registrations'],
678 678
             admin_url('admin.php')
679 679
         );
680
-        $items['registrations']['text']  = sprintf(
680
+        $items['registrations']['text'] = sprintf(
681 681
             esc_html(
682 682
                 _n('%s Registration', '%s Registrations', $registrations, 'event_espresso')
683 683
             ),
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
 
690 690
         foreach ($items as $type => $item_properties) {
691 691
             $elements[] = sprintf(
692
-                '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
692
+                '<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>',
693 693
                 $item_properties['url'],
694 694
                 $item_properties['title'],
695 695
                 $item_properties['text']
@@ -713,10 +713,10 @@  discard block
 block discarded – undo
713 713
         // check for date_format or time_format
714 714
         switch ($option) {
715 715
             case 'date_format':
716
-                $date_time_format = $value . ' ' . get_option('time_format');
716
+                $date_time_format = $value.' '.get_option('time_format');
717 717
                 break;
718 718
             case 'time_format':
719
-                $date_time_format = get_option('date_format') . ' ' . $value;
719
+                $date_time_format = get_option('date_format').' '.$value;
720 720
                 break;
721 721
             default:
722 722
                 $date_time_format = false;
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
 
740 740
 
741 741
                 foreach ($error_msg as $error) {
742
-                    $msg .= '<li>' . $error . '</li>';
742
+                    $msg .= '<li>'.$error.'</li>';
743 743
                 }
744 744
 
745 745
                 $msg .= '</ul></p><p>'
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
     public function displayStateForCriticalPages($post_states, $post)
812 812
     {
813 813
         $post_states = (array) $post_states;
814
-        if (! $post instanceof WP_Post || $post->post_type !== 'page') {
814
+        if ( ! $post instanceof WP_Post || $post->post_type !== 'page') {
815 815
             return $post_states;
816 816
         }
817 817
         /** @var EE_Core_Config $config */
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_Menu_Map.core.php 2 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -12,50 +12,50 @@
 block discarded – undo
12 12
  */
13 13
 abstract class EE_Admin_Page_Menu_Map extends AdminMenuItem
14 14
 {
15
-    const NONE                   = 0;
15
+	const NONE                   = 0;
16 16
 
17
-    const BLOG_ADMIN_ONLY        = 1;
17
+	const BLOG_ADMIN_ONLY        = 1;
18 18
 
19
-    const BLOG_AND_NETWORK_ADMIN = 2;
19
+	const BLOG_AND_NETWORK_ADMIN = 2;
20 20
 
21
-    const NETWORK_ADMIN_ONLY     = 3;
21
+	const NETWORK_ADMIN_ONLY     = 3;
22 22
 
23 23
 
24
-    /**
25
-     * @return string
26
-     * @deprecated $VID:$
27
-     */
28
-    protected function _add_menu_page(): string
29
-    {
30
-        return $this->registerMenuItem();
31
-    }
24
+	/**
25
+	 * @return string
26
+	 * @deprecated $VID:$
27
+	 */
28
+	protected function _add_menu_page(): string
29
+	{
30
+		return $this->registerMenuItem();
31
+	}
32 32
 
33 33
 
34
-    /**
35
-     * @param boolean $network_admin whether this is being added to the network admin page or not
36
-     * @deprecated $VID:$
37
-     * @since  4.4.0
38
-     */
39
-    public function add_menu_page(bool $network_admin = false)
40
-    {
41
-        $this->registerAdminMenuItem($network_admin);
42
-    }
34
+	/**
35
+	 * @param boolean $network_admin whether this is being added to the network admin page or not
36
+	 * @deprecated $VID:$
37
+	 * @since  4.4.0
38
+	 */
39
+	public function add_menu_page(bool $network_admin = false)
40
+	{
41
+		$this->registerAdminMenuItem($network_admin);
42
+	}
43 43
 
44 44
 
45
-    public function __get(string $property)
46
-    {
47
-        // converts a property name like 'menu_slug' into 'menuSlug'
48
-        $getter = lcfirst(ucwords($property, '_'));
49
-        return method_exists($this, $getter) ? $this->{$getter}() : null;
50
-    }
45
+	public function __get(string $property)
46
+	{
47
+		// converts a property name like 'menu_slug' into 'menuSlug'
48
+		$getter = lcfirst(ucwords($property, '_'));
49
+		return method_exists($this, $getter) ? $this->{$getter}() : null;
50
+	}
51 51
 
52 52
 
53
-    public function __set(string $property, $value)
54
-    {
55
-        // converts a property name like 'menu_slug' into 'setMenuSlug'
56
-        $setter = 'set' . ucwords($property, '_');
57
-        if (method_exists($this, $setter)) {
58
-            $this->{$setter}($value);
59
-        }
60
-    }
53
+	public function __set(string $property, $value)
54
+	{
55
+		// converts a property name like 'menu_slug' into 'setMenuSlug'
56
+		$setter = 'set' . ucwords($property, '_');
57
+		if (method_exists($this, $setter)) {
58
+			$this->{$setter}($value);
59
+		}
60
+	}
61 61
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@
 block discarded – undo
53 53
     public function __set(string $property, $value)
54 54
     {
55 55
         // converts a property name like 'menu_slug' into 'setMenuSlug'
56
-        $setter = 'set' . ucwords($property, '_');
56
+        $setter = 'set'.ucwords($property, '_');
57 57
         if (method_exists($this, $setter)) {
58 58
             $this->{$setter}($value);
59 59
         }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_Menu_Group.core.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -10,22 +10,22 @@
 block discarded – undo
10 10
  */
11 11
 class EE_Admin_Page_Menu_Group extends AdminMenuGroup
12 12
 {
13
-    /**
14
-     * @return string
15
-     * @deprecated $VID:$
16
-     */
17
-    protected function _add_menu_page(): string
18
-    {
19
-        return $this->registerMenuItem();
20
-    }
13
+	/**
14
+	 * @return string
15
+	 * @deprecated $VID:$
16
+	 */
17
+	protected function _add_menu_page(): string
18
+	{
19
+		return $this->registerMenuItem();
20
+	}
21 21
 
22 22
 
23
-    /**
24
-     * @return string
25
-     * @deprecated $VID:$
26
-     */
27
-    private function _group_link(): string
28
-    {
29
-        return $this->groupLink();
30
-    }
23
+	/**
24
+	 * @return string
25
+	 * @deprecated $VID:$
26
+	 */
27
+	private function _group_link(): string
28
+	{
29
+		return $this->groupLink();
30
+	}
31 31
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_CPT_Init.core.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -12,44 +12,44 @@
 block discarded – undo
12 12
  */
13 13
 abstract class EE_Admin_Page_CPT_Init extends EE_Admin_Page_Init
14 14
 {
15
-    public function do_initial_loads()
16
-    {
17
-        // we want to use the corresponding admin page object (but not route it!).
18
-        // To do this we just set _routing to false.
19
-        // That way this page object is being loaded on all pages to make sure we hook into admin properly.
20
-        // But note... we are ONLY doing this if the given page is NOT pages we WANT to load ;)
21
-        // This is important because we have hooks that help redirect custom post type saves
22
-        $page = $this->request->getRequestParam('page');
23
-        $this->_routing = $page === $this->_menu_map->menuSlug();
24
-        $this->_initialize_admin_page();
25
-        if ($this->_routing) {
26
-            // added for 4.1 to completely disable autosave for our pages.
27
-            // This can be removed once we fully enable autosave functionality
28
-            remove_filter('wp_print_scripts', 'wp_just_in_time_script_localization');
29
-            add_filter('wp_print_scripts', [$this, 'wp_just_in_time_script_localization'], 100);
30
-            // end removal of autosave functionality.
31
-        }
32
-    }
15
+	public function do_initial_loads()
16
+	{
17
+		// we want to use the corresponding admin page object (but not route it!).
18
+		// To do this we just set _routing to false.
19
+		// That way this page object is being loaded on all pages to make sure we hook into admin properly.
20
+		// But note... we are ONLY doing this if the given page is NOT pages we WANT to load ;)
21
+		// This is important because we have hooks that help redirect custom post type saves
22
+		$page = $this->request->getRequestParam('page');
23
+		$this->_routing = $page === $this->_menu_map->menuSlug();
24
+		$this->_initialize_admin_page();
25
+		if ($this->_routing) {
26
+			// added for 4.1 to completely disable autosave for our pages.
27
+			// This can be removed once we fully enable autosave functionality
28
+			remove_filter('wp_print_scripts', 'wp_just_in_time_script_localization');
29
+			add_filter('wp_print_scripts', [$this, 'wp_just_in_time_script_localization'], 100);
30
+			// end removal of autosave functionality.
31
+		}
32
+	}
33 33
 
34 34
 
35
-    public function wp_just_in_time_script_localization()
36
-    {
37
-        wp_localize_script(
38
-            'autosave',
39
-            'autosaveL10n',
40
-            [
41
-                'autosaveInterval' => 172800,
42
-                'savingText'       => wp_strip_all_tags(__('Saving Draft&#8230;', 'event_espresso')),
43
-                'saveAlert'        => wp_strip_all_tags(
44
-                    __('The changes you made will be lost if you navigate away from this page.', 'event_espresso')
45
-                ),
46
-            ]
47
-        );
48
-    }
35
+	public function wp_just_in_time_script_localization()
36
+	{
37
+		wp_localize_script(
38
+			'autosave',
39
+			'autosaveL10n',
40
+			[
41
+				'autosaveInterval' => 172800,
42
+				'savingText'       => wp_strip_all_tags(__('Saving Draft&#8230;', 'event_espresso')),
43
+				'saveAlert'        => wp_strip_all_tags(
44
+					__('The changes you made will be lost if you navigate away from this page.', 'event_espresso')
45
+				),
46
+			]
47
+		);
48
+	}
49 49
 
50 50
 
51
-    public function adjust_post_lock_window($interval)
52
-    {
53
-        return 172800;
54
-    }
51
+	public function adjust_post_lock_window($interval)
52
+	{
53
+		return 172800;
54
+	}
55 55
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Hooks.core.php 1 patch
Indentation   +761 added lines, -761 removed lines patch added patch discarded remove patch
@@ -14,765 +14,765 @@
 block discarded – undo
14 14
  */
15 15
 abstract class EE_Admin_Hooks extends EE_Base
16 16
 {
17
-    /**
18
-     * we're just going to use this to hold the name of the caller class (child class name)
19
-     *
20
-     * @var string
21
-     */
22
-    public $caller;
23
-
24
-
25
-    /**
26
-     * this is just a flag set automatically to indicate whether we've got an extended hook class running (i.e.
27
-     * espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks).  This flag is
28
-     * used later to make sure we require the needed files.
29
-     *
30
-     * @var bool
31
-     */
32
-    protected $_extend;
33
-
34
-
35
-    /**
36
-     * child classes MUST set this property so that the page object can be loaded correctly
37
-     *
38
-     * @var string
39
-     */
40
-    protected $_name;
41
-
42
-
43
-    /**
44
-     * This is set by child classes and is an associative array of ajax hooks in the format:
45
-     * array(
46
-     *    'ajax_action_ref' => 'executing_method'; //must be public
47
-     * )
48
-     *
49
-     * @var array
50
-     */
51
-    protected $_ajax_func;
52
-
53
-
54
-    /**
55
-     * This is an array of methods that get executed on a page routes admin_init hook. Use the following format:
56
-     * array(
57
-     *    'page_route' => 'executing_method' //must be public
58
-     * )
59
-     *
60
-     * @var array
61
-     */
62
-    protected $_init_func;
63
-
64
-
65
-    /**
66
-     * This is an array of methods that output metabox content for the given page route.  Use the following format:
67
-     * [
68
-     *      0 => [
69
-     *          'page_route' => 'string_for_page_route',    must correspond to a page route in the class being connected
70
-     *                                                      with (i.e. "edit_event") If this is in an array then the
71
-     *                                                      same params below will be used but the metabox will be
72
-     *                                                      added to each route.
73
-     *          'func' =>  'executing_method',              must be public (i.e. public function executing_method
74
-     *                                                      ($post, $callback_args){} ).
75
-     *                                                      Note if you include callback args in the array then you
76
-     *                                                      need to declare them in the method arguments.
77
-     *          'id' => 'identifier_for_metabox',           so it can be removed by addons
78
-     *                                                      (optional, class will set it automatically)
79
-     *          'priority' => 'default',                    default 'default' (optional)
80
-     *          'label' => esc_html__('Localized Title', 'event_espresso'),
81
-     *          'context' => 'advanced'                     advanced is default (optional),
82
-     *      ]
83
-     *      'callback_args' => array() //any callback args to include (optional)
84
-     * ]
85
-     * Why are we indexing numerically?  Because it's possible there may be more than one metabox per page_route.
86
-     *
87
-     * @var array
88
-     */
89
-    protected $_metaboxes;
90
-
91
-
92
-    /**
93
-     * This is an array of values that indicate any metaboxes we want removed from a given page route.  Usually this is
94
-     * used when caffeinated functionality is replacing decaffeinated functionality.  Use the following format for the
95
-     * array: array(
96
-     *    0 => array(
97
-     *        'page_route' => 'string_for_page_route' //can be string or array of strings that match a page_route(s)
98
-     *        that are in the class being connected with (i.e. 'edit', or 'create_new').
99
-     *        'id' => 'identifier_for_metabox', //what the id is of the metabox being removed
100
-     *        'context' => 'normal', //the context for the metabox being removed (has to match)
101
-     *        'screen' => 'screen_id', //(optional), if not included then this class will attempt to remove the metabox
102
-     *        using the currently loaded screen object->id  however, there may be cases where you have to specify the
103
-     *        id for the screen the metabox is on.
104
-     *    )
105
-     * )
106
-     *
107
-     * @var array
108
-     */
109
-    protected $_remove_metaboxes;
110
-
111
-
112
-    /**
113
-     * This parent class takes care of loading the scripts and styles if the child class has set the properties for
114
-     * them in the following format.  Note, the first array index ('register') is for defining all the registers.  The
115
-     * second array index is for indicating what routes each script/style loads on. array(
116
-     * 'registers' => array(
117
-     *        'script_ref' => array( // if more than one script is to be loaded its best to use the 'dependency'
118
-     *        argument to link scripts together.
119
-     *            'type' => 'js' // 'js' or 'css' (defaults to js).  This tells us what type of wp_function to use
120
-     *            'url' => 'http://urltoscript.css.js',
121
-     *            'depends' => array('jquery'), //an array of dependencies for the scripts. REMEMBER, if a script has
122
-     *            already been registered elsewhere in the system.  You can just use the depends array to make sure it
123
-     *            gets loaded before the one you are setting here.
124
-     *            'footer' => TRUE //defaults to true (styles don't use this parameter)
125
-     *        ),
126
-     *    'enqueues' => array( //this time each key corresponds to the script ref followed by an array of page routes
127
-     *    the script gets enqueued on.
128
-     *        'script_ref' => array('route_one', 'route_two')
129
-     *    ),
130
-     *    'localize' => array( //this allows you to set a localized object.  Indicate which script the object is being
131
-     *    attached to and then include an array indexed by the name of the object and the array of key/value pairs for
132
-     *    the object.
133
-     *        'scrip_ref' => array(
134
-     *            'NAME_OF_JS_OBJECT' => array(
135
-     *                'translate_ref' => esc_html__('localized_string', 'event_espresso'),
136
-     *                'some_data' => 5
137
-     *            )
138
-     *        )
139
-     *    )
140
-     * )
141
-     *
142
-     * @var array
143
-     */
144
-    protected $_scripts_styles;
145
-
146
-
147
-    /**
148
-     * This is a property that will contain the current route.
149
-     *
150
-     * @var string;
151
-     */
152
-    protected $_current_route;
153
-
154
-
155
-    /**
156
-     * this optional property can be set by child classes to override the priority for the automatic action/filter hook
157
-     * loading in the `_load_routed_hooks()` method.  Please follow this format: array(
158
-     *    'wp_hook_reference' => 1
159
-     *    )
160
-     * )
161
-     *
162
-     * @var array
163
-     */
164
-    protected $_wp_action_filters_priority;
165
-
166
-
167
-    /**
168
-     * This just holds a merged array of the request vars
169
-     *
170
-     * @var array
171
-     */
172
-    protected $_req_data;
173
-
174
-    /**
175
-     * @var array
176
-     */
177
-    protected $_scripts;
178
-
179
-    /**
180
-     * @var array
181
-     */
182
-    protected $_styles;
183
-
184
-    /**
185
-     * This just holds an instance of the page object for this hook
186
-     *
187
-     * @var EE_Admin_Page
188
-     */
189
-    protected $_page_object;
190
-
191
-
192
-    /**
193
-     * This holds the EE_Admin_Page object from the calling admin page that this object hooks into.
194
-     *
195
-     * @var EE_Admin_Page|EE_Admin_Page_CPT
196
-     */
197
-    protected $_adminpage_obj;
198
-
199
-
200
-    /**
201
-     * Holds EE_Registry object
202
-     *
203
-     * @var EE_Registry
204
-     */
205
-    protected $EE = null;
206
-
207
-    /**
208
-     * @var RequestInterface
209
-     */
210
-    protected $request;
211
-
212
-
213
-    /**
214
-     * constructor
215
-     *
216
-     * @param EE_Admin_Page $admin_page
217
-     * @throws EE_Error
218
-     */
219
-    public function __construct(EE_Admin_Page $admin_page)
220
-    {
221
-        $this->_adminpage_obj = $admin_page;
222
-        $this->request        = LoaderFactory::getLoader()->getShared(RequestInterface::class);
223
-        $this->_req_data      = $this->request->requestParams();
224
-        // first let's verify we're on the right page
225
-        if ($this->request->getRequestParam('page') !== $this->_adminpage_obj->page_slug) {
226
-            return;
227
-        }
228
-        $this->_set_defaults();
229
-        $this->_set_hooks_properties();
230
-        // get out nothing more to be done here.
231
-        // allow for extends to modify properties
232
-        if (method_exists($this, '_extend_properties')) {
233
-            $this->_extend_properties();
234
-        }
235
-        $this->_set_page_object();
236
-        $this->_init_hooks();
237
-        $this->_load_custom_methods();
238
-        $this->_load_routed_hooks();
239
-        add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts_styles']);
240
-        add_action('admin_enqueue_scripts', [$this, 'add_metaboxes'], 20);
241
-        add_action('admin_enqueue_scripts', [$this, 'remove_metaboxes'], 15);
242
-        $this->_ajax_hooks();
243
-    }
244
-
245
-
246
-    /**
247
-     * used by child classes to set the following properties:
248
-     * $_ajax_func (optional)
249
-     * $_init_func (optional)
250
-     * $_metaboxes (optional)
251
-     * $_scripts (optional)
252
-     * $_styles (optional)
253
-     * $_name (required)
254
-     * Also in this method will be registered any scripts or styles loaded on the targeted page (as indicated in the
255
-     * _scripts/_styles properties) Also children should place in this method any filters/actions that have to happen
256
-     * really early on page load (just after admin_init) if they want to have them registered for handling early.
257
-     *
258
-     * @abstract
259
-     * @return void
260
-     */
261
-    abstract protected function _set_hooks_properties();
262
-
263
-
264
-    /**
265
-     * The hooks for enqueue_scripts and enqueue_styles will be run in here.  Child classes need to define their
266
-     * scripts and styles in the relevant $_scripts and $_styles properties.  Child classes must have also already
267
-     * registered the scripts and styles using wp_register_script and wp_register_style functions.
268
-     *
269
-     * @return void
270
-     * @throws EE_Error
271
-     */
272
-    public function enqueue_scripts_styles()
273
-    {
274
-        if (! empty($this->_scripts_styles)) {
275
-            // first let's do all the registrations
276
-            if (! isset($this->_scripts_styles['registers'])) {
277
-                $msg[] = esc_html__(
278
-                    'There is no "registers" index in the <code>$this->_scripts_styles</code> property.',
279
-                    'event_espresso'
280
-                );
281
-                $msg[] = sprintf(
282
-                    esc_html__(
283
-                        'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child',
284
-                        'event_espresso'
285
-                    ),
286
-                    '<strong>' . $this->caller . '</strong>'
287
-                );
288
-                throw new EE_Error(implode('||', $msg));
289
-            }
290
-            $defaults = [
291
-                'type'    => 'js',
292
-                'url'     => '',
293
-                'depends' => [],
294
-                'version' => EVENT_ESPRESSO_VERSION,
295
-                'footer'  => true,
296
-            ];
297
-            foreach ($this->_scripts_styles['registers'] as $ref => $details) {
298
-                $details = wp_parse_args($details, $defaults);
299
-                $type    = $details['type'];
300
-                $url     = $details['url'];
301
-                $depends = $details['depends'];
302
-                $version = $details['version'];
303
-                $footer  = $details['footer'];
304
-                // let's make sure that we set the 'registers' type if it's not set!
305
-                // We need it later to determine which enqueue we do
306
-                $this->_scripts_styles['registers'][ $ref ]['type'] = $type;
307
-                // let's make sure we're not missing any REQUIRED parameters
308
-                if (empty($url)) {
309
-                    $msg[] = sprintf(
310
-                        esc_html__('Missing the url for the requested %s', 'event_espresso'),
311
-                        $type == 'js' ? 'script' : 'stylesheet'
312
-                    );
313
-                    $msg[] = sprintf(
314
-                        esc_html__(
315
-                            'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref',
316
-                            'event_espresso'
317
-                        ),
318
-                        '<strong>' . $this->caller . '</strong>',
319
-                        $ref
320
-                    );
321
-                    throw new EE_Error(implode('||', $msg));
322
-                }
323
-                // made it here so let's do the appropriate registration
324
-                $type == 'js'
325
-                    ? wp_register_script($ref, $url, $depends, $version, $footer)
326
-                    : wp_register_style(
327
-                        $ref,
328
-                        $url,
329
-                        $depends,
330
-                        $version
331
-                    );
332
-            }
333
-            // k now let's do the enqueues
334
-            if (! isset($this->_scripts_styles['enqueues'])) {
335
-                return;
336
-            }  //not sure if we should throw an error here or not.
337
-
338
-            foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) {
339
-                // make sure $routes is an array
340
-                $routes = (array) $routes;
341
-                if (in_array($this->_current_route, $routes)) {
342
-                    $this->_scripts_styles['registers'][ $ref ]['type'] == 'js' ? wp_enqueue_script($ref)
343
-                        : wp_enqueue_style($ref);
344
-                    // if we have a localization for the script let's do that too.
345
-                    if (isset($this->_scripts_styles['localize'][ $ref ])) {
346
-                        foreach ($this->_scripts_styles['localize'][ $ref ] as $object_name => $indexes) {
347
-                            wp_localize_script(
348
-                                $ref,
349
-                                $object_name,
350
-                                $this->_scripts_styles['localize'][ $ref ][ $object_name ]
351
-                            );
352
-                        }
353
-                    }
354
-                }
355
-            }
356
-            // let's do the deregisters
357
-            if (! isset($this->_scripts_styles['deregisters'])) {
358
-                return;
359
-            }
360
-            foreach ($this->_scripts_styles['deregisters'] as $ref => $details) {
361
-                $defaults = ['type' => 'js'];
362
-                $details  = wp_parse_args($details, $defaults);
363
-                $details['type'] === 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref);
364
-            }
365
-        }
366
-    }
367
-
368
-
369
-    /**
370
-     * just set the defaults for the hooks properties.
371
-     *
372
-     * @return void
373
-     */
374
-    private function _set_defaults()
375
-    {
376
-        $this->_ajax_func                  = [];
377
-        $this->_init_func                  = [];
378
-        $this->_metaboxes                  = [];
379
-        $this->_scripts                    = [];
380
-        $this->_styles                     = [];
381
-        $this->_wp_action_filters_priority = [];
382
-        $this->_current_route              = $this->getCurrentRoute();
383
-        $this->caller                      = get_class($this);
384
-        $this->_extend                     = (bool) stripos($this->caller, 'Extend');
385
-    }
386
-
387
-
388
-    /**
389
-     * A helper for determining the current route.
390
-     *
391
-     * @return string
392
-     */
393
-    private function getCurrentRoute()
394
-    {
395
-        $action = $this->request->getRequestParam('action');
396
-        // list tables do something else with 'action' for bulk actions.
397
-        $action = $action !== '-1' && $action !== '' ? $action : 'default';
398
-        $route  = $this->request->getRequestParam('route');
399
-        // we set a 'route' variable in some cases where action is being used by something else.
400
-        return $action === 'default' && $route !== '' ? $route : $action;
401
-    }
402
-
403
-
404
-    /**
405
-     * this sets the _page_object property
406
-     *
407
-     * @return void
408
-     * @throws EE_Error
409
-     */
410
-    protected function _set_page_object()
411
-    {
412
-        if ($this->_page_object instanceof EE_Admin_Page) {
413
-            return;
414
-        }
415
-        // first make sure $this->_name is set
416
-        if (empty($this->_name)) {
417
-            $msg[] = esc_html__('We can\'t load the page object', 'event_espresso');
418
-            $msg[] = sprintf(
419
-                esc_html__("This is because the %s child class has not set the '_name' property", 'event_espresso'),
420
-                $this->caller
421
-            );
422
-            throw new EE_Error(implode('||', $msg));
423
-        }
424
-        // change "the_message" to "the message"
425
-        $class_name = str_replace('_', ' ', $this->_name);
426
-        // change "the message" to "The_Message_Admin_Page"
427
-        $class_name = str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page';
428
-        // first default file (if exists)
429
-        $decaf_file = EE_ADMIN_PAGES . $this->_name . '/' . $class_name . '.core.php';
430
-        if (is_readable($decaf_file)) {
431
-            require_once($decaf_file);
432
-        }
433
-        // now we have to do require for extended file (if needed)
434
-        if ($this->_extend) {
435
-            require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . '/Extend_' . $class_name . '.core.php');
436
-            // and extend the class name as well
437
-            $class_name = 'Extend_' . $class_name;
438
-        }
439
-        // let's make sure the class exists
440
-        if (! class_exists($class_name)) {
441
-            $msg[] = esc_html__('We can\'t load the page object', 'event_espresso');
442
-            $msg[] = sprintf(
443
-                esc_html__(
444
-                    'The class name that was given is %s. Check the spelling and make sure its correct, also there needs to be an autoloader setup for the class',
445
-                    'event_espresso'
446
-                ),
447
-                $class_name
448
-            );
449
-            throw new EE_Error(implode('||', $msg));
450
-        }
451
-        $this->_page_object = LoaderFactory::getLoader()->getShared($class_name, [false]);
452
-        $this->_page_object->initializePage();
453
-    }
454
-
455
-
456
-    /**
457
-     * Child "hook" classes can declare any methods that they want executed when a specific page route is loaded.  The
458
-     * advantage of this is when doing things like running our own db interactions on saves etc.  Remember that
459
-     * $this->_req_data (all the _POST and _GET data) is available to your methods.
460
-     *
461
-     * @return void
462
-     */
463
-    private function _load_custom_methods()
464
-    {
465
-        /**
466
-         * method cannot be named 'default' (@see http://us3.php
467
-         * .net/manual/en/reserved.keywords.php) so need to
468
-         * handle routes that are "default"
469
-         *
470
-         * @since 4.3.0
471
-         */
472
-        $method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route;
473
-        // these run before the Admin_Page route executes.
474
-        if (method_exists($this, $method_callback)) {
475
-            call_user_func([$this, $method_callback]);
476
-        }
477
-        // these run via the _redirect_after_action method in EE_Admin_Page which usually happens after non_UI methods in EE_Admin_Page classes.  There are two redirect actions, the first fires before $query_args might be manipulated by "save and close" actions and the seond fires right before the actual redirect happens.
478
-        // first the actions
479
-        // note that these action hooks will have the $query_args value available.
480
-        $admin_class_name = get_class($this->_adminpage_obj);
481
-        if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) {
482
-            add_action(
483
-                'AHEE__'
484
-                . $admin_class_name
485
-                . '___redirect_after_action__before_redirect_modification_'
486
-                . $this->_current_route,
487
-                [$this, '_redirect_action_early_' . $this->_current_route],
488
-                10
489
-            );
490
-        }
491
-        if (method_exists($this, '_redirect_action_' . $this->_current_route)) {
492
-            add_action(
493
-                'AHEE_redirect_' . $admin_class_name . $this->_current_route,
494
-                [$this, '_redirect_action_' . $this->_current_route],
495
-                10
496
-            );
497
-        }
498
-        // let's hook into the _redirect itself and allow for changing where the user goes after redirect.  This will have $query_args and $redirect_url available.
499
-        if (method_exists($this, '_redirect_filter_' . $this->_current_route)) {
500
-            add_filter(
501
-                'FHEE_redirect_' . $admin_class_name . $this->_current_route,
502
-                [$this, '_redirect_filter_' . $this->_current_route],
503
-                10,
504
-                2
505
-            );
506
-        }
507
-    }
508
-
509
-
510
-    /**
511
-     * This method will search for a corresponding method with a name matching the route and the wp_hook to run.  This
512
-     * allows child hook classes to target hooking into a specific wp action or filter hook ONLY on a certain route.
513
-     * just remember, methods MUST be public Future hooks should be added in here to be access by child classes.
514
-     *
515
-     * @return void
516
-     */
517
-    private function _load_routed_hooks()
518
-    {
519
-
520
-        // this array provides the hook action names that will be referenced.  Key is the action. Value is an array with the type (action or filter) and the number of parameters for the hook.  We'll default all priorities for automatic hooks to 10.
521
-        $hook_filter_array = [
522
-            'admin_footer'                                                                            => [
523
-                'type'     => 'action',
524
-                'argnum'   => 1,
525
-                'priority' => 10,
526
-            ],
527
-            'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => [
528
-                'type'     => 'filter',
529
-                'argnum'   => 1,
530
-                'priority' => 10,
531
-            ],
532
-            'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug                               => [
533
-                'type'     => 'filter',
534
-                'argnum'   => 1,
535
-                'priority' => 10,
536
-            ],
537
-            'FHEE_list_table_views'                                                                   => [
538
-                'type'     => 'filter',
539
-                'argnum'   => 1,
540
-                'priority' => 10,
541
-            ],
542
-            'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'                              => [
543
-                'type'     => 'action',
544
-                'argnum'   => 1,
545
-                'priority' => 10,
546
-            ],
547
-        ];
548
-        foreach ($hook_filter_array as $hook => $args) {
549
-            if (method_exists($this, $this->_current_route . '_' . $hook)) {
550
-                if (isset($this->_wp_action_filters_priority[ $hook ])) {
551
-                    $args['priority'] = $this->_wp_action_filters_priority[ $hook ];
552
-                }
553
-                if ($args['type'] == 'action') {
554
-                    add_action(
555
-                        $hook,
556
-                        [$this, $this->_current_route . '_' . $hook],
557
-                        $args['priority'],
558
-                        $args['argnum']
559
-                    );
560
-                } else {
561
-                    add_filter(
562
-                        $hook,
563
-                        [$this, $this->_current_route . '_' . $hook],
564
-                        $args['priority'],
565
-                        $args['argnum']
566
-                    );
567
-                }
568
-            }
569
-        }
570
-    }
571
-
572
-
573
-    /**
574
-     * Loop throught the $_ajax_func array and add_actions for the array.
575
-     *
576
-     * @return void
577
-     * @throws EE_Error
578
-     */
579
-    private function _ajax_hooks()
580
-    {
581
-        if (empty($this->_ajax_func)) {
582
-            return;
583
-        } //get out there's nothing to take care of.
584
-        foreach ($this->_ajax_func as $action => $method) {
585
-            // make sure method exists
586
-            if (! method_exists($this, $method)) {
587
-                $msg[] = esc_html__(
588
-                    'There is no corresponding method for the hook labeled in the _ajax_func array',
589
-                    'event_espresso'
590
-                ) . '<br />';
591
-                $msg[] = sprintf(
592
-                    esc_html__(
593
-                        'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
594
-                        'event_espresso'
595
-                    ),
596
-                    $method,
597
-                    $this->caller
598
-                );
599
-                throw new EE_Error(implode('||', $msg));
600
-            }
601
-            add_action('wp_ajax_' . $action, [$this, $method]);
602
-        }
603
-    }
604
-
605
-
606
-    /**
607
-     * Loop throught the $_init_func array and add_actions for the array.
608
-     *
609
-     * @return void
610
-     * @throws EE_Error
611
-     */
612
-    protected function _init_hooks()
613
-    {
614
-        if (empty($this->_init_func)) {
615
-            return;
616
-        }
617
-        // get out there's nothing to take care of.
618
-        // We need to determine what page_route we are on!
619
-        foreach ($this->_init_func as $route => $method) {
620
-            // make sure method exists
621
-            if (! method_exists($this, $method)) {
622
-                $msg[] = esc_html__(
623
-                    'There is no corresponding method for the hook labeled in the _init_func array',
624
-                    'event_espresso'
625
-                ) . '<br />';
626
-                $msg[] = sprintf(
627
-                    esc_html__(
628
-                        'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
629
-                        'event_espresso'
630
-                    ),
631
-                    $method,
632
-                    $this->caller
633
-                );
634
-                throw new EE_Error(implode('||', $msg));
635
-            }
636
-            if ($route == $this->_current_route) {
637
-                add_action('admin_init', [$this, $method]);
638
-            }
639
-        }
640
-    }
641
-
642
-
643
-    /**
644
-     * Loop through the _metaboxes property and add_metaboxes accordingly
645
-     * //todo we could eventually make this a config component class (i.e. new EE_Metabox);
646
-     *
647
-     * @return void
648
-     * @throws EE_Error
649
-     */
650
-    public function add_metaboxes()
651
-    {
652
-        if (empty($this->_metaboxes)) {
653
-            return;
654
-        } //get out we don't have any metaboxes to set for this connection
655
-        $this->_handle_metabox_array($this->_metaboxes);
656
-    }
657
-
658
-
659
-    /**
660
-     * @param array $boxes
661
-     * @param bool  $add
662
-     * @throws EE_Error
663
-     */
664
-    private function _handle_metabox_array(array $boxes, $add = true)
665
-    {
666
-        foreach ($boxes as $box) {
667
-            if (! isset($box['page_route'])) {
668
-                continue;
669
-            }
670
-            // we don't have a valid array
671
-            // let's make sure $box['page_route'] is an array so the "foreach" will work.
672
-            $box['page_route'] = (array) $box['page_route'];
673
-            foreach ($box['page_route'] as $route) {
674
-                if ($route != $this->_current_route) {
675
-                    continue;
676
-                } //get out we only add metaboxes for set route.
677
-                if ($add) {
678
-                    $this->_add_metabox($box);
679
-                } else {
680
-                    $this->_remove_metabox($box);
681
-                }
682
-            }
683
-        }
684
-    }
685
-
686
-
687
-    /**
688
-     * Loop through the _remove_metaboxes property and remove metaboxes accordingly.
689
-     *
690
-     * @return void
691
-     * @throws EE_Error
692
-     */
693
-    public function remove_metaboxes()
694
-    {
695
-        if (empty($this->_remove_metaboxes)) {
696
-            return;
697
-        } //get out there are no metaboxes to remove
698
-        $this->_handle_metabox_array($this->_remove_metaboxes, false);
699
-    }
700
-
701
-
702
-    /**
703
-     * This just handles adding a metabox
704
-     *
705
-     * @param array $args an array of args that have been set for this metabox by the child class
706
-     * @throws EE_Error
707
-     */
708
-    private function _add_metabox($args)
709
-    {
710
-        $current_screen = get_current_screen();
711
-        $screen_id      = is_object($current_screen) ? $current_screen->id : null;
712
-        $func           = isset($args['func']) ? $args['func'] : 'some_invalid_callback';
713
-        // set defaults
714
-        $defaults      = [
715
-            'callback_args' => [],
716
-            'context'       => 'advanced',
717
-            'func'          => $func,
718
-            'id'            => $this->caller . '_' . $func . '_metabox',
719
-            'label'         => $this->caller,
720
-            'page'          => isset($args['page']) ? $args['page'] : $screen_id,
721
-            'priority'      => 'default',
722
-        ];
723
-        $args          = wp_parse_args($args, $defaults);
724
-        $callback_args = $args['callback_args'];
725
-        $context       = $args['context'];
726
-        $func          = $args['func'];
727
-        $id            = $args['id'];
728
-        $label         = $args['label'];
729
-        $page          = $args['page'];
730
-        $priority      = $args['priority'];
731
-        // make sure method exists
732
-        if (! method_exists($this, $func)) {
733
-            $msg[] =
734
-                esc_html__('There is no corresponding method to display the metabox content', 'event_espresso')
735
-                . '<br />';
736
-            $msg[] = sprintf(
737
-                esc_html__(
738
-                    'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
739
-                    'event_espresso'
740
-                ),
741
-                $func,
742
-                $this->caller
743
-            );
744
-            throw new EE_Error(implode('||', $msg));
745
-        }
746
-        // everything checks out so let's add the metabox
747
-        add_meta_box($id, $label, [$this, $func], $page, $context, $priority, $callback_args);
748
-        add_filter(
749
-            "postbox_classes_{$page}_{$id}",
750
-            function ($classes) {
751
-                array_push($classes, 'ee-admin-container');
752
-                return $classes;
753
-            }
754
-        );
755
-    }
756
-
757
-
758
-    private function _remove_metabox($args)
759
-    {
760
-        $current_screen = get_current_screen();
761
-        $screen_id      = is_object($current_screen) ? $current_screen->id : null;
762
-        $func           = isset($args['func']) ? $args['func'] : 'some_invalid_callback';
763
-        // set defaults
764
-        $defaults = [
765
-            'context' => 'default',
766
-            'id'      => isset($args['id'])
767
-                ? $args['id']
768
-                : $this->_current_route . '_' . $this->caller . '_' . $func . '_metabox',
769
-            'screen'  => isset($args['screen']) ? $args['screen'] : $screen_id,
770
-        ];
771
-        $args     = wp_parse_args($args, $defaults);
772
-        $context  = $args['context'];
773
-        $id       = $args['id'];
774
-        $screen   = $args['screen'];
775
-        // everything checks out so lets remove the box!
776
-        remove_meta_box($id, $screen, $context);
777
-    }
17
+	/**
18
+	 * we're just going to use this to hold the name of the caller class (child class name)
19
+	 *
20
+	 * @var string
21
+	 */
22
+	public $caller;
23
+
24
+
25
+	/**
26
+	 * this is just a flag set automatically to indicate whether we've got an extended hook class running (i.e.
27
+	 * espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks).  This flag is
28
+	 * used later to make sure we require the needed files.
29
+	 *
30
+	 * @var bool
31
+	 */
32
+	protected $_extend;
33
+
34
+
35
+	/**
36
+	 * child classes MUST set this property so that the page object can be loaded correctly
37
+	 *
38
+	 * @var string
39
+	 */
40
+	protected $_name;
41
+
42
+
43
+	/**
44
+	 * This is set by child classes and is an associative array of ajax hooks in the format:
45
+	 * array(
46
+	 *    'ajax_action_ref' => 'executing_method'; //must be public
47
+	 * )
48
+	 *
49
+	 * @var array
50
+	 */
51
+	protected $_ajax_func;
52
+
53
+
54
+	/**
55
+	 * This is an array of methods that get executed on a page routes admin_init hook. Use the following format:
56
+	 * array(
57
+	 *    'page_route' => 'executing_method' //must be public
58
+	 * )
59
+	 *
60
+	 * @var array
61
+	 */
62
+	protected $_init_func;
63
+
64
+
65
+	/**
66
+	 * This is an array of methods that output metabox content for the given page route.  Use the following format:
67
+	 * [
68
+	 *      0 => [
69
+	 *          'page_route' => 'string_for_page_route',    must correspond to a page route in the class being connected
70
+	 *                                                      with (i.e. "edit_event") If this is in an array then the
71
+	 *                                                      same params below will be used but the metabox will be
72
+	 *                                                      added to each route.
73
+	 *          'func' =>  'executing_method',              must be public (i.e. public function executing_method
74
+	 *                                                      ($post, $callback_args){} ).
75
+	 *                                                      Note if you include callback args in the array then you
76
+	 *                                                      need to declare them in the method arguments.
77
+	 *          'id' => 'identifier_for_metabox',           so it can be removed by addons
78
+	 *                                                      (optional, class will set it automatically)
79
+	 *          'priority' => 'default',                    default 'default' (optional)
80
+	 *          'label' => esc_html__('Localized Title', 'event_espresso'),
81
+	 *          'context' => 'advanced'                     advanced is default (optional),
82
+	 *      ]
83
+	 *      'callback_args' => array() //any callback args to include (optional)
84
+	 * ]
85
+	 * Why are we indexing numerically?  Because it's possible there may be more than one metabox per page_route.
86
+	 *
87
+	 * @var array
88
+	 */
89
+	protected $_metaboxes;
90
+
91
+
92
+	/**
93
+	 * This is an array of values that indicate any metaboxes we want removed from a given page route.  Usually this is
94
+	 * used when caffeinated functionality is replacing decaffeinated functionality.  Use the following format for the
95
+	 * array: array(
96
+	 *    0 => array(
97
+	 *        'page_route' => 'string_for_page_route' //can be string or array of strings that match a page_route(s)
98
+	 *        that are in the class being connected with (i.e. 'edit', or 'create_new').
99
+	 *        'id' => 'identifier_for_metabox', //what the id is of the metabox being removed
100
+	 *        'context' => 'normal', //the context for the metabox being removed (has to match)
101
+	 *        'screen' => 'screen_id', //(optional), if not included then this class will attempt to remove the metabox
102
+	 *        using the currently loaded screen object->id  however, there may be cases where you have to specify the
103
+	 *        id for the screen the metabox is on.
104
+	 *    )
105
+	 * )
106
+	 *
107
+	 * @var array
108
+	 */
109
+	protected $_remove_metaboxes;
110
+
111
+
112
+	/**
113
+	 * This parent class takes care of loading the scripts and styles if the child class has set the properties for
114
+	 * them in the following format.  Note, the first array index ('register') is for defining all the registers.  The
115
+	 * second array index is for indicating what routes each script/style loads on. array(
116
+	 * 'registers' => array(
117
+	 *        'script_ref' => array( // if more than one script is to be loaded its best to use the 'dependency'
118
+	 *        argument to link scripts together.
119
+	 *            'type' => 'js' // 'js' or 'css' (defaults to js).  This tells us what type of wp_function to use
120
+	 *            'url' => 'http://urltoscript.css.js',
121
+	 *            'depends' => array('jquery'), //an array of dependencies for the scripts. REMEMBER, if a script has
122
+	 *            already been registered elsewhere in the system.  You can just use the depends array to make sure it
123
+	 *            gets loaded before the one you are setting here.
124
+	 *            'footer' => TRUE //defaults to true (styles don't use this parameter)
125
+	 *        ),
126
+	 *    'enqueues' => array( //this time each key corresponds to the script ref followed by an array of page routes
127
+	 *    the script gets enqueued on.
128
+	 *        'script_ref' => array('route_one', 'route_two')
129
+	 *    ),
130
+	 *    'localize' => array( //this allows you to set a localized object.  Indicate which script the object is being
131
+	 *    attached to and then include an array indexed by the name of the object and the array of key/value pairs for
132
+	 *    the object.
133
+	 *        'scrip_ref' => array(
134
+	 *            'NAME_OF_JS_OBJECT' => array(
135
+	 *                'translate_ref' => esc_html__('localized_string', 'event_espresso'),
136
+	 *                'some_data' => 5
137
+	 *            )
138
+	 *        )
139
+	 *    )
140
+	 * )
141
+	 *
142
+	 * @var array
143
+	 */
144
+	protected $_scripts_styles;
145
+
146
+
147
+	/**
148
+	 * This is a property that will contain the current route.
149
+	 *
150
+	 * @var string;
151
+	 */
152
+	protected $_current_route;
153
+
154
+
155
+	/**
156
+	 * this optional property can be set by child classes to override the priority for the automatic action/filter hook
157
+	 * loading in the `_load_routed_hooks()` method.  Please follow this format: array(
158
+	 *    'wp_hook_reference' => 1
159
+	 *    )
160
+	 * )
161
+	 *
162
+	 * @var array
163
+	 */
164
+	protected $_wp_action_filters_priority;
165
+
166
+
167
+	/**
168
+	 * This just holds a merged array of the request vars
169
+	 *
170
+	 * @var array
171
+	 */
172
+	protected $_req_data;
173
+
174
+	/**
175
+	 * @var array
176
+	 */
177
+	protected $_scripts;
178
+
179
+	/**
180
+	 * @var array
181
+	 */
182
+	protected $_styles;
183
+
184
+	/**
185
+	 * This just holds an instance of the page object for this hook
186
+	 *
187
+	 * @var EE_Admin_Page
188
+	 */
189
+	protected $_page_object;
190
+
191
+
192
+	/**
193
+	 * This holds the EE_Admin_Page object from the calling admin page that this object hooks into.
194
+	 *
195
+	 * @var EE_Admin_Page|EE_Admin_Page_CPT
196
+	 */
197
+	protected $_adminpage_obj;
198
+
199
+
200
+	/**
201
+	 * Holds EE_Registry object
202
+	 *
203
+	 * @var EE_Registry
204
+	 */
205
+	protected $EE = null;
206
+
207
+	/**
208
+	 * @var RequestInterface
209
+	 */
210
+	protected $request;
211
+
212
+
213
+	/**
214
+	 * constructor
215
+	 *
216
+	 * @param EE_Admin_Page $admin_page
217
+	 * @throws EE_Error
218
+	 */
219
+	public function __construct(EE_Admin_Page $admin_page)
220
+	{
221
+		$this->_adminpage_obj = $admin_page;
222
+		$this->request        = LoaderFactory::getLoader()->getShared(RequestInterface::class);
223
+		$this->_req_data      = $this->request->requestParams();
224
+		// first let's verify we're on the right page
225
+		if ($this->request->getRequestParam('page') !== $this->_adminpage_obj->page_slug) {
226
+			return;
227
+		}
228
+		$this->_set_defaults();
229
+		$this->_set_hooks_properties();
230
+		// get out nothing more to be done here.
231
+		// allow for extends to modify properties
232
+		if (method_exists($this, '_extend_properties')) {
233
+			$this->_extend_properties();
234
+		}
235
+		$this->_set_page_object();
236
+		$this->_init_hooks();
237
+		$this->_load_custom_methods();
238
+		$this->_load_routed_hooks();
239
+		add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts_styles']);
240
+		add_action('admin_enqueue_scripts', [$this, 'add_metaboxes'], 20);
241
+		add_action('admin_enqueue_scripts', [$this, 'remove_metaboxes'], 15);
242
+		$this->_ajax_hooks();
243
+	}
244
+
245
+
246
+	/**
247
+	 * used by child classes to set the following properties:
248
+	 * $_ajax_func (optional)
249
+	 * $_init_func (optional)
250
+	 * $_metaboxes (optional)
251
+	 * $_scripts (optional)
252
+	 * $_styles (optional)
253
+	 * $_name (required)
254
+	 * Also in this method will be registered any scripts or styles loaded on the targeted page (as indicated in the
255
+	 * _scripts/_styles properties) Also children should place in this method any filters/actions that have to happen
256
+	 * really early on page load (just after admin_init) if they want to have them registered for handling early.
257
+	 *
258
+	 * @abstract
259
+	 * @return void
260
+	 */
261
+	abstract protected function _set_hooks_properties();
262
+
263
+
264
+	/**
265
+	 * The hooks for enqueue_scripts and enqueue_styles will be run in here.  Child classes need to define their
266
+	 * scripts and styles in the relevant $_scripts and $_styles properties.  Child classes must have also already
267
+	 * registered the scripts and styles using wp_register_script and wp_register_style functions.
268
+	 *
269
+	 * @return void
270
+	 * @throws EE_Error
271
+	 */
272
+	public function enqueue_scripts_styles()
273
+	{
274
+		if (! empty($this->_scripts_styles)) {
275
+			// first let's do all the registrations
276
+			if (! isset($this->_scripts_styles['registers'])) {
277
+				$msg[] = esc_html__(
278
+					'There is no "registers" index in the <code>$this->_scripts_styles</code> property.',
279
+					'event_espresso'
280
+				);
281
+				$msg[] = sprintf(
282
+					esc_html__(
283
+						'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child',
284
+						'event_espresso'
285
+					),
286
+					'<strong>' . $this->caller . '</strong>'
287
+				);
288
+				throw new EE_Error(implode('||', $msg));
289
+			}
290
+			$defaults = [
291
+				'type'    => 'js',
292
+				'url'     => '',
293
+				'depends' => [],
294
+				'version' => EVENT_ESPRESSO_VERSION,
295
+				'footer'  => true,
296
+			];
297
+			foreach ($this->_scripts_styles['registers'] as $ref => $details) {
298
+				$details = wp_parse_args($details, $defaults);
299
+				$type    = $details['type'];
300
+				$url     = $details['url'];
301
+				$depends = $details['depends'];
302
+				$version = $details['version'];
303
+				$footer  = $details['footer'];
304
+				// let's make sure that we set the 'registers' type if it's not set!
305
+				// We need it later to determine which enqueue we do
306
+				$this->_scripts_styles['registers'][ $ref ]['type'] = $type;
307
+				// let's make sure we're not missing any REQUIRED parameters
308
+				if (empty($url)) {
309
+					$msg[] = sprintf(
310
+						esc_html__('Missing the url for the requested %s', 'event_espresso'),
311
+						$type == 'js' ? 'script' : 'stylesheet'
312
+					);
313
+					$msg[] = sprintf(
314
+						esc_html__(
315
+							'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref',
316
+							'event_espresso'
317
+						),
318
+						'<strong>' . $this->caller . '</strong>',
319
+						$ref
320
+					);
321
+					throw new EE_Error(implode('||', $msg));
322
+				}
323
+				// made it here so let's do the appropriate registration
324
+				$type == 'js'
325
+					? wp_register_script($ref, $url, $depends, $version, $footer)
326
+					: wp_register_style(
327
+						$ref,
328
+						$url,
329
+						$depends,
330
+						$version
331
+					);
332
+			}
333
+			// k now let's do the enqueues
334
+			if (! isset($this->_scripts_styles['enqueues'])) {
335
+				return;
336
+			}  //not sure if we should throw an error here or not.
337
+
338
+			foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) {
339
+				// make sure $routes is an array
340
+				$routes = (array) $routes;
341
+				if (in_array($this->_current_route, $routes)) {
342
+					$this->_scripts_styles['registers'][ $ref ]['type'] == 'js' ? wp_enqueue_script($ref)
343
+						: wp_enqueue_style($ref);
344
+					// if we have a localization for the script let's do that too.
345
+					if (isset($this->_scripts_styles['localize'][ $ref ])) {
346
+						foreach ($this->_scripts_styles['localize'][ $ref ] as $object_name => $indexes) {
347
+							wp_localize_script(
348
+								$ref,
349
+								$object_name,
350
+								$this->_scripts_styles['localize'][ $ref ][ $object_name ]
351
+							);
352
+						}
353
+					}
354
+				}
355
+			}
356
+			// let's do the deregisters
357
+			if (! isset($this->_scripts_styles['deregisters'])) {
358
+				return;
359
+			}
360
+			foreach ($this->_scripts_styles['deregisters'] as $ref => $details) {
361
+				$defaults = ['type' => 'js'];
362
+				$details  = wp_parse_args($details, $defaults);
363
+				$details['type'] === 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref);
364
+			}
365
+		}
366
+	}
367
+
368
+
369
+	/**
370
+	 * just set the defaults for the hooks properties.
371
+	 *
372
+	 * @return void
373
+	 */
374
+	private function _set_defaults()
375
+	{
376
+		$this->_ajax_func                  = [];
377
+		$this->_init_func                  = [];
378
+		$this->_metaboxes                  = [];
379
+		$this->_scripts                    = [];
380
+		$this->_styles                     = [];
381
+		$this->_wp_action_filters_priority = [];
382
+		$this->_current_route              = $this->getCurrentRoute();
383
+		$this->caller                      = get_class($this);
384
+		$this->_extend                     = (bool) stripos($this->caller, 'Extend');
385
+	}
386
+
387
+
388
+	/**
389
+	 * A helper for determining the current route.
390
+	 *
391
+	 * @return string
392
+	 */
393
+	private function getCurrentRoute()
394
+	{
395
+		$action = $this->request->getRequestParam('action');
396
+		// list tables do something else with 'action' for bulk actions.
397
+		$action = $action !== '-1' && $action !== '' ? $action : 'default';
398
+		$route  = $this->request->getRequestParam('route');
399
+		// we set a 'route' variable in some cases where action is being used by something else.
400
+		return $action === 'default' && $route !== '' ? $route : $action;
401
+	}
402
+
403
+
404
+	/**
405
+	 * this sets the _page_object property
406
+	 *
407
+	 * @return void
408
+	 * @throws EE_Error
409
+	 */
410
+	protected function _set_page_object()
411
+	{
412
+		if ($this->_page_object instanceof EE_Admin_Page) {
413
+			return;
414
+		}
415
+		// first make sure $this->_name is set
416
+		if (empty($this->_name)) {
417
+			$msg[] = esc_html__('We can\'t load the page object', 'event_espresso');
418
+			$msg[] = sprintf(
419
+				esc_html__("This is because the %s child class has not set the '_name' property", 'event_espresso'),
420
+				$this->caller
421
+			);
422
+			throw new EE_Error(implode('||', $msg));
423
+		}
424
+		// change "the_message" to "the message"
425
+		$class_name = str_replace('_', ' ', $this->_name);
426
+		// change "the message" to "The_Message_Admin_Page"
427
+		$class_name = str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page';
428
+		// first default file (if exists)
429
+		$decaf_file = EE_ADMIN_PAGES . $this->_name . '/' . $class_name . '.core.php';
430
+		if (is_readable($decaf_file)) {
431
+			require_once($decaf_file);
432
+		}
433
+		// now we have to do require for extended file (if needed)
434
+		if ($this->_extend) {
435
+			require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . '/Extend_' . $class_name . '.core.php');
436
+			// and extend the class name as well
437
+			$class_name = 'Extend_' . $class_name;
438
+		}
439
+		// let's make sure the class exists
440
+		if (! class_exists($class_name)) {
441
+			$msg[] = esc_html__('We can\'t load the page object', 'event_espresso');
442
+			$msg[] = sprintf(
443
+				esc_html__(
444
+					'The class name that was given is %s. Check the spelling and make sure its correct, also there needs to be an autoloader setup for the class',
445
+					'event_espresso'
446
+				),
447
+				$class_name
448
+			);
449
+			throw new EE_Error(implode('||', $msg));
450
+		}
451
+		$this->_page_object = LoaderFactory::getLoader()->getShared($class_name, [false]);
452
+		$this->_page_object->initializePage();
453
+	}
454
+
455
+
456
+	/**
457
+	 * Child "hook" classes can declare any methods that they want executed when a specific page route is loaded.  The
458
+	 * advantage of this is when doing things like running our own db interactions on saves etc.  Remember that
459
+	 * $this->_req_data (all the _POST and _GET data) is available to your methods.
460
+	 *
461
+	 * @return void
462
+	 */
463
+	private function _load_custom_methods()
464
+	{
465
+		/**
466
+		 * method cannot be named 'default' (@see http://us3.php
467
+		 * .net/manual/en/reserved.keywords.php) so need to
468
+		 * handle routes that are "default"
469
+		 *
470
+		 * @since 4.3.0
471
+		 */
472
+		$method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route;
473
+		// these run before the Admin_Page route executes.
474
+		if (method_exists($this, $method_callback)) {
475
+			call_user_func([$this, $method_callback]);
476
+		}
477
+		// these run via the _redirect_after_action method in EE_Admin_Page which usually happens after non_UI methods in EE_Admin_Page classes.  There are two redirect actions, the first fires before $query_args might be manipulated by "save and close" actions and the seond fires right before the actual redirect happens.
478
+		// first the actions
479
+		// note that these action hooks will have the $query_args value available.
480
+		$admin_class_name = get_class($this->_adminpage_obj);
481
+		if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) {
482
+			add_action(
483
+				'AHEE__'
484
+				. $admin_class_name
485
+				. '___redirect_after_action__before_redirect_modification_'
486
+				. $this->_current_route,
487
+				[$this, '_redirect_action_early_' . $this->_current_route],
488
+				10
489
+			);
490
+		}
491
+		if (method_exists($this, '_redirect_action_' . $this->_current_route)) {
492
+			add_action(
493
+				'AHEE_redirect_' . $admin_class_name . $this->_current_route,
494
+				[$this, '_redirect_action_' . $this->_current_route],
495
+				10
496
+			);
497
+		}
498
+		// let's hook into the _redirect itself and allow for changing where the user goes after redirect.  This will have $query_args and $redirect_url available.
499
+		if (method_exists($this, '_redirect_filter_' . $this->_current_route)) {
500
+			add_filter(
501
+				'FHEE_redirect_' . $admin_class_name . $this->_current_route,
502
+				[$this, '_redirect_filter_' . $this->_current_route],
503
+				10,
504
+				2
505
+			);
506
+		}
507
+	}
508
+
509
+
510
+	/**
511
+	 * This method will search for a corresponding method with a name matching the route and the wp_hook to run.  This
512
+	 * allows child hook classes to target hooking into a specific wp action or filter hook ONLY on a certain route.
513
+	 * just remember, methods MUST be public Future hooks should be added in here to be access by child classes.
514
+	 *
515
+	 * @return void
516
+	 */
517
+	private function _load_routed_hooks()
518
+	{
519
+
520
+		// this array provides the hook action names that will be referenced.  Key is the action. Value is an array with the type (action or filter) and the number of parameters for the hook.  We'll default all priorities for automatic hooks to 10.
521
+		$hook_filter_array = [
522
+			'admin_footer'                                                                            => [
523
+				'type'     => 'action',
524
+				'argnum'   => 1,
525
+				'priority' => 10,
526
+			],
527
+			'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => [
528
+				'type'     => 'filter',
529
+				'argnum'   => 1,
530
+				'priority' => 10,
531
+			],
532
+			'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug                               => [
533
+				'type'     => 'filter',
534
+				'argnum'   => 1,
535
+				'priority' => 10,
536
+			],
537
+			'FHEE_list_table_views'                                                                   => [
538
+				'type'     => 'filter',
539
+				'argnum'   => 1,
540
+				'priority' => 10,
541
+			],
542
+			'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'                              => [
543
+				'type'     => 'action',
544
+				'argnum'   => 1,
545
+				'priority' => 10,
546
+			],
547
+		];
548
+		foreach ($hook_filter_array as $hook => $args) {
549
+			if (method_exists($this, $this->_current_route . '_' . $hook)) {
550
+				if (isset($this->_wp_action_filters_priority[ $hook ])) {
551
+					$args['priority'] = $this->_wp_action_filters_priority[ $hook ];
552
+				}
553
+				if ($args['type'] == 'action') {
554
+					add_action(
555
+						$hook,
556
+						[$this, $this->_current_route . '_' . $hook],
557
+						$args['priority'],
558
+						$args['argnum']
559
+					);
560
+				} else {
561
+					add_filter(
562
+						$hook,
563
+						[$this, $this->_current_route . '_' . $hook],
564
+						$args['priority'],
565
+						$args['argnum']
566
+					);
567
+				}
568
+			}
569
+		}
570
+	}
571
+
572
+
573
+	/**
574
+	 * Loop throught the $_ajax_func array and add_actions for the array.
575
+	 *
576
+	 * @return void
577
+	 * @throws EE_Error
578
+	 */
579
+	private function _ajax_hooks()
580
+	{
581
+		if (empty($this->_ajax_func)) {
582
+			return;
583
+		} //get out there's nothing to take care of.
584
+		foreach ($this->_ajax_func as $action => $method) {
585
+			// make sure method exists
586
+			if (! method_exists($this, $method)) {
587
+				$msg[] = esc_html__(
588
+					'There is no corresponding method for the hook labeled in the _ajax_func array',
589
+					'event_espresso'
590
+				) . '<br />';
591
+				$msg[] = sprintf(
592
+					esc_html__(
593
+						'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
594
+						'event_espresso'
595
+					),
596
+					$method,
597
+					$this->caller
598
+				);
599
+				throw new EE_Error(implode('||', $msg));
600
+			}
601
+			add_action('wp_ajax_' . $action, [$this, $method]);
602
+		}
603
+	}
604
+
605
+
606
+	/**
607
+	 * Loop throught the $_init_func array and add_actions for the array.
608
+	 *
609
+	 * @return void
610
+	 * @throws EE_Error
611
+	 */
612
+	protected function _init_hooks()
613
+	{
614
+		if (empty($this->_init_func)) {
615
+			return;
616
+		}
617
+		// get out there's nothing to take care of.
618
+		// We need to determine what page_route we are on!
619
+		foreach ($this->_init_func as $route => $method) {
620
+			// make sure method exists
621
+			if (! method_exists($this, $method)) {
622
+				$msg[] = esc_html__(
623
+					'There is no corresponding method for the hook labeled in the _init_func array',
624
+					'event_espresso'
625
+				) . '<br />';
626
+				$msg[] = sprintf(
627
+					esc_html__(
628
+						'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
629
+						'event_espresso'
630
+					),
631
+					$method,
632
+					$this->caller
633
+				);
634
+				throw new EE_Error(implode('||', $msg));
635
+			}
636
+			if ($route == $this->_current_route) {
637
+				add_action('admin_init', [$this, $method]);
638
+			}
639
+		}
640
+	}
641
+
642
+
643
+	/**
644
+	 * Loop through the _metaboxes property and add_metaboxes accordingly
645
+	 * //todo we could eventually make this a config component class (i.e. new EE_Metabox);
646
+	 *
647
+	 * @return void
648
+	 * @throws EE_Error
649
+	 */
650
+	public function add_metaboxes()
651
+	{
652
+		if (empty($this->_metaboxes)) {
653
+			return;
654
+		} //get out we don't have any metaboxes to set for this connection
655
+		$this->_handle_metabox_array($this->_metaboxes);
656
+	}
657
+
658
+
659
+	/**
660
+	 * @param array $boxes
661
+	 * @param bool  $add
662
+	 * @throws EE_Error
663
+	 */
664
+	private function _handle_metabox_array(array $boxes, $add = true)
665
+	{
666
+		foreach ($boxes as $box) {
667
+			if (! isset($box['page_route'])) {
668
+				continue;
669
+			}
670
+			// we don't have a valid array
671
+			// let's make sure $box['page_route'] is an array so the "foreach" will work.
672
+			$box['page_route'] = (array) $box['page_route'];
673
+			foreach ($box['page_route'] as $route) {
674
+				if ($route != $this->_current_route) {
675
+					continue;
676
+				} //get out we only add metaboxes for set route.
677
+				if ($add) {
678
+					$this->_add_metabox($box);
679
+				} else {
680
+					$this->_remove_metabox($box);
681
+				}
682
+			}
683
+		}
684
+	}
685
+
686
+
687
+	/**
688
+	 * Loop through the _remove_metaboxes property and remove metaboxes accordingly.
689
+	 *
690
+	 * @return void
691
+	 * @throws EE_Error
692
+	 */
693
+	public function remove_metaboxes()
694
+	{
695
+		if (empty($this->_remove_metaboxes)) {
696
+			return;
697
+		} //get out there are no metaboxes to remove
698
+		$this->_handle_metabox_array($this->_remove_metaboxes, false);
699
+	}
700
+
701
+
702
+	/**
703
+	 * This just handles adding a metabox
704
+	 *
705
+	 * @param array $args an array of args that have been set for this metabox by the child class
706
+	 * @throws EE_Error
707
+	 */
708
+	private function _add_metabox($args)
709
+	{
710
+		$current_screen = get_current_screen();
711
+		$screen_id      = is_object($current_screen) ? $current_screen->id : null;
712
+		$func           = isset($args['func']) ? $args['func'] : 'some_invalid_callback';
713
+		// set defaults
714
+		$defaults      = [
715
+			'callback_args' => [],
716
+			'context'       => 'advanced',
717
+			'func'          => $func,
718
+			'id'            => $this->caller . '_' . $func . '_metabox',
719
+			'label'         => $this->caller,
720
+			'page'          => isset($args['page']) ? $args['page'] : $screen_id,
721
+			'priority'      => 'default',
722
+		];
723
+		$args          = wp_parse_args($args, $defaults);
724
+		$callback_args = $args['callback_args'];
725
+		$context       = $args['context'];
726
+		$func          = $args['func'];
727
+		$id            = $args['id'];
728
+		$label         = $args['label'];
729
+		$page          = $args['page'];
730
+		$priority      = $args['priority'];
731
+		// make sure method exists
732
+		if (! method_exists($this, $func)) {
733
+			$msg[] =
734
+				esc_html__('There is no corresponding method to display the metabox content', 'event_espresso')
735
+				. '<br />';
736
+			$msg[] = sprintf(
737
+				esc_html__(
738
+					'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
739
+					'event_espresso'
740
+				),
741
+				$func,
742
+				$this->caller
743
+			);
744
+			throw new EE_Error(implode('||', $msg));
745
+		}
746
+		// everything checks out so let's add the metabox
747
+		add_meta_box($id, $label, [$this, $func], $page, $context, $priority, $callback_args);
748
+		add_filter(
749
+			"postbox_classes_{$page}_{$id}",
750
+			function ($classes) {
751
+				array_push($classes, 'ee-admin-container');
752
+				return $classes;
753
+			}
754
+		);
755
+	}
756
+
757
+
758
+	private function _remove_metabox($args)
759
+	{
760
+		$current_screen = get_current_screen();
761
+		$screen_id      = is_object($current_screen) ? $current_screen->id : null;
762
+		$func           = isset($args['func']) ? $args['func'] : 'some_invalid_callback';
763
+		// set defaults
764
+		$defaults = [
765
+			'context' => 'default',
766
+			'id'      => isset($args['id'])
767
+				? $args['id']
768
+				: $this->_current_route . '_' . $this->caller . '_' . $func . '_metabox',
769
+			'screen'  => isset($args['screen']) ? $args['screen'] : $screen_id,
770
+		];
771
+		$args     = wp_parse_args($args, $defaults);
772
+		$context  = $args['context'];
773
+		$id       = $args['id'];
774
+		$screen   = $args['screen'];
775
+		// everything checks out so lets remove the box!
776
+		remove_meta_box($id, $screen, $context);
777
+	}
778 778
 }
Please login to merge, or discard this patch.