Completed
Branch Gutenberg/master (d0e4cb)
by
unknown
81:46 queued 67:38
created
core/services/assets/I18nRegistry.php 1 patch
Indentation   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -14,238 +14,238 @@
 block discarded – undo
14 14
  */
15 15
 class I18nRegistry
16 16
 {
17
-    /**
18
-     * @var DomainInterface
19
-     */
20
-    private $domain;
21
-
22
-    /**
23
-     * Will hold all registered i18n scripts.  Prevents script handles from being registered more than once.
24
-     *
25
-     * @var array
26
-     */
27
-    private $registered_i18n = array();
28
-
29
-
30
-    /**
31
-     * Used to hold queued translations for the chunks loading in a view.
32
-     *
33
-     * @var array
34
-     */
35
-    private $queued_handle_translations = array();
36
-
37
-    /**
38
-     * Used to track script handles queued for adding translation strings as inline data in the dom.
39
-     *
40
-     * @var array
41
-     */
42
-    private $queued_scripts = array();
43
-
44
-
45
-    /**
46
-     * Obtained from the generated json file from the all javascript using wp.i18n with a map of script handle names to
47
-     * translation strings.
48
-     *
49
-     * @var array
50
-     */
51
-    private $i18n_map;
52
-
53
-
54
-    /**
55
-     * I18nRegistry constructor.
56
-     *
57
-     * @param array() $i18n_map  An array of script handle names and the strings translated for those handles.  If not
58
-     *                            provided, the class will look for map in root of plugin with filename of
59
-     *                            'translation-map.json'.
60
-     * @param DomainInterface $domain
61
-     */
62
-    public function __construct(array $i18n_map = array(), DomainInterface $domain)
63
-    {
64
-        $this->domain = $domain;
65
-        $this->setI18nMap($i18n_map);
66
-        add_filter('print_scripts_array', array($this, 'queueI18n'));
67
-    }
68
-
69
-
70
-    /**
71
-     * Used to register a script that has i18n strings for its $handle
72
-     *
73
-     * @param string $handle The script handle reference.
74
-     * @param string $domain The i18n domain for the strings.
75
-     */
76
-    public function registerScriptI18n($handle, $domain = 'event_espresso')
77
-    {
78
-        if(! isset($this->registered_i18n[$handle])) {
79
-            $this->registered_i18n[ $handle ] = 1;
80
-            $this->queued_scripts[ $handle ] = $domain;
81
-        }
82
-    }
83
-
84
-
85
-
86
-    /**
87
-     * Callback on print_scripts_array to listen for scripts enqueued and handle setting up the localized data.
88
-     *
89
-     * @param array $handles Array of registered script handles.
90
-     * @return array
91
-     */
92
-    public function queueI18n(array $handles)
93
-    {
94
-        if (empty($this->queued_scripts)) {
95
-            return $handles;
96
-        }
97
-        foreach ($handles as $handle) {
98
-            $this->queueI18nTranslationsForHandle($handle);
99
-        }
100
-        if ($this->queued_handle_translations) {
101
-            foreach ($this->queued_handle_translations as $handle => $translations_for_domain) {
102
-                $this->registerInlineScript(
103
-                    $handle,
104
-                    $translations_for_domain['translations'],
105
-                    $translations_for_domain['domain']
106
-                );
107
-            }
108
-        }
109
-        return $handles;
110
-    }
111
-
112
-
113
-    /**
114
-     * Registers inline script with translations for given handle and domain.
115
-     *
116
-     * @param string $handle       Handle used to register javascript file containing translations.
117
-     * @param array  $translations Array of string translations.
118
-     * @param string $domain       Domain for translations.  If left empty then strings are registered with the default
119
-     *                             domain for the javascript.
120
-     */
121
-    protected function registerInlineScript($handle, array $translations, $domain)
122
-    {
123
-        $script = $domain ?
124
-            'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ', "' . $domain . '" );' :
125
-            'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );';
126
-        wp_add_inline_script($handle, $script, 'before');
127
-    }
128
-
129
-
130
-    /**
131
-     * Queues up the translation strings for the given handle.
132
-     *
133
-     * @param string $handle The script handle being queued up.
134
-     */
135
-    private function queueI18nTranslationsForHandle($handle)
136
-    {
137
-        if (isset($this->queued_scripts[$handle])) {
138
-            $domain = $this->queued_scripts[$handle];
139
-            $translations = $this->getJedLocaleDataForDomainAndChunk($handle, $domain);
140
-            if (count($translations) > 0) {
141
-                $this->queued_handle_translations[$handle] = array(
142
-                    'domain'       => $domain,
143
-                    'translations' => $translations,
144
-                );
145
-            }
146
-            unset($this->queued_scripts[$handle]);
147
-        }
148
-    }
149
-
150
-
151
-    /**
152
-     * Sets the internal i18n_map property.
153
-     * If $chunk_map is empty or not an array, will attempt to load a chunk map from a default named map.
154
-     *
155
-     * @param array $i18n_map  If provided, an array of translation strings indexed by script handle names they
156
-     *                         correspond to.
157
-     */
158
-    private function setI18nMap(array $i18n_map)
159
-    {
160
-        if (empty($i18n_map)) {
161
-            $i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json')
162
-                ? json_decode(
163
-                        file_get_contents($this->domain->pluginPath() . 'translation-map.json'),
164
-                        true
165
-                    )
166
-                : array();
167
-        }
168
-        $this->i18n_map = $i18n_map;
169
-    }
170
-
171
-
172
-    /**
173
-     * Get the jed locale data for a given $handle and domain
174
-     *
175
-     * @param string $handle The name for the script handle we want strings returned for.
176
-     * @param string $domain The i18n domain.
177
-     * @return array
178
-     */
179
-    protected function getJedLocaleDataForDomainAndChunk($handle, $domain)
180
-    {
181
-        $translations = $this->getJedLocaleData($domain);
182
-        // get index for adding back after extracting strings for this $chunk.
183
-        $index = $translations[''];
184
-        $translations = $this->getLocaleDataMatchingMap(
185
-            $this->getOriginalStringsForHandleFromMap($handle),
186
-            $translations
187
-        );
188
-        $translations[''] = $index;
189
-        return $translations;
190
-    }
191
-
192
-
193
-    /**
194
-     * Get locale data for given strings from given translations
195
-     *
196
-     * @param array $string_set   This is the subset of strings (msgIds) we want to extract from the translations array.
197
-     * @param array $translations Translation data to extra strings from.
198
-     * @return array
199
-     */
200
-    protected function getLocaleDataMatchingMap(array $string_set, array $translations)
201
-    {
202
-        if (empty($string_set)) {
203
-            return array();
204
-        }
205
-        // some strings with quotes in them will break on the array_flip, so making sure quotes in the string are
206
-        // slashed also filter falsey values.
207
-        $string_set = array_unique(array_filter(wp_slash($string_set)));
208
-        return array_intersect_key($translations, array_flip($string_set));
209
-    }
210
-
211
-
212
-    /**
213
-     * Get original strings to translate for the given chunk from the map
214
-     *
215
-     * @param string $handle The script handle name to get strings from the map for.
216
-     * @return array
217
-     */
218
-    protected function getOriginalStringsForHandleFromMap($handle)
219
-    {
220
-        return isset($this->i18n_map[$handle]) ? $this->i18n_map[$handle] : array();
221
-    }
222
-
223
-
224
-    /**
225
-     * Returns Jed-formatted localization data.
226
-     *
227
-     * @param  string $domain Translation domain.
228
-     * @return array
229
-     */
230
-    private function getJedLocaleData($domain)
231
-    {
232
-        $translations = get_translations_for_domain($domain);
233
-
234
-        $locale = array(
235
-            '' => array(
236
-                'domain' => $domain,
237
-                'lang'   => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale()
238
-            ),
239
-        );
240
-
241
-        if (! empty($translations->headers['Plural-Forms'])) {
242
-            $locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
243
-        }
244
-
245
-        foreach ($translations->entries as $msgid => $entry) {
246
-            $locale[$msgid] = $entry->translations;
247
-        }
248
-
249
-        return $locale;
250
-    }
17
+	/**
18
+	 * @var DomainInterface
19
+	 */
20
+	private $domain;
21
+
22
+	/**
23
+	 * Will hold all registered i18n scripts.  Prevents script handles from being registered more than once.
24
+	 *
25
+	 * @var array
26
+	 */
27
+	private $registered_i18n = array();
28
+
29
+
30
+	/**
31
+	 * Used to hold queued translations for the chunks loading in a view.
32
+	 *
33
+	 * @var array
34
+	 */
35
+	private $queued_handle_translations = array();
36
+
37
+	/**
38
+	 * Used to track script handles queued for adding translation strings as inline data in the dom.
39
+	 *
40
+	 * @var array
41
+	 */
42
+	private $queued_scripts = array();
43
+
44
+
45
+	/**
46
+	 * Obtained from the generated json file from the all javascript using wp.i18n with a map of script handle names to
47
+	 * translation strings.
48
+	 *
49
+	 * @var array
50
+	 */
51
+	private $i18n_map;
52
+
53
+
54
+	/**
55
+	 * I18nRegistry constructor.
56
+	 *
57
+	 * @param array() $i18n_map  An array of script handle names and the strings translated for those handles.  If not
58
+	 *                            provided, the class will look for map in root of plugin with filename of
59
+	 *                            'translation-map.json'.
60
+	 * @param DomainInterface $domain
61
+	 */
62
+	public function __construct(array $i18n_map = array(), DomainInterface $domain)
63
+	{
64
+		$this->domain = $domain;
65
+		$this->setI18nMap($i18n_map);
66
+		add_filter('print_scripts_array', array($this, 'queueI18n'));
67
+	}
68
+
69
+
70
+	/**
71
+	 * Used to register a script that has i18n strings for its $handle
72
+	 *
73
+	 * @param string $handle The script handle reference.
74
+	 * @param string $domain The i18n domain for the strings.
75
+	 */
76
+	public function registerScriptI18n($handle, $domain = 'event_espresso')
77
+	{
78
+		if(! isset($this->registered_i18n[$handle])) {
79
+			$this->registered_i18n[ $handle ] = 1;
80
+			$this->queued_scripts[ $handle ] = $domain;
81
+		}
82
+	}
83
+
84
+
85
+
86
+	/**
87
+	 * Callback on print_scripts_array to listen for scripts enqueued and handle setting up the localized data.
88
+	 *
89
+	 * @param array $handles Array of registered script handles.
90
+	 * @return array
91
+	 */
92
+	public function queueI18n(array $handles)
93
+	{
94
+		if (empty($this->queued_scripts)) {
95
+			return $handles;
96
+		}
97
+		foreach ($handles as $handle) {
98
+			$this->queueI18nTranslationsForHandle($handle);
99
+		}
100
+		if ($this->queued_handle_translations) {
101
+			foreach ($this->queued_handle_translations as $handle => $translations_for_domain) {
102
+				$this->registerInlineScript(
103
+					$handle,
104
+					$translations_for_domain['translations'],
105
+					$translations_for_domain['domain']
106
+				);
107
+			}
108
+		}
109
+		return $handles;
110
+	}
111
+
112
+
113
+	/**
114
+	 * Registers inline script with translations for given handle and domain.
115
+	 *
116
+	 * @param string $handle       Handle used to register javascript file containing translations.
117
+	 * @param array  $translations Array of string translations.
118
+	 * @param string $domain       Domain for translations.  If left empty then strings are registered with the default
119
+	 *                             domain for the javascript.
120
+	 */
121
+	protected function registerInlineScript($handle, array $translations, $domain)
122
+	{
123
+		$script = $domain ?
124
+			'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ', "' . $domain . '" );' :
125
+			'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );';
126
+		wp_add_inline_script($handle, $script, 'before');
127
+	}
128
+
129
+
130
+	/**
131
+	 * Queues up the translation strings for the given handle.
132
+	 *
133
+	 * @param string $handle The script handle being queued up.
134
+	 */
135
+	private function queueI18nTranslationsForHandle($handle)
136
+	{
137
+		if (isset($this->queued_scripts[$handle])) {
138
+			$domain = $this->queued_scripts[$handle];
139
+			$translations = $this->getJedLocaleDataForDomainAndChunk($handle, $domain);
140
+			if (count($translations) > 0) {
141
+				$this->queued_handle_translations[$handle] = array(
142
+					'domain'       => $domain,
143
+					'translations' => $translations,
144
+				);
145
+			}
146
+			unset($this->queued_scripts[$handle]);
147
+		}
148
+	}
149
+
150
+
151
+	/**
152
+	 * Sets the internal i18n_map property.
153
+	 * If $chunk_map is empty or not an array, will attempt to load a chunk map from a default named map.
154
+	 *
155
+	 * @param array $i18n_map  If provided, an array of translation strings indexed by script handle names they
156
+	 *                         correspond to.
157
+	 */
158
+	private function setI18nMap(array $i18n_map)
159
+	{
160
+		if (empty($i18n_map)) {
161
+			$i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json')
162
+				? json_decode(
163
+						file_get_contents($this->domain->pluginPath() . 'translation-map.json'),
164
+						true
165
+					)
166
+				: array();
167
+		}
168
+		$this->i18n_map = $i18n_map;
169
+	}
170
+
171
+
172
+	/**
173
+	 * Get the jed locale data for a given $handle and domain
174
+	 *
175
+	 * @param string $handle The name for the script handle we want strings returned for.
176
+	 * @param string $domain The i18n domain.
177
+	 * @return array
178
+	 */
179
+	protected function getJedLocaleDataForDomainAndChunk($handle, $domain)
180
+	{
181
+		$translations = $this->getJedLocaleData($domain);
182
+		// get index for adding back after extracting strings for this $chunk.
183
+		$index = $translations[''];
184
+		$translations = $this->getLocaleDataMatchingMap(
185
+			$this->getOriginalStringsForHandleFromMap($handle),
186
+			$translations
187
+		);
188
+		$translations[''] = $index;
189
+		return $translations;
190
+	}
191
+
192
+
193
+	/**
194
+	 * Get locale data for given strings from given translations
195
+	 *
196
+	 * @param array $string_set   This is the subset of strings (msgIds) we want to extract from the translations array.
197
+	 * @param array $translations Translation data to extra strings from.
198
+	 * @return array
199
+	 */
200
+	protected function getLocaleDataMatchingMap(array $string_set, array $translations)
201
+	{
202
+		if (empty($string_set)) {
203
+			return array();
204
+		}
205
+		// some strings with quotes in them will break on the array_flip, so making sure quotes in the string are
206
+		// slashed also filter falsey values.
207
+		$string_set = array_unique(array_filter(wp_slash($string_set)));
208
+		return array_intersect_key($translations, array_flip($string_set));
209
+	}
210
+
211
+
212
+	/**
213
+	 * Get original strings to translate for the given chunk from the map
214
+	 *
215
+	 * @param string $handle The script handle name to get strings from the map for.
216
+	 * @return array
217
+	 */
218
+	protected function getOriginalStringsForHandleFromMap($handle)
219
+	{
220
+		return isset($this->i18n_map[$handle]) ? $this->i18n_map[$handle] : array();
221
+	}
222
+
223
+
224
+	/**
225
+	 * Returns Jed-formatted localization data.
226
+	 *
227
+	 * @param  string $domain Translation domain.
228
+	 * @return array
229
+	 */
230
+	private function getJedLocaleData($domain)
231
+	{
232
+		$translations = get_translations_for_domain($domain);
233
+
234
+		$locale = array(
235
+			'' => array(
236
+				'domain' => $domain,
237
+				'lang'   => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale()
238
+			),
239
+		);
240
+
241
+		if (! empty($translations->headers['Plural-Forms'])) {
242
+			$locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
243
+		}
244
+
245
+		foreach ($translations->entries as $msgid => $entry) {
246
+			$locale[$msgid] = $entry->translations;
247
+		}
248
+
249
+		return $locale;
250
+	}
251 251
 }
252 252
\ No newline at end of file
Please login to merge, or discard this patch.
core/domain/entities/shortcodes/EspressoEventAttendees.php 1 patch
Indentation   +304 added lines, -304 removed lines patch added patch discarded remove patch
@@ -27,334 +27,334 @@
 block discarded – undo
27 27
 class EspressoEventAttendees extends EspressoShortcode
28 28
 {
29 29
 
30
-    private $query_params = array(
31
-        0 => array(),
32
-    );
30
+	private $query_params = array(
31
+		0 => array(),
32
+	);
33 33
 
34
-    private $template_args = array(
35
-        'contacts' => array(),
36
-        'event'    => null,
37
-        'datetime' => null,
38
-        'ticket'   => null,
39
-    );
34
+	private $template_args = array(
35
+		'contacts' => array(),
36
+		'event'    => null,
37
+		'datetime' => null,
38
+		'ticket'   => null,
39
+	);
40 40
 
41
-    /**
42
-     * the actual shortcode tag that gets registered with WordPress
43
-     *
44
-     * @return string
45
-     */
46
-    public function getTag()
47
-    {
48
-        return 'ESPRESSO_EVENT_ATTENDEES';
49
-    }
41
+	/**
42
+	 * the actual shortcode tag that gets registered with WordPress
43
+	 *
44
+	 * @return string
45
+	 */
46
+	public function getTag()
47
+	{
48
+		return 'ESPRESSO_EVENT_ATTENDEES';
49
+	}
50 50
 
51 51
 
52
-    /**
53
-     * the time in seconds to cache the results of the processShortcode() method
54
-     * 0 means the processShortcode() results will NOT be cached at all
55
-     *
56
-     * @return int
57
-     */
58
-    public function cacheExpiration()
59
-    {
60
-        return 0;
61
-    }
52
+	/**
53
+	 * the time in seconds to cache the results of the processShortcode() method
54
+	 * 0 means the processShortcode() results will NOT be cached at all
55
+	 *
56
+	 * @return int
57
+	 */
58
+	public function cacheExpiration()
59
+	{
60
+		return 0;
61
+	}
62 62
 
63 63
 
64
-    /**
65
-     * a place for adding any initialization code that needs to run prior to wp_header().
66
-     * this may be required for shortcodes that utilize a corresponding module,
67
-     * and need to enqueue assets for that module
68
-     *
69
-     * @return void
70
-     */
71
-    public function initializeShortcode()
72
-    {
73
-        $this->shortcodeHasBeenInitialized();
74
-    }
64
+	/**
65
+	 * a place for adding any initialization code that needs to run prior to wp_header().
66
+	 * this may be required for shortcodes that utilize a corresponding module,
67
+	 * and need to enqueue assets for that module
68
+	 *
69
+	 * @return void
70
+	 */
71
+	public function initializeShortcode()
72
+	{
73
+		$this->shortcodeHasBeenInitialized();
74
+	}
75 75
 
76 76
 
77
-    /**
78
-     * process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event.
79
-     *  [ESPRESSO_EVENT_ATTENDEES]
80
-     *  - defaults to attendees for earliest active event, or earliest upcoming event.
81
-     *  [ESPRESSO_EVENT_ATTENDEES event_id=123]
82
-     *  - attendees for specific event.
83
-     *  [ESPRESSO_EVENT_ATTENDEES datetime_id=245]
84
-     *  - attendees for a specific datetime.
85
-     *  [ESPRESSO_EVENT_ATTENDEES ticket_id=123]
86
-     *  - attendees for a specific ticket.
87
-     *  [ESPRESSO_EVENT_ATTENDEES status=all]
88
-     *  - specific registration status (use status id) or all for all attendees regardless of status.
89
-     *  Note default is to only return approved attendees
90
-     *  [ESPRESSO_EVENT_ATTENDEES show_gravatar=true]
91
-     *  - default is to not return gravatar.  Otherwise if this is set then return gravatar for email address given.
92
-     *  [ESPRESSO_EVENT_ATTENDEES display_on_archives=true]
93
-     *  - default is to not display attendees list on archive pages.
94
-     * Note: because of the relationship between event_id, ticket_id, and datetime_id:
95
-     * If more than one of those params is included, then preference is given to the following:
96
-     *  - event_id is used whenever its present and any others are ignored.
97
-     *  - if no event_id then datetime is used whenever its present and any others are ignored.
98
-     *  - otherwise ticket_id is used if present.
99
-     *
100
-     * @param array $attributes
101
-     * @return string
102
-     * @throws EE_Error
103
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
104
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
105
-     * @throws \InvalidArgumentException
106
-     */
107
-    public function processShortcode($attributes = array())
108
-    {
109
-        // grab attributes and merge with defaults
110
-        $attributes = $this->getAttributes((array) $attributes);
111
-        $archive = is_archive();
112
-        $display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN);
113
-        // don't display on archives unless 'display_on_archives' is true
114
-        if ($archive && ! $display_on_archives) {
115
-            return '';
116
-        }
77
+	/**
78
+	 * process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event.
79
+	 *  [ESPRESSO_EVENT_ATTENDEES]
80
+	 *  - defaults to attendees for earliest active event, or earliest upcoming event.
81
+	 *  [ESPRESSO_EVENT_ATTENDEES event_id=123]
82
+	 *  - attendees for specific event.
83
+	 *  [ESPRESSO_EVENT_ATTENDEES datetime_id=245]
84
+	 *  - attendees for a specific datetime.
85
+	 *  [ESPRESSO_EVENT_ATTENDEES ticket_id=123]
86
+	 *  - attendees for a specific ticket.
87
+	 *  [ESPRESSO_EVENT_ATTENDEES status=all]
88
+	 *  - specific registration status (use status id) or all for all attendees regardless of status.
89
+	 *  Note default is to only return approved attendees
90
+	 *  [ESPRESSO_EVENT_ATTENDEES show_gravatar=true]
91
+	 *  - default is to not return gravatar.  Otherwise if this is set then return gravatar for email address given.
92
+	 *  [ESPRESSO_EVENT_ATTENDEES display_on_archives=true]
93
+	 *  - default is to not display attendees list on archive pages.
94
+	 * Note: because of the relationship between event_id, ticket_id, and datetime_id:
95
+	 * If more than one of those params is included, then preference is given to the following:
96
+	 *  - event_id is used whenever its present and any others are ignored.
97
+	 *  - if no event_id then datetime is used whenever its present and any others are ignored.
98
+	 *  - otherwise ticket_id is used if present.
99
+	 *
100
+	 * @param array $attributes
101
+	 * @return string
102
+	 * @throws EE_Error
103
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
104
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
105
+	 * @throws \InvalidArgumentException
106
+	 */
107
+	public function processShortcode($attributes = array())
108
+	{
109
+		// grab attributes and merge with defaults
110
+		$attributes = $this->getAttributes((array) $attributes);
111
+		$archive = is_archive();
112
+		$display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN);
113
+		// don't display on archives unless 'display_on_archives' is true
114
+		if ($archive && ! $display_on_archives) {
115
+			return '';
116
+		}
117 117
 
118
-        try {
119
-            $this->setBaseTemplateArguments($attributes);
120
-            $this->validateEntities($attributes);
121
-            $this->setBaseQueryParams();
122
-        } catch (EntityNotFoundException $e) {
123
-            if (WP_DEBUG) {
124
-                return '<div class="important-notice ee-error">'
125
-                       . $e->getMessage()
126
-                       . '</div>';
127
-            }
128
-            return '';
129
-        }
130
-        $this->setAdditionalQueryParams($attributes);
131
-        // get contacts!
132
-        $this->template_args['contacts'] = EEM_Attendee::instance()->get_all($this->query_params);
133
-        // all set let's load up the template and return.
134
-        return EEH_Template::locate_template(
135
-            'loop-espresso_event_attendees.php',
136
-            $this->template_args
137
-        );
138
-    }
118
+		try {
119
+			$this->setBaseTemplateArguments($attributes);
120
+			$this->validateEntities($attributes);
121
+			$this->setBaseQueryParams();
122
+		} catch (EntityNotFoundException $e) {
123
+			if (WP_DEBUG) {
124
+				return '<div class="important-notice ee-error">'
125
+					   . $e->getMessage()
126
+					   . '</div>';
127
+			}
128
+			return '';
129
+		}
130
+		$this->setAdditionalQueryParams($attributes);
131
+		// get contacts!
132
+		$this->template_args['contacts'] = EEM_Attendee::instance()->get_all($this->query_params);
133
+		// all set let's load up the template and return.
134
+		return EEH_Template::locate_template(
135
+			'loop-espresso_event_attendees.php',
136
+			$this->template_args
137
+		);
138
+	}
139 139
 
140 140
 
141
-    /**
142
-     * merge incoming attributes with filtered defaults
143
-     *
144
-     * @param array $attributes
145
-     * @return array
146
-     */
147
-    private function getAttributes(array $attributes)
148
-    {
149
-        return (array) apply_filters(
150
-            'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts',
151
-            $attributes + array(
152
-                'event_id'            => null,
153
-                'datetime_id'         => null,
154
-                'ticket_id'           => null,
155
-                'status'              => EEM_Registration::status_id_approved,
156
-                'show_gravatar'       => false,
157
-                'display_on_archives' => false,
158
-            )
159
-        );
160
-    }
141
+	/**
142
+	 * merge incoming attributes with filtered defaults
143
+	 *
144
+	 * @param array $attributes
145
+	 * @return array
146
+	 */
147
+	private function getAttributes(array $attributes)
148
+	{
149
+		return (array) apply_filters(
150
+			'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts',
151
+			$attributes + array(
152
+				'event_id'            => null,
153
+				'datetime_id'         => null,
154
+				'ticket_id'           => null,
155
+				'status'              => EEM_Registration::status_id_approved,
156
+				'show_gravatar'       => false,
157
+				'display_on_archives' => false,
158
+			)
159
+		);
160
+	}
161 161
 
162 162
 
163
-    /**
164
-     * Set all the base template arguments from the incoming attributes.
165
-     * * Note: because of the relationship between event_id, ticket_id, and datetime_id:
166
-     * If more than one of those params is included, then preference is given to the following:
167
-     *  - event_id is used whenever its present and any others are ignored.
168
-     *  - if no event_id then datetime is used whenever its present and any others are ignored.
169
-     *  - otherwise ticket_id is used if present.
170
-     *
171
-     * @param array $attributes
172
-     * @throws EE_Error
173
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
174
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
175
-     * @throws \InvalidArgumentException
176
-     */
177
-    private function setBaseTemplateArguments(array $attributes)
178
-    {
179
-        $this->template_args['show_gravatar'] = $attributes['show_gravatar'];
180
-        $this->template_args['event'] = $this->getEvent($attributes);
181
-        $this->template_args['datetime'] = empty($attributes['event_id'])
182
-            ? $this->getDatetime($attributes)
183
-            : null;
184
-        $this->template_args['ticket'] = empty($attributes['datetime_id']) && empty($attributes['event_id'])
185
-            ? $this->getTicket($attributes)
186
-            : null;
187
-    }
163
+	/**
164
+	 * Set all the base template arguments from the incoming attributes.
165
+	 * * Note: because of the relationship between event_id, ticket_id, and datetime_id:
166
+	 * If more than one of those params is included, then preference is given to the following:
167
+	 *  - event_id is used whenever its present and any others are ignored.
168
+	 *  - if no event_id then datetime is used whenever its present and any others are ignored.
169
+	 *  - otherwise ticket_id is used if present.
170
+	 *
171
+	 * @param array $attributes
172
+	 * @throws EE_Error
173
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
174
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
175
+	 * @throws \InvalidArgumentException
176
+	 */
177
+	private function setBaseTemplateArguments(array $attributes)
178
+	{
179
+		$this->template_args['show_gravatar'] = $attributes['show_gravatar'];
180
+		$this->template_args['event'] = $this->getEvent($attributes);
181
+		$this->template_args['datetime'] = empty($attributes['event_id'])
182
+			? $this->getDatetime($attributes)
183
+			: null;
184
+		$this->template_args['ticket'] = empty($attributes['datetime_id']) && empty($attributes['event_id'])
185
+			? $this->getTicket($attributes)
186
+			: null;
187
+	}
188 188
 
189 189
 
190
-    /**
191
-     * Validates the presence of entities for the given attribute values.
192
-     *
193
-     * @param array $attributes
194
-     * @throws EntityNotFoundException
195
-     */
196
-    private function validateEntities(array $attributes)
197
-    {
198
-        if (! $this->template_args['event'] instanceof EE_Event
199
-            || (
200
-                empty($attributes['event_id'])
201
-                && $attributes['datetime_id']
202
-                && ! $this->template_args['datetime'] instanceof EE_Datetime
203
-            )
204
-            || (
205
-                empty($attributes['event_id'])
206
-                && empty($attributes['datetime_id'])
207
-                && $attributes['ticket_id']
208
-                && ! $this->template_args['ticket'] instanceof EE_Ticket
209
-            )
210
-        ) {
211
-            throw new EntityNotFoundException(
212
-                '',
213
-                '',
214
-                esc_html__(
215
-                    'The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly.  Please double check the arguments you used for any typos.  In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.',
216
-                    'event_espresso'
217
-                )
218
-            );
219
-        }
220
-    }
190
+	/**
191
+	 * Validates the presence of entities for the given attribute values.
192
+	 *
193
+	 * @param array $attributes
194
+	 * @throws EntityNotFoundException
195
+	 */
196
+	private function validateEntities(array $attributes)
197
+	{
198
+		if (! $this->template_args['event'] instanceof EE_Event
199
+			|| (
200
+				empty($attributes['event_id'])
201
+				&& $attributes['datetime_id']
202
+				&& ! $this->template_args['datetime'] instanceof EE_Datetime
203
+			)
204
+			|| (
205
+				empty($attributes['event_id'])
206
+				&& empty($attributes['datetime_id'])
207
+				&& $attributes['ticket_id']
208
+				&& ! $this->template_args['ticket'] instanceof EE_Ticket
209
+			)
210
+		) {
211
+			throw new EntityNotFoundException(
212
+				'',
213
+				'',
214
+				esc_html__(
215
+					'The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly.  Please double check the arguments you used for any typos.  In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.',
216
+					'event_espresso'
217
+				)
218
+			);
219
+		}
220
+	}
221 221
 
222 222
 
223
-    /**
224
-     * Sets the query params for the base query elements.
225
-     */
226
-    private function setBaseQueryParams()
227
-    {
228
-        switch (true) {
229
-            case $this->template_args['datetime'] instanceof EE_Datetime:
230
-                $this->query_params = array(
231
-                    0                          => array(
232
-                        'Registration.Ticket.Datetime.DTT_ID' => $this->template_args['datetime']->ID(),
233
-                    ),
234
-                    'default_where_conditions' => 'this_model_only',
235
-                );
236
-                break;
237
-            case $this->template_args['ticket'] instanceof EE_Ticket:
238
-                $this->query_params[0] = array(
239
-                    'Registration.TKT_ID' => $this->template_args['ticket']->ID(),
240
-                );
241
-                break;
242
-            case $this->template_args['event'] instanceof EE_Event:
243
-                $this->query_params[0] = array(
244
-                    'Registration.EVT_ID' => $this->template_args['event']->ID(),
245
-                );
246
-                break;
247
-        }
248
-    }
223
+	/**
224
+	 * Sets the query params for the base query elements.
225
+	 */
226
+	private function setBaseQueryParams()
227
+	{
228
+		switch (true) {
229
+			case $this->template_args['datetime'] instanceof EE_Datetime:
230
+				$this->query_params = array(
231
+					0                          => array(
232
+						'Registration.Ticket.Datetime.DTT_ID' => $this->template_args['datetime']->ID(),
233
+					),
234
+					'default_where_conditions' => 'this_model_only',
235
+				);
236
+				break;
237
+			case $this->template_args['ticket'] instanceof EE_Ticket:
238
+				$this->query_params[0] = array(
239
+					'Registration.TKT_ID' => $this->template_args['ticket']->ID(),
240
+				);
241
+				break;
242
+			case $this->template_args['event'] instanceof EE_Event:
243
+				$this->query_params[0] = array(
244
+					'Registration.EVT_ID' => $this->template_args['event']->ID(),
245
+				);
246
+				break;
247
+		}
248
+	}
249 249
 
250 250
 
251
-    /**
252
-     * @param array $attributes
253
-     * @return EE_Event|null
254
-     * @throws EE_Error
255
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
256
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
257
-     * @throws \InvalidArgumentException
258
-     */
259
-    private function getEvent(array $attributes)
260
-    {
261
-        switch (true) {
262
-            case ! empty($attributes['event_id']):
263
-                $event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']);
264
-                break;
265
-            case ! empty($attributes['datetime_id']):
266
-                $event = EEM_Event::instance()->get_one(array(
267
-                    array(
268
-                        'Datetime.DTT_ID' => $attributes['datetime_id'],
269
-                    ),
270
-                ));
271
-                break;
272
-            case ! empty($attributes['ticket_id']):
273
-                $event = EEM_Event::instance()->get_one(array(
274
-                    array(
275
-                        'Datetime.Ticket.TKT_ID' => $attributes['ticket_id'],
276
-                    ),
277
-                    'default_where_conditions' => 'none'
278
-                ));
279
-                break;
280
-            case is_espresso_event():
281
-                $event = EEH_Event_View::get_event();
282
-                break;
283
-            default:
284
-                // one last shot...
285
-                // try getting the earliest active event
286
-                $events = EEM_Event::instance()->get_active_events(array(
287
-                    'limit'    => 1,
288
-                    'order_by' => array('Datetime.DTT_EVT_start' => 'ASC'),
289
-                ));
290
-                //  if none then get the next upcoming
291
-                $events = empty($events)
292
-                    ? EEM_Event::instance()->get_upcoming_events(array(
293
-                        'limit'    => 1,
294
-                        'order_by' => array('Datetime.DTT_EVT_start' => 'ASC'),
295
-                    ))
296
-                    : $events;
297
-                $event = reset($events);
298
-        }
251
+	/**
252
+	 * @param array $attributes
253
+	 * @return EE_Event|null
254
+	 * @throws EE_Error
255
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
256
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
257
+	 * @throws \InvalidArgumentException
258
+	 */
259
+	private function getEvent(array $attributes)
260
+	{
261
+		switch (true) {
262
+			case ! empty($attributes['event_id']):
263
+				$event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']);
264
+				break;
265
+			case ! empty($attributes['datetime_id']):
266
+				$event = EEM_Event::instance()->get_one(array(
267
+					array(
268
+						'Datetime.DTT_ID' => $attributes['datetime_id'],
269
+					),
270
+				));
271
+				break;
272
+			case ! empty($attributes['ticket_id']):
273
+				$event = EEM_Event::instance()->get_one(array(
274
+					array(
275
+						'Datetime.Ticket.TKT_ID' => $attributes['ticket_id'],
276
+					),
277
+					'default_where_conditions' => 'none'
278
+				));
279
+				break;
280
+			case is_espresso_event():
281
+				$event = EEH_Event_View::get_event();
282
+				break;
283
+			default:
284
+				// one last shot...
285
+				// try getting the earliest active event
286
+				$events = EEM_Event::instance()->get_active_events(array(
287
+					'limit'    => 1,
288
+					'order_by' => array('Datetime.DTT_EVT_start' => 'ASC'),
289
+				));
290
+				//  if none then get the next upcoming
291
+				$events = empty($events)
292
+					? EEM_Event::instance()->get_upcoming_events(array(
293
+						'limit'    => 1,
294
+						'order_by' => array('Datetime.DTT_EVT_start' => 'ASC'),
295
+					))
296
+					: $events;
297
+				$event = reset($events);
298
+		}
299 299
 
300
-        return $event instanceof EE_Event ? $event : null;
301
-    }
300
+		return $event instanceof EE_Event ? $event : null;
301
+	}
302 302
 
303 303
 
304
-    /**
305
-     * @param array $attributes
306
-     * @return EE_Datetime|null
307
-     * @throws EE_Error
308
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
309
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
310
-     * @throws \InvalidArgumentException
311
-     */
312
-    private function getDatetime(array $attributes)
313
-    {
314
-        if (! empty($attributes['datetime_id'])) {
315
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']);
316
-            if ($datetime instanceof EE_Datetime) {
317
-                return $datetime;
318
-            }
319
-        }
320
-        return null;
321
-    }
304
+	/**
305
+	 * @param array $attributes
306
+	 * @return EE_Datetime|null
307
+	 * @throws EE_Error
308
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
309
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
310
+	 * @throws \InvalidArgumentException
311
+	 */
312
+	private function getDatetime(array $attributes)
313
+	{
314
+		if (! empty($attributes['datetime_id'])) {
315
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']);
316
+			if ($datetime instanceof EE_Datetime) {
317
+				return $datetime;
318
+			}
319
+		}
320
+		return null;
321
+	}
322 322
 
323 323
 
324
-    /**
325
-     * @param array $attributes
326
-     * @return \EE_Base_Class|EE_Ticket|null
327
-     * @throws EE_Error
328
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
329
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
330
-     * @throws \InvalidArgumentException
331
-     */
332
-    private function getTicket(array $attributes)
333
-    {
334
-        if (! empty($attributes['ticket_id'])) {
335
-            $ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']);
336
-            if ($ticket instanceof EE_Ticket) {
337
-                return $ticket;
338
-            }
339
-        }
340
-        return null;
341
-    }
324
+	/**
325
+	 * @param array $attributes
326
+	 * @return \EE_Base_Class|EE_Ticket|null
327
+	 * @throws EE_Error
328
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
329
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
330
+	 * @throws \InvalidArgumentException
331
+	 */
332
+	private function getTicket(array $attributes)
333
+	{
334
+		if (! empty($attributes['ticket_id'])) {
335
+			$ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']);
336
+			if ($ticket instanceof EE_Ticket) {
337
+				return $ticket;
338
+			}
339
+		}
340
+		return null;
341
+	}
342 342
 
343 343
 
344
-    /**
345
-     * @param array $attributes
346
-     * @throws EE_Error
347
-     */
348
-    private function setAdditionalQueryParams(array $attributes)
349
-    {
350
-        $reg_status_array = EEM_Registration::reg_status_array();
351
-        if ($attributes['status'] !== 'all' && isset($reg_status_array[ $attributes['status'] ])) {
352
-            $this->query_params[0]['Registration.STS_ID'] = $attributes['status'];
353
-        }
354
-        $this->query_params['group_by'] = array('ATT_ID');
355
-        $this->query_params['order_by'] = (array) apply_filters(
356
-            'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by',
357
-            array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC')
358
-        );
359
-    }
344
+	/**
345
+	 * @param array $attributes
346
+	 * @throws EE_Error
347
+	 */
348
+	private function setAdditionalQueryParams(array $attributes)
349
+	{
350
+		$reg_status_array = EEM_Registration::reg_status_array();
351
+		if ($attributes['status'] !== 'all' && isset($reg_status_array[ $attributes['status'] ])) {
352
+			$this->query_params[0]['Registration.STS_ID'] = $attributes['status'];
353
+		}
354
+		$this->query_params['group_by'] = array('ATT_ID');
355
+		$this->query_params['order_by'] = (array) apply_filters(
356
+			'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by',
357
+			array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC')
358
+		);
359
+	}
360 360
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.65.rc.020');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.65.rc.020');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.