Completed
Branch BUG/delete-event (aaf513)
by
unknown
06:37 queued 04:39
created
core/libraries/plugin_api/EE_Register_Messages_Template_Pack.lib.php 2 patches
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -12,201 +12,201 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * Holds values for registered template pack
17
-     *
18
-     * @since 4.5.0
19
-     *
20
-     * @var array
21
-     */
22
-    protected static $_registry = [];
23
-
24
-
25
-    /**
26
-     * Used to register a new template pack with the messages system.
27
-     *
28
-     * Template packs are primarily defined via class extending EE_Messages_Template_Pack and are typically used to
29
-     * change entire layouts for a set of message templates.  This method is used to register the new template pack and
30
-     * automatically have it loaded in the appropriate places.
31
-     *
32
-     * This registry also verifies that there isn't already a template pack registered with the same name and if there
33
-     * is then it will add an EE_Error notice.
34
-     *
35
-     * Note that this only handles registering the your Template Pack class with the message template pack system.
36
-     * However, there is also a naming schema you must follow for templates you are providing with your template pack.
37
-     *
38
-     * @param string $identifier The internal reference used to refer to this template pack.  Note, this is first come,
39
-     *                           first serve.  If there is already a template pack registered with this name then the
40
-     *                           registry will assign a unique reference for it so it can still be activated (but this
41
-     *                           makes it harder to deregister as it will be unique per load - so its best to try to
42
-     *                           make this a unique string!)
43
-     * @param array  $setup_args array {
44
-     *                           An array of required values for registering the template pack.
45
-     * @type string  $path       The path for the new template pack class.
46
-     * @type string  $classname  The name of the new Template Pack Class.
47
-     *                           }
48
-     *
49
-     * @return void
50
-     * @throws EE_Error
51
-     *
52
-     * @see    core/libraries/messages/defaults/default/* for all the example templates the default template pack
53
-     *         supports.
54
-     *
55
-     *
56
-     * @since  4.5.0
57
-     * @see    EE_Messages_Template_Pack_Default for an example class
58
-     */
59
-    public static function register($identifier = '', array $setup_args = [])
60
-    {
61
-
62
-        // check for required params
63
-        if (empty($identifier) || empty($setup_args['path']) || empty($setup_args['classname'])) {
64
-            throw new EE_Error(
65
-                __(
66
-                    'In order to register a new template pack for the EE Messages system, you must include a value to reference the template pack being registered and the setup_args must have the path for the new template pack class as well as the classname for the new Template Pack Class. ',
67
-                    'event_espresso'
68
-                )
69
-            );
70
-        }
71
-
72
-        // make sure we don't register twice
73
-        if (isset(self::$_registry[ $identifier ])) {
74
-            return;
75
-        }
76
-
77
-        // check that incoming $identifier doesn't already exist. If it does then we'll create a unique reference for this template pack.
78
-        if (isset(self::$_registry[ $identifier ])) {
79
-            $identifier = uniqid() . '_' . $identifier;
80
-        }
81
-
82
-
83
-        // make sure this was called in the right place!
84
-        if (! did_action('EE_Brewing_Regular___messages_caf')
85
-            || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
86
-        ) {
87
-            EE_Error::doing_it_wrong(
88
-                __METHOD__,
89
-                sprintf(
90
-                    __(
91
-                        'A EE Messages Template Pack given the reference "%s" has been attempted to be registered with the EE Messages System.  It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.',
92
-                        'event_espresso'
93
-                    ),
94
-                    $identifier
95
-                ),
96
-                '4.5.0'
97
-            );
98
-        }
99
-
100
-        if (self::_verify_class_not_exist($setup_args['classname'])) {
101
-            self::$_registry[ $identifier ] = [
102
-                'path'      => (string) $setup_args['path'],
103
-                'classname' => (string) $setup_args['classname'],
104
-            ];
105
-        }
106
-
107
-        // hook into the system
108
-        add_filter(
109
-            'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
110
-            ['EE_Register_Messages_Template_Pack', 'set_template_pack_path'],
111
-            10
112
-        );
113
-        add_filter(
114
-            'FHEE__EED_Messages__get_template_packs__template_packs',
115
-            ['EE_Register_Messages_Template_Pack', 'set_template_pack'],
116
-            10
117
-        );
118
-    }
119
-
120
-
121
-    /**
122
-     * Callback for the FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.  This adds this template packs path
123
-     * to the messages autoloader paths.
124
-     *
125
-     * @param array $paths Array of paths already registered with the messages autoloader
126
-     *
127
-     * @return array
128
-     * @since  4.5.0
129
-     *
130
-     */
131
-    public static function set_template_pack_path(array $paths)
132
-    {
133
-        foreach (self::$_registry as $args) {
134
-            $paths[] = $args['path'];
135
-        }
136
-        return $paths;
137
-    }
138
-
139
-
140
-    /**
141
-     * Callback for the FHEE__EED_Messages__get_template_packs__template_packs filter. This adds the instantiated,
142
-     * registered template pack to the template packs array when requested by client code.
143
-     *
144
-     * @param EE_Messages_Template_Pack[] $template_packs
145
-     * @return EE_Messages_Template_Pack[]
146
-     * @since 4.5.0
147
-     *
148
-     */
149
-    public static function set_template_pack(array $template_packs)
150
-    {
151
-        foreach (self::$_registry as $args) {
152
-            // verify class_exists
153
-            if (! class_exists($args['classname'])) {
154
-                require_once($args['path'] . '/' . $args['classname'] . '.class.php');
155
-            }
156
-
157
-            // check again!
158
-            if (class_exists($args['classname'])) {
159
-                $template_pack                           = new $args['classname'];
160
-                $template_packs[ $template_pack->dbref ] = $template_pack;
161
-            }
162
-        }
163
-
164
-        return $template_packs;
165
-    }
166
-
167
-
168
-    /**
169
-     * This verifies that the classes for each registered template pack are unique  names.
170
-     *
171
-     * @param string $classname The classname being checked
172
-     *
173
-     * @return bool
174
-     */
175
-    private static function _verify_class_not_exist($classname)
176
-    {
177
-        // loop through the existing registry and see if the classname is already present.
178
-        foreach (self::$_registry as $args) {
179
-            if ($args['classname'] == $classname) {
180
-                EE_Error::add_error(
181
-                    sprintf(
182
-                        __(
183
-                            'The %s template pack that you just activated cannot be registered with the messages system because there is already a template pack active using the same classname.  Contact the author of this template pack to let them know of the conflict.  To stop seeing this message you will need to deactivate this template pack.',
184
-                            'event_espresso'
185
-                        ),
186
-                        $classname
187
-                    ),
188
-                    __FILE__,
189
-                    __LINE__,
190
-                    __FUNCTION__
191
-                );
192
-                return false;
193
-            }
194
-        }
195
-        return true;
196
-    }
197
-
198
-
199
-    /**
200
-     * This deregisters a variation set that was previously registered with the given slug.
201
-     *
202
-     * @param string $identifier The name for the variation set that was previously registered.
203
-     *
204
-     * @return void
205
-     * @since 4.5.0
206
-     *
207
-     */
208
-    public static function deregister($identifier = '')
209
-    {
210
-        unset(self::$_registry[ $identifier ]);
211
-    }
15
+	/**
16
+	 * Holds values for registered template pack
17
+	 *
18
+	 * @since 4.5.0
19
+	 *
20
+	 * @var array
21
+	 */
22
+	protected static $_registry = [];
23
+
24
+
25
+	/**
26
+	 * Used to register a new template pack with the messages system.
27
+	 *
28
+	 * Template packs are primarily defined via class extending EE_Messages_Template_Pack and are typically used to
29
+	 * change entire layouts for a set of message templates.  This method is used to register the new template pack and
30
+	 * automatically have it loaded in the appropriate places.
31
+	 *
32
+	 * This registry also verifies that there isn't already a template pack registered with the same name and if there
33
+	 * is then it will add an EE_Error notice.
34
+	 *
35
+	 * Note that this only handles registering the your Template Pack class with the message template pack system.
36
+	 * However, there is also a naming schema you must follow for templates you are providing with your template pack.
37
+	 *
38
+	 * @param string $identifier The internal reference used to refer to this template pack.  Note, this is first come,
39
+	 *                           first serve.  If there is already a template pack registered with this name then the
40
+	 *                           registry will assign a unique reference for it so it can still be activated (but this
41
+	 *                           makes it harder to deregister as it will be unique per load - so its best to try to
42
+	 *                           make this a unique string!)
43
+	 * @param array  $setup_args array {
44
+	 *                           An array of required values for registering the template pack.
45
+	 * @type string  $path       The path for the new template pack class.
46
+	 * @type string  $classname  The name of the new Template Pack Class.
47
+	 *                           }
48
+	 *
49
+	 * @return void
50
+	 * @throws EE_Error
51
+	 *
52
+	 * @see    core/libraries/messages/defaults/default/* for all the example templates the default template pack
53
+	 *         supports.
54
+	 *
55
+	 *
56
+	 * @since  4.5.0
57
+	 * @see    EE_Messages_Template_Pack_Default for an example class
58
+	 */
59
+	public static function register($identifier = '', array $setup_args = [])
60
+	{
61
+
62
+		// check for required params
63
+		if (empty($identifier) || empty($setup_args['path']) || empty($setup_args['classname'])) {
64
+			throw new EE_Error(
65
+				__(
66
+					'In order to register a new template pack for the EE Messages system, you must include a value to reference the template pack being registered and the setup_args must have the path for the new template pack class as well as the classname for the new Template Pack Class. ',
67
+					'event_espresso'
68
+				)
69
+			);
70
+		}
71
+
72
+		// make sure we don't register twice
73
+		if (isset(self::$_registry[ $identifier ])) {
74
+			return;
75
+		}
76
+
77
+		// check that incoming $identifier doesn't already exist. If it does then we'll create a unique reference for this template pack.
78
+		if (isset(self::$_registry[ $identifier ])) {
79
+			$identifier = uniqid() . '_' . $identifier;
80
+		}
81
+
82
+
83
+		// make sure this was called in the right place!
84
+		if (! did_action('EE_Brewing_Regular___messages_caf')
85
+			|| did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
86
+		) {
87
+			EE_Error::doing_it_wrong(
88
+				__METHOD__,
89
+				sprintf(
90
+					__(
91
+						'A EE Messages Template Pack given the reference "%s" has been attempted to be registered with the EE Messages System.  It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.',
92
+						'event_espresso'
93
+					),
94
+					$identifier
95
+				),
96
+				'4.5.0'
97
+			);
98
+		}
99
+
100
+		if (self::_verify_class_not_exist($setup_args['classname'])) {
101
+			self::$_registry[ $identifier ] = [
102
+				'path'      => (string) $setup_args['path'],
103
+				'classname' => (string) $setup_args['classname'],
104
+			];
105
+		}
106
+
107
+		// hook into the system
108
+		add_filter(
109
+			'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
110
+			['EE_Register_Messages_Template_Pack', 'set_template_pack_path'],
111
+			10
112
+		);
113
+		add_filter(
114
+			'FHEE__EED_Messages__get_template_packs__template_packs',
115
+			['EE_Register_Messages_Template_Pack', 'set_template_pack'],
116
+			10
117
+		);
118
+	}
119
+
120
+
121
+	/**
122
+	 * Callback for the FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.  This adds this template packs path
123
+	 * to the messages autoloader paths.
124
+	 *
125
+	 * @param array $paths Array of paths already registered with the messages autoloader
126
+	 *
127
+	 * @return array
128
+	 * @since  4.5.0
129
+	 *
130
+	 */
131
+	public static function set_template_pack_path(array $paths)
132
+	{
133
+		foreach (self::$_registry as $args) {
134
+			$paths[] = $args['path'];
135
+		}
136
+		return $paths;
137
+	}
138
+
139
+
140
+	/**
141
+	 * Callback for the FHEE__EED_Messages__get_template_packs__template_packs filter. This adds the instantiated,
142
+	 * registered template pack to the template packs array when requested by client code.
143
+	 *
144
+	 * @param EE_Messages_Template_Pack[] $template_packs
145
+	 * @return EE_Messages_Template_Pack[]
146
+	 * @since 4.5.0
147
+	 *
148
+	 */
149
+	public static function set_template_pack(array $template_packs)
150
+	{
151
+		foreach (self::$_registry as $args) {
152
+			// verify class_exists
153
+			if (! class_exists($args['classname'])) {
154
+				require_once($args['path'] . '/' . $args['classname'] . '.class.php');
155
+			}
156
+
157
+			// check again!
158
+			if (class_exists($args['classname'])) {
159
+				$template_pack                           = new $args['classname'];
160
+				$template_packs[ $template_pack->dbref ] = $template_pack;
161
+			}
162
+		}
163
+
164
+		return $template_packs;
165
+	}
166
+
167
+
168
+	/**
169
+	 * This verifies that the classes for each registered template pack are unique  names.
170
+	 *
171
+	 * @param string $classname The classname being checked
172
+	 *
173
+	 * @return bool
174
+	 */
175
+	private static function _verify_class_not_exist($classname)
176
+	{
177
+		// loop through the existing registry and see if the classname is already present.
178
+		foreach (self::$_registry as $args) {
179
+			if ($args['classname'] == $classname) {
180
+				EE_Error::add_error(
181
+					sprintf(
182
+						__(
183
+							'The %s template pack that you just activated cannot be registered with the messages system because there is already a template pack active using the same classname.  Contact the author of this template pack to let them know of the conflict.  To stop seeing this message you will need to deactivate this template pack.',
184
+							'event_espresso'
185
+						),
186
+						$classname
187
+					),
188
+					__FILE__,
189
+					__LINE__,
190
+					__FUNCTION__
191
+				);
192
+				return false;
193
+			}
194
+		}
195
+		return true;
196
+	}
197
+
198
+
199
+	/**
200
+	 * This deregisters a variation set that was previously registered with the given slug.
201
+	 *
202
+	 * @param string $identifier The name for the variation set that was previously registered.
203
+	 *
204
+	 * @return void
205
+	 * @since 4.5.0
206
+	 *
207
+	 */
208
+	public static function deregister($identifier = '')
209
+	{
210
+		unset(self::$_registry[ $identifier ]);
211
+	}
212 212
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -70,18 +70,18 @@  discard block
 block discarded – undo
70 70
         }
71 71
 
72 72
         // make sure we don't register twice
73
-        if (isset(self::$_registry[ $identifier ])) {
73
+        if (isset(self::$_registry[$identifier])) {
74 74
             return;
75 75
         }
76 76
 
77 77
         // check that incoming $identifier doesn't already exist. If it does then we'll create a unique reference for this template pack.
78
-        if (isset(self::$_registry[ $identifier ])) {
79
-            $identifier = uniqid() . '_' . $identifier;
78
+        if (isset(self::$_registry[$identifier])) {
79
+            $identifier = uniqid().'_'.$identifier;
80 80
         }
81 81
 
82 82
 
83 83
         // make sure this was called in the right place!
84
-        if (! did_action('EE_Brewing_Regular___messages_caf')
84
+        if ( ! did_action('EE_Brewing_Regular___messages_caf')
85 85
             || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
86 86
         ) {
87 87
             EE_Error::doing_it_wrong(
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
         }
99 99
 
100 100
         if (self::_verify_class_not_exist($setup_args['classname'])) {
101
-            self::$_registry[ $identifier ] = [
101
+            self::$_registry[$identifier] = [
102 102
                 'path'      => (string) $setup_args['path'],
103 103
                 'classname' => (string) $setup_args['classname'],
104 104
             ];
@@ -150,14 +150,14 @@  discard block
 block discarded – undo
150 150
     {
151 151
         foreach (self::$_registry as $args) {
152 152
             // verify class_exists
153
-            if (! class_exists($args['classname'])) {
154
-                require_once($args['path'] . '/' . $args['classname'] . '.class.php');
153
+            if ( ! class_exists($args['classname'])) {
154
+                require_once($args['path'].'/'.$args['classname'].'.class.php');
155 155
             }
156 156
 
157 157
             // check again!
158 158
             if (class_exists($args['classname'])) {
159 159
                 $template_pack                           = new $args['classname'];
160
-                $template_packs[ $template_pack->dbref ] = $template_pack;
160
+                $template_packs[$template_pack->dbref] = $template_pack;
161 161
             }
162 162
         }
163 163
 
@@ -207,6 +207,6 @@  discard block
 block discarded – undo
207 207
      */
208 208
     public static function deregister($identifier = '')
209 209
     {
210
-        unset(self::$_registry[ $identifier ]);
210
+        unset(self::$_registry[$identifier]);
211 211
     }
212 212
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Config.lib.php 2 patches
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -12,114 +12,114 @@
 block discarded – undo
12 12
 class EE_Register_Config implements EEI_Plugin_API
13 13
 {
14 14
 
15
-    /**
16
-     * Holds registered EE_Config items
17
-     *
18
-     * @var array
19
-     */
20
-    protected static $_ee_config_registry = [];
15
+	/**
16
+	 * Holds registered EE_Config items
17
+	 *
18
+	 * @var array
19
+	 */
20
+	protected static $_ee_config_registry = [];
21 21
 
22 22
 
23
-    /**
24
-     * Handles registering the new config with the EE_Config::instance()->addons property
25
-     *
26
-     * @param string $identifier                          The name of the Config class being registered.
27
-     *                                                    Note this class must extend EE_Config Base and must have
28
-     *                                                    already been registered with an autoloader.
29
-     * @param array  $setup_args                          {
30
-     *
31
-     * @type  string $config_name                         Optional.  by default the new config will be registered to
32
-     *        EE_Config::instance()->addons->{config_class}, but supplying a "config_name" will set the property name
33
-     *        that this variable is accessible by. ie: EE_Config::instance()->addons->{config_name}
34
-     *                            }
35
-     * @return void
36
-     * @throws EE_Error
37
-     *
38
-     * @since    4.3.0
39
-     */
40
-    public static function register($identifier = '', array $setup_args = [])
41
-    {
23
+	/**
24
+	 * Handles registering the new config with the EE_Config::instance()->addons property
25
+	 *
26
+	 * @param string $identifier                          The name of the Config class being registered.
27
+	 *                                                    Note this class must extend EE_Config Base and must have
28
+	 *                                                    already been registered with an autoloader.
29
+	 * @param array  $setup_args                          {
30
+	 *
31
+	 * @type  string $config_name                         Optional.  by default the new config will be registered to
32
+	 *        EE_Config::instance()->addons->{config_class}, but supplying a "config_name" will set the property name
33
+	 *        that this variable is accessible by. ie: EE_Config::instance()->addons->{config_name}
34
+	 *                            }
35
+	 * @return void
36
+	 * @throws EE_Error
37
+	 *
38
+	 * @since    4.3.0
39
+	 */
40
+	public static function register($identifier = '', array $setup_args = [])
41
+	{
42 42
 
43
-        $setup_args['config_name']    = isset($setup_args['config_name']) && ! empty($setup_args['config_name'])
44
-            ? $setup_args['config_name'] : $identifier;
45
-        $setup_args['config_section'] = isset($setup_args['config_section']) && ! empty($setup_args['config_section'])
46
-            ? $setup_args['config_section'] : 'addons';
43
+		$setup_args['config_name']    = isset($setup_args['config_name']) && ! empty($setup_args['config_name'])
44
+			? $setup_args['config_name'] : $identifier;
45
+		$setup_args['config_section'] = isset($setup_args['config_section']) && ! empty($setup_args['config_section'])
46
+			? $setup_args['config_section'] : 'addons';
47 47
 
48
-        // required fields MUST be present, so let's make sure they are.
49
-        if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['config_name'])) {
50
-            throw new EE_Error(
51
-                __(
52
-                    'In order to register a Config Class with EE_Register_Config::register(), you must include a "config_class" (the actual class name for this config class). As well, you can supply an array containing the following keys: "config_section" the main section of the config object the settings will be saved under (by default the new config will be registered under EE_Config::instance()->modules or EE_Config::instance()->addons depending on what type of class is calling this), "config_name" (by default the new config will be registered to EE_Config::instance()->{config_section}->{config_class}, but supplying a "config_name" will set the property name that this variable is accessible by. ie: EE_Config::instance()->{config_section}->{config_name})',
53
-                    'event_espresso'
54
-                )
55
-            );
56
-        }
48
+		// required fields MUST be present, so let's make sure they are.
49
+		if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['config_name'])) {
50
+			throw new EE_Error(
51
+				__(
52
+					'In order to register a Config Class with EE_Register_Config::register(), you must include a "config_class" (the actual class name for this config class). As well, you can supply an array containing the following keys: "config_section" the main section of the config object the settings will be saved under (by default the new config will be registered under EE_Config::instance()->modules or EE_Config::instance()->addons depending on what type of class is calling this), "config_name" (by default the new config will be registered to EE_Config::instance()->{config_section}->{config_class}, but supplying a "config_name" will set the property name that this variable is accessible by. ie: EE_Config::instance()->{config_section}->{config_name})',
53
+					'event_espresso'
54
+				)
55
+			);
56
+		}
57 57
 
58
-        // make sure we don't register twice
59
-        if (isset(self::$_ee_config_registry[ $identifier ])) {
60
-            return;
61
-        }
58
+		// make sure we don't register twice
59
+		if (isset(self::$_ee_config_registry[ $identifier ])) {
60
+			return;
61
+		}
62 62
 
63 63
 
64
-        // first find out if this happened too late.
65
-        if (did_action('AHEE__EE_System__load_core_configuration__begin')) {
66
-            EE_Error::doing_it_wrong(
67
-                __METHOD__,
68
-                sprintf(
69
-                    __(
70
-                        'An attempt to register "%s" as an EE_Config object has failed because it was not registered at the correct hookpoint.  Please register before the "AHEE__EE_System__load_core_configuration__begin" hook has fired',
71
-                        'event_espresso'
72
-                    ),
73
-                    $setup_args['config_name']
74
-                ),
75
-                '4.3'
76
-            );
77
-        }
78
-        // add incoming stuff to our registry property
79
-        self::$_ee_config_registry[ $identifier ] = [
80
-            'section' => $setup_args['config_section'],
81
-            'name'    => $setup_args['config_name'],
82
-        ];
64
+		// first find out if this happened too late.
65
+		if (did_action('AHEE__EE_System__load_core_configuration__begin')) {
66
+			EE_Error::doing_it_wrong(
67
+				__METHOD__,
68
+				sprintf(
69
+					__(
70
+						'An attempt to register "%s" as an EE_Config object has failed because it was not registered at the correct hookpoint.  Please register before the "AHEE__EE_System__load_core_configuration__begin" hook has fired',
71
+						'event_espresso'
72
+					),
73
+					$setup_args['config_name']
74
+				),
75
+				'4.3'
76
+			);
77
+		}
78
+		// add incoming stuff to our registry property
79
+		self::$_ee_config_registry[ $identifier ] = [
80
+			'section' => $setup_args['config_section'],
81
+			'name'    => $setup_args['config_name'],
82
+		];
83 83
 
84
-        add_action('AHEE__EE_Config___load_core_config__end', ['EE_Register_Config', 'set_config'], 15, 1);
85
-        add_action('AHEE__EE_Config__update_espresso_config__end', ['EE_Register_Config', 'set_config'], 15, 1);
86
-    }
84
+		add_action('AHEE__EE_Config___load_core_config__end', ['EE_Register_Config', 'set_config'], 15, 1);
85
+		add_action('AHEE__EE_Config__update_espresso_config__end', ['EE_Register_Config', 'set_config'], 15, 1);
86
+	}
87 87
 
88 88
 
89
-    /**
90
-     * Callback for the AHEE__EE_Config___load_core_config__end hook.
91
-     * basically just calls EE_Config->get_config() which will take care of loading or creating our config object for us
92
-     *
93
-     * @param EE_Config $EE_Config
94
-     * @return void
95
-     * @throws EE_Error
96
-     * @since    4.3.0
97
-     */
98
-    public static function set_config(EE_Config $EE_Config)
99
-    {
100
-        foreach (self::$_ee_config_registry as $identifier => $settings) {
101
-            // first some validation of our incoming class_name.  We'll throw an error early if its' not registered correctly
102
-            if (! class_exists($identifier)) {
103
-                throw new EE_Error(
104
-                    sprintf(
105
-                        __(
106
-                            'The "%s" config class can not be registered with EE_Config because it does not exist.  Verify that an autoloader has been set for this class',
107
-                            'event_espresso'
108
-                        ),
109
-                        $identifier
110
-                    )
111
-                );
112
-            }
113
-            $EE_Config->get_config($settings['section'], $settings['name'], $identifier);
114
-        }
115
-    }
89
+	/**
90
+	 * Callback for the AHEE__EE_Config___load_core_config__end hook.
91
+	 * basically just calls EE_Config->get_config() which will take care of loading or creating our config object for us
92
+	 *
93
+	 * @param EE_Config $EE_Config
94
+	 * @return void
95
+	 * @throws EE_Error
96
+	 * @since    4.3.0
97
+	 */
98
+	public static function set_config(EE_Config $EE_Config)
99
+	{
100
+		foreach (self::$_ee_config_registry as $identifier => $settings) {
101
+			// first some validation of our incoming class_name.  We'll throw an error early if its' not registered correctly
102
+			if (! class_exists($identifier)) {
103
+				throw new EE_Error(
104
+					sprintf(
105
+						__(
106
+							'The "%s" config class can not be registered with EE_Config because it does not exist.  Verify that an autoloader has been set for this class',
107
+							'event_espresso'
108
+						),
109
+						$identifier
110
+					)
111
+				);
112
+			}
113
+			$EE_Config->get_config($settings['section'], $settings['name'], $identifier);
114
+		}
115
+	}
116 116
 
117 117
 
118
-    /**
119
-     * @param string $identifier
120
-     */
121
-    public static function deregister($identifier = '')
122
-    {
123
-        unset(self::$_ee_config_registry[ $identifier ]);
124
-    }
118
+	/**
119
+	 * @param string $identifier
120
+	 */
121
+	public static function deregister($identifier = '')
122
+	{
123
+		unset(self::$_ee_config_registry[ $identifier ]);
124
+	}
125 125
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
         }
57 57
 
58 58
         // make sure we don't register twice
59
-        if (isset(self::$_ee_config_registry[ $identifier ])) {
59
+        if (isset(self::$_ee_config_registry[$identifier])) {
60 60
             return;
61 61
         }
62 62
 
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
             );
77 77
         }
78 78
         // add incoming stuff to our registry property
79
-        self::$_ee_config_registry[ $identifier ] = [
79
+        self::$_ee_config_registry[$identifier] = [
80 80
             'section' => $setup_args['config_section'],
81 81
             'name'    => $setup_args['config_name'],
82 82
         ];
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
     {
100 100
         foreach (self::$_ee_config_registry as $identifier => $settings) {
101 101
             // first some validation of our incoming class_name.  We'll throw an error early if its' not registered correctly
102
-            if (! class_exists($identifier)) {
102
+            if ( ! class_exists($identifier)) {
103 103
                 throw new EE_Error(
104 104
                     sprintf(
105 105
                         __(
@@ -120,6 +120,6 @@  discard block
 block discarded – undo
120 120
      */
121 121
     public static function deregister($identifier = '')
122 122
     {
123
-        unset(self::$_ee_config_registry[ $identifier ]);
123
+        unset(self::$_ee_config_registry[$identifier]);
124 124
     }
125 125
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_CPT.lib.php 2 patches
Indentation   +228 added lines, -228 removed lines patch added patch discarded remove patch
@@ -13,255 +13,255 @@
 block discarded – undo
13 13
 class EE_Register_CPT implements EEI_Plugin_API
14 14
 {
15 15
 
16
-    /**
17
-     * Holds values for registered variations
18
-     *
19
-     * @since 4.5.0
20
-     *
21
-     * @var array[][][]
22
-     */
23
-    protected static $_registry = [];
16
+	/**
17
+	 * Holds values for registered variations
18
+	 *
19
+	 * @since 4.5.0
20
+	 *
21
+	 * @var array[][][]
22
+	 */
23
+	protected static $_registry = [];
24 24
 
25 25
 
26
-    /**
27
-     * Used to register new CPTs and Taxonomies.
28
-     *
29
-     * @param string $identifier              reference used for the addon registering cpts and cts
30
-     * @param array  $setup_args              {
31
-     *                                        An array of required values for registering the cpts and taxonomies
32
-     * @type array   $cpts                    {
33
-     *                                        An array of cpts and their arguments.(short example below)
34
-     * @return void
35
-     * @throws  EE_Error
36
-     * @see CustomPostTypeDefinitions::setDefinitions for a more complete example.
37
-     *                                        'people' => array(
38
-     *                                        'singular_name' => __('People', 'event_espresso'),
39
-     *                                        'plural_name' => __('People', 'event_espresso'),
40
-     *                                        'singular_slug' => __('people', 'event_espresso'),
41
-     *                                        'plural_slug' => __('peoples', 'event_espresso'),
42
-     *                                        'class_name' => 'EE_People'
43
-     *                                        )
44
-     *                                        },
45
-     * @type array   $cts                     {
46
-     *                                        An array of custom taxonomies and their arguments (short example below).
47
-     * @see CustomTaxonomyDefinitions::setTaxonomies() for a more complete example.
48
-     *                                        'espresso_people_type' => array(
49
-     *                                        'singular_name' => __('People Type', 'event_espresso'),
50
-     *                                        'plural_name' => __('People Types', 'event_espresso'),
51
-     *                                        'args' => array()
52
-     *                                        )
53
-     *                                        },
54
-     * @type array   $default_terms           {
55
-     *                                        An array of terms to set as the default for a given taxonomy and the
56
-     *                                        custom post types applied to.
57
-     *                                        'taxonomy_name' => array(
58
-     *                                        'term' => array( 'cpt_a_name', 'cpt_b_name' )
59
-     *                                        )
60
-     *                                        }
61
-     *                                        }
62
-     */
63
-    public static function register($identifier = '', array $setup_args = [])
64
-    {
26
+	/**
27
+	 * Used to register new CPTs and Taxonomies.
28
+	 *
29
+	 * @param string $identifier              reference used for the addon registering cpts and cts
30
+	 * @param array  $setup_args              {
31
+	 *                                        An array of required values for registering the cpts and taxonomies
32
+	 * @type array   $cpts                    {
33
+	 *                                        An array of cpts and their arguments.(short example below)
34
+	 * @return void
35
+	 * @throws  EE_Error
36
+	 * @see CustomPostTypeDefinitions::setDefinitions for a more complete example.
37
+	 *                                        'people' => array(
38
+	 *                                        'singular_name' => __('People', 'event_espresso'),
39
+	 *                                        'plural_name' => __('People', 'event_espresso'),
40
+	 *                                        'singular_slug' => __('people', 'event_espresso'),
41
+	 *                                        'plural_slug' => __('peoples', 'event_espresso'),
42
+	 *                                        'class_name' => 'EE_People'
43
+	 *                                        )
44
+	 *                                        },
45
+	 * @type array   $cts                     {
46
+	 *                                        An array of custom taxonomies and their arguments (short example below).
47
+	 * @see CustomTaxonomyDefinitions::setTaxonomies() for a more complete example.
48
+	 *                                        'espresso_people_type' => array(
49
+	 *                                        'singular_name' => __('People Type', 'event_espresso'),
50
+	 *                                        'plural_name' => __('People Types', 'event_espresso'),
51
+	 *                                        'args' => array()
52
+	 *                                        )
53
+	 *                                        },
54
+	 * @type array   $default_terms           {
55
+	 *                                        An array of terms to set as the default for a given taxonomy and the
56
+	 *                                        custom post types applied to.
57
+	 *                                        'taxonomy_name' => array(
58
+	 *                                        'term' => array( 'cpt_a_name', 'cpt_b_name' )
59
+	 *                                        )
60
+	 *                                        }
61
+	 *                                        }
62
+	 */
63
+	public static function register($identifier = '', array $setup_args = [])
64
+	{
65 65
 
66
-        // check for required params
67
-        if (empty($identifier)) {
68
-            throw new EE_Error(
69
-                __(
70
-                    'In order to register custom post types and custom taxonomies, you must include a value to reference what had been registered',
71
-                    'event_espresso'
72
-                )
73
-            );
74
-        }
66
+		// check for required params
67
+		if (empty($identifier)) {
68
+			throw new EE_Error(
69
+				__(
70
+					'In order to register custom post types and custom taxonomies, you must include a value to reference what had been registered',
71
+					'event_espresso'
72
+				)
73
+			);
74
+		}
75 75
 
76
-        if (! is_array($setup_args) || (empty($setup_args['cpts']) && empty($setup_args['cts']))) {
77
-            throw new EE_Error(
78
-                __(
79
-                    'In order to register custom post types or custom taxonomies, you must include an array containing either an array of custom post types to register (key "cpts"), an array of custom taxonomies ("cts") or both.',
80
-                    'event_espresso'
81
-                )
82
-            );
83
-        }
76
+		if (! is_array($setup_args) || (empty($setup_args['cpts']) && empty($setup_args['cts']))) {
77
+			throw new EE_Error(
78
+				__(
79
+					'In order to register custom post types or custom taxonomies, you must include an array containing either an array of custom post types to register (key "cpts"), an array of custom taxonomies ("cts") or both.',
80
+					'event_espresso'
81
+				)
82
+			);
83
+		}
84 84
 
85
-        // make sure we don't register twice
86
-        if (isset(self::$_registry[ $identifier ])) {
87
-            return;
88
-        }
85
+		// make sure we don't register twice
86
+		if (isset(self::$_registry[ $identifier ])) {
87
+			return;
88
+		}
89 89
 
90
-        // make sure cpt ref is unique.
91
-        if (isset(self::$_registry[ $identifier ])) {
92
-            $identifier = uniqid() . '_' . $identifier;
93
-        }
90
+		// make sure cpt ref is unique.
91
+		if (isset(self::$_registry[ $identifier ])) {
92
+			$identifier = uniqid() . '_' . $identifier;
93
+		}
94 94
 
95
-        // make sure this was called in the right place!
96
-        if (did_action('AHEE__EE_System__load_CPTs_and_session__complete')) {
97
-            EE_Error::doing_it_wrong(
98
-                __METHOD__,
99
-                sprintf(
100
-                    __(
101
-                        'EE_Register_CPT has been called and given a reference of "%s".  It may or may not work because it should be called on or before "AHEE__EE_System__load_CPTs_and_session__complete" action hook.',
102
-                        'event_espresso'
103
-                    ),
104
-                    $identifier
105
-                ),
106
-                '4.5.0'
107
-            );
108
-        }
109
-        // validate incoming args
110
-        $validated = [
111
-            'cpts'          => isset($setup_args['cpts'])
112
-                ? (array) $setup_args['cpts']
113
-                : [],
114
-            'cts'           => isset($setup_args['cts'])
115
-                ? (array) $setup_args['cts']
116
-                : [],
117
-            'default_terms' => isset($setup_args['default_terms'])
118
-                ? (array) $setup_args['default_terms']
119
-                : [],
120
-        ];
95
+		// make sure this was called in the right place!
96
+		if (did_action('AHEE__EE_System__load_CPTs_and_session__complete')) {
97
+			EE_Error::doing_it_wrong(
98
+				__METHOD__,
99
+				sprintf(
100
+					__(
101
+						'EE_Register_CPT has been called and given a reference of "%s".  It may or may not work because it should be called on or before "AHEE__EE_System__load_CPTs_and_session__complete" action hook.',
102
+						'event_espresso'
103
+					),
104
+					$identifier
105
+				),
106
+				'4.5.0'
107
+			);
108
+		}
109
+		// validate incoming args
110
+		$validated = [
111
+			'cpts'          => isset($setup_args['cpts'])
112
+				? (array) $setup_args['cpts']
113
+				: [],
114
+			'cts'           => isset($setup_args['cts'])
115
+				? (array) $setup_args['cts']
116
+				: [],
117
+			'default_terms' => isset($setup_args['default_terms'])
118
+				? (array) $setup_args['default_terms']
119
+				: [],
120
+		];
121 121
 
122
-        self::$_registry[ $identifier ] = $validated;
122
+		self::$_registry[ $identifier ] = $validated;
123 123
 
124
-        // hook into to cpt system
125
-        add_filter(
126
-            'FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes',
127
-            [__CLASS__, 'filterCustomPostTypeDefinitions'],
128
-            5
129
-        );
130
-        add_filter(
131
-            'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies',
132
-            [__CLASS__, 'filterCustomTaxonomyDefinitions'],
133
-            5
134
-        );
135
-        add_action(
136
-            'AHEE__EventEspresso_core_domain_services_custom_post_types_RegisterCustomTaxonomyTerms__construct_end',
137
-            [__CLASS__, 'registerCustomTaxonomyTerm'],
138
-            5
139
-        );
140
-    }
124
+		// hook into to cpt system
125
+		add_filter(
126
+			'FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes',
127
+			[__CLASS__, 'filterCustomPostTypeDefinitions'],
128
+			5
129
+		);
130
+		add_filter(
131
+			'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies',
132
+			[__CLASS__, 'filterCustomTaxonomyDefinitions'],
133
+			5
134
+		);
135
+		add_action(
136
+			'AHEE__EventEspresso_core_domain_services_custom_post_types_RegisterCustomTaxonomyTerms__construct_end',
137
+			[__CLASS__, 'registerCustomTaxonomyTerm'],
138
+			5
139
+		);
140
+	}
141 141
 
142 142
 
143
-    /**
144
-     * Callback for
145
-     * FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes
146
-     * that adds additional custom post types to be registered.
147
-     *
148
-     * @param array $custom_post_type_definitions array of cpts that are already set
149
-     * @return array new array of cpts and their registration information
150
-     */
151
-    public static function filterCustomPostTypeDefinitions(array $custom_post_type_definitions)
152
-    {
153
-        foreach (self::$_registry as $registries) {
154
-            foreach ($registries['cpts'] as $cpt_name => $cpt_settings) {
155
-                $custom_post_type_definitions[ $cpt_name ] = $cpt_settings;
156
-            }
157
-        }
158
-        return $custom_post_type_definitions;
159
-    }
143
+	/**
144
+	 * Callback for
145
+	 * FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes
146
+	 * that adds additional custom post types to be registered.
147
+	 *
148
+	 * @param array $custom_post_type_definitions array of cpts that are already set
149
+	 * @return array new array of cpts and their registration information
150
+	 */
151
+	public static function filterCustomPostTypeDefinitions(array $custom_post_type_definitions)
152
+	{
153
+		foreach (self::$_registry as $registries) {
154
+			foreach ($registries['cpts'] as $cpt_name => $cpt_settings) {
155
+				$custom_post_type_definitions[ $cpt_name ] = $cpt_settings;
156
+			}
157
+		}
158
+		return $custom_post_type_definitions;
159
+	}
160 160
 
161 161
 
162
-    /**
163
-     * Callback for
164
-     * FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies
165
-     * that adds additional custom taxonomies to be registered.
166
-     *
167
-     * @param array $custom_taxonomy_definitions array of cts that are already set.
168
-     * @return array new array of cts and their registration information.
169
-     */
170
-    public static function filterCustomTaxonomyDefinitions(array $custom_taxonomy_definitions)
171
-    {
172
-        foreach (self::$_registry as $registries) {
173
-            foreach ($registries['cts'] as $ct_name => $ct_settings) {
174
-                $custom_taxonomy_definitions[ $ct_name ] = $ct_settings;
175
-            }
176
-        }
177
-        return $custom_taxonomy_definitions;
178
-    }
162
+	/**
163
+	 * Callback for
164
+	 * FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies
165
+	 * that adds additional custom taxonomies to be registered.
166
+	 *
167
+	 * @param array $custom_taxonomy_definitions array of cts that are already set.
168
+	 * @return array new array of cts and their registration information.
169
+	 */
170
+	public static function filterCustomTaxonomyDefinitions(array $custom_taxonomy_definitions)
171
+	{
172
+		foreach (self::$_registry as $registries) {
173
+			foreach ($registries['cts'] as $ct_name => $ct_settings) {
174
+				$custom_taxonomy_definitions[ $ct_name ] = $ct_settings;
175
+			}
176
+		}
177
+		return $custom_taxonomy_definitions;
178
+	}
179 179
 
180 180
 
181
-    /**
182
-     * Callback for
183
-     * AHEE__EventEspresso_core_domain_services_custom_post_types_RegisterCustomTaxonomyTerms__construct_end
184
-     * which is used to set the default terms
185
-     *
186
-     * @param RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms
187
-     * @return void
188
-     */
189
-    public static function registerCustomTaxonomyTerm(RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms)
190
-    {
191
-        foreach (self::$_registry as $registries) {
192
-            foreach ($registries['default_terms'] as $taxonomy => $terms) {
193
-                foreach ($terms as $term => $cpts) {
194
-                    $register_custom_taxonomy_terms->registerCustomTaxonomyTerm(
195
-                        $taxonomy,
196
-                        $term,
197
-                        $cpts
198
-                    );
199
-                }
200
-            }
201
-        }
202
-    }
181
+	/**
182
+	 * Callback for
183
+	 * AHEE__EventEspresso_core_domain_services_custom_post_types_RegisterCustomTaxonomyTerms__construct_end
184
+	 * which is used to set the default terms
185
+	 *
186
+	 * @param RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms
187
+	 * @return void
188
+	 */
189
+	public static function registerCustomTaxonomyTerm(RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms)
190
+	{
191
+		foreach (self::$_registry as $registries) {
192
+			foreach ($registries['default_terms'] as $taxonomy => $terms) {
193
+				foreach ($terms as $term => $cpts) {
194
+					$register_custom_taxonomy_terms->registerCustomTaxonomyTerm(
195
+						$taxonomy,
196
+						$term,
197
+						$cpts
198
+					);
199
+				}
200
+			}
201
+		}
202
+	}
203 203
 
204 204
 
205
-    /**
206
-     * @param array $cpts array of cpts that are already set
207
-     * @return array new array of cpts and their registration information
208
-     * @deprecated 4.9.62.p
209
-     */
210
-    public static function filter_cpts(array $cpts)
211
-    {
212
-        foreach (self::$_registry as $registries) {
213
-            foreach ($registries['cpts'] as $cpt_name => $cpt_settings) {
214
-                $cpts[ $cpt_name ] = $cpt_settings;
215
-            }
216
-        }
217
-        return $cpts;
218
-    }
205
+	/**
206
+	 * @param array $cpts array of cpts that are already set
207
+	 * @return array new array of cpts and their registration information
208
+	 * @deprecated 4.9.62.p
209
+	 */
210
+	public static function filter_cpts(array $cpts)
211
+	{
212
+		foreach (self::$_registry as $registries) {
213
+			foreach ($registries['cpts'] as $cpt_name => $cpt_settings) {
214
+				$cpts[ $cpt_name ] = $cpt_settings;
215
+			}
216
+		}
217
+		return $cpts;
218
+	}
219 219
 
220 220
 
221
-    /**
222
-     * @param array $cts array of cts that are already set.
223
-     * @return array new array of cts and their registration information.
224
-     * @deprecated 4.9.62.p
225
-     */
226
-    public static function filter_cts(array $cts)
227
-    {
228
-        foreach (self::$_registry as $registries) {
229
-            foreach ($registries['cts'] as $ct_name => $ct_settings) {
230
-                $cts[ $ct_name ] = $ct_settings;
231
-            }
232
-        }
233
-        return $cts;
234
-    }
221
+	/**
222
+	 * @param array $cts array of cts that are already set.
223
+	 * @return array new array of cts and their registration information.
224
+	 * @deprecated 4.9.62.p
225
+	 */
226
+	public static function filter_cts(array $cts)
227
+	{
228
+		foreach (self::$_registry as $registries) {
229
+			foreach ($registries['cts'] as $ct_name => $ct_settings) {
230
+				$cts[ $ct_name ] = $ct_settings;
231
+			}
232
+		}
233
+		return $cts;
234
+	}
235 235
 
236 236
 
237
-    /**
238
-     * @param EE_Register_CPTs $cpt_class
239
-     * @return void
240
-     * @deprecated 4.9.62.p
241
-     */
242
-    public static function default_terms(EE_Register_CPTs $cpt_class)
243
-    {
244
-        foreach (self::$_registry as $registries) {
245
-            foreach ($registries['default_terms'] as $taxonomy => $terms) {
246
-                foreach ($terms as $term => $cpts) {
247
-                    $cpt_class->set_default_term($taxonomy, $term, $cpts);
248
-                }
249
-            }
250
-        }
251
-    }
237
+	/**
238
+	 * @param EE_Register_CPTs $cpt_class
239
+	 * @return void
240
+	 * @deprecated 4.9.62.p
241
+	 */
242
+	public static function default_terms(EE_Register_CPTs $cpt_class)
243
+	{
244
+		foreach (self::$_registry as $registries) {
245
+			foreach ($registries['default_terms'] as $taxonomy => $terms) {
246
+				foreach ($terms as $term => $cpts) {
247
+					$cpt_class->set_default_term($taxonomy, $term, $cpts);
248
+				}
249
+			}
250
+		}
251
+	}
252 252
 
253 253
 
254
-    /**
255
-     * This deregisters whats been registered on this class (for the given slug).
256
-     *
257
-     * @param string $identifier The reference for the item registered to be removed.
258
-     *
259
-     * @return void
260
-     * @since 4.5.0
261
-     *
262
-     */
263
-    public static function deregister($identifier = '')
264
-    {
265
-        unset(self::$_registry[ $identifier ]);
266
-    }
254
+	/**
255
+	 * This deregisters whats been registered on this class (for the given slug).
256
+	 *
257
+	 * @param string $identifier The reference for the item registered to be removed.
258
+	 *
259
+	 * @return void
260
+	 * @since 4.5.0
261
+	 *
262
+	 */
263
+	public static function deregister($identifier = '')
264
+	{
265
+		unset(self::$_registry[ $identifier ]);
266
+	}
267 267
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
             );
74 74
         }
75 75
 
76
-        if (! is_array($setup_args) || (empty($setup_args['cpts']) && empty($setup_args['cts']))) {
76
+        if ( ! is_array($setup_args) || (empty($setup_args['cpts']) && empty($setup_args['cts']))) {
77 77
             throw new EE_Error(
78 78
                 __(
79 79
                     'In order to register custom post types or custom taxonomies, you must include an array containing either an array of custom post types to register (key "cpts"), an array of custom taxonomies ("cts") or both.',
@@ -83,13 +83,13 @@  discard block
 block discarded – undo
83 83
         }
84 84
 
85 85
         // make sure we don't register twice
86
-        if (isset(self::$_registry[ $identifier ])) {
86
+        if (isset(self::$_registry[$identifier])) {
87 87
             return;
88 88
         }
89 89
 
90 90
         // make sure cpt ref is unique.
91
-        if (isset(self::$_registry[ $identifier ])) {
92
-            $identifier = uniqid() . '_' . $identifier;
91
+        if (isset(self::$_registry[$identifier])) {
92
+            $identifier = uniqid().'_'.$identifier;
93 93
         }
94 94
 
95 95
         // make sure this was called in the right place!
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
                 : [],
120 120
         ];
121 121
 
122
-        self::$_registry[ $identifier ] = $validated;
122
+        self::$_registry[$identifier] = $validated;
123 123
 
124 124
         // hook into to cpt system
125 125
         add_filter(
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
     {
153 153
         foreach (self::$_registry as $registries) {
154 154
             foreach ($registries['cpts'] as $cpt_name => $cpt_settings) {
155
-                $custom_post_type_definitions[ $cpt_name ] = $cpt_settings;
155
+                $custom_post_type_definitions[$cpt_name] = $cpt_settings;
156 156
             }
157 157
         }
158 158
         return $custom_post_type_definitions;
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
     {
172 172
         foreach (self::$_registry as $registries) {
173 173
             foreach ($registries['cts'] as $ct_name => $ct_settings) {
174
-                $custom_taxonomy_definitions[ $ct_name ] = $ct_settings;
174
+                $custom_taxonomy_definitions[$ct_name] = $ct_settings;
175 175
             }
176 176
         }
177 177
         return $custom_taxonomy_definitions;
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
     {
212 212
         foreach (self::$_registry as $registries) {
213 213
             foreach ($registries['cpts'] as $cpt_name => $cpt_settings) {
214
-                $cpts[ $cpt_name ] = $cpt_settings;
214
+                $cpts[$cpt_name] = $cpt_settings;
215 215
             }
216 216
         }
217 217
         return $cpts;
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
     {
228 228
         foreach (self::$_registry as $registries) {
229 229
             foreach ($registries['cts'] as $ct_name => $ct_settings) {
230
-                $cts[ $ct_name ] = $ct_settings;
230
+                $cts[$ct_name] = $ct_settings;
231 231
             }
232 232
         }
233 233
         return $cts;
@@ -262,6 +262,6 @@  discard block
 block discarded – undo
262 262
      */
263 263
     public static function deregister($identifier = '')
264 264
     {
265
-        unset(self::$_registry[ $identifier ]);
265
+        unset(self::$_registry[$identifier]);
266 266
     }
267 267
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Addon.lib.php 2 patches
Indentation   +1233 added lines, -1233 removed lines patch added patch discarded remove patch
@@ -22,1237 +22,1237 @@
 block discarded – undo
22 22
 class EE_Register_Addon implements EEI_Plugin_API
23 23
 {
24 24
 
25
-    /**
26
-     * possibly truncated version of the EE core version string
27
-     *
28
-     * @var string
29
-     */
30
-    protected static $_core_version = '';
31
-
32
-    /**
33
-     * Holds values for registered addons
34
-     *
35
-     * @var array
36
-     */
37
-    protected static $_settings = array();
38
-
39
-    /**
40
-     * @var  array $_incompatible_addons keys are addon SLUGS
41
-     * (first argument passed to EE_Register_Addon::register()), keys are
42
-     * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004).
43
-     * Generally this should be used sparingly, as we don't want to muddle up
44
-     * EE core with knowledge of ALL the addons out there.
45
-     * If you want NO versions of an addon to run with a certain version of core,
46
-     * it's usually best to define the addon's "min_core_version" as part of its call
47
-     * to EE_Register_Addon::register(), rather than using this array with a super high value for its
48
-     * minimum plugin version.
49
-     * @access    protected
50
-     */
51
-    protected static $_incompatible_addons = array(
52
-        'Multi_Event_Registration' => '2.0.11.rc.002',
53
-        'Promotions'               => '1.0.0.rc.084',
54
-    );
55
-
56
-
57
-    /**
58
-     * We should always be comparing core to a version like '4.3.0.rc.000',
59
-     * not just '4.3.0'.
60
-     * So if the addon developer doesn't provide that full version string,
61
-     * fill in the blanks for them
62
-     *
63
-     * @param string $min_core_version
64
-     * @return string always like '4.3.0.rc.000'
65
-     */
66
-    protected static function _effective_version($min_core_version)
67
-    {
68
-        // versions: 4 . 3 . 1 . p . 123
69
-        // offsets:    0 . 1 . 2 . 3 . 4
70
-        $version_parts = explode('.', $min_core_version);
71
-        // check they specified the micro version (after 2nd period)
72
-        if (! isset($version_parts[2])) {
73
-            $version_parts[2] = '0';
74
-        }
75
-        // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
76
-        // soon we can assume that's 'rc', but this current version is 'alpha'
77
-        if (! isset($version_parts[3])) {
78
-            $version_parts[3] = 'dev';
79
-        }
80
-        if (! isset($version_parts[4])) {
81
-            $version_parts[4] = '000';
82
-        }
83
-        return implode('.', $version_parts);
84
-    }
85
-
86
-
87
-    /**
88
-     * Returns whether or not the min core version requirement of the addon is met
89
-     *
90
-     * @param string $min_core_version    the minimum core version required by the addon
91
-     * @param string $actual_core_version the actual core version, optional
92
-     * @return boolean
93
-     */
94
-    public static function _meets_min_core_version_requirement(
95
-        $min_core_version,
96
-        $actual_core_version = EVENT_ESPRESSO_VERSION
97
-    ) {
98
-        return version_compare(
99
-            self::_effective_version($actual_core_version),
100
-            self::_effective_version($min_core_version),
101
-            '>='
102
-        );
103
-    }
104
-
105
-
106
-    /**
107
-     * Method for registering new EE_Addons.
108
-     * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE
109
-     * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it
110
-     * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon
111
-     * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after
112
-     * 'activate_plugin', it registers the addon still, but its components are not registered
113
-     * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do
114
-     * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns
115
-     * (so that we can detect that the addon has activated on the subsequent request)
116
-     *
117
-     * @since    4.3.0
118
-     * @param string                  $addon_name                       [Required] the EE_Addon's name.
119
-     * @param  array                  $setup_args                       {
120
-     *                                                                  An array of arguments provided for registering
121
-     *                                                                  the message type.
122
-     * @type  string                  $class_name                       the addon's main file name.
123
-     *                                                                  If left blank, generated from the addon name,
124
-     *                                                                  changes something like "calendar" to
125
-     *                                                                  "EE_Calendar"
126
-     * @type string                   $min_core_version                 the minimum version of EE Core that the
127
-     *                                                                  addon will work with. eg "4.8.1.rc.084"
128
-     * @type string                   $version                          the "software" version for the addon. eg
129
-     *                                                                  "1.0.0.p" for a first stable release, or
130
-     *                                                                  "1.0.0.rc.043" for a version in progress
131
-     * @type string                   $main_file_path                   the full server path to the main file
132
-     *                                                                  loaded directly by WP
133
-     * @type DomainInterface $domain                                    child class of
134
-     *                                                                  EventEspresso\core\domain\DomainBase
135
-     * @type string                   $domain_fqcn                      Fully Qualified Class Name
136
-     *                                                                  for the addon's Domain class
137
-     *                                                                  (see EventEspresso\core\domain\Domain)
138
-     * @type string                   $admin_path                       full server path to the folder where the
139
-     *                                                                  addon\'s admin files reside
140
-     * @type string                   $admin_callback                   a method to be called when the EE Admin is
141
-     *                                                                  first invoked, can be used for hooking into
142
-     *                                                                  any admin page
143
-     * @type string                   $config_section                   the section name for this addon's
144
-     *                                                                  configuration settings section
145
-     *                                                                  (defaults to "addons")
146
-     * @type string                   $config_class                     the class name for this addon's
147
-     *                                                                  configuration settings object
148
-     * @type string                   $config_name                      the class name for this addon's
149
-     *                                                                  configuration settings object
150
-     * @type string                   $autoloader_paths                 [Required] an array of class names and the full
151
-     *                                                                  server paths to those files.
152
-     * @type string                   $autoloader_folders               an array of  "full server paths" for any
153
-     *                                                                  folders containing classes that might be
154
-     *                                                                  invoked by the addon
155
-     * @type string                   $dms_paths                        [Required] an array of full server paths to
156
-     *                                                                  folders that contain data migration scripts.
157
-     *                                                                  The key should be the EE_Addon class name that
158
-     *                                                                  this set of data migration scripts belongs to.
159
-     *                                                                  If the EE_Addon class is namespaced, then this
160
-     *                                                                  needs to be the Fully Qualified Class Name
161
-     * @type string                   $module_paths                     an array of full server paths to any
162
-     *                                                                  EED_Modules used by the addon
163
-     * @type string                   $shortcode_paths                  an array of full server paths to folders
164
-     *                                                                  that contain EES_Shortcodes
165
-     * @type string                   $widget_paths                     an array of full server paths to folders
166
-     *                                                                  that contain WP_Widgets
167
-     * @type string                   $pue_options
168
-     * @type array                    $capabilities                     an array indexed by role name
169
-     *                                                                  (i.e administrator,author ) and the values
170
-     *                                                                  are an array of caps to add to the role.
171
-     *                                                                  'administrator' => array(
172
-     *                                                                  'read_addon',
173
-     *                                                                  'edit_addon',
174
-     *                                                                  etc.
175
-     *                                                                  ).
176
-     * @type EE_Meta_Capability_Map[] $capability_maps                  an array of EE_Meta_Capability_Map object
177
-     *                                                                  for any addons that need to register any
178
-     *                                                                  special meta mapped capabilities.  Should
179
-     *                                                                  be indexed where the key is the
180
-     *                                                                  EE_Meta_Capability_Map class name and the
181
-     *                                                                  values are the arguments sent to the class.
182
-     * @type array                    $model_paths                      array of folders containing DB models
183
-     * @see      EE_Register_Model
184
-     * @type array                    $class_paths                      array of folders containing DB classes
185
-     * @see      EE_Register_Model
186
-     * @type array                    $model_extension_paths            array of folders containing DB model
187
-     *                                                                  extensions
188
-     * @see      EE_Register_Model_Extension
189
-     * @type array                    $class_extension_paths            array of folders containing DB class
190
-     *                                                                  extensions
191
-     * @see      EE_Register_Model_Extension
192
-     * @type array message_types {
193
-     *                                                                  An array of message types with the key as
194
-     *                                                                  the message type name and the values as
195
-     *                                                                  below:
196
-     * @type string                   $mtfilename                       [Required] The filename of the message type
197
-     *                                                                  being registered. This will be the main
198
-     *                                                                  EE_{Message Type Name}_message_type class.
199
-     *                                                                  for example:
200
-     *                                                                  EE_Declined_Registration_message_type.class.php
201
-     * @type array                    $autoloadpaths                    [Required] An array of paths to add to the
202
-     *                                                                  messages autoloader for the new message type.
203
-     * @type array                    $messengers_to_activate_with      An array of messengers that this message
204
-     *                                                                  type should activate with. Each value in
205
-     *                                                                  the
206
-     *                                                                  array
207
-     *                                                                  should match the name property of a
208
-     *                                                                  EE_messenger. Optional.
209
-     * @type array                    $messengers_to_validate_with      An array of messengers that this message
210
-     *                                                                  type should validate with. Each value in
211
-     *                                                                  the
212
-     *                                                                  array
213
-     *                                                                  should match the name property of an
214
-     *                                                                  EE_messenger.
215
-     *                                                                  Optional.
216
-     *                                                                  }
217
-     * @type array                    $custom_post_types
218
-     * @type array                    $custom_taxonomies
219
-     * @type array                    $payment_method_paths             each element is the folder containing the
220
-     *                                                                  EE_PMT_Base child class
221
-     *                                                                  (eg,
222
-     *                                                                  '/wp-content/plugins/my_plugin/Payomatic/'
223
-     *                                                                  which contains the files
224
-     *                                                                  EE_PMT_Payomatic.pm.php)
225
-     * @type array                    $default_terms
226
-     * @type array                    $namespace                        {
227
-     *                                                                  An array with two items for registering the
228
-     *                                                                  addon's namespace. (If, for some reason, you
229
-     *                                                                  require additional namespaces,
230
-     *                                                                  use
231
-     *                                                                  EventEspresso\core\Psr4Autoloader::addNamespace()
232
-     *                                                                  directly)
233
-     * @see      EventEspresso\core\Psr4Autoloader::addNamespace()
234
-     * @type string                   $FQNS                             the namespace prefix
235
-     * @type string                   $DIR                              a base directory for class files in the
236
-     *                                                                  namespace.
237
-     *                                                                  }
238
-     *                                                                  }
239
-     * @type string                   $privacy_policies                 FQNSs (namespaces, each of which contains only
240
-     *                                                                  privacy policy classes) or FQCNs (specific
241
-     *                                                                  classnames of privacy policy classes)
242
-     * @type string                   $personal_data_exporters          FQNSs (namespaces, each of which contains only
243
-     *                                                                  privacy policy classes) or FQCNs (specific
244
-     *                                                                  classnames of privacy policy classes)
245
-     * @type string                   $personal_data_erasers            FQNSs (namespaces, each of which contains only
246
-     *                                                                  privacy policy classes) or FQCNs (specific
247
-     *                                                                  classnames of privacy policy classes)
248
-     * @return void
249
-     * @throws DomainException
250
-     * @throws EE_Error
251
-     * @throws InvalidArgumentException
252
-     * @throws InvalidDataTypeException
253
-     * @throws InvalidInterfaceException
254
-     */
255
-    public static function register($addon_name = '', array $setup_args = array())
256
-    {
257
-        // required fields MUST be present, so let's make sure they are.
258
-        EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
259
-        // get class name for addon
260
-        $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
261
-        // setup $_settings array from incoming values.
262
-        $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
263
-        // setup PUE
264
-        EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
265
-        // does this addon work with this version of core or WordPress ?
266
-        // does this addon work with this version of core or WordPress ?
267
-        if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
268
-            return;
269
-        }
270
-        // register namespaces
271
-        EE_Register_Addon::_setup_namespaces($addon_settings);
272
-        // check if this is an activation request
273
-        if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
274
-            // dont bother setting up the rest of the addon atm
275
-            return;
276
-        }
277
-        // we need cars
278
-        EE_Register_Addon::_setup_autoloaders($addon_name);
279
-        // register new models and extensions
280
-        EE_Register_Addon::_register_models_and_extensions($addon_name);
281
-        // setup DMS
282
-        EE_Register_Addon::_register_data_migration_scripts($addon_name);
283
-        // if config_class is present let's register config.
284
-        EE_Register_Addon::_register_config($addon_name);
285
-        // register admin pages
286
-        EE_Register_Addon::_register_admin_pages($addon_name);
287
-        // add to list of modules to be registered
288
-        EE_Register_Addon::_register_modules($addon_name);
289
-        // add to list of shortcodes to be registered
290
-        EE_Register_Addon::_register_shortcodes($addon_name);
291
-        // add to list of widgets to be registered
292
-        EE_Register_Addon::_register_widgets($addon_name);
293
-        // register capability related stuff.
294
-        EE_Register_Addon::_register_capabilities($addon_name);
295
-        // any message type to register?
296
-        EE_Register_Addon::_register_message_types($addon_name);
297
-        // any custom post type/ custom capabilities or default terms to register
298
-        EE_Register_Addon::_register_custom_post_types($addon_name);
299
-        // and any payment methods
300
-        EE_Register_Addon::_register_payment_methods($addon_name);
301
-        // and privacy policy generators
302
-        EE_Register_Addon::registerPrivacyPolicies($addon_name);
303
-        // and privacy policy generators
304
-        EE_Register_Addon::registerPersonalDataExporters($addon_name);
305
-        // and privacy policy generators
306
-        EE_Register_Addon::registerPersonalDataErasers($addon_name);
307
-        // load and instantiate main addon class
308
-        $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name);
309
-        // delay calling after_registration hook on each addon until after all add-ons have been registered.
310
-        add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999);
311
-    }
312
-
313
-
314
-    /**
315
-     * @param string $addon_name
316
-     * @param array  $setup_args
317
-     * @return void
318
-     * @throws EE_Error
319
-     */
320
-    private static function _verify_parameters($addon_name, array $setup_args)
321
-    {
322
-        // required fields MUST be present, so let's make sure they are.
323
-        if (empty($addon_name) || ! is_array($setup_args)) {
324
-            throw new EE_Error(
325
-                __(
326
-                    'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.',
327
-                    'event_espresso'
328
-                )
329
-            );
330
-        }
331
-        if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
332
-            throw new EE_Error(
333
-                sprintf(
334
-                    __(
335
-                        'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s',
336
-                        'event_espresso'
337
-                    ),
338
-                    implode(',', array_keys($setup_args))
339
-                )
340
-            );
341
-        }
342
-        // check that addon has not already been registered with that name
343
-        if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
344
-            throw new EE_Error(
345
-                sprintf(
346
-                    __(
347
-                        'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
348
-                        'event_espresso'
349
-                    ),
350
-                    $addon_name
351
-                )
352
-            );
353
-        }
354
-    }
355
-
356
-
357
-    /**
358
-     * @param string $addon_name
359
-     * @param array  $setup_args
360
-     * @return string
361
-     */
362
-    private static function _parse_class_name($addon_name, array $setup_args)
363
-    {
364
-        if (empty($setup_args['class_name'])) {
365
-            // generate one by first separating name with spaces
366
-            $class_name = str_replace(array('-', '_'), ' ', trim($addon_name));
367
-            // capitalize, then replace spaces with underscores
368
-            $class_name = str_replace(' ', '_', ucwords($class_name));
369
-        } else {
370
-            $class_name = $setup_args['class_name'];
371
-        }
372
-        // check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
373
-        return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
374
-            ? $class_name
375
-            : 'EE_' . $class_name;
376
-    }
377
-
378
-
379
-    /**
380
-     * @param string $class_name
381
-     * @param array  $setup_args
382
-     * @return array
383
-     */
384
-    private static function _get_addon_settings($class_name, array $setup_args)
385
-    {
386
-        // setup $_settings array from incoming values.
387
-        $addon_settings = array(
388
-            // generated from the addon name, changes something like "calendar" to "EE_Calendar"
389
-            'class_name'            => $class_name,
390
-            // the addon slug for use in URLs, etc
391
-            'plugin_slug'           => isset($setup_args['plugin_slug'])
392
-                ? (string) $setup_args['plugin_slug']
393
-                : '',
394
-            // page slug to be used when generating the "Settings" link on the WP plugin page
395
-            'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
396
-                ? (string) $setup_args['plugin_action_slug']
397
-                : '',
398
-            // the "software" version for the addon
399
-            'version'               => isset($setup_args['version'])
400
-                ? (string) $setup_args['version']
401
-                : '',
402
-            // the minimum version of EE Core that the addon will work with
403
-            'min_core_version'      => isset($setup_args['min_core_version'])
404
-                ? (string) $setup_args['min_core_version']
405
-                : '',
406
-            // the minimum version of WordPress that the addon will work with
407
-            'min_wp_version'        => isset($setup_args['min_wp_version'])
408
-                ? (string) $setup_args['min_wp_version']
409
-                : EE_MIN_WP_VER_REQUIRED,
410
-            // full server path to main file (file loaded directly by WP)
411
-            'main_file_path'        => isset($setup_args['main_file_path'])
412
-                ? (string) $setup_args['main_file_path']
413
-                : '',
414
-            // instance of \EventEspresso\core\domain\DomainInterface
415
-            'domain'                => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface
416
-                ? $setup_args['domain']
417
-                : null,
418
-            // Fully Qualified Class Name for the addon's Domain class
419
-            'domain_fqcn'           => isset($setup_args['domain_fqcn'])
420
-                ? (string) $setup_args['domain_fqcn']
421
-                : '',
422
-            // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
423
-            'admin_path'            => isset($setup_args['admin_path'])
424
-                ? (string) $setup_args['admin_path'] : '',
425
-            // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
426
-            'admin_callback'        => isset($setup_args['admin_callback'])
427
-                ? (string) $setup_args['admin_callback']
428
-                : '',
429
-            // the section name for this addon's configuration settings section (defaults to "addons")
430
-            'config_section'        => isset($setup_args['config_section'])
431
-                ? (string) $setup_args['config_section']
432
-                : 'addons',
433
-            // the class name for this addon's configuration settings object
434
-            'config_class'          => isset($setup_args['config_class'])
435
-                ? (string) $setup_args['config_class'] : '',
436
-            // the name given to the config for this addons' configuration settings object (optional)
437
-            'config_name'           => isset($setup_args['config_name'])
438
-                ? (string) $setup_args['config_name'] : '',
439
-            // an array of "class names" => "full server paths" for any classes that might be invoked by the addon
440
-            'autoloader_paths'      => isset($setup_args['autoloader_paths'])
441
-                ? (array) $setup_args['autoloader_paths']
442
-                : array(),
443
-            // an array of  "full server paths" for any folders containing classes that might be invoked by the addon
444
-            'autoloader_folders'    => isset($setup_args['autoloader_folders'])
445
-                ? (array) $setup_args['autoloader_folders']
446
-                : array(),
447
-            // array of full server paths to any EE_DMS data migration scripts used by the addon.
448
-            // The key should be the EE_Addon class name that this set of data migration scripts belongs to.
449
-            // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name
450
-            'dms_paths'             => isset($setup_args['dms_paths'])
451
-                ? (array) $setup_args['dms_paths']
452
-                : array(),
453
-            // array of full server paths to any EED_Modules used by the addon
454
-            'module_paths'          => isset($setup_args['module_paths'])
455
-                ? (array) $setup_args['module_paths']
456
-                : array(),
457
-            // array of full server paths to any EES_Shortcodes used by the addon
458
-            'shortcode_paths'       => isset($setup_args['shortcode_paths'])
459
-                ? (array) $setup_args['shortcode_paths']
460
-                : array(),
461
-            'shortcode_fqcns'       => isset($setup_args['shortcode_fqcns'])
462
-                ? (array) $setup_args['shortcode_fqcns']
463
-                : array(),
464
-            // array of full server paths to any WP_Widgets used by the addon
465
-            'widget_paths'          => isset($setup_args['widget_paths'])
466
-                ? (array) $setup_args['widget_paths']
467
-                : array(),
468
-            // array of PUE options used by the addon
469
-            'pue_options'           => isset($setup_args['pue_options'])
470
-                ? (array) $setup_args['pue_options']
471
-                : array(),
472
-            'message_types'         => isset($setup_args['message_types'])
473
-                ? (array) $setup_args['message_types']
474
-                : array(),
475
-            'capabilities'          => isset($setup_args['capabilities'])
476
-                ? (array) $setup_args['capabilities']
477
-                : array(),
478
-            'capability_maps'       => isset($setup_args['capability_maps'])
479
-                ? (array) $setup_args['capability_maps']
480
-                : array(),
481
-            'model_paths'           => isset($setup_args['model_paths'])
482
-                ? (array) $setup_args['model_paths']
483
-                : array(),
484
-            'class_paths'           => isset($setup_args['class_paths'])
485
-                ? (array) $setup_args['class_paths']
486
-                : array(),
487
-            'model_extension_paths' => isset($setup_args['model_extension_paths'])
488
-                ? (array) $setup_args['model_extension_paths']
489
-                : array(),
490
-            'class_extension_paths' => isset($setup_args['class_extension_paths'])
491
-                ? (array) $setup_args['class_extension_paths']
492
-                : array(),
493
-            'custom_post_types'     => isset($setup_args['custom_post_types'])
494
-                ? (array) $setup_args['custom_post_types']
495
-                : array(),
496
-            'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
497
-                ? (array) $setup_args['custom_taxonomies']
498
-                : array(),
499
-            'payment_method_paths'  => isset($setup_args['payment_method_paths'])
500
-                ? (array) $setup_args['payment_method_paths']
501
-                : array(),
502
-            'default_terms'         => isset($setup_args['default_terms'])
503
-                ? (array) $setup_args['default_terms']
504
-                : array(),
505
-            // if not empty, inserts a new table row after this plugin's row on the WP Plugins page
506
-            // that can be used for adding upgrading/marketing info
507
-            'plugins_page_row'      => isset($setup_args['plugins_page_row']) ? $setup_args['plugins_page_row'] : '',
508
-            'namespace'             => isset(
509
-                $setup_args['namespace']['FQNS'],
510
-                $setup_args['namespace']['DIR']
511
-            )
512
-                ? (array) $setup_args['namespace']
513
-                : array(),
514
-            'privacy_policies'      => isset($setup_args['privacy_policies'])
515
-                ? (array) $setup_args['privacy_policies']
516
-                : '',
517
-        );
518
-        // if plugin_action_slug is NOT set, but an admin page path IS set,
519
-        // then let's just use the plugin_slug since that will be used for linking to the admin page
520
-        $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
521
-                                                && ! empty($addon_settings['admin_path'])
522
-            ? $addon_settings['plugin_slug']
523
-            : $addon_settings['plugin_action_slug'];
524
-        // full server path to main file (file loaded directly by WP)
525
-        $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
526
-        return $addon_settings;
527
-    }
528
-
529
-
530
-    /**
531
-     * @param string $addon_name
532
-     * @param array  $addon_settings
533
-     * @return boolean
534
-     */
535
-    private static function _addon_is_compatible($addon_name, array $addon_settings)
536
-    {
537
-        global $wp_version;
538
-        $incompatibility_message = '';
539
-        // check whether this addon version is compatible with EE core
540
-        if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
541
-            && ! self::_meets_min_core_version_requirement(
542
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
543
-                $addon_settings['version']
544
-            )
545
-        ) {
546
-            $incompatibility_message = sprintf(
547
-                __(
548
-                    '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.',
549
-                    'event_espresso'
550
-                ),
551
-                $addon_name,
552
-                '<br />',
553
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
554
-                '<span style="font-weight: bold; color: #D54E21;">',
555
-                '</span><br />'
556
-            );
557
-        } elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
558
-        ) {
559
-            $incompatibility_message = sprintf(
560
-                __(
561
-                    '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".',
562
-                    'event_espresso'
563
-                ),
564
-                $addon_name,
565
-                self::_effective_version($addon_settings['min_core_version']),
566
-                self::_effective_version(espresso_version()),
567
-                '<br />',
568
-                '<span style="font-weight: bold; color: #D54E21;">',
569
-                '</span><br />'
570
-            );
571
-        } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
572
-            $incompatibility_message = sprintf(
573
-                __(
574
-                    '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.',
575
-                    'event_espresso'
576
-                ),
577
-                $addon_name,
578
-                $addon_settings['min_wp_version'],
579
-                '<br />',
580
-                '<span style="font-weight: bold; color: #D54E21;">',
581
-                '</span><br />'
582
-            );
583
-        }
584
-        if (! empty($incompatibility_message)) {
585
-            // remove 'activate' from the REQUEST
586
-            // so WP doesn't erroneously tell the user the plugin activated fine when it didn't
587
-            unset($_GET['activate'], $_REQUEST['activate']);
588
-            if (current_user_can('activate_plugins')) {
589
-                // show an error message indicating the plugin didn't activate properly
590
-                EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
591
-            }
592
-            // BAIL FROM THE ADDON REGISTRATION PROCESS
593
-            return false;
594
-        }
595
-        // addon IS compatible
596
-        return true;
597
-    }
598
-
599
-
600
-    /**
601
-     * if plugin update engine is being used for auto-updates,
602
-     * then let's set that up now before going any further so that ALL addons can be updated
603
-     * (not needed if PUE is not being used)
604
-     *
605
-     * @param string $addon_name
606
-     * @param string $class_name
607
-     * @param array  $setup_args
608
-     * @return void
609
-     */
610
-    private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
611
-    {
612
-        if (! empty($setup_args['pue_options'])) {
613
-            self::$_settings[ $addon_name ]['pue_options'] = array(
614
-                'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
615
-                    ? (string) $setup_args['pue_options']['pue_plugin_slug']
616
-                    : 'espresso_' . strtolower($class_name),
617
-                'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
618
-                    ? (string) $setup_args['pue_options']['plugin_basename']
619
-                    : plugin_basename($setup_args['main_file_path']),
620
-                'checkPeriod'     => isset($setup_args['pue_options']['checkPeriod'])
621
-                    ? (string) $setup_args['pue_options']['checkPeriod']
622
-                    : '24',
623
-                'use_wp_update'   => isset($setup_args['pue_options']['use_wp_update'])
624
-                    ? (string) $setup_args['pue_options']['use_wp_update']
625
-                    : false,
626
-            );
627
-            add_action(
628
-                'AHEE__EE_System__brew_espresso__after_pue_init',
629
-                array('EE_Register_Addon', 'load_pue_update')
630
-            );
631
-        }
632
-    }
633
-
634
-
635
-    /**
636
-     * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
637
-     *
638
-     * @param array $addon_settings
639
-     * @return void
640
-     */
641
-    private static function _setup_namespaces(array $addon_settings)
642
-    {
643
-        //
644
-        if (isset(
645
-            $addon_settings['namespace']['FQNS'],
646
-            $addon_settings['namespace']['DIR']
647
-        )) {
648
-            EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
649
-                $addon_settings['namespace']['FQNS'],
650
-                $addon_settings['namespace']['DIR']
651
-            );
652
-        }
653
-    }
654
-
655
-
656
-    /**
657
-     * @param string $addon_name
658
-     * @param array  $addon_settings
659
-     * @return bool
660
-     * @throws InvalidArgumentException
661
-     * @throws InvalidDataTypeException
662
-     * @throws InvalidInterfaceException
663
-     */
664
-    private static function _addon_activation($addon_name, array $addon_settings)
665
-    {
666
-        // this is an activation request
667
-        if (did_action('activate_plugin')) {
668
-            // to find if THIS is the addon that was activated, just check if we have already registered it or not
669
-            // (as the newly-activated addon wasn't around the first time addons were registered).
670
-            // Note: the presence of pue_options in the addon registration options will initialize the $_settings
671
-            // property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
672
-            if (! isset(self::$_settings[ $addon_name ])
673
-                || (isset(self::$_settings[ $addon_name ])
674
-                    && ! isset(self::$_settings[ $addon_name ]['class_name'])
675
-                )
676
-            ) {
677
-                self::$_settings[ $addon_name ] = $addon_settings;
678
-                $addon = self::_load_and_init_addon_class($addon_name);
679
-                $addon->set_activation_indicator_option();
680
-                // dont bother setting up the rest of the addon.
681
-                // we know it was just activated and the request will end soon
682
-            }
683
-            return true;
684
-        }
685
-        // make sure this was called in the right place!
686
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
687
-            || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
688
-        ) {
689
-            EE_Error::doing_it_wrong(
690
-                __METHOD__,
691
-                sprintf(
692
-                    __(
693
-                        'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.',
694
-                        'event_espresso'
695
-                    ),
696
-                    $addon_name
697
-                ),
698
-                '4.3.0'
699
-            );
700
-        }
701
-        // make sure addon settings are set correctly without overwriting anything existing
702
-        if (isset(self::$_settings[ $addon_name ])) {
703
-            self::$_settings[ $addon_name ] += $addon_settings;
704
-        } else {
705
-            self::$_settings[ $addon_name ] = $addon_settings;
706
-        }
707
-        return false;
708
-    }
709
-
710
-
711
-    /**
712
-     * @param string $addon_name
713
-     * @return void
714
-     * @throws EE_Error
715
-     */
716
-    private static function _setup_autoloaders($addon_name)
717
-    {
718
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
719
-            // setup autoloader for single file
720
-            EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
721
-        }
722
-        // setup autoloaders for folders
723
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
724
-            foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
725
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
726
-            }
727
-        }
728
-    }
729
-
730
-
731
-    /**
732
-     * register new models and extensions
733
-     *
734
-     * @param string $addon_name
735
-     * @return void
736
-     * @throws EE_Error
737
-     */
738
-    private static function _register_models_and_extensions($addon_name)
739
-    {
740
-        // register new models
741
-        if (! empty(self::$_settings[ $addon_name ]['model_paths'])
742
-            || ! empty(self::$_settings[ $addon_name ]['class_paths'])
743
-        ) {
744
-            EE_Register_Model::register(
745
-                $addon_name,
746
-                array(
747
-                    'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
748
-                    'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
749
-                )
750
-            );
751
-        }
752
-        // register model extensions
753
-        if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
754
-            || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
755
-        ) {
756
-            EE_Register_Model_Extensions::register(
757
-                $addon_name,
758
-                array(
759
-                    'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
760
-                    'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
761
-                )
762
-            );
763
-        }
764
-    }
765
-
766
-
767
-    /**
768
-     * @param string $addon_name
769
-     * @return void
770
-     * @throws EE_Error
771
-     */
772
-    private static function _register_data_migration_scripts($addon_name)
773
-    {
774
-        // setup DMS
775
-        if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
776
-            EE_Register_Data_Migration_Scripts::register(
777
-                $addon_name,
778
-                array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths'])
779
-            );
780
-        }
781
-    }
782
-
783
-
784
-    /**
785
-     * @param string $addon_name
786
-     * @return void
787
-     * @throws EE_Error
788
-     */
789
-    private static function _register_config($addon_name)
790
-    {
791
-        // if config_class is present let's register config.
792
-        if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
793
-            EE_Register_Config::register(
794
-                self::$_settings[ $addon_name ]['config_class'],
795
-                array(
796
-                    'config_section' => self::$_settings[ $addon_name ]['config_section'],
797
-                    'config_name'    => self::$_settings[ $addon_name ]['config_name'],
798
-                )
799
-            );
800
-        }
801
-    }
802
-
803
-
804
-    /**
805
-     * @param string $addon_name
806
-     * @return void
807
-     * @throws EE_Error
808
-     */
809
-    private static function _register_admin_pages($addon_name)
810
-    {
811
-        if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
812
-            EE_Register_Admin_Page::register(
813
-                $addon_name,
814
-                array('page_path' => self::$_settings[ $addon_name ]['admin_path'])
815
-            );
816
-        }
817
-    }
818
-
819
-
820
-    /**
821
-     * @param string $addon_name
822
-     * @return void
823
-     * @throws EE_Error
824
-     */
825
-    private static function _register_modules($addon_name)
826
-    {
827
-        if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
828
-            EE_Register_Module::register(
829
-                $addon_name,
830
-                array('module_paths' => self::$_settings[ $addon_name ]['module_paths'])
831
-            );
832
-        }
833
-    }
834
-
835
-
836
-    /**
837
-     * @param string $addon_name
838
-     * @return void
839
-     * @throws EE_Error
840
-     */
841
-    private static function _register_shortcodes($addon_name)
842
-    {
843
-        if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
844
-            || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
845
-        ) {
846
-            EE_Register_Shortcode::register(
847
-                $addon_name,
848
-                array(
849
-                    'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths'])
850
-                        ? self::$_settings[ $addon_name ]['shortcode_paths'] : array(),
851
-                    'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns'])
852
-                        ? self::$_settings[ $addon_name ]['shortcode_fqcns'] : array(),
853
-                )
854
-            );
855
-        }
856
-    }
857
-
858
-
859
-    /**
860
-     * @param string $addon_name
861
-     * @return void
862
-     * @throws EE_Error
863
-     */
864
-    private static function _register_widgets($addon_name)
865
-    {
866
-        if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
867
-            EE_Register_Widget::register(
868
-                $addon_name,
869
-                array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths'])
870
-            );
871
-        }
872
-    }
873
-
874
-
875
-    /**
876
-     * @param string $addon_name
877
-     * @return void
878
-     * @throws EE_Error
879
-     */
880
-    private static function _register_capabilities($addon_name)
881
-    {
882
-        if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
883
-            EE_Register_Capabilities::register(
884
-                $addon_name,
885
-                array(
886
-                    'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
887
-                    'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
888
-                )
889
-            );
890
-        }
891
-    }
892
-
893
-
894
-    /**
895
-     * @param string $addon_name
896
-     * @return void
897
-     */
898
-    private static function _register_message_types($addon_name)
899
-    {
900
-        if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
901
-            add_action(
902
-                'EE_Brewing_Regular___messages_caf',
903
-                array('EE_Register_Addon', 'register_message_types')
904
-            );
905
-        }
906
-    }
907
-
908
-
909
-    /**
910
-     * @param string $addon_name
911
-     * @return void
912
-     * @throws EE_Error
913
-     */
914
-    private static function _register_custom_post_types($addon_name)
915
-    {
916
-        if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])
917
-            || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
918
-        ) {
919
-            EE_Register_CPT::register(
920
-                $addon_name,
921
-                array(
922
-                    'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
923
-                    'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
924
-                    'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
925
-                )
926
-            );
927
-        }
928
-    }
929
-
930
-
931
-    /**
932
-     * @param string $addon_name
933
-     * @return void
934
-     * @throws InvalidArgumentException
935
-     * @throws InvalidInterfaceException
936
-     * @throws InvalidDataTypeException
937
-     * @throws DomainException
938
-     * @throws EE_Error
939
-     */
940
-    private static function _register_payment_methods($addon_name)
941
-    {
942
-        if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
943
-            EE_Register_Payment_Method::register(
944
-                $addon_name,
945
-                array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths'])
946
-            );
947
-        }
948
-    }
949
-
950
-
951
-    /**
952
-     * @param string $addon_name
953
-     * @return void
954
-     * @throws InvalidArgumentException
955
-     * @throws InvalidInterfaceException
956
-     * @throws InvalidDataTypeException
957
-     * @throws DomainException
958
-     */
959
-    private static function registerPrivacyPolicies($addon_name)
960
-    {
961
-        if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) {
962
-            EE_Register_Privacy_Policy::register(
963
-                $addon_name,
964
-                self::$_settings[ $addon_name ]['privacy_policies']
965
-            );
966
-        }
967
-    }
968
-
969
-
970
-    /**
971
-     * @param string $addon_name
972
-     * @return void
973
-     */
974
-    private static function registerPersonalDataExporters($addon_name)
975
-    {
976
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) {
977
-            EE_Register_Personal_Data_Eraser::register(
978
-                $addon_name,
979
-                self::$_settings[ $addon_name ]['personal_data_exporters']
980
-            );
981
-        }
982
-    }
983
-
984
-
985
-    /**
986
-     * @param string $addon_name
987
-     * @return void
988
-     */
989
-    private static function registerPersonalDataErasers($addon_name)
990
-    {
991
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) {
992
-            EE_Register_Personal_Data_Eraser::register(
993
-                $addon_name,
994
-                self::$_settings[ $addon_name ]['personal_data_erasers']
995
-            );
996
-        }
997
-    }
998
-
999
-
1000
-    /**
1001
-     * Loads and instantiates the EE_Addon class and adds it onto the registry
1002
-     *
1003
-     * @param string $addon_name
1004
-     * @return EE_Addon
1005
-     * @throws InvalidArgumentException
1006
-     * @throws InvalidInterfaceException
1007
-     * @throws InvalidDataTypeException
1008
-     */
1009
-    private static function _load_and_init_addon_class($addon_name)
1010
-    {
1011
-        $addon = LoaderFactory::getLoader()->getShared(
1012
-            self::$_settings[ $addon_name ]['class_name'],
1013
-            array('EE_Registry::create(addon)' => true)
1014
-        );
1015
-        if (! $addon instanceof EE_Addon) {
1016
-            throw new DomainException(
1017
-                sprintf(
1018
-                    esc_html__(
1019
-                        'Failed to instantiate the %1$s class. PLease check that the class exists.',
1020
-                        'event_espresso'
1021
-                    ),
1022
-                    $addon_name
1023
-                )
1024
-            );
1025
-        }
1026
-        // setter inject dep map if required
1027
-        if ($addon->dependencyMap() === null) {
1028
-            $addon->setDependencyMap(LoaderFactory::getLoader()->getShared('EE_Dependency_Map'));
1029
-        }
1030
-        // setter inject domain if required
1031
-        EE_Register_Addon::injectAddonDomain($addon_name, $addon);
1032
-
1033
-        $addon->set_name($addon_name);
1034
-        $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
1035
-        $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
1036
-        $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
1037
-        $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
1038
-        $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
1039
-        $addon->set_version(self::$_settings[ $addon_name ]['version']);
1040
-        $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
1041
-        $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
1042
-        $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
1043
-        $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
1044
-        // setup the add-on's pue_slug if we have one.
1045
-        if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) {
1046
-            $addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']);
1047
-        }
1048
-        // unfortunately this can't be hooked in upon construction,
1049
-        // because we don't have the plugin's mainfile path upon construction.
1050
-        register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
1051
-        // call any additional admin_callback functions during load_admin_controller hook
1052
-        if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
1053
-            add_action(
1054
-                'AHEE__EE_System__load_controllers__load_admin_controllers',
1055
-                array($addon, self::$_settings[ $addon_name ]['admin_callback'])
1056
-            );
1057
-        }
1058
-        return $addon;
1059
-    }
1060
-
1061
-
1062
-    /**
1063
-     * @param string   $addon_name
1064
-     * @param EE_Addon $addon
1065
-     * @since   $VID:$
1066
-     */
1067
-    private static function injectAddonDomain($addon_name, EE_Addon $addon)
1068
-    {
1069
-        if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) {
1070
-            // using supplied Domain object
1071
-            $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface
1072
-                ? self::$_settings[ $addon_name ]['domain']
1073
-                : null;
1074
-            // or construct one using Domain FQCN
1075
-            if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') {
1076
-                $domain = LoaderFactory::getLoader()->getShared(
1077
-                    self::$_settings[ $addon_name ]['domain_fqcn'],
1078
-                    [
1079
-                        new EventEspresso\core\domain\values\FilePath(
1080
-                            self::$_settings[ $addon_name ]['main_file_path']
1081
-                        ),
1082
-                        EventEspresso\core\domain\values\Version::fromString(
1083
-                            self::$_settings[ $addon_name ]['version']
1084
-                        ),
1085
-                    ]
1086
-                );
1087
-            }
1088
-            if ($domain instanceof DomainInterface) {
1089
-                $addon->setDomain($domain);
1090
-            }
1091
-        }
1092
-    }
1093
-
1094
-
1095
-    /**
1096
-     *    load_pue_update - Update notifications
1097
-     *
1098
-     * @return void
1099
-     * @throws InvalidArgumentException
1100
-     * @throws InvalidDataTypeException
1101
-     * @throws InvalidInterfaceException
1102
-     */
1103
-    public static function load_pue_update()
1104
-    {
1105
-        // load PUE client
1106
-        require_once EE_THIRD_PARTY . 'pue/pue-client.php';
1107
-        $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com';
1108
-        // cycle thru settings
1109
-        foreach (self::$_settings as $settings) {
1110
-            if (! empty($settings['pue_options'])) {
1111
-                // initiate the class and start the plugin update engine!
1112
-                new PluginUpdateEngineChecker(
1113
-                    // host file URL
1114
-                    $license_server,
1115
-                    // plugin slug(s)
1116
-                    array(
1117
-                        'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
1118
-                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
1119
-                    ),
1120
-                    // options
1121
-                    array(
1122
-                        'apikey'            => EE_Registry::instance()->NET_CFG->core->site_license_key,
1123
-                        'lang_domain'       => 'event_espresso',
1124
-                        'checkPeriod'       => $settings['pue_options']['checkPeriod'],
1125
-                        'option_key'        => 'ee_site_license_key',
1126
-                        'options_page_slug' => 'event_espresso',
1127
-                        'plugin_basename'   => $settings['pue_options']['plugin_basename'],
1128
-                        // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP
1129
-                        'use_wp_update'     => $settings['pue_options']['use_wp_update'],
1130
-                    )
1131
-                );
1132
-            }
1133
-        }
1134
-    }
1135
-
1136
-
1137
-    /**
1138
-     * Callback for EE_Brewing_Regular__messages_caf hook used to register message types.
1139
-     *
1140
-     * @since 4.4.0
1141
-     * @return void
1142
-     * @throws EE_Error
1143
-     */
1144
-    public static function register_message_types()
1145
-    {
1146
-        foreach (self::$_settings as $settings) {
1147
-            if (! empty($settings['message_types'])) {
1148
-                foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1149
-                    EE_Register_Message_Type::register($message_type, $message_type_settings);
1150
-                }
1151
-            }
1152
-        }
1153
-    }
1154
-
1155
-
1156
-    /**
1157
-     * This deregisters an addon that was previously registered with a specific addon_name.
1158
-     *
1159
-     * @param string $addon_name the name for the addon that was previously registered
1160
-     * @throws DomainException
1161
-     * @throws InvalidArgumentException
1162
-     * @throws InvalidDataTypeException
1163
-     * @throws InvalidInterfaceException
1164
-     *@since    4.3.0
1165
-     */
1166
-    public static function deregister($addon_name = '')
1167
-    {
1168
-        if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1169
-            try {
1170
-                do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1171
-                $class_name = self::$_settings[ $addon_name ]['class_name'];
1172
-                if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1173
-                    // setup DMS
1174
-                    EE_Register_Data_Migration_Scripts::deregister($addon_name);
1175
-                }
1176
-                if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1177
-                    // register admin page
1178
-                    EE_Register_Admin_Page::deregister($addon_name);
1179
-                }
1180
-                if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1181
-                    // add to list of modules to be registered
1182
-                    EE_Register_Module::deregister($addon_name);
1183
-                }
1184
-                if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1185
-                    || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1186
-                ) {
1187
-                    // add to list of shortcodes to be registered
1188
-                    EE_Register_Shortcode::deregister($addon_name);
1189
-                }
1190
-                if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1191
-                    // if config_class present let's register config.
1192
-                    EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1193
-                }
1194
-                if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1195
-                    // add to list of widgets to be registered
1196
-                    EE_Register_Widget::deregister($addon_name);
1197
-                }
1198
-                if (! empty(self::$_settings[ $addon_name ]['model_paths'])
1199
-                    || ! empty(self::$_settings[ $addon_name ]['class_paths'])
1200
-                ) {
1201
-                    // add to list of shortcodes to be registered
1202
-                    EE_Register_Model::deregister($addon_name);
1203
-                }
1204
-                if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1205
-                    || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1206
-                ) {
1207
-                    // add to list of shortcodes to be registered
1208
-                    EE_Register_Model_Extensions::deregister($addon_name);
1209
-                }
1210
-                if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1211
-                    foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) {
1212
-                        EE_Register_Message_Type::deregister($message_type);
1213
-                    }
1214
-                }
1215
-                // deregister capabilities for addon
1216
-                if (! empty(self::$_settings[ $addon_name ]['capabilities'])
1217
-                    || ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1218
-                ) {
1219
-                    EE_Register_Capabilities::deregister($addon_name);
1220
-                }
1221
-                // deregister custom_post_types for addon
1222
-                if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1223
-                    EE_Register_CPT::deregister($addon_name);
1224
-                }
1225
-                if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1226
-                    EE_Register_Payment_Method::deregister($addon_name);
1227
-                }
1228
-                $addon = EE_Registry::instance()->getAddon($class_name);
1229
-                if ($addon instanceof EE_Addon) {
1230
-                    remove_action(
1231
-                        'deactivate_' . $addon->get_main_plugin_file_basename(),
1232
-                        array($addon, 'deactivation')
1233
-                    );
1234
-                    remove_action(
1235
-                        'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1236
-                        array($addon, 'initialize_db_if_no_migrations_required')
1237
-                    );
1238
-                    // remove `after_registration` call
1239
-                    remove_action(
1240
-                        'AHEE__EE_System__load_espresso_addons__complete',
1241
-                        array($addon, 'after_registration'),
1242
-                        999
1243
-                    );
1244
-                }
1245
-                EE_Registry::instance()->removeAddon($class_name);
1246
-            } catch (OutOfBoundsException $addon_not_yet_registered_exception) {
1247
-                // the add-on was not yet registered in the registry,
1248
-                // so RegistryContainer::__get() throws this exception.
1249
-                // also no need to worry about this or log it,
1250
-                // it's ok to deregister an add-on before its registered in the registry
1251
-            } catch (Exception $e) {
1252
-                new ExceptionLogger($e);
1253
-            }
1254
-            unset(self::$_settings[ $addon_name ]);
1255
-            do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1256
-        }
1257
-    }
25
+	/**
26
+	 * possibly truncated version of the EE core version string
27
+	 *
28
+	 * @var string
29
+	 */
30
+	protected static $_core_version = '';
31
+
32
+	/**
33
+	 * Holds values for registered addons
34
+	 *
35
+	 * @var array
36
+	 */
37
+	protected static $_settings = array();
38
+
39
+	/**
40
+	 * @var  array $_incompatible_addons keys are addon SLUGS
41
+	 * (first argument passed to EE_Register_Addon::register()), keys are
42
+	 * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004).
43
+	 * Generally this should be used sparingly, as we don't want to muddle up
44
+	 * EE core with knowledge of ALL the addons out there.
45
+	 * If you want NO versions of an addon to run with a certain version of core,
46
+	 * it's usually best to define the addon's "min_core_version" as part of its call
47
+	 * to EE_Register_Addon::register(), rather than using this array with a super high value for its
48
+	 * minimum plugin version.
49
+	 * @access    protected
50
+	 */
51
+	protected static $_incompatible_addons = array(
52
+		'Multi_Event_Registration' => '2.0.11.rc.002',
53
+		'Promotions'               => '1.0.0.rc.084',
54
+	);
55
+
56
+
57
+	/**
58
+	 * We should always be comparing core to a version like '4.3.0.rc.000',
59
+	 * not just '4.3.0'.
60
+	 * So if the addon developer doesn't provide that full version string,
61
+	 * fill in the blanks for them
62
+	 *
63
+	 * @param string $min_core_version
64
+	 * @return string always like '4.3.0.rc.000'
65
+	 */
66
+	protected static function _effective_version($min_core_version)
67
+	{
68
+		// versions: 4 . 3 . 1 . p . 123
69
+		// offsets:    0 . 1 . 2 . 3 . 4
70
+		$version_parts = explode('.', $min_core_version);
71
+		// check they specified the micro version (after 2nd period)
72
+		if (! isset($version_parts[2])) {
73
+			$version_parts[2] = '0';
74
+		}
75
+		// if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
76
+		// soon we can assume that's 'rc', but this current version is 'alpha'
77
+		if (! isset($version_parts[3])) {
78
+			$version_parts[3] = 'dev';
79
+		}
80
+		if (! isset($version_parts[4])) {
81
+			$version_parts[4] = '000';
82
+		}
83
+		return implode('.', $version_parts);
84
+	}
85
+
86
+
87
+	/**
88
+	 * Returns whether or not the min core version requirement of the addon is met
89
+	 *
90
+	 * @param string $min_core_version    the minimum core version required by the addon
91
+	 * @param string $actual_core_version the actual core version, optional
92
+	 * @return boolean
93
+	 */
94
+	public static function _meets_min_core_version_requirement(
95
+		$min_core_version,
96
+		$actual_core_version = EVENT_ESPRESSO_VERSION
97
+	) {
98
+		return version_compare(
99
+			self::_effective_version($actual_core_version),
100
+			self::_effective_version($min_core_version),
101
+			'>='
102
+		);
103
+	}
104
+
105
+
106
+	/**
107
+	 * Method for registering new EE_Addons.
108
+	 * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE
109
+	 * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it
110
+	 * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon
111
+	 * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after
112
+	 * 'activate_plugin', it registers the addon still, but its components are not registered
113
+	 * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do
114
+	 * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns
115
+	 * (so that we can detect that the addon has activated on the subsequent request)
116
+	 *
117
+	 * @since    4.3.0
118
+	 * @param string                  $addon_name                       [Required] the EE_Addon's name.
119
+	 * @param  array                  $setup_args                       {
120
+	 *                                                                  An array of arguments provided for registering
121
+	 *                                                                  the message type.
122
+	 * @type  string                  $class_name                       the addon's main file name.
123
+	 *                                                                  If left blank, generated from the addon name,
124
+	 *                                                                  changes something like "calendar" to
125
+	 *                                                                  "EE_Calendar"
126
+	 * @type string                   $min_core_version                 the minimum version of EE Core that the
127
+	 *                                                                  addon will work with. eg "4.8.1.rc.084"
128
+	 * @type string                   $version                          the "software" version for the addon. eg
129
+	 *                                                                  "1.0.0.p" for a first stable release, or
130
+	 *                                                                  "1.0.0.rc.043" for a version in progress
131
+	 * @type string                   $main_file_path                   the full server path to the main file
132
+	 *                                                                  loaded directly by WP
133
+	 * @type DomainInterface $domain                                    child class of
134
+	 *                                                                  EventEspresso\core\domain\DomainBase
135
+	 * @type string                   $domain_fqcn                      Fully Qualified Class Name
136
+	 *                                                                  for the addon's Domain class
137
+	 *                                                                  (see EventEspresso\core\domain\Domain)
138
+	 * @type string                   $admin_path                       full server path to the folder where the
139
+	 *                                                                  addon\'s admin files reside
140
+	 * @type string                   $admin_callback                   a method to be called when the EE Admin is
141
+	 *                                                                  first invoked, can be used for hooking into
142
+	 *                                                                  any admin page
143
+	 * @type string                   $config_section                   the section name for this addon's
144
+	 *                                                                  configuration settings section
145
+	 *                                                                  (defaults to "addons")
146
+	 * @type string                   $config_class                     the class name for this addon's
147
+	 *                                                                  configuration settings object
148
+	 * @type string                   $config_name                      the class name for this addon's
149
+	 *                                                                  configuration settings object
150
+	 * @type string                   $autoloader_paths                 [Required] an array of class names and the full
151
+	 *                                                                  server paths to those files.
152
+	 * @type string                   $autoloader_folders               an array of  "full server paths" for any
153
+	 *                                                                  folders containing classes that might be
154
+	 *                                                                  invoked by the addon
155
+	 * @type string                   $dms_paths                        [Required] an array of full server paths to
156
+	 *                                                                  folders that contain data migration scripts.
157
+	 *                                                                  The key should be the EE_Addon class name that
158
+	 *                                                                  this set of data migration scripts belongs to.
159
+	 *                                                                  If the EE_Addon class is namespaced, then this
160
+	 *                                                                  needs to be the Fully Qualified Class Name
161
+	 * @type string                   $module_paths                     an array of full server paths to any
162
+	 *                                                                  EED_Modules used by the addon
163
+	 * @type string                   $shortcode_paths                  an array of full server paths to folders
164
+	 *                                                                  that contain EES_Shortcodes
165
+	 * @type string                   $widget_paths                     an array of full server paths to folders
166
+	 *                                                                  that contain WP_Widgets
167
+	 * @type string                   $pue_options
168
+	 * @type array                    $capabilities                     an array indexed by role name
169
+	 *                                                                  (i.e administrator,author ) and the values
170
+	 *                                                                  are an array of caps to add to the role.
171
+	 *                                                                  'administrator' => array(
172
+	 *                                                                  'read_addon',
173
+	 *                                                                  'edit_addon',
174
+	 *                                                                  etc.
175
+	 *                                                                  ).
176
+	 * @type EE_Meta_Capability_Map[] $capability_maps                  an array of EE_Meta_Capability_Map object
177
+	 *                                                                  for any addons that need to register any
178
+	 *                                                                  special meta mapped capabilities.  Should
179
+	 *                                                                  be indexed where the key is the
180
+	 *                                                                  EE_Meta_Capability_Map class name and the
181
+	 *                                                                  values are the arguments sent to the class.
182
+	 * @type array                    $model_paths                      array of folders containing DB models
183
+	 * @see      EE_Register_Model
184
+	 * @type array                    $class_paths                      array of folders containing DB classes
185
+	 * @see      EE_Register_Model
186
+	 * @type array                    $model_extension_paths            array of folders containing DB model
187
+	 *                                                                  extensions
188
+	 * @see      EE_Register_Model_Extension
189
+	 * @type array                    $class_extension_paths            array of folders containing DB class
190
+	 *                                                                  extensions
191
+	 * @see      EE_Register_Model_Extension
192
+	 * @type array message_types {
193
+	 *                                                                  An array of message types with the key as
194
+	 *                                                                  the message type name and the values as
195
+	 *                                                                  below:
196
+	 * @type string                   $mtfilename                       [Required] The filename of the message type
197
+	 *                                                                  being registered. This will be the main
198
+	 *                                                                  EE_{Message Type Name}_message_type class.
199
+	 *                                                                  for example:
200
+	 *                                                                  EE_Declined_Registration_message_type.class.php
201
+	 * @type array                    $autoloadpaths                    [Required] An array of paths to add to the
202
+	 *                                                                  messages autoloader for the new message type.
203
+	 * @type array                    $messengers_to_activate_with      An array of messengers that this message
204
+	 *                                                                  type should activate with. Each value in
205
+	 *                                                                  the
206
+	 *                                                                  array
207
+	 *                                                                  should match the name property of a
208
+	 *                                                                  EE_messenger. Optional.
209
+	 * @type array                    $messengers_to_validate_with      An array of messengers that this message
210
+	 *                                                                  type should validate with. Each value in
211
+	 *                                                                  the
212
+	 *                                                                  array
213
+	 *                                                                  should match the name property of an
214
+	 *                                                                  EE_messenger.
215
+	 *                                                                  Optional.
216
+	 *                                                                  }
217
+	 * @type array                    $custom_post_types
218
+	 * @type array                    $custom_taxonomies
219
+	 * @type array                    $payment_method_paths             each element is the folder containing the
220
+	 *                                                                  EE_PMT_Base child class
221
+	 *                                                                  (eg,
222
+	 *                                                                  '/wp-content/plugins/my_plugin/Payomatic/'
223
+	 *                                                                  which contains the files
224
+	 *                                                                  EE_PMT_Payomatic.pm.php)
225
+	 * @type array                    $default_terms
226
+	 * @type array                    $namespace                        {
227
+	 *                                                                  An array with two items for registering the
228
+	 *                                                                  addon's namespace. (If, for some reason, you
229
+	 *                                                                  require additional namespaces,
230
+	 *                                                                  use
231
+	 *                                                                  EventEspresso\core\Psr4Autoloader::addNamespace()
232
+	 *                                                                  directly)
233
+	 * @see      EventEspresso\core\Psr4Autoloader::addNamespace()
234
+	 * @type string                   $FQNS                             the namespace prefix
235
+	 * @type string                   $DIR                              a base directory for class files in the
236
+	 *                                                                  namespace.
237
+	 *                                                                  }
238
+	 *                                                                  }
239
+	 * @type string                   $privacy_policies                 FQNSs (namespaces, each of which contains only
240
+	 *                                                                  privacy policy classes) or FQCNs (specific
241
+	 *                                                                  classnames of privacy policy classes)
242
+	 * @type string                   $personal_data_exporters          FQNSs (namespaces, each of which contains only
243
+	 *                                                                  privacy policy classes) or FQCNs (specific
244
+	 *                                                                  classnames of privacy policy classes)
245
+	 * @type string                   $personal_data_erasers            FQNSs (namespaces, each of which contains only
246
+	 *                                                                  privacy policy classes) or FQCNs (specific
247
+	 *                                                                  classnames of privacy policy classes)
248
+	 * @return void
249
+	 * @throws DomainException
250
+	 * @throws EE_Error
251
+	 * @throws InvalidArgumentException
252
+	 * @throws InvalidDataTypeException
253
+	 * @throws InvalidInterfaceException
254
+	 */
255
+	public static function register($addon_name = '', array $setup_args = array())
256
+	{
257
+		// required fields MUST be present, so let's make sure they are.
258
+		EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
259
+		// get class name for addon
260
+		$class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
261
+		// setup $_settings array from incoming values.
262
+		$addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
263
+		// setup PUE
264
+		EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
265
+		// does this addon work with this version of core or WordPress ?
266
+		// does this addon work with this version of core or WordPress ?
267
+		if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
268
+			return;
269
+		}
270
+		// register namespaces
271
+		EE_Register_Addon::_setup_namespaces($addon_settings);
272
+		// check if this is an activation request
273
+		if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
274
+			// dont bother setting up the rest of the addon atm
275
+			return;
276
+		}
277
+		// we need cars
278
+		EE_Register_Addon::_setup_autoloaders($addon_name);
279
+		// register new models and extensions
280
+		EE_Register_Addon::_register_models_and_extensions($addon_name);
281
+		// setup DMS
282
+		EE_Register_Addon::_register_data_migration_scripts($addon_name);
283
+		// if config_class is present let's register config.
284
+		EE_Register_Addon::_register_config($addon_name);
285
+		// register admin pages
286
+		EE_Register_Addon::_register_admin_pages($addon_name);
287
+		// add to list of modules to be registered
288
+		EE_Register_Addon::_register_modules($addon_name);
289
+		// add to list of shortcodes to be registered
290
+		EE_Register_Addon::_register_shortcodes($addon_name);
291
+		// add to list of widgets to be registered
292
+		EE_Register_Addon::_register_widgets($addon_name);
293
+		// register capability related stuff.
294
+		EE_Register_Addon::_register_capabilities($addon_name);
295
+		// any message type to register?
296
+		EE_Register_Addon::_register_message_types($addon_name);
297
+		// any custom post type/ custom capabilities or default terms to register
298
+		EE_Register_Addon::_register_custom_post_types($addon_name);
299
+		// and any payment methods
300
+		EE_Register_Addon::_register_payment_methods($addon_name);
301
+		// and privacy policy generators
302
+		EE_Register_Addon::registerPrivacyPolicies($addon_name);
303
+		// and privacy policy generators
304
+		EE_Register_Addon::registerPersonalDataExporters($addon_name);
305
+		// and privacy policy generators
306
+		EE_Register_Addon::registerPersonalDataErasers($addon_name);
307
+		// load and instantiate main addon class
308
+		$addon = EE_Register_Addon::_load_and_init_addon_class($addon_name);
309
+		// delay calling after_registration hook on each addon until after all add-ons have been registered.
310
+		add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999);
311
+	}
312
+
313
+
314
+	/**
315
+	 * @param string $addon_name
316
+	 * @param array  $setup_args
317
+	 * @return void
318
+	 * @throws EE_Error
319
+	 */
320
+	private static function _verify_parameters($addon_name, array $setup_args)
321
+	{
322
+		// required fields MUST be present, so let's make sure they are.
323
+		if (empty($addon_name) || ! is_array($setup_args)) {
324
+			throw new EE_Error(
325
+				__(
326
+					'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.',
327
+					'event_espresso'
328
+				)
329
+			);
330
+		}
331
+		if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
332
+			throw new EE_Error(
333
+				sprintf(
334
+					__(
335
+						'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s',
336
+						'event_espresso'
337
+					),
338
+					implode(',', array_keys($setup_args))
339
+				)
340
+			);
341
+		}
342
+		// check that addon has not already been registered with that name
343
+		if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
344
+			throw new EE_Error(
345
+				sprintf(
346
+					__(
347
+						'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
348
+						'event_espresso'
349
+					),
350
+					$addon_name
351
+				)
352
+			);
353
+		}
354
+	}
355
+
356
+
357
+	/**
358
+	 * @param string $addon_name
359
+	 * @param array  $setup_args
360
+	 * @return string
361
+	 */
362
+	private static function _parse_class_name($addon_name, array $setup_args)
363
+	{
364
+		if (empty($setup_args['class_name'])) {
365
+			// generate one by first separating name with spaces
366
+			$class_name = str_replace(array('-', '_'), ' ', trim($addon_name));
367
+			// capitalize, then replace spaces with underscores
368
+			$class_name = str_replace(' ', '_', ucwords($class_name));
369
+		} else {
370
+			$class_name = $setup_args['class_name'];
371
+		}
372
+		// check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
373
+		return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
374
+			? $class_name
375
+			: 'EE_' . $class_name;
376
+	}
377
+
378
+
379
+	/**
380
+	 * @param string $class_name
381
+	 * @param array  $setup_args
382
+	 * @return array
383
+	 */
384
+	private static function _get_addon_settings($class_name, array $setup_args)
385
+	{
386
+		// setup $_settings array from incoming values.
387
+		$addon_settings = array(
388
+			// generated from the addon name, changes something like "calendar" to "EE_Calendar"
389
+			'class_name'            => $class_name,
390
+			// the addon slug for use in URLs, etc
391
+			'plugin_slug'           => isset($setup_args['plugin_slug'])
392
+				? (string) $setup_args['plugin_slug']
393
+				: '',
394
+			// page slug to be used when generating the "Settings" link on the WP plugin page
395
+			'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
396
+				? (string) $setup_args['plugin_action_slug']
397
+				: '',
398
+			// the "software" version for the addon
399
+			'version'               => isset($setup_args['version'])
400
+				? (string) $setup_args['version']
401
+				: '',
402
+			// the minimum version of EE Core that the addon will work with
403
+			'min_core_version'      => isset($setup_args['min_core_version'])
404
+				? (string) $setup_args['min_core_version']
405
+				: '',
406
+			// the minimum version of WordPress that the addon will work with
407
+			'min_wp_version'        => isset($setup_args['min_wp_version'])
408
+				? (string) $setup_args['min_wp_version']
409
+				: EE_MIN_WP_VER_REQUIRED,
410
+			// full server path to main file (file loaded directly by WP)
411
+			'main_file_path'        => isset($setup_args['main_file_path'])
412
+				? (string) $setup_args['main_file_path']
413
+				: '',
414
+			// instance of \EventEspresso\core\domain\DomainInterface
415
+			'domain'                => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface
416
+				? $setup_args['domain']
417
+				: null,
418
+			// Fully Qualified Class Name for the addon's Domain class
419
+			'domain_fqcn'           => isset($setup_args['domain_fqcn'])
420
+				? (string) $setup_args['domain_fqcn']
421
+				: '',
422
+			// path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
423
+			'admin_path'            => isset($setup_args['admin_path'])
424
+				? (string) $setup_args['admin_path'] : '',
425
+			// a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
426
+			'admin_callback'        => isset($setup_args['admin_callback'])
427
+				? (string) $setup_args['admin_callback']
428
+				: '',
429
+			// the section name for this addon's configuration settings section (defaults to "addons")
430
+			'config_section'        => isset($setup_args['config_section'])
431
+				? (string) $setup_args['config_section']
432
+				: 'addons',
433
+			// the class name for this addon's configuration settings object
434
+			'config_class'          => isset($setup_args['config_class'])
435
+				? (string) $setup_args['config_class'] : '',
436
+			// the name given to the config for this addons' configuration settings object (optional)
437
+			'config_name'           => isset($setup_args['config_name'])
438
+				? (string) $setup_args['config_name'] : '',
439
+			// an array of "class names" => "full server paths" for any classes that might be invoked by the addon
440
+			'autoloader_paths'      => isset($setup_args['autoloader_paths'])
441
+				? (array) $setup_args['autoloader_paths']
442
+				: array(),
443
+			// an array of  "full server paths" for any folders containing classes that might be invoked by the addon
444
+			'autoloader_folders'    => isset($setup_args['autoloader_folders'])
445
+				? (array) $setup_args['autoloader_folders']
446
+				: array(),
447
+			// array of full server paths to any EE_DMS data migration scripts used by the addon.
448
+			// The key should be the EE_Addon class name that this set of data migration scripts belongs to.
449
+			// If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name
450
+			'dms_paths'             => isset($setup_args['dms_paths'])
451
+				? (array) $setup_args['dms_paths']
452
+				: array(),
453
+			// array of full server paths to any EED_Modules used by the addon
454
+			'module_paths'          => isset($setup_args['module_paths'])
455
+				? (array) $setup_args['module_paths']
456
+				: array(),
457
+			// array of full server paths to any EES_Shortcodes used by the addon
458
+			'shortcode_paths'       => isset($setup_args['shortcode_paths'])
459
+				? (array) $setup_args['shortcode_paths']
460
+				: array(),
461
+			'shortcode_fqcns'       => isset($setup_args['shortcode_fqcns'])
462
+				? (array) $setup_args['shortcode_fqcns']
463
+				: array(),
464
+			// array of full server paths to any WP_Widgets used by the addon
465
+			'widget_paths'          => isset($setup_args['widget_paths'])
466
+				? (array) $setup_args['widget_paths']
467
+				: array(),
468
+			// array of PUE options used by the addon
469
+			'pue_options'           => isset($setup_args['pue_options'])
470
+				? (array) $setup_args['pue_options']
471
+				: array(),
472
+			'message_types'         => isset($setup_args['message_types'])
473
+				? (array) $setup_args['message_types']
474
+				: array(),
475
+			'capabilities'          => isset($setup_args['capabilities'])
476
+				? (array) $setup_args['capabilities']
477
+				: array(),
478
+			'capability_maps'       => isset($setup_args['capability_maps'])
479
+				? (array) $setup_args['capability_maps']
480
+				: array(),
481
+			'model_paths'           => isset($setup_args['model_paths'])
482
+				? (array) $setup_args['model_paths']
483
+				: array(),
484
+			'class_paths'           => isset($setup_args['class_paths'])
485
+				? (array) $setup_args['class_paths']
486
+				: array(),
487
+			'model_extension_paths' => isset($setup_args['model_extension_paths'])
488
+				? (array) $setup_args['model_extension_paths']
489
+				: array(),
490
+			'class_extension_paths' => isset($setup_args['class_extension_paths'])
491
+				? (array) $setup_args['class_extension_paths']
492
+				: array(),
493
+			'custom_post_types'     => isset($setup_args['custom_post_types'])
494
+				? (array) $setup_args['custom_post_types']
495
+				: array(),
496
+			'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
497
+				? (array) $setup_args['custom_taxonomies']
498
+				: array(),
499
+			'payment_method_paths'  => isset($setup_args['payment_method_paths'])
500
+				? (array) $setup_args['payment_method_paths']
501
+				: array(),
502
+			'default_terms'         => isset($setup_args['default_terms'])
503
+				? (array) $setup_args['default_terms']
504
+				: array(),
505
+			// if not empty, inserts a new table row after this plugin's row on the WP Plugins page
506
+			// that can be used for adding upgrading/marketing info
507
+			'plugins_page_row'      => isset($setup_args['plugins_page_row']) ? $setup_args['plugins_page_row'] : '',
508
+			'namespace'             => isset(
509
+				$setup_args['namespace']['FQNS'],
510
+				$setup_args['namespace']['DIR']
511
+			)
512
+				? (array) $setup_args['namespace']
513
+				: array(),
514
+			'privacy_policies'      => isset($setup_args['privacy_policies'])
515
+				? (array) $setup_args['privacy_policies']
516
+				: '',
517
+		);
518
+		// if plugin_action_slug is NOT set, but an admin page path IS set,
519
+		// then let's just use the plugin_slug since that will be used for linking to the admin page
520
+		$addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
521
+												&& ! empty($addon_settings['admin_path'])
522
+			? $addon_settings['plugin_slug']
523
+			: $addon_settings['plugin_action_slug'];
524
+		// full server path to main file (file loaded directly by WP)
525
+		$addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
526
+		return $addon_settings;
527
+	}
528
+
529
+
530
+	/**
531
+	 * @param string $addon_name
532
+	 * @param array  $addon_settings
533
+	 * @return boolean
534
+	 */
535
+	private static function _addon_is_compatible($addon_name, array $addon_settings)
536
+	{
537
+		global $wp_version;
538
+		$incompatibility_message = '';
539
+		// check whether this addon version is compatible with EE core
540
+		if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
541
+			&& ! self::_meets_min_core_version_requirement(
542
+				EE_Register_Addon::$_incompatible_addons[ $addon_name ],
543
+				$addon_settings['version']
544
+			)
545
+		) {
546
+			$incompatibility_message = sprintf(
547
+				__(
548
+					'%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.',
549
+					'event_espresso'
550
+				),
551
+				$addon_name,
552
+				'<br />',
553
+				EE_Register_Addon::$_incompatible_addons[ $addon_name ],
554
+				'<span style="font-weight: bold; color: #D54E21;">',
555
+				'</span><br />'
556
+			);
557
+		} elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
558
+		) {
559
+			$incompatibility_message = sprintf(
560
+				__(
561
+					'%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".',
562
+					'event_espresso'
563
+				),
564
+				$addon_name,
565
+				self::_effective_version($addon_settings['min_core_version']),
566
+				self::_effective_version(espresso_version()),
567
+				'<br />',
568
+				'<span style="font-weight: bold; color: #D54E21;">',
569
+				'</span><br />'
570
+			);
571
+		} elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
572
+			$incompatibility_message = sprintf(
573
+				__(
574
+					'%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.',
575
+					'event_espresso'
576
+				),
577
+				$addon_name,
578
+				$addon_settings['min_wp_version'],
579
+				'<br />',
580
+				'<span style="font-weight: bold; color: #D54E21;">',
581
+				'</span><br />'
582
+			);
583
+		}
584
+		if (! empty($incompatibility_message)) {
585
+			// remove 'activate' from the REQUEST
586
+			// so WP doesn't erroneously tell the user the plugin activated fine when it didn't
587
+			unset($_GET['activate'], $_REQUEST['activate']);
588
+			if (current_user_can('activate_plugins')) {
589
+				// show an error message indicating the plugin didn't activate properly
590
+				EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
591
+			}
592
+			// BAIL FROM THE ADDON REGISTRATION PROCESS
593
+			return false;
594
+		}
595
+		// addon IS compatible
596
+		return true;
597
+	}
598
+
599
+
600
+	/**
601
+	 * if plugin update engine is being used for auto-updates,
602
+	 * then let's set that up now before going any further so that ALL addons can be updated
603
+	 * (not needed if PUE is not being used)
604
+	 *
605
+	 * @param string $addon_name
606
+	 * @param string $class_name
607
+	 * @param array  $setup_args
608
+	 * @return void
609
+	 */
610
+	private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
611
+	{
612
+		if (! empty($setup_args['pue_options'])) {
613
+			self::$_settings[ $addon_name ]['pue_options'] = array(
614
+				'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
615
+					? (string) $setup_args['pue_options']['pue_plugin_slug']
616
+					: 'espresso_' . strtolower($class_name),
617
+				'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
618
+					? (string) $setup_args['pue_options']['plugin_basename']
619
+					: plugin_basename($setup_args['main_file_path']),
620
+				'checkPeriod'     => isset($setup_args['pue_options']['checkPeriod'])
621
+					? (string) $setup_args['pue_options']['checkPeriod']
622
+					: '24',
623
+				'use_wp_update'   => isset($setup_args['pue_options']['use_wp_update'])
624
+					? (string) $setup_args['pue_options']['use_wp_update']
625
+					: false,
626
+			);
627
+			add_action(
628
+				'AHEE__EE_System__brew_espresso__after_pue_init',
629
+				array('EE_Register_Addon', 'load_pue_update')
630
+			);
631
+		}
632
+	}
633
+
634
+
635
+	/**
636
+	 * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
637
+	 *
638
+	 * @param array $addon_settings
639
+	 * @return void
640
+	 */
641
+	private static function _setup_namespaces(array $addon_settings)
642
+	{
643
+		//
644
+		if (isset(
645
+			$addon_settings['namespace']['FQNS'],
646
+			$addon_settings['namespace']['DIR']
647
+		)) {
648
+			EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
649
+				$addon_settings['namespace']['FQNS'],
650
+				$addon_settings['namespace']['DIR']
651
+			);
652
+		}
653
+	}
654
+
655
+
656
+	/**
657
+	 * @param string $addon_name
658
+	 * @param array  $addon_settings
659
+	 * @return bool
660
+	 * @throws InvalidArgumentException
661
+	 * @throws InvalidDataTypeException
662
+	 * @throws InvalidInterfaceException
663
+	 */
664
+	private static function _addon_activation($addon_name, array $addon_settings)
665
+	{
666
+		// this is an activation request
667
+		if (did_action('activate_plugin')) {
668
+			// to find if THIS is the addon that was activated, just check if we have already registered it or not
669
+			// (as the newly-activated addon wasn't around the first time addons were registered).
670
+			// Note: the presence of pue_options in the addon registration options will initialize the $_settings
671
+			// property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
672
+			if (! isset(self::$_settings[ $addon_name ])
673
+				|| (isset(self::$_settings[ $addon_name ])
674
+					&& ! isset(self::$_settings[ $addon_name ]['class_name'])
675
+				)
676
+			) {
677
+				self::$_settings[ $addon_name ] = $addon_settings;
678
+				$addon = self::_load_and_init_addon_class($addon_name);
679
+				$addon->set_activation_indicator_option();
680
+				// dont bother setting up the rest of the addon.
681
+				// we know it was just activated and the request will end soon
682
+			}
683
+			return true;
684
+		}
685
+		// make sure this was called in the right place!
686
+		if (! did_action('AHEE__EE_System__load_espresso_addons')
687
+			|| did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
688
+		) {
689
+			EE_Error::doing_it_wrong(
690
+				__METHOD__,
691
+				sprintf(
692
+					__(
693
+						'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.',
694
+						'event_espresso'
695
+					),
696
+					$addon_name
697
+				),
698
+				'4.3.0'
699
+			);
700
+		}
701
+		// make sure addon settings are set correctly without overwriting anything existing
702
+		if (isset(self::$_settings[ $addon_name ])) {
703
+			self::$_settings[ $addon_name ] += $addon_settings;
704
+		} else {
705
+			self::$_settings[ $addon_name ] = $addon_settings;
706
+		}
707
+		return false;
708
+	}
709
+
710
+
711
+	/**
712
+	 * @param string $addon_name
713
+	 * @return void
714
+	 * @throws EE_Error
715
+	 */
716
+	private static function _setup_autoloaders($addon_name)
717
+	{
718
+		if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
719
+			// setup autoloader for single file
720
+			EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
721
+		}
722
+		// setup autoloaders for folders
723
+		if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
724
+			foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
725
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
726
+			}
727
+		}
728
+	}
729
+
730
+
731
+	/**
732
+	 * register new models and extensions
733
+	 *
734
+	 * @param string $addon_name
735
+	 * @return void
736
+	 * @throws EE_Error
737
+	 */
738
+	private static function _register_models_and_extensions($addon_name)
739
+	{
740
+		// register new models
741
+		if (! empty(self::$_settings[ $addon_name ]['model_paths'])
742
+			|| ! empty(self::$_settings[ $addon_name ]['class_paths'])
743
+		) {
744
+			EE_Register_Model::register(
745
+				$addon_name,
746
+				array(
747
+					'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
748
+					'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
749
+				)
750
+			);
751
+		}
752
+		// register model extensions
753
+		if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
754
+			|| ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
755
+		) {
756
+			EE_Register_Model_Extensions::register(
757
+				$addon_name,
758
+				array(
759
+					'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
760
+					'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
761
+				)
762
+			);
763
+		}
764
+	}
765
+
766
+
767
+	/**
768
+	 * @param string $addon_name
769
+	 * @return void
770
+	 * @throws EE_Error
771
+	 */
772
+	private static function _register_data_migration_scripts($addon_name)
773
+	{
774
+		// setup DMS
775
+		if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
776
+			EE_Register_Data_Migration_Scripts::register(
777
+				$addon_name,
778
+				array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths'])
779
+			);
780
+		}
781
+	}
782
+
783
+
784
+	/**
785
+	 * @param string $addon_name
786
+	 * @return void
787
+	 * @throws EE_Error
788
+	 */
789
+	private static function _register_config($addon_name)
790
+	{
791
+		// if config_class is present let's register config.
792
+		if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
793
+			EE_Register_Config::register(
794
+				self::$_settings[ $addon_name ]['config_class'],
795
+				array(
796
+					'config_section' => self::$_settings[ $addon_name ]['config_section'],
797
+					'config_name'    => self::$_settings[ $addon_name ]['config_name'],
798
+				)
799
+			);
800
+		}
801
+	}
802
+
803
+
804
+	/**
805
+	 * @param string $addon_name
806
+	 * @return void
807
+	 * @throws EE_Error
808
+	 */
809
+	private static function _register_admin_pages($addon_name)
810
+	{
811
+		if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
812
+			EE_Register_Admin_Page::register(
813
+				$addon_name,
814
+				array('page_path' => self::$_settings[ $addon_name ]['admin_path'])
815
+			);
816
+		}
817
+	}
818
+
819
+
820
+	/**
821
+	 * @param string $addon_name
822
+	 * @return void
823
+	 * @throws EE_Error
824
+	 */
825
+	private static function _register_modules($addon_name)
826
+	{
827
+		if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
828
+			EE_Register_Module::register(
829
+				$addon_name,
830
+				array('module_paths' => self::$_settings[ $addon_name ]['module_paths'])
831
+			);
832
+		}
833
+	}
834
+
835
+
836
+	/**
837
+	 * @param string $addon_name
838
+	 * @return void
839
+	 * @throws EE_Error
840
+	 */
841
+	private static function _register_shortcodes($addon_name)
842
+	{
843
+		if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
844
+			|| ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
845
+		) {
846
+			EE_Register_Shortcode::register(
847
+				$addon_name,
848
+				array(
849
+					'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths'])
850
+						? self::$_settings[ $addon_name ]['shortcode_paths'] : array(),
851
+					'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns'])
852
+						? self::$_settings[ $addon_name ]['shortcode_fqcns'] : array(),
853
+				)
854
+			);
855
+		}
856
+	}
857
+
858
+
859
+	/**
860
+	 * @param string $addon_name
861
+	 * @return void
862
+	 * @throws EE_Error
863
+	 */
864
+	private static function _register_widgets($addon_name)
865
+	{
866
+		if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
867
+			EE_Register_Widget::register(
868
+				$addon_name,
869
+				array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths'])
870
+			);
871
+		}
872
+	}
873
+
874
+
875
+	/**
876
+	 * @param string $addon_name
877
+	 * @return void
878
+	 * @throws EE_Error
879
+	 */
880
+	private static function _register_capabilities($addon_name)
881
+	{
882
+		if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
883
+			EE_Register_Capabilities::register(
884
+				$addon_name,
885
+				array(
886
+					'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
887
+					'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
888
+				)
889
+			);
890
+		}
891
+	}
892
+
893
+
894
+	/**
895
+	 * @param string $addon_name
896
+	 * @return void
897
+	 */
898
+	private static function _register_message_types($addon_name)
899
+	{
900
+		if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
901
+			add_action(
902
+				'EE_Brewing_Regular___messages_caf',
903
+				array('EE_Register_Addon', 'register_message_types')
904
+			);
905
+		}
906
+	}
907
+
908
+
909
+	/**
910
+	 * @param string $addon_name
911
+	 * @return void
912
+	 * @throws EE_Error
913
+	 */
914
+	private static function _register_custom_post_types($addon_name)
915
+	{
916
+		if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])
917
+			|| ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
918
+		) {
919
+			EE_Register_CPT::register(
920
+				$addon_name,
921
+				array(
922
+					'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
923
+					'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
924
+					'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
925
+				)
926
+			);
927
+		}
928
+	}
929
+
930
+
931
+	/**
932
+	 * @param string $addon_name
933
+	 * @return void
934
+	 * @throws InvalidArgumentException
935
+	 * @throws InvalidInterfaceException
936
+	 * @throws InvalidDataTypeException
937
+	 * @throws DomainException
938
+	 * @throws EE_Error
939
+	 */
940
+	private static function _register_payment_methods($addon_name)
941
+	{
942
+		if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
943
+			EE_Register_Payment_Method::register(
944
+				$addon_name,
945
+				array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths'])
946
+			);
947
+		}
948
+	}
949
+
950
+
951
+	/**
952
+	 * @param string $addon_name
953
+	 * @return void
954
+	 * @throws InvalidArgumentException
955
+	 * @throws InvalidInterfaceException
956
+	 * @throws InvalidDataTypeException
957
+	 * @throws DomainException
958
+	 */
959
+	private static function registerPrivacyPolicies($addon_name)
960
+	{
961
+		if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) {
962
+			EE_Register_Privacy_Policy::register(
963
+				$addon_name,
964
+				self::$_settings[ $addon_name ]['privacy_policies']
965
+			);
966
+		}
967
+	}
968
+
969
+
970
+	/**
971
+	 * @param string $addon_name
972
+	 * @return void
973
+	 */
974
+	private static function registerPersonalDataExporters($addon_name)
975
+	{
976
+		if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) {
977
+			EE_Register_Personal_Data_Eraser::register(
978
+				$addon_name,
979
+				self::$_settings[ $addon_name ]['personal_data_exporters']
980
+			);
981
+		}
982
+	}
983
+
984
+
985
+	/**
986
+	 * @param string $addon_name
987
+	 * @return void
988
+	 */
989
+	private static function registerPersonalDataErasers($addon_name)
990
+	{
991
+		if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) {
992
+			EE_Register_Personal_Data_Eraser::register(
993
+				$addon_name,
994
+				self::$_settings[ $addon_name ]['personal_data_erasers']
995
+			);
996
+		}
997
+	}
998
+
999
+
1000
+	/**
1001
+	 * Loads and instantiates the EE_Addon class and adds it onto the registry
1002
+	 *
1003
+	 * @param string $addon_name
1004
+	 * @return EE_Addon
1005
+	 * @throws InvalidArgumentException
1006
+	 * @throws InvalidInterfaceException
1007
+	 * @throws InvalidDataTypeException
1008
+	 */
1009
+	private static function _load_and_init_addon_class($addon_name)
1010
+	{
1011
+		$addon = LoaderFactory::getLoader()->getShared(
1012
+			self::$_settings[ $addon_name ]['class_name'],
1013
+			array('EE_Registry::create(addon)' => true)
1014
+		);
1015
+		if (! $addon instanceof EE_Addon) {
1016
+			throw new DomainException(
1017
+				sprintf(
1018
+					esc_html__(
1019
+						'Failed to instantiate the %1$s class. PLease check that the class exists.',
1020
+						'event_espresso'
1021
+					),
1022
+					$addon_name
1023
+				)
1024
+			);
1025
+		}
1026
+		// setter inject dep map if required
1027
+		if ($addon->dependencyMap() === null) {
1028
+			$addon->setDependencyMap(LoaderFactory::getLoader()->getShared('EE_Dependency_Map'));
1029
+		}
1030
+		// setter inject domain if required
1031
+		EE_Register_Addon::injectAddonDomain($addon_name, $addon);
1032
+
1033
+		$addon->set_name($addon_name);
1034
+		$addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
1035
+		$addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
1036
+		$addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
1037
+		$addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
1038
+		$addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
1039
+		$addon->set_version(self::$_settings[ $addon_name ]['version']);
1040
+		$addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
1041
+		$addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
1042
+		$addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
1043
+		$addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
1044
+		// setup the add-on's pue_slug if we have one.
1045
+		if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) {
1046
+			$addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']);
1047
+		}
1048
+		// unfortunately this can't be hooked in upon construction,
1049
+		// because we don't have the plugin's mainfile path upon construction.
1050
+		register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
1051
+		// call any additional admin_callback functions during load_admin_controller hook
1052
+		if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
1053
+			add_action(
1054
+				'AHEE__EE_System__load_controllers__load_admin_controllers',
1055
+				array($addon, self::$_settings[ $addon_name ]['admin_callback'])
1056
+			);
1057
+		}
1058
+		return $addon;
1059
+	}
1060
+
1061
+
1062
+	/**
1063
+	 * @param string   $addon_name
1064
+	 * @param EE_Addon $addon
1065
+	 * @since   $VID:$
1066
+	 */
1067
+	private static function injectAddonDomain($addon_name, EE_Addon $addon)
1068
+	{
1069
+		if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) {
1070
+			// using supplied Domain object
1071
+			$domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface
1072
+				? self::$_settings[ $addon_name ]['domain']
1073
+				: null;
1074
+			// or construct one using Domain FQCN
1075
+			if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') {
1076
+				$domain = LoaderFactory::getLoader()->getShared(
1077
+					self::$_settings[ $addon_name ]['domain_fqcn'],
1078
+					[
1079
+						new EventEspresso\core\domain\values\FilePath(
1080
+							self::$_settings[ $addon_name ]['main_file_path']
1081
+						),
1082
+						EventEspresso\core\domain\values\Version::fromString(
1083
+							self::$_settings[ $addon_name ]['version']
1084
+						),
1085
+					]
1086
+				);
1087
+			}
1088
+			if ($domain instanceof DomainInterface) {
1089
+				$addon->setDomain($domain);
1090
+			}
1091
+		}
1092
+	}
1093
+
1094
+
1095
+	/**
1096
+	 *    load_pue_update - Update notifications
1097
+	 *
1098
+	 * @return void
1099
+	 * @throws InvalidArgumentException
1100
+	 * @throws InvalidDataTypeException
1101
+	 * @throws InvalidInterfaceException
1102
+	 */
1103
+	public static function load_pue_update()
1104
+	{
1105
+		// load PUE client
1106
+		require_once EE_THIRD_PARTY . 'pue/pue-client.php';
1107
+		$license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com';
1108
+		// cycle thru settings
1109
+		foreach (self::$_settings as $settings) {
1110
+			if (! empty($settings['pue_options'])) {
1111
+				// initiate the class and start the plugin update engine!
1112
+				new PluginUpdateEngineChecker(
1113
+					// host file URL
1114
+					$license_server,
1115
+					// plugin slug(s)
1116
+					array(
1117
+						'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
1118
+						'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
1119
+					),
1120
+					// options
1121
+					array(
1122
+						'apikey'            => EE_Registry::instance()->NET_CFG->core->site_license_key,
1123
+						'lang_domain'       => 'event_espresso',
1124
+						'checkPeriod'       => $settings['pue_options']['checkPeriod'],
1125
+						'option_key'        => 'ee_site_license_key',
1126
+						'options_page_slug' => 'event_espresso',
1127
+						'plugin_basename'   => $settings['pue_options']['plugin_basename'],
1128
+						// if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP
1129
+						'use_wp_update'     => $settings['pue_options']['use_wp_update'],
1130
+					)
1131
+				);
1132
+			}
1133
+		}
1134
+	}
1135
+
1136
+
1137
+	/**
1138
+	 * Callback for EE_Brewing_Regular__messages_caf hook used to register message types.
1139
+	 *
1140
+	 * @since 4.4.0
1141
+	 * @return void
1142
+	 * @throws EE_Error
1143
+	 */
1144
+	public static function register_message_types()
1145
+	{
1146
+		foreach (self::$_settings as $settings) {
1147
+			if (! empty($settings['message_types'])) {
1148
+				foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1149
+					EE_Register_Message_Type::register($message_type, $message_type_settings);
1150
+				}
1151
+			}
1152
+		}
1153
+	}
1154
+
1155
+
1156
+	/**
1157
+	 * This deregisters an addon that was previously registered with a specific addon_name.
1158
+	 *
1159
+	 * @param string $addon_name the name for the addon that was previously registered
1160
+	 * @throws DomainException
1161
+	 * @throws InvalidArgumentException
1162
+	 * @throws InvalidDataTypeException
1163
+	 * @throws InvalidInterfaceException
1164
+	 *@since    4.3.0
1165
+	 */
1166
+	public static function deregister($addon_name = '')
1167
+	{
1168
+		if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1169
+			try {
1170
+				do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1171
+				$class_name = self::$_settings[ $addon_name ]['class_name'];
1172
+				if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1173
+					// setup DMS
1174
+					EE_Register_Data_Migration_Scripts::deregister($addon_name);
1175
+				}
1176
+				if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1177
+					// register admin page
1178
+					EE_Register_Admin_Page::deregister($addon_name);
1179
+				}
1180
+				if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1181
+					// add to list of modules to be registered
1182
+					EE_Register_Module::deregister($addon_name);
1183
+				}
1184
+				if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1185
+					|| ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1186
+				) {
1187
+					// add to list of shortcodes to be registered
1188
+					EE_Register_Shortcode::deregister($addon_name);
1189
+				}
1190
+				if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1191
+					// if config_class present let's register config.
1192
+					EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1193
+				}
1194
+				if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1195
+					// add to list of widgets to be registered
1196
+					EE_Register_Widget::deregister($addon_name);
1197
+				}
1198
+				if (! empty(self::$_settings[ $addon_name ]['model_paths'])
1199
+					|| ! empty(self::$_settings[ $addon_name ]['class_paths'])
1200
+				) {
1201
+					// add to list of shortcodes to be registered
1202
+					EE_Register_Model::deregister($addon_name);
1203
+				}
1204
+				if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1205
+					|| ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1206
+				) {
1207
+					// add to list of shortcodes to be registered
1208
+					EE_Register_Model_Extensions::deregister($addon_name);
1209
+				}
1210
+				if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1211
+					foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) {
1212
+						EE_Register_Message_Type::deregister($message_type);
1213
+					}
1214
+				}
1215
+				// deregister capabilities for addon
1216
+				if (! empty(self::$_settings[ $addon_name ]['capabilities'])
1217
+					|| ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1218
+				) {
1219
+					EE_Register_Capabilities::deregister($addon_name);
1220
+				}
1221
+				// deregister custom_post_types for addon
1222
+				if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1223
+					EE_Register_CPT::deregister($addon_name);
1224
+				}
1225
+				if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1226
+					EE_Register_Payment_Method::deregister($addon_name);
1227
+				}
1228
+				$addon = EE_Registry::instance()->getAddon($class_name);
1229
+				if ($addon instanceof EE_Addon) {
1230
+					remove_action(
1231
+						'deactivate_' . $addon->get_main_plugin_file_basename(),
1232
+						array($addon, 'deactivation')
1233
+					);
1234
+					remove_action(
1235
+						'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1236
+						array($addon, 'initialize_db_if_no_migrations_required')
1237
+					);
1238
+					// remove `after_registration` call
1239
+					remove_action(
1240
+						'AHEE__EE_System__load_espresso_addons__complete',
1241
+						array($addon, 'after_registration'),
1242
+						999
1243
+					);
1244
+				}
1245
+				EE_Registry::instance()->removeAddon($class_name);
1246
+			} catch (OutOfBoundsException $addon_not_yet_registered_exception) {
1247
+				// the add-on was not yet registered in the registry,
1248
+				// so RegistryContainer::__get() throws this exception.
1249
+				// also no need to worry about this or log it,
1250
+				// it's ok to deregister an add-on before its registered in the registry
1251
+			} catch (Exception $e) {
1252
+				new ExceptionLogger($e);
1253
+			}
1254
+			unset(self::$_settings[ $addon_name ]);
1255
+			do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1256
+		}
1257
+	}
1258 1258
 }
Please login to merge, or discard this patch.
Spacing   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -69,15 +69,15 @@  discard block
 block discarded – undo
69 69
         // offsets:    0 . 1 . 2 . 3 . 4
70 70
         $version_parts = explode('.', $min_core_version);
71 71
         // check they specified the micro version (after 2nd period)
72
-        if (! isset($version_parts[2])) {
72
+        if ( ! isset($version_parts[2])) {
73 73
             $version_parts[2] = '0';
74 74
         }
75 75
         // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
76 76
         // soon we can assume that's 'rc', but this current version is 'alpha'
77
-        if (! isset($version_parts[3])) {
77
+        if ( ! isset($version_parts[3])) {
78 78
             $version_parts[3] = 'dev';
79 79
         }
80
-        if (! isset($version_parts[4])) {
80
+        if ( ! isset($version_parts[4])) {
81 81
             $version_parts[4] = '000';
82 82
         }
83 83
         return implode('.', $version_parts);
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
         EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
265 265
         // does this addon work with this version of core or WordPress ?
266 266
         // does this addon work with this version of core or WordPress ?
267
-        if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
267
+        if ( ! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
268 268
             return;
269 269
         }
270 270
         // register namespaces
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
                 )
329 329
             );
330 330
         }
331
-        if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
331
+        if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
332 332
             throw new EE_Error(
333 333
                 sprintf(
334 334
                     __(
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
             );
341 341
         }
342 342
         // check that addon has not already been registered with that name
343
-        if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
343
+        if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) {
344 344
             throw new EE_Error(
345 345
                 sprintf(
346 346
                     __(
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
         // check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
373 373
         return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
374 374
             ? $class_name
375
-            : 'EE_' . $class_name;
375
+            : 'EE_'.$class_name;
376 376
     }
377 377
 
378 378
 
@@ -537,9 +537,9 @@  discard block
 block discarded – undo
537 537
         global $wp_version;
538 538
         $incompatibility_message = '';
539 539
         // check whether this addon version is compatible with EE core
540
-        if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
540
+        if (isset(EE_Register_Addon::$_incompatible_addons[$addon_name])
541 541
             && ! self::_meets_min_core_version_requirement(
542
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
542
+                EE_Register_Addon::$_incompatible_addons[$addon_name],
543 543
                 $addon_settings['version']
544 544
             )
545 545
         ) {
@@ -550,11 +550,11 @@  discard block
 block discarded – undo
550 550
                 ),
551 551
                 $addon_name,
552 552
                 '<br />',
553
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
553
+                EE_Register_Addon::$_incompatible_addons[$addon_name],
554 554
                 '<span style="font-weight: bold; color: #D54E21;">',
555 555
                 '</span><br />'
556 556
             );
557
-        } elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
557
+        } elseif ( ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
558 558
         ) {
559 559
             $incompatibility_message = sprintf(
560 560
                 __(
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
                 '</span><br />'
582 582
             );
583 583
         }
584
-        if (! empty($incompatibility_message)) {
584
+        if ( ! empty($incompatibility_message)) {
585 585
             // remove 'activate' from the REQUEST
586 586
             // so WP doesn't erroneously tell the user the plugin activated fine when it didn't
587 587
             unset($_GET['activate'], $_REQUEST['activate']);
@@ -609,11 +609,11 @@  discard block
 block discarded – undo
609 609
      */
610 610
     private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
611 611
     {
612
-        if (! empty($setup_args['pue_options'])) {
613
-            self::$_settings[ $addon_name ]['pue_options'] = array(
612
+        if ( ! empty($setup_args['pue_options'])) {
613
+            self::$_settings[$addon_name]['pue_options'] = array(
614 614
                 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
615 615
                     ? (string) $setup_args['pue_options']['pue_plugin_slug']
616
-                    : 'espresso_' . strtolower($class_name),
616
+                    : 'espresso_'.strtolower($class_name),
617 617
                 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
618 618
                     ? (string) $setup_args['pue_options']['plugin_basename']
619 619
                     : plugin_basename($setup_args['main_file_path']),
@@ -669,12 +669,12 @@  discard block
 block discarded – undo
669 669
             // (as the newly-activated addon wasn't around the first time addons were registered).
670 670
             // Note: the presence of pue_options in the addon registration options will initialize the $_settings
671 671
             // property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
672
-            if (! isset(self::$_settings[ $addon_name ])
673
-                || (isset(self::$_settings[ $addon_name ])
674
-                    && ! isset(self::$_settings[ $addon_name ]['class_name'])
672
+            if ( ! isset(self::$_settings[$addon_name])
673
+                || (isset(self::$_settings[$addon_name])
674
+                    && ! isset(self::$_settings[$addon_name]['class_name'])
675 675
                 )
676 676
             ) {
677
-                self::$_settings[ $addon_name ] = $addon_settings;
677
+                self::$_settings[$addon_name] = $addon_settings;
678 678
                 $addon = self::_load_and_init_addon_class($addon_name);
679 679
                 $addon->set_activation_indicator_option();
680 680
                 // dont bother setting up the rest of the addon.
@@ -683,7 +683,7 @@  discard block
 block discarded – undo
683 683
             return true;
684 684
         }
685 685
         // make sure this was called in the right place!
686
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
686
+        if ( ! did_action('AHEE__EE_System__load_espresso_addons')
687 687
             || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
688 688
         ) {
689 689
             EE_Error::doing_it_wrong(
@@ -699,10 +699,10 @@  discard block
 block discarded – undo
699 699
             );
700 700
         }
701 701
         // make sure addon settings are set correctly without overwriting anything existing
702
-        if (isset(self::$_settings[ $addon_name ])) {
703
-            self::$_settings[ $addon_name ] += $addon_settings;
702
+        if (isset(self::$_settings[$addon_name])) {
703
+            self::$_settings[$addon_name] += $addon_settings;
704 704
         } else {
705
-            self::$_settings[ $addon_name ] = $addon_settings;
705
+            self::$_settings[$addon_name] = $addon_settings;
706 706
         }
707 707
         return false;
708 708
     }
@@ -715,13 +715,13 @@  discard block
 block discarded – undo
715 715
      */
716 716
     private static function _setup_autoloaders($addon_name)
717 717
     {
718
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
718
+        if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) {
719 719
             // setup autoloader for single file
720
-            EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
720
+            EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']);
721 721
         }
722 722
         // setup autoloaders for folders
723
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
724
-            foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
723
+        if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) {
724
+            foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
725 725
                 EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
726 726
             }
727 727
         }
@@ -738,26 +738,26 @@  discard block
 block discarded – undo
738 738
     private static function _register_models_and_extensions($addon_name)
739 739
     {
740 740
         // register new models
741
-        if (! empty(self::$_settings[ $addon_name ]['model_paths'])
742
-            || ! empty(self::$_settings[ $addon_name ]['class_paths'])
741
+        if ( ! empty(self::$_settings[$addon_name]['model_paths'])
742
+            || ! empty(self::$_settings[$addon_name]['class_paths'])
743 743
         ) {
744 744
             EE_Register_Model::register(
745 745
                 $addon_name,
746 746
                 array(
747
-                    'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
748
-                    'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
747
+                    'model_paths' => self::$_settings[$addon_name]['model_paths'],
748
+                    'class_paths' => self::$_settings[$addon_name]['class_paths'],
749 749
                 )
750 750
             );
751 751
         }
752 752
         // register model extensions
753
-        if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
754
-            || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
753
+        if ( ! empty(self::$_settings[$addon_name]['model_extension_paths'])
754
+            || ! empty(self::$_settings[$addon_name]['class_extension_paths'])
755 755
         ) {
756 756
             EE_Register_Model_Extensions::register(
757 757
                 $addon_name,
758 758
                 array(
759
-                    'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
760
-                    'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
759
+                    'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'],
760
+                    'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'],
761 761
                 )
762 762
             );
763 763
         }
@@ -772,10 +772,10 @@  discard block
 block discarded – undo
772 772
     private static function _register_data_migration_scripts($addon_name)
773 773
     {
774 774
         // setup DMS
775
-        if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
775
+        if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
776 776
             EE_Register_Data_Migration_Scripts::register(
777 777
                 $addon_name,
778
-                array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths'])
778
+                array('dms_paths' => self::$_settings[$addon_name]['dms_paths'])
779 779
             );
780 780
         }
781 781
     }
@@ -789,12 +789,12 @@  discard block
 block discarded – undo
789 789
     private static function _register_config($addon_name)
790 790
     {
791 791
         // if config_class is present let's register config.
792
-        if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
792
+        if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
793 793
             EE_Register_Config::register(
794
-                self::$_settings[ $addon_name ]['config_class'],
794
+                self::$_settings[$addon_name]['config_class'],
795 795
                 array(
796
-                    'config_section' => self::$_settings[ $addon_name ]['config_section'],
797
-                    'config_name'    => self::$_settings[ $addon_name ]['config_name'],
796
+                    'config_section' => self::$_settings[$addon_name]['config_section'],
797
+                    'config_name'    => self::$_settings[$addon_name]['config_name'],
798 798
                 )
799 799
             );
800 800
         }
@@ -808,10 +808,10 @@  discard block
 block discarded – undo
808 808
      */
809 809
     private static function _register_admin_pages($addon_name)
810 810
     {
811
-        if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
811
+        if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
812 812
             EE_Register_Admin_Page::register(
813 813
                 $addon_name,
814
-                array('page_path' => self::$_settings[ $addon_name ]['admin_path'])
814
+                array('page_path' => self::$_settings[$addon_name]['admin_path'])
815 815
             );
816 816
         }
817 817
     }
@@ -824,10 +824,10 @@  discard block
 block discarded – undo
824 824
      */
825 825
     private static function _register_modules($addon_name)
826 826
     {
827
-        if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
827
+        if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
828 828
             EE_Register_Module::register(
829 829
                 $addon_name,
830
-                array('module_paths' => self::$_settings[ $addon_name ]['module_paths'])
830
+                array('module_paths' => self::$_settings[$addon_name]['module_paths'])
831 831
             );
832 832
         }
833 833
     }
@@ -840,16 +840,16 @@  discard block
 block discarded – undo
840 840
      */
841 841
     private static function _register_shortcodes($addon_name)
842 842
     {
843
-        if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
844
-            || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
843
+        if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])
844
+            || ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
845 845
         ) {
846 846
             EE_Register_Shortcode::register(
847 847
                 $addon_name,
848 848
                 array(
849
-                    'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths'])
850
-                        ? self::$_settings[ $addon_name ]['shortcode_paths'] : array(),
851
-                    'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns'])
852
-                        ? self::$_settings[ $addon_name ]['shortcode_fqcns'] : array(),
849
+                    'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths'])
850
+                        ? self::$_settings[$addon_name]['shortcode_paths'] : array(),
851
+                    'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns'])
852
+                        ? self::$_settings[$addon_name]['shortcode_fqcns'] : array(),
853 853
                 )
854 854
             );
855 855
         }
@@ -863,10 +863,10 @@  discard block
 block discarded – undo
863 863
      */
864 864
     private static function _register_widgets($addon_name)
865 865
     {
866
-        if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
866
+        if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
867 867
             EE_Register_Widget::register(
868 868
                 $addon_name,
869
-                array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths'])
869
+                array('widget_paths' => self::$_settings[$addon_name]['widget_paths'])
870 870
             );
871 871
         }
872 872
     }
@@ -879,12 +879,12 @@  discard block
 block discarded – undo
879 879
      */
880 880
     private static function _register_capabilities($addon_name)
881 881
     {
882
-        if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
882
+        if ( ! empty(self::$_settings[$addon_name]['capabilities'])) {
883 883
             EE_Register_Capabilities::register(
884 884
                 $addon_name,
885 885
                 array(
886
-                    'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
887
-                    'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
886
+                    'capabilities'    => self::$_settings[$addon_name]['capabilities'],
887
+                    'capability_maps' => self::$_settings[$addon_name]['capability_maps'],
888 888
                 )
889 889
             );
890 890
         }
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
      */
898 898
     private static function _register_message_types($addon_name)
899 899
     {
900
-        if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
900
+        if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
901 901
             add_action(
902 902
                 'EE_Brewing_Regular___messages_caf',
903 903
                 array('EE_Register_Addon', 'register_message_types')
@@ -913,15 +913,15 @@  discard block
 block discarded – undo
913 913
      */
914 914
     private static function _register_custom_post_types($addon_name)
915 915
     {
916
-        if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])
917
-            || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
916
+        if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])
917
+            || ! empty(self::$_settings[$addon_name]['custom_taxonomies'])
918 918
         ) {
919 919
             EE_Register_CPT::register(
920 920
                 $addon_name,
921 921
                 array(
922
-                    'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
923
-                    'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
924
-                    'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
922
+                    'cpts'          => self::$_settings[$addon_name]['custom_post_types'],
923
+                    'cts'           => self::$_settings[$addon_name]['custom_taxonomies'],
924
+                    'default_terms' => self::$_settings[$addon_name]['default_terms'],
925 925
                 )
926 926
             );
927 927
         }
@@ -939,10 +939,10 @@  discard block
 block discarded – undo
939 939
      */
940 940
     private static function _register_payment_methods($addon_name)
941 941
     {
942
-        if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
942
+        if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
943 943
             EE_Register_Payment_Method::register(
944 944
                 $addon_name,
945
-                array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths'])
945
+                array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths'])
946 946
             );
947 947
         }
948 948
     }
@@ -958,10 +958,10 @@  discard block
 block discarded – undo
958 958
      */
959 959
     private static function registerPrivacyPolicies($addon_name)
960 960
     {
961
-        if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) {
961
+        if ( ! empty(self::$_settings[$addon_name]['privacy_policies'])) {
962 962
             EE_Register_Privacy_Policy::register(
963 963
                 $addon_name,
964
-                self::$_settings[ $addon_name ]['privacy_policies']
964
+                self::$_settings[$addon_name]['privacy_policies']
965 965
             );
966 966
         }
967 967
     }
@@ -973,10 +973,10 @@  discard block
 block discarded – undo
973 973
      */
974 974
     private static function registerPersonalDataExporters($addon_name)
975 975
     {
976
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) {
976
+        if ( ! empty(self::$_settings[$addon_name]['personal_data_exporters'])) {
977 977
             EE_Register_Personal_Data_Eraser::register(
978 978
                 $addon_name,
979
-                self::$_settings[ $addon_name ]['personal_data_exporters']
979
+                self::$_settings[$addon_name]['personal_data_exporters']
980 980
             );
981 981
         }
982 982
     }
@@ -988,10 +988,10 @@  discard block
 block discarded – undo
988 988
      */
989 989
     private static function registerPersonalDataErasers($addon_name)
990 990
     {
991
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) {
991
+        if ( ! empty(self::$_settings[$addon_name]['personal_data_erasers'])) {
992 992
             EE_Register_Personal_Data_Eraser::register(
993 993
                 $addon_name,
994
-                self::$_settings[ $addon_name ]['personal_data_erasers']
994
+                self::$_settings[$addon_name]['personal_data_erasers']
995 995
             );
996 996
         }
997 997
     }
@@ -1009,10 +1009,10 @@  discard block
 block discarded – undo
1009 1009
     private static function _load_and_init_addon_class($addon_name)
1010 1010
     {
1011 1011
         $addon = LoaderFactory::getLoader()->getShared(
1012
-            self::$_settings[ $addon_name ]['class_name'],
1012
+            self::$_settings[$addon_name]['class_name'],
1013 1013
             array('EE_Registry::create(addon)' => true)
1014 1014
         );
1015
-        if (! $addon instanceof EE_Addon) {
1015
+        if ( ! $addon instanceof EE_Addon) {
1016 1016
             throw new DomainException(
1017 1017
                 sprintf(
1018 1018
                     esc_html__(
@@ -1031,28 +1031,28 @@  discard block
 block discarded – undo
1031 1031
         EE_Register_Addon::injectAddonDomain($addon_name, $addon);
1032 1032
 
1033 1033
         $addon->set_name($addon_name);
1034
-        $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
1035
-        $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
1036
-        $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
1037
-        $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
1038
-        $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
1039
-        $addon->set_version(self::$_settings[ $addon_name ]['version']);
1040
-        $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
1041
-        $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
1042
-        $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
1043
-        $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
1034
+        $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']);
1035
+        $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']);
1036
+        $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']);
1037
+        $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']);
1038
+        $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']);
1039
+        $addon->set_version(self::$_settings[$addon_name]['version']);
1040
+        $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version']));
1041
+        $addon->set_config_section(self::$_settings[$addon_name]['config_section']);
1042
+        $addon->set_config_class(self::$_settings[$addon_name]['config_class']);
1043
+        $addon->set_config_name(self::$_settings[$addon_name]['config_name']);
1044 1044
         // setup the add-on's pue_slug if we have one.
1045
-        if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) {
1046
-            $addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']);
1045
+        if ( ! empty(self::$_settings[$addon_name]['pue_options']['pue_plugin_slug'])) {
1046
+            $addon->setPueSlug(self::$_settings[$addon_name]['pue_options']['pue_plugin_slug']);
1047 1047
         }
1048 1048
         // unfortunately this can't be hooked in upon construction,
1049 1049
         // because we don't have the plugin's mainfile path upon construction.
1050 1050
         register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
1051 1051
         // call any additional admin_callback functions during load_admin_controller hook
1052
-        if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
1052
+        if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) {
1053 1053
             add_action(
1054 1054
                 'AHEE__EE_System__load_controllers__load_admin_controllers',
1055
-                array($addon, self::$_settings[ $addon_name ]['admin_callback'])
1055
+                array($addon, self::$_settings[$addon_name]['admin_callback'])
1056 1056
             );
1057 1057
         }
1058 1058
         return $addon;
@@ -1068,19 +1068,19 @@  discard block
 block discarded – undo
1068 1068
     {
1069 1069
         if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) {
1070 1070
             // using supplied Domain object
1071
-            $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface
1072
-                ? self::$_settings[ $addon_name ]['domain']
1071
+            $domain = self::$_settings[$addon_name]['domain'] instanceof DomainInterface
1072
+                ? self::$_settings[$addon_name]['domain']
1073 1073
                 : null;
1074 1074
             // or construct one using Domain FQCN
1075
-            if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') {
1075
+            if ($domain === null && self::$_settings[$addon_name]['domain_fqcn'] !== '') {
1076 1076
                 $domain = LoaderFactory::getLoader()->getShared(
1077
-                    self::$_settings[ $addon_name ]['domain_fqcn'],
1077
+                    self::$_settings[$addon_name]['domain_fqcn'],
1078 1078
                     [
1079 1079
                         new EventEspresso\core\domain\values\FilePath(
1080
-                            self::$_settings[ $addon_name ]['main_file_path']
1080
+                            self::$_settings[$addon_name]['main_file_path']
1081 1081
                         ),
1082 1082
                         EventEspresso\core\domain\values\Version::fromString(
1083
-                            self::$_settings[ $addon_name ]['version']
1083
+                            self::$_settings[$addon_name]['version']
1084 1084
                         ),
1085 1085
                     ]
1086 1086
                 );
@@ -1103,11 +1103,11 @@  discard block
 block discarded – undo
1103 1103
     public static function load_pue_update()
1104 1104
     {
1105 1105
         // load PUE client
1106
-        require_once EE_THIRD_PARTY . 'pue/pue-client.php';
1106
+        require_once EE_THIRD_PARTY.'pue/pue-client.php';
1107 1107
         $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com';
1108 1108
         // cycle thru settings
1109 1109
         foreach (self::$_settings as $settings) {
1110
-            if (! empty($settings['pue_options'])) {
1110
+            if ( ! empty($settings['pue_options'])) {
1111 1111
                 // initiate the class and start the plugin update engine!
1112 1112
                 new PluginUpdateEngineChecker(
1113 1113
                     // host file URL
@@ -1115,7 +1115,7 @@  discard block
 block discarded – undo
1115 1115
                     // plugin slug(s)
1116 1116
                     array(
1117 1117
                         'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
1118
-                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
1118
+                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'),
1119 1119
                     ),
1120 1120
                     // options
1121 1121
                     array(
@@ -1144,7 +1144,7 @@  discard block
 block discarded – undo
1144 1144
     public static function register_message_types()
1145 1145
     {
1146 1146
         foreach (self::$_settings as $settings) {
1147
-            if (! empty($settings['message_types'])) {
1147
+            if ( ! empty($settings['message_types'])) {
1148 1148
                 foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1149 1149
                     EE_Register_Message_Type::register($message_type, $message_type_settings);
1150 1150
                 }
@@ -1165,70 +1165,70 @@  discard block
 block discarded – undo
1165 1165
      */
1166 1166
     public static function deregister($addon_name = '')
1167 1167
     {
1168
-        if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1168
+        if (isset(self::$_settings[$addon_name]['class_name'])) {
1169 1169
             try {
1170 1170
                 do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1171
-                $class_name = self::$_settings[ $addon_name ]['class_name'];
1172
-                if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1171
+                $class_name = self::$_settings[$addon_name]['class_name'];
1172
+                if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
1173 1173
                     // setup DMS
1174 1174
                     EE_Register_Data_Migration_Scripts::deregister($addon_name);
1175 1175
                 }
1176
-                if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1176
+                if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
1177 1177
                     // register admin page
1178 1178
                     EE_Register_Admin_Page::deregister($addon_name);
1179 1179
                 }
1180
-                if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1180
+                if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
1181 1181
                     // add to list of modules to be registered
1182 1182
                     EE_Register_Module::deregister($addon_name);
1183 1183
                 }
1184
-                if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1185
-                    || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1184
+                if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])
1185
+                    || ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
1186 1186
                 ) {
1187 1187
                     // add to list of shortcodes to be registered
1188 1188
                     EE_Register_Shortcode::deregister($addon_name);
1189 1189
                 }
1190
-                if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1190
+                if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
1191 1191
                     // if config_class present let's register config.
1192
-                    EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1192
+                    EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']);
1193 1193
                 }
1194
-                if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1194
+                if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
1195 1195
                     // add to list of widgets to be registered
1196 1196
                     EE_Register_Widget::deregister($addon_name);
1197 1197
                 }
1198
-                if (! empty(self::$_settings[ $addon_name ]['model_paths'])
1199
-                    || ! empty(self::$_settings[ $addon_name ]['class_paths'])
1198
+                if ( ! empty(self::$_settings[$addon_name]['model_paths'])
1199
+                    || ! empty(self::$_settings[$addon_name]['class_paths'])
1200 1200
                 ) {
1201 1201
                     // add to list of shortcodes to be registered
1202 1202
                     EE_Register_Model::deregister($addon_name);
1203 1203
                 }
1204
-                if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1205
-                    || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1204
+                if ( ! empty(self::$_settings[$addon_name]['model_extension_paths'])
1205
+                    || ! empty(self::$_settings[$addon_name]['class_extension_paths'])
1206 1206
                 ) {
1207 1207
                     // add to list of shortcodes to be registered
1208 1208
                     EE_Register_Model_Extensions::deregister($addon_name);
1209 1209
                 }
1210
-                if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1211
-                    foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) {
1210
+                if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
1211
+                    foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) {
1212 1212
                         EE_Register_Message_Type::deregister($message_type);
1213 1213
                     }
1214 1214
                 }
1215 1215
                 // deregister capabilities for addon
1216
-                if (! empty(self::$_settings[ $addon_name ]['capabilities'])
1217
-                    || ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1216
+                if ( ! empty(self::$_settings[$addon_name]['capabilities'])
1217
+                    || ! empty(self::$_settings[$addon_name]['capability_maps'])
1218 1218
                 ) {
1219 1219
                     EE_Register_Capabilities::deregister($addon_name);
1220 1220
                 }
1221 1221
                 // deregister custom_post_types for addon
1222
-                if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1222
+                if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) {
1223 1223
                     EE_Register_CPT::deregister($addon_name);
1224 1224
                 }
1225
-                if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1225
+                if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
1226 1226
                     EE_Register_Payment_Method::deregister($addon_name);
1227 1227
                 }
1228 1228
                 $addon = EE_Registry::instance()->getAddon($class_name);
1229 1229
                 if ($addon instanceof EE_Addon) {
1230 1230
                     remove_action(
1231
-                        'deactivate_' . $addon->get_main_plugin_file_basename(),
1231
+                        'deactivate_'.$addon->get_main_plugin_file_basename(),
1232 1232
                         array($addon, 'deactivation')
1233 1233
                     );
1234 1234
                     remove_action(
@@ -1251,7 +1251,7 @@  discard block
 block discarded – undo
1251 1251
             } catch (Exception $e) {
1252 1252
                 new ExceptionLogger($e);
1253 1253
             }
1254
-            unset(self::$_settings[ $addon_name ]);
1254
+            unset(self::$_settings[$addon_name]);
1255 1255
             do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1256 1256
         }
1257 1257
     }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Model.lib.php 2 patches
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -11,183 +11,183 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Register_Model implements EEI_Plugin_API
13 13
 {
14
-    /**
15
-     *
16
-     * @var array keys are the model_id used to register with, values are the array provided to register them, exactly
17
-     *      like EE_Register_Model::register()'s 2nd arg
18
-     */
19
-    protected static $_model_registry;
14
+	/**
15
+	 *
16
+	 * @var array keys are the model_id used to register with, values are the array provided to register them, exactly
17
+	 *      like EE_Register_Model::register()'s 2nd arg
18
+	 */
19
+	protected static $_model_registry;
20 20
 
21
-    /**
22
-     *
23
-     * @var array keys are model names, values are their class names. Stored on registration and used
24
-     * on a hook
25
-     */
26
-    protected static $_model_name_to_classname_map;
21
+	/**
22
+	 *
23
+	 * @var array keys are model names, values are their class names. Stored on registration and used
24
+	 * on a hook
25
+	 */
26
+	protected static $_model_name_to_classname_map;
27 27
 
28 28
 
29
-    /**
30
-     * @param string $identifier  unique id for it
31
-     * @param array  $setup_args  {
32
-     * @type array   $model_paths array of folders containing DB models, where each file follows the models naming
33
-     *                            convention, which is: EEM_{model_name}.model.php which contains a single class called
34
-     *                            EEM_{model_name}. Eg. you could pass
35
-     *                            "public_html/wp-content/plugins/my_addon/db_models" (with or without trailing slash)
36
-     *                            and in that folder put each of your model files, like "EEM_Food.model.php" which
37
-     *                            contains the class "EEM_Food" and
38
-     *                            "EEM_Monkey.model.php" which contains the class "EEM_Monkey". These will be
39
-     *                            autoloaded and added to the EE registry so they can be used like ordinary models. The
40
-     *                            class contained in each file should extend EEM_Base.
41
-     * @type array   $class_paths array of folders containing DB classes, where each file follows the model class
42
-     *                            naming convention, which is EE_{model_name}.class.php. The class contained in each
43
-     *                            file should extend EE_Base_Class
44
-     *
45
-     * }
46
-     * @throws EE_Error
47
-     */
48
-    public static function register($identifier = '', array $setup_args = [])
49
-    {
50
-        // required fields MUST be present, so let's make sure they are.
51
-        if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['model_paths'])) {
52
-            throw new EE_Error(
53
-                __(
54
-                    'In order to register Models with EE_Register_Model::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_paths" (an array of full server paths to folders that contain models)',
55
-                    'event_espresso'
56
-                )
57
-            );
58
-        }
29
+	/**
30
+	 * @param string $identifier  unique id for it
31
+	 * @param array  $setup_args  {
32
+	 * @type array   $model_paths array of folders containing DB models, where each file follows the models naming
33
+	 *                            convention, which is: EEM_{model_name}.model.php which contains a single class called
34
+	 *                            EEM_{model_name}. Eg. you could pass
35
+	 *                            "public_html/wp-content/plugins/my_addon/db_models" (with or without trailing slash)
36
+	 *                            and in that folder put each of your model files, like "EEM_Food.model.php" which
37
+	 *                            contains the class "EEM_Food" and
38
+	 *                            "EEM_Monkey.model.php" which contains the class "EEM_Monkey". These will be
39
+	 *                            autoloaded and added to the EE registry so they can be used like ordinary models. The
40
+	 *                            class contained in each file should extend EEM_Base.
41
+	 * @type array   $class_paths array of folders containing DB classes, where each file follows the model class
42
+	 *                            naming convention, which is EE_{model_name}.class.php. The class contained in each
43
+	 *                            file should extend EE_Base_Class
44
+	 *
45
+	 * }
46
+	 * @throws EE_Error
47
+	 */
48
+	public static function register($identifier = '', array $setup_args = [])
49
+	{
50
+		// required fields MUST be present, so let's make sure they are.
51
+		if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['model_paths'])) {
52
+			throw new EE_Error(
53
+				__(
54
+					'In order to register Models with EE_Register_Model::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_paths" (an array of full server paths to folders that contain models)',
55
+					'event_espresso'
56
+				)
57
+			);
58
+		}
59 59
 
60
-        // make sure we don't register twice
61
-        if (isset(self::$_model_registry[ $identifier ])) {
62
-            return;
63
-        }
60
+		// make sure we don't register twice
61
+		if (isset(self::$_model_registry[ $identifier ])) {
62
+			return;
63
+		}
64 64
 
65
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
66
-            || did_action('FHEE__EE_System__parse_model_names')
67
-            || did_action('FHEE__EE_System__parse_implemented_model_names')) {
68
-            EE_Error::doing_it_wrong(
69
-                __METHOD__,
70
-                sprintf(
71
-                    __(
72
-                        'An attempt was made to register "%s" as a group models has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.',
73
-                        'event_espresso'
74
-                    ),
75
-                    $identifier
76
-                ),
77
-                '4.5'
78
-            );
79
-        }
80
-        self::$_model_registry[ $identifier ] = $setup_args;
65
+		if (! did_action('AHEE__EE_System__load_espresso_addons')
66
+			|| did_action('FHEE__EE_System__parse_model_names')
67
+			|| did_action('FHEE__EE_System__parse_implemented_model_names')) {
68
+			EE_Error::doing_it_wrong(
69
+				__METHOD__,
70
+				sprintf(
71
+					__(
72
+						'An attempt was made to register "%s" as a group models has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.',
73
+						'event_espresso'
74
+					),
75
+					$identifier
76
+				),
77
+				'4.5'
78
+			);
79
+		}
80
+		self::$_model_registry[ $identifier ] = $setup_args;
81 81
 
82
-        if ((isset($setup_args['model_paths']) && ! isset($setup_args['class_paths']))
83
-            || (! isset($setup_args['model_paths']) && isset($setup_args['class_paths']))) {
84
-            throw new EE_Error(
85
-                sprintf(
86
-                    __(
87
-                        'You must register both "model_paths" AND "class_paths", not just one or the other You provided %s',
88
-                        'event_espresso'
89
-                    ),
90
-                    implode(", ", array_keys($setup_args))
91
-                )
92
-            );
93
-        }
94
-        if (isset($setup_args['model_paths'])) {
95
-            // make sure they passed in an array
96
-            if (! is_array($setup_args['model_paths'])) {
97
-                $setup_args['model_paths'] = [$setup_args['model_paths']];
98
-            }
99
-            // we want to add this as a model folder
100
-            // and autoload them all
101
-            $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_paths']);
102
-            EEH_Autoloader::register_autoloader($class_to_filepath_map);
103
-            $model_name_to_classname_map = [];
104
-            foreach (array_keys($class_to_filepath_map) as $classname) {
105
-                $model_name_to_classname_map[ str_replace("EEM_", "", $classname) ] = $classname;
106
-            }
107
-            self::$_model_name_to_classname_map[ $identifier ] = $model_name_to_classname_map;
108
-            add_filter('FHEE__EE_System__parse_model_names', ['EE_Register_Model', 'add_addon_models']);
109
-            add_filter(
110
-                'FHEE__EE_System__parse_implemented_model_names',
111
-                ['EE_Register_Model', 'add_addon_models']
112
-            );
113
-            add_filter('FHEE__EE_Registry__load_model__paths', ['EE_Register_Model', 'add_model_folders']);
114
-            unset($setup_args['model_paths']);
115
-        }
116
-        if (isset($setup_args['class_paths'])) {
117
-            // make sure they passed in an array
118
-            if (! is_array($setup_args['class_paths'])) {
119
-                $setup_args['class_paths'] = [$setup_args['class_paths']];
120
-            }
121
-            $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_paths']);
122
-            EEH_Autoloader::register_autoloader($class_to_filepath_map);
123
-            add_filter('FHEE__EE_Registry__load_class__paths', ['EE_Register_Model', 'add_class_folders']);
124
-            unset($setup_args['class_paths']);
125
-        }
126
-        foreach ($setup_args as $unknown_key => $unknown_config) {
127
-            self::deregister($identifier);
128
-            throw new EE_Error(
129
-                sprintf(__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key)
130
-            );
131
-        }
132
-    }
82
+		if ((isset($setup_args['model_paths']) && ! isset($setup_args['class_paths']))
83
+			|| (! isset($setup_args['model_paths']) && isset($setup_args['class_paths']))) {
84
+			throw new EE_Error(
85
+				sprintf(
86
+					__(
87
+						'You must register both "model_paths" AND "class_paths", not just one or the other You provided %s',
88
+						'event_espresso'
89
+					),
90
+					implode(", ", array_keys($setup_args))
91
+				)
92
+			);
93
+		}
94
+		if (isset($setup_args['model_paths'])) {
95
+			// make sure they passed in an array
96
+			if (! is_array($setup_args['model_paths'])) {
97
+				$setup_args['model_paths'] = [$setup_args['model_paths']];
98
+			}
99
+			// we want to add this as a model folder
100
+			// and autoload them all
101
+			$class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_paths']);
102
+			EEH_Autoloader::register_autoloader($class_to_filepath_map);
103
+			$model_name_to_classname_map = [];
104
+			foreach (array_keys($class_to_filepath_map) as $classname) {
105
+				$model_name_to_classname_map[ str_replace("EEM_", "", $classname) ] = $classname;
106
+			}
107
+			self::$_model_name_to_classname_map[ $identifier ] = $model_name_to_classname_map;
108
+			add_filter('FHEE__EE_System__parse_model_names', ['EE_Register_Model', 'add_addon_models']);
109
+			add_filter(
110
+				'FHEE__EE_System__parse_implemented_model_names',
111
+				['EE_Register_Model', 'add_addon_models']
112
+			);
113
+			add_filter('FHEE__EE_Registry__load_model__paths', ['EE_Register_Model', 'add_model_folders']);
114
+			unset($setup_args['model_paths']);
115
+		}
116
+		if (isset($setup_args['class_paths'])) {
117
+			// make sure they passed in an array
118
+			if (! is_array($setup_args['class_paths'])) {
119
+				$setup_args['class_paths'] = [$setup_args['class_paths']];
120
+			}
121
+			$class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_paths']);
122
+			EEH_Autoloader::register_autoloader($class_to_filepath_map);
123
+			add_filter('FHEE__EE_Registry__load_class__paths', ['EE_Register_Model', 'add_class_folders']);
124
+			unset($setup_args['class_paths']);
125
+		}
126
+		foreach ($setup_args as $unknown_key => $unknown_config) {
127
+			self::deregister($identifier);
128
+			throw new EE_Error(
129
+				sprintf(__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key)
130
+			);
131
+		}
132
+	}
133 133
 
134 134
 
135
-    /**
136
-     * Filters the core list of models
137
-     *
138
-     * @param array $core_models
139
-     * @return array keys are model names (eg 'Event') and values are their classes (eg 'EE_Event')
140
-     */
141
-    public static function add_addon_models(array $core_models = [])
142
-    {
143
-        foreach (self::$_model_name_to_classname_map as $model_name_to_class_map) {
144
-            $core_models = array_merge($core_models, $model_name_to_class_map);
145
-        }
146
-        return $core_models;
147
-    }
135
+	/**
136
+	 * Filters the core list of models
137
+	 *
138
+	 * @param array $core_models
139
+	 * @return array keys are model names (eg 'Event') and values are their classes (eg 'EE_Event')
140
+	 */
141
+	public static function add_addon_models(array $core_models = [])
142
+	{
143
+		foreach (self::$_model_name_to_classname_map as $model_name_to_class_map) {
144
+			$core_models = array_merge($core_models, $model_name_to_class_map);
145
+		}
146
+		return $core_models;
147
+	}
148 148
 
149 149
 
150
-    /**
151
-     * Filters the list of model folders
152
-     *
153
-     * @param array $folders
154
-     * @return array of folder paths
155
-     */
156
-    public static function add_model_folders(array $folders = [])
157
-    {
158
-        foreach (self::$_model_registry as $setup_args) {
159
-            if (isset($setup_args['model_paths'])) {
160
-                $folders = array_merge($folders, $setup_args['model_paths']);
161
-            }
162
-        }
163
-        return $folders;
164
-    }
150
+	/**
151
+	 * Filters the list of model folders
152
+	 *
153
+	 * @param array $folders
154
+	 * @return array of folder paths
155
+	 */
156
+	public static function add_model_folders(array $folders = [])
157
+	{
158
+		foreach (self::$_model_registry as $setup_args) {
159
+			if (isset($setup_args['model_paths'])) {
160
+				$folders = array_merge($folders, $setup_args['model_paths']);
161
+			}
162
+		}
163
+		return $folders;
164
+	}
165 165
 
166 166
 
167
-    /**
168
-     * Filters the array of model class paths
169
-     *
170
-     * @param array $folders
171
-     * @return array of folder paths
172
-     */
173
-    public static function add_class_folders(array $folders = [])
174
-    {
175
-        foreach (self::$_model_registry as $setup_args) {
176
-            if (isset($setup_args['class_paths'])) {
177
-                $folders = array_merge($folders, $setup_args['class_paths']);
178
-            }
179
-        }
180
-        return $folders;
181
-    }
167
+	/**
168
+	 * Filters the array of model class paths
169
+	 *
170
+	 * @param array $folders
171
+	 * @return array of folder paths
172
+	 */
173
+	public static function add_class_folders(array $folders = [])
174
+	{
175
+		foreach (self::$_model_registry as $setup_args) {
176
+			if (isset($setup_args['class_paths'])) {
177
+				$folders = array_merge($folders, $setup_args['class_paths']);
178
+			}
179
+		}
180
+		return $folders;
181
+	}
182 182
 
183 183
 
184
-    /**
185
-     * deregister
186
-     *
187
-     * @param string $identifier
188
-     */
189
-    public static function deregister($identifier = '')
190
-    {
191
-        unset(self::$_model_registry[ $identifier ], self::$_model_name_to_classname_map[ $identifier ]);
192
-    }
184
+	/**
185
+	 * deregister
186
+	 *
187
+	 * @param string $identifier
188
+	 */
189
+	public static function deregister($identifier = '')
190
+	{
191
+		unset(self::$_model_registry[ $identifier ], self::$_model_name_to_classname_map[ $identifier ]);
192
+	}
193 193
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -58,11 +58,11 @@  discard block
 block discarded – undo
58 58
         }
59 59
 
60 60
         // make sure we don't register twice
61
-        if (isset(self::$_model_registry[ $identifier ])) {
61
+        if (isset(self::$_model_registry[$identifier])) {
62 62
             return;
63 63
         }
64 64
 
65
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
65
+        if ( ! did_action('AHEE__EE_System__load_espresso_addons')
66 66
             || did_action('FHEE__EE_System__parse_model_names')
67 67
             || did_action('FHEE__EE_System__parse_implemented_model_names')) {
68 68
             EE_Error::doing_it_wrong(
@@ -77,10 +77,10 @@  discard block
 block discarded – undo
77 77
                 '4.5'
78 78
             );
79 79
         }
80
-        self::$_model_registry[ $identifier ] = $setup_args;
80
+        self::$_model_registry[$identifier] = $setup_args;
81 81
 
82 82
         if ((isset($setup_args['model_paths']) && ! isset($setup_args['class_paths']))
83
-            || (! isset($setup_args['model_paths']) && isset($setup_args['class_paths']))) {
83
+            || ( ! isset($setup_args['model_paths']) && isset($setup_args['class_paths']))) {
84 84
             throw new EE_Error(
85 85
                 sprintf(
86 86
                     __(
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
         }
94 94
         if (isset($setup_args['model_paths'])) {
95 95
             // make sure they passed in an array
96
-            if (! is_array($setup_args['model_paths'])) {
96
+            if ( ! is_array($setup_args['model_paths'])) {
97 97
                 $setup_args['model_paths'] = [$setup_args['model_paths']];
98 98
             }
99 99
             // we want to add this as a model folder
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
             EEH_Autoloader::register_autoloader($class_to_filepath_map);
103 103
             $model_name_to_classname_map = [];
104 104
             foreach (array_keys($class_to_filepath_map) as $classname) {
105
-                $model_name_to_classname_map[ str_replace("EEM_", "", $classname) ] = $classname;
105
+                $model_name_to_classname_map[str_replace("EEM_", "", $classname)] = $classname;
106 106
             }
107
-            self::$_model_name_to_classname_map[ $identifier ] = $model_name_to_classname_map;
107
+            self::$_model_name_to_classname_map[$identifier] = $model_name_to_classname_map;
108 108
             add_filter('FHEE__EE_System__parse_model_names', ['EE_Register_Model', 'add_addon_models']);
109 109
             add_filter(
110 110
                 'FHEE__EE_System__parse_implemented_model_names',
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
         }
116 116
         if (isset($setup_args['class_paths'])) {
117 117
             // make sure they passed in an array
118
-            if (! is_array($setup_args['class_paths'])) {
118
+            if ( ! is_array($setup_args['class_paths'])) {
119 119
                 $setup_args['class_paths'] = [$setup_args['class_paths']];
120 120
             }
121 121
             $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_paths']);
@@ -188,6 +188,6 @@  discard block
 block discarded – undo
188 188
      */
189 189
     public static function deregister($identifier = '')
190 190
     {
191
-        unset(self::$_model_registry[ $identifier ], self::$_model_name_to_classname_map[ $identifier ]);
191
+        unset(self::$_model_registry[$identifier], self::$_model_name_to_classname_map[$identifier]);
192 192
     }
193 193
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Module.lib.php 2 patches
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -15,95 +15,95 @@
 block discarded – undo
15 15
 class EE_Register_Module implements EEI_Plugin_API
16 16
 {
17 17
 
18
-    /**
19
-     * Holds values for registered modules
20
-     *
21
-     * @var array
22
-     */
23
-    protected static $_settings = [];
18
+	/**
19
+	 * Holds values for registered modules
20
+	 *
21
+	 * @var array
22
+	 */
23
+	protected static $_settings = [];
24 24
 
25 25
 
26
-    /**
27
-     *    Method for registering new EED_Modules
28
-     *
29
-     * @param string $identifier a unique identifier for this set of modules Required.
30
-     * @param array  $setup_args an array of full server paths to folders containing any EED_Modules, or to the
31
-     *                           EED_Module files themselves Required.
32
-     * @type    array module_paths    an array of full server paths to folders containing any EED_Modules, or to the
33
-     *                           EED_Module files themselves
34
-     * @return void
35
-     * @throws EE_Error
36
-     * @since    4.3.0
37
-     */
38
-    public static function register($identifier = '', array $setup_args = [])
39
-    {
40
-        // required fields MUST be present, so let's make sure they are.
41
-        if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['module_paths'])) {
42
-            throw new EE_Error(
43
-                __(
44
-                    'In order to register Modules with EE_Register_Module::register(), you must include a "module_id" (a unique identifier for this set of modules), and an array containing the following keys: "module_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)',
45
-                    'event_espresso'
46
-                )
47
-            );
48
-        }
26
+	/**
27
+	 *    Method for registering new EED_Modules
28
+	 *
29
+	 * @param string $identifier a unique identifier for this set of modules Required.
30
+	 * @param array  $setup_args an array of full server paths to folders containing any EED_Modules, or to the
31
+	 *                           EED_Module files themselves Required.
32
+	 * @type    array module_paths    an array of full server paths to folders containing any EED_Modules, or to the
33
+	 *                           EED_Module files themselves
34
+	 * @return void
35
+	 * @throws EE_Error
36
+	 * @since    4.3.0
37
+	 */
38
+	public static function register($identifier = '', array $setup_args = [])
39
+	{
40
+		// required fields MUST be present, so let's make sure they are.
41
+		if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['module_paths'])) {
42
+			throw new EE_Error(
43
+				__(
44
+					'In order to register Modules with EE_Register_Module::register(), you must include a "module_id" (a unique identifier for this set of modules), and an array containing the following keys: "module_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)',
45
+					'event_espresso'
46
+				)
47
+			);
48
+		}
49 49
 
50
-        // make sure we don't register twice
51
-        if (isset(self::$_settings[ $identifier ])) {
52
-            return;
53
-        }
50
+		// make sure we don't register twice
51
+		if (isset(self::$_settings[ $identifier ])) {
52
+			return;
53
+		}
54 54
 
55
-        // make sure this was called in the right place!
56
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
57
-            || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
58
-        ) {
59
-            EE_Error::doing_it_wrong(
60
-                __METHOD__,
61
-                __(
62
-                    'An attempt to register modules has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.',
63
-                    'event_espresso'
64
-                ),
65
-                '4.3.0'
66
-            );
67
-        }
68
-        // setup $_settings array from incoming values.
69
-        self::$_settings[ $identifier ] = [
70
-            // array of full server paths to any EED_Modules used by the module
71
-            'module_paths' => isset($setup_args['module_paths']) ? (array) $setup_args['module_paths'] : [],
72
-        ];
73
-        // add to list of modules to be registered
74
-        add_filter(
75
-            'FHEE__EE_Config__register_modules__modules_to_register',
76
-            ['EE_Register_Module', 'add_modules']
77
-        );
78
-    }
55
+		// make sure this was called in the right place!
56
+		if (! did_action('AHEE__EE_System__load_espresso_addons')
57
+			|| did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
58
+		) {
59
+			EE_Error::doing_it_wrong(
60
+				__METHOD__,
61
+				__(
62
+					'An attempt to register modules has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.',
63
+					'event_espresso'
64
+				),
65
+				'4.3.0'
66
+			);
67
+		}
68
+		// setup $_settings array from incoming values.
69
+		self::$_settings[ $identifier ] = [
70
+			// array of full server paths to any EED_Modules used by the module
71
+			'module_paths' => isset($setup_args['module_paths']) ? (array) $setup_args['module_paths'] : [],
72
+		];
73
+		// add to list of modules to be registered
74
+		add_filter(
75
+			'FHEE__EE_Config__register_modules__modules_to_register',
76
+			['EE_Register_Module', 'add_modules']
77
+		);
78
+	}
79 79
 
80 80
 
81
-    /**
82
-     * Filters the list of modules to add ours.
83
-     * and they're just full filepaths to FOLDERS containing a module class file. Eg.
84
-     * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey'...)
85
-     *
86
-     * @param array $modules_to_register array of paths to all modules that require registering
87
-     * @return array
88
-     */
89
-    public static function add_modules(array $modules_to_register)
90
-    {
91
-        foreach (self::$_settings as $settings) {
92
-            $modules_to_register = array_merge($modules_to_register, $settings['module_paths']);
93
-        }
94
-        return $modules_to_register;
95
-    }
81
+	/**
82
+	 * Filters the list of modules to add ours.
83
+	 * and they're just full filepaths to FOLDERS containing a module class file. Eg.
84
+	 * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey'...)
85
+	 *
86
+	 * @param array $modules_to_register array of paths to all modules that require registering
87
+	 * @return array
88
+	 */
89
+	public static function add_modules(array $modules_to_register)
90
+	{
91
+		foreach (self::$_settings as $settings) {
92
+			$modules_to_register = array_merge($modules_to_register, $settings['module_paths']);
93
+		}
94
+		return $modules_to_register;
95
+	}
96 96
 
97 97
 
98
-    /**
99
-     * This deregisters a module that was previously registered with a specific $identifier.
100
-     *
101
-     * @param string $identifier the name for the module that was previously registered
102
-     * @return void
103
-     * @since    4.3.0
104
-     */
105
-    public static function deregister($identifier = '')
106
-    {
107
-        unset(self::$_settings[ $identifier ]);
108
-    }
98
+	/**
99
+	 * This deregisters a module that was previously registered with a specific $identifier.
100
+	 *
101
+	 * @param string $identifier the name for the module that was previously registered
102
+	 * @return void
103
+	 * @since    4.3.0
104
+	 */
105
+	public static function deregister($identifier = '')
106
+	{
107
+		unset(self::$_settings[ $identifier ]);
108
+	}
109 109
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -48,12 +48,12 @@  discard block
 block discarded – undo
48 48
         }
49 49
 
50 50
         // make sure we don't register twice
51
-        if (isset(self::$_settings[ $identifier ])) {
51
+        if (isset(self::$_settings[$identifier])) {
52 52
             return;
53 53
         }
54 54
 
55 55
         // make sure this was called in the right place!
56
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
56
+        if ( ! did_action('AHEE__EE_System__load_espresso_addons')
57 57
             || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
58 58
         ) {
59 59
             EE_Error::doing_it_wrong(
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
             );
67 67
         }
68 68
         // setup $_settings array from incoming values.
69
-        self::$_settings[ $identifier ] = [
69
+        self::$_settings[$identifier] = [
70 70
             // array of full server paths to any EED_Modules used by the module
71 71
             'module_paths' => isset($setup_args['module_paths']) ? (array) $setup_args['module_paths'] : [],
72 72
         ];
@@ -104,6 +104,6 @@  discard block
 block discarded – undo
104 104
      */
105 105
     public static function deregister($identifier = '')
106 106
     {
107
-        unset(self::$_settings[ $identifier ]);
107
+        unset(self::$_settings[$identifier]);
108 108
     }
109 109
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Message_Type.lib.php 2 patches
Indentation   +447 added lines, -447 removed lines patch added patch discarded remove patch
@@ -12,477 +12,477 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * Holds values for registered message types
17
-     *
18
-     * @var array
19
-     */
20
-    protected static $_ee_message_type_registry = [];
15
+	/**
16
+	 * Holds values for registered message types
17
+	 *
18
+	 * @var array
19
+	 */
20
+	protected static $_ee_message_type_registry = [];
21 21
 
22 22
 
23
-    /**
24
-     * Method for registering new message types in the EE_messages system.
25
-     * Note:  All message types must have the following files in order to work:
26
-     * Template files for default templates getting setup.
27
-     * See /core/libraries/messages/defaults/default/ for examples
28
-     * (note that template files match a specific naming schema).
29
-     * These templates will need to be registered with the default template pack.
30
-     * - EE_Messages_Validator extended class(es).  See /core/libraries/messages/validators/email/
31
-     *      for examples.  Note for any new message types, there will need to be a validator for each
32
-     *      messenger combo this message type can activate with.
33
-     * - And of course the main EE_{Message_Type_Name}_message_type class that defines the new
34
-     *      message type and its properties.
35
-     *
36
-     * @param string $identifier    Whatever is defined for the $name property of
37
-     *                              the message type you are registering (eg.
38
-     *                              declined_registration). Required.
39
-     * @param array  $setup_args    An array of arguments provided for registering the message type.
40
-     * @throws EE_Error
41
-     *                              }
42
-     * @see      inline docs in the register method for what can be passed in as arguments.
43
-     * @since    4.3.0
44
-     */
45
-    public static function register($identifier = '', array $setup_args = [])
46
-    {
47
-        // required fields MUST be present, so let's make sure they are.
48
-        if (! isset($identifier)
49
-            || ! is_array($setup_args)
50
-            || empty($setup_args['mtfilename'])
51
-            || empty($setup_args['autoloadpaths'])
52
-        ) {
53
-            throw new EE_Error(
54
-                __(
55
-                    'In order to register a message type with EE_Register_Message_Type::register, you must include a unique name for the message type, plus an array containing the following keys: "mtfilename", "autoloadpaths"',
56
-                    'event_espresso'
57
-                )
58
-            );
59
-        }
23
+	/**
24
+	 * Method for registering new message types in the EE_messages system.
25
+	 * Note:  All message types must have the following files in order to work:
26
+	 * Template files for default templates getting setup.
27
+	 * See /core/libraries/messages/defaults/default/ for examples
28
+	 * (note that template files match a specific naming schema).
29
+	 * These templates will need to be registered with the default template pack.
30
+	 * - EE_Messages_Validator extended class(es).  See /core/libraries/messages/validators/email/
31
+	 *      for examples.  Note for any new message types, there will need to be a validator for each
32
+	 *      messenger combo this message type can activate with.
33
+	 * - And of course the main EE_{Message_Type_Name}_message_type class that defines the new
34
+	 *      message type and its properties.
35
+	 *
36
+	 * @param string $identifier    Whatever is defined for the $name property of
37
+	 *                              the message type you are registering (eg.
38
+	 *                              declined_registration). Required.
39
+	 * @param array  $setup_args    An array of arguments provided for registering the message type.
40
+	 * @throws EE_Error
41
+	 *                              }
42
+	 * @see      inline docs in the register method for what can be passed in as arguments.
43
+	 * @since    4.3.0
44
+	 */
45
+	public static function register($identifier = '', array $setup_args = [])
46
+	{
47
+		// required fields MUST be present, so let's make sure they are.
48
+		if (! isset($identifier)
49
+			|| ! is_array($setup_args)
50
+			|| empty($setup_args['mtfilename'])
51
+			|| empty($setup_args['autoloadpaths'])
52
+		) {
53
+			throw new EE_Error(
54
+				__(
55
+					'In order to register a message type with EE_Register_Message_Type::register, you must include a unique name for the message type, plus an array containing the following keys: "mtfilename", "autoloadpaths"',
56
+					'event_espresso'
57
+				)
58
+			);
59
+		}
60 60
 
61
-        // make sure we don't register twice
62
-        if (isset(self::$_ee_message_type_registry[ $identifier ])) {
63
-            return;
64
-        }
61
+		// make sure we don't register twice
62
+		if (isset(self::$_ee_message_type_registry[ $identifier ])) {
63
+			return;
64
+		}
65 65
 
66
-        // make sure this was called in the right place!
67
-        if (! did_action('EE_Brewing_Regular___messages_caf')
68
-            || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
69
-        ) {
70
-            EE_Error::doing_it_wrong(
71
-                __METHOD__,
72
-                sprintf(
73
-                    __(
74
-                        'A message type named "%s" has been attempted to be registered with the EE Messages System.  It may or may not work because it should be only called on the "EE_Brewing_Regular___messages_caf" hook.',
75
-                        'event_espresso'
76
-                    ),
77
-                    $identifier
78
-                ),
79
-                '4.3.0'
80
-            );
81
-        }
82
-        // setup $__ee_message_type_registry array from incoming values.
83
-        self::$_ee_message_type_registry[ $identifier ] = [
84
-            /**
85
-             * The file name for the message type being registered.
86
-             * Required.
87
-             *
88
-             * @type string
89
-             */
90
-            'mtfilename'                                       => (string) $setup_args['mtfilename'],
91
-            /**
92
-             * Autoload paths for classes used by the message type.
93
-             * Required.
94
-             *
95
-             * @type array
96
-             */
97
-            'autoloadpaths'                                    => (array) $setup_args['autoloadpaths'],
98
-            /**
99
-             * Messengers that the message type should be able to activate with.
100
-             * Use messenger slugs.
101
-             *
102
-             * @type array
103
-             */
104
-            'messengers_to_activate_with'                      => ! empty($setup_args['messengers_to_activate_with'])
105
-                ? (array) $setup_args['messengers_to_activate_with']
106
-                : [],
107
-            /**
108
-             * Messengers that the message type should validate with.
109
-             * Use messenger slugs.
110
-             *
111
-             * @type array
112
-             */
113
-            'messengers_to_validate_with'                      => ! empty($setup_args['messengers_to_validate_with'])
114
-                ? (array) $setup_args['messengers_to_validate_with']
115
-                : [],
116
-            /**
117
-             * Whether to force activate this message type the first time it is registered.
118
-             *
119
-             * @type bool   False means its not activated by default and left up to the end user to activate.
120
-             */
121
-            'force_activation'                                 => ! empty($setup_args['force_activation'])
122
-                                                                  && $setup_args['force_activation'],
123
-            /**
124
-             * What messengers this message type supports the default template pack for.
125
-             * Note: If you do not set this (or any of the following template pack/variation related arguments) to true,
126
-             * then it is expected that the message type being registered is doing its own custom default template
127
-             * pack/variation registration.
128
-             *
129
-             * If this is set and has values, then it is expected that the following arguments are also set in the incoming options
130
-             * $setup_arguments array as well:
131
-             * - 'base_path_for_default_templates'
132
-             *
133
-             * @type array   Expect an array of messengers this supports default template packs for.
134
-             */
135
-            'messengers_supporting_default_template_pack_with' => isset($setup_args['messengers_supporting_default_template_pack_with'])
136
-                ? (array) $setup_args['messengers_supporting_default_template_pack_with']
137
-                : [],
138
-            /**
139
-             * The base path where the default templates for this message type can be found.
140
-             *
141
-             * @type string
142
-             */
143
-            'base_path_for_default_templates'                  => isset($setup_args['base_path_for_default_templates'])
144
-                ? $setup_args['base_path_for_default_templates'] : '',
145
-            /**
146
-             * The base path where the default variations for this message type can be found.
147
-             *
148
-             * @type string
149
-             */
150
-            'base_path_for_default_variation'                  => isset($setup_args['base_path_for_default_variation'])
151
-                ? $setup_args['base_path_for_default_variation'] : '',
152
-            /**
153
-             * The base url for the default variations for this message type.
154
-             *
155
-             * @type string
156
-             */
157
-            'base_url_for_default_variation'                   => isset($setup_args['base_url_for_default_variation'])
158
-                ? $setup_args['base_url_for_default_variation'] : '',
159
-        ];
160
-        // add filters but only if they haven't already been set (these filters only need to be registered ONCE because
161
-        // the callback handles all registered message types.
162
-        if (false === has_filter(
163
-            'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
164
-            ['EE_Register_Message_Type', 'register_msgs_autoload_paths']
165
-        )) {
166
-            add_filter(
167
-                'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
168
-                ['EE_Register_Message_Type', 'register_msgs_autoload_paths'],
169
-                10
170
-            );
171
-            add_filter(
172
-                'FHEE__EE_messages__get_installed__messagetype_files',
173
-                ['EE_Register_Message_Type', 'register_messagetype_files'],
174
-                10,
175
-                1
176
-            );
177
-            add_filter(
178
-                'FHEE__EE_messenger__get_default_message_types__default_types',
179
-                ['EE_Register_Message_Type', 'register_messengers_to_activate_mt_with'],
180
-                10,
181
-                2
182
-            );
183
-            add_filter(
184
-                'FHEE__EE_messenger__get_valid_message_types__valid_types',
185
-                ['EE_Register_Message_Type', 'register_messengers_to_validate_mt_with'],
186
-                10,
187
-                2
188
-            );
189
-            // actions
190
-            add_action(
191
-                'AHEE__EE_Addon__initialize_default_data__begin',
192
-                ['EE_Register_Message_Type', 'set_defaults']
193
-            );
66
+		// make sure this was called in the right place!
67
+		if (! did_action('EE_Brewing_Regular___messages_caf')
68
+			|| did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
69
+		) {
70
+			EE_Error::doing_it_wrong(
71
+				__METHOD__,
72
+				sprintf(
73
+					__(
74
+						'A message type named "%s" has been attempted to be registered with the EE Messages System.  It may or may not work because it should be only called on the "EE_Brewing_Regular___messages_caf" hook.',
75
+						'event_espresso'
76
+					),
77
+					$identifier
78
+				),
79
+				'4.3.0'
80
+			);
81
+		}
82
+		// setup $__ee_message_type_registry array from incoming values.
83
+		self::$_ee_message_type_registry[ $identifier ] = [
84
+			/**
85
+			 * The file name for the message type being registered.
86
+			 * Required.
87
+			 *
88
+			 * @type string
89
+			 */
90
+			'mtfilename'                                       => (string) $setup_args['mtfilename'],
91
+			/**
92
+			 * Autoload paths for classes used by the message type.
93
+			 * Required.
94
+			 *
95
+			 * @type array
96
+			 */
97
+			'autoloadpaths'                                    => (array) $setup_args['autoloadpaths'],
98
+			/**
99
+			 * Messengers that the message type should be able to activate with.
100
+			 * Use messenger slugs.
101
+			 *
102
+			 * @type array
103
+			 */
104
+			'messengers_to_activate_with'                      => ! empty($setup_args['messengers_to_activate_with'])
105
+				? (array) $setup_args['messengers_to_activate_with']
106
+				: [],
107
+			/**
108
+			 * Messengers that the message type should validate with.
109
+			 * Use messenger slugs.
110
+			 *
111
+			 * @type array
112
+			 */
113
+			'messengers_to_validate_with'                      => ! empty($setup_args['messengers_to_validate_with'])
114
+				? (array) $setup_args['messengers_to_validate_with']
115
+				: [],
116
+			/**
117
+			 * Whether to force activate this message type the first time it is registered.
118
+			 *
119
+			 * @type bool   False means its not activated by default and left up to the end user to activate.
120
+			 */
121
+			'force_activation'                                 => ! empty($setup_args['force_activation'])
122
+																  && $setup_args['force_activation'],
123
+			/**
124
+			 * What messengers this message type supports the default template pack for.
125
+			 * Note: If you do not set this (or any of the following template pack/variation related arguments) to true,
126
+			 * then it is expected that the message type being registered is doing its own custom default template
127
+			 * pack/variation registration.
128
+			 *
129
+			 * If this is set and has values, then it is expected that the following arguments are also set in the incoming options
130
+			 * $setup_arguments array as well:
131
+			 * - 'base_path_for_default_templates'
132
+			 *
133
+			 * @type array   Expect an array of messengers this supports default template packs for.
134
+			 */
135
+			'messengers_supporting_default_template_pack_with' => isset($setup_args['messengers_supporting_default_template_pack_with'])
136
+				? (array) $setup_args['messengers_supporting_default_template_pack_with']
137
+				: [],
138
+			/**
139
+			 * The base path where the default templates for this message type can be found.
140
+			 *
141
+			 * @type string
142
+			 */
143
+			'base_path_for_default_templates'                  => isset($setup_args['base_path_for_default_templates'])
144
+				? $setup_args['base_path_for_default_templates'] : '',
145
+			/**
146
+			 * The base path where the default variations for this message type can be found.
147
+			 *
148
+			 * @type string
149
+			 */
150
+			'base_path_for_default_variation'                  => isset($setup_args['base_path_for_default_variation'])
151
+				? $setup_args['base_path_for_default_variation'] : '',
152
+			/**
153
+			 * The base url for the default variations for this message type.
154
+			 *
155
+			 * @type string
156
+			 */
157
+			'base_url_for_default_variation'                   => isset($setup_args['base_url_for_default_variation'])
158
+				? $setup_args['base_url_for_default_variation'] : '',
159
+		];
160
+		// add filters but only if they haven't already been set (these filters only need to be registered ONCE because
161
+		// the callback handles all registered message types.
162
+		if (false === has_filter(
163
+			'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
164
+			['EE_Register_Message_Type', 'register_msgs_autoload_paths']
165
+		)) {
166
+			add_filter(
167
+				'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
168
+				['EE_Register_Message_Type', 'register_msgs_autoload_paths'],
169
+				10
170
+			);
171
+			add_filter(
172
+				'FHEE__EE_messages__get_installed__messagetype_files',
173
+				['EE_Register_Message_Type', 'register_messagetype_files'],
174
+				10,
175
+				1
176
+			);
177
+			add_filter(
178
+				'FHEE__EE_messenger__get_default_message_types__default_types',
179
+				['EE_Register_Message_Type', 'register_messengers_to_activate_mt_with'],
180
+				10,
181
+				2
182
+			);
183
+			add_filter(
184
+				'FHEE__EE_messenger__get_valid_message_types__valid_types',
185
+				['EE_Register_Message_Type', 'register_messengers_to_validate_mt_with'],
186
+				10,
187
+				2
188
+			);
189
+			// actions
190
+			add_action(
191
+				'AHEE__EE_Addon__initialize_default_data__begin',
192
+				['EE_Register_Message_Type', 'set_defaults']
193
+			);
194 194
 
195
-            // default template packs and variations related
196
-            add_filter(
197
-                'FHEE__EE_Messages_Template_Pack_Default__get_supports',
198
-                ['EE_Register_Message_Type', 'register_default_template_pack_supports']
199
-            );
200
-            add_filter(
201
-                'FHEE__EE_Template_Pack___get_specific_template__filtered_base_path',
202
-                ['EE_Register_Message_Type', 'register_base_template_path'],
203
-                10,
204
-                6
205
-            );
206
-            add_filter(
207
-                'FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url',
208
-                ['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
209
-                10,
210
-                8
211
-            );
212
-            add_filter(
213
-                'FHEE__EE_Messages_Template_Pack__get_variation__base_path',
214
-                ['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
215
-                10,
216
-                8
217
-            );
218
-        }
219
-    }
195
+			// default template packs and variations related
196
+			add_filter(
197
+				'FHEE__EE_Messages_Template_Pack_Default__get_supports',
198
+				['EE_Register_Message_Type', 'register_default_template_pack_supports']
199
+			);
200
+			add_filter(
201
+				'FHEE__EE_Template_Pack___get_specific_template__filtered_base_path',
202
+				['EE_Register_Message_Type', 'register_base_template_path'],
203
+				10,
204
+				6
205
+			);
206
+			add_filter(
207
+				'FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url',
208
+				['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
209
+				10,
210
+				8
211
+			);
212
+			add_filter(
213
+				'FHEE__EE_Messages_Template_Pack__get_variation__base_path',
214
+				['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
215
+				10,
216
+				8
217
+			);
218
+		}
219
+	}
220 220
 
221 221
 
222
-    /**
223
-     * This just ensures that when an addon registers a message type that on initial activation/reactivation the
224
-     * defaults the addon sets are taken care of.
225
-     *
226
-     * @throws EE_Error
227
-     * @throws ReflectionException
228
-     */
229
-    public static function set_defaults()
230
-    {
231
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
232
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
222
+	/**
223
+	 * This just ensures that when an addon registers a message type that on initial activation/reactivation the
224
+	 * defaults the addon sets are taken care of.
225
+	 *
226
+	 * @throws EE_Error
227
+	 * @throws ReflectionException
228
+	 */
229
+	public static function set_defaults()
230
+	{
231
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
232
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
233 233
 
234
-        // for any message types with force activation, let's ensure they are activated
235
-        foreach (self::$_ee_message_type_registry as $identifier => $settings) {
236
-            if ($settings['force_activation']) {
237
-                foreach ($settings['messengers_to_activate_with'] as $messenger) {
238
-                    // DO not force activation if this message type has already been activated in the system
239
-                    if (! $message_resource_manager->has_message_type_been_activated_for_messenger(
240
-                        $identifier,
241
-                        $messenger
242
-                    )
243
-                    ) {
244
-                        $message_resource_manager->ensure_message_type_is_active($identifier, $messenger);
245
-                    }
246
-                }
247
-            }
248
-        }
249
-    }
234
+		// for any message types with force activation, let's ensure they are activated
235
+		foreach (self::$_ee_message_type_registry as $identifier => $settings) {
236
+			if ($settings['force_activation']) {
237
+				foreach ($settings['messengers_to_activate_with'] as $messenger) {
238
+					// DO not force activation if this message type has already been activated in the system
239
+					if (! $message_resource_manager->has_message_type_been_activated_for_messenger(
240
+						$identifier,
241
+						$messenger
242
+					)
243
+					) {
244
+						$message_resource_manager->ensure_message_type_is_active($identifier, $messenger);
245
+					}
246
+				}
247
+			}
248
+		}
249
+	}
250 250
 
251 251
 
252
-    /**
253
-     * This deregisters a message type that was previously registered with a specific message_type_name.
254
-     *
255
-     * @param string $identifier the name for the message type that was previously registered
256
-     * @return void
257
-     * @throws EE_Error
258
-     * @throws ReflectionException
259
-     * @since    4.3.0
260
-     */
261
-    public static function deregister($identifier = '')
262
-    {
263
-        if (! empty(self::$_ee_message_type_registry[ $identifier ])) {
264
-            // let's make sure that we remove any place this message type was made active
265
-            /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
266
-            $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
267
-            // ensures that if this message type is registered again that it retains its previous active state vs
268
-            // remaining inactive.
269
-            $Message_Resource_Manager->remove_message_type_has_been_activated_from_all_messengers(
270
-                $identifier,
271
-                true
272
-            );
273
-            $Message_Resource_Manager->deactivate_message_type($identifier, false);
274
-        }
275
-        unset(self::$_ee_message_type_registry[ $identifier ]);
276
-    }
252
+	/**
253
+	 * This deregisters a message type that was previously registered with a specific message_type_name.
254
+	 *
255
+	 * @param string $identifier the name for the message type that was previously registered
256
+	 * @return void
257
+	 * @throws EE_Error
258
+	 * @throws ReflectionException
259
+	 * @since    4.3.0
260
+	 */
261
+	public static function deregister($identifier = '')
262
+	{
263
+		if (! empty(self::$_ee_message_type_registry[ $identifier ])) {
264
+			// let's make sure that we remove any place this message type was made active
265
+			/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
266
+			$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
267
+			// ensures that if this message type is registered again that it retains its previous active state vs
268
+			// remaining inactive.
269
+			$Message_Resource_Manager->remove_message_type_has_been_activated_from_all_messengers(
270
+				$identifier,
271
+				true
272
+			);
273
+			$Message_Resource_Manager->deactivate_message_type($identifier, false);
274
+		}
275
+		unset(self::$_ee_message_type_registry[ $identifier ]);
276
+	}
277 277
 
278 278
 
279
-    /**
280
-     * callback for FHEE__EE_messages__get_installed__messagetype_files filter.
281
-     *
282
-     * @param array $messagetype_files The current array of message type file names
283
-     * @return  array                                 Array of message type file names
284
-     * @since   4.3.0
285
-     */
286
-    public static function register_messagetype_files(array $messagetype_files)
287
-    {
288
-        if (empty(self::$_ee_message_type_registry)) {
289
-            return $messagetype_files;
290
-        }
291
-        foreach (self::$_ee_message_type_registry as $mt_reg) {
292
-            if (empty($mt_reg['mtfilename'])) {
293
-                continue;
294
-            }
295
-            $messagetype_files[] = $mt_reg['mtfilename'];
296
-        }
297
-        return $messagetype_files;
298
-    }
279
+	/**
280
+	 * callback for FHEE__EE_messages__get_installed__messagetype_files filter.
281
+	 *
282
+	 * @param array $messagetype_files The current array of message type file names
283
+	 * @return  array                                 Array of message type file names
284
+	 * @since   4.3.0
285
+	 */
286
+	public static function register_messagetype_files(array $messagetype_files)
287
+	{
288
+		if (empty(self::$_ee_message_type_registry)) {
289
+			return $messagetype_files;
290
+		}
291
+		foreach (self::$_ee_message_type_registry as $mt_reg) {
292
+			if (empty($mt_reg['mtfilename'])) {
293
+				continue;
294
+			}
295
+			$messagetype_files[] = $mt_reg['mtfilename'];
296
+		}
297
+		return $messagetype_files;
298
+	}
299 299
 
300 300
 
301
-    /**
302
-     * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.
303
-     *
304
-     * @param array $paths array of paths to be checked by EE_messages autoloader.
305
-     * @return array
306
-     * @since    4.3.0
307
-     */
308
-    public static function register_msgs_autoload_paths(array $paths)
309
-    {
310
-        if (! empty(self::$_ee_message_type_registry)) {
311
-            foreach (self::$_ee_message_type_registry as $mt_reg) {
312
-                if (empty($mt_reg['autoloadpaths'])) {
313
-                    continue;
314
-                }
315
-                $paths = array_merge($paths, $mt_reg['autoloadpaths']);
316
-            }
317
-        }
318
-        return $paths;
319
-    }
301
+	/**
302
+	 * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.
303
+	 *
304
+	 * @param array $paths array of paths to be checked by EE_messages autoloader.
305
+	 * @return array
306
+	 * @since    4.3.0
307
+	 */
308
+	public static function register_msgs_autoload_paths(array $paths)
309
+	{
310
+		if (! empty(self::$_ee_message_type_registry)) {
311
+			foreach (self::$_ee_message_type_registry as $mt_reg) {
312
+				if (empty($mt_reg['autoloadpaths'])) {
313
+					continue;
314
+				}
315
+				$paths = array_merge($paths, $mt_reg['autoloadpaths']);
316
+			}
317
+		}
318
+		return $paths;
319
+	}
320 320
 
321 321
 
322
-    /**
323
-     * callback for FHEE__EE_messenger__get_default_message_types__default_types filter.
324
-     *
325
-     * @param array        $default_types   array of message types activated with messenger (
326
-     *                                      corresponds to the $name property of message type)
327
-     * @param EE_messenger $messenger       The EE_messenger the filter is called from.
328
-     * @return array
329
-     * @since  4.3.0
330
-     */
331
-    public static function register_messengers_to_activate_mt_with(array $default_types, EE_messenger $messenger)
332
-    {
333
-        if (empty(self::$_ee_message_type_registry)) {
334
-            return $default_types;
335
-        }
336
-        foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
337
-            if (empty($mt_reg['messengers_to_activate_with']) || empty($mt_reg['mtfilename'])) {
338
-                continue;
339
-            }
340
-            // loop through each of the messengers and if it matches the loaded class
341
-            // then we add this message type to the
342
-            foreach ($mt_reg['messengers_to_activate_with'] as $msgr) {
343
-                if ($messenger->name == $msgr) {
344
-                    $default_types[] = $identifier;
345
-                }
346
-            }
347
-        }
322
+	/**
323
+	 * callback for FHEE__EE_messenger__get_default_message_types__default_types filter.
324
+	 *
325
+	 * @param array        $default_types   array of message types activated with messenger (
326
+	 *                                      corresponds to the $name property of message type)
327
+	 * @param EE_messenger $messenger       The EE_messenger the filter is called from.
328
+	 * @return array
329
+	 * @since  4.3.0
330
+	 */
331
+	public static function register_messengers_to_activate_mt_with(array $default_types, EE_messenger $messenger)
332
+	{
333
+		if (empty(self::$_ee_message_type_registry)) {
334
+			return $default_types;
335
+		}
336
+		foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
337
+			if (empty($mt_reg['messengers_to_activate_with']) || empty($mt_reg['mtfilename'])) {
338
+				continue;
339
+			}
340
+			// loop through each of the messengers and if it matches the loaded class
341
+			// then we add this message type to the
342
+			foreach ($mt_reg['messengers_to_activate_with'] as $msgr) {
343
+				if ($messenger->name == $msgr) {
344
+					$default_types[] = $identifier;
345
+				}
346
+			}
347
+		}
348 348
 
349
-        return $default_types;
350
-    }
349
+		return $default_types;
350
+	}
351 351
 
352 352
 
353
-    /**
354
-     * callback for FHEE__EE_messenger__get_valid_message_types__default_types filter.
355
-     *
356
-     * @param array        $valid_types     array of message types valid with messenger (
357
-     *                                      corresponds to the $name property of message type)
358
-     * @param EE_messenger $messenger       The EE_messenger the filter is called from.
359
-     * @return  array
360
-     * @since   4.3.0
361
-     */
362
-    public static function register_messengers_to_validate_mt_with(array $valid_types, EE_messenger $messenger)
363
-    {
364
-        if (empty(self::$_ee_message_type_registry)) {
365
-            return $valid_types;
366
-        }
367
-        foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
368
-            if (empty($mt_reg['messengers_to_validate_with']) || empty($mt_reg['mtfilename'])) {
369
-                continue;
370
-            }
371
-            // loop through each of the messengers and if it matches the loaded class
372
-            // then we add this message type to the
373
-            foreach ($mt_reg['messengers_to_validate_with'] as $msgr) {
374
-                if ($messenger->name == $msgr) {
375
-                    $valid_types[] = $identifier;
376
-                }
377
-            }
378
-        }
353
+	/**
354
+	 * callback for FHEE__EE_messenger__get_valid_message_types__default_types filter.
355
+	 *
356
+	 * @param array        $valid_types     array of message types valid with messenger (
357
+	 *                                      corresponds to the $name property of message type)
358
+	 * @param EE_messenger $messenger       The EE_messenger the filter is called from.
359
+	 * @return  array
360
+	 * @since   4.3.0
361
+	 */
362
+	public static function register_messengers_to_validate_mt_with(array $valid_types, EE_messenger $messenger)
363
+	{
364
+		if (empty(self::$_ee_message_type_registry)) {
365
+			return $valid_types;
366
+		}
367
+		foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
368
+			if (empty($mt_reg['messengers_to_validate_with']) || empty($mt_reg['mtfilename'])) {
369
+				continue;
370
+			}
371
+			// loop through each of the messengers and if it matches the loaded class
372
+			// then we add this message type to the
373
+			foreach ($mt_reg['messengers_to_validate_with'] as $msgr) {
374
+				if ($messenger->name == $msgr) {
375
+					$valid_types[] = $identifier;
376
+				}
377
+			}
378
+		}
379 379
 
380
-        return $valid_types;
381
-    }
380
+		return $valid_types;
381
+	}
382 382
 
383 383
 
384
-    /**
385
-     * Callback for `FHEE__EE_Messages_Template_Pack_Default__get_supports` filter to register this message type as
386
-     * supporting the default template pack
387
-     *
388
-     * @param array $supports
389
-     *
390
-     * @return array
391
-     */
392
-    public static function register_default_template_pack_supports(array $supports)
393
-    {
394
-        foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
395
-            if (empty($mt_reg['messengers_supporting_default_template_pack_with'])) {
396
-                continue;
397
-            }
398
-            foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) {
399
-                $supports[ $messenger_slug ][] = $identifier;
400
-            }
401
-        }
402
-        return $supports;
403
-    }
384
+	/**
385
+	 * Callback for `FHEE__EE_Messages_Template_Pack_Default__get_supports` filter to register this message type as
386
+	 * supporting the default template pack
387
+	 *
388
+	 * @param array $supports
389
+	 *
390
+	 * @return array
391
+	 */
392
+	public static function register_default_template_pack_supports(array $supports)
393
+	{
394
+		foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
395
+			if (empty($mt_reg['messengers_supporting_default_template_pack_with'])) {
396
+				continue;
397
+			}
398
+			foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) {
399
+				$supports[ $messenger_slug ][] = $identifier;
400
+			}
401
+		}
402
+		return $supports;
403
+	}
404 404
 
405 405
 
406
-    /**
407
-     * Callback for FHEE__EE_Template_Pack___get_specific_template__filtered_base_path
408
-     *
409
-     * @param string                    $base_path The original base path for message templates
410
-     * @param EE_messenger              $messenger
411
-     * @param EE_message_type           $message_type
412
-     * @param string                    $field     The field requesting a template
413
-     * @param string                    $context   The context requesting a template
414
-     * @param EE_Messages_Template_Pack $template_pack
415
-     *
416
-     * @return string
417
-     */
418
-    public static function register_base_template_path(
419
-        $base_path,
420
-        EE_messenger $messenger,
421
-        EE_message_type $message_type,
422
-        $field,
423
-        $context,
424
-        EE_Messages_Template_Pack $template_pack
425
-    ) {
426
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default
427
-            || ! $message_type instanceof EE_message_type
428
-        ) {
429
-            return $base_path;
430
-        }
431
-        foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
432
-            if ($message_type->name === $identifier
433
-                && ! empty($mt_reg['base_path_for_default_templates'])
434
-            ) {
435
-                return $mt_reg['base_path_for_default_templates'];
436
-            }
437
-        }
438
-        return $base_path;
439
-    }
406
+	/**
407
+	 * Callback for FHEE__EE_Template_Pack___get_specific_template__filtered_base_path
408
+	 *
409
+	 * @param string                    $base_path The original base path for message templates
410
+	 * @param EE_messenger              $messenger
411
+	 * @param EE_message_type           $message_type
412
+	 * @param string                    $field     The field requesting a template
413
+	 * @param string                    $context   The context requesting a template
414
+	 * @param EE_Messages_Template_Pack $template_pack
415
+	 *
416
+	 * @return string
417
+	 */
418
+	public static function register_base_template_path(
419
+		$base_path,
420
+		EE_messenger $messenger,
421
+		EE_message_type $message_type,
422
+		$field,
423
+		$context,
424
+		EE_Messages_Template_Pack $template_pack
425
+	) {
426
+		if (! $template_pack instanceof EE_Messages_Template_Pack_Default
427
+			|| ! $message_type instanceof EE_message_type
428
+		) {
429
+			return $base_path;
430
+		}
431
+		foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
432
+			if ($message_type->name === $identifier
433
+				&& ! empty($mt_reg['base_path_for_default_templates'])
434
+			) {
435
+				return $mt_reg['base_path_for_default_templates'];
436
+			}
437
+		}
438
+		return $base_path;
439
+	}
440 440
 
441 441
 
442
-    /**
443
-     * Callback for FHEE__EE_Messages_Template_Pack__get_variation__base_path and
444
-     * FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url hooks
445
-     *
446
-     * @param string                    $base_path_or_url  The original incoming base url or path
447
-     * @param string                    $messenger_slug    The slug of the messenger the template is being generated
448
-     *                                                     for.
449
-     * @param string                    $message_type_slug The slug of the message type the template is being generated
450
-     *                                                     for.
451
-     * @param string                    $type              The "type" of css being requested.
452
-     * @param string                    $variation         The variation being requested.
453
-     * @param bool                      $url               whether a url or path is being requested.
454
-     * @param string                    $file_extension    What file extension is expected for the variation file.
455
-     * @param EE_Messages_Template_Pack $template_pack
456
-     *
457
-     * @return string
458
-     */
459
-    public static function register_variation_base_path_or_url(
460
-        $base_path_or_url,
461
-        $messenger_slug,
462
-        $message_type_slug,
463
-        $type,
464
-        $variation,
465
-        $url,
466
-        $file_extension,
467
-        EE_Messages_Template_Pack $template_pack
468
-    ) {
469
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
470
-            return $base_path_or_url;
471
-        }
472
-        foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
473
-            if ($identifier === $message_type_slug
474
-            ) {
475
-                if ($url
476
-                    && ! empty($mt_reg['base_url_for_default_variation'])
477
-                ) {
478
-                    return $mt_reg['base_url_for_default_variation'];
479
-                } elseif (! $url
480
-                          && ! empty($mt_reg['base_path_for_default_variation'])
481
-                ) {
482
-                    return $mt_reg['base_path_for_default_variation'];
483
-                }
484
-            }
485
-        }
486
-        return $base_path_or_url;
487
-    }
442
+	/**
443
+	 * Callback for FHEE__EE_Messages_Template_Pack__get_variation__base_path and
444
+	 * FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url hooks
445
+	 *
446
+	 * @param string                    $base_path_or_url  The original incoming base url or path
447
+	 * @param string                    $messenger_slug    The slug of the messenger the template is being generated
448
+	 *                                                     for.
449
+	 * @param string                    $message_type_slug The slug of the message type the template is being generated
450
+	 *                                                     for.
451
+	 * @param string                    $type              The "type" of css being requested.
452
+	 * @param string                    $variation         The variation being requested.
453
+	 * @param bool                      $url               whether a url or path is being requested.
454
+	 * @param string                    $file_extension    What file extension is expected for the variation file.
455
+	 * @param EE_Messages_Template_Pack $template_pack
456
+	 *
457
+	 * @return string
458
+	 */
459
+	public static function register_variation_base_path_or_url(
460
+		$base_path_or_url,
461
+		$messenger_slug,
462
+		$message_type_slug,
463
+		$type,
464
+		$variation,
465
+		$url,
466
+		$file_extension,
467
+		EE_Messages_Template_Pack $template_pack
468
+	) {
469
+		if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
470
+			return $base_path_or_url;
471
+		}
472
+		foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
473
+			if ($identifier === $message_type_slug
474
+			) {
475
+				if ($url
476
+					&& ! empty($mt_reg['base_url_for_default_variation'])
477
+				) {
478
+					return $mt_reg['base_url_for_default_variation'];
479
+				} elseif (! $url
480
+						  && ! empty($mt_reg['base_path_for_default_variation'])
481
+				) {
482
+					return $mt_reg['base_path_for_default_variation'];
483
+				}
484
+			}
485
+		}
486
+		return $base_path_or_url;
487
+	}
488 488
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     public static function register($identifier = '', array $setup_args = [])
46 46
     {
47 47
         // required fields MUST be present, so let's make sure they are.
48
-        if (! isset($identifier)
48
+        if ( ! isset($identifier)
49 49
             || ! is_array($setup_args)
50 50
             || empty($setup_args['mtfilename'])
51 51
             || empty($setup_args['autoloadpaths'])
@@ -59,12 +59,12 @@  discard block
 block discarded – undo
59 59
         }
60 60
 
61 61
         // make sure we don't register twice
62
-        if (isset(self::$_ee_message_type_registry[ $identifier ])) {
62
+        if (isset(self::$_ee_message_type_registry[$identifier])) {
63 63
             return;
64 64
         }
65 65
 
66 66
         // make sure this was called in the right place!
67
-        if (! did_action('EE_Brewing_Regular___messages_caf')
67
+        if ( ! did_action('EE_Brewing_Regular___messages_caf')
68 68
             || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
69 69
         ) {
70 70
             EE_Error::doing_it_wrong(
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
             );
81 81
         }
82 82
         // setup $__ee_message_type_registry array from incoming values.
83
-        self::$_ee_message_type_registry[ $identifier ] = [
83
+        self::$_ee_message_type_registry[$identifier] = [
84 84
             /**
85 85
              * The file name for the message type being registered.
86 86
              * Required.
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
             if ($settings['force_activation']) {
237 237
                 foreach ($settings['messengers_to_activate_with'] as $messenger) {
238 238
                     // DO not force activation if this message type has already been activated in the system
239
-                    if (! $message_resource_manager->has_message_type_been_activated_for_messenger(
239
+                    if ( ! $message_resource_manager->has_message_type_been_activated_for_messenger(
240 240
                         $identifier,
241 241
                         $messenger
242 242
                     )
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
      */
261 261
     public static function deregister($identifier = '')
262 262
     {
263
-        if (! empty(self::$_ee_message_type_registry[ $identifier ])) {
263
+        if ( ! empty(self::$_ee_message_type_registry[$identifier])) {
264 264
             // let's make sure that we remove any place this message type was made active
265 265
             /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
266 266
             $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
             );
273 273
             $Message_Resource_Manager->deactivate_message_type($identifier, false);
274 274
         }
275
-        unset(self::$_ee_message_type_registry[ $identifier ]);
275
+        unset(self::$_ee_message_type_registry[$identifier]);
276 276
     }
277 277
 
278 278
 
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
      */
308 308
     public static function register_msgs_autoload_paths(array $paths)
309 309
     {
310
-        if (! empty(self::$_ee_message_type_registry)) {
310
+        if ( ! empty(self::$_ee_message_type_registry)) {
311 311
             foreach (self::$_ee_message_type_registry as $mt_reg) {
312 312
                 if (empty($mt_reg['autoloadpaths'])) {
313 313
                     continue;
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
                 continue;
397 397
             }
398 398
             foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) {
399
-                $supports[ $messenger_slug ][] = $identifier;
399
+                $supports[$messenger_slug][] = $identifier;
400 400
             }
401 401
         }
402 402
         return $supports;
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
         $context,
424 424
         EE_Messages_Template_Pack $template_pack
425 425
     ) {
426
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default
426
+        if ( ! $template_pack instanceof EE_Messages_Template_Pack_Default
427 427
             || ! $message_type instanceof EE_message_type
428 428
         ) {
429 429
             return $base_path;
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
         $file_extension,
467 467
         EE_Messages_Template_Pack $template_pack
468 468
     ) {
469
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
469
+        if ( ! $template_pack instanceof EE_Messages_Template_Pack_Default) {
470 470
             return $base_path_or_url;
471 471
         }
472 472
         foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
                     && ! empty($mt_reg['base_url_for_default_variation'])
477 477
                 ) {
478 478
                     return $mt_reg['base_url_for_default_variation'];
479
-                } elseif (! $url
479
+                } elseif ( ! $url
480 480
                           && ! empty($mt_reg['base_path_for_default_variation'])
481 481
                 ) {
482 482
                     return $mt_reg['base_path_for_default_variation'];
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 2 patches
Indentation   +2664 added lines, -2664 removed lines patch added patch discarded remove patch
@@ -19,2668 +19,2668 @@
 block discarded – undo
19 19
 class Events_Admin_Page extends EE_Admin_Page_CPT
20 20
 {
21 21
 
22
-    /**
23
-     * This will hold the event object for event_details screen.
24
-     *
25
-     * @access protected
26
-     * @var EE_Event $_event
27
-     */
28
-    protected $_event;
29
-
30
-
31
-    /**
32
-     * This will hold the category object for category_details screen.
33
-     *
34
-     * @var stdClass $_category
35
-     */
36
-    protected $_category;
37
-
38
-
39
-    /**
40
-     * This will hold the event model instance
41
-     *
42
-     * @var EEM_Event $_event_model
43
-     */
44
-    protected $_event_model;
45
-
46
-
47
-    /**
48
-     * @var EE_Event
49
-     */
50
-    protected $_cpt_model_obj = false;
51
-
52
-
53
-    /**
54
-     * @var NodeGroupDao
55
-     */
56
-    protected $model_obj_node_group_persister;
57
-
58
-    /**
59
-     * Initialize page props for this admin page group.
60
-     */
61
-    protected function _init_page_props()
62
-    {
63
-        $this->page_slug = EVENTS_PG_SLUG;
64
-        $this->page_label = EVENTS_LABEL;
65
-        $this->_admin_base_url = EVENTS_ADMIN_URL;
66
-        $this->_admin_base_path = EVENTS_ADMIN;
67
-        $this->_cpt_model_names = array(
68
-            'create_new' => 'EEM_Event',
69
-            'edit'       => 'EEM_Event',
70
-        );
71
-        $this->_cpt_edit_routes = array(
72
-            'espresso_events' => 'edit',
73
-        );
74
-        add_action(
75
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
76
-            array($this, 'verify_event_edit'),
77
-            10,
78
-            2
79
-        );
80
-    }
81
-
82
-
83
-    /**
84
-     * Sets the ajax hooks used for this admin page group.
85
-     */
86
-    protected function _ajax_hooks()
87
-    {
88
-        add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting'));
89
-    }
90
-
91
-
92
-    /**
93
-     * Sets the page properties for this admin page group.
94
-     */
95
-    protected function _define_page_props()
96
-    {
97
-        $this->_admin_page_title = EVENTS_LABEL;
98
-        $this->_labels = array(
99
-            'buttons'      => array(
100
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
101
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
102
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
103
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
104
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
105
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
106
-            ),
107
-            'editor_title' => array(
108
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
109
-            ),
110
-            'publishbox'   => array(
111
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
112
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
113
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
114
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
115
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
116
-            ),
117
-        );
118
-    }
119
-
120
-
121
-    /**
122
-     * Sets the page routes property for this admin page group.
123
-     */
124
-    protected function _set_page_routes()
125
-    {
126
-        // load formatter helper
127
-        // load field generator helper
128
-        // is there a evt_id in the request?
129
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
130
-            ? $this->_req_data['EVT_ID']
131
-            : 0;
132
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
133
-        $this->_page_routes = array(
134
-            'default'                       => array(
135
-                'func'       => '_events_overview_list_table',
136
-                'capability' => 'ee_read_events',
137
-            ),
138
-            'create_new'                    => array(
139
-                'func'       => '_create_new_cpt_item',
140
-                'capability' => 'ee_edit_events',
141
-            ),
142
-            'edit'                          => array(
143
-                'func'       => '_edit_cpt_item',
144
-                'capability' => 'ee_edit_event',
145
-                'obj_id'     => $evt_id,
146
-            ),
147
-            'copy_event'                    => array(
148
-                'func'       => '_copy_events',
149
-                'capability' => 'ee_edit_event',
150
-                'obj_id'     => $evt_id,
151
-                'noheader'   => true,
152
-            ),
153
-            'trash_event'                   => array(
154
-                'func'       => '_trash_or_restore_event',
155
-                'args'       => array('event_status' => 'trash'),
156
-                'capability' => 'ee_delete_event',
157
-                'obj_id'     => $evt_id,
158
-                'noheader'   => true,
159
-            ),
160
-            'trash_events'                  => array(
161
-                'func'       => '_trash_or_restore_events',
162
-                'args'       => array('event_status' => 'trash'),
163
-                'capability' => 'ee_delete_events',
164
-                'noheader'   => true,
165
-            ),
166
-            'restore_event'                 => array(
167
-                'func'       => '_trash_or_restore_event',
168
-                'args'       => array('event_status' => 'draft'),
169
-                'capability' => 'ee_delete_event',
170
-                'obj_id'     => $evt_id,
171
-                'noheader'   => true,
172
-            ),
173
-            'restore_events'                => array(
174
-                'func'       => '_trash_or_restore_events',
175
-                'args'       => array('event_status' => 'draft'),
176
-                'capability' => 'ee_delete_events',
177
-                'noheader'   => true,
178
-            ),
179
-            'delete_event'                  => array(
180
-                'func'       => '_delete_event',
181
-                'capability' => 'ee_delete_event',
182
-                'obj_id'     => $evt_id,
183
-                'noheader'   => true,
184
-            ),
185
-            'delete_events'                 => array(
186
-                'func'       => '_delete_events',
187
-                'capability' => 'ee_delete_events',
188
-                'noheader'   => true,
189
-            ),
190
-            'view_report'                   => array(
191
-                'func'      => '_view_report',
192
-                'capablity' => 'ee_edit_events',
193
-            ),
194
-            'default_event_settings'        => array(
195
-                'func'       => '_default_event_settings',
196
-                'capability' => 'manage_options',
197
-            ),
198
-            'update_default_event_settings' => array(
199
-                'func'       => '_update_default_event_settings',
200
-                'capability' => 'manage_options',
201
-                'noheader'   => true,
202
-            ),
203
-            'template_settings'             => array(
204
-                'func'       => '_template_settings',
205
-                'capability' => 'manage_options',
206
-            ),
207
-            // event category tab related
208
-            'add_category'                  => array(
209
-                'func'       => '_category_details',
210
-                'capability' => 'ee_edit_event_category',
211
-                'args'       => array('add'),
212
-            ),
213
-            'edit_category'                 => array(
214
-                'func'       => '_category_details',
215
-                'capability' => 'ee_edit_event_category',
216
-                'args'       => array('edit'),
217
-            ),
218
-            'delete_categories'             => array(
219
-                'func'       => '_delete_categories',
220
-                'capability' => 'ee_delete_event_category',
221
-                'noheader'   => true,
222
-            ),
223
-            'delete_category'               => array(
224
-                'func'       => '_delete_categories',
225
-                'capability' => 'ee_delete_event_category',
226
-                'noheader'   => true,
227
-            ),
228
-            'insert_category'               => array(
229
-                'func'       => '_insert_or_update_category',
230
-                'args'       => array('new_category' => true),
231
-                'capability' => 'ee_edit_event_category',
232
-                'noheader'   => true,
233
-            ),
234
-            'update_category'               => array(
235
-                'func'       => '_insert_or_update_category',
236
-                'args'       => array('new_category' => false),
237
-                'capability' => 'ee_edit_event_category',
238
-                'noheader'   => true,
239
-            ),
240
-            'category_list'                 => array(
241
-                'func'       => '_category_list_table',
242
-                'capability' => 'ee_manage_event_categories',
243
-            ),
244
-            'preview_deletion' => [
245
-                'func' => 'previewDeletion',
246
-                'capability' => 'ee_delete_events',
247
-            ],
248
-            'confirm_deletion' => [
249
-                'func' => 'confirmDeletion',
250
-                'capability' => 'ee_delete_events',
251
-                'noheader' => true,
252
-            ]
253
-        );
254
-    }
255
-
256
-
257
-    /**
258
-     * Set the _page_config property for this admin page group.
259
-     */
260
-    protected function _set_page_config()
261
-    {
262
-        $this->_page_config = array(
263
-            'default'                => array(
264
-                'nav'           => array(
265
-                    'label' => esc_html__('Overview', 'event_espresso'),
266
-                    'order' => 10,
267
-                ),
268
-                'list_table'    => 'Events_Admin_List_Table',
269
-                'help_tabs'     => array(
270
-                    'events_overview_help_tab'                       => array(
271
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
272
-                        'filename' => 'events_overview',
273
-                    ),
274
-                    'events_overview_table_column_headings_help_tab' => array(
275
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
276
-                        'filename' => 'events_overview_table_column_headings',
277
-                    ),
278
-                    'events_overview_filters_help_tab'               => array(
279
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
280
-                        'filename' => 'events_overview_filters',
281
-                    ),
282
-                    'events_overview_view_help_tab'                  => array(
283
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
284
-                        'filename' => 'events_overview_views',
285
-                    ),
286
-                    'events_overview_other_help_tab'                 => array(
287
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
288
-                        'filename' => 'events_overview_other',
289
-                    ),
290
-                ),
291
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
292
-                // 'help_tour'     => array(
293
-                //     'Event_Overview_Help_Tour',
294
-                //     // 'New_Features_Test_Help_Tour' for testing multiple help tour
295
-                // ),
296
-                'qtips'         => array(
297
-                    'EE_Event_List_Table_Tips',
298
-                ),
299
-                'require_nonce' => false,
300
-            ),
301
-            'create_new'             => array(
302
-                'nav'           => array(
303
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
304
-                    'order'      => 5,
305
-                    'persistent' => false,
306
-                ),
307
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
308
-                'help_tabs'     => array(
309
-                    'event_editor_help_tab'                            => array(
310
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
311
-                        'filename' => 'event_editor',
312
-                    ),
313
-                    'event_editor_title_richtexteditor_help_tab'       => array(
314
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
315
-                        'filename' => 'event_editor_title_richtexteditor',
316
-                    ),
317
-                    'event_editor_venue_details_help_tab'              => array(
318
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
319
-                        'filename' => 'event_editor_venue_details',
320
-                    ),
321
-                    'event_editor_event_datetimes_help_tab'            => array(
322
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
323
-                        'filename' => 'event_editor_event_datetimes',
324
-                    ),
325
-                    'event_editor_event_tickets_help_tab'              => array(
326
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
327
-                        'filename' => 'event_editor_event_tickets',
328
-                    ),
329
-                    'event_editor_event_registration_options_help_tab' => array(
330
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
331
-                        'filename' => 'event_editor_event_registration_options',
332
-                    ),
333
-                    'event_editor_tags_categories_help_tab'            => array(
334
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
335
-                        'filename' => 'event_editor_tags_categories',
336
-                    ),
337
-                    'event_editor_questions_registrants_help_tab'      => array(
338
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
339
-                        'filename' => 'event_editor_questions_registrants',
340
-                    ),
341
-                    'event_editor_save_new_event_help_tab'             => array(
342
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
343
-                        'filename' => 'event_editor_save_new_event',
344
-                    ),
345
-                    'event_editor_other_help_tab'                      => array(
346
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
347
-                        'filename' => 'event_editor_other',
348
-                    ),
349
-                ),
350
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
351
-                // 'help_tour'     => array(
352
-                //     'Event_Editor_Help_Tour',
353
-                // ),
354
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
355
-                'require_nonce' => false,
356
-            ),
357
-            'edit'                   => array(
358
-                'nav'           => array(
359
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
360
-                    'order'      => 5,
361
-                    'persistent' => false,
362
-                    'url'        => isset($this->_req_data['post'])
363
-                        ? EE_Admin_Page::add_query_args_and_nonce(
364
-                            array('post' => $this->_req_data['post'], 'action' => 'edit'),
365
-                            $this->_current_page_view_url
366
-                        )
367
-                        : $this->_admin_base_url,
368
-                ),
369
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
370
-                'help_tabs'     => array(
371
-                    'event_editor_help_tab'                            => array(
372
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
373
-                        'filename' => 'event_editor',
374
-                    ),
375
-                    'event_editor_title_richtexteditor_help_tab'       => array(
376
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
377
-                        'filename' => 'event_editor_title_richtexteditor',
378
-                    ),
379
-                    'event_editor_venue_details_help_tab'              => array(
380
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
381
-                        'filename' => 'event_editor_venue_details',
382
-                    ),
383
-                    'event_editor_event_datetimes_help_tab'            => array(
384
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
385
-                        'filename' => 'event_editor_event_datetimes',
386
-                    ),
387
-                    'event_editor_event_tickets_help_tab'              => array(
388
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
389
-                        'filename' => 'event_editor_event_tickets',
390
-                    ),
391
-                    'event_editor_event_registration_options_help_tab' => array(
392
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
393
-                        'filename' => 'event_editor_event_registration_options',
394
-                    ),
395
-                    'event_editor_tags_categories_help_tab'            => array(
396
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
397
-                        'filename' => 'event_editor_tags_categories',
398
-                    ),
399
-                    'event_editor_questions_registrants_help_tab'      => array(
400
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
401
-                        'filename' => 'event_editor_questions_registrants',
402
-                    ),
403
-                    'event_editor_save_new_event_help_tab'             => array(
404
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
405
-                        'filename' => 'event_editor_save_new_event',
406
-                    ),
407
-                    'event_editor_other_help_tab'                      => array(
408
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
409
-                        'filename' => 'event_editor_other',
410
-                    ),
411
-                ),
412
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
413
-                'require_nonce' => false,
414
-            ),
415
-            'default_event_settings' => array(
416
-                'nav'           => array(
417
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
418
-                    'order' => 40,
419
-                ),
420
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
421
-                'labels'        => array(
422
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
423
-                ),
424
-                'help_tabs'     => array(
425
-                    'default_settings_help_tab'        => array(
426
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
427
-                        'filename' => 'events_default_settings',
428
-                    ),
429
-                    'default_settings_status_help_tab' => array(
430
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
431
-                        'filename' => 'events_default_settings_status',
432
-                    ),
433
-                    'default_maximum_tickets_help_tab' => array(
434
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
435
-                        'filename' => 'events_default_settings_max_tickets',
436
-                    ),
437
-                ),
438
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
439
-                // 'help_tour'     => array('Event_Default_Settings_Help_Tour'),
440
-                'require_nonce' => false,
441
-            ),
442
-            // template settings
443
-            'template_settings'      => array(
444
-                'nav'           => array(
445
-                    'label' => esc_html__('Templates', 'event_espresso'),
446
-                    'order' => 30,
447
-                ),
448
-                'metaboxes'     => $this->_default_espresso_metaboxes,
449
-                'help_tabs'     => array(
450
-                    'general_settings_templates_help_tab' => array(
451
-                        'title'    => esc_html__('Templates', 'event_espresso'),
452
-                        'filename' => 'general_settings_templates',
453
-                    ),
454
-                ),
455
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
456
-                // 'help_tour'     => array('Templates_Help_Tour'),
457
-                'require_nonce' => false,
458
-            ),
459
-            // event category stuff
460
-            'add_category'           => array(
461
-                'nav'           => array(
462
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
463
-                    'order'      => 15,
464
-                    'persistent' => false,
465
-                ),
466
-                'help_tabs'     => array(
467
-                    'add_category_help_tab' => array(
468
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
469
-                        'filename' => 'events_add_category',
470
-                    ),
471
-                ),
472
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
473
-                // 'help_tour'     => array('Event_Add_Category_Help_Tour'),
474
-                'metaboxes'     => array('_publish_post_box'),
475
-                'require_nonce' => false,
476
-            ),
477
-            'edit_category'          => array(
478
-                'nav'           => array(
479
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
480
-                    'order'      => 15,
481
-                    'persistent' => false,
482
-                    'url'        => isset($this->_req_data['EVT_CAT_ID'])
483
-                        ? add_query_arg(
484
-                            array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
485
-                            $this->_current_page_view_url
486
-                        )
487
-                        : $this->_admin_base_url,
488
-                ),
489
-                'help_tabs'     => array(
490
-                    'edit_category_help_tab' => array(
491
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
492
-                        'filename' => 'events_edit_category',
493
-                    ),
494
-                ),
495
-                /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
496
-                'metaboxes'     => array('_publish_post_box'),
497
-                'require_nonce' => false,
498
-            ),
499
-            'category_list'          => array(
500
-                'nav'           => array(
501
-                    'label' => esc_html__('Categories', 'event_espresso'),
502
-                    'order' => 20,
503
-                ),
504
-                'list_table'    => 'Event_Categories_Admin_List_Table',
505
-                'help_tabs'     => array(
506
-                    'events_categories_help_tab'                       => array(
507
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
508
-                        'filename' => 'events_categories',
509
-                    ),
510
-                    'events_categories_table_column_headings_help_tab' => array(
511
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
512
-                        'filename' => 'events_categories_table_column_headings',
513
-                    ),
514
-                    'events_categories_view_help_tab'                  => array(
515
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
516
-                        'filename' => 'events_categories_views',
517
-                    ),
518
-                    'events_categories_other_help_tab'                 => array(
519
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
520
-                        'filename' => 'events_categories_other',
521
-                    ),
522
-                ),
523
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
524
-                // 'help_tour'     => array(
525
-                //     'Event_Categories_Help_Tour',
526
-                // ),
527
-                'metaboxes'     => $this->_default_espresso_metaboxes,
528
-                'require_nonce' => false,
529
-            ),
530
-            'preview_deletion'           => array(
531
-                'nav'           => array(
532
-                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
533
-                    'order'      => 15,
534
-                    'persistent' => false,
535
-                    'url'        => '',
536
-                ),
537
-                'require_nonce' => false
538
-            )
539
-        );
540
-    }
541
-
542
-
543
-    /**
544
-     * Used to register any global screen options if necessary for every route in this admin page group.
545
-     */
546
-    protected function _add_screen_options()
547
-    {
548
-    }
549
-
550
-
551
-    /**
552
-     * Implementing the screen options for the 'default' route.
553
-     */
554
-    protected function _add_screen_options_default()
555
-    {
556
-        $this->_per_page_screen_option();
557
-    }
558
-
559
-
560
-    /**
561
-     * Implementing screen options for the category list route.
562
-     */
563
-    protected function _add_screen_options_category_list()
564
-    {
565
-        $page_title = $this->_admin_page_title;
566
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
567
-        $this->_per_page_screen_option();
568
-        $this->_admin_page_title = $page_title;
569
-    }
570
-
571
-
572
-    /**
573
-     * Used to register any global feature pointers for the admin page group.
574
-     */
575
-    protected function _add_feature_pointers()
576
-    {
577
-    }
578
-
579
-
580
-    /**
581
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
582
-     */
583
-    public function load_scripts_styles()
584
-    {
585
-        wp_register_style(
586
-            'events-admin-css',
587
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
588
-            array(),
589
-            EVENT_ESPRESSO_VERSION
590
-        );
591
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
592
-        wp_enqueue_style('events-admin-css');
593
-        wp_enqueue_style('ee-cat-admin');
594
-        // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
595
-        // registers for all views
596
-        // scripts
597
-        wp_register_script(
598
-            'event_editor_js',
599
-            EVENTS_ASSETS_URL . 'event_editor.js',
600
-            array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
601
-            EVENT_ESPRESSO_VERSION,
602
-            true
603
-        );
604
-    }
605
-
606
-
607
-    /**
608
-     * Enqueuing scripts and styles specific to this view
609
-     */
610
-    public function load_scripts_styles_create_new()
611
-    {
612
-        $this->load_scripts_styles_edit();
613
-    }
614
-
615
-
616
-    /**
617
-     * Enqueuing scripts and styles specific to this view
618
-     */
619
-    public function load_scripts_styles_edit()
620
-    {
621
-        // styles
622
-        wp_enqueue_style('espresso-ui-theme');
623
-        wp_register_style(
624
-            'event-editor-css',
625
-            EVENTS_ASSETS_URL . 'event-editor.css',
626
-            array('ee-admin-css'),
627
-            EVENT_ESPRESSO_VERSION
628
-        );
629
-        wp_enqueue_style('event-editor-css');
630
-        // scripts
631
-        wp_register_script(
632
-            'event-datetime-metabox',
633
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
634
-            array('event_editor_js', 'ee-datepicker'),
635
-            EVENT_ESPRESSO_VERSION
636
-        );
637
-        wp_enqueue_script('event-datetime-metabox');
638
-    }
639
-
640
-
641
-    /**
642
-     * Populating the _views property for the category list table view.
643
-     */
644
-    protected function _set_list_table_views_category_list()
645
-    {
646
-        $this->_views = array(
647
-            'all' => array(
648
-                'slug'        => 'all',
649
-                'label'       => esc_html__('All', 'event_espresso'),
650
-                'count'       => 0,
651
-                'bulk_action' => array(
652
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
653
-                ),
654
-            ),
655
-        );
656
-    }
657
-
658
-
659
-    /**
660
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
661
-     */
662
-    public function admin_init()
663
-    {
664
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
665
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
666
-            'event_espresso'
667
-        );
668
-    }
669
-
670
-
671
-    /**
672
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
673
-     * group.
674
-     */
675
-    public function admin_notices()
676
-    {
677
-    }
678
-
679
-
680
-    /**
681
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
682
-     * this admin page group.
683
-     */
684
-    public function admin_footer_scripts()
685
-    {
686
-    }
687
-
688
-
689
-    /**
690
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
691
-     * warning (via EE_Error::add_error());
692
-     *
693
-     * @param  EE_Event $event Event object
694
-     * @param string    $req_type
695
-     * @return void
696
-     * @throws EE_Error
697
-     * @access public
698
-     */
699
-    public function verify_event_edit($event = null, $req_type = '')
700
-    {
701
-        // don't need to do this when processing
702
-        if (! empty($req_type)) {
703
-            return;
704
-        }
705
-        // no event?
706
-        if (empty($event)) {
707
-            // set event
708
-            $event = $this->_cpt_model_obj;
709
-        }
710
-        // STILL no event?
711
-        if (! $event instanceof EE_Event) {
712
-            return;
713
-        }
714
-        $orig_status = $event->status();
715
-        // first check if event is active.
716
-        if ($orig_status === EEM_Event::cancelled
717
-            || $orig_status === EEM_Event::postponed
718
-            || $event->is_expired()
719
-            || $event->is_inactive()
720
-        ) {
721
-            return;
722
-        }
723
-        // made it here so it IS active... next check that any of the tickets are sold.
724
-        if ($event->is_sold_out(true)) {
725
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
726
-                EE_Error::add_attention(
727
-                    sprintf(
728
-                        esc_html__(
729
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
730
-                            'event_espresso'
731
-                        ),
732
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
733
-                    )
734
-                );
735
-            }
736
-            return;
737
-        } elseif ($orig_status === EEM_Event::sold_out) {
738
-            EE_Error::add_attention(
739
-                sprintf(
740
-                    esc_html__(
741
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
742
-                        'event_espresso'
743
-                    ),
744
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
745
-                )
746
-            );
747
-        }
748
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
749
-        if (! $event->tickets_on_sale()) {
750
-            return;
751
-        }
752
-        // made it here so show warning
753
-        $this->_edit_event_warning();
754
-    }
755
-
756
-
757
-    /**
758
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
759
-     * When needed, hook this into a EE_Error::add_error() notice.
760
-     *
761
-     * @access protected
762
-     * @return void
763
-     */
764
-    protected function _edit_event_warning()
765
-    {
766
-        // we don't want to add warnings during these requests
767
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
768
-            return;
769
-        }
770
-        EE_Error::add_attention(
771
-            sprintf(
772
-                esc_html__(
773
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
774
-                    'event_espresso'
775
-                ),
776
-                '<a class="espresso-help-tab-lnk">',
777
-                '</a>'
778
-            )
779
-        );
780
-    }
781
-
782
-
783
-    /**
784
-     * When a user is creating a new event, notify them if they haven't set their timezone.
785
-     * Otherwise, do the normal logic
786
-     *
787
-     * @return string
788
-     * @throws \EE_Error
789
-     */
790
-    protected function _create_new_cpt_item()
791
-    {
792
-        $has_timezone_string = get_option('timezone_string');
793
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
794
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
795
-            EE_Error::add_attention(
796
-                sprintf(
797
-                    __(
798
-                        'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
799
-                        'event_espresso'
800
-                    ),
801
-                    '<br>',
802
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
803
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
804
-                    . '</select>',
805
-                    '<button class="button button-secondary timezone-submit">',
806
-                    '</button><span class="spinner"></span>'
807
-                ),
808
-                __FILE__,
809
-                __FUNCTION__,
810
-                __LINE__
811
-            );
812
-        }
813
-        return parent::_create_new_cpt_item();
814
-    }
815
-
816
-
817
-    /**
818
-     * Sets the _views property for the default route in this admin page group.
819
-     */
820
-    protected function _set_list_table_views_default()
821
-    {
822
-        $this->_views = array(
823
-            'all'   => array(
824
-                'slug'        => 'all',
825
-                'label'       => esc_html__('View All Events', 'event_espresso'),
826
-                'count'       => 0,
827
-                'bulk_action' => array(
828
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
829
-                ),
830
-            ),
831
-            'draft' => array(
832
-                'slug'        => 'draft',
833
-                'label'       => esc_html__('Draft', 'event_espresso'),
834
-                'count'       => 0,
835
-                'bulk_action' => array(
836
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
837
-                ),
838
-            ),
839
-        );
840
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
841
-            $this->_views['trash'] = array(
842
-                'slug'        => 'trash',
843
-                'label'       => esc_html__('Trash', 'event_espresso'),
844
-                'count'       => 0,
845
-                'bulk_action' => array(
846
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
847
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
848
-                ),
849
-            );
850
-        }
851
-    }
852
-
853
-
854
-    /**
855
-     * Provides the legend item array for the default list table view.
856
-     *
857
-     * @return array
858
-     */
859
-    protected function _event_legend_items()
860
-    {
861
-        $items = array(
862
-            'view_details'   => array(
863
-                'class' => 'dashicons dashicons-search',
864
-                'desc'  => esc_html__('View Event', 'event_espresso'),
865
-            ),
866
-            'edit_event'     => array(
867
-                'class' => 'ee-icon ee-icon-calendar-edit',
868
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
869
-            ),
870
-            'view_attendees' => array(
871
-                'class' => 'dashicons dashicons-groups',
872
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
873
-            ),
874
-        );
875
-        $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
876
-        $statuses = array(
877
-            'sold_out_status'  => array(
878
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
879
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
880
-            ),
881
-            'active_status'    => array(
882
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
883
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
884
-            ),
885
-            'upcoming_status'  => array(
886
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
887
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
888
-            ),
889
-            'postponed_status' => array(
890
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
891
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
892
-            ),
893
-            'cancelled_status' => array(
894
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
895
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
896
-            ),
897
-            'expired_status'   => array(
898
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
899
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
900
-            ),
901
-            'inactive_status'  => array(
902
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
903
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
904
-            ),
905
-        );
906
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
907
-        return array_merge($items, $statuses);
908
-    }
909
-
910
-
911
-    /**
912
-     * @return EEM_Event
913
-     */
914
-    private function _event_model()
915
-    {
916
-        if (! $this->_event_model instanceof EEM_Event) {
917
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
918
-        }
919
-        return $this->_event_model;
920
-    }
921
-
922
-
923
-    /**
924
-     * Adds extra buttons to the WP CPT permalink field row.
925
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
926
-     *
927
-     * @param  string $return    the current html
928
-     * @param  int    $id        the post id for the page
929
-     * @param  string $new_title What the title is
930
-     * @param  string $new_slug  what the slug is
931
-     * @return string            The new html string for the permalink area
932
-     */
933
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
934
-    {
935
-        // make sure this is only when editing
936
-        if (! empty($id)) {
937
-            $post = get_post($id);
938
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
939
-                       . esc_html__('Shortcode', 'event_espresso')
940
-                       . '</a> ';
941
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
942
-                       . $post->ID
943
-                       . ']">';
944
-        }
945
-        return $return;
946
-    }
947
-
948
-
949
-    /**
950
-     * _events_overview_list_table
951
-     * This contains the logic for showing the events_overview list
952
-     *
953
-     * @access protected
954
-     * @return void
955
-     * @throws \EE_Error
956
-     */
957
-    protected function _events_overview_list_table()
958
-    {
959
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
960
-        $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
961
-            ? (array) $this->_template_args['after_list_table']
962
-            : array();
963
-        $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
964
-                . EEH_Template::get_button_or_link(
965
-                    get_post_type_archive_link('espresso_events'),
966
-                    esc_html__("View Event Archive Page", "event_espresso"),
967
-                    'button'
968
-                );
969
-        $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
970
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
971
-            'create_new',
972
-            'add',
973
-            array(),
974
-            'add-new-h2'
975
-        );
976
-        $this->display_admin_list_table_page_with_no_sidebar();
977
-    }
978
-
979
-
980
-    /**
981
-     * this allows for extra misc actions in the default WP publish box
982
-     *
983
-     * @return void
984
-     */
985
-    public function extra_misc_actions_publish_box()
986
-    {
987
-        $this->_generate_publish_box_extra_content();
988
-    }
989
-
990
-
991
-    /**
992
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
993
-     * saved.
994
-     * Typically you would use this to save any additional data.
995
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
996
-     * ALSO very important.  When a post transitions from scheduled to published,
997
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
998
-     * other meta saves. So MAKE sure that you handle this accordingly.
999
-     *
1000
-     * @access protected
1001
-     * @abstract
1002
-     * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
1003
-     * @param  object $post    The post object of the cpt that was saved.
1004
-     * @return void
1005
-     * @throws \EE_Error
1006
-     */
1007
-    protected function _insert_update_cpt_item($post_id, $post)
1008
-    {
1009
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1010
-            // get out we're not processing an event save.
1011
-            return;
1012
-        }
1013
-        $event_values = array(
1014
-            'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
1015
-            'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
1016
-            'EVT_additional_limit'            => min(
1017
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1018
-                ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
1019
-            ),
1020
-            'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
1021
-                ? $this->_req_data['EVT_default_registration_status']
1022
-                : EE_Registry::instance()->CFG->registration->default_STS_ID,
1023
-            'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
1024
-            'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
1025
-            'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
1026
-                ? $this->_req_data['timezone_string'] : null,
1027
-            'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
1028
-                ? $this->_req_data['externalURL'] : null,
1029
-            'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
1030
-                ? $this->_req_data['event_phone'] : null,
1031
-        );
1032
-        // update event
1033
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1034
-        // get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
1035
-        $get_one_where = array(
1036
-            $this->_event_model()->primary_key_name() => $post_id,
1037
-            'OR'                                      => array(
1038
-                'status'   => $post->post_status,
1039
-                // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1040
-                // but the returned object here has a status of "publish", so use the original post status as well
1041
-                'status*1' => $this->_req_data['original_post_status'],
1042
-            ),
1043
-        );
1044
-        $event = $this->_event_model()->get_one(array($get_one_where));
1045
-        // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1046
-        $event_update_callbacks = apply_filters(
1047
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1048
-            array(
1049
-                array($this, '_default_venue_update'),
1050
-                array($this, '_default_tickets_update'),
1051
-            )
1052
-        );
1053
-        $att_success = true;
1054
-        foreach ($event_update_callbacks as $e_callback) {
1055
-            $_success = is_callable($e_callback)
1056
-                ? call_user_func($e_callback, $event, $this->_req_data)
1057
-                : false;
1058
-            // if ANY of these updates fail then we want the appropriate global error message
1059
-            $att_success = ! $att_success ? $att_success : $_success;
1060
-        }
1061
-        // any errors?
1062
-        if ($success && false === $att_success) {
1063
-            EE_Error::add_error(
1064
-                esc_html__(
1065
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1066
-                    'event_espresso'
1067
-                ),
1068
-                __FILE__,
1069
-                __FUNCTION__,
1070
-                __LINE__
1071
-            );
1072
-        } elseif ($success === false) {
1073
-            EE_Error::add_error(
1074
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1075
-                __FILE__,
1076
-                __FUNCTION__,
1077
-                __LINE__
1078
-            );
1079
-        }
1080
-    }
1081
-
1082
-
1083
-    /**
1084
-     * @see parent::restore_item()
1085
-     * @param int $post_id
1086
-     * @param int $revision_id
1087
-     */
1088
-    protected function _restore_cpt_item($post_id, $revision_id)
1089
-    {
1090
-        // copy existing event meta to new post
1091
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1092
-        if ($post_evt instanceof EE_Event) {
1093
-            // meta revision restore
1094
-            $post_evt->restore_revision($revision_id);
1095
-            // related objs restore
1096
-            $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1097
-        }
1098
-    }
1099
-
1100
-
1101
-    /**
1102
-     * Attach the venue to the Event
1103
-     *
1104
-     * @param  \EE_Event $evtobj Event Object to add the venue to
1105
-     * @param  array     $data   The request data from the form
1106
-     * @return bool           Success or fail.
1107
-     */
1108
-    protected function _default_venue_update(\EE_Event $evtobj, $data)
1109
-    {
1110
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1111
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1112
-        $rows_affected = null;
1113
-        $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1114
-        // very important.  If we don't have a venue name...
1115
-        // then we'll get out because not necessary to create empty venue
1116
-        if (empty($data['venue_title'])) {
1117
-            return false;
1118
-        }
1119
-        $venue_array = array(
1120
-            'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1121
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1122
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1123
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1124
-            'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1125
-                : null,
1126
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1127
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1128
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1129
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1130
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1131
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1132
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1133
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1134
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1135
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1136
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1137
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1138
-            'status'              => 'publish',
1139
-        );
1140
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1141
-        if (! empty($venue_id)) {
1142
-            $update_where = array($venue_model->primary_key_name() => $venue_id);
1143
-            $rows_affected = $venue_model->update($venue_array, array($update_where));
1144
-            // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1145
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1146
-            return $rows_affected > 0 ? true : false;
1147
-        } else {
1148
-            // we insert the venue
1149
-            $venue_id = $venue_model->insert($venue_array);
1150
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1151
-            return ! empty($venue_id) ? true : false;
1152
-        }
1153
-        // when we have the ancestor come in it's already been handled by the revision save.
1154
-    }
1155
-
1156
-
1157
-    /**
1158
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1159
-     *
1160
-     * @param  EE_Event $evtobj The Event object we're attaching data to
1161
-     * @param  array    $data   The request data from the form
1162
-     * @return array
1163
-     */
1164
-    protected function _default_tickets_update(EE_Event $evtobj, $data)
1165
-    {
1166
-        $success = true;
1167
-        $saved_dtt = null;
1168
-        $saved_tickets = array();
1169
-        $incoming_date_formats = array('Y-m-d', 'h:i a');
1170
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1171
-            // trim all values to ensure any excess whitespace is removed.
1172
-            $dtt = array_map('trim', $dtt);
1173
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1174
-                : $dtt['DTT_EVT_start'];
1175
-            $datetime_values = array(
1176
-                'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1177
-                'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1178
-                'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1179
-                'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1180
-                'DTT_order'     => $row,
1181
-            );
1182
-            // if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1183
-            if (! empty($dtt['DTT_ID'])) {
1184
-                $DTM = EE_Registry::instance()
1185
-                                  ->load_model('Datetime', array($evtobj->get_timezone()))
1186
-                                  ->get_one_by_ID($dtt['DTT_ID']);
1187
-                $DTM->set_date_format($incoming_date_formats[0]);
1188
-                $DTM->set_time_format($incoming_date_formats[1]);
1189
-                foreach ($datetime_values as $field => $value) {
1190
-                    $DTM->set($field, $value);
1191
-                }
1192
-                // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1193
-                $saved_dtts[ $DTM->ID() ] = $DTM;
1194
-            } else {
1195
-                $DTM = EE_Registry::instance()->load_class(
1196
-                    'Datetime',
1197
-                    array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1198
-                    false,
1199
-                    false
1200
-                );
1201
-                foreach ($datetime_values as $field => $value) {
1202
-                    $DTM->set($field, $value);
1203
-                }
1204
-            }
1205
-            $DTM->save();
1206
-            $DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1207
-            // load DTT helper
1208
-            // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1209
-            if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1210
-                $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1211
-                $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1212
-                $DTT->save();
1213
-            }
1214
-            // now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1215
-            $saved_dtt = $DTT;
1216
-            $success = ! $success ? $success : $DTT;
1217
-            // if ANY of these updates fail then we want the appropriate global error message.
1218
-            // //todo this is actually sucky we need a better error message but this is what it is for now.
1219
-        }
1220
-        // no dtts get deleted so we don't do any of that logic here.
1221
-        // update tickets next
1222
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1223
-        foreach ($data['edit_tickets'] as $row => $tkt) {
1224
-            $incoming_date_formats = array('Y-m-d', 'h:i a');
1225
-            $update_prices = false;
1226
-            $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1227
-                ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1228
-            // trim inputs to ensure any excess whitespace is removed.
1229
-            $tkt = array_map('trim', $tkt);
1230
-            if (empty($tkt['TKT_start_date'])) {
1231
-                // let's use now in the set timezone.
1232
-                $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1233
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1234
-            }
1235
-            if (empty($tkt['TKT_end_date'])) {
1236
-                // use the start date of the first datetime
1237
-                $dtt = $evtobj->first_datetime();
1238
-                $tkt['TKT_end_date'] = $dtt->start_date_and_time(
1239
-                    $incoming_date_formats[0],
1240
-                    $incoming_date_formats[1]
1241
-                );
1242
-            }
1243
-            $TKT_values = array(
1244
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1245
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1246
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1247
-                'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1248
-                'TKT_start_date'  => $tkt['TKT_start_date'],
1249
-                'TKT_end_date'    => $tkt['TKT_end_date'],
1250
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1251
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1252
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1253
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1254
-                'TKT_row'         => $row,
1255
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1256
-                'TKT_price'       => $ticket_price,
1257
-            );
1258
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1259
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1260
-                $TKT_values['TKT_ID'] = 0;
1261
-                $TKT_values['TKT_is_default'] = 0;
1262
-                $TKT_values['TKT_price'] = $ticket_price;
1263
-                $update_prices = true;
1264
-            }
1265
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1266
-            // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1267
-            // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1268
-            if (! empty($tkt['TKT_ID'])) {
1269
-                $TKT = EE_Registry::instance()
1270
-                                  ->load_model('Ticket', array($evtobj->get_timezone()))
1271
-                                  ->get_one_by_ID($tkt['TKT_ID']);
1272
-                if ($TKT instanceof EE_Ticket) {
1273
-                    $ticket_sold = $TKT->count_related(
1274
-                        'Registration',
1275
-                        array(
1276
-                            array(
1277
-                                'STS_ID' => array(
1278
-                                    'NOT IN',
1279
-                                    array(EEM_Registration::status_id_incomplete),
1280
-                                ),
1281
-                            ),
1282
-                        )
1283
-                    ) > 0 ? true : false;
1284
-                    // let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1285
-                    $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1286
-                                      && ! $TKT->get('TKT_deleted');
1287
-                    $TKT->set_date_format($incoming_date_formats[0]);
1288
-                    $TKT->set_time_format($incoming_date_formats[1]);
1289
-                    // set new values
1290
-                    foreach ($TKT_values as $field => $value) {
1291
-                        if ($field == 'TKT_qty') {
1292
-                            $TKT->set_qty($value);
1293
-                        } else {
1294
-                            $TKT->set($field, $value);
1295
-                        }
1296
-                    }
1297
-                    // if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1298
-                    if ($create_new_TKT) {
1299
-                        // archive the old ticket first
1300
-                        $TKT->set('TKT_deleted', 1);
1301
-                        $TKT->save();
1302
-                        // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1303
-                        $saved_tickets[ $TKT->ID() ] = $TKT;
1304
-                        // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1305
-                        $TKT = clone $TKT;
1306
-                        $TKT->set('TKT_ID', 0);
1307
-                        $TKT->set('TKT_deleted', 0);
1308
-                        $TKT->set('TKT_price', $ticket_price);
1309
-                        $TKT->set('TKT_sold', 0);
1310
-                        // now we need to make sure that $new prices are created as well and attached to new ticket.
1311
-                        $update_prices = true;
1312
-                    }
1313
-                    // make sure price is set if it hasn't been already
1314
-                    $TKT->set('TKT_price', $ticket_price);
1315
-                }
1316
-            } else {
1317
-                // no TKT_id so a new TKT
1318
-                $TKT_values['TKT_price'] = $ticket_price;
1319
-                $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1320
-                if ($TKT instanceof EE_Ticket) {
1321
-                    // need to reset values to properly account for the date formats
1322
-                    $TKT->set_date_format($incoming_date_formats[0]);
1323
-                    $TKT->set_time_format($incoming_date_formats[1]);
1324
-                    $TKT->set_timezone($evtobj->get_timezone());
1325
-                    // set new values
1326
-                    foreach ($TKT_values as $field => $value) {
1327
-                        if ($field == 'TKT_qty') {
1328
-                            $TKT->set_qty($value);
1329
-                        } else {
1330
-                            $TKT->set($field, $value);
1331
-                        }
1332
-                    }
1333
-                    $update_prices = true;
1334
-                }
1335
-            }
1336
-            // cap ticket qty by datetime reg limits
1337
-            $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1338
-            // update ticket.
1339
-            $TKT->save();
1340
-            // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1341
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1342
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1343
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1344
-                $TKT->save();
1345
-            }
1346
-            // initially let's add the ticket to the dtt
1347
-            $saved_dtt->_add_relation_to($TKT, 'Ticket');
1348
-            $saved_tickets[ $TKT->ID() ] = $TKT;
1349
-            // add prices to ticket
1350
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1351
-        }
1352
-        // however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1353
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1354
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1355
-        foreach ($tickets_removed as $id) {
1356
-            $id = absint($id);
1357
-            // get the ticket for this id
1358
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1359
-            // need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1360
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
1361
-            foreach ($dtts as $dtt) {
1362
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1363
-            }
1364
-            // need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1365
-            $tkt_to_remove->delete_related_permanently('Price');
1366
-            // finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1367
-            $tkt_to_remove->delete_permanently();
1368
-        }
1369
-        return array($saved_dtt, $saved_tickets);
1370
-    }
1371
-
1372
-
1373
-    /**
1374
-     * This attaches a list of given prices to a ticket.
1375
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1376
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1377
-     * price info and prices are automatically "archived" via the ticket.
1378
-     *
1379
-     * @access  private
1380
-     * @param array     $prices     Array of prices from the form.
1381
-     * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1382
-     * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1383
-     * @return  void
1384
-     */
1385
-    private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1386
-    {
1387
-        foreach ($prices as $row => $prc) {
1388
-            $PRC_values = array(
1389
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1390
-                'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1391
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1392
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1393
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1394
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1395
-                'PRC_order'      => $row,
1396
-            );
1397
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
1398
-                $PRC_values['PRC_ID'] = 0;
1399
-                $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1400
-            } else {
1401
-                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1402
-                // update this price with new values
1403
-                foreach ($PRC_values as $field => $newprc) {
1404
-                    $PRC->set($field, $newprc);
1405
-                }
1406
-                $PRC->save();
1407
-            }
1408
-            $ticket->_add_relation_to($PRC, 'Price');
1409
-        }
1410
-    }
1411
-
1412
-
1413
-    /**
1414
-     * Add in our autosave ajax handlers
1415
-     *
1416
-     */
1417
-    protected function _ee_autosave_create_new()
1418
-    {
1419
-    }
1420
-
1421
-
1422
-    /**
1423
-     * More autosave handlers.
1424
-     */
1425
-    protected function _ee_autosave_edit()
1426
-    {
1427
-        return; // TEMPORARILY EXITING CAUSE THIS IS A TODO
1428
-    }
1429
-
1430
-
1431
-    /**
1432
-     *    _generate_publish_box_extra_content
1433
-     */
1434
-    private function _generate_publish_box_extra_content()
1435
-    {
1436
-        // load formatter helper
1437
-        // args for getting related registrations
1438
-        $approved_query_args = array(
1439
-            array(
1440
-                'REG_deleted' => 0,
1441
-                'STS_ID'      => EEM_Registration::status_id_approved,
1442
-            ),
1443
-        );
1444
-        $not_approved_query_args = array(
1445
-            array(
1446
-                'REG_deleted' => 0,
1447
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1448
-            ),
1449
-        );
1450
-        $pending_payment_query_args = array(
1451
-            array(
1452
-                'REG_deleted' => 0,
1453
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1454
-            ),
1455
-        );
1456
-        // publish box
1457
-        $publish_box_extra_args = array(
1458
-            'view_approved_reg_url'        => add_query_arg(
1459
-                array(
1460
-                    'action'      => 'default',
1461
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1462
-                    '_reg_status' => EEM_Registration::status_id_approved,
1463
-                ),
1464
-                REG_ADMIN_URL
1465
-            ),
1466
-            'view_not_approved_reg_url'    => add_query_arg(
1467
-                array(
1468
-                    'action'      => 'default',
1469
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1470
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1471
-                ),
1472
-                REG_ADMIN_URL
1473
-            ),
1474
-            'view_pending_payment_reg_url' => add_query_arg(
1475
-                array(
1476
-                    'action'      => 'default',
1477
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1478
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1479
-                ),
1480
-                REG_ADMIN_URL
1481
-            ),
1482
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1483
-                'Registration',
1484
-                $approved_query_args
1485
-            ),
1486
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1487
-                'Registration',
1488
-                $not_approved_query_args
1489
-            ),
1490
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1491
-                'Registration',
1492
-                $pending_payment_query_args
1493
-            ),
1494
-            'misc_pub_section_class'       => apply_filters(
1495
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1496
-                'misc-pub-section'
1497
-            ),
1498
-        );
1499
-        ob_start();
1500
-        do_action(
1501
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1502
-            $this->_cpt_model_obj
1503
-        );
1504
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1505
-        // load template
1506
-        EEH_Template::display_template(
1507
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1508
-            $publish_box_extra_args
1509
-        );
1510
-    }
1511
-
1512
-
1513
-    /**
1514
-     * @return EE_Event
1515
-     */
1516
-    public function get_event_object()
1517
-    {
1518
-        return $this->_cpt_model_obj;
1519
-    }
1520
-
1521
-
1522
-
1523
-
1524
-    /** METABOXES * */
1525
-    /**
1526
-     * _register_event_editor_meta_boxes
1527
-     * add all metaboxes related to the event_editor
1528
-     *
1529
-     * @return void
1530
-     */
1531
-    protected function _register_event_editor_meta_boxes()
1532
-    {
1533
-        $this->verify_cpt_object();
1534
-        add_meta_box(
1535
-            'espresso_event_editor_tickets',
1536
-            esc_html__('Event Datetime & Ticket', 'event_espresso'),
1537
-            array($this, 'ticket_metabox'),
1538
-            $this->page_slug,
1539
-            'normal',
1540
-            'high'
1541
-        );
1542
-        add_meta_box(
1543
-            'espresso_event_editor_event_options',
1544
-            esc_html__('Event Registration Options', 'event_espresso'),
1545
-            array($this, 'registration_options_meta_box'),
1546
-            $this->page_slug,
1547
-            'side',
1548
-            'default'
1549
-        );
1550
-        // NOTE: if you're looking for other metaboxes in here,
1551
-        // where a metabox has a related management page in the admin
1552
-        // you will find it setup in the related management page's "_Hooks" file.
1553
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1554
-    }
1555
-
1556
-
1557
-    /**
1558
-     * @throws DomainException
1559
-     * @throws EE_Error
1560
-     */
1561
-    public function ticket_metabox()
1562
-    {
1563
-        $existing_datetime_ids = $existing_ticket_ids = array();
1564
-        // defaults for template args
1565
-        $template_args = array(
1566
-            'existing_datetime_ids'    => '',
1567
-            'event_datetime_help_link' => '',
1568
-            'ticket_options_help_link' => '',
1569
-            'time'                     => null,
1570
-            'ticket_rows'              => '',
1571
-            'existing_ticket_ids'      => '',
1572
-            'total_ticket_rows'        => 1,
1573
-            'ticket_js_structure'      => '',
1574
-            'trash_icon'               => 'ee-lock-icon',
1575
-            'disabled'                 => '',
1576
-        );
1577
-        $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1578
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1579
-        /**
1580
-         * 1. Start with retrieving Datetimes
1581
-         * 2. Fore each datetime get related tickets
1582
-         * 3. For each ticket get related prices
1583
-         */
1584
-        $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1585
-        /** @type EE_Datetime $first_datetime */
1586
-        $first_datetime = reset($times);
1587
-        // do we get related tickets?
1588
-        if ($first_datetime instanceof EE_Datetime
1589
-            && $first_datetime->ID() !== 0
1590
-        ) {
1591
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1592
-            $template_args['time'] = $first_datetime;
1593
-            $related_tickets = $first_datetime->tickets(
1594
-                array(
1595
-                    array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1596
-                    'default_where_conditions' => 'none',
1597
-                )
1598
-            );
1599
-            if (! empty($related_tickets)) {
1600
-                $template_args['total_ticket_rows'] = count($related_tickets);
1601
-                $row = 0;
1602
-                foreach ($related_tickets as $ticket) {
1603
-                    $existing_ticket_ids[] = $ticket->get('TKT_ID');
1604
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1605
-                    $row++;
1606
-                }
1607
-            } else {
1608
-                $template_args['total_ticket_rows'] = 1;
1609
-                /** @type EE_Ticket $ticket */
1610
-                $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1611
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1612
-            }
1613
-        } else {
1614
-            $template_args['time'] = $times[0];
1615
-            /** @type EE_Ticket $ticket */
1616
-            $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1617
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1618
-            // NOTE: we're just sending the first default row
1619
-            // (decaf can't manage default tickets so this should be sufficient);
1620
-        }
1621
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1622
-            'event_editor_event_datetimes_help_tab'
1623
-        );
1624
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1625
-        $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1626
-        $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1627
-        $template_args['ticket_js_structure'] = $this->_get_ticket_row(
1628
-            EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1629
-            true
1630
-        );
1631
-        $template = apply_filters(
1632
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1633
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1634
-        );
1635
-        EEH_Template::display_template($template, $template_args);
1636
-    }
1637
-
1638
-
1639
-    /**
1640
-     * Setup an individual ticket form for the decaf event editor page
1641
-     *
1642
-     * @access private
1643
-     * @param  EE_Ticket $ticket   the ticket object
1644
-     * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1645
-     * @param int        $row
1646
-     * @return string generated html for the ticket row.
1647
-     */
1648
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1649
-    {
1650
-        $template_args = array(
1651
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1652
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1653
-                : '',
1654
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1655
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1656
-            'TKT_name'            => $ticket->get('TKT_name'),
1657
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1658
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1659
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1660
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1661
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1662
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1663
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1664
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1665
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1666
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1667
-                : ' disabled=disabled',
1668
-        );
1669
-        $price = $ticket->ID() !== 0
1670
-            ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1671
-            : EE_Registry::instance()->load_model('Price')->create_default_object();
1672
-        $price_args = array(
1673
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1674
-            'PRC_amount'            => $price->get('PRC_amount'),
1675
-            'PRT_ID'                => $price->get('PRT_ID'),
1676
-            'PRC_ID'                => $price->get('PRC_ID'),
1677
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1678
-        );
1679
-        // make sure we have default start and end dates if skeleton
1680
-        // handle rows that should NOT be empty
1681
-        if (empty($template_args['TKT_start_date'])) {
1682
-            // if empty then the start date will be now.
1683
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1684
-        }
1685
-        if (empty($template_args['TKT_end_date'])) {
1686
-            // get the earliest datetime (if present);
1687
-            $earliest_dtt = $this->_cpt_model_obj->ID() > 0
1688
-                ? $this->_cpt_model_obj->get_first_related(
1689
-                    'Datetime',
1690
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1691
-                )
1692
-                : null;
1693
-            if (! empty($earliest_dtt)) {
1694
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1695
-            } else {
1696
-                $template_args['TKT_end_date'] = date(
1697
-                    'Y-m-d h:i a',
1698
-                    mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1699
-                );
1700
-            }
1701
-        }
1702
-        $template_args = array_merge($template_args, $price_args);
1703
-        $template = apply_filters(
1704
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1705
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1706
-            $ticket
1707
-        );
1708
-        return EEH_Template::display_template($template, $template_args, true);
1709
-    }
1710
-
1711
-
1712
-    /**
1713
-     * @throws DomainException
1714
-     */
1715
-    public function registration_options_meta_box()
1716
-    {
1717
-        $yes_no_values = array(
1718
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1719
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1720
-        );
1721
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1722
-            array(
1723
-                EEM_Registration::status_id_cancelled,
1724
-                EEM_Registration::status_id_declined,
1725
-                EEM_Registration::status_id_incomplete,
1726
-            ),
1727
-            true
1728
-        );
1729
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1730
-        $template_args['_event'] = $this->_cpt_model_obj;
1731
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1732
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1733
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1734
-            'default_reg_status',
1735
-            $default_reg_status_values,
1736
-            $this->_cpt_model_obj->default_registration_status()
1737
-        );
1738
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
1739
-            'display_desc',
1740
-            $yes_no_values,
1741
-            $this->_cpt_model_obj->display_description()
1742
-        );
1743
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1744
-            'display_ticket_selector',
1745
-            $yes_no_values,
1746
-            $this->_cpt_model_obj->display_ticket_selector(),
1747
-            '',
1748
-            '',
1749
-            false
1750
-        );
1751
-        $template_args['additional_registration_options'] = apply_filters(
1752
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1753
-            '',
1754
-            $template_args,
1755
-            $yes_no_values,
1756
-            $default_reg_status_values
1757
-        );
1758
-        EEH_Template::display_template(
1759
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1760
-            $template_args
1761
-        );
1762
-    }
1763
-
1764
-
1765
-    /**
1766
-     * _get_events()
1767
-     * This method simply returns all the events (for the given _view and paging)
1768
-     *
1769
-     * @access public
1770
-     * @param int  $per_page     count of items per page (20 default);
1771
-     * @param int  $current_page what is the current page being viewed.
1772
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1773
-     *                           If FALSE then we return an array of event objects
1774
-     *                           that match the given _view and paging parameters.
1775
-     * @return array an array of event objects.
1776
-     */
1777
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1778
-    {
1779
-        $EEME = $this->_event_model();
1780
-        $offset = ($current_page - 1) * $per_page;
1781
-        $limit = $count ? null : $offset . ',' . $per_page;
1782
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1783
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1784
-        if (isset($this->_req_data['month_range'])) {
1785
-            $pieces = explode(' ', $this->_req_data['month_range'], 3);
1786
-            // simulate the FIRST day of the month, that fixes issues for months like February
1787
-            // where PHP doesn't know what to assume for date.
1788
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1789
-            $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1790
-            $year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1791
-        }
1792
-        $where = array();
1793
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1794
-        // determine what post_status our condition will have for the query.
1795
-        switch ($status) {
1796
-            case 'month':
1797
-            case 'today':
1798
-            case null:
1799
-            case 'all':
1800
-                break;
1801
-            case 'draft':
1802
-                $where['status'] = array('IN', array('draft', 'auto-draft'));
1803
-                break;
1804
-            default:
1805
-                $where['status'] = $status;
1806
-        }
1807
-        // categories?
1808
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1809
-            ? $this->_req_data['EVT_CAT'] : null;
1810
-        if (! empty($category)) {
1811
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1812
-            $where['Term_Taxonomy.term_id'] = $category;
1813
-        }
1814
-        // date where conditions
1815
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1816
-        if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1817
-            $DateTime = new DateTime(
1818
-                $year_r . '-' . $month_r . '-01 00:00:00',
1819
-                new DateTimeZone('UTC')
1820
-            );
1821
-            $start = $DateTime->getTimestamp();
1822
-            // set the datetime to be the end of the month
1823
-            $DateTime->setDate(
1824
-                $year_r,
1825
-                $month_r,
1826
-                $DateTime->format('t')
1827
-            )->setTime(23, 59, 59);
1828
-            $end = $DateTime->getTimestamp();
1829
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1830
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1831
-            $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1832
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1833
-            $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1834
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1835
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1836
-            $now = date('Y-m-01');
1837
-            $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1838
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1839
-            $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1840
-                            ->setTime(23, 59, 59)
1841
-                            ->format(implode(' ', $start_formats));
1842
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1843
-        }
1844
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1845
-            $where['EVT_wp_user'] = get_current_user_id();
1846
-        } else {
1847
-            if (! isset($where['status'])) {
1848
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1849
-                    $where['OR'] = array(
1850
-                        'status*restrict_private' => array('!=', 'private'),
1851
-                        'AND'                     => array(
1852
-                            'status*inclusive' => array('=', 'private'),
1853
-                            'EVT_wp_user'      => get_current_user_id(),
1854
-                        ),
1855
-                    );
1856
-                }
1857
-            }
1858
-        }
1859
-        if (isset($this->_req_data['EVT_wp_user'])) {
1860
-            if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1861
-                && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1862
-            ) {
1863
-                $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1864
-            }
1865
-        }
1866
-        // search query handling
1867
-        if (isset($this->_req_data['s'])) {
1868
-            $search_string = '%' . $this->_req_data['s'] . '%';
1869
-            $where['OR'] = array(
1870
-                'EVT_name'       => array('LIKE', $search_string),
1871
-                'EVT_desc'       => array('LIKE', $search_string),
1872
-                'EVT_short_desc' => array('LIKE', $search_string),
1873
-            );
1874
-        }
1875
-        // filter events by venue.
1876
-        if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) {
1877
-            $where['Venue.VNU_ID'] = absint($this->_req_data['venue']);
1878
-        }
1879
-        $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1880
-        $query_params = apply_filters(
1881
-            'FHEE__Events_Admin_Page__get_events__query_params',
1882
-            array(
1883
-                $where,
1884
-                'limit'    => $limit,
1885
-                'order_by' => $orderby,
1886
-                'order'    => $order,
1887
-                'group_by' => 'EVT_ID',
1888
-            ),
1889
-            $this->_req_data
1890
-        );
1891
-
1892
-        // let's first check if we have special requests coming in.
1893
-        if (isset($this->_req_data['active_status'])) {
1894
-            switch ($this->_req_data['active_status']) {
1895
-                case 'upcoming':
1896
-                    return $EEME->get_upcoming_events($query_params, $count);
1897
-                    break;
1898
-                case 'expired':
1899
-                    return $EEME->get_expired_events($query_params, $count);
1900
-                    break;
1901
-                case 'active':
1902
-                    return $EEME->get_active_events($query_params, $count);
1903
-                    break;
1904
-                case 'inactive':
1905
-                    return $EEME->get_inactive_events($query_params, $count);
1906
-                    break;
1907
-            }
1908
-        }
1909
-
1910
-        $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1911
-        return $events;
1912
-    }
1913
-
1914
-
1915
-    /**
1916
-     * handling for WordPress CPT actions (trash, restore, delete)
1917
-     *
1918
-     * @param string $post_id
1919
-     */
1920
-    public function trash_cpt_item($post_id)
1921
-    {
1922
-        $this->_req_data['EVT_ID'] = $post_id;
1923
-        $this->_trash_or_restore_event('trash', false);
1924
-    }
1925
-
1926
-
1927
-    /**
1928
-     * @param string $post_id
1929
-     */
1930
-    public function restore_cpt_item($post_id)
1931
-    {
1932
-        $this->_req_data['EVT_ID'] = $post_id;
1933
-        $this->_trash_or_restore_event('draft', false);
1934
-    }
1935
-
1936
-
1937
-    /**
1938
-     * @param string $post_id
1939
-     */
1940
-    public function delete_cpt_item($post_id)
1941
-    {
1942
-        throw new EE_Error(esc_html__('Please contact Event Espresso support with the details of the steps taken to produce this error.', 'event_espresso'));
1943
-        $this->_req_data['EVT_ID'] = $post_id;
1944
-        $this->_delete_event();
1945
-    }
1946
-
1947
-
1948
-    /**
1949
-     * _trash_or_restore_event
1950
-     *
1951
-     * @access protected
1952
-     * @param  string $event_status
1953
-     * @param bool    $redirect_after
1954
-     */
1955
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1956
-    {
1957
-        // determine the event id and set to array.
1958
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1959
-        // loop thru events
1960
-        if ($EVT_ID) {
1961
-            // clean status
1962
-            $event_status = sanitize_key($event_status);
1963
-            // grab status
1964
-            if (! empty($event_status)) {
1965
-                $success = $this->_change_event_status($EVT_ID, $event_status);
1966
-            } else {
1967
-                $success = false;
1968
-                $msg = esc_html__(
1969
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1970
-                    'event_espresso'
1971
-                );
1972
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1973
-            }
1974
-        } else {
1975
-            $success = false;
1976
-            $msg = esc_html__(
1977
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1978
-                'event_espresso'
1979
-            );
1980
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1981
-        }
1982
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1983
-        if ($redirect_after) {
1984
-            $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1985
-        }
1986
-    }
1987
-
1988
-
1989
-    /**
1990
-     * _trash_or_restore_events
1991
-     *
1992
-     * @access protected
1993
-     * @param  string $event_status
1994
-     * @return void
1995
-     */
1996
-    protected function _trash_or_restore_events($event_status = 'trash')
1997
-    {
1998
-        // clean status
1999
-        $event_status = sanitize_key($event_status);
2000
-        // grab status
2001
-        if (! empty($event_status)) {
2002
-            $success = true;
2003
-            // determine the event id and set to array.
2004
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
2005
-            // loop thru events
2006
-            foreach ($EVT_IDs as $EVT_ID) {
2007
-                if ($EVT_ID = absint($EVT_ID)) {
2008
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
2009
-                    $success = $results !== false ? $success : false;
2010
-                } else {
2011
-                    $msg = sprintf(
2012
-                        esc_html__(
2013
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2014
-                            'event_espresso'
2015
-                        ),
2016
-                        $EVT_ID
2017
-                    );
2018
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2019
-                    $success = false;
2020
-                }
2021
-            }
2022
-        } else {
2023
-            $success = false;
2024
-            $msg = esc_html__(
2025
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2026
-                'event_espresso'
2027
-            );
2028
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2029
-        }
2030
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2031
-        $success = $success ? 2 : false;
2032
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2033
-        $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
2034
-    }
2035
-
2036
-
2037
-    /**
2038
-     * @param  int    $EVT_ID
2039
-     * @param  string $event_status
2040
-     * @return bool
2041
-     */
2042
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2043
-    {
2044
-        // grab event id
2045
-        if (! $EVT_ID) {
2046
-            $msg = esc_html__(
2047
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2048
-                'event_espresso'
2049
-            );
2050
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2051
-            return false;
2052
-        }
2053
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2054
-        // clean status
2055
-        $event_status = sanitize_key($event_status);
2056
-        // grab status
2057
-        if (empty($event_status)) {
2058
-            $msg = esc_html__(
2059
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2060
-                'event_espresso'
2061
-            );
2062
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2063
-            return false;
2064
-        }
2065
-        // was event trashed or restored ?
2066
-        switch ($event_status) {
2067
-            case 'draft':
2068
-                $action = 'restored from the trash';
2069
-                $hook = 'AHEE_event_restored_from_trash';
2070
-                break;
2071
-            case 'trash':
2072
-                $action = 'moved to the trash';
2073
-                $hook = 'AHEE_event_moved_to_trash';
2074
-                break;
2075
-            default:
2076
-                $action = 'updated';
2077
-                $hook = false;
2078
-        }
2079
-        // use class to change status
2080
-        $this->_cpt_model_obj->set_status($event_status);
2081
-        $success = $this->_cpt_model_obj->save();
2082
-        if (! $success) {
2083
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2084
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2085
-            return false;
2086
-        }
2087
-        if ($hook) {
2088
-            do_action($hook);
2089
-        }
2090
-        return true;
2091
-    }
2092
-
2093
-
2094
-    /**
2095
-     * @param array $event_ids
2096
-     * @return array
2097
-     * @since   $VID:$
2098
-     */
2099
-    private function cleanEventIds(array $event_ids)
2100
-    {
2101
-        return array_map('absint', $event_ids);
2102
-    }
2103
-
2104
-
2105
-    /**
2106
-     * @return array
2107
-     * @since   $VID:$
2108
-     */
2109
-    private function getEventIdsFromRequest()
2110
-    {
2111
-        $event_ids = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : [];
2112
-        $event_ids = is_string($event_ids) ? explode(',', $event_ids) : (array) $event_ids;
2113
-        return $this->cleanEventIds($event_ids);
2114
-    }
2115
-
2116
-
2117
-    /**
2118
-     * @param bool $preview_delete
2119
-     * @throws EE_Error
2120
-     */
2121
-    protected function _delete_event($preview_delete = true)
2122
-    {
2123
-        $this->_delete_events($preview_delete);
2124
-    }
2125
-
2126
-
2127
-    /**
2128
-     * Gets the tree traversal batch persister.
2129
-     * @since 4.10.12.p
2130
-     * @return NodeGroupDao
2131
-     * @throws InvalidArgumentException
2132
-     * @throws InvalidDataTypeException
2133
-     * @throws InvalidInterfaceException
2134
-     */
2135
-    protected function getModelObjNodeGroupPersister()
2136
-    {
2137
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2138
-            $this->model_obj_node_group_persister = $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2139
-        }
2140
-        return $this->model_obj_node_group_persister;
2141
-    }
2142
-
2143
-
2144
-    /**
2145
-     * @param bool $preview_delete
2146
-     * @return void
2147
-     * @throws EE_Error
2148
-     */
2149
-    protected function _delete_events($preview_delete = true)
2150
-    {
2151
-        $event_ids = $this->getEventIdsFromRequest();
2152
-        if ($preview_delete) {
2153
-            $this->generateDeletionPreview($event_ids);
2154
-        } else {
2155
-            EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2156
-        }
2157
-    }
2158
-
2159
-
2160
-    /**
2161
-     * @param array $event_ids
2162
-     */
2163
-    protected function generateDeletionPreview(array $event_ids)
2164
-    {
2165
-        $event_ids = $this->cleanEventIds($event_ids);
2166
-        // Set a code we can use to reference this deletion task in the batch jobs and preview page.
2167
-        $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2168
-        $return_url = EE_Admin_Page::add_query_args_and_nonce(
2169
-            [
2170
-                'action' => 'preview_deletion',
2171
-                'deletion_job_code' => $deletion_job_code,
2172
-            ],
2173
-            $this->_admin_base_url
2174
-        );
2175
-        EEH_URL::safeRedirectAndExit(
2176
-            EE_Admin_Page::add_query_args_and_nonce(
2177
-                [
2178
-                    'page'              => 'espresso_batch',
2179
-                    'batch'             => EED_Batch::batch_job,
2180
-                    'EVT_IDs'           => $event_ids,
2181
-                    'deletion_job_code' => $deletion_job_code,
2182
-                    'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2183
-                    'return_url'        => urlencode($return_url),
2184
-                ],
2185
-                admin_url()
2186
-            )
2187
-        );
2188
-    }
2189
-
2190
-    /**
2191
-     * Checks for a POST submission
2192
-     * @since 4.10.12.p
2193
-     */
2194
-    protected function confirmDeletion()
2195
-    {
2196
-        $deletion_redirect_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2197
-        $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2198
-    }
2199
-
2200
-    /**
2201
-     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2202
-     * @since 4.10.12.p
2203
-     * @throws EE_Error
2204
-     */
2205
-    protected function previewDeletion()
2206
-    {
2207
-        $preview_deletion_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2208
-        $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2209
-        $this->display_admin_page_with_no_sidebar();
2210
-    }
2211
-
2212
-    /**
2213
-     * get total number of events
2214
-     *
2215
-     * @access public
2216
-     * @return int
2217
-     */
2218
-    public function total_events()
2219
-    {
2220
-        $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2221
-        return $count;
2222
-    }
2223
-
2224
-
2225
-    /**
2226
-     * get total number of draft events
2227
-     *
2228
-     * @access public
2229
-     * @return int
2230
-     */
2231
-    public function total_events_draft()
2232
-    {
2233
-        $where = array(
2234
-            'status' => array('IN', array('draft', 'auto-draft')),
2235
-        );
2236
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2237
-        return $count;
2238
-    }
2239
-
2240
-
2241
-    /**
2242
-     * get total number of trashed events
2243
-     *
2244
-     * @access public
2245
-     * @return int
2246
-     */
2247
-    public function total_trashed_events()
2248
-    {
2249
-        $where = array(
2250
-            'status' => 'trash',
2251
-        );
2252
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2253
-        return $count;
2254
-    }
2255
-
2256
-
2257
-    /**
2258
-     *    _default_event_settings
2259
-     *    This generates the Default Settings Tab
2260
-     *
2261
-     * @return void
2262
-     * @throws EE_Error
2263
-     */
2264
-    protected function _default_event_settings()
2265
-    {
2266
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2267
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2268
-        $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2269
-        $this->display_admin_page_with_sidebar();
2270
-    }
2271
-
2272
-
2273
-    /**
2274
-     * Return the form for event settings.
2275
-     *
2276
-     * @return EE_Form_Section_Proper
2277
-     * @throws EE_Error
2278
-     */
2279
-    protected function _default_event_settings_form()
2280
-    {
2281
-        $registration_config = EE_Registry::instance()->CFG->registration;
2282
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2283
-            // exclude
2284
-            array(
2285
-                EEM_Registration::status_id_cancelled,
2286
-                EEM_Registration::status_id_declined,
2287
-                EEM_Registration::status_id_incomplete,
2288
-                EEM_Registration::status_id_wait_list,
2289
-            ),
2290
-            true
2291
-        );
2292
-        return new EE_Form_Section_Proper(
2293
-            array(
2294
-                'name'            => 'update_default_event_settings',
2295
-                'html_id'         => 'update_default_event_settings',
2296
-                'html_class'      => 'form-table',
2297
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2298
-                'subsections'     => apply_filters(
2299
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2300
-                    array(
2301
-                        'default_reg_status'  => new EE_Select_Input(
2302
-                            $registration_stati_for_selection,
2303
-                            array(
2304
-                                'default'         => isset($registration_config->default_STS_ID)
2305
-                                                     && array_key_exists(
2306
-                                                         $registration_config->default_STS_ID,
2307
-                                                         $registration_stati_for_selection
2308
-                                                     )
2309
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2310
-                                    : EEM_Registration::status_id_pending_payment,
2311
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2312
-                                                     . EEH_Template::get_help_tab_link(
2313
-                                                         'default_settings_status_help_tab'
2314
-                                                     ),
2315
-                                'html_help_text'  => esc_html__(
2316
-                                    'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2317
-                                    'event_espresso'
2318
-                                ),
2319
-                            )
2320
-                        ),
2321
-                        'default_max_tickets' => new EE_Integer_Input(
2322
-                            array(
2323
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2324
-                                    ? $registration_config->default_maximum_number_of_tickets
2325
-                                    : EEM_Event::get_default_additional_limit(),
2326
-                                'html_label_text' => esc_html__(
2327
-                                    'Default Maximum Tickets Allowed Per Order:',
2328
-                                    'event_espresso'
2329
-                                )
2330
-                                                     . EEH_Template::get_help_tab_link(
2331
-                                                         'default_maximum_tickets_help_tab"'
2332
-                                                     ),
2333
-                                'html_help_text'  => esc_html__(
2334
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2335
-                                    'event_espresso'
2336
-                                ),
2337
-                            )
2338
-                        ),
2339
-                    )
2340
-                ),
2341
-            )
2342
-        );
2343
-    }
2344
-
2345
-
2346
-    /**
2347
-     * _update_default_event_settings
2348
-     *
2349
-     * @access protected
2350
-     * @return void
2351
-     * @throws EE_Error
2352
-     */
2353
-    protected function _update_default_event_settings()
2354
-    {
2355
-        $registration_config = EE_Registry::instance()->CFG->registration;
2356
-        $form = $this->_default_event_settings_form();
2357
-        if ($form->was_submitted()) {
2358
-            $form->receive_form_submission();
2359
-            if ($form->is_valid()) {
2360
-                $valid_data = $form->valid_data();
2361
-                if (isset($valid_data['default_reg_status'])) {
2362
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2363
-                }
2364
-                if (isset($valid_data['default_max_tickets'])) {
2365
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2366
-                }
2367
-                // update because data was valid!
2368
-                EE_Registry::instance()->CFG->update_espresso_config();
2369
-                EE_Error::overwrite_success();
2370
-                EE_Error::add_success(
2371
-                    __('Default Event Settings were updated', 'event_espresso')
2372
-                );
2373
-            }
2374
-        }
2375
-        $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true);
2376
-    }
2377
-
2378
-
2379
-    /*************        Templates        *************/
2380
-    protected function _template_settings()
2381
-    {
2382
-        $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2383
-        $this->_template_args['preview_img'] = '<img src="'
2384
-                                               . EVENTS_ASSETS_URL
2385
-                                               . '/images/'
2386
-                                               . 'caffeinated_template_features.jpg" alt="'
2387
-                                               . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2388
-                                               . '" />';
2389
-        $this->_template_args['preview_text'] = '<strong>'
2390
-                                                . esc_html__(
2391
-                                                    'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2392
-                                                    'event_espresso'
2393
-                                                ) . '</strong>';
2394
-        $this->display_admin_caf_preview_page('template_settings_tab');
2395
-    }
2396
-
2397
-
2398
-    /** Event Category Stuff **/
2399
-    /**
2400
-     * set the _category property with the category object for the loaded page.
2401
-     *
2402
-     * @access private
2403
-     * @return void
2404
-     */
2405
-    private function _set_category_object()
2406
-    {
2407
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2408
-            return;
2409
-        } //already have the category object so get out.
2410
-        // set default category object
2411
-        $this->_set_empty_category_object();
2412
-        // only set if we've got an id
2413
-        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2414
-            return;
2415
-        }
2416
-        $category_id = absint($this->_req_data['EVT_CAT_ID']);
2417
-        $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2418
-        if (! empty($term)) {
2419
-            $this->_category->category_name = $term->name;
2420
-            $this->_category->category_identifier = $term->slug;
2421
-            $this->_category->category_desc = $term->description;
2422
-            $this->_category->id = $term->term_id;
2423
-            $this->_category->parent = $term->parent;
2424
-        }
2425
-    }
2426
-
2427
-
2428
-    /**
2429
-     * Clears out category properties.
2430
-     */
2431
-    private function _set_empty_category_object()
2432
-    {
2433
-        $this->_category = new stdClass();
2434
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2435
-        $this->_category->id = $this->_category->parent = 0;
2436
-    }
2437
-
2438
-
2439
-    /**
2440
-     * @throws EE_Error
2441
-     */
2442
-    protected function _category_list_table()
2443
-    {
2444
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2445
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2446
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2447
-            'add_category',
2448
-            'add_category',
2449
-            array(),
2450
-            'add-new-h2'
2451
-        );
2452
-        $this->display_admin_list_table_page_with_sidebar();
2453
-    }
2454
-
2455
-
2456
-    /**
2457
-     * Output category details view.
2458
-     */
2459
-    protected function _category_details($view)
2460
-    {
2461
-        // load formatter helper
2462
-        // load field generator helper
2463
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
2464
-        $this->_set_add_edit_form_tags($route);
2465
-        $this->_set_category_object();
2466
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
2467
-        $delete_action = 'delete_category';
2468
-        // custom redirect
2469
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2470
-            array('action' => 'category_list'),
2471
-            $this->_admin_base_url
2472
-        );
2473
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2474
-        // take care of contents
2475
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2476
-        $this->display_admin_page_with_sidebar();
2477
-    }
2478
-
2479
-
2480
-    /**
2481
-     * Output category details content.
2482
-     */
2483
-    protected function _category_details_content()
2484
-    {
2485
-        $editor_args['category_desc'] = array(
2486
-            'type'          => 'wp_editor',
2487
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2488
-            'class'         => 'my_editor_custom',
2489
-            'wpeditor_args' => array('media_buttons' => false),
2490
-        );
2491
-        $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2492
-        $all_terms = get_terms(
2493
-            array(EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY),
2494
-            array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2495
-        );
2496
-        // setup category select for term parents.
2497
-        $category_select_values[] = array(
2498
-            'text' => esc_html__('No Parent', 'event_espresso'),
2499
-            'id'   => 0,
2500
-        );
2501
-        foreach ($all_terms as $term) {
2502
-            $category_select_values[] = array(
2503
-                'text' => $term->name,
2504
-                'id'   => $term->term_id,
2505
-            );
2506
-        }
2507
-        $category_select = EEH_Form_Fields::select_input(
2508
-            'category_parent',
2509
-            $category_select_values,
2510
-            $this->_category->parent
2511
-        );
2512
-        $template_args = array(
2513
-            'category'                 => $this->_category,
2514
-            'category_select'          => $category_select,
2515
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2516
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2517
-            'disable'                  => '',
2518
-            'disabled_message'         => false,
2519
-        );
2520
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2521
-        return EEH_Template::display_template($template, $template_args, true);
2522
-    }
2523
-
2524
-
2525
-    /**
2526
-     * Handles deleting categories.
2527
-     */
2528
-    protected function _delete_categories()
2529
-    {
2530
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2531
-            : (array) $this->_req_data['category_id'];
2532
-        foreach ($cat_ids as $cat_id) {
2533
-            $this->_delete_category($cat_id);
2534
-        }
2535
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2536
-        $query_args = array(
2537
-            'action' => 'category_list',
2538
-        );
2539
-        $this->_redirect_after_action(0, '', '', $query_args);
2540
-    }
2541
-
2542
-
2543
-    /**
2544
-     * Handles deleting specific category.
2545
-     *
2546
-     * @param int $cat_id
2547
-     */
2548
-    protected function _delete_category($cat_id)
2549
-    {
2550
-        $cat_id = absint($cat_id);
2551
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2552
-    }
2553
-
2554
-
2555
-    /**
2556
-     * Handles triggering the update or insertion of a new category.
2557
-     *
2558
-     * @param bool $new_category true means we're triggering the insert of a new category.
2559
-     */
2560
-    protected function _insert_or_update_category($new_category)
2561
-    {
2562
-        $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2563
-        $success = 0; // we already have a success message so lets not send another.
2564
-        if ($cat_id) {
2565
-            $query_args = array(
2566
-                'action'     => 'edit_category',
2567
-                'EVT_CAT_ID' => $cat_id,
2568
-            );
2569
-        } else {
2570
-            $query_args = array('action' => 'add_category');
2571
-        }
2572
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2573
-    }
2574
-
2575
-
2576
-    /**
2577
-     * Inserts or updates category
2578
-     *
2579
-     * @param bool $update (true indicates we're updating a category).
2580
-     * @return bool|mixed|string
2581
-     */
2582
-    private function _insert_category($update = false)
2583
-    {
2584
-        $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2585
-        $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2586
-        $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2587
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2588
-        if (empty($category_name)) {
2589
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2590
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2591
-            return false;
2592
-        }
2593
-        $term_args = array(
2594
-            'name'        => $category_name,
2595
-            'description' => $category_desc,
2596
-            'parent'      => $category_parent,
2597
-        );
2598
-        // was the category_identifier input disabled?
2599
-        if (isset($this->_req_data['category_identifier'])) {
2600
-            $term_args['slug'] = $this->_req_data['category_identifier'];
2601
-        }
2602
-        $insert_ids = $update
2603
-            ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2604
-            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2605
-        if (! is_array($insert_ids)) {
2606
-            $msg = esc_html__(
2607
-                'An error occurred and the category has not been saved to the database.',
2608
-                'event_espresso'
2609
-            );
2610
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2611
-        } else {
2612
-            $cat_id = $insert_ids['term_id'];
2613
-            $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2614
-            EE_Error::add_success($msg);
2615
-        }
2616
-        return $cat_id;
2617
-    }
2618
-
2619
-
2620
-    /**
2621
-     * Gets categories or count of categories matching the arguments in the request.
2622
-     *
2623
-     * @param int  $per_page
2624
-     * @param int  $current_page
2625
-     * @param bool $count
2626
-     * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2627
-     */
2628
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2629
-    {
2630
-        // testing term stuff
2631
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2632
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2633
-        $limit = ($current_page - 1) * $per_page;
2634
-        $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2635
-        if (isset($this->_req_data['s'])) {
2636
-            $sstr = '%' . $this->_req_data['s'] . '%';
2637
-            $where['OR'] = array(
2638
-                'Term.name'   => array('LIKE', $sstr),
2639
-                'description' => array('LIKE', $sstr),
2640
-            );
2641
-        }
2642
-        $query_params = array(
2643
-            $where,
2644
-            'order_by'   => array($orderby => $order),
2645
-            'limit'      => $limit . ',' . $per_page,
2646
-            'force_join' => array('Term'),
2647
-        );
2648
-        $categories = $count
2649
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2650
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2651
-        return $categories;
2652
-    }
2653
-
2654
-    /* end category stuff */
2655
-    /**************/
2656
-
2657
-
2658
-    /**
2659
-     * Callback for the `ee_save_timezone_setting` ajax action.
2660
-     *
2661
-     * @throws EE_Error
2662
-     */
2663
-    public function save_timezonestring_setting()
2664
-    {
2665
-        $timezone_string = isset($this->_req_data['timezone_selected'])
2666
-            ? $this->_req_data['timezone_selected']
2667
-            : '';
2668
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2669
-            EE_Error::add_error(
2670
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2671
-                __FILE__,
2672
-                __FUNCTION__,
2673
-                __LINE__
2674
-            );
2675
-            $this->_template_args['error'] = true;
2676
-            $this->_return_json();
2677
-        }
2678
-
2679
-        update_option('timezone_string', $timezone_string);
2680
-        EE_Error::add_success(
2681
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2682
-        );
2683
-        $this->_template_args['success'] = true;
2684
-        $this->_return_json(true, array('action' => 'create_new'));
2685
-    }
22
+	/**
23
+	 * This will hold the event object for event_details screen.
24
+	 *
25
+	 * @access protected
26
+	 * @var EE_Event $_event
27
+	 */
28
+	protected $_event;
29
+
30
+
31
+	/**
32
+	 * This will hold the category object for category_details screen.
33
+	 *
34
+	 * @var stdClass $_category
35
+	 */
36
+	protected $_category;
37
+
38
+
39
+	/**
40
+	 * This will hold the event model instance
41
+	 *
42
+	 * @var EEM_Event $_event_model
43
+	 */
44
+	protected $_event_model;
45
+
46
+
47
+	/**
48
+	 * @var EE_Event
49
+	 */
50
+	protected $_cpt_model_obj = false;
51
+
52
+
53
+	/**
54
+	 * @var NodeGroupDao
55
+	 */
56
+	protected $model_obj_node_group_persister;
57
+
58
+	/**
59
+	 * Initialize page props for this admin page group.
60
+	 */
61
+	protected function _init_page_props()
62
+	{
63
+		$this->page_slug = EVENTS_PG_SLUG;
64
+		$this->page_label = EVENTS_LABEL;
65
+		$this->_admin_base_url = EVENTS_ADMIN_URL;
66
+		$this->_admin_base_path = EVENTS_ADMIN;
67
+		$this->_cpt_model_names = array(
68
+			'create_new' => 'EEM_Event',
69
+			'edit'       => 'EEM_Event',
70
+		);
71
+		$this->_cpt_edit_routes = array(
72
+			'espresso_events' => 'edit',
73
+		);
74
+		add_action(
75
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
76
+			array($this, 'verify_event_edit'),
77
+			10,
78
+			2
79
+		);
80
+	}
81
+
82
+
83
+	/**
84
+	 * Sets the ajax hooks used for this admin page group.
85
+	 */
86
+	protected function _ajax_hooks()
87
+	{
88
+		add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting'));
89
+	}
90
+
91
+
92
+	/**
93
+	 * Sets the page properties for this admin page group.
94
+	 */
95
+	protected function _define_page_props()
96
+	{
97
+		$this->_admin_page_title = EVENTS_LABEL;
98
+		$this->_labels = array(
99
+			'buttons'      => array(
100
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
101
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
102
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
103
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
104
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
105
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
106
+			),
107
+			'editor_title' => array(
108
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
109
+			),
110
+			'publishbox'   => array(
111
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
112
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
113
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
114
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
115
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
116
+			),
117
+		);
118
+	}
119
+
120
+
121
+	/**
122
+	 * Sets the page routes property for this admin page group.
123
+	 */
124
+	protected function _set_page_routes()
125
+	{
126
+		// load formatter helper
127
+		// load field generator helper
128
+		// is there a evt_id in the request?
129
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
130
+			? $this->_req_data['EVT_ID']
131
+			: 0;
132
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
133
+		$this->_page_routes = array(
134
+			'default'                       => array(
135
+				'func'       => '_events_overview_list_table',
136
+				'capability' => 'ee_read_events',
137
+			),
138
+			'create_new'                    => array(
139
+				'func'       => '_create_new_cpt_item',
140
+				'capability' => 'ee_edit_events',
141
+			),
142
+			'edit'                          => array(
143
+				'func'       => '_edit_cpt_item',
144
+				'capability' => 'ee_edit_event',
145
+				'obj_id'     => $evt_id,
146
+			),
147
+			'copy_event'                    => array(
148
+				'func'       => '_copy_events',
149
+				'capability' => 'ee_edit_event',
150
+				'obj_id'     => $evt_id,
151
+				'noheader'   => true,
152
+			),
153
+			'trash_event'                   => array(
154
+				'func'       => '_trash_or_restore_event',
155
+				'args'       => array('event_status' => 'trash'),
156
+				'capability' => 'ee_delete_event',
157
+				'obj_id'     => $evt_id,
158
+				'noheader'   => true,
159
+			),
160
+			'trash_events'                  => array(
161
+				'func'       => '_trash_or_restore_events',
162
+				'args'       => array('event_status' => 'trash'),
163
+				'capability' => 'ee_delete_events',
164
+				'noheader'   => true,
165
+			),
166
+			'restore_event'                 => array(
167
+				'func'       => '_trash_or_restore_event',
168
+				'args'       => array('event_status' => 'draft'),
169
+				'capability' => 'ee_delete_event',
170
+				'obj_id'     => $evt_id,
171
+				'noheader'   => true,
172
+			),
173
+			'restore_events'                => array(
174
+				'func'       => '_trash_or_restore_events',
175
+				'args'       => array('event_status' => 'draft'),
176
+				'capability' => 'ee_delete_events',
177
+				'noheader'   => true,
178
+			),
179
+			'delete_event'                  => array(
180
+				'func'       => '_delete_event',
181
+				'capability' => 'ee_delete_event',
182
+				'obj_id'     => $evt_id,
183
+				'noheader'   => true,
184
+			),
185
+			'delete_events'                 => array(
186
+				'func'       => '_delete_events',
187
+				'capability' => 'ee_delete_events',
188
+				'noheader'   => true,
189
+			),
190
+			'view_report'                   => array(
191
+				'func'      => '_view_report',
192
+				'capablity' => 'ee_edit_events',
193
+			),
194
+			'default_event_settings'        => array(
195
+				'func'       => '_default_event_settings',
196
+				'capability' => 'manage_options',
197
+			),
198
+			'update_default_event_settings' => array(
199
+				'func'       => '_update_default_event_settings',
200
+				'capability' => 'manage_options',
201
+				'noheader'   => true,
202
+			),
203
+			'template_settings'             => array(
204
+				'func'       => '_template_settings',
205
+				'capability' => 'manage_options',
206
+			),
207
+			// event category tab related
208
+			'add_category'                  => array(
209
+				'func'       => '_category_details',
210
+				'capability' => 'ee_edit_event_category',
211
+				'args'       => array('add'),
212
+			),
213
+			'edit_category'                 => array(
214
+				'func'       => '_category_details',
215
+				'capability' => 'ee_edit_event_category',
216
+				'args'       => array('edit'),
217
+			),
218
+			'delete_categories'             => array(
219
+				'func'       => '_delete_categories',
220
+				'capability' => 'ee_delete_event_category',
221
+				'noheader'   => true,
222
+			),
223
+			'delete_category'               => array(
224
+				'func'       => '_delete_categories',
225
+				'capability' => 'ee_delete_event_category',
226
+				'noheader'   => true,
227
+			),
228
+			'insert_category'               => array(
229
+				'func'       => '_insert_or_update_category',
230
+				'args'       => array('new_category' => true),
231
+				'capability' => 'ee_edit_event_category',
232
+				'noheader'   => true,
233
+			),
234
+			'update_category'               => array(
235
+				'func'       => '_insert_or_update_category',
236
+				'args'       => array('new_category' => false),
237
+				'capability' => 'ee_edit_event_category',
238
+				'noheader'   => true,
239
+			),
240
+			'category_list'                 => array(
241
+				'func'       => '_category_list_table',
242
+				'capability' => 'ee_manage_event_categories',
243
+			),
244
+			'preview_deletion' => [
245
+				'func' => 'previewDeletion',
246
+				'capability' => 'ee_delete_events',
247
+			],
248
+			'confirm_deletion' => [
249
+				'func' => 'confirmDeletion',
250
+				'capability' => 'ee_delete_events',
251
+				'noheader' => true,
252
+			]
253
+		);
254
+	}
255
+
256
+
257
+	/**
258
+	 * Set the _page_config property for this admin page group.
259
+	 */
260
+	protected function _set_page_config()
261
+	{
262
+		$this->_page_config = array(
263
+			'default'                => array(
264
+				'nav'           => array(
265
+					'label' => esc_html__('Overview', 'event_espresso'),
266
+					'order' => 10,
267
+				),
268
+				'list_table'    => 'Events_Admin_List_Table',
269
+				'help_tabs'     => array(
270
+					'events_overview_help_tab'                       => array(
271
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
272
+						'filename' => 'events_overview',
273
+					),
274
+					'events_overview_table_column_headings_help_tab' => array(
275
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
276
+						'filename' => 'events_overview_table_column_headings',
277
+					),
278
+					'events_overview_filters_help_tab'               => array(
279
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
280
+						'filename' => 'events_overview_filters',
281
+					),
282
+					'events_overview_view_help_tab'                  => array(
283
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
284
+						'filename' => 'events_overview_views',
285
+					),
286
+					'events_overview_other_help_tab'                 => array(
287
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
288
+						'filename' => 'events_overview_other',
289
+					),
290
+				),
291
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
292
+				// 'help_tour'     => array(
293
+				//     'Event_Overview_Help_Tour',
294
+				//     // 'New_Features_Test_Help_Tour' for testing multiple help tour
295
+				// ),
296
+				'qtips'         => array(
297
+					'EE_Event_List_Table_Tips',
298
+				),
299
+				'require_nonce' => false,
300
+			),
301
+			'create_new'             => array(
302
+				'nav'           => array(
303
+					'label'      => esc_html__('Add Event', 'event_espresso'),
304
+					'order'      => 5,
305
+					'persistent' => false,
306
+				),
307
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
308
+				'help_tabs'     => array(
309
+					'event_editor_help_tab'                            => array(
310
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
311
+						'filename' => 'event_editor',
312
+					),
313
+					'event_editor_title_richtexteditor_help_tab'       => array(
314
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
315
+						'filename' => 'event_editor_title_richtexteditor',
316
+					),
317
+					'event_editor_venue_details_help_tab'              => array(
318
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
319
+						'filename' => 'event_editor_venue_details',
320
+					),
321
+					'event_editor_event_datetimes_help_tab'            => array(
322
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
323
+						'filename' => 'event_editor_event_datetimes',
324
+					),
325
+					'event_editor_event_tickets_help_tab'              => array(
326
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
327
+						'filename' => 'event_editor_event_tickets',
328
+					),
329
+					'event_editor_event_registration_options_help_tab' => array(
330
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
331
+						'filename' => 'event_editor_event_registration_options',
332
+					),
333
+					'event_editor_tags_categories_help_tab'            => array(
334
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
335
+						'filename' => 'event_editor_tags_categories',
336
+					),
337
+					'event_editor_questions_registrants_help_tab'      => array(
338
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
339
+						'filename' => 'event_editor_questions_registrants',
340
+					),
341
+					'event_editor_save_new_event_help_tab'             => array(
342
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
343
+						'filename' => 'event_editor_save_new_event',
344
+					),
345
+					'event_editor_other_help_tab'                      => array(
346
+						'title'    => esc_html__('Event Other', 'event_espresso'),
347
+						'filename' => 'event_editor_other',
348
+					),
349
+				),
350
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
351
+				// 'help_tour'     => array(
352
+				//     'Event_Editor_Help_Tour',
353
+				// ),
354
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
355
+				'require_nonce' => false,
356
+			),
357
+			'edit'                   => array(
358
+				'nav'           => array(
359
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
360
+					'order'      => 5,
361
+					'persistent' => false,
362
+					'url'        => isset($this->_req_data['post'])
363
+						? EE_Admin_Page::add_query_args_and_nonce(
364
+							array('post' => $this->_req_data['post'], 'action' => 'edit'),
365
+							$this->_current_page_view_url
366
+						)
367
+						: $this->_admin_base_url,
368
+				),
369
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
370
+				'help_tabs'     => array(
371
+					'event_editor_help_tab'                            => array(
372
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
373
+						'filename' => 'event_editor',
374
+					),
375
+					'event_editor_title_richtexteditor_help_tab'       => array(
376
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
377
+						'filename' => 'event_editor_title_richtexteditor',
378
+					),
379
+					'event_editor_venue_details_help_tab'              => array(
380
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
381
+						'filename' => 'event_editor_venue_details',
382
+					),
383
+					'event_editor_event_datetimes_help_tab'            => array(
384
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
385
+						'filename' => 'event_editor_event_datetimes',
386
+					),
387
+					'event_editor_event_tickets_help_tab'              => array(
388
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
389
+						'filename' => 'event_editor_event_tickets',
390
+					),
391
+					'event_editor_event_registration_options_help_tab' => array(
392
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
393
+						'filename' => 'event_editor_event_registration_options',
394
+					),
395
+					'event_editor_tags_categories_help_tab'            => array(
396
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
397
+						'filename' => 'event_editor_tags_categories',
398
+					),
399
+					'event_editor_questions_registrants_help_tab'      => array(
400
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
401
+						'filename' => 'event_editor_questions_registrants',
402
+					),
403
+					'event_editor_save_new_event_help_tab'             => array(
404
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
405
+						'filename' => 'event_editor_save_new_event',
406
+					),
407
+					'event_editor_other_help_tab'                      => array(
408
+						'title'    => esc_html__('Event Other', 'event_espresso'),
409
+						'filename' => 'event_editor_other',
410
+					),
411
+				),
412
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
413
+				'require_nonce' => false,
414
+			),
415
+			'default_event_settings' => array(
416
+				'nav'           => array(
417
+					'label' => esc_html__('Default Settings', 'event_espresso'),
418
+					'order' => 40,
419
+				),
420
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
421
+				'labels'        => array(
422
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
423
+				),
424
+				'help_tabs'     => array(
425
+					'default_settings_help_tab'        => array(
426
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
427
+						'filename' => 'events_default_settings',
428
+					),
429
+					'default_settings_status_help_tab' => array(
430
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
431
+						'filename' => 'events_default_settings_status',
432
+					),
433
+					'default_maximum_tickets_help_tab' => array(
434
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
435
+						'filename' => 'events_default_settings_max_tickets',
436
+					),
437
+				),
438
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
439
+				// 'help_tour'     => array('Event_Default_Settings_Help_Tour'),
440
+				'require_nonce' => false,
441
+			),
442
+			// template settings
443
+			'template_settings'      => array(
444
+				'nav'           => array(
445
+					'label' => esc_html__('Templates', 'event_espresso'),
446
+					'order' => 30,
447
+				),
448
+				'metaboxes'     => $this->_default_espresso_metaboxes,
449
+				'help_tabs'     => array(
450
+					'general_settings_templates_help_tab' => array(
451
+						'title'    => esc_html__('Templates', 'event_espresso'),
452
+						'filename' => 'general_settings_templates',
453
+					),
454
+				),
455
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
456
+				// 'help_tour'     => array('Templates_Help_Tour'),
457
+				'require_nonce' => false,
458
+			),
459
+			// event category stuff
460
+			'add_category'           => array(
461
+				'nav'           => array(
462
+					'label'      => esc_html__('Add Category', 'event_espresso'),
463
+					'order'      => 15,
464
+					'persistent' => false,
465
+				),
466
+				'help_tabs'     => array(
467
+					'add_category_help_tab' => array(
468
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
469
+						'filename' => 'events_add_category',
470
+					),
471
+				),
472
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
473
+				// 'help_tour'     => array('Event_Add_Category_Help_Tour'),
474
+				'metaboxes'     => array('_publish_post_box'),
475
+				'require_nonce' => false,
476
+			),
477
+			'edit_category'          => array(
478
+				'nav'           => array(
479
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
480
+					'order'      => 15,
481
+					'persistent' => false,
482
+					'url'        => isset($this->_req_data['EVT_CAT_ID'])
483
+						? add_query_arg(
484
+							array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
485
+							$this->_current_page_view_url
486
+						)
487
+						: $this->_admin_base_url,
488
+				),
489
+				'help_tabs'     => array(
490
+					'edit_category_help_tab' => array(
491
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
492
+						'filename' => 'events_edit_category',
493
+					),
494
+				),
495
+				/*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
496
+				'metaboxes'     => array('_publish_post_box'),
497
+				'require_nonce' => false,
498
+			),
499
+			'category_list'          => array(
500
+				'nav'           => array(
501
+					'label' => esc_html__('Categories', 'event_espresso'),
502
+					'order' => 20,
503
+				),
504
+				'list_table'    => 'Event_Categories_Admin_List_Table',
505
+				'help_tabs'     => array(
506
+					'events_categories_help_tab'                       => array(
507
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
508
+						'filename' => 'events_categories',
509
+					),
510
+					'events_categories_table_column_headings_help_tab' => array(
511
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
512
+						'filename' => 'events_categories_table_column_headings',
513
+					),
514
+					'events_categories_view_help_tab'                  => array(
515
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
516
+						'filename' => 'events_categories_views',
517
+					),
518
+					'events_categories_other_help_tab'                 => array(
519
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
520
+						'filename' => 'events_categories_other',
521
+					),
522
+				),
523
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
524
+				// 'help_tour'     => array(
525
+				//     'Event_Categories_Help_Tour',
526
+				// ),
527
+				'metaboxes'     => $this->_default_espresso_metaboxes,
528
+				'require_nonce' => false,
529
+			),
530
+			'preview_deletion'           => array(
531
+				'nav'           => array(
532
+					'label'      => esc_html__('Preview Deletion', 'event_espresso'),
533
+					'order'      => 15,
534
+					'persistent' => false,
535
+					'url'        => '',
536
+				),
537
+				'require_nonce' => false
538
+			)
539
+		);
540
+	}
541
+
542
+
543
+	/**
544
+	 * Used to register any global screen options if necessary for every route in this admin page group.
545
+	 */
546
+	protected function _add_screen_options()
547
+	{
548
+	}
549
+
550
+
551
+	/**
552
+	 * Implementing the screen options for the 'default' route.
553
+	 */
554
+	protected function _add_screen_options_default()
555
+	{
556
+		$this->_per_page_screen_option();
557
+	}
558
+
559
+
560
+	/**
561
+	 * Implementing screen options for the category list route.
562
+	 */
563
+	protected function _add_screen_options_category_list()
564
+	{
565
+		$page_title = $this->_admin_page_title;
566
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
567
+		$this->_per_page_screen_option();
568
+		$this->_admin_page_title = $page_title;
569
+	}
570
+
571
+
572
+	/**
573
+	 * Used to register any global feature pointers for the admin page group.
574
+	 */
575
+	protected function _add_feature_pointers()
576
+	{
577
+	}
578
+
579
+
580
+	/**
581
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
582
+	 */
583
+	public function load_scripts_styles()
584
+	{
585
+		wp_register_style(
586
+			'events-admin-css',
587
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
588
+			array(),
589
+			EVENT_ESPRESSO_VERSION
590
+		);
591
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
592
+		wp_enqueue_style('events-admin-css');
593
+		wp_enqueue_style('ee-cat-admin');
594
+		// todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
595
+		// registers for all views
596
+		// scripts
597
+		wp_register_script(
598
+			'event_editor_js',
599
+			EVENTS_ASSETS_URL . 'event_editor.js',
600
+			array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
601
+			EVENT_ESPRESSO_VERSION,
602
+			true
603
+		);
604
+	}
605
+
606
+
607
+	/**
608
+	 * Enqueuing scripts and styles specific to this view
609
+	 */
610
+	public function load_scripts_styles_create_new()
611
+	{
612
+		$this->load_scripts_styles_edit();
613
+	}
614
+
615
+
616
+	/**
617
+	 * Enqueuing scripts and styles specific to this view
618
+	 */
619
+	public function load_scripts_styles_edit()
620
+	{
621
+		// styles
622
+		wp_enqueue_style('espresso-ui-theme');
623
+		wp_register_style(
624
+			'event-editor-css',
625
+			EVENTS_ASSETS_URL . 'event-editor.css',
626
+			array('ee-admin-css'),
627
+			EVENT_ESPRESSO_VERSION
628
+		);
629
+		wp_enqueue_style('event-editor-css');
630
+		// scripts
631
+		wp_register_script(
632
+			'event-datetime-metabox',
633
+			EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
634
+			array('event_editor_js', 'ee-datepicker'),
635
+			EVENT_ESPRESSO_VERSION
636
+		);
637
+		wp_enqueue_script('event-datetime-metabox');
638
+	}
639
+
640
+
641
+	/**
642
+	 * Populating the _views property for the category list table view.
643
+	 */
644
+	protected function _set_list_table_views_category_list()
645
+	{
646
+		$this->_views = array(
647
+			'all' => array(
648
+				'slug'        => 'all',
649
+				'label'       => esc_html__('All', 'event_espresso'),
650
+				'count'       => 0,
651
+				'bulk_action' => array(
652
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
653
+				),
654
+			),
655
+		);
656
+	}
657
+
658
+
659
+	/**
660
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
661
+	 */
662
+	public function admin_init()
663
+	{
664
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
665
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
666
+			'event_espresso'
667
+		);
668
+	}
669
+
670
+
671
+	/**
672
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
673
+	 * group.
674
+	 */
675
+	public function admin_notices()
676
+	{
677
+	}
678
+
679
+
680
+	/**
681
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
682
+	 * this admin page group.
683
+	 */
684
+	public function admin_footer_scripts()
685
+	{
686
+	}
687
+
688
+
689
+	/**
690
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
691
+	 * warning (via EE_Error::add_error());
692
+	 *
693
+	 * @param  EE_Event $event Event object
694
+	 * @param string    $req_type
695
+	 * @return void
696
+	 * @throws EE_Error
697
+	 * @access public
698
+	 */
699
+	public function verify_event_edit($event = null, $req_type = '')
700
+	{
701
+		// don't need to do this when processing
702
+		if (! empty($req_type)) {
703
+			return;
704
+		}
705
+		// no event?
706
+		if (empty($event)) {
707
+			// set event
708
+			$event = $this->_cpt_model_obj;
709
+		}
710
+		// STILL no event?
711
+		if (! $event instanceof EE_Event) {
712
+			return;
713
+		}
714
+		$orig_status = $event->status();
715
+		// first check if event is active.
716
+		if ($orig_status === EEM_Event::cancelled
717
+			|| $orig_status === EEM_Event::postponed
718
+			|| $event->is_expired()
719
+			|| $event->is_inactive()
720
+		) {
721
+			return;
722
+		}
723
+		// made it here so it IS active... next check that any of the tickets are sold.
724
+		if ($event->is_sold_out(true)) {
725
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
726
+				EE_Error::add_attention(
727
+					sprintf(
728
+						esc_html__(
729
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
730
+							'event_espresso'
731
+						),
732
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
733
+					)
734
+				);
735
+			}
736
+			return;
737
+		} elseif ($orig_status === EEM_Event::sold_out) {
738
+			EE_Error::add_attention(
739
+				sprintf(
740
+					esc_html__(
741
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
742
+						'event_espresso'
743
+					),
744
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
745
+				)
746
+			);
747
+		}
748
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
749
+		if (! $event->tickets_on_sale()) {
750
+			return;
751
+		}
752
+		// made it here so show warning
753
+		$this->_edit_event_warning();
754
+	}
755
+
756
+
757
+	/**
758
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
759
+	 * When needed, hook this into a EE_Error::add_error() notice.
760
+	 *
761
+	 * @access protected
762
+	 * @return void
763
+	 */
764
+	protected function _edit_event_warning()
765
+	{
766
+		// we don't want to add warnings during these requests
767
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
768
+			return;
769
+		}
770
+		EE_Error::add_attention(
771
+			sprintf(
772
+				esc_html__(
773
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
774
+					'event_espresso'
775
+				),
776
+				'<a class="espresso-help-tab-lnk">',
777
+				'</a>'
778
+			)
779
+		);
780
+	}
781
+
782
+
783
+	/**
784
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
785
+	 * Otherwise, do the normal logic
786
+	 *
787
+	 * @return string
788
+	 * @throws \EE_Error
789
+	 */
790
+	protected function _create_new_cpt_item()
791
+	{
792
+		$has_timezone_string = get_option('timezone_string');
793
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
794
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
795
+			EE_Error::add_attention(
796
+				sprintf(
797
+					__(
798
+						'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
799
+						'event_espresso'
800
+					),
801
+					'<br>',
802
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
803
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
804
+					. '</select>',
805
+					'<button class="button button-secondary timezone-submit">',
806
+					'</button><span class="spinner"></span>'
807
+				),
808
+				__FILE__,
809
+				__FUNCTION__,
810
+				__LINE__
811
+			);
812
+		}
813
+		return parent::_create_new_cpt_item();
814
+	}
815
+
816
+
817
+	/**
818
+	 * Sets the _views property for the default route in this admin page group.
819
+	 */
820
+	protected function _set_list_table_views_default()
821
+	{
822
+		$this->_views = array(
823
+			'all'   => array(
824
+				'slug'        => 'all',
825
+				'label'       => esc_html__('View All Events', 'event_espresso'),
826
+				'count'       => 0,
827
+				'bulk_action' => array(
828
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
829
+				),
830
+			),
831
+			'draft' => array(
832
+				'slug'        => 'draft',
833
+				'label'       => esc_html__('Draft', 'event_espresso'),
834
+				'count'       => 0,
835
+				'bulk_action' => array(
836
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
837
+				),
838
+			),
839
+		);
840
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
841
+			$this->_views['trash'] = array(
842
+				'slug'        => 'trash',
843
+				'label'       => esc_html__('Trash', 'event_espresso'),
844
+				'count'       => 0,
845
+				'bulk_action' => array(
846
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
847
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
848
+				),
849
+			);
850
+		}
851
+	}
852
+
853
+
854
+	/**
855
+	 * Provides the legend item array for the default list table view.
856
+	 *
857
+	 * @return array
858
+	 */
859
+	protected function _event_legend_items()
860
+	{
861
+		$items = array(
862
+			'view_details'   => array(
863
+				'class' => 'dashicons dashicons-search',
864
+				'desc'  => esc_html__('View Event', 'event_espresso'),
865
+			),
866
+			'edit_event'     => array(
867
+				'class' => 'ee-icon ee-icon-calendar-edit',
868
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
869
+			),
870
+			'view_attendees' => array(
871
+				'class' => 'dashicons dashicons-groups',
872
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
873
+			),
874
+		);
875
+		$items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
876
+		$statuses = array(
877
+			'sold_out_status'  => array(
878
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
879
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
880
+			),
881
+			'active_status'    => array(
882
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
883
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
884
+			),
885
+			'upcoming_status'  => array(
886
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
887
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
888
+			),
889
+			'postponed_status' => array(
890
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
891
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
892
+			),
893
+			'cancelled_status' => array(
894
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
895
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
896
+			),
897
+			'expired_status'   => array(
898
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
899
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
900
+			),
901
+			'inactive_status'  => array(
902
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
903
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
904
+			),
905
+		);
906
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
907
+		return array_merge($items, $statuses);
908
+	}
909
+
910
+
911
+	/**
912
+	 * @return EEM_Event
913
+	 */
914
+	private function _event_model()
915
+	{
916
+		if (! $this->_event_model instanceof EEM_Event) {
917
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
918
+		}
919
+		return $this->_event_model;
920
+	}
921
+
922
+
923
+	/**
924
+	 * Adds extra buttons to the WP CPT permalink field row.
925
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
926
+	 *
927
+	 * @param  string $return    the current html
928
+	 * @param  int    $id        the post id for the page
929
+	 * @param  string $new_title What the title is
930
+	 * @param  string $new_slug  what the slug is
931
+	 * @return string            The new html string for the permalink area
932
+	 */
933
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
934
+	{
935
+		// make sure this is only when editing
936
+		if (! empty($id)) {
937
+			$post = get_post($id);
938
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
939
+					   . esc_html__('Shortcode', 'event_espresso')
940
+					   . '</a> ';
941
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
942
+					   . $post->ID
943
+					   . ']">';
944
+		}
945
+		return $return;
946
+	}
947
+
948
+
949
+	/**
950
+	 * _events_overview_list_table
951
+	 * This contains the logic for showing the events_overview list
952
+	 *
953
+	 * @access protected
954
+	 * @return void
955
+	 * @throws \EE_Error
956
+	 */
957
+	protected function _events_overview_list_table()
958
+	{
959
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
960
+		$this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
961
+			? (array) $this->_template_args['after_list_table']
962
+			: array();
963
+		$this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
964
+				. EEH_Template::get_button_or_link(
965
+					get_post_type_archive_link('espresso_events'),
966
+					esc_html__("View Event Archive Page", "event_espresso"),
967
+					'button'
968
+				);
969
+		$this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
970
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
971
+			'create_new',
972
+			'add',
973
+			array(),
974
+			'add-new-h2'
975
+		);
976
+		$this->display_admin_list_table_page_with_no_sidebar();
977
+	}
978
+
979
+
980
+	/**
981
+	 * this allows for extra misc actions in the default WP publish box
982
+	 *
983
+	 * @return void
984
+	 */
985
+	public function extra_misc_actions_publish_box()
986
+	{
987
+		$this->_generate_publish_box_extra_content();
988
+	}
989
+
990
+
991
+	/**
992
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
993
+	 * saved.
994
+	 * Typically you would use this to save any additional data.
995
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
996
+	 * ALSO very important.  When a post transitions from scheduled to published,
997
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
998
+	 * other meta saves. So MAKE sure that you handle this accordingly.
999
+	 *
1000
+	 * @access protected
1001
+	 * @abstract
1002
+	 * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
1003
+	 * @param  object $post    The post object of the cpt that was saved.
1004
+	 * @return void
1005
+	 * @throws \EE_Error
1006
+	 */
1007
+	protected function _insert_update_cpt_item($post_id, $post)
1008
+	{
1009
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1010
+			// get out we're not processing an event save.
1011
+			return;
1012
+		}
1013
+		$event_values = array(
1014
+			'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
1015
+			'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
1016
+			'EVT_additional_limit'            => min(
1017
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1018
+				! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
1019
+			),
1020
+			'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
1021
+				? $this->_req_data['EVT_default_registration_status']
1022
+				: EE_Registry::instance()->CFG->registration->default_STS_ID,
1023
+			'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
1024
+			'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
1025
+			'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
1026
+				? $this->_req_data['timezone_string'] : null,
1027
+			'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
1028
+				? $this->_req_data['externalURL'] : null,
1029
+			'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
1030
+				? $this->_req_data['event_phone'] : null,
1031
+		);
1032
+		// update event
1033
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1034
+		// get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
1035
+		$get_one_where = array(
1036
+			$this->_event_model()->primary_key_name() => $post_id,
1037
+			'OR'                                      => array(
1038
+				'status'   => $post->post_status,
1039
+				// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1040
+				// but the returned object here has a status of "publish", so use the original post status as well
1041
+				'status*1' => $this->_req_data['original_post_status'],
1042
+			),
1043
+		);
1044
+		$event = $this->_event_model()->get_one(array($get_one_where));
1045
+		// the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1046
+		$event_update_callbacks = apply_filters(
1047
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1048
+			array(
1049
+				array($this, '_default_venue_update'),
1050
+				array($this, '_default_tickets_update'),
1051
+			)
1052
+		);
1053
+		$att_success = true;
1054
+		foreach ($event_update_callbacks as $e_callback) {
1055
+			$_success = is_callable($e_callback)
1056
+				? call_user_func($e_callback, $event, $this->_req_data)
1057
+				: false;
1058
+			// if ANY of these updates fail then we want the appropriate global error message
1059
+			$att_success = ! $att_success ? $att_success : $_success;
1060
+		}
1061
+		// any errors?
1062
+		if ($success && false === $att_success) {
1063
+			EE_Error::add_error(
1064
+				esc_html__(
1065
+					'Event Details saved successfully but something went wrong with saving attachments.',
1066
+					'event_espresso'
1067
+				),
1068
+				__FILE__,
1069
+				__FUNCTION__,
1070
+				__LINE__
1071
+			);
1072
+		} elseif ($success === false) {
1073
+			EE_Error::add_error(
1074
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1075
+				__FILE__,
1076
+				__FUNCTION__,
1077
+				__LINE__
1078
+			);
1079
+		}
1080
+	}
1081
+
1082
+
1083
+	/**
1084
+	 * @see parent::restore_item()
1085
+	 * @param int $post_id
1086
+	 * @param int $revision_id
1087
+	 */
1088
+	protected function _restore_cpt_item($post_id, $revision_id)
1089
+	{
1090
+		// copy existing event meta to new post
1091
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1092
+		if ($post_evt instanceof EE_Event) {
1093
+			// meta revision restore
1094
+			$post_evt->restore_revision($revision_id);
1095
+			// related objs restore
1096
+			$post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1097
+		}
1098
+	}
1099
+
1100
+
1101
+	/**
1102
+	 * Attach the venue to the Event
1103
+	 *
1104
+	 * @param  \EE_Event $evtobj Event Object to add the venue to
1105
+	 * @param  array     $data   The request data from the form
1106
+	 * @return bool           Success or fail.
1107
+	 */
1108
+	protected function _default_venue_update(\EE_Event $evtobj, $data)
1109
+	{
1110
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1111
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1112
+		$rows_affected = null;
1113
+		$venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1114
+		// very important.  If we don't have a venue name...
1115
+		// then we'll get out because not necessary to create empty venue
1116
+		if (empty($data['venue_title'])) {
1117
+			return false;
1118
+		}
1119
+		$venue_array = array(
1120
+			'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1121
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1122
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1123
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1124
+			'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1125
+				: null,
1126
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1127
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1128
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1129
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1130
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1131
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1132
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1133
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1134
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1135
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1136
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1137
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1138
+			'status'              => 'publish',
1139
+		);
1140
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1141
+		if (! empty($venue_id)) {
1142
+			$update_where = array($venue_model->primary_key_name() => $venue_id);
1143
+			$rows_affected = $venue_model->update($venue_array, array($update_where));
1144
+			// we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1145
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1146
+			return $rows_affected > 0 ? true : false;
1147
+		} else {
1148
+			// we insert the venue
1149
+			$venue_id = $venue_model->insert($venue_array);
1150
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1151
+			return ! empty($venue_id) ? true : false;
1152
+		}
1153
+		// when we have the ancestor come in it's already been handled by the revision save.
1154
+	}
1155
+
1156
+
1157
+	/**
1158
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1159
+	 *
1160
+	 * @param  EE_Event $evtobj The Event object we're attaching data to
1161
+	 * @param  array    $data   The request data from the form
1162
+	 * @return array
1163
+	 */
1164
+	protected function _default_tickets_update(EE_Event $evtobj, $data)
1165
+	{
1166
+		$success = true;
1167
+		$saved_dtt = null;
1168
+		$saved_tickets = array();
1169
+		$incoming_date_formats = array('Y-m-d', 'h:i a');
1170
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1171
+			// trim all values to ensure any excess whitespace is removed.
1172
+			$dtt = array_map('trim', $dtt);
1173
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1174
+				: $dtt['DTT_EVT_start'];
1175
+			$datetime_values = array(
1176
+				'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1177
+				'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1178
+				'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1179
+				'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1180
+				'DTT_order'     => $row,
1181
+			);
1182
+			// if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1183
+			if (! empty($dtt['DTT_ID'])) {
1184
+				$DTM = EE_Registry::instance()
1185
+								  ->load_model('Datetime', array($evtobj->get_timezone()))
1186
+								  ->get_one_by_ID($dtt['DTT_ID']);
1187
+				$DTM->set_date_format($incoming_date_formats[0]);
1188
+				$DTM->set_time_format($incoming_date_formats[1]);
1189
+				foreach ($datetime_values as $field => $value) {
1190
+					$DTM->set($field, $value);
1191
+				}
1192
+				// make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1193
+				$saved_dtts[ $DTM->ID() ] = $DTM;
1194
+			} else {
1195
+				$DTM = EE_Registry::instance()->load_class(
1196
+					'Datetime',
1197
+					array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1198
+					false,
1199
+					false
1200
+				);
1201
+				foreach ($datetime_values as $field => $value) {
1202
+					$DTM->set($field, $value);
1203
+				}
1204
+			}
1205
+			$DTM->save();
1206
+			$DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1207
+			// load DTT helper
1208
+			// before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1209
+			if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1210
+				$DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1211
+				$DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1212
+				$DTT->save();
1213
+			}
1214
+			// now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1215
+			$saved_dtt = $DTT;
1216
+			$success = ! $success ? $success : $DTT;
1217
+			// if ANY of these updates fail then we want the appropriate global error message.
1218
+			// //todo this is actually sucky we need a better error message but this is what it is for now.
1219
+		}
1220
+		// no dtts get deleted so we don't do any of that logic here.
1221
+		// update tickets next
1222
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1223
+		foreach ($data['edit_tickets'] as $row => $tkt) {
1224
+			$incoming_date_formats = array('Y-m-d', 'h:i a');
1225
+			$update_prices = false;
1226
+			$ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1227
+				? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1228
+			// trim inputs to ensure any excess whitespace is removed.
1229
+			$tkt = array_map('trim', $tkt);
1230
+			if (empty($tkt['TKT_start_date'])) {
1231
+				// let's use now in the set timezone.
1232
+				$now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1233
+				$tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1234
+			}
1235
+			if (empty($tkt['TKT_end_date'])) {
1236
+				// use the start date of the first datetime
1237
+				$dtt = $evtobj->first_datetime();
1238
+				$tkt['TKT_end_date'] = $dtt->start_date_and_time(
1239
+					$incoming_date_formats[0],
1240
+					$incoming_date_formats[1]
1241
+				);
1242
+			}
1243
+			$TKT_values = array(
1244
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1245
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1246
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1247
+				'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1248
+				'TKT_start_date'  => $tkt['TKT_start_date'],
1249
+				'TKT_end_date'    => $tkt['TKT_end_date'],
1250
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1251
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1252
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1253
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1254
+				'TKT_row'         => $row,
1255
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1256
+				'TKT_price'       => $ticket_price,
1257
+			);
1258
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1259
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1260
+				$TKT_values['TKT_ID'] = 0;
1261
+				$TKT_values['TKT_is_default'] = 0;
1262
+				$TKT_values['TKT_price'] = $ticket_price;
1263
+				$update_prices = true;
1264
+			}
1265
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1266
+			// we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1267
+			// keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1268
+			if (! empty($tkt['TKT_ID'])) {
1269
+				$TKT = EE_Registry::instance()
1270
+								  ->load_model('Ticket', array($evtobj->get_timezone()))
1271
+								  ->get_one_by_ID($tkt['TKT_ID']);
1272
+				if ($TKT instanceof EE_Ticket) {
1273
+					$ticket_sold = $TKT->count_related(
1274
+						'Registration',
1275
+						array(
1276
+							array(
1277
+								'STS_ID' => array(
1278
+									'NOT IN',
1279
+									array(EEM_Registration::status_id_incomplete),
1280
+								),
1281
+							),
1282
+						)
1283
+					) > 0 ? true : false;
1284
+					// let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1285
+					$create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1286
+									  && ! $TKT->get('TKT_deleted');
1287
+					$TKT->set_date_format($incoming_date_formats[0]);
1288
+					$TKT->set_time_format($incoming_date_formats[1]);
1289
+					// set new values
1290
+					foreach ($TKT_values as $field => $value) {
1291
+						if ($field == 'TKT_qty') {
1292
+							$TKT->set_qty($value);
1293
+						} else {
1294
+							$TKT->set($field, $value);
1295
+						}
1296
+					}
1297
+					// if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1298
+					if ($create_new_TKT) {
1299
+						// archive the old ticket first
1300
+						$TKT->set('TKT_deleted', 1);
1301
+						$TKT->save();
1302
+						// make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1303
+						$saved_tickets[ $TKT->ID() ] = $TKT;
1304
+						// create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1305
+						$TKT = clone $TKT;
1306
+						$TKT->set('TKT_ID', 0);
1307
+						$TKT->set('TKT_deleted', 0);
1308
+						$TKT->set('TKT_price', $ticket_price);
1309
+						$TKT->set('TKT_sold', 0);
1310
+						// now we need to make sure that $new prices are created as well and attached to new ticket.
1311
+						$update_prices = true;
1312
+					}
1313
+					// make sure price is set if it hasn't been already
1314
+					$TKT->set('TKT_price', $ticket_price);
1315
+				}
1316
+			} else {
1317
+				// no TKT_id so a new TKT
1318
+				$TKT_values['TKT_price'] = $ticket_price;
1319
+				$TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1320
+				if ($TKT instanceof EE_Ticket) {
1321
+					// need to reset values to properly account for the date formats
1322
+					$TKT->set_date_format($incoming_date_formats[0]);
1323
+					$TKT->set_time_format($incoming_date_formats[1]);
1324
+					$TKT->set_timezone($evtobj->get_timezone());
1325
+					// set new values
1326
+					foreach ($TKT_values as $field => $value) {
1327
+						if ($field == 'TKT_qty') {
1328
+							$TKT->set_qty($value);
1329
+						} else {
1330
+							$TKT->set($field, $value);
1331
+						}
1332
+					}
1333
+					$update_prices = true;
1334
+				}
1335
+			}
1336
+			// cap ticket qty by datetime reg limits
1337
+			$TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1338
+			// update ticket.
1339
+			$TKT->save();
1340
+			// before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1341
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1342
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1343
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1344
+				$TKT->save();
1345
+			}
1346
+			// initially let's add the ticket to the dtt
1347
+			$saved_dtt->_add_relation_to($TKT, 'Ticket');
1348
+			$saved_tickets[ $TKT->ID() ] = $TKT;
1349
+			// add prices to ticket
1350
+			$this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1351
+		}
1352
+		// however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1353
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1354
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1355
+		foreach ($tickets_removed as $id) {
1356
+			$id = absint($id);
1357
+			// get the ticket for this id
1358
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1359
+			// need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1360
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
1361
+			foreach ($dtts as $dtt) {
1362
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1363
+			}
1364
+			// need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1365
+			$tkt_to_remove->delete_related_permanently('Price');
1366
+			// finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1367
+			$tkt_to_remove->delete_permanently();
1368
+		}
1369
+		return array($saved_dtt, $saved_tickets);
1370
+	}
1371
+
1372
+
1373
+	/**
1374
+	 * This attaches a list of given prices to a ticket.
1375
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1376
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1377
+	 * price info and prices are automatically "archived" via the ticket.
1378
+	 *
1379
+	 * @access  private
1380
+	 * @param array     $prices     Array of prices from the form.
1381
+	 * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1382
+	 * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1383
+	 * @return  void
1384
+	 */
1385
+	private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1386
+	{
1387
+		foreach ($prices as $row => $prc) {
1388
+			$PRC_values = array(
1389
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1390
+				'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1391
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1392
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1393
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1394
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1395
+				'PRC_order'      => $row,
1396
+			);
1397
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
1398
+				$PRC_values['PRC_ID'] = 0;
1399
+				$PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1400
+			} else {
1401
+				$PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1402
+				// update this price with new values
1403
+				foreach ($PRC_values as $field => $newprc) {
1404
+					$PRC->set($field, $newprc);
1405
+				}
1406
+				$PRC->save();
1407
+			}
1408
+			$ticket->_add_relation_to($PRC, 'Price');
1409
+		}
1410
+	}
1411
+
1412
+
1413
+	/**
1414
+	 * Add in our autosave ajax handlers
1415
+	 *
1416
+	 */
1417
+	protected function _ee_autosave_create_new()
1418
+	{
1419
+	}
1420
+
1421
+
1422
+	/**
1423
+	 * More autosave handlers.
1424
+	 */
1425
+	protected function _ee_autosave_edit()
1426
+	{
1427
+		return; // TEMPORARILY EXITING CAUSE THIS IS A TODO
1428
+	}
1429
+
1430
+
1431
+	/**
1432
+	 *    _generate_publish_box_extra_content
1433
+	 */
1434
+	private function _generate_publish_box_extra_content()
1435
+	{
1436
+		// load formatter helper
1437
+		// args for getting related registrations
1438
+		$approved_query_args = array(
1439
+			array(
1440
+				'REG_deleted' => 0,
1441
+				'STS_ID'      => EEM_Registration::status_id_approved,
1442
+			),
1443
+		);
1444
+		$not_approved_query_args = array(
1445
+			array(
1446
+				'REG_deleted' => 0,
1447
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1448
+			),
1449
+		);
1450
+		$pending_payment_query_args = array(
1451
+			array(
1452
+				'REG_deleted' => 0,
1453
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1454
+			),
1455
+		);
1456
+		// publish box
1457
+		$publish_box_extra_args = array(
1458
+			'view_approved_reg_url'        => add_query_arg(
1459
+				array(
1460
+					'action'      => 'default',
1461
+					'event_id'    => $this->_cpt_model_obj->ID(),
1462
+					'_reg_status' => EEM_Registration::status_id_approved,
1463
+				),
1464
+				REG_ADMIN_URL
1465
+			),
1466
+			'view_not_approved_reg_url'    => add_query_arg(
1467
+				array(
1468
+					'action'      => 'default',
1469
+					'event_id'    => $this->_cpt_model_obj->ID(),
1470
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1471
+				),
1472
+				REG_ADMIN_URL
1473
+			),
1474
+			'view_pending_payment_reg_url' => add_query_arg(
1475
+				array(
1476
+					'action'      => 'default',
1477
+					'event_id'    => $this->_cpt_model_obj->ID(),
1478
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1479
+				),
1480
+				REG_ADMIN_URL
1481
+			),
1482
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1483
+				'Registration',
1484
+				$approved_query_args
1485
+			),
1486
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1487
+				'Registration',
1488
+				$not_approved_query_args
1489
+			),
1490
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1491
+				'Registration',
1492
+				$pending_payment_query_args
1493
+			),
1494
+			'misc_pub_section_class'       => apply_filters(
1495
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1496
+				'misc-pub-section'
1497
+			),
1498
+		);
1499
+		ob_start();
1500
+		do_action(
1501
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1502
+			$this->_cpt_model_obj
1503
+		);
1504
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1505
+		// load template
1506
+		EEH_Template::display_template(
1507
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1508
+			$publish_box_extra_args
1509
+		);
1510
+	}
1511
+
1512
+
1513
+	/**
1514
+	 * @return EE_Event
1515
+	 */
1516
+	public function get_event_object()
1517
+	{
1518
+		return $this->_cpt_model_obj;
1519
+	}
1520
+
1521
+
1522
+
1523
+
1524
+	/** METABOXES * */
1525
+	/**
1526
+	 * _register_event_editor_meta_boxes
1527
+	 * add all metaboxes related to the event_editor
1528
+	 *
1529
+	 * @return void
1530
+	 */
1531
+	protected function _register_event_editor_meta_boxes()
1532
+	{
1533
+		$this->verify_cpt_object();
1534
+		add_meta_box(
1535
+			'espresso_event_editor_tickets',
1536
+			esc_html__('Event Datetime & Ticket', 'event_espresso'),
1537
+			array($this, 'ticket_metabox'),
1538
+			$this->page_slug,
1539
+			'normal',
1540
+			'high'
1541
+		);
1542
+		add_meta_box(
1543
+			'espresso_event_editor_event_options',
1544
+			esc_html__('Event Registration Options', 'event_espresso'),
1545
+			array($this, 'registration_options_meta_box'),
1546
+			$this->page_slug,
1547
+			'side',
1548
+			'default'
1549
+		);
1550
+		// NOTE: if you're looking for other metaboxes in here,
1551
+		// where a metabox has a related management page in the admin
1552
+		// you will find it setup in the related management page's "_Hooks" file.
1553
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1554
+	}
1555
+
1556
+
1557
+	/**
1558
+	 * @throws DomainException
1559
+	 * @throws EE_Error
1560
+	 */
1561
+	public function ticket_metabox()
1562
+	{
1563
+		$existing_datetime_ids = $existing_ticket_ids = array();
1564
+		// defaults for template args
1565
+		$template_args = array(
1566
+			'existing_datetime_ids'    => '',
1567
+			'event_datetime_help_link' => '',
1568
+			'ticket_options_help_link' => '',
1569
+			'time'                     => null,
1570
+			'ticket_rows'              => '',
1571
+			'existing_ticket_ids'      => '',
1572
+			'total_ticket_rows'        => 1,
1573
+			'ticket_js_structure'      => '',
1574
+			'trash_icon'               => 'ee-lock-icon',
1575
+			'disabled'                 => '',
1576
+		);
1577
+		$event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1578
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1579
+		/**
1580
+		 * 1. Start with retrieving Datetimes
1581
+		 * 2. Fore each datetime get related tickets
1582
+		 * 3. For each ticket get related prices
1583
+		 */
1584
+		$times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1585
+		/** @type EE_Datetime $first_datetime */
1586
+		$first_datetime = reset($times);
1587
+		// do we get related tickets?
1588
+		if ($first_datetime instanceof EE_Datetime
1589
+			&& $first_datetime->ID() !== 0
1590
+		) {
1591
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1592
+			$template_args['time'] = $first_datetime;
1593
+			$related_tickets = $first_datetime->tickets(
1594
+				array(
1595
+					array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1596
+					'default_where_conditions' => 'none',
1597
+				)
1598
+			);
1599
+			if (! empty($related_tickets)) {
1600
+				$template_args['total_ticket_rows'] = count($related_tickets);
1601
+				$row = 0;
1602
+				foreach ($related_tickets as $ticket) {
1603
+					$existing_ticket_ids[] = $ticket->get('TKT_ID');
1604
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1605
+					$row++;
1606
+				}
1607
+			} else {
1608
+				$template_args['total_ticket_rows'] = 1;
1609
+				/** @type EE_Ticket $ticket */
1610
+				$ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1611
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1612
+			}
1613
+		} else {
1614
+			$template_args['time'] = $times[0];
1615
+			/** @type EE_Ticket $ticket */
1616
+			$ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1617
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1618
+			// NOTE: we're just sending the first default row
1619
+			// (decaf can't manage default tickets so this should be sufficient);
1620
+		}
1621
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1622
+			'event_editor_event_datetimes_help_tab'
1623
+		);
1624
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1625
+		$template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1626
+		$template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1627
+		$template_args['ticket_js_structure'] = $this->_get_ticket_row(
1628
+			EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1629
+			true
1630
+		);
1631
+		$template = apply_filters(
1632
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1633
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1634
+		);
1635
+		EEH_Template::display_template($template, $template_args);
1636
+	}
1637
+
1638
+
1639
+	/**
1640
+	 * Setup an individual ticket form for the decaf event editor page
1641
+	 *
1642
+	 * @access private
1643
+	 * @param  EE_Ticket $ticket   the ticket object
1644
+	 * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1645
+	 * @param int        $row
1646
+	 * @return string generated html for the ticket row.
1647
+	 */
1648
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1649
+	{
1650
+		$template_args = array(
1651
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1652
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1653
+				: '',
1654
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1655
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1656
+			'TKT_name'            => $ticket->get('TKT_name'),
1657
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1658
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1659
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1660
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1661
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1662
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1663
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1664
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1665
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1666
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1667
+				: ' disabled=disabled',
1668
+		);
1669
+		$price = $ticket->ID() !== 0
1670
+			? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1671
+			: EE_Registry::instance()->load_model('Price')->create_default_object();
1672
+		$price_args = array(
1673
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1674
+			'PRC_amount'            => $price->get('PRC_amount'),
1675
+			'PRT_ID'                => $price->get('PRT_ID'),
1676
+			'PRC_ID'                => $price->get('PRC_ID'),
1677
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1678
+		);
1679
+		// make sure we have default start and end dates if skeleton
1680
+		// handle rows that should NOT be empty
1681
+		if (empty($template_args['TKT_start_date'])) {
1682
+			// if empty then the start date will be now.
1683
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1684
+		}
1685
+		if (empty($template_args['TKT_end_date'])) {
1686
+			// get the earliest datetime (if present);
1687
+			$earliest_dtt = $this->_cpt_model_obj->ID() > 0
1688
+				? $this->_cpt_model_obj->get_first_related(
1689
+					'Datetime',
1690
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1691
+				)
1692
+				: null;
1693
+			if (! empty($earliest_dtt)) {
1694
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1695
+			} else {
1696
+				$template_args['TKT_end_date'] = date(
1697
+					'Y-m-d h:i a',
1698
+					mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1699
+				);
1700
+			}
1701
+		}
1702
+		$template_args = array_merge($template_args, $price_args);
1703
+		$template = apply_filters(
1704
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1705
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1706
+			$ticket
1707
+		);
1708
+		return EEH_Template::display_template($template, $template_args, true);
1709
+	}
1710
+
1711
+
1712
+	/**
1713
+	 * @throws DomainException
1714
+	 */
1715
+	public function registration_options_meta_box()
1716
+	{
1717
+		$yes_no_values = array(
1718
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1719
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1720
+		);
1721
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1722
+			array(
1723
+				EEM_Registration::status_id_cancelled,
1724
+				EEM_Registration::status_id_declined,
1725
+				EEM_Registration::status_id_incomplete,
1726
+			),
1727
+			true
1728
+		);
1729
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1730
+		$template_args['_event'] = $this->_cpt_model_obj;
1731
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1732
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1733
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1734
+			'default_reg_status',
1735
+			$default_reg_status_values,
1736
+			$this->_cpt_model_obj->default_registration_status()
1737
+		);
1738
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
1739
+			'display_desc',
1740
+			$yes_no_values,
1741
+			$this->_cpt_model_obj->display_description()
1742
+		);
1743
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1744
+			'display_ticket_selector',
1745
+			$yes_no_values,
1746
+			$this->_cpt_model_obj->display_ticket_selector(),
1747
+			'',
1748
+			'',
1749
+			false
1750
+		);
1751
+		$template_args['additional_registration_options'] = apply_filters(
1752
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1753
+			'',
1754
+			$template_args,
1755
+			$yes_no_values,
1756
+			$default_reg_status_values
1757
+		);
1758
+		EEH_Template::display_template(
1759
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1760
+			$template_args
1761
+		);
1762
+	}
1763
+
1764
+
1765
+	/**
1766
+	 * _get_events()
1767
+	 * This method simply returns all the events (for the given _view and paging)
1768
+	 *
1769
+	 * @access public
1770
+	 * @param int  $per_page     count of items per page (20 default);
1771
+	 * @param int  $current_page what is the current page being viewed.
1772
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1773
+	 *                           If FALSE then we return an array of event objects
1774
+	 *                           that match the given _view and paging parameters.
1775
+	 * @return array an array of event objects.
1776
+	 */
1777
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1778
+	{
1779
+		$EEME = $this->_event_model();
1780
+		$offset = ($current_page - 1) * $per_page;
1781
+		$limit = $count ? null : $offset . ',' . $per_page;
1782
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1783
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1784
+		if (isset($this->_req_data['month_range'])) {
1785
+			$pieces = explode(' ', $this->_req_data['month_range'], 3);
1786
+			// simulate the FIRST day of the month, that fixes issues for months like February
1787
+			// where PHP doesn't know what to assume for date.
1788
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1789
+			$month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1790
+			$year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1791
+		}
1792
+		$where = array();
1793
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1794
+		// determine what post_status our condition will have for the query.
1795
+		switch ($status) {
1796
+			case 'month':
1797
+			case 'today':
1798
+			case null:
1799
+			case 'all':
1800
+				break;
1801
+			case 'draft':
1802
+				$where['status'] = array('IN', array('draft', 'auto-draft'));
1803
+				break;
1804
+			default:
1805
+				$where['status'] = $status;
1806
+		}
1807
+		// categories?
1808
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1809
+			? $this->_req_data['EVT_CAT'] : null;
1810
+		if (! empty($category)) {
1811
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1812
+			$where['Term_Taxonomy.term_id'] = $category;
1813
+		}
1814
+		// date where conditions
1815
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1816
+		if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1817
+			$DateTime = new DateTime(
1818
+				$year_r . '-' . $month_r . '-01 00:00:00',
1819
+				new DateTimeZone('UTC')
1820
+			);
1821
+			$start = $DateTime->getTimestamp();
1822
+			// set the datetime to be the end of the month
1823
+			$DateTime->setDate(
1824
+				$year_r,
1825
+				$month_r,
1826
+				$DateTime->format('t')
1827
+			)->setTime(23, 59, 59);
1828
+			$end = $DateTime->getTimestamp();
1829
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1830
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1831
+			$DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1832
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1833
+			$end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1834
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1835
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1836
+			$now = date('Y-m-01');
1837
+			$DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1838
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1839
+			$end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1840
+							->setTime(23, 59, 59)
1841
+							->format(implode(' ', $start_formats));
1842
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1843
+		}
1844
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1845
+			$where['EVT_wp_user'] = get_current_user_id();
1846
+		} else {
1847
+			if (! isset($where['status'])) {
1848
+				if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1849
+					$where['OR'] = array(
1850
+						'status*restrict_private' => array('!=', 'private'),
1851
+						'AND'                     => array(
1852
+							'status*inclusive' => array('=', 'private'),
1853
+							'EVT_wp_user'      => get_current_user_id(),
1854
+						),
1855
+					);
1856
+				}
1857
+			}
1858
+		}
1859
+		if (isset($this->_req_data['EVT_wp_user'])) {
1860
+			if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1861
+				&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1862
+			) {
1863
+				$where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1864
+			}
1865
+		}
1866
+		// search query handling
1867
+		if (isset($this->_req_data['s'])) {
1868
+			$search_string = '%' . $this->_req_data['s'] . '%';
1869
+			$where['OR'] = array(
1870
+				'EVT_name'       => array('LIKE', $search_string),
1871
+				'EVT_desc'       => array('LIKE', $search_string),
1872
+				'EVT_short_desc' => array('LIKE', $search_string),
1873
+			);
1874
+		}
1875
+		// filter events by venue.
1876
+		if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) {
1877
+			$where['Venue.VNU_ID'] = absint($this->_req_data['venue']);
1878
+		}
1879
+		$where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1880
+		$query_params = apply_filters(
1881
+			'FHEE__Events_Admin_Page__get_events__query_params',
1882
+			array(
1883
+				$where,
1884
+				'limit'    => $limit,
1885
+				'order_by' => $orderby,
1886
+				'order'    => $order,
1887
+				'group_by' => 'EVT_ID',
1888
+			),
1889
+			$this->_req_data
1890
+		);
1891
+
1892
+		// let's first check if we have special requests coming in.
1893
+		if (isset($this->_req_data['active_status'])) {
1894
+			switch ($this->_req_data['active_status']) {
1895
+				case 'upcoming':
1896
+					return $EEME->get_upcoming_events($query_params, $count);
1897
+					break;
1898
+				case 'expired':
1899
+					return $EEME->get_expired_events($query_params, $count);
1900
+					break;
1901
+				case 'active':
1902
+					return $EEME->get_active_events($query_params, $count);
1903
+					break;
1904
+				case 'inactive':
1905
+					return $EEME->get_inactive_events($query_params, $count);
1906
+					break;
1907
+			}
1908
+		}
1909
+
1910
+		$events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1911
+		return $events;
1912
+	}
1913
+
1914
+
1915
+	/**
1916
+	 * handling for WordPress CPT actions (trash, restore, delete)
1917
+	 *
1918
+	 * @param string $post_id
1919
+	 */
1920
+	public function trash_cpt_item($post_id)
1921
+	{
1922
+		$this->_req_data['EVT_ID'] = $post_id;
1923
+		$this->_trash_or_restore_event('trash', false);
1924
+	}
1925
+
1926
+
1927
+	/**
1928
+	 * @param string $post_id
1929
+	 */
1930
+	public function restore_cpt_item($post_id)
1931
+	{
1932
+		$this->_req_data['EVT_ID'] = $post_id;
1933
+		$this->_trash_or_restore_event('draft', false);
1934
+	}
1935
+
1936
+
1937
+	/**
1938
+	 * @param string $post_id
1939
+	 */
1940
+	public function delete_cpt_item($post_id)
1941
+	{
1942
+		throw new EE_Error(esc_html__('Please contact Event Espresso support with the details of the steps taken to produce this error.', 'event_espresso'));
1943
+		$this->_req_data['EVT_ID'] = $post_id;
1944
+		$this->_delete_event();
1945
+	}
1946
+
1947
+
1948
+	/**
1949
+	 * _trash_or_restore_event
1950
+	 *
1951
+	 * @access protected
1952
+	 * @param  string $event_status
1953
+	 * @param bool    $redirect_after
1954
+	 */
1955
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1956
+	{
1957
+		// determine the event id and set to array.
1958
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1959
+		// loop thru events
1960
+		if ($EVT_ID) {
1961
+			// clean status
1962
+			$event_status = sanitize_key($event_status);
1963
+			// grab status
1964
+			if (! empty($event_status)) {
1965
+				$success = $this->_change_event_status($EVT_ID, $event_status);
1966
+			} else {
1967
+				$success = false;
1968
+				$msg = esc_html__(
1969
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1970
+					'event_espresso'
1971
+				);
1972
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1973
+			}
1974
+		} else {
1975
+			$success = false;
1976
+			$msg = esc_html__(
1977
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1978
+				'event_espresso'
1979
+			);
1980
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1981
+		}
1982
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1983
+		if ($redirect_after) {
1984
+			$this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1985
+		}
1986
+	}
1987
+
1988
+
1989
+	/**
1990
+	 * _trash_or_restore_events
1991
+	 *
1992
+	 * @access protected
1993
+	 * @param  string $event_status
1994
+	 * @return void
1995
+	 */
1996
+	protected function _trash_or_restore_events($event_status = 'trash')
1997
+	{
1998
+		// clean status
1999
+		$event_status = sanitize_key($event_status);
2000
+		// grab status
2001
+		if (! empty($event_status)) {
2002
+			$success = true;
2003
+			// determine the event id and set to array.
2004
+			$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
2005
+			// loop thru events
2006
+			foreach ($EVT_IDs as $EVT_ID) {
2007
+				if ($EVT_ID = absint($EVT_ID)) {
2008
+					$results = $this->_change_event_status($EVT_ID, $event_status);
2009
+					$success = $results !== false ? $success : false;
2010
+				} else {
2011
+					$msg = sprintf(
2012
+						esc_html__(
2013
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2014
+							'event_espresso'
2015
+						),
2016
+						$EVT_ID
2017
+					);
2018
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2019
+					$success = false;
2020
+				}
2021
+			}
2022
+		} else {
2023
+			$success = false;
2024
+			$msg = esc_html__(
2025
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2026
+				'event_espresso'
2027
+			);
2028
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2029
+		}
2030
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2031
+		$success = $success ? 2 : false;
2032
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2033
+		$this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
2034
+	}
2035
+
2036
+
2037
+	/**
2038
+	 * @param  int    $EVT_ID
2039
+	 * @param  string $event_status
2040
+	 * @return bool
2041
+	 */
2042
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2043
+	{
2044
+		// grab event id
2045
+		if (! $EVT_ID) {
2046
+			$msg = esc_html__(
2047
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2048
+				'event_espresso'
2049
+			);
2050
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2051
+			return false;
2052
+		}
2053
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2054
+		// clean status
2055
+		$event_status = sanitize_key($event_status);
2056
+		// grab status
2057
+		if (empty($event_status)) {
2058
+			$msg = esc_html__(
2059
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2060
+				'event_espresso'
2061
+			);
2062
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2063
+			return false;
2064
+		}
2065
+		// was event trashed or restored ?
2066
+		switch ($event_status) {
2067
+			case 'draft':
2068
+				$action = 'restored from the trash';
2069
+				$hook = 'AHEE_event_restored_from_trash';
2070
+				break;
2071
+			case 'trash':
2072
+				$action = 'moved to the trash';
2073
+				$hook = 'AHEE_event_moved_to_trash';
2074
+				break;
2075
+			default:
2076
+				$action = 'updated';
2077
+				$hook = false;
2078
+		}
2079
+		// use class to change status
2080
+		$this->_cpt_model_obj->set_status($event_status);
2081
+		$success = $this->_cpt_model_obj->save();
2082
+		if (! $success) {
2083
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2084
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2085
+			return false;
2086
+		}
2087
+		if ($hook) {
2088
+			do_action($hook);
2089
+		}
2090
+		return true;
2091
+	}
2092
+
2093
+
2094
+	/**
2095
+	 * @param array $event_ids
2096
+	 * @return array
2097
+	 * @since   $VID:$
2098
+	 */
2099
+	private function cleanEventIds(array $event_ids)
2100
+	{
2101
+		return array_map('absint', $event_ids);
2102
+	}
2103
+
2104
+
2105
+	/**
2106
+	 * @return array
2107
+	 * @since   $VID:$
2108
+	 */
2109
+	private function getEventIdsFromRequest()
2110
+	{
2111
+		$event_ids = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : [];
2112
+		$event_ids = is_string($event_ids) ? explode(',', $event_ids) : (array) $event_ids;
2113
+		return $this->cleanEventIds($event_ids);
2114
+	}
2115
+
2116
+
2117
+	/**
2118
+	 * @param bool $preview_delete
2119
+	 * @throws EE_Error
2120
+	 */
2121
+	protected function _delete_event($preview_delete = true)
2122
+	{
2123
+		$this->_delete_events($preview_delete);
2124
+	}
2125
+
2126
+
2127
+	/**
2128
+	 * Gets the tree traversal batch persister.
2129
+	 * @since 4.10.12.p
2130
+	 * @return NodeGroupDao
2131
+	 * @throws InvalidArgumentException
2132
+	 * @throws InvalidDataTypeException
2133
+	 * @throws InvalidInterfaceException
2134
+	 */
2135
+	protected function getModelObjNodeGroupPersister()
2136
+	{
2137
+		if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2138
+			$this->model_obj_node_group_persister = $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2139
+		}
2140
+		return $this->model_obj_node_group_persister;
2141
+	}
2142
+
2143
+
2144
+	/**
2145
+	 * @param bool $preview_delete
2146
+	 * @return void
2147
+	 * @throws EE_Error
2148
+	 */
2149
+	protected function _delete_events($preview_delete = true)
2150
+	{
2151
+		$event_ids = $this->getEventIdsFromRequest();
2152
+		if ($preview_delete) {
2153
+			$this->generateDeletionPreview($event_ids);
2154
+		} else {
2155
+			EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2156
+		}
2157
+	}
2158
+
2159
+
2160
+	/**
2161
+	 * @param array $event_ids
2162
+	 */
2163
+	protected function generateDeletionPreview(array $event_ids)
2164
+	{
2165
+		$event_ids = $this->cleanEventIds($event_ids);
2166
+		// Set a code we can use to reference this deletion task in the batch jobs and preview page.
2167
+		$deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2168
+		$return_url = EE_Admin_Page::add_query_args_and_nonce(
2169
+			[
2170
+				'action' => 'preview_deletion',
2171
+				'deletion_job_code' => $deletion_job_code,
2172
+			],
2173
+			$this->_admin_base_url
2174
+		);
2175
+		EEH_URL::safeRedirectAndExit(
2176
+			EE_Admin_Page::add_query_args_and_nonce(
2177
+				[
2178
+					'page'              => 'espresso_batch',
2179
+					'batch'             => EED_Batch::batch_job,
2180
+					'EVT_IDs'           => $event_ids,
2181
+					'deletion_job_code' => $deletion_job_code,
2182
+					'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2183
+					'return_url'        => urlencode($return_url),
2184
+				],
2185
+				admin_url()
2186
+			)
2187
+		);
2188
+	}
2189
+
2190
+	/**
2191
+	 * Checks for a POST submission
2192
+	 * @since 4.10.12.p
2193
+	 */
2194
+	protected function confirmDeletion()
2195
+	{
2196
+		$deletion_redirect_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2197
+		$deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2198
+	}
2199
+
2200
+	/**
2201
+	 * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2202
+	 * @since 4.10.12.p
2203
+	 * @throws EE_Error
2204
+	 */
2205
+	protected function previewDeletion()
2206
+	{
2207
+		$preview_deletion_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2208
+		$this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2209
+		$this->display_admin_page_with_no_sidebar();
2210
+	}
2211
+
2212
+	/**
2213
+	 * get total number of events
2214
+	 *
2215
+	 * @access public
2216
+	 * @return int
2217
+	 */
2218
+	public function total_events()
2219
+	{
2220
+		$count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2221
+		return $count;
2222
+	}
2223
+
2224
+
2225
+	/**
2226
+	 * get total number of draft events
2227
+	 *
2228
+	 * @access public
2229
+	 * @return int
2230
+	 */
2231
+	public function total_events_draft()
2232
+	{
2233
+		$where = array(
2234
+			'status' => array('IN', array('draft', 'auto-draft')),
2235
+		);
2236
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2237
+		return $count;
2238
+	}
2239
+
2240
+
2241
+	/**
2242
+	 * get total number of trashed events
2243
+	 *
2244
+	 * @access public
2245
+	 * @return int
2246
+	 */
2247
+	public function total_trashed_events()
2248
+	{
2249
+		$where = array(
2250
+			'status' => 'trash',
2251
+		);
2252
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2253
+		return $count;
2254
+	}
2255
+
2256
+
2257
+	/**
2258
+	 *    _default_event_settings
2259
+	 *    This generates the Default Settings Tab
2260
+	 *
2261
+	 * @return void
2262
+	 * @throws EE_Error
2263
+	 */
2264
+	protected function _default_event_settings()
2265
+	{
2266
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2267
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2268
+		$this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2269
+		$this->display_admin_page_with_sidebar();
2270
+	}
2271
+
2272
+
2273
+	/**
2274
+	 * Return the form for event settings.
2275
+	 *
2276
+	 * @return EE_Form_Section_Proper
2277
+	 * @throws EE_Error
2278
+	 */
2279
+	protected function _default_event_settings_form()
2280
+	{
2281
+		$registration_config = EE_Registry::instance()->CFG->registration;
2282
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2283
+			// exclude
2284
+			array(
2285
+				EEM_Registration::status_id_cancelled,
2286
+				EEM_Registration::status_id_declined,
2287
+				EEM_Registration::status_id_incomplete,
2288
+				EEM_Registration::status_id_wait_list,
2289
+			),
2290
+			true
2291
+		);
2292
+		return new EE_Form_Section_Proper(
2293
+			array(
2294
+				'name'            => 'update_default_event_settings',
2295
+				'html_id'         => 'update_default_event_settings',
2296
+				'html_class'      => 'form-table',
2297
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2298
+				'subsections'     => apply_filters(
2299
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2300
+					array(
2301
+						'default_reg_status'  => new EE_Select_Input(
2302
+							$registration_stati_for_selection,
2303
+							array(
2304
+								'default'         => isset($registration_config->default_STS_ID)
2305
+													 && array_key_exists(
2306
+														 $registration_config->default_STS_ID,
2307
+														 $registration_stati_for_selection
2308
+													 )
2309
+									? sanitize_text_field($registration_config->default_STS_ID)
2310
+									: EEM_Registration::status_id_pending_payment,
2311
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2312
+													 . EEH_Template::get_help_tab_link(
2313
+														 'default_settings_status_help_tab'
2314
+													 ),
2315
+								'html_help_text'  => esc_html__(
2316
+									'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2317
+									'event_espresso'
2318
+								),
2319
+							)
2320
+						),
2321
+						'default_max_tickets' => new EE_Integer_Input(
2322
+							array(
2323
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2324
+									? $registration_config->default_maximum_number_of_tickets
2325
+									: EEM_Event::get_default_additional_limit(),
2326
+								'html_label_text' => esc_html__(
2327
+									'Default Maximum Tickets Allowed Per Order:',
2328
+									'event_espresso'
2329
+								)
2330
+													 . EEH_Template::get_help_tab_link(
2331
+														 'default_maximum_tickets_help_tab"'
2332
+													 ),
2333
+								'html_help_text'  => esc_html__(
2334
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2335
+									'event_espresso'
2336
+								),
2337
+							)
2338
+						),
2339
+					)
2340
+				),
2341
+			)
2342
+		);
2343
+	}
2344
+
2345
+
2346
+	/**
2347
+	 * _update_default_event_settings
2348
+	 *
2349
+	 * @access protected
2350
+	 * @return void
2351
+	 * @throws EE_Error
2352
+	 */
2353
+	protected function _update_default_event_settings()
2354
+	{
2355
+		$registration_config = EE_Registry::instance()->CFG->registration;
2356
+		$form = $this->_default_event_settings_form();
2357
+		if ($form->was_submitted()) {
2358
+			$form->receive_form_submission();
2359
+			if ($form->is_valid()) {
2360
+				$valid_data = $form->valid_data();
2361
+				if (isset($valid_data['default_reg_status'])) {
2362
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2363
+				}
2364
+				if (isset($valid_data['default_max_tickets'])) {
2365
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2366
+				}
2367
+				// update because data was valid!
2368
+				EE_Registry::instance()->CFG->update_espresso_config();
2369
+				EE_Error::overwrite_success();
2370
+				EE_Error::add_success(
2371
+					__('Default Event Settings were updated', 'event_espresso')
2372
+				);
2373
+			}
2374
+		}
2375
+		$this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true);
2376
+	}
2377
+
2378
+
2379
+	/*************        Templates        *************/
2380
+	protected function _template_settings()
2381
+	{
2382
+		$this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2383
+		$this->_template_args['preview_img'] = '<img src="'
2384
+											   . EVENTS_ASSETS_URL
2385
+											   . '/images/'
2386
+											   . 'caffeinated_template_features.jpg" alt="'
2387
+											   . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2388
+											   . '" />';
2389
+		$this->_template_args['preview_text'] = '<strong>'
2390
+												. esc_html__(
2391
+													'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2392
+													'event_espresso'
2393
+												) . '</strong>';
2394
+		$this->display_admin_caf_preview_page('template_settings_tab');
2395
+	}
2396
+
2397
+
2398
+	/** Event Category Stuff **/
2399
+	/**
2400
+	 * set the _category property with the category object for the loaded page.
2401
+	 *
2402
+	 * @access private
2403
+	 * @return void
2404
+	 */
2405
+	private function _set_category_object()
2406
+	{
2407
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2408
+			return;
2409
+		} //already have the category object so get out.
2410
+		// set default category object
2411
+		$this->_set_empty_category_object();
2412
+		// only set if we've got an id
2413
+		if (! isset($this->_req_data['EVT_CAT_ID'])) {
2414
+			return;
2415
+		}
2416
+		$category_id = absint($this->_req_data['EVT_CAT_ID']);
2417
+		$term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2418
+		if (! empty($term)) {
2419
+			$this->_category->category_name = $term->name;
2420
+			$this->_category->category_identifier = $term->slug;
2421
+			$this->_category->category_desc = $term->description;
2422
+			$this->_category->id = $term->term_id;
2423
+			$this->_category->parent = $term->parent;
2424
+		}
2425
+	}
2426
+
2427
+
2428
+	/**
2429
+	 * Clears out category properties.
2430
+	 */
2431
+	private function _set_empty_category_object()
2432
+	{
2433
+		$this->_category = new stdClass();
2434
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2435
+		$this->_category->id = $this->_category->parent = 0;
2436
+	}
2437
+
2438
+
2439
+	/**
2440
+	 * @throws EE_Error
2441
+	 */
2442
+	protected function _category_list_table()
2443
+	{
2444
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2445
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2446
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2447
+			'add_category',
2448
+			'add_category',
2449
+			array(),
2450
+			'add-new-h2'
2451
+		);
2452
+		$this->display_admin_list_table_page_with_sidebar();
2453
+	}
2454
+
2455
+
2456
+	/**
2457
+	 * Output category details view.
2458
+	 */
2459
+	protected function _category_details($view)
2460
+	{
2461
+		// load formatter helper
2462
+		// load field generator helper
2463
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
2464
+		$this->_set_add_edit_form_tags($route);
2465
+		$this->_set_category_object();
2466
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
2467
+		$delete_action = 'delete_category';
2468
+		// custom redirect
2469
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2470
+			array('action' => 'category_list'),
2471
+			$this->_admin_base_url
2472
+		);
2473
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2474
+		// take care of contents
2475
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2476
+		$this->display_admin_page_with_sidebar();
2477
+	}
2478
+
2479
+
2480
+	/**
2481
+	 * Output category details content.
2482
+	 */
2483
+	protected function _category_details_content()
2484
+	{
2485
+		$editor_args['category_desc'] = array(
2486
+			'type'          => 'wp_editor',
2487
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2488
+			'class'         => 'my_editor_custom',
2489
+			'wpeditor_args' => array('media_buttons' => false),
2490
+		);
2491
+		$_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2492
+		$all_terms = get_terms(
2493
+			array(EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY),
2494
+			array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2495
+		);
2496
+		// setup category select for term parents.
2497
+		$category_select_values[] = array(
2498
+			'text' => esc_html__('No Parent', 'event_espresso'),
2499
+			'id'   => 0,
2500
+		);
2501
+		foreach ($all_terms as $term) {
2502
+			$category_select_values[] = array(
2503
+				'text' => $term->name,
2504
+				'id'   => $term->term_id,
2505
+			);
2506
+		}
2507
+		$category_select = EEH_Form_Fields::select_input(
2508
+			'category_parent',
2509
+			$category_select_values,
2510
+			$this->_category->parent
2511
+		);
2512
+		$template_args = array(
2513
+			'category'                 => $this->_category,
2514
+			'category_select'          => $category_select,
2515
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2516
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2517
+			'disable'                  => '',
2518
+			'disabled_message'         => false,
2519
+		);
2520
+		$template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2521
+		return EEH_Template::display_template($template, $template_args, true);
2522
+	}
2523
+
2524
+
2525
+	/**
2526
+	 * Handles deleting categories.
2527
+	 */
2528
+	protected function _delete_categories()
2529
+	{
2530
+		$cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2531
+			: (array) $this->_req_data['category_id'];
2532
+		foreach ($cat_ids as $cat_id) {
2533
+			$this->_delete_category($cat_id);
2534
+		}
2535
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2536
+		$query_args = array(
2537
+			'action' => 'category_list',
2538
+		);
2539
+		$this->_redirect_after_action(0, '', '', $query_args);
2540
+	}
2541
+
2542
+
2543
+	/**
2544
+	 * Handles deleting specific category.
2545
+	 *
2546
+	 * @param int $cat_id
2547
+	 */
2548
+	protected function _delete_category($cat_id)
2549
+	{
2550
+		$cat_id = absint($cat_id);
2551
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2552
+	}
2553
+
2554
+
2555
+	/**
2556
+	 * Handles triggering the update or insertion of a new category.
2557
+	 *
2558
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2559
+	 */
2560
+	protected function _insert_or_update_category($new_category)
2561
+	{
2562
+		$cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2563
+		$success = 0; // we already have a success message so lets not send another.
2564
+		if ($cat_id) {
2565
+			$query_args = array(
2566
+				'action'     => 'edit_category',
2567
+				'EVT_CAT_ID' => $cat_id,
2568
+			);
2569
+		} else {
2570
+			$query_args = array('action' => 'add_category');
2571
+		}
2572
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2573
+	}
2574
+
2575
+
2576
+	/**
2577
+	 * Inserts or updates category
2578
+	 *
2579
+	 * @param bool $update (true indicates we're updating a category).
2580
+	 * @return bool|mixed|string
2581
+	 */
2582
+	private function _insert_category($update = false)
2583
+	{
2584
+		$cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2585
+		$category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2586
+		$category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2587
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2588
+		if (empty($category_name)) {
2589
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2590
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2591
+			return false;
2592
+		}
2593
+		$term_args = array(
2594
+			'name'        => $category_name,
2595
+			'description' => $category_desc,
2596
+			'parent'      => $category_parent,
2597
+		);
2598
+		// was the category_identifier input disabled?
2599
+		if (isset($this->_req_data['category_identifier'])) {
2600
+			$term_args['slug'] = $this->_req_data['category_identifier'];
2601
+		}
2602
+		$insert_ids = $update
2603
+			? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2604
+			: wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2605
+		if (! is_array($insert_ids)) {
2606
+			$msg = esc_html__(
2607
+				'An error occurred and the category has not been saved to the database.',
2608
+				'event_espresso'
2609
+			);
2610
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2611
+		} else {
2612
+			$cat_id = $insert_ids['term_id'];
2613
+			$msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2614
+			EE_Error::add_success($msg);
2615
+		}
2616
+		return $cat_id;
2617
+	}
2618
+
2619
+
2620
+	/**
2621
+	 * Gets categories or count of categories matching the arguments in the request.
2622
+	 *
2623
+	 * @param int  $per_page
2624
+	 * @param int  $current_page
2625
+	 * @param bool $count
2626
+	 * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2627
+	 */
2628
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2629
+	{
2630
+		// testing term stuff
2631
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2632
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2633
+		$limit = ($current_page - 1) * $per_page;
2634
+		$where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2635
+		if (isset($this->_req_data['s'])) {
2636
+			$sstr = '%' . $this->_req_data['s'] . '%';
2637
+			$where['OR'] = array(
2638
+				'Term.name'   => array('LIKE', $sstr),
2639
+				'description' => array('LIKE', $sstr),
2640
+			);
2641
+		}
2642
+		$query_params = array(
2643
+			$where,
2644
+			'order_by'   => array($orderby => $order),
2645
+			'limit'      => $limit . ',' . $per_page,
2646
+			'force_join' => array('Term'),
2647
+		);
2648
+		$categories = $count
2649
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2650
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2651
+		return $categories;
2652
+	}
2653
+
2654
+	/* end category stuff */
2655
+	/**************/
2656
+
2657
+
2658
+	/**
2659
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2660
+	 *
2661
+	 * @throws EE_Error
2662
+	 */
2663
+	public function save_timezonestring_setting()
2664
+	{
2665
+		$timezone_string = isset($this->_req_data['timezone_selected'])
2666
+			? $this->_req_data['timezone_selected']
2667
+			: '';
2668
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2669
+			EE_Error::add_error(
2670
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2671
+				__FILE__,
2672
+				__FUNCTION__,
2673
+				__LINE__
2674
+			);
2675
+			$this->_template_args['error'] = true;
2676
+			$this->_return_json();
2677
+		}
2678
+
2679
+		update_option('timezone_string', $timezone_string);
2680
+		EE_Error::add_success(
2681
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2682
+		);
2683
+		$this->_template_args['success'] = true;
2684
+		$this->_return_json(true, array('action' => 'create_new'));
2685
+	}
2686 2686
 }
Please login to merge, or discard this patch.
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -584,11 +584,11 @@  discard block
 block discarded – undo
584 584
     {
585 585
         wp_register_style(
586 586
             'events-admin-css',
587
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
587
+            EVENTS_ASSETS_URL.'events-admin-page.css',
588 588
             array(),
589 589
             EVENT_ESPRESSO_VERSION
590 590
         );
591
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
591
+        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
592 592
         wp_enqueue_style('events-admin-css');
593 593
         wp_enqueue_style('ee-cat-admin');
594 594
         // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
         // scripts
597 597
         wp_register_script(
598 598
             'event_editor_js',
599
-            EVENTS_ASSETS_URL . 'event_editor.js',
599
+            EVENTS_ASSETS_URL.'event_editor.js',
600 600
             array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
601 601
             EVENT_ESPRESSO_VERSION,
602 602
             true
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
         wp_enqueue_style('espresso-ui-theme');
623 623
         wp_register_style(
624 624
             'event-editor-css',
625
-            EVENTS_ASSETS_URL . 'event-editor.css',
625
+            EVENTS_ASSETS_URL.'event-editor.css',
626 626
             array('ee-admin-css'),
627 627
             EVENT_ESPRESSO_VERSION
628 628
         );
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
         // scripts
631 631
         wp_register_script(
632 632
             'event-datetime-metabox',
633
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
633
+            EVENTS_ASSETS_URL.'event-datetime-metabox.js',
634 634
             array('event_editor_js', 'ee-datepicker'),
635 635
             EVENT_ESPRESSO_VERSION
636 636
         );
@@ -699,7 +699,7 @@  discard block
 block discarded – undo
699 699
     public function verify_event_edit($event = null, $req_type = '')
700 700
     {
701 701
         // don't need to do this when processing
702
-        if (! empty($req_type)) {
702
+        if ( ! empty($req_type)) {
703 703
             return;
704 704
         }
705 705
         // no event?
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
             $event = $this->_cpt_model_obj;
709 709
         }
710 710
         // STILL no event?
711
-        if (! $event instanceof EE_Event) {
711
+        if ( ! $event instanceof EE_Event) {
712 712
             return;
713 713
         }
714 714
         $orig_status = $event->status();
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
             );
747 747
         }
748 748
         // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
749
-        if (! $event->tickets_on_sale()) {
749
+        if ( ! $event->tickets_on_sale()) {
750 750
             return;
751 751
         }
752 752
         // made it here so show warning
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
     {
792 792
         $has_timezone_string = get_option('timezone_string');
793 793
         // only nag them about setting their timezone if it's their first event, and they haven't already done it
794
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
794
+        if ( ! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
795 795
             EE_Error::add_attention(
796 796
                 sprintf(
797 797
                     __(
@@ -875,31 +875,31 @@  discard block
 block discarded – undo
875 875
         $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
876 876
         $statuses = array(
877 877
             'sold_out_status'  => array(
878
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
878
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out,
879 879
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
880 880
             ),
881 881
             'active_status'    => array(
882
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
882
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active,
883 883
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
884 884
             ),
885 885
             'upcoming_status'  => array(
886
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
886
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming,
887 887
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
888 888
             ),
889 889
             'postponed_status' => array(
890
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
890
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed,
891 891
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
892 892
             ),
893 893
             'cancelled_status' => array(
894
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
894
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled,
895 895
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
896 896
             ),
897 897
             'expired_status'   => array(
898
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
898
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired,
899 899
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
900 900
             ),
901 901
             'inactive_status'  => array(
902
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
902
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive,
903 903
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
904 904
             ),
905 905
         );
@@ -913,7 +913,7 @@  discard block
 block discarded – undo
913 913
      */
914 914
     private function _event_model()
915 915
     {
916
-        if (! $this->_event_model instanceof EEM_Event) {
916
+        if ( ! $this->_event_model instanceof EEM_Event) {
917 917
             $this->_event_model = EE_Registry::instance()->load_model('Event');
918 918
         }
919 919
         return $this->_event_model;
@@ -933,7 +933,7 @@  discard block
 block discarded – undo
933 933
     public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
934 934
     {
935 935
         // make sure this is only when editing
936
-        if (! empty($id)) {
936
+        if ( ! empty($id)) {
937 937
             $post = get_post($id);
938 938
             $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
939 939
                        . esc_html__('Shortcode', 'event_espresso')
@@ -967,7 +967,7 @@  discard block
 block discarded – undo
967 967
                     'button'
968 968
                 );
969 969
         $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
970
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
970
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
971 971
             'create_new',
972 972
             'add',
973 973
             array(),
@@ -1107,7 +1107,7 @@  discard block
 block discarded – undo
1107 1107
      */
1108 1108
     protected function _default_venue_update(\EE_Event $evtobj, $data)
1109 1109
     {
1110
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1110
+        require_once(EE_MODELS.'EEM_Venue.model.php');
1111 1111
         $venue_model = EE_Registry::instance()->load_model('Venue');
1112 1112
         $rows_affected = null;
1113 1113
         $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
@@ -1138,7 +1138,7 @@  discard block
 block discarded – undo
1138 1138
             'status'              => 'publish',
1139 1139
         );
1140 1140
         // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1141
-        if (! empty($venue_id)) {
1141
+        if ( ! empty($venue_id)) {
1142 1142
             $update_where = array($venue_model->primary_key_name() => $venue_id);
1143 1143
             $rows_affected = $venue_model->update($venue_array, array($update_where));
1144 1144
             // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
@@ -1180,7 +1180,7 @@  discard block
 block discarded – undo
1180 1180
                 'DTT_order'     => $row,
1181 1181
             );
1182 1182
             // if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1183
-            if (! empty($dtt['DTT_ID'])) {
1183
+            if ( ! empty($dtt['DTT_ID'])) {
1184 1184
                 $DTM = EE_Registry::instance()
1185 1185
                                   ->load_model('Datetime', array($evtobj->get_timezone()))
1186 1186
                                   ->get_one_by_ID($dtt['DTT_ID']);
@@ -1190,7 +1190,7 @@  discard block
 block discarded – undo
1190 1190
                     $DTM->set($field, $value);
1191 1191
                 }
1192 1192
                 // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1193
-                $saved_dtts[ $DTM->ID() ] = $DTM;
1193
+                $saved_dtts[$DTM->ID()] = $DTM;
1194 1194
             } else {
1195 1195
                 $DTM = EE_Registry::instance()->load_class(
1196 1196
                     'Datetime',
@@ -1223,14 +1223,14 @@  discard block
 block discarded – undo
1223 1223
         foreach ($data['edit_tickets'] as $row => $tkt) {
1224 1224
             $incoming_date_formats = array('Y-m-d', 'h:i a');
1225 1225
             $update_prices = false;
1226
-            $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1227
-                ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1226
+            $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1227
+                ? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1228 1228
             // trim inputs to ensure any excess whitespace is removed.
1229 1229
             $tkt = array_map('trim', $tkt);
1230 1230
             if (empty($tkt['TKT_start_date'])) {
1231 1231
                 // let's use now in the set timezone.
1232 1232
                 $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1233
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1233
+                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]);
1234 1234
             }
1235 1235
             if (empty($tkt['TKT_end_date'])) {
1236 1236
                 // use the start date of the first datetime
@@ -1265,7 +1265,7 @@  discard block
 block discarded – undo
1265 1265
             // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1266 1266
             // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1267 1267
             // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1268
-            if (! empty($tkt['TKT_ID'])) {
1268
+            if ( ! empty($tkt['TKT_ID'])) {
1269 1269
                 $TKT = EE_Registry::instance()
1270 1270
                                   ->load_model('Ticket', array($evtobj->get_timezone()))
1271 1271
                                   ->get_one_by_ID($tkt['TKT_ID']);
@@ -1300,7 +1300,7 @@  discard block
 block discarded – undo
1300 1300
                         $TKT->set('TKT_deleted', 1);
1301 1301
                         $TKT->save();
1302 1302
                         // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1303
-                        $saved_tickets[ $TKT->ID() ] = $TKT;
1303
+                        $saved_tickets[$TKT->ID()] = $TKT;
1304 1304
                         // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1305 1305
                         $TKT = clone $TKT;
1306 1306
                         $TKT->set('TKT_ID', 0);
@@ -1345,9 +1345,9 @@  discard block
 block discarded – undo
1345 1345
             }
1346 1346
             // initially let's add the ticket to the dtt
1347 1347
             $saved_dtt->_add_relation_to($TKT, 'Ticket');
1348
-            $saved_tickets[ $TKT->ID() ] = $TKT;
1348
+            $saved_tickets[$TKT->ID()] = $TKT;
1349 1349
             // add prices to ticket
1350
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1350
+            $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1351 1351
         }
1352 1352
         // however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1353 1353
         $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
@@ -1504,7 +1504,7 @@  discard block
 block discarded – undo
1504 1504
         $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1505 1505
         // load template
1506 1506
         EEH_Template::display_template(
1507
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1507
+            EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php',
1508 1508
             $publish_box_extra_args
1509 1509
         );
1510 1510
     }
@@ -1596,7 +1596,7 @@  discard block
 block discarded – undo
1596 1596
                     'default_where_conditions' => 'none',
1597 1597
                 )
1598 1598
             );
1599
-            if (! empty($related_tickets)) {
1599
+            if ( ! empty($related_tickets)) {
1600 1600
                 $template_args['total_ticket_rows'] = count($related_tickets);
1601 1601
                 $row = 0;
1602 1602
                 foreach ($related_tickets as $ticket) {
@@ -1630,7 +1630,7 @@  discard block
 block discarded – undo
1630 1630
         );
1631 1631
         $template = apply_filters(
1632 1632
             'FHEE__Events_Admin_Page__ticket_metabox__template',
1633
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1633
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php'
1634 1634
         );
1635 1635
         EEH_Template::display_template($template, $template_args);
1636 1636
     }
@@ -1648,7 +1648,7 @@  discard block
 block discarded – undo
1648 1648
     private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1649 1649
     {
1650 1650
         $template_args = array(
1651
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1651
+            'tkt_status_class'    => ' tkt-status-'.$ticket->ticket_status(),
1652 1652
             'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1653 1653
                 : '',
1654 1654
             'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
@@ -1660,10 +1660,10 @@  discard block
 block discarded – undo
1660 1660
             'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1661 1661
             'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1662 1662
             'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1663
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1664
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1663
+            'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1664
+                                     && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1665 1665
                 ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1666
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1666
+            'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1667 1667
                 : ' disabled=disabled',
1668 1668
         );
1669 1669
         $price = $ticket->ID() !== 0
@@ -1690,7 +1690,7 @@  discard block
 block discarded – undo
1690 1690
                     array('order_by' => array('DTT_EVT_start' => 'ASC'))
1691 1691
                 )
1692 1692
                 : null;
1693
-            if (! empty($earliest_dtt)) {
1693
+            if ( ! empty($earliest_dtt)) {
1694 1694
                 $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1695 1695
             } else {
1696 1696
                 $template_args['TKT_end_date'] = date(
@@ -1702,7 +1702,7 @@  discard block
 block discarded – undo
1702 1702
         $template_args = array_merge($template_args, $price_args);
1703 1703
         $template = apply_filters(
1704 1704
             'FHEE__Events_Admin_Page__get_ticket_row__template',
1705
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1705
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php',
1706 1706
             $ticket
1707 1707
         );
1708 1708
         return EEH_Template::display_template($template, $template_args, true);
@@ -1756,7 +1756,7 @@  discard block
 block discarded – undo
1756 1756
             $default_reg_status_values
1757 1757
         );
1758 1758
         EEH_Template::display_template(
1759
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1759
+            EVENTS_TEMPLATE_PATH.'event_registration_options.template.php',
1760 1760
             $template_args
1761 1761
         );
1762 1762
     }
@@ -1778,7 +1778,7 @@  discard block
 block discarded – undo
1778 1778
     {
1779 1779
         $EEME = $this->_event_model();
1780 1780
         $offset = ($current_page - 1) * $per_page;
1781
-        $limit = $count ? null : $offset . ',' . $per_page;
1781
+        $limit = $count ? null : $offset.','.$per_page;
1782 1782
         $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1783 1783
         $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1784 1784
         if (isset($this->_req_data['month_range'])) {
@@ -1807,7 +1807,7 @@  discard block
 block discarded – undo
1807 1807
         // categories?
1808 1808
         $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1809 1809
             ? $this->_req_data['EVT_CAT'] : null;
1810
-        if (! empty($category)) {
1810
+        if ( ! empty($category)) {
1811 1811
             $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1812 1812
             $where['Term_Taxonomy.term_id'] = $category;
1813 1813
         }
@@ -1815,7 +1815,7 @@  discard block
 block discarded – undo
1815 1815
         $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1816 1816
         if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1817 1817
             $DateTime = new DateTime(
1818
-                $year_r . '-' . $month_r . '-01 00:00:00',
1818
+                $year_r.'-'.$month_r.'-01 00:00:00',
1819 1819
                 new DateTimeZone('UTC')
1820 1820
             );
1821 1821
             $start = $DateTime->getTimestamp();
@@ -1841,11 +1841,11 @@  discard block
 block discarded – undo
1841 1841
                             ->format(implode(' ', $start_formats));
1842 1842
             $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1843 1843
         }
1844
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1844
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1845 1845
             $where['EVT_wp_user'] = get_current_user_id();
1846 1846
         } else {
1847
-            if (! isset($where['status'])) {
1848
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1847
+            if ( ! isset($where['status'])) {
1848
+                if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1849 1849
                     $where['OR'] = array(
1850 1850
                         'status*restrict_private' => array('!=', 'private'),
1851 1851
                         'AND'                     => array(
@@ -1865,7 +1865,7 @@  discard block
 block discarded – undo
1865 1865
         }
1866 1866
         // search query handling
1867 1867
         if (isset($this->_req_data['s'])) {
1868
-            $search_string = '%' . $this->_req_data['s'] . '%';
1868
+            $search_string = '%'.$this->_req_data['s'].'%';
1869 1869
             $where['OR'] = array(
1870 1870
                 'EVT_name'       => array('LIKE', $search_string),
1871 1871
                 'EVT_desc'       => array('LIKE', $search_string),
@@ -1961,7 +1961,7 @@  discard block
 block discarded – undo
1961 1961
             // clean status
1962 1962
             $event_status = sanitize_key($event_status);
1963 1963
             // grab status
1964
-            if (! empty($event_status)) {
1964
+            if ( ! empty($event_status)) {
1965 1965
                 $success = $this->_change_event_status($EVT_ID, $event_status);
1966 1966
             } else {
1967 1967
                 $success = false;
@@ -1998,7 +1998,7 @@  discard block
 block discarded – undo
1998 1998
         // clean status
1999 1999
         $event_status = sanitize_key($event_status);
2000 2000
         // grab status
2001
-        if (! empty($event_status)) {
2001
+        if ( ! empty($event_status)) {
2002 2002
             $success = true;
2003 2003
             // determine the event id and set to array.
2004 2004
             $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
@@ -2042,7 +2042,7 @@  discard block
 block discarded – undo
2042 2042
     private function _change_event_status($EVT_ID = 0, $event_status = '')
2043 2043
     {
2044 2044
         // grab event id
2045
-        if (! $EVT_ID) {
2045
+        if ( ! $EVT_ID) {
2046 2046
             $msg = esc_html__(
2047 2047
                 'An error occurred. No Event ID or an invalid Event ID was received.',
2048 2048
                 'event_espresso'
@@ -2079,7 +2079,7 @@  discard block
 block discarded – undo
2079 2079
         // use class to change status
2080 2080
         $this->_cpt_model_obj->set_status($event_status);
2081 2081
         $success = $this->_cpt_model_obj->save();
2082
-        if (! $success) {
2082
+        if ( ! $success) {
2083 2083
             $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2084 2084
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2085 2085
             return false;
@@ -2134,7 +2134,7 @@  discard block
 block discarded – undo
2134 2134
      */
2135 2135
     protected function getModelObjNodeGroupPersister()
2136 2136
     {
2137
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2137
+        if ( ! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2138 2138
             $this->model_obj_node_group_persister = $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2139 2139
         }
2140 2140
         return $this->model_obj_node_group_persister;
@@ -2390,7 +2390,7 @@  discard block
 block discarded – undo
2390 2390
                                                 . esc_html__(
2391 2391
                                                     'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2392 2392
                                                     'event_espresso'
2393
-                                                ) . '</strong>';
2393
+                                                ).'</strong>';
2394 2394
         $this->display_admin_caf_preview_page('template_settings_tab');
2395 2395
     }
2396 2396
 
@@ -2410,12 +2410,12 @@  discard block
 block discarded – undo
2410 2410
         // set default category object
2411 2411
         $this->_set_empty_category_object();
2412 2412
         // only set if we've got an id
2413
-        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2413
+        if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2414 2414
             return;
2415 2415
         }
2416 2416
         $category_id = absint($this->_req_data['EVT_CAT_ID']);
2417 2417
         $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2418
-        if (! empty($term)) {
2418
+        if ( ! empty($term)) {
2419 2419
             $this->_category->category_name = $term->name;
2420 2420
             $this->_category->category_identifier = $term->slug;
2421 2421
             $this->_category->category_desc = $term->description;
@@ -2443,7 +2443,7 @@  discard block
 block discarded – undo
2443 2443
     {
2444 2444
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2445 2445
         $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2446
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2446
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
2447 2447
             'add_category',
2448 2448
             'add_category',
2449 2449
             array(),
@@ -2517,7 +2517,7 @@  discard block
 block discarded – undo
2517 2517
             'disable'                  => '',
2518 2518
             'disabled_message'         => false,
2519 2519
         );
2520
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2520
+        $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php';
2521 2521
         return EEH_Template::display_template($template, $template_args, true);
2522 2522
     }
2523 2523
 
@@ -2602,7 +2602,7 @@  discard block
 block discarded – undo
2602 2602
         $insert_ids = $update
2603 2603
             ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2604 2604
             : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2605
-        if (! is_array($insert_ids)) {
2605
+        if ( ! is_array($insert_ids)) {
2606 2606
             $msg = esc_html__(
2607 2607
                 'An error occurred and the category has not been saved to the database.',
2608 2608
                 'event_espresso'
@@ -2633,7 +2633,7 @@  discard block
 block discarded – undo
2633 2633
         $limit = ($current_page - 1) * $per_page;
2634 2634
         $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2635 2635
         if (isset($this->_req_data['s'])) {
2636
-            $sstr = '%' . $this->_req_data['s'] . '%';
2636
+            $sstr = '%'.$this->_req_data['s'].'%';
2637 2637
             $where['OR'] = array(
2638 2638
                 'Term.name'   => array('LIKE', $sstr),
2639 2639
                 'description' => array('LIKE', $sstr),
@@ -2642,7 +2642,7 @@  discard block
 block discarded – undo
2642 2642
         $query_params = array(
2643 2643
             $where,
2644 2644
             'order_by'   => array($orderby => $order),
2645
-            'limit'      => $limit . ',' . $per_page,
2645
+            'limit'      => $limit.','.$per_page,
2646 2646
             'force_join' => array('Term'),
2647 2647
         );
2648 2648
         $categories = $count
Please login to merge, or discard this patch.
core/libraries/batch/JobHandlers/PreviewEventDeletion.php 1 patch
Indentation   +214 added lines, -214 removed lines patch added patch discarded remove patch
@@ -37,149 +37,149 @@  discard block
 block discarded – undo
37 37
 class PreviewEventDeletion extends JobHandler
38 38
 {
39 39
 
40
-    /**
41
-     * @var NodeGroupDao
42
-     */
43
-    protected $model_obj_node_group_persister;
40
+	/**
41
+	 * @var NodeGroupDao
42
+	 */
43
+	protected $model_obj_node_group_persister;
44 44
 
45
-    public function __construct(NodeGroupDao $model_obj_node_group_persister)
46
-    {
47
-        $this->model_obj_node_group_persister = $model_obj_node_group_persister;
48
-    }
45
+	public function __construct(NodeGroupDao $model_obj_node_group_persister)
46
+	{
47
+		$this->model_obj_node_group_persister = $model_obj_node_group_persister;
48
+	}
49 49
 
50
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
50
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
51 51
 
52
-    /**
53
-     *
54
-     * @param JobParameters $job_parameters
55
-     * @return JobStepResponse
56
-     * @throws EE_Error
57
-     * @throws InvalidDataTypeException
58
-     * @throws InvalidInterfaceException
59
-     * @throws InvalidArgumentException
60
-     * @throws ReflectionException
61
-     */
62
-    public function create_job(JobParameters $job_parameters)
63
-    {
64
-        // Set the "root" model objects we will want to delete (record their ID and model)
65
-        $event_ids = $job_parameters->request_datum('EVT_IDs', array());
66
-        // Find all the root nodes to delete (this isn't just events, because there's other data, like related tickets,
67
-        // prices, message templates, etc, whose model definition doesn't make them dependent on events. But,
68
-        // we have no UI to access them independent of events, so they may as well get deleted too.)
69
-        $roots = [];
70
-        foreach ($event_ids as $event_id) {
71
-            $roots[] = new ModelObjNode(
72
-                $event_id,
73
-                EEM_Event::instance()
74
-            );
75
-            // Also, we want to delete their related, non-global, tickets, prices and message templates
76
-            $related_non_global_tickets = EEM_Ticket::instance()->get_all_deleted_and_undeleted(
77
-                [
78
-                    [
79
-                        'TKT_is_default' => false,
80
-                        'Datetime.EVT_ID' => $event_id
81
-                    ]
82
-                ]
83
-            );
84
-            foreach ($related_non_global_tickets as $ticket) {
85
-                $roots[] = new ModelObjNode(
86
-                    $ticket->ID(),
87
-                    $ticket->get_model(),
88
-                    ['Registration']
89
-                );
90
-            }
91
-            $related_non_global_prices = EEM_Price::instance()->get_all_deleted_and_undeleted(
92
-                [
93
-                    [
94
-                        'PRC_is_default' => false,
95
-                        'Ticket.Datetime.EVT_ID' => $event_id
96
-                    ]
97
-                ]
98
-            );
99
-            foreach ($related_non_global_prices as $price) {
100
-                $roots[] = new ModelObjNode(
101
-                    $price->ID(),
102
-                    $price->get_model()
103
-                );
104
-            }
105
-        }
106
-        $transactions_ids = $this->getTransactionsToDelete($event_ids);
107
-        foreach ($transactions_ids as $transaction_id) {
108
-            $roots[] = new ModelObjNode(
109
-                $transaction_id,
110
-                EEM_Transaction::instance(),
111
-                ['Registration']
112
-            );
113
-        }
114
-        $job_parameters->add_extra_data('roots', $roots);
115
-        // Set an estimate of how long this will take (we're discovering as we go, so it seems impossible to give
116
-        // an accurate count.)
117
-        $estimated_work_per_model_obj = 10;
118
-        $count_regs = EEM_Registration::instance()->count(
119
-            [
120
-                [
121
-                    'EVT_ID' => ['IN', $event_ids]
122
-                ]
123
-            ]
124
-        );
125
-        $job_parameters->set_job_size((count($roots) + $count_regs) * $estimated_work_per_model_obj);
126
-        return new JobStepResponse(
127
-            $job_parameters,
128
-            esc_html__('Generating preview of data to be deleted...', 'event_espresso')
129
-        );
130
-    }
52
+	/**
53
+	 *
54
+	 * @param JobParameters $job_parameters
55
+	 * @return JobStepResponse
56
+	 * @throws EE_Error
57
+	 * @throws InvalidDataTypeException
58
+	 * @throws InvalidInterfaceException
59
+	 * @throws InvalidArgumentException
60
+	 * @throws ReflectionException
61
+	 */
62
+	public function create_job(JobParameters $job_parameters)
63
+	{
64
+		// Set the "root" model objects we will want to delete (record their ID and model)
65
+		$event_ids = $job_parameters->request_datum('EVT_IDs', array());
66
+		// Find all the root nodes to delete (this isn't just events, because there's other data, like related tickets,
67
+		// prices, message templates, etc, whose model definition doesn't make them dependent on events. But,
68
+		// we have no UI to access them independent of events, so they may as well get deleted too.)
69
+		$roots = [];
70
+		foreach ($event_ids as $event_id) {
71
+			$roots[] = new ModelObjNode(
72
+				$event_id,
73
+				EEM_Event::instance()
74
+			);
75
+			// Also, we want to delete their related, non-global, tickets, prices and message templates
76
+			$related_non_global_tickets = EEM_Ticket::instance()->get_all_deleted_and_undeleted(
77
+				[
78
+					[
79
+						'TKT_is_default' => false,
80
+						'Datetime.EVT_ID' => $event_id
81
+					]
82
+				]
83
+			);
84
+			foreach ($related_non_global_tickets as $ticket) {
85
+				$roots[] = new ModelObjNode(
86
+					$ticket->ID(),
87
+					$ticket->get_model(),
88
+					['Registration']
89
+				);
90
+			}
91
+			$related_non_global_prices = EEM_Price::instance()->get_all_deleted_and_undeleted(
92
+				[
93
+					[
94
+						'PRC_is_default' => false,
95
+						'Ticket.Datetime.EVT_ID' => $event_id
96
+					]
97
+				]
98
+			);
99
+			foreach ($related_non_global_prices as $price) {
100
+				$roots[] = new ModelObjNode(
101
+					$price->ID(),
102
+					$price->get_model()
103
+				);
104
+			}
105
+		}
106
+		$transactions_ids = $this->getTransactionsToDelete($event_ids);
107
+		foreach ($transactions_ids as $transaction_id) {
108
+			$roots[] = new ModelObjNode(
109
+				$transaction_id,
110
+				EEM_Transaction::instance(),
111
+				['Registration']
112
+			);
113
+		}
114
+		$job_parameters->add_extra_data('roots', $roots);
115
+		// Set an estimate of how long this will take (we're discovering as we go, so it seems impossible to give
116
+		// an accurate count.)
117
+		$estimated_work_per_model_obj = 10;
118
+		$count_regs = EEM_Registration::instance()->count(
119
+			[
120
+				[
121
+					'EVT_ID' => ['IN', $event_ids]
122
+				]
123
+			]
124
+		);
125
+		$job_parameters->set_job_size((count($roots) + $count_regs) * $estimated_work_per_model_obj);
126
+		return new JobStepResponse(
127
+			$job_parameters,
128
+			esc_html__('Generating preview of data to be deleted...', 'event_espresso')
129
+		);
130
+	}
131 131
 
132
-    /**
133
-     * @since 4.10.12.p
134
-     * @param EE_Base_Class[] $model_objs
135
-     * @param array $dont_traverse_models
136
-     * @return array
137
-     * @throws EE_Error
138
-     * @throws InvalidArgumentException
139
-     * @throws InvalidDataTypeException
140
-     * @throws InvalidInterfaceException
141
-     * @throws ReflectionException
142
-     */
143
-    protected function createModelObjNodes($model_objs, array $dont_traverse_models = [])
144
-    {
145
-        $nodes = [];
146
-        foreach ($model_objs as $model_obj) {
147
-            $nodes[] = new ModelObjNode(
148
-                $model_obj->ID(),
149
-                $model_obj->get_model(),
150
-                $dont_traverse_models
151
-            );
152
-        }
153
-        return $nodes;
154
-    }
132
+	/**
133
+	 * @since 4.10.12.p
134
+	 * @param EE_Base_Class[] $model_objs
135
+	 * @param array $dont_traverse_models
136
+	 * @return array
137
+	 * @throws EE_Error
138
+	 * @throws InvalidArgumentException
139
+	 * @throws InvalidDataTypeException
140
+	 * @throws InvalidInterfaceException
141
+	 * @throws ReflectionException
142
+	 */
143
+	protected function createModelObjNodes($model_objs, array $dont_traverse_models = [])
144
+	{
145
+		$nodes = [];
146
+		foreach ($model_objs as $model_obj) {
147
+			$nodes[] = new ModelObjNode(
148
+				$model_obj->ID(),
149
+				$model_obj->get_model(),
150
+				$dont_traverse_models
151
+			);
152
+		}
153
+		return $nodes;
154
+	}
155 155
 
156
-    /**
157
-     * Gets all the transactions related to these events that aren't related to other events. They'll be deleted too.
158
-     * (Ones that are related to other events can stay around until those other events are deleted too.)
159
-     * @since 4.10.12.p
160
-     * @param $event_ids
161
-     * @return array of transaction IDs
162
-     */
163
-    protected function getTransactionsToDelete($event_ids)
164
-    {
165
-        if (empty($event_ids)) {
166
-            return [];
167
-        }
168
-        global $wpdb;
169
-        $event_ids = array_map(
170
-            'intval',
171
-            $event_ids
172
-        );
173
-        $imploded_sanitized_event_ids = implode(',', $event_ids);
174
-        // Select transactions with registrations for the events $event_ids which also don't have registrations
175
-        // for any events NOT in $event_ids.
176
-        // Notice the outer query searched for transactions whose registrations ARE in $event_ids,
177
-        // whereas the inner query checks if the outer query's transaction has any registrations that are
178
-        // NOT IN $event_ids (ie, don't have registrations for events we're not just about to delete.)
179
-        return array_map(
180
-            'intval',
181
-            $wpdb->get_col(
182
-                "SELECT 
156
+	/**
157
+	 * Gets all the transactions related to these events that aren't related to other events. They'll be deleted too.
158
+	 * (Ones that are related to other events can stay around until those other events are deleted too.)
159
+	 * @since 4.10.12.p
160
+	 * @param $event_ids
161
+	 * @return array of transaction IDs
162
+	 */
163
+	protected function getTransactionsToDelete($event_ids)
164
+	{
165
+		if (empty($event_ids)) {
166
+			return [];
167
+		}
168
+		global $wpdb;
169
+		$event_ids = array_map(
170
+			'intval',
171
+			$event_ids
172
+		);
173
+		$imploded_sanitized_event_ids = implode(',', $event_ids);
174
+		// Select transactions with registrations for the events $event_ids which also don't have registrations
175
+		// for any events NOT in $event_ids.
176
+		// Notice the outer query searched for transactions whose registrations ARE in $event_ids,
177
+		// whereas the inner query checks if the outer query's transaction has any registrations that are
178
+		// NOT IN $event_ids (ie, don't have registrations for events we're not just about to delete.)
179
+		return array_map(
180
+			'intval',
181
+			$wpdb->get_col(
182
+				"SELECT 
183 183
                       DISTINCT t.TXN_ID
184 184
                     FROM 
185 185
                       {$wpdb->prefix}esp_transaction t INNER JOIN 
@@ -197,84 +197,84 @@  discard block
 block discarded – undo
197 197
                            tsub.TXN_ID=t.TXN_ID AND
198 198
                            rsub.EVT_ID NOT IN ({$imploded_sanitized_event_ids})
199 199
                        )"
200
-            )
201
-        );
202
-    }
200
+			)
201
+		);
202
+	}
203 203
 
204
-    /**
205
-     * Performs another step of the job
206
-     * @param JobParameters $job_parameters
207
-     * @param int $batch_size
208
-     * @return JobStepResponse
209
-     * @throws BatchRequestException
210
-     */
211
-    public function continue_job(JobParameters $job_parameters, $batch_size = 50)
212
-    {
213
-        // Serializing and unserializing is what really makes this drag on (eg on localhost, the ajax requests took
214
-        // about 4 seconds when the batch size was 250, but 3 seconds when the batch size was 50. So like
215
-        // 50% of the request is just serializing and unserializing.) So, make the batches much bigger.
216
-        $batch_size *= 3;
217
-        $units_processed = 0;
218
-        foreach ($job_parameters->extra_datum('roots', array()) as $root_node) {
219
-            if ($units_processed >= $batch_size) {
220
-                break;
221
-            }
222
-            if (!$root_node instanceof ModelObjNode) {
223
-                throw new InvalidClassException('ModelObjNode');
224
-            }
225
-            if ($root_node->isComplete()) {
226
-                continue;
227
-            }
228
-            $units_processed += $root_node->visit($batch_size - $units_processed);
229
-        }
230
-        $job_parameters->mark_processed($units_processed);
231
-        // If the most-recently processed root node is complete, we must be all done because we're doing them
232
-        // sequentially.
233
-        if (isset($root_node) && $root_node instanceof ModelObjNode && $root_node->isComplete()) {
234
-            $job_parameters->set_status(JobParameters::status_complete);
235
-            // Show a full progress bar.
236
-            $job_parameters->set_units_processed($job_parameters->job_size());
237
-            $deletion_job_code = $job_parameters->request_datum('deletion_job_code');
238
-            $this->model_obj_node_group_persister->persistModelObjNodesGroup(
239
-                $job_parameters->extra_datum('roots'),
240
-                $deletion_job_code
241
-            );
242
-            return new JobStepResponse(
243
-                $job_parameters,
244
-                esc_html__('Finished identifying items for deletion.', 'event_espresso'),
245
-                [
246
-                    'deletion_job_code' => $deletion_job_code
247
-                ]
248
-            );
249
-        } else {
250
-            // Because the job size was a guess, it may have likely been proven wrong. We don't want to show more work
251
-            // done than we originally said there would be. So adjust the estimate.
252
-            if (($job_parameters->units_processed() / $job_parameters->job_size()) > .8) {
253
-                $job_parameters->set_job_size($job_parameters->job_size() * 2);
254
-            }
255
-            return new JobStepResponse(
256
-                $job_parameters,
257
-                sprintf(
258
-                    esc_html__('Identified %d items for deletion.', 'event_espresso'),
259
-                    $units_processed
260
-                )
261
-            );
262
-        }
263
-    }
204
+	/**
205
+	 * Performs another step of the job
206
+	 * @param JobParameters $job_parameters
207
+	 * @param int $batch_size
208
+	 * @return JobStepResponse
209
+	 * @throws BatchRequestException
210
+	 */
211
+	public function continue_job(JobParameters $job_parameters, $batch_size = 50)
212
+	{
213
+		// Serializing and unserializing is what really makes this drag on (eg on localhost, the ajax requests took
214
+		// about 4 seconds when the batch size was 250, but 3 seconds when the batch size was 50. So like
215
+		// 50% of the request is just serializing and unserializing.) So, make the batches much bigger.
216
+		$batch_size *= 3;
217
+		$units_processed = 0;
218
+		foreach ($job_parameters->extra_datum('roots', array()) as $root_node) {
219
+			if ($units_processed >= $batch_size) {
220
+				break;
221
+			}
222
+			if (!$root_node instanceof ModelObjNode) {
223
+				throw new InvalidClassException('ModelObjNode');
224
+			}
225
+			if ($root_node->isComplete()) {
226
+				continue;
227
+			}
228
+			$units_processed += $root_node->visit($batch_size - $units_processed);
229
+		}
230
+		$job_parameters->mark_processed($units_processed);
231
+		// If the most-recently processed root node is complete, we must be all done because we're doing them
232
+		// sequentially.
233
+		if (isset($root_node) && $root_node instanceof ModelObjNode && $root_node->isComplete()) {
234
+			$job_parameters->set_status(JobParameters::status_complete);
235
+			// Show a full progress bar.
236
+			$job_parameters->set_units_processed($job_parameters->job_size());
237
+			$deletion_job_code = $job_parameters->request_datum('deletion_job_code');
238
+			$this->model_obj_node_group_persister->persistModelObjNodesGroup(
239
+				$job_parameters->extra_datum('roots'),
240
+				$deletion_job_code
241
+			);
242
+			return new JobStepResponse(
243
+				$job_parameters,
244
+				esc_html__('Finished identifying items for deletion.', 'event_espresso'),
245
+				[
246
+					'deletion_job_code' => $deletion_job_code
247
+				]
248
+			);
249
+		} else {
250
+			// Because the job size was a guess, it may have likely been proven wrong. We don't want to show more work
251
+			// done than we originally said there would be. So adjust the estimate.
252
+			if (($job_parameters->units_processed() / $job_parameters->job_size()) > .8) {
253
+				$job_parameters->set_job_size($job_parameters->job_size() * 2);
254
+			}
255
+			return new JobStepResponse(
256
+				$job_parameters,
257
+				sprintf(
258
+					esc_html__('Identified %d items for deletion.', 'event_espresso'),
259
+					$units_processed
260
+				)
261
+			);
262
+		}
263
+	}
264 264
 
265
-    /**
266
-     * Performs any clean-up logic when we know the job is completed
267
-     * @param JobParameters $job_parameters
268
-     * @return JobStepResponse
269
-     */
270
-    public function cleanup_job(JobParameters $job_parameters)
271
-    {
272
-        // Nothing much to do. We can't delete the option with the built tree because we may need it in a moment for the deletion
273
-        return new JobStepResponse(
274
-            $job_parameters,
275
-            esc_html__('All done', 'event_espresso')
276
-        );
277
-    }
265
+	/**
266
+	 * Performs any clean-up logic when we know the job is completed
267
+	 * @param JobParameters $job_parameters
268
+	 * @return JobStepResponse
269
+	 */
270
+	public function cleanup_job(JobParameters $job_parameters)
271
+	{
272
+		// Nothing much to do. We can't delete the option with the built tree because we may need it in a moment for the deletion
273
+		return new JobStepResponse(
274
+			$job_parameters,
275
+			esc_html__('All done', 'event_espresso')
276
+		);
277
+	}
278 278
 }
279 279
 // End of file EventDeletion.php
280 280
 // Location: EventEspressoBatchRequest\JobHandlers/EventDeletion.php
Please login to merge, or discard this patch.