@@ -21,8 +21,8 @@ |
||
21 | 21 | |
22 | 22 | |
23 | 23 | <div id="postbox-container-2" class="postbox-container"> |
24 | - <?php do_meta_boxes( $current_page, 'normal', NULL ); ?> |
|
25 | - <?php do_meta_boxes( $current_page, 'advanced', NULL ); ?> |
|
24 | + <?php do_meta_boxes($current_page, 'normal', NULL); ?> |
|
25 | + <?php do_meta_boxes($current_page, 'advanced', NULL); ?> |
|
26 | 26 | </div> |
27 | 27 | <!-- postbox-container-2 --> |
28 | 28 | <div class="clear"></div> |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | |
53 | 53 | /** |
54 | 54 | * @param string $word |
55 | - * @return mixed |
|
55 | + * @return string |
|
56 | 56 | */ |
57 | 57 | public static function singularize_and_upper( $word ) { |
58 | 58 | return str_replace( ' ', '_', self::humanize( self::singularize( $word ), 'all' ) ); |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | |
380 | 380 | |
381 | 381 | /** |
382 | - * @param $string |
|
382 | + * @param string $string |
|
383 | 383 | * @return string |
384 | 384 | */ |
385 | 385 | public static function add_indefinite_article($string) { |
@@ -35,357 +35,357 @@ |
||
35 | 35 | * @version $Revision 0.1 $ |
36 | 36 | */ |
37 | 37 | class EEH_Inflector{ |
38 | - // ------ CLASS METHODS ------ // |
|
39 | - // ---- Public methods ---- // |
|
40 | - // {{{ pluralize() |
|
38 | + // ------ CLASS METHODS ------ // |
|
39 | + // ---- Public methods ---- // |
|
40 | + // {{{ pluralize() |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * Just calls self::pluralize and strtolower on $word and returns it |
44 | 44 | * @param string $word |
45 | 45 | * @return string |
46 | 46 | */ |
47 | - public static function pluralize_and_lower( $word ){ |
|
47 | + public static function pluralize_and_lower( $word ){ |
|
48 | 48 | return strtolower( self::pluralize( $word ) ); |
49 | 49 | } |
50 | 50 | |
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * @param string $word |
|
55 | - * @return mixed |
|
56 | - */ |
|
57 | - public static function singularize_and_upper( $word ) { |
|
53 | + /** |
|
54 | + * @param string $word |
|
55 | + * @return mixed |
|
56 | + */ |
|
57 | + public static function singularize_and_upper( $word ) { |
|
58 | 58 | return str_replace( ' ', '_', self::humanize( self::singularize( $word ), 'all' ) ); |
59 | 59 | } |
60 | 60 | |
61 | 61 | |
62 | 62 | |
63 | - /** |
|
64 | - * Pluralizes English nouns. |
|
65 | - * |
|
66 | - * @access public |
|
67 | - * @static |
|
68 | - * @param string $word English noun to pluralize |
|
69 | - * @return string Plural noun |
|
70 | - */ |
|
71 | - public static function pluralize($word){ |
|
72 | - $plural = array( |
|
73 | - '/(quiz)$/i' => '\1zes', |
|
74 | - '/^(ox)$/i' => '\1en', |
|
75 | - '/([m|l])ouse$/i' => '\1ice', |
|
76 | - '/(matr|vert|ind)ix|ex$/i' => '\1ices', |
|
77 | - '/(x|ch|ss|sh)$/i' => '\1es', |
|
78 | - '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
79 | - '/([^aeiouy]|qu)y$/i' => '\1ies', |
|
80 | - '/(hive)$/i' => '\1s', |
|
81 | - '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves', |
|
82 | - '/sis$/i' => 'ses', |
|
83 | - '/([ti])um$/i' => '\1a', |
|
84 | - '/(buffal|tomat)o$/i' => '\1oes', |
|
85 | - '/(bu)s$/i' => '\1ses', |
|
86 | - '/(alias|status)/i' => '\1es', |
|
87 | - '/(octop|vir)us$/i' => '\1i', |
|
88 | - '/(ax|test)is$/i' => '\1es', |
|
89 | - '/s$/i' => 's', |
|
90 | - '/$/' => 's'); |
|
91 | - |
|
92 | - $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
93 | - |
|
94 | - $irregular = array( |
|
95 | - 'person' => 'people', |
|
96 | - 'man' => 'men', |
|
97 | - 'child' => 'children', |
|
98 | - 'sex' => 'sexes', |
|
99 | - 'move' => 'moves'); |
|
100 | - |
|
101 | - $lowercased_word = strtolower($word); |
|
102 | - |
|
103 | - foreach($uncountable as $_uncountable){ |
|
104 | - if(substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && //even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter |
|
63 | + /** |
|
64 | + * Pluralizes English nouns. |
|
65 | + * |
|
66 | + * @access public |
|
67 | + * @static |
|
68 | + * @param string $word English noun to pluralize |
|
69 | + * @return string Plural noun |
|
70 | + */ |
|
71 | + public static function pluralize($word){ |
|
72 | + $plural = array( |
|
73 | + '/(quiz)$/i' => '\1zes', |
|
74 | + '/^(ox)$/i' => '\1en', |
|
75 | + '/([m|l])ouse$/i' => '\1ice', |
|
76 | + '/(matr|vert|ind)ix|ex$/i' => '\1ices', |
|
77 | + '/(x|ch|ss|sh)$/i' => '\1es', |
|
78 | + '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
79 | + '/([^aeiouy]|qu)y$/i' => '\1ies', |
|
80 | + '/(hive)$/i' => '\1s', |
|
81 | + '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves', |
|
82 | + '/sis$/i' => 'ses', |
|
83 | + '/([ti])um$/i' => '\1a', |
|
84 | + '/(buffal|tomat)o$/i' => '\1oes', |
|
85 | + '/(bu)s$/i' => '\1ses', |
|
86 | + '/(alias|status)/i' => '\1es', |
|
87 | + '/(octop|vir)us$/i' => '\1i', |
|
88 | + '/(ax|test)is$/i' => '\1es', |
|
89 | + '/s$/i' => 's', |
|
90 | + '/$/' => 's'); |
|
91 | + |
|
92 | + $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
93 | + |
|
94 | + $irregular = array( |
|
95 | + 'person' => 'people', |
|
96 | + 'man' => 'men', |
|
97 | + 'child' => 'children', |
|
98 | + 'sex' => 'sexes', |
|
99 | + 'move' => 'moves'); |
|
100 | + |
|
101 | + $lowercased_word = strtolower($word); |
|
102 | + |
|
103 | + foreach($uncountable as $_uncountable){ |
|
104 | + if(substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && //even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter |
|
105 | 105 | ! ctype_alpha( $lowercased_word[ strlen( $lowercased_word ) - strlen($_uncountable) ] ) ){ |
106 | - return $word; |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - foreach($irregular as $_plural => $_singular){ |
|
111 | - if(preg_match('/(' . $_plural . ')$/i', $word, $arr)){ |
|
112 | - return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word); |
|
113 | - } |
|
114 | - } |
|
115 | - |
|
116 | - foreach($plural as $rule => $replacement){ |
|
117 | - if(preg_match($rule, $word)){ |
|
118 | - return preg_replace($rule, $replacement, $word); |
|
119 | - } |
|
120 | - } |
|
121 | - return false; |
|
122 | - } |
|
123 | - |
|
124 | - // }}} |
|
125 | - // {{{ singularize() |
|
126 | - |
|
127 | - /** |
|
128 | - * Singularizes English nouns. |
|
129 | - * |
|
130 | - * @access public |
|
131 | - * @static |
|
132 | - * @param string $word English noun to singularize |
|
133 | - * @return string Singular noun. |
|
134 | - */ |
|
135 | - public static function singularize($word){ |
|
136 | - $singular = array( |
|
137 | - '/(quiz)zes$/i' => '\1', |
|
138 | - '/(matr)ices$/i' => '\1ix', |
|
139 | - '/(vert|ind)ices$/i' => '\1ex', |
|
140 | - '/^(ox)en/i' => '\1', |
|
141 | - '/(alias|status)es$/i' => '\1', |
|
142 | - '/([octop|vir])i$/i' => '\1us', |
|
143 | - '/(cris|ax|test)es$/i' => '\1is', |
|
144 | - '/(shoe)s$/i' => '\1', |
|
145 | - '/(o)es$/i' => '\1', |
|
146 | - '/(bus)es$/i' => '\1', |
|
147 | - '/([m|l])ice$/i' => '\1ouse', |
|
148 | - '/(x|ch|ss|sh)es$/i' => '\1', |
|
149 | - '/(m)ovies$/i' => '\1ovie', |
|
150 | - '/(s)eries$/i' => '\1eries', |
|
151 | - '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
152 | - '/([lr])ves$/i' => '\1f', |
|
153 | - '/(tive)s$/i' => '\1', |
|
154 | - '/(hive)s$/i' => '\1', |
|
155 | - '/([^f])ves$/i' => '\1fe', |
|
156 | - '/(^analy)ses$/i' => '\1sis', |
|
157 | - '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis', |
|
158 | - '/([ti])a$/i' => '\1um', |
|
159 | - '/(n)ews$/i' => '\1ews', |
|
160 | - '/s$/i' => '', |
|
161 | - ); |
|
162 | - |
|
163 | - $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
164 | - |
|
165 | - $irregular = array( |
|
166 | - 'person' => 'people', |
|
167 | - 'man' => 'men', |
|
168 | - 'child' => 'children', |
|
169 | - 'sex' => 'sexes', |
|
170 | - 'move' => 'moves'); |
|
171 | - |
|
172 | - $lowercased_word = strtolower($word); |
|
173 | - foreach($uncountable as $_uncountable){ |
|
174 | - if(substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable){ |
|
175 | - return $word; |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - foreach($irregular as $_plural => $_singular){ |
|
180 | - if(preg_match('/(' . $_singular . ')$/i', $word, $arr)){ |
|
181 | - return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word); |
|
182 | - } |
|
183 | - } |
|
184 | - |
|
185 | - foreach($singular as $rule => $replacement){ |
|
186 | - if(preg_match($rule, $word)){ |
|
187 | - return preg_replace($rule, $replacement, $word); |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - return $word; |
|
192 | - } |
|
193 | - |
|
194 | - // }}} |
|
195 | - // {{{ titleize() |
|
196 | - |
|
197 | - /** |
|
198 | - * Converts an underscored or CamelCase word into a English |
|
199 | - * sentence. |
|
200 | - * |
|
201 | - * The titleize static function converts text like "WelcomePage", |
|
202 | - * "welcome_page" or "welcome page" to this "Welcome |
|
203 | - * Page". |
|
204 | - * If second parameter is set to 'first' it will only |
|
205 | - * capitalize the first character of the title. |
|
206 | - * |
|
207 | - * @access public |
|
208 | - * @static |
|
209 | - * @param string $word Word to format as tile |
|
210 | - * @param string $uppercase If set to 'first' it will only uppercase the |
|
211 | - * first character. Otherwise it will uppercase all |
|
212 | - * the words in the title. |
|
213 | - * @return string Text formatted as title |
|
214 | - */ |
|
215 | - public static function titleize($word, $uppercase = ''){ |
|
216 | - $uppercase = $uppercase === 'first' ? 'ucfirst' : 'ucwords'; |
|
217 | - return $uppercase(EEH_Inflector::humanize(EEH_Inflector::underscore($word))); |
|
218 | - } |
|
219 | - |
|
220 | - // }}} |
|
221 | - // {{{ camelize() |
|
222 | - |
|
223 | - /** |
|
224 | - * Returns given word as CamelCased |
|
225 | - * |
|
226 | - * Converts a word like "send_email" to "SendEmail". It |
|
227 | - * will remove non alphanumeric character from the word, so |
|
228 | - * "who's online" will be converted to "WhoSOnline" |
|
229 | - * |
|
230 | - * @access public |
|
231 | - * @static |
|
232 | - * @see variablize |
|
233 | - * @param string $word Word to convert to camel case |
|
234 | - * @return string UpperCamelCasedWord |
|
235 | - */ |
|
236 | - public static function camelize($word){ |
|
237 | - return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word))); |
|
238 | - } |
|
239 | - |
|
240 | - // }}} |
|
241 | - // {{{ underscore() |
|
242 | - |
|
243 | - /** |
|
244 | - * Converts a word "into_it_s_underscored_version" |
|
245 | - * |
|
246 | - * Convert any "CamelCased" or "ordinary Word" into an |
|
247 | - * "underscored_word". |
|
248 | - * |
|
249 | - * This can be really useful for creating friendly URLs. |
|
250 | - * |
|
251 | - * @access public |
|
252 | - * @static |
|
253 | - * @param string $word Word to underscore |
|
254 | - * @return string Underscored word |
|
255 | - */ |
|
256 | - public static function underscore($word){ |
|
257 | - return strtolower(preg_replace('/[^A-Z^a-z^0-9]+/', '_', preg_replace('/([a-zd])([A-Z])/', '1_2', preg_replace('/([A-Z]+)([A-Z][a-z])/', '1_2', $word)))); |
|
258 | - } |
|
259 | - |
|
260 | - // }}} |
|
261 | - // {{{ humanize() |
|
262 | - |
|
263 | - /** |
|
264 | - * Returns a human-readable string from $word |
|
265 | - * |
|
266 | - * Returns a human-readable string from $word, by replacing |
|
267 | - * underscores with a space, and by upper-casing the initial |
|
268 | - * character by default. |
|
269 | - * |
|
270 | - * If you need to uppercase all the words you just have to |
|
271 | - * pass 'all' as a second parameter. |
|
272 | - * |
|
273 | - * @access public |
|
274 | - * @static |
|
275 | - * @param string $word String to "humanize" |
|
276 | - * @param string $uppercase If set to 'all' it will uppercase all the words |
|
277 | - * instead of just the first one. |
|
278 | - * @return string Human-readable word |
|
279 | - */ |
|
280 | - public static function humanize($word, $uppercase = ''){ |
|
106 | + return $word; |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + foreach($irregular as $_plural => $_singular){ |
|
111 | + if(preg_match('/(' . $_plural . ')$/i', $word, $arr)){ |
|
112 | + return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word); |
|
113 | + } |
|
114 | + } |
|
115 | + |
|
116 | + foreach($plural as $rule => $replacement){ |
|
117 | + if(preg_match($rule, $word)){ |
|
118 | + return preg_replace($rule, $replacement, $word); |
|
119 | + } |
|
120 | + } |
|
121 | + return false; |
|
122 | + } |
|
123 | + |
|
124 | + // }}} |
|
125 | + // {{{ singularize() |
|
126 | + |
|
127 | + /** |
|
128 | + * Singularizes English nouns. |
|
129 | + * |
|
130 | + * @access public |
|
131 | + * @static |
|
132 | + * @param string $word English noun to singularize |
|
133 | + * @return string Singular noun. |
|
134 | + */ |
|
135 | + public static function singularize($word){ |
|
136 | + $singular = array( |
|
137 | + '/(quiz)zes$/i' => '\1', |
|
138 | + '/(matr)ices$/i' => '\1ix', |
|
139 | + '/(vert|ind)ices$/i' => '\1ex', |
|
140 | + '/^(ox)en/i' => '\1', |
|
141 | + '/(alias|status)es$/i' => '\1', |
|
142 | + '/([octop|vir])i$/i' => '\1us', |
|
143 | + '/(cris|ax|test)es$/i' => '\1is', |
|
144 | + '/(shoe)s$/i' => '\1', |
|
145 | + '/(o)es$/i' => '\1', |
|
146 | + '/(bus)es$/i' => '\1', |
|
147 | + '/([m|l])ice$/i' => '\1ouse', |
|
148 | + '/(x|ch|ss|sh)es$/i' => '\1', |
|
149 | + '/(m)ovies$/i' => '\1ovie', |
|
150 | + '/(s)eries$/i' => '\1eries', |
|
151 | + '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
152 | + '/([lr])ves$/i' => '\1f', |
|
153 | + '/(tive)s$/i' => '\1', |
|
154 | + '/(hive)s$/i' => '\1', |
|
155 | + '/([^f])ves$/i' => '\1fe', |
|
156 | + '/(^analy)ses$/i' => '\1sis', |
|
157 | + '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis', |
|
158 | + '/([ti])a$/i' => '\1um', |
|
159 | + '/(n)ews$/i' => '\1ews', |
|
160 | + '/s$/i' => '', |
|
161 | + ); |
|
162 | + |
|
163 | + $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
164 | + |
|
165 | + $irregular = array( |
|
166 | + 'person' => 'people', |
|
167 | + 'man' => 'men', |
|
168 | + 'child' => 'children', |
|
169 | + 'sex' => 'sexes', |
|
170 | + 'move' => 'moves'); |
|
171 | + |
|
172 | + $lowercased_word = strtolower($word); |
|
173 | + foreach($uncountable as $_uncountable){ |
|
174 | + if(substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable){ |
|
175 | + return $word; |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + foreach($irregular as $_plural => $_singular){ |
|
180 | + if(preg_match('/(' . $_singular . ')$/i', $word, $arr)){ |
|
181 | + return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word); |
|
182 | + } |
|
183 | + } |
|
184 | + |
|
185 | + foreach($singular as $rule => $replacement){ |
|
186 | + if(preg_match($rule, $word)){ |
|
187 | + return preg_replace($rule, $replacement, $word); |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + return $word; |
|
192 | + } |
|
193 | + |
|
194 | + // }}} |
|
195 | + // {{{ titleize() |
|
196 | + |
|
197 | + /** |
|
198 | + * Converts an underscored or CamelCase word into a English |
|
199 | + * sentence. |
|
200 | + * |
|
201 | + * The titleize static function converts text like "WelcomePage", |
|
202 | + * "welcome_page" or "welcome page" to this "Welcome |
|
203 | + * Page". |
|
204 | + * If second parameter is set to 'first' it will only |
|
205 | + * capitalize the first character of the title. |
|
206 | + * |
|
207 | + * @access public |
|
208 | + * @static |
|
209 | + * @param string $word Word to format as tile |
|
210 | + * @param string $uppercase If set to 'first' it will only uppercase the |
|
211 | + * first character. Otherwise it will uppercase all |
|
212 | + * the words in the title. |
|
213 | + * @return string Text formatted as title |
|
214 | + */ |
|
215 | + public static function titleize($word, $uppercase = ''){ |
|
216 | + $uppercase = $uppercase === 'first' ? 'ucfirst' : 'ucwords'; |
|
217 | + return $uppercase(EEH_Inflector::humanize(EEH_Inflector::underscore($word))); |
|
218 | + } |
|
219 | + |
|
220 | + // }}} |
|
221 | + // {{{ camelize() |
|
222 | + |
|
223 | + /** |
|
224 | + * Returns given word as CamelCased |
|
225 | + * |
|
226 | + * Converts a word like "send_email" to "SendEmail". It |
|
227 | + * will remove non alphanumeric character from the word, so |
|
228 | + * "who's online" will be converted to "WhoSOnline" |
|
229 | + * |
|
230 | + * @access public |
|
231 | + * @static |
|
232 | + * @see variablize |
|
233 | + * @param string $word Word to convert to camel case |
|
234 | + * @return string UpperCamelCasedWord |
|
235 | + */ |
|
236 | + public static function camelize($word){ |
|
237 | + return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word))); |
|
238 | + } |
|
239 | + |
|
240 | + // }}} |
|
241 | + // {{{ underscore() |
|
242 | + |
|
243 | + /** |
|
244 | + * Converts a word "into_it_s_underscored_version" |
|
245 | + * |
|
246 | + * Convert any "CamelCased" or "ordinary Word" into an |
|
247 | + * "underscored_word". |
|
248 | + * |
|
249 | + * This can be really useful for creating friendly URLs. |
|
250 | + * |
|
251 | + * @access public |
|
252 | + * @static |
|
253 | + * @param string $word Word to underscore |
|
254 | + * @return string Underscored word |
|
255 | + */ |
|
256 | + public static function underscore($word){ |
|
257 | + return strtolower(preg_replace('/[^A-Z^a-z^0-9]+/', '_', preg_replace('/([a-zd])([A-Z])/', '1_2', preg_replace('/([A-Z]+)([A-Z][a-z])/', '1_2', $word)))); |
|
258 | + } |
|
259 | + |
|
260 | + // }}} |
|
261 | + // {{{ humanize() |
|
262 | + |
|
263 | + /** |
|
264 | + * Returns a human-readable string from $word |
|
265 | + * |
|
266 | + * Returns a human-readable string from $word, by replacing |
|
267 | + * underscores with a space, and by upper-casing the initial |
|
268 | + * character by default. |
|
269 | + * |
|
270 | + * If you need to uppercase all the words you just have to |
|
271 | + * pass 'all' as a second parameter. |
|
272 | + * |
|
273 | + * @access public |
|
274 | + * @static |
|
275 | + * @param string $word String to "humanize" |
|
276 | + * @param string $uppercase If set to 'all' it will uppercase all the words |
|
277 | + * instead of just the first one. |
|
278 | + * @return string Human-readable word |
|
279 | + */ |
|
280 | + public static function humanize($word, $uppercase = ''){ |
|
281 | 281 | //make special exceptions for acronyms |
282 | 282 | $word = str_replace('wp_', 'WP_', $word ); |
283 | - $uppercase = $uppercase === 'all' ? 'ucwords' : 'ucfirst'; |
|
284 | - return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word))); |
|
285 | - } |
|
286 | - |
|
287 | - // }}} |
|
288 | - // {{{ variablize() |
|
289 | - |
|
290 | - /** |
|
291 | - * Same as camelize but first char is underscored |
|
292 | - * |
|
293 | - * Converts a word like "send_email" to "sendEmail". It |
|
294 | - * will remove non alphanumeric character from the word, so |
|
295 | - * "who's online" will be converted to "whoSOnline" |
|
296 | - * |
|
297 | - * @access public |
|
298 | - * @static |
|
299 | - * @see camelize |
|
300 | - * @param string $word Word to lowerCamelCase |
|
301 | - * @return string Returns a lowerCamelCasedWord |
|
302 | - */ |
|
303 | - public static function variablize($word){ |
|
304 | - $word = EEH_Inflector::camelize($word); |
|
305 | - return strtolower($word[0]) . substr($word, 1); |
|
306 | - } |
|
307 | - |
|
308 | - // }}} |
|
309 | - // {{{ tableize() |
|
310 | - |
|
311 | - /** |
|
312 | - * Converts a class name to its table name according to rails |
|
313 | - * naming conventions. |
|
314 | - * |
|
315 | - * Converts "Person" to "people" |
|
316 | - * |
|
317 | - * @access public |
|
318 | - * @static |
|
319 | - * @see classify |
|
320 | - * @param string $class_name Class name for getting related table_name. |
|
321 | - * @return string plural_table_name |
|
322 | - */ |
|
323 | - public static function tableize($class_name){ |
|
324 | - return EEH_Inflector::pluralize(EEH_Inflector::underscore($class_name)); |
|
325 | - } |
|
326 | - |
|
327 | - // }}} |
|
328 | - // {{{ classify() |
|
329 | - |
|
330 | - /** |
|
331 | - * Converts a table name to its class name according to rails |
|
332 | - * naming conventions. |
|
333 | - * |
|
334 | - * Converts "people" to "Person" |
|
335 | - * |
|
336 | - * @access public |
|
337 | - * @static |
|
338 | - * @see tableize |
|
339 | - * @param string $table_name Table name for getting related ClassName. |
|
340 | - * @return string SingularClassName |
|
341 | - */ |
|
342 | - public static function classify($table_name){ |
|
343 | - return EEH_Inflector::camelize(EEH_Inflector::singularize($table_name)); |
|
344 | - } |
|
345 | - |
|
346 | - // }}} |
|
347 | - // {{{ ordinalize() |
|
348 | - |
|
349 | - /** |
|
350 | - * Converts number to its ordinal English form. |
|
351 | - * |
|
352 | - * This method converts 13 to 13th, 2 to 2nd ... |
|
353 | - * |
|
354 | - * @access public |
|
355 | - * @static |
|
356 | - * @param integer $number Number to get its ordinal value |
|
357 | - * @return string Ordinal representation of given string. |
|
358 | - */ |
|
359 | - public static function ordinalize($number){ |
|
360 | - if(in_array(($number % 100), range(11, 13))){ |
|
361 | - return $number . 'th'; |
|
362 | - }else{ |
|
363 | - switch(($number % 10)){ |
|
364 | - case 1: |
|
365 | - return $number . 'st'; |
|
366 | - break; |
|
367 | - case 2: |
|
368 | - return $number . 'nd'; |
|
369 | - break; |
|
370 | - case 3: |
|
371 | - return $number . 'rd'; |
|
372 | - default: |
|
373 | - return $number . 'th'; |
|
374 | - break; |
|
375 | - } |
|
376 | - } |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * @param $string |
|
383 | - * @return string |
|
384 | - */ |
|
385 | - public static function add_indefinite_article($string) { |
|
386 | - if (strtolower($string) === 'null') { |
|
387 | - return $string; |
|
388 | - } |
|
389 | - return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string; |
|
390 | - } |
|
283 | + $uppercase = $uppercase === 'all' ? 'ucwords' : 'ucfirst'; |
|
284 | + return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word))); |
|
285 | + } |
|
286 | + |
|
287 | + // }}} |
|
288 | + // {{{ variablize() |
|
289 | + |
|
290 | + /** |
|
291 | + * Same as camelize but first char is underscored |
|
292 | + * |
|
293 | + * Converts a word like "send_email" to "sendEmail". It |
|
294 | + * will remove non alphanumeric character from the word, so |
|
295 | + * "who's online" will be converted to "whoSOnline" |
|
296 | + * |
|
297 | + * @access public |
|
298 | + * @static |
|
299 | + * @see camelize |
|
300 | + * @param string $word Word to lowerCamelCase |
|
301 | + * @return string Returns a lowerCamelCasedWord |
|
302 | + */ |
|
303 | + public static function variablize($word){ |
|
304 | + $word = EEH_Inflector::camelize($word); |
|
305 | + return strtolower($word[0]) . substr($word, 1); |
|
306 | + } |
|
307 | + |
|
308 | + // }}} |
|
309 | + // {{{ tableize() |
|
310 | + |
|
311 | + /** |
|
312 | + * Converts a class name to its table name according to rails |
|
313 | + * naming conventions. |
|
314 | + * |
|
315 | + * Converts "Person" to "people" |
|
316 | + * |
|
317 | + * @access public |
|
318 | + * @static |
|
319 | + * @see classify |
|
320 | + * @param string $class_name Class name for getting related table_name. |
|
321 | + * @return string plural_table_name |
|
322 | + */ |
|
323 | + public static function tableize($class_name){ |
|
324 | + return EEH_Inflector::pluralize(EEH_Inflector::underscore($class_name)); |
|
325 | + } |
|
326 | + |
|
327 | + // }}} |
|
328 | + // {{{ classify() |
|
329 | + |
|
330 | + /** |
|
331 | + * Converts a table name to its class name according to rails |
|
332 | + * naming conventions. |
|
333 | + * |
|
334 | + * Converts "people" to "Person" |
|
335 | + * |
|
336 | + * @access public |
|
337 | + * @static |
|
338 | + * @see tableize |
|
339 | + * @param string $table_name Table name for getting related ClassName. |
|
340 | + * @return string SingularClassName |
|
341 | + */ |
|
342 | + public static function classify($table_name){ |
|
343 | + return EEH_Inflector::camelize(EEH_Inflector::singularize($table_name)); |
|
344 | + } |
|
345 | + |
|
346 | + // }}} |
|
347 | + // {{{ ordinalize() |
|
348 | + |
|
349 | + /** |
|
350 | + * Converts number to its ordinal English form. |
|
351 | + * |
|
352 | + * This method converts 13 to 13th, 2 to 2nd ... |
|
353 | + * |
|
354 | + * @access public |
|
355 | + * @static |
|
356 | + * @param integer $number Number to get its ordinal value |
|
357 | + * @return string Ordinal representation of given string. |
|
358 | + */ |
|
359 | + public static function ordinalize($number){ |
|
360 | + if(in_array(($number % 100), range(11, 13))){ |
|
361 | + return $number . 'th'; |
|
362 | + }else{ |
|
363 | + switch(($number % 10)){ |
|
364 | + case 1: |
|
365 | + return $number . 'st'; |
|
366 | + break; |
|
367 | + case 2: |
|
368 | + return $number . 'nd'; |
|
369 | + break; |
|
370 | + case 3: |
|
371 | + return $number . 'rd'; |
|
372 | + default: |
|
373 | + return $number . 'th'; |
|
374 | + break; |
|
375 | + } |
|
376 | + } |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * @param $string |
|
383 | + * @return string |
|
384 | + */ |
|
385 | + public static function add_indefinite_article($string) { |
|
386 | + if (strtolower($string) === 'null') { |
|
387 | + return $string; |
|
388 | + } |
|
389 | + return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string; |
|
390 | + } |
|
391 | 391 | } |
392 | 392 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
3 | - exit( 'No direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | // +----------------------------------------------------------------------+ |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @since 0.1 |
35 | 35 | * @version $Revision 0.1 $ |
36 | 36 | */ |
37 | -class EEH_Inflector{ |
|
37 | +class EEH_Inflector { |
|
38 | 38 | // ------ CLASS METHODS ------ // |
39 | 39 | // ---- Public methods ---- // |
40 | 40 | // {{{ pluralize() |
@@ -44,8 +44,8 @@ discard block |
||
44 | 44 | * @param string $word |
45 | 45 | * @return string |
46 | 46 | */ |
47 | - public static function pluralize_and_lower( $word ){ |
|
48 | - return strtolower( self::pluralize( $word ) ); |
|
47 | + public static function pluralize_and_lower($word) { |
|
48 | + return strtolower(self::pluralize($word)); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | * @param string $word |
55 | 55 | * @return mixed |
56 | 56 | */ |
57 | - public static function singularize_and_upper( $word ) { |
|
58 | - return str_replace( ' ', '_', self::humanize( self::singularize( $word ), 'all' ) ); |
|
57 | + public static function singularize_and_upper($word) { |
|
58 | + return str_replace(' ', '_', self::humanize(self::singularize($word), 'all')); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @param string $word English noun to pluralize |
69 | 69 | * @return string Plural noun |
70 | 70 | */ |
71 | - public static function pluralize($word){ |
|
71 | + public static function pluralize($word) { |
|
72 | 72 | $plural = array( |
73 | 73 | '/(quiz)$/i' => '\1zes', |
74 | 74 | '/^(ox)$/i' => '\1en', |
@@ -100,21 +100,21 @@ discard block |
||
100 | 100 | |
101 | 101 | $lowercased_word = strtolower($word); |
102 | 102 | |
103 | - foreach($uncountable as $_uncountable){ |
|
104 | - if(substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && //even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter |
|
105 | - ! ctype_alpha( $lowercased_word[ strlen( $lowercased_word ) - strlen($_uncountable) ] ) ){ |
|
103 | + foreach ($uncountable as $_uncountable) { |
|
104 | + if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && //even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter |
|
105 | + ! ctype_alpha($lowercased_word[strlen($lowercased_word) - strlen($_uncountable)])) { |
|
106 | 106 | return $word; |
107 | 107 | } |
108 | 108 | } |
109 | 109 | |
110 | - foreach($irregular as $_plural => $_singular){ |
|
111 | - if(preg_match('/(' . $_plural . ')$/i', $word, $arr)){ |
|
112 | - return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word); |
|
110 | + foreach ($irregular as $_plural => $_singular) { |
|
111 | + if (preg_match('/('.$_plural.')$/i', $word, $arr)) { |
|
112 | + return preg_replace('/('.$_plural.')$/i', substr($arr[0], 0, 1).substr($_singular, 1), $word); |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
116 | - foreach($plural as $rule => $replacement){ |
|
117 | - if(preg_match($rule, $word)){ |
|
116 | + foreach ($plural as $rule => $replacement) { |
|
117 | + if (preg_match($rule, $word)) { |
|
118 | 118 | return preg_replace($rule, $replacement, $word); |
119 | 119 | } |
120 | 120 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * @param string $word English noun to singularize |
133 | 133 | * @return string Singular noun. |
134 | 134 | */ |
135 | - public static function singularize($word){ |
|
135 | + public static function singularize($word) { |
|
136 | 136 | $singular = array( |
137 | 137 | '/(quiz)zes$/i' => '\1', |
138 | 138 | '/(matr)ices$/i' => '\1ix', |
@@ -170,20 +170,20 @@ discard block |
||
170 | 170 | 'move' => 'moves'); |
171 | 171 | |
172 | 172 | $lowercased_word = strtolower($word); |
173 | - foreach($uncountable as $_uncountable){ |
|
174 | - if(substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable){ |
|
173 | + foreach ($uncountable as $_uncountable) { |
|
174 | + if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable) { |
|
175 | 175 | return $word; |
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
179 | - foreach($irregular as $_plural => $_singular){ |
|
180 | - if(preg_match('/(' . $_singular . ')$/i', $word, $arr)){ |
|
181 | - return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word); |
|
179 | + foreach ($irregular as $_plural => $_singular) { |
|
180 | + if (preg_match('/('.$_singular.')$/i', $word, $arr)) { |
|
181 | + return preg_replace('/('.$_singular.')$/i', substr($arr[0], 0, 1).substr($_plural, 1), $word); |
|
182 | 182 | } |
183 | 183 | } |
184 | 184 | |
185 | - foreach($singular as $rule => $replacement){ |
|
186 | - if(preg_match($rule, $word)){ |
|
185 | + foreach ($singular as $rule => $replacement) { |
|
186 | + if (preg_match($rule, $word)) { |
|
187 | 187 | return preg_replace($rule, $replacement, $word); |
188 | 188 | } |
189 | 189 | } |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | * the words in the title. |
213 | 213 | * @return string Text formatted as title |
214 | 214 | */ |
215 | - public static function titleize($word, $uppercase = ''){ |
|
215 | + public static function titleize($word, $uppercase = '') { |
|
216 | 216 | $uppercase = $uppercase === 'first' ? 'ucfirst' : 'ucwords'; |
217 | 217 | return $uppercase(EEH_Inflector::humanize(EEH_Inflector::underscore($word))); |
218 | 218 | } |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | * @param string $word Word to convert to camel case |
234 | 234 | * @return string UpperCamelCasedWord |
235 | 235 | */ |
236 | - public static function camelize($word){ |
|
236 | + public static function camelize($word) { |
|
237 | 237 | return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word))); |
238 | 238 | } |
239 | 239 | |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * @param string $word Word to underscore |
254 | 254 | * @return string Underscored word |
255 | 255 | */ |
256 | - public static function underscore($word){ |
|
256 | + public static function underscore($word) { |
|
257 | 257 | return strtolower(preg_replace('/[^A-Z^a-z^0-9]+/', '_', preg_replace('/([a-zd])([A-Z])/', '1_2', preg_replace('/([A-Z]+)([A-Z][a-z])/', '1_2', $word)))); |
258 | 258 | } |
259 | 259 | |
@@ -277,9 +277,9 @@ discard block |
||
277 | 277 | * instead of just the first one. |
278 | 278 | * @return string Human-readable word |
279 | 279 | */ |
280 | - public static function humanize($word, $uppercase = ''){ |
|
280 | + public static function humanize($word, $uppercase = '') { |
|
281 | 281 | //make special exceptions for acronyms |
282 | - $word = str_replace('wp_', 'WP_', $word ); |
|
282 | + $word = str_replace('wp_', 'WP_', $word); |
|
283 | 283 | $uppercase = $uppercase === 'all' ? 'ucwords' : 'ucfirst'; |
284 | 284 | return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word))); |
285 | 285 | } |
@@ -300,9 +300,9 @@ discard block |
||
300 | 300 | * @param string $word Word to lowerCamelCase |
301 | 301 | * @return string Returns a lowerCamelCasedWord |
302 | 302 | */ |
303 | - public static function variablize($word){ |
|
303 | + public static function variablize($word) { |
|
304 | 304 | $word = EEH_Inflector::camelize($word); |
305 | - return strtolower($word[0]) . substr($word, 1); |
|
305 | + return strtolower($word[0]).substr($word, 1); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | // }}} |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | * @param string $class_name Class name for getting related table_name. |
321 | 321 | * @return string plural_table_name |
322 | 322 | */ |
323 | - public static function tableize($class_name){ |
|
323 | + public static function tableize($class_name) { |
|
324 | 324 | return EEH_Inflector::pluralize(EEH_Inflector::underscore($class_name)); |
325 | 325 | } |
326 | 326 | |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | * @param string $table_name Table name for getting related ClassName. |
340 | 340 | * @return string SingularClassName |
341 | 341 | */ |
342 | - public static function classify($table_name){ |
|
342 | + public static function classify($table_name) { |
|
343 | 343 | return EEH_Inflector::camelize(EEH_Inflector::singularize($table_name)); |
344 | 344 | } |
345 | 345 | |
@@ -356,21 +356,21 @@ discard block |
||
356 | 356 | * @param integer $number Number to get its ordinal value |
357 | 357 | * @return string Ordinal representation of given string. |
358 | 358 | */ |
359 | - public static function ordinalize($number){ |
|
360 | - if(in_array(($number % 100), range(11, 13))){ |
|
361 | - return $number . 'th'; |
|
362 | - }else{ |
|
363 | - switch(($number % 10)){ |
|
359 | + public static function ordinalize($number) { |
|
360 | + if (in_array(($number % 100), range(11, 13))) { |
|
361 | + return $number.'th'; |
|
362 | + } else { |
|
363 | + switch (($number % 10)) { |
|
364 | 364 | case 1: |
365 | - return $number . 'st'; |
|
365 | + return $number.'st'; |
|
366 | 366 | break; |
367 | 367 | case 2: |
368 | - return $number . 'nd'; |
|
368 | + return $number.'nd'; |
|
369 | 369 | break; |
370 | 370 | case 3: |
371 | - return $number . 'rd'; |
|
371 | + return $number.'rd'; |
|
372 | 372 | default: |
373 | - return $number . 'th'; |
|
373 | + return $number.'th'; |
|
374 | 374 | break; |
375 | 375 | } |
376 | 376 | } |
@@ -386,6 +386,6 @@ discard block |
||
386 | 386 | if (strtolower($string) === 'null') { |
387 | 387 | return $string; |
388 | 388 | } |
389 | - return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string; |
|
389 | + return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ').$string; |
|
390 | 390 | } |
391 | 391 | } |
392 | 392 | \ No newline at end of file |
@@ -359,7 +359,7 @@ |
||
359 | 359 | public static function ordinalize($number){ |
360 | 360 | if(in_array(($number % 100), range(11, 13))){ |
361 | 361 | return $number . 'th'; |
362 | - }else{ |
|
362 | + } else{ |
|
363 | 363 | switch(($number % 10)){ |
364 | 364 | case 1: |
365 | 365 | return $number . 'st'; |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
4 | - exit( 'No direct script access allowed' ); |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | /** |
7 | 7 | * |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function __construct() { |
54 | 54 | // deprecated functions |
55 | - espresso_load_required( 'EventEspresso\core\Factory', EE_CORE . 'Factory.php' ); |
|
55 | + espresso_load_required('EventEspresso\core\Factory', EE_CORE.'Factory.php'); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | |
@@ -68,16 +68,16 @@ discard block |
||
68 | 68 | * @param EE_Response $response |
69 | 69 | * @return EE_Response |
70 | 70 | */ |
71 | - public function handle_request( EE_Request $request, EE_Response $response ) { |
|
71 | + public function handle_request(EE_Request $request, EE_Response $response) { |
|
72 | 72 | $this->request = $request; |
73 | 73 | $this->response = $response; |
74 | 74 | // info about how to load classes required by other classes |
75 | 75 | $this->dependency_map = $this->_load_dependency_map(); |
76 | 76 | // central repository for classes |
77 | 77 | $this->registry = $this->_load_registry(); |
78 | - do_action( 'EE_Load_Espresso_Core__handle_request__initialize_core_loading' ); |
|
78 | + do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading'); |
|
79 | 79 | // PSR4 Autoloaders |
80 | - $this->registry->load_core( 'EE_Psr4AutoloaderInit' ); |
|
80 | + $this->registry->load_core('EE_Psr4AutoloaderInit'); |
|
81 | 81 | // build DI container |
82 | 82 | $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); |
83 | 83 | $OpenCoffeeShop->addRecipes(); |
@@ -87,20 +87,20 @@ discard block |
||
87 | 87 | 'CommandBusInterface', |
88 | 88 | array( |
89 | 89 | null, |
90 | - $this->registry->create( 'CapChecker' ) |
|
90 | + $this->registry->create('CapChecker') |
|
91 | 91 | ), |
92 | 92 | true |
93 | 93 | ); |
94 | 94 | // workarounds for PHP < 5.3 |
95 | 95 | $this->_load_class_tools(); |
96 | 96 | // load interfaces |
97 | - espresso_load_required( 'EEI_Payment_Method_Interfaces', EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php' ); |
|
97 | + espresso_load_required('EEI_Payment_Method_Interfaces', EE_LIBRARIES.'payment_methods'.DS.'EEI_Payment_Method_Interfaces.php'); |
|
98 | 98 | // deprecated functions |
99 | - espresso_load_required( 'EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php' ); |
|
99 | + espresso_load_required('EE_Deprecated', EE_CORE.'EE_Deprecated.core.php'); |
|
100 | 100 | // WP cron jobs |
101 | - $this->registry->load_core( 'Cron_Tasks' ); |
|
102 | - $this->registry->load_core( 'EE_Request_Handler' ); |
|
103 | - $this->registry->load_core( 'EE_System' ); |
|
101 | + $this->registry->load_core('Cron_Tasks'); |
|
102 | + $this->registry->load_core('EE_Request_Handler'); |
|
103 | + $this->registry->load_core('EE_System'); |
|
104 | 104 | |
105 | 105 | return $this->response; |
106 | 106 | } |
@@ -130,11 +130,11 @@ discard block |
||
130 | 130 | * @throws \EE_Error |
131 | 131 | */ |
132 | 132 | public function dependency_map() { |
133 | - if ( ! $this->dependency_map instanceof EE_Dependency_Map ) { |
|
133 | + if ( ! $this->dependency_map instanceof EE_Dependency_Map) { |
|
134 | 134 | throw new EE_Error( |
135 | 135 | sprintf( |
136 | - __( 'Invalid EE_Dependency_Map: "%1$s"', 'event_espresso' ), |
|
137 | - print_r( $this->dependency_map, true ) |
|
136 | + __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
|
137 | + print_r($this->dependency_map, true) |
|
138 | 138 | ) |
139 | 139 | ); |
140 | 140 | } |
@@ -148,11 +148,11 @@ discard block |
||
148 | 148 | * @throws \EE_Error |
149 | 149 | */ |
150 | 150 | public function registry() { |
151 | - if ( ! $this->registry instanceof EE_Registry ) { |
|
151 | + if ( ! $this->registry instanceof EE_Registry) { |
|
152 | 152 | throw new EE_Error( |
153 | 153 | sprintf( |
154 | - __( 'Invalid EE_Registry: "%1$s"', 'event_espresso' ), |
|
155 | - print_r( $this->registry, true ) |
|
154 | + __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
|
155 | + print_r($this->registry, true) |
|
156 | 156 | ) |
157 | 157 | ); |
158 | 158 | } |
@@ -168,15 +168,15 @@ discard block |
||
168 | 168 | * @return EE_Dependency_Map |
169 | 169 | */ |
170 | 170 | private function _load_dependency_map() { |
171 | - if ( ! is_readable( EE_CORE . 'EE_Dependency_Map.core.php' ) ) { |
|
171 | + if ( ! is_readable(EE_CORE.'EE_Dependency_Map.core.php')) { |
|
172 | 172 | EE_Error::add_error( |
173 | - __( 'The EE_Dependency_Map core class could not be loaded.', 'event_espresso' ), |
|
173 | + __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
|
174 | 174 | __FILE__, __FUNCTION__, __LINE__ |
175 | 175 | ); |
176 | - wp_die( EE_Error::get_notices() ); |
|
176 | + wp_die(EE_Error::get_notices()); |
|
177 | 177 | } |
178 | - require_once( EE_CORE . 'EE_Dependency_Map.core.php' ); |
|
179 | - return EE_Dependency_Map::instance( $this->request, $this->response ); |
|
178 | + require_once(EE_CORE.'EE_Dependency_Map.core.php'); |
|
179 | + return EE_Dependency_Map::instance($this->request, $this->response); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | |
@@ -188,15 +188,15 @@ discard block |
||
188 | 188 | * @return EE_Registry |
189 | 189 | */ |
190 | 190 | private function _load_registry() { |
191 | - if ( ! is_readable( EE_CORE . 'EE_Registry.core.php' )) { |
|
191 | + if ( ! is_readable(EE_CORE.'EE_Registry.core.php')) { |
|
192 | 192 | EE_Error::add_error( |
193 | - __( 'The EE_Registry core class could not be loaded.', 'event_espresso' ), |
|
193 | + __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
|
194 | 194 | __FILE__, __FUNCTION__, __LINE__ |
195 | 195 | ); |
196 | - wp_die( EE_Error::get_notices() ); |
|
196 | + wp_die(EE_Error::get_notices()); |
|
197 | 197 | } |
198 | - require_once( EE_CORE . 'EE_Registry.core.php' ); |
|
199 | - return EE_Registry::instance( $this->dependency_map ); |
|
198 | + require_once(EE_CORE.'EE_Registry.core.php'); |
|
199 | + return EE_Registry::instance($this->dependency_map); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | |
@@ -207,13 +207,13 @@ discard block |
||
207 | 207 | * @return void |
208 | 208 | */ |
209 | 209 | private function _load_class_tools() { |
210 | - if ( ! is_readable( EE_HELPERS . 'EEH_Class_Tools.helper.php' )) { |
|
210 | + if ( ! is_readable(EE_HELPERS.'EEH_Class_Tools.helper.php')) { |
|
211 | 211 | EE_Error::add_error( |
212 | - __( 'The EEH_Class_Tools helper could not be loaded.', 'event_espresso' ), |
|
212 | + __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
|
213 | 213 | __FILE__, __FUNCTION__, __LINE__ |
214 | 214 | ); |
215 | 215 | } |
216 | - require_once( EE_HELPERS . 'EEH_Class_Tools.helper.php' ); |
|
216 | + require_once(EE_HELPERS.'EEH_Class_Tools.helper.php'); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | |
@@ -227,13 +227,13 @@ discard block |
||
227 | 227 | * @param \EE_Request $request |
228 | 228 | * @param \EE_Response $response |
229 | 229 | */ |
230 | - public function handle_response( EE_Request $request, EE_Response $response ) { |
|
230 | + public function handle_response(EE_Request $request, EE_Response $response) { |
|
231 | 231 | //\EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 ); |
232 | 232 | //EEH_Debug_Tools::printr( $request, '$request', __FILE__, __LINE__ ); |
233 | 233 | //EEH_Debug_Tools::printr( $response, '$response', __FILE__, __LINE__ ); |
234 | 234 | //die(); |
235 | - if ( $response->plugin_deactivated() ) { |
|
236 | - espresso_deactivate_plugin( EE_PLUGIN_BASENAME ); |
|
235 | + if ($response->plugin_deactivated()) { |
|
236 | + espresso_deactivate_plugin(EE_PLUGIN_BASENAME); |
|
237 | 237 | } |
238 | 238 | } |
239 | 239 |
@@ -1,11 +1,11 @@ discard block |
||
1 | 1 | <p> |
2 | - <strong><?php _e( 'PayPal Express Checkout', 'event_espresso' ); ?></strong> |
|
2 | + <strong><?php _e('PayPal Express Checkout', 'event_espresso'); ?></strong> |
|
3 | 3 | </p> |
4 | 4 | <p> |
5 | 5 | <?php _e('Please be sure to update the settings for the PayPal Express Checkout payment method.', 'event_espresso'); ?> |
6 | 6 | </p> |
7 | 7 | <p> |
8 | - <?php printf( __('For more information on how to get your API credentials, please view the %1$sPayPal Documentation%2$s.', 'event_espresso'), '<a target="_blank" href="https://developer.paypal.com/docs/classic/api/apiCredentials/#create-an-api-signature">', '</a>' ); ?> |
|
8 | + <?php printf(__('For more information on how to get your API credentials, please view the %1$sPayPal Documentation%2$s.', 'event_espresso'), '<a target="_blank" href="https://developer.paypal.com/docs/classic/api/apiCredentials/#create-an-api-signature">', '</a>'); ?> |
|
9 | 9 | </p> |
10 | 10 | |
11 | 11 | |
@@ -14,25 +14,25 @@ discard block |
||
14 | 14 | </p> |
15 | 15 | <ul> |
16 | 16 | <li> |
17 | - <strong><?php _e( 'API Username', 'event_espresso' ); ?></strong><br/> |
|
18 | - <?php _e( 'Your PayPal API Username.'); ?> |
|
17 | + <strong><?php _e('API Username', 'event_espresso'); ?></strong><br/> |
|
18 | + <?php _e('Your PayPal API Username.'); ?> |
|
19 | 19 | </li> |
20 | 20 | <li> |
21 | - <strong><?php _e( 'API Password', 'event_espresso' ); ?></strong><br/> |
|
22 | - <?php _e( 'Your PayPal API Password.' ); ?> |
|
21 | + <strong><?php _e('API Password', 'event_espresso'); ?></strong><br/> |
|
22 | + <?php _e('Your PayPal API Password.'); ?> |
|
23 | 23 | </li> |
24 | 24 | <li> |
25 | - <strong><?php _e( 'API Signature', 'event_espresso' ); ?></strong><br/> |
|
26 | - <?php _e( 'Your PayPal Account Signature.' ); ?> |
|
25 | + <strong><?php _e('API Signature', 'event_espresso'); ?></strong><br/> |
|
26 | + <?php _e('Your PayPal Account Signature.'); ?> |
|
27 | 27 | </li> |
28 | 28 | <li> |
29 | - <strong><?php _e( 'Request Shipping Address', 'event_espresso' ); ?></strong><br/> |
|
30 | - <?php _e( 'Indicates whether or not you require the buyer\'s shipping address on file with PayPal be a confirmed address.' ); ?> |
|
29 | + <strong><?php _e('Request Shipping Address', 'event_espresso'); ?></strong><br/> |
|
30 | + <?php _e('Indicates whether or not you require the buyer\'s shipping address on file with PayPal be a confirmed address.'); ?> |
|
31 | 31 | </li> |
32 | 32 | </ul> |
33 | 33 | <p> |
34 | - <?php printf( __('For testing please use a %1$s PaypPal Sandbox account%2$s.', 'event_espresso'), '<a target="_blank" href="https://developer.paypal.com">', '</a>' ); ?> |
|
34 | + <?php printf(__('For testing please use a %1$s PaypPal Sandbox account%2$s.', 'event_espresso'), '<a target="_blank" href="https://developer.paypal.com">', '</a>'); ?> |
|
35 | 35 | </p> |
36 | 36 | <p> |
37 | - <?php printf( __('Don\'t have PayPal? %1$sSign up for an account%2$s to get start right away.', 'event_espresso'), '<a target="_blank" href="hhttps://eventespresso.com/go/paypalstandard/">', '</a>' ); ?> |
|
37 | + <?php printf(__('Don\'t have PayPal? %1$sSign up for an account%2$s to get start right away.', 'event_espresso'), '<a target="_blank" href="hhttps://eventespresso.com/go/paypalstandard/">', '</a>'); ?> |
|
38 | 38 | </p> |
39 | 39 | \ No newline at end of file |
@@ -259,7 +259,7 @@ |
||
259 | 259 | * @param int $ID |
260 | 260 | * @param $shortcode_class |
261 | 261 | * @param $shortcode_posts |
262 | - * @param $page_for_posts |
|
262 | + * @param string $page_for_posts |
|
263 | 263 | * @param bool $update_post_shortcodes |
264 | 264 | * @return bool |
265 | 265 | */ |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | namespace EventEspresso\core\admin; |
3 | 3 | |
4 | 4 | if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
5 | - exit( 'No direct script access allowed' ); |
|
5 | + exit( 'No direct script access allowed' ); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -19,450 +19,450 @@ discard block |
||
19 | 19 | class PostShortcodeTracking |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * set_hooks_admin |
|
24 | - * |
|
25 | - * @access public |
|
26 | - */ |
|
27 | - public static function set_hooks_admin() |
|
28 | - { |
|
29 | - add_action( |
|
30 | - 'save_post', |
|
31 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'parse_post_content_on_save' ), |
|
32 | - 100, |
|
33 | - 2 |
|
34 | - ); |
|
35 | - add_action( |
|
36 | - 'delete_post', |
|
37 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'unset_post_shortcodes_on_delete' ), |
|
38 | - 100, |
|
39 | - 1 |
|
40 | - ); |
|
41 | - add_action( |
|
42 | - 'add_option_page_for_posts', |
|
43 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_initial_set' ), |
|
44 | - 100, |
|
45 | - 2 |
|
46 | - ); |
|
47 | - add_action( |
|
48 | - 'update_option', |
|
49 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_change' ), |
|
50 | - 100, |
|
51 | - 3 |
|
52 | - ); |
|
53 | - add_action( |
|
54 | - 'delete_option', |
|
55 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_delete' ), |
|
56 | - 100, |
|
57 | - 1 |
|
58 | - ); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * parse_post_content_on_save |
|
65 | - * any time a post is saved, we need to check for any EE shortcodes that may be embedded in the content, |
|
66 | - * and then track what posts those shortcodes are on, so that we can initialize shortcodes well before |
|
67 | - * the_content() runs. this allows us to do things like enqueue scripts for shortcodes ONLY on the pages the |
|
68 | - * shortcodes are actually used on |
|
69 | - * |
|
70 | - * @access public |
|
71 | - * @param int $post_ID |
|
72 | - * @param \WP_Post $post |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - public static function parse_post_content_on_save( $post_ID, $post ) |
|
76 | - { |
|
77 | - // if the post is trashed, then let's remove our post shortcode tracking |
|
78 | - if ( $post instanceof \WP_Post && $post->post_status === 'trash' ) { |
|
79 | - PostShortcodeTracking::unset_post_shortcodes_on_delete( $post_ID ); |
|
80 | - return; |
|
81 | - } |
|
82 | - // default post types |
|
83 | - $post_types = array( 'post' => 0, 'page' => 1 ); |
|
84 | - // add CPTs |
|
85 | - $CPTs = \EE_Register_CPTs::get_CPTs(); |
|
86 | - $post_types = array_merge( $post_types, $CPTs ); |
|
87 | - // for default or CPT posts... |
|
88 | - if ( isset( $post_types[ $post->post_type ] ) ) { |
|
89 | - // post on frontpage ? |
|
90 | - $page_for_posts = \EE_Config::get_page_for_posts(); |
|
91 | - if ( $post->post_name === $page_for_posts ) { |
|
92 | - PostShortcodeTracking::set_post_shortcodes_for_posts_page( $page_for_posts ); |
|
93 | - return; |
|
94 | - } |
|
95 | - // array of shortcodes indexed by post name |
|
96 | - \EE_Registry::CFG()->core->post_shortcodes = isset( \EE_Registry::CFG()->core->post_shortcodes ) |
|
97 | - ? \EE_Registry::CFG()->core->post_shortcodes |
|
98 | - : array(); |
|
99 | - // whether to proceed with update |
|
100 | - $update_post_shortcodes = false; |
|
101 | - // empty both arrays |
|
102 | - \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ] = array(); |
|
103 | - // check that posts page is already being tracked |
|
104 | - if ( ! isset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] ) ) { |
|
105 | - // if not, then ensure that it is properly added |
|
106 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] = array(); |
|
107 | - } |
|
108 | - // loop thru shortcodes |
|
109 | - foreach ( \EE_Registry::instance()->shortcodes as $EES_Shortcode => $shortcode_dir ) { |
|
110 | - // convert to UPPERCASE to get actual shortcode |
|
111 | - $EES_Shortcode = strtoupper( $EES_Shortcode ); |
|
112 | - // is the shortcode in the post_content ? |
|
113 | - if ( strpos( $post->post_content, $EES_Shortcode ) !== false ) { |
|
114 | - // map shortcode to post names and post IDs |
|
115 | - \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] = $post_ID; |
|
116 | - // and add this shortcode to the tracking for the blog page |
|
117 | - PostShortcodeTracking::set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, |
|
118 | - $post_ID ); |
|
119 | - $update_post_shortcodes = true; |
|
120 | - } else { |
|
121 | - // shortcode is not present in post content, so check if we were tracking it previously |
|
122 | - // stop tracking if shortcode is not used in this specific post |
|
123 | - if ( isset( \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] ) ) { |
|
124 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] ); |
|
125 | - $update_post_shortcodes = true; |
|
126 | - } |
|
127 | - // make sure that something is set for the shortcode posts (even though we may remove this) |
|
128 | - $shortcode_posts = isset( |
|
129 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] |
|
130 | - ) |
|
131 | - ? \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] |
|
132 | - : array(); |
|
133 | - // and stop tracking for this shortcode on the blog page if it is not used |
|
134 | - $update_post_shortcodes = PostShortcodeTracking::unset_posts_page_shortcode_for_post( |
|
135 | - $post_ID, |
|
136 | - $EES_Shortcode, |
|
137 | - $shortcode_posts, |
|
138 | - $page_for_posts, |
|
139 | - $update_post_shortcodes |
|
140 | - ) |
|
141 | - ? true |
|
142 | - : $update_post_shortcodes; |
|
143 | - } |
|
144 | - } |
|
145 | - if ( $update_post_shortcodes ) { |
|
146 | - PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
147 | - } |
|
148 | - } |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * set_post_shortcodes_for_posts_page (plz note: shortcodes is plural) |
|
155 | - * called when updating the WordPress Posts Page, |
|
156 | - * and adds shortcode tracking for the Posts Page, for all shortcodes currently tracked on individual posts |
|
157 | - * |
|
158 | - * @access protected |
|
159 | - * @param string $page_for_posts |
|
160 | - * @return void |
|
161 | - */ |
|
162 | - protected static function set_post_shortcodes_for_posts_page( $page_for_posts ) |
|
163 | - { |
|
164 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] = array(); |
|
165 | - // loop thru shortcodes |
|
166 | - foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
167 | - foreach ( $post_shortcodes as $EES_Shortcode => $post_ID ) { |
|
168 | - PostShortcodeTracking::set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID ); |
|
169 | - } |
|
170 | - } |
|
171 | - PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * set_post_shortcode_for_posts_page (plz note: shortcode is singular) |
|
178 | - * adds Posts Page shortcode tracking for the supplied shortcode for an individual post |
|
179 | - * |
|
180 | - * @access protected |
|
181 | - * @param string $page_for_posts |
|
182 | - * @param $EES_Shortcode |
|
183 | - * @param $post_ID |
|
184 | - */ |
|
185 | - protected static function set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID ) |
|
186 | - { |
|
187 | - // critical page shortcodes that we do NOT want added to the Posts page (blog) |
|
188 | - $critical_shortcodes = \EE_Registry::CFG()->core->get_critical_pages_shortcodes_array(); |
|
189 | - // if the shortcode is NOT one of the critical page shortcodes like ESPRESSO_TXN_PAGE |
|
190 | - if ( in_array( $EES_Shortcode, $critical_shortcodes ) ) { |
|
191 | - return; |
|
192 | - } |
|
193 | - // add shortcode to "Posts page" tracking |
|
194 | - if ( isset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] ) ) { |
|
195 | - // make sure tracking is in form of an array |
|
196 | - if ( ! is_array( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] ) ) { |
|
197 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] = array( |
|
198 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] => true, |
|
199 | - ); |
|
200 | - } |
|
201 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] += array( $post_ID => true ); |
|
202 | - } else { |
|
203 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] = array( $post_ID => true ); |
|
204 | - } |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * unset_post_shortcodes_on_delete |
|
211 | - * |
|
212 | - * @access protected |
|
213 | - * @param int $ID |
|
214 | - * @return void |
|
215 | - */ |
|
216 | - public static function unset_post_shortcodes_on_delete( $ID ) |
|
217 | - { |
|
218 | - $update_post_shortcodes = false; |
|
219 | - // post on frontpage ? |
|
220 | - $page_for_posts = \EE_Config::get_page_for_posts(); |
|
221 | - // looking for any references to this post |
|
222 | - foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
223 | - // is this the "Posts Page" (blog) ? |
|
224 | - if ( $post_name === $page_for_posts ) { |
|
225 | - // loop thru shortcodes registered for the posts page |
|
226 | - foreach ( $post_shortcodes as $shortcode_class => $shortcode_posts ) { |
|
227 | - $update_post_shortcodes = PostShortcodeTracking::unset_posts_page_shortcode_for_post( |
|
228 | - $ID, |
|
229 | - $shortcode_class, |
|
230 | - $shortcode_posts, |
|
231 | - $page_for_posts, |
|
232 | - $update_post_shortcodes |
|
233 | - ) |
|
234 | - ? true |
|
235 | - : $update_post_shortcodes; |
|
236 | - } |
|
237 | - } else { |
|
238 | - // loop thru shortcodes registered for each page |
|
239 | - foreach ( $post_shortcodes as $shortcode_class => $post_ID ) { |
|
240 | - // if this is page is being deleted, then don't track any post shortcodes for it |
|
241 | - if ( $post_ID === $ID ) { |
|
242 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $post_name ] ); |
|
243 | - $update_post_shortcodes = true; |
|
244 | - } |
|
245 | - } |
|
246 | - } |
|
247 | - } |
|
248 | - if ( $update_post_shortcodes ) { |
|
249 | - PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
250 | - } |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * unset_post_shortcodes_on_delete |
|
257 | - * |
|
258 | - * @access protected |
|
259 | - * @param int $ID |
|
260 | - * @param $shortcode_class |
|
261 | - * @param $shortcode_posts |
|
262 | - * @param $page_for_posts |
|
263 | - * @param bool $update_post_shortcodes |
|
264 | - * @return bool |
|
265 | - */ |
|
266 | - protected static function unset_posts_page_shortcode_for_post( |
|
267 | - $ID, |
|
268 | - $shortcode_class, |
|
269 | - $shortcode_posts, |
|
270 | - $page_for_posts, |
|
271 | - $update_post_shortcodes = false |
|
272 | - ) { |
|
273 | - // make sure that an array of post IDs is being tracked for each shortcode |
|
274 | - if ( ! is_array( $shortcode_posts ) ) { |
|
275 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] = array( |
|
276 | - $shortcode_posts => true, |
|
277 | - ); |
|
278 | - $update_post_shortcodes = true; |
|
279 | - } |
|
280 | - // now if the ID of the post being deleted is in the $shortcode_posts array |
|
281 | - if ( is_array( $shortcode_posts ) && isset( $shortcode_posts[ $ID ] ) ) { |
|
282 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ][ $ID ] ); |
|
283 | - $update_post_shortcodes = true; |
|
284 | - } |
|
285 | - // if nothing is registered for that shortcode anymore, then delete the shortcode altogether |
|
286 | - if ( empty( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] ) ) { |
|
287 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] ); |
|
288 | - $update_post_shortcodes = true; |
|
289 | - } |
|
290 | - return $update_post_shortcodes; |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * update_post_shortcodes |
|
297 | - * |
|
298 | - * @access public |
|
299 | - * @param $page_for_posts |
|
300 | - * @return void |
|
301 | - */ |
|
302 | - public static function update_post_shortcodes( $page_for_posts = '' ) |
|
303 | - { |
|
304 | - // make sure page_for_posts is set |
|
305 | - $page_for_posts = ! empty( $page_for_posts ) |
|
306 | - ? $page_for_posts |
|
307 | - : \EE_Config::get_page_for_posts(); |
|
308 | - // allow others to mess stuff up :D |
|
309 | - do_action( |
|
310 | - 'AHEE__\EventEspresso\core\admin\PostShortcodeTracking__update_post_shortcodes', |
|
311 | - \EE_Config::instance()->core->post_shortcodes, |
|
312 | - $page_for_posts |
|
313 | - ); |
|
314 | - // keep old hookpoint for now, will deprecate later |
|
315 | - do_action( |
|
316 | - 'AHEE__EE_Config__update_post_shortcodes', |
|
317 | - \EE_Config::instance()->core->post_shortcodes, |
|
318 | - $page_for_posts |
|
319 | - ); |
|
320 | - // verify that post_shortcodes is set |
|
321 | - \EE_Config::instance()->core->post_shortcodes = isset( \EE_Config::instance()->core->post_shortcodes ) |
|
322 | - && is_array( \EE_Config::instance()->core->post_shortcodes ) |
|
323 | - ? \EE_Config::instance()->core->post_shortcodes |
|
324 | - : array(); |
|
325 | - // cycle thru post_shortcodes |
|
326 | - foreach ( \EE_Config::instance()->core->post_shortcodes as $post_name => $shortcodes ) { |
|
327 | - // are there any shortcodes to track ? |
|
328 | - if ( ! empty( $shortcodes ) ) { |
|
329 | - // skip the posts page, because we want all shortcodes registered for it |
|
330 | - if ( $post_name === $page_for_posts ) { |
|
331 | - continue; |
|
332 | - } |
|
333 | - // loop thru list of tracked shortcodes |
|
334 | - foreach ( $shortcodes as $shortcode => $post_id ) { |
|
335 | - // make sure post still exists |
|
336 | - $post = get_post( $post_id ); |
|
337 | - // check that the post name matches what we have saved |
|
338 | - if ( $post && $post->post_name === $post_name ) { |
|
339 | - // if so, then break before hitting the unset below |
|
340 | - continue; |
|
341 | - } |
|
342 | - // we don't like missing posts around here >:( |
|
343 | - unset( \EE_Config::instance()->core->post_shortcodes[ $post_name ] ); |
|
344 | - } |
|
345 | - } else { |
|
346 | - // you got no shortcodes to keep track of ! |
|
347 | - unset( \EE_Config::instance()->core->post_shortcodes[ $post_name ] ); |
|
348 | - } |
|
349 | - } |
|
350 | - // critical page shortcodes that we do NOT want added to the Posts page (blog) |
|
351 | - $critical_shortcodes = \EE_Config::instance()->core->get_critical_pages_shortcodes_array(); |
|
352 | - $critical_shortcodes = array_flip( $critical_shortcodes ); |
|
353 | - foreach ( $critical_shortcodes as $critical_shortcode ) { |
|
354 | - unset( \EE_Config::instance()->core->post_shortcodes[ $page_for_posts ][ $critical_shortcode ] ); |
|
355 | - } |
|
356 | - //only show errors |
|
357 | - \EE_Config::instance()->update_espresso_config(); |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * reset_page_for_posts_on_initial_set |
|
364 | - * if an admin is on the WP Reading Settings page and sets the option for "Posts page", |
|
365 | - * when it had previously been unset, |
|
366 | - * then we need to attribute any actively used shortcodes to the new blog page |
|
367 | - * |
|
368 | - * @access public |
|
369 | - * @param string $option |
|
370 | - * @param string $value |
|
371 | - * @return void |
|
372 | - */ |
|
373 | - public static function reset_page_for_posts_on_initial_set( $option, $value ) |
|
374 | - { |
|
375 | - PostShortcodeTracking::reset_page_for_posts_on_change( $option, '', $value ); |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * reset_page_for_posts_on_change |
|
382 | - * if an admin is on the WP Reading Settings page and changes the option for "Posts page", |
|
383 | - * then we need to attribute any actively used shortcodes for the previous blog page to the new blog page |
|
384 | - * |
|
385 | - * @access public |
|
386 | - * @param string $option |
|
387 | - * @param string $old_value |
|
388 | - * @param string $value |
|
389 | - * @return void |
|
390 | - */ |
|
391 | - public static function reset_page_for_posts_on_change( $option, $old_value = '', $value = '' ) |
|
392 | - { |
|
393 | - if ( $option === 'page_for_posts' ) { |
|
394 | - global $wpdb; |
|
395 | - $table = $wpdb->posts; |
|
396 | - $SQL = "SELECT post_name from $table WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
397 | - $new_page_for_posts = $value ? $wpdb->get_var( $wpdb->prepare( $SQL, $value ) ) : 'posts'; |
|
398 | - PostShortcodeTracking::set_post_shortcodes_for_posts_page( $new_page_for_posts ); |
|
399 | - } |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - |
|
404 | - /** |
|
405 | - * reset_page_for_posts_on_delete |
|
406 | - * if an admin deletes a page designated as the WP "Posts page", |
|
407 | - * then we need to attribute any actively used shortcodes for that blog page to a generic 'posts' page |
|
408 | - * |
|
409 | - * @access public |
|
410 | - * @param string $option |
|
411 | - * @return void |
|
412 | - */ |
|
413 | - public static function reset_page_for_posts_on_delete( $option ) |
|
414 | - { |
|
415 | - if ( $option === 'page_for_posts' ) { |
|
416 | - PostShortcodeTracking::set_post_shortcodes_for_posts_page( 'posts' ); |
|
417 | - } |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * @param array|string $shortcodes |
|
424 | - * @param bool $index_results if passing more than one shortcode for the $shortcodes parameter above, |
|
425 | - * then setting this to true, will return as associative array indexed by |
|
426 | - * the shortcodes. If false, then the returned array will be unindexed |
|
427 | - * @return array |
|
428 | - */ |
|
429 | - public static function get_post_ids_for_shortcode( $shortcodes, $index_results = true ) |
|
430 | - { |
|
431 | - $post_ids = array(); |
|
432 | - if ( is_array( $shortcodes ) ) { |
|
433 | - foreach ( $shortcodes as $shortcode ) { |
|
434 | - $new_post_ids = PostShortcodeTracking::get_post_ids_for_shortcode( |
|
435 | - $shortcode, |
|
436 | - $index_results |
|
437 | - ); |
|
438 | - foreach ( $new_post_ids as $new_post_id ) { |
|
439 | - if ( $index_results ) { |
|
440 | - $post_ids[ $shortcode ][ $new_post_id ] = $new_post_id; |
|
441 | - } else { |
|
442 | - $post_ids[ $new_post_id ] = $new_post_id; |
|
443 | - } |
|
444 | - } |
|
445 | - } |
|
446 | - } else { |
|
447 | - $shortcode = strtoupper( $shortcodes ); |
|
448 | - $shortcode = strpos( $shortcode, 'ESPRESSO_' ) !== 0 ? "ESPRESSO_{$shortcode}" : $shortcode; |
|
449 | - $page_for_posts = \EE_Config::get_page_for_posts(); |
|
450 | - // looking for any references to this post |
|
451 | - foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
452 | - // if this is the "Posts Page" (blog), then skip it |
|
453 | - if ( $post_name === $page_for_posts ) { |
|
454 | - continue; |
|
455 | - } |
|
456 | - // loop thru shortcodes registered for each page, and grab post id for matches |
|
457 | - foreach ( (array) $post_shortcodes as $post_shortcode => $post_ID ) { |
|
458 | - if ( $post_shortcode === $shortcode ) { |
|
459 | - $post_ids[ $post_ID ] = $post_ID; |
|
460 | - } |
|
461 | - } |
|
462 | - } |
|
463 | - } |
|
464 | - return $post_ids; |
|
465 | - } |
|
22 | + /** |
|
23 | + * set_hooks_admin |
|
24 | + * |
|
25 | + * @access public |
|
26 | + */ |
|
27 | + public static function set_hooks_admin() |
|
28 | + { |
|
29 | + add_action( |
|
30 | + 'save_post', |
|
31 | + array( 'EventEspresso\core\admin\PostShortcodeTracking', 'parse_post_content_on_save' ), |
|
32 | + 100, |
|
33 | + 2 |
|
34 | + ); |
|
35 | + add_action( |
|
36 | + 'delete_post', |
|
37 | + array( 'EventEspresso\core\admin\PostShortcodeTracking', 'unset_post_shortcodes_on_delete' ), |
|
38 | + 100, |
|
39 | + 1 |
|
40 | + ); |
|
41 | + add_action( |
|
42 | + 'add_option_page_for_posts', |
|
43 | + array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_initial_set' ), |
|
44 | + 100, |
|
45 | + 2 |
|
46 | + ); |
|
47 | + add_action( |
|
48 | + 'update_option', |
|
49 | + array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_change' ), |
|
50 | + 100, |
|
51 | + 3 |
|
52 | + ); |
|
53 | + add_action( |
|
54 | + 'delete_option', |
|
55 | + array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_delete' ), |
|
56 | + 100, |
|
57 | + 1 |
|
58 | + ); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * parse_post_content_on_save |
|
65 | + * any time a post is saved, we need to check for any EE shortcodes that may be embedded in the content, |
|
66 | + * and then track what posts those shortcodes are on, so that we can initialize shortcodes well before |
|
67 | + * the_content() runs. this allows us to do things like enqueue scripts for shortcodes ONLY on the pages the |
|
68 | + * shortcodes are actually used on |
|
69 | + * |
|
70 | + * @access public |
|
71 | + * @param int $post_ID |
|
72 | + * @param \WP_Post $post |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + public static function parse_post_content_on_save( $post_ID, $post ) |
|
76 | + { |
|
77 | + // if the post is trashed, then let's remove our post shortcode tracking |
|
78 | + if ( $post instanceof \WP_Post && $post->post_status === 'trash' ) { |
|
79 | + PostShortcodeTracking::unset_post_shortcodes_on_delete( $post_ID ); |
|
80 | + return; |
|
81 | + } |
|
82 | + // default post types |
|
83 | + $post_types = array( 'post' => 0, 'page' => 1 ); |
|
84 | + // add CPTs |
|
85 | + $CPTs = \EE_Register_CPTs::get_CPTs(); |
|
86 | + $post_types = array_merge( $post_types, $CPTs ); |
|
87 | + // for default or CPT posts... |
|
88 | + if ( isset( $post_types[ $post->post_type ] ) ) { |
|
89 | + // post on frontpage ? |
|
90 | + $page_for_posts = \EE_Config::get_page_for_posts(); |
|
91 | + if ( $post->post_name === $page_for_posts ) { |
|
92 | + PostShortcodeTracking::set_post_shortcodes_for_posts_page( $page_for_posts ); |
|
93 | + return; |
|
94 | + } |
|
95 | + // array of shortcodes indexed by post name |
|
96 | + \EE_Registry::CFG()->core->post_shortcodes = isset( \EE_Registry::CFG()->core->post_shortcodes ) |
|
97 | + ? \EE_Registry::CFG()->core->post_shortcodes |
|
98 | + : array(); |
|
99 | + // whether to proceed with update |
|
100 | + $update_post_shortcodes = false; |
|
101 | + // empty both arrays |
|
102 | + \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ] = array(); |
|
103 | + // check that posts page is already being tracked |
|
104 | + if ( ! isset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] ) ) { |
|
105 | + // if not, then ensure that it is properly added |
|
106 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] = array(); |
|
107 | + } |
|
108 | + // loop thru shortcodes |
|
109 | + foreach ( \EE_Registry::instance()->shortcodes as $EES_Shortcode => $shortcode_dir ) { |
|
110 | + // convert to UPPERCASE to get actual shortcode |
|
111 | + $EES_Shortcode = strtoupper( $EES_Shortcode ); |
|
112 | + // is the shortcode in the post_content ? |
|
113 | + if ( strpos( $post->post_content, $EES_Shortcode ) !== false ) { |
|
114 | + // map shortcode to post names and post IDs |
|
115 | + \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] = $post_ID; |
|
116 | + // and add this shortcode to the tracking for the blog page |
|
117 | + PostShortcodeTracking::set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, |
|
118 | + $post_ID ); |
|
119 | + $update_post_shortcodes = true; |
|
120 | + } else { |
|
121 | + // shortcode is not present in post content, so check if we were tracking it previously |
|
122 | + // stop tracking if shortcode is not used in this specific post |
|
123 | + if ( isset( \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] ) ) { |
|
124 | + unset( \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] ); |
|
125 | + $update_post_shortcodes = true; |
|
126 | + } |
|
127 | + // make sure that something is set for the shortcode posts (even though we may remove this) |
|
128 | + $shortcode_posts = isset( |
|
129 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] |
|
130 | + ) |
|
131 | + ? \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] |
|
132 | + : array(); |
|
133 | + // and stop tracking for this shortcode on the blog page if it is not used |
|
134 | + $update_post_shortcodes = PostShortcodeTracking::unset_posts_page_shortcode_for_post( |
|
135 | + $post_ID, |
|
136 | + $EES_Shortcode, |
|
137 | + $shortcode_posts, |
|
138 | + $page_for_posts, |
|
139 | + $update_post_shortcodes |
|
140 | + ) |
|
141 | + ? true |
|
142 | + : $update_post_shortcodes; |
|
143 | + } |
|
144 | + } |
|
145 | + if ( $update_post_shortcodes ) { |
|
146 | + PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
147 | + } |
|
148 | + } |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * set_post_shortcodes_for_posts_page (plz note: shortcodes is plural) |
|
155 | + * called when updating the WordPress Posts Page, |
|
156 | + * and adds shortcode tracking for the Posts Page, for all shortcodes currently tracked on individual posts |
|
157 | + * |
|
158 | + * @access protected |
|
159 | + * @param string $page_for_posts |
|
160 | + * @return void |
|
161 | + */ |
|
162 | + protected static function set_post_shortcodes_for_posts_page( $page_for_posts ) |
|
163 | + { |
|
164 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] = array(); |
|
165 | + // loop thru shortcodes |
|
166 | + foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
167 | + foreach ( $post_shortcodes as $EES_Shortcode => $post_ID ) { |
|
168 | + PostShortcodeTracking::set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID ); |
|
169 | + } |
|
170 | + } |
|
171 | + PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * set_post_shortcode_for_posts_page (plz note: shortcode is singular) |
|
178 | + * adds Posts Page shortcode tracking for the supplied shortcode for an individual post |
|
179 | + * |
|
180 | + * @access protected |
|
181 | + * @param string $page_for_posts |
|
182 | + * @param $EES_Shortcode |
|
183 | + * @param $post_ID |
|
184 | + */ |
|
185 | + protected static function set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID ) |
|
186 | + { |
|
187 | + // critical page shortcodes that we do NOT want added to the Posts page (blog) |
|
188 | + $critical_shortcodes = \EE_Registry::CFG()->core->get_critical_pages_shortcodes_array(); |
|
189 | + // if the shortcode is NOT one of the critical page shortcodes like ESPRESSO_TXN_PAGE |
|
190 | + if ( in_array( $EES_Shortcode, $critical_shortcodes ) ) { |
|
191 | + return; |
|
192 | + } |
|
193 | + // add shortcode to "Posts page" tracking |
|
194 | + if ( isset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] ) ) { |
|
195 | + // make sure tracking is in form of an array |
|
196 | + if ( ! is_array( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] ) ) { |
|
197 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] = array( |
|
198 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] => true, |
|
199 | + ); |
|
200 | + } |
|
201 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] += array( $post_ID => true ); |
|
202 | + } else { |
|
203 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] = array( $post_ID => true ); |
|
204 | + } |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * unset_post_shortcodes_on_delete |
|
211 | + * |
|
212 | + * @access protected |
|
213 | + * @param int $ID |
|
214 | + * @return void |
|
215 | + */ |
|
216 | + public static function unset_post_shortcodes_on_delete( $ID ) |
|
217 | + { |
|
218 | + $update_post_shortcodes = false; |
|
219 | + // post on frontpage ? |
|
220 | + $page_for_posts = \EE_Config::get_page_for_posts(); |
|
221 | + // looking for any references to this post |
|
222 | + foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
223 | + // is this the "Posts Page" (blog) ? |
|
224 | + if ( $post_name === $page_for_posts ) { |
|
225 | + // loop thru shortcodes registered for the posts page |
|
226 | + foreach ( $post_shortcodes as $shortcode_class => $shortcode_posts ) { |
|
227 | + $update_post_shortcodes = PostShortcodeTracking::unset_posts_page_shortcode_for_post( |
|
228 | + $ID, |
|
229 | + $shortcode_class, |
|
230 | + $shortcode_posts, |
|
231 | + $page_for_posts, |
|
232 | + $update_post_shortcodes |
|
233 | + ) |
|
234 | + ? true |
|
235 | + : $update_post_shortcodes; |
|
236 | + } |
|
237 | + } else { |
|
238 | + // loop thru shortcodes registered for each page |
|
239 | + foreach ( $post_shortcodes as $shortcode_class => $post_ID ) { |
|
240 | + // if this is page is being deleted, then don't track any post shortcodes for it |
|
241 | + if ( $post_ID === $ID ) { |
|
242 | + unset( \EE_Registry::CFG()->core->post_shortcodes[ $post_name ] ); |
|
243 | + $update_post_shortcodes = true; |
|
244 | + } |
|
245 | + } |
|
246 | + } |
|
247 | + } |
|
248 | + if ( $update_post_shortcodes ) { |
|
249 | + PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
250 | + } |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * unset_post_shortcodes_on_delete |
|
257 | + * |
|
258 | + * @access protected |
|
259 | + * @param int $ID |
|
260 | + * @param $shortcode_class |
|
261 | + * @param $shortcode_posts |
|
262 | + * @param $page_for_posts |
|
263 | + * @param bool $update_post_shortcodes |
|
264 | + * @return bool |
|
265 | + */ |
|
266 | + protected static function unset_posts_page_shortcode_for_post( |
|
267 | + $ID, |
|
268 | + $shortcode_class, |
|
269 | + $shortcode_posts, |
|
270 | + $page_for_posts, |
|
271 | + $update_post_shortcodes = false |
|
272 | + ) { |
|
273 | + // make sure that an array of post IDs is being tracked for each shortcode |
|
274 | + if ( ! is_array( $shortcode_posts ) ) { |
|
275 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] = array( |
|
276 | + $shortcode_posts => true, |
|
277 | + ); |
|
278 | + $update_post_shortcodes = true; |
|
279 | + } |
|
280 | + // now if the ID of the post being deleted is in the $shortcode_posts array |
|
281 | + if ( is_array( $shortcode_posts ) && isset( $shortcode_posts[ $ID ] ) ) { |
|
282 | + unset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ][ $ID ] ); |
|
283 | + $update_post_shortcodes = true; |
|
284 | + } |
|
285 | + // if nothing is registered for that shortcode anymore, then delete the shortcode altogether |
|
286 | + if ( empty( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] ) ) { |
|
287 | + unset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] ); |
|
288 | + $update_post_shortcodes = true; |
|
289 | + } |
|
290 | + return $update_post_shortcodes; |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * update_post_shortcodes |
|
297 | + * |
|
298 | + * @access public |
|
299 | + * @param $page_for_posts |
|
300 | + * @return void |
|
301 | + */ |
|
302 | + public static function update_post_shortcodes( $page_for_posts = '' ) |
|
303 | + { |
|
304 | + // make sure page_for_posts is set |
|
305 | + $page_for_posts = ! empty( $page_for_posts ) |
|
306 | + ? $page_for_posts |
|
307 | + : \EE_Config::get_page_for_posts(); |
|
308 | + // allow others to mess stuff up :D |
|
309 | + do_action( |
|
310 | + 'AHEE__\EventEspresso\core\admin\PostShortcodeTracking__update_post_shortcodes', |
|
311 | + \EE_Config::instance()->core->post_shortcodes, |
|
312 | + $page_for_posts |
|
313 | + ); |
|
314 | + // keep old hookpoint for now, will deprecate later |
|
315 | + do_action( |
|
316 | + 'AHEE__EE_Config__update_post_shortcodes', |
|
317 | + \EE_Config::instance()->core->post_shortcodes, |
|
318 | + $page_for_posts |
|
319 | + ); |
|
320 | + // verify that post_shortcodes is set |
|
321 | + \EE_Config::instance()->core->post_shortcodes = isset( \EE_Config::instance()->core->post_shortcodes ) |
|
322 | + && is_array( \EE_Config::instance()->core->post_shortcodes ) |
|
323 | + ? \EE_Config::instance()->core->post_shortcodes |
|
324 | + : array(); |
|
325 | + // cycle thru post_shortcodes |
|
326 | + foreach ( \EE_Config::instance()->core->post_shortcodes as $post_name => $shortcodes ) { |
|
327 | + // are there any shortcodes to track ? |
|
328 | + if ( ! empty( $shortcodes ) ) { |
|
329 | + // skip the posts page, because we want all shortcodes registered for it |
|
330 | + if ( $post_name === $page_for_posts ) { |
|
331 | + continue; |
|
332 | + } |
|
333 | + // loop thru list of tracked shortcodes |
|
334 | + foreach ( $shortcodes as $shortcode => $post_id ) { |
|
335 | + // make sure post still exists |
|
336 | + $post = get_post( $post_id ); |
|
337 | + // check that the post name matches what we have saved |
|
338 | + if ( $post && $post->post_name === $post_name ) { |
|
339 | + // if so, then break before hitting the unset below |
|
340 | + continue; |
|
341 | + } |
|
342 | + // we don't like missing posts around here >:( |
|
343 | + unset( \EE_Config::instance()->core->post_shortcodes[ $post_name ] ); |
|
344 | + } |
|
345 | + } else { |
|
346 | + // you got no shortcodes to keep track of ! |
|
347 | + unset( \EE_Config::instance()->core->post_shortcodes[ $post_name ] ); |
|
348 | + } |
|
349 | + } |
|
350 | + // critical page shortcodes that we do NOT want added to the Posts page (blog) |
|
351 | + $critical_shortcodes = \EE_Config::instance()->core->get_critical_pages_shortcodes_array(); |
|
352 | + $critical_shortcodes = array_flip( $critical_shortcodes ); |
|
353 | + foreach ( $critical_shortcodes as $critical_shortcode ) { |
|
354 | + unset( \EE_Config::instance()->core->post_shortcodes[ $page_for_posts ][ $critical_shortcode ] ); |
|
355 | + } |
|
356 | + //only show errors |
|
357 | + \EE_Config::instance()->update_espresso_config(); |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * reset_page_for_posts_on_initial_set |
|
364 | + * if an admin is on the WP Reading Settings page and sets the option for "Posts page", |
|
365 | + * when it had previously been unset, |
|
366 | + * then we need to attribute any actively used shortcodes to the new blog page |
|
367 | + * |
|
368 | + * @access public |
|
369 | + * @param string $option |
|
370 | + * @param string $value |
|
371 | + * @return void |
|
372 | + */ |
|
373 | + public static function reset_page_for_posts_on_initial_set( $option, $value ) |
|
374 | + { |
|
375 | + PostShortcodeTracking::reset_page_for_posts_on_change( $option, '', $value ); |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * reset_page_for_posts_on_change |
|
382 | + * if an admin is on the WP Reading Settings page and changes the option for "Posts page", |
|
383 | + * then we need to attribute any actively used shortcodes for the previous blog page to the new blog page |
|
384 | + * |
|
385 | + * @access public |
|
386 | + * @param string $option |
|
387 | + * @param string $old_value |
|
388 | + * @param string $value |
|
389 | + * @return void |
|
390 | + */ |
|
391 | + public static function reset_page_for_posts_on_change( $option, $old_value = '', $value = '' ) |
|
392 | + { |
|
393 | + if ( $option === 'page_for_posts' ) { |
|
394 | + global $wpdb; |
|
395 | + $table = $wpdb->posts; |
|
396 | + $SQL = "SELECT post_name from $table WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
397 | + $new_page_for_posts = $value ? $wpdb->get_var( $wpdb->prepare( $SQL, $value ) ) : 'posts'; |
|
398 | + PostShortcodeTracking::set_post_shortcodes_for_posts_page( $new_page_for_posts ); |
|
399 | + } |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + |
|
404 | + /** |
|
405 | + * reset_page_for_posts_on_delete |
|
406 | + * if an admin deletes a page designated as the WP "Posts page", |
|
407 | + * then we need to attribute any actively used shortcodes for that blog page to a generic 'posts' page |
|
408 | + * |
|
409 | + * @access public |
|
410 | + * @param string $option |
|
411 | + * @return void |
|
412 | + */ |
|
413 | + public static function reset_page_for_posts_on_delete( $option ) |
|
414 | + { |
|
415 | + if ( $option === 'page_for_posts' ) { |
|
416 | + PostShortcodeTracking::set_post_shortcodes_for_posts_page( 'posts' ); |
|
417 | + } |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * @param array|string $shortcodes |
|
424 | + * @param bool $index_results if passing more than one shortcode for the $shortcodes parameter above, |
|
425 | + * then setting this to true, will return as associative array indexed by |
|
426 | + * the shortcodes. If false, then the returned array will be unindexed |
|
427 | + * @return array |
|
428 | + */ |
|
429 | + public static function get_post_ids_for_shortcode( $shortcodes, $index_results = true ) |
|
430 | + { |
|
431 | + $post_ids = array(); |
|
432 | + if ( is_array( $shortcodes ) ) { |
|
433 | + foreach ( $shortcodes as $shortcode ) { |
|
434 | + $new_post_ids = PostShortcodeTracking::get_post_ids_for_shortcode( |
|
435 | + $shortcode, |
|
436 | + $index_results |
|
437 | + ); |
|
438 | + foreach ( $new_post_ids as $new_post_id ) { |
|
439 | + if ( $index_results ) { |
|
440 | + $post_ids[ $shortcode ][ $new_post_id ] = $new_post_id; |
|
441 | + } else { |
|
442 | + $post_ids[ $new_post_id ] = $new_post_id; |
|
443 | + } |
|
444 | + } |
|
445 | + } |
|
446 | + } else { |
|
447 | + $shortcode = strtoupper( $shortcodes ); |
|
448 | + $shortcode = strpos( $shortcode, 'ESPRESSO_' ) !== 0 ? "ESPRESSO_{$shortcode}" : $shortcode; |
|
449 | + $page_for_posts = \EE_Config::get_page_for_posts(); |
|
450 | + // looking for any references to this post |
|
451 | + foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
452 | + // if this is the "Posts Page" (blog), then skip it |
|
453 | + if ( $post_name === $page_for_posts ) { |
|
454 | + continue; |
|
455 | + } |
|
456 | + // loop thru shortcodes registered for each page, and grab post id for matches |
|
457 | + foreach ( (array) $post_shortcodes as $post_shortcode => $post_ID ) { |
|
458 | + if ( $post_shortcode === $shortcode ) { |
|
459 | + $post_ids[ $post_ID ] = $post_ID; |
|
460 | + } |
|
461 | + } |
|
462 | + } |
|
463 | + } |
|
464 | + return $post_ids; |
|
465 | + } |
|
466 | 466 | |
467 | 467 | |
468 | 468 |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\admin; |
3 | 3 | |
4 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
5 | - exit( 'No direct script access allowed' ); |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -28,31 +28,31 @@ discard block |
||
28 | 28 | { |
29 | 29 | add_action( |
30 | 30 | 'save_post', |
31 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'parse_post_content_on_save' ), |
|
31 | + array('EventEspresso\core\admin\PostShortcodeTracking', 'parse_post_content_on_save'), |
|
32 | 32 | 100, |
33 | 33 | 2 |
34 | 34 | ); |
35 | 35 | add_action( |
36 | 36 | 'delete_post', |
37 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'unset_post_shortcodes_on_delete' ), |
|
37 | + array('EventEspresso\core\admin\PostShortcodeTracking', 'unset_post_shortcodes_on_delete'), |
|
38 | 38 | 100, |
39 | 39 | 1 |
40 | 40 | ); |
41 | 41 | add_action( |
42 | 42 | 'add_option_page_for_posts', |
43 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_initial_set' ), |
|
43 | + array('EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_initial_set'), |
|
44 | 44 | 100, |
45 | 45 | 2 |
46 | 46 | ); |
47 | 47 | add_action( |
48 | 48 | 'update_option', |
49 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_change' ), |
|
49 | + array('EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_change'), |
|
50 | 50 | 100, |
51 | 51 | 3 |
52 | 52 | ); |
53 | 53 | add_action( |
54 | 54 | 'delete_option', |
55 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_delete' ), |
|
55 | + array('EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_delete'), |
|
56 | 56 | 100, |
57 | 57 | 1 |
58 | 58 | ); |
@@ -72,63 +72,63 @@ discard block |
||
72 | 72 | * @param \WP_Post $post |
73 | 73 | * @return void |
74 | 74 | */ |
75 | - public static function parse_post_content_on_save( $post_ID, $post ) |
|
75 | + public static function parse_post_content_on_save($post_ID, $post) |
|
76 | 76 | { |
77 | 77 | // if the post is trashed, then let's remove our post shortcode tracking |
78 | - if ( $post instanceof \WP_Post && $post->post_status === 'trash' ) { |
|
79 | - PostShortcodeTracking::unset_post_shortcodes_on_delete( $post_ID ); |
|
78 | + if ($post instanceof \WP_Post && $post->post_status === 'trash') { |
|
79 | + PostShortcodeTracking::unset_post_shortcodes_on_delete($post_ID); |
|
80 | 80 | return; |
81 | 81 | } |
82 | 82 | // default post types |
83 | - $post_types = array( 'post' => 0, 'page' => 1 ); |
|
83 | + $post_types = array('post' => 0, 'page' => 1); |
|
84 | 84 | // add CPTs |
85 | 85 | $CPTs = \EE_Register_CPTs::get_CPTs(); |
86 | - $post_types = array_merge( $post_types, $CPTs ); |
|
86 | + $post_types = array_merge($post_types, $CPTs); |
|
87 | 87 | // for default or CPT posts... |
88 | - if ( isset( $post_types[ $post->post_type ] ) ) { |
|
88 | + if (isset($post_types[$post->post_type])) { |
|
89 | 89 | // post on frontpage ? |
90 | 90 | $page_for_posts = \EE_Config::get_page_for_posts(); |
91 | - if ( $post->post_name === $page_for_posts ) { |
|
92 | - PostShortcodeTracking::set_post_shortcodes_for_posts_page( $page_for_posts ); |
|
91 | + if ($post->post_name === $page_for_posts) { |
|
92 | + PostShortcodeTracking::set_post_shortcodes_for_posts_page($page_for_posts); |
|
93 | 93 | return; |
94 | 94 | } |
95 | 95 | // array of shortcodes indexed by post name |
96 | - \EE_Registry::CFG()->core->post_shortcodes = isset( \EE_Registry::CFG()->core->post_shortcodes ) |
|
96 | + \EE_Registry::CFG()->core->post_shortcodes = isset(\EE_Registry::CFG()->core->post_shortcodes) |
|
97 | 97 | ? \EE_Registry::CFG()->core->post_shortcodes |
98 | 98 | : array(); |
99 | 99 | // whether to proceed with update |
100 | 100 | $update_post_shortcodes = false; |
101 | 101 | // empty both arrays |
102 | - \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ] = array(); |
|
102 | + \EE_Registry::CFG()->core->post_shortcodes[$post->post_name] = array(); |
|
103 | 103 | // check that posts page is already being tracked |
104 | - if ( ! isset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] ) ) { |
|
104 | + if ( ! isset(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts])) { |
|
105 | 105 | // if not, then ensure that it is properly added |
106 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] = array(); |
|
106 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts] = array(); |
|
107 | 107 | } |
108 | 108 | // loop thru shortcodes |
109 | - foreach ( \EE_Registry::instance()->shortcodes as $EES_Shortcode => $shortcode_dir ) { |
|
109 | + foreach (\EE_Registry::instance()->shortcodes as $EES_Shortcode => $shortcode_dir) { |
|
110 | 110 | // convert to UPPERCASE to get actual shortcode |
111 | - $EES_Shortcode = strtoupper( $EES_Shortcode ); |
|
111 | + $EES_Shortcode = strtoupper($EES_Shortcode); |
|
112 | 112 | // is the shortcode in the post_content ? |
113 | - if ( strpos( $post->post_content, $EES_Shortcode ) !== false ) { |
|
113 | + if (strpos($post->post_content, $EES_Shortcode) !== false) { |
|
114 | 114 | // map shortcode to post names and post IDs |
115 | - \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] = $post_ID; |
|
115 | + \EE_Registry::CFG()->core->post_shortcodes[$post->post_name][$EES_Shortcode] = $post_ID; |
|
116 | 116 | // and add this shortcode to the tracking for the blog page |
117 | - PostShortcodeTracking::set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, |
|
118 | - $post_ID ); |
|
117 | + PostShortcodeTracking::set_post_shortcode_for_posts_page($page_for_posts, $EES_Shortcode, |
|
118 | + $post_ID); |
|
119 | 119 | $update_post_shortcodes = true; |
120 | 120 | } else { |
121 | 121 | // shortcode is not present in post content, so check if we were tracking it previously |
122 | 122 | // stop tracking if shortcode is not used in this specific post |
123 | - if ( isset( \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] ) ) { |
|
124 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] ); |
|
123 | + if (isset(\EE_Registry::CFG()->core->post_shortcodes[$post->post_name][$EES_Shortcode])) { |
|
124 | + unset(\EE_Registry::CFG()->core->post_shortcodes[$post->post_name][$EES_Shortcode]); |
|
125 | 125 | $update_post_shortcodes = true; |
126 | 126 | } |
127 | 127 | // make sure that something is set for the shortcode posts (even though we may remove this) |
128 | 128 | $shortcode_posts = isset( |
129 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] |
|
129 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] |
|
130 | 130 | ) |
131 | - ? \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] |
|
131 | + ? \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] |
|
132 | 132 | : array(); |
133 | 133 | // and stop tracking for this shortcode on the blog page if it is not used |
134 | 134 | $update_post_shortcodes = PostShortcodeTracking::unset_posts_page_shortcode_for_post( |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | : $update_post_shortcodes; |
143 | 143 | } |
144 | 144 | } |
145 | - if ( $update_post_shortcodes ) { |
|
146 | - PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
145 | + if ($update_post_shortcodes) { |
|
146 | + PostShortcodeTracking::update_post_shortcodes($page_for_posts); |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | } |
@@ -159,16 +159,16 @@ discard block |
||
159 | 159 | * @param string $page_for_posts |
160 | 160 | * @return void |
161 | 161 | */ |
162 | - protected static function set_post_shortcodes_for_posts_page( $page_for_posts ) |
|
162 | + protected static function set_post_shortcodes_for_posts_page($page_for_posts) |
|
163 | 163 | { |
164 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] = array(); |
|
164 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts] = array(); |
|
165 | 165 | // loop thru shortcodes |
166 | - foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
167 | - foreach ( $post_shortcodes as $EES_Shortcode => $post_ID ) { |
|
168 | - PostShortcodeTracking::set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID ); |
|
166 | + foreach (\EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes) { |
|
167 | + foreach ($post_shortcodes as $EES_Shortcode => $post_ID) { |
|
168 | + PostShortcodeTracking::set_post_shortcode_for_posts_page($page_for_posts, $EES_Shortcode, $post_ID); |
|
169 | 169 | } |
170 | 170 | } |
171 | - PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
171 | + PostShortcodeTracking::update_post_shortcodes($page_for_posts); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | |
@@ -182,25 +182,25 @@ discard block |
||
182 | 182 | * @param $EES_Shortcode |
183 | 183 | * @param $post_ID |
184 | 184 | */ |
185 | - protected static function set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID ) |
|
185 | + protected static function set_post_shortcode_for_posts_page($page_for_posts, $EES_Shortcode, $post_ID) |
|
186 | 186 | { |
187 | 187 | // critical page shortcodes that we do NOT want added to the Posts page (blog) |
188 | 188 | $critical_shortcodes = \EE_Registry::CFG()->core->get_critical_pages_shortcodes_array(); |
189 | 189 | // if the shortcode is NOT one of the critical page shortcodes like ESPRESSO_TXN_PAGE |
190 | - if ( in_array( $EES_Shortcode, $critical_shortcodes ) ) { |
|
190 | + if (in_array($EES_Shortcode, $critical_shortcodes)) { |
|
191 | 191 | return; |
192 | 192 | } |
193 | 193 | // add shortcode to "Posts page" tracking |
194 | - if ( isset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] ) ) { |
|
194 | + if (isset(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode])) { |
|
195 | 195 | // make sure tracking is in form of an array |
196 | - if ( ! is_array( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] ) ) { |
|
197 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] = array( |
|
198 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] => true, |
|
196 | + if ( ! is_array(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode])) { |
|
197 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] = array( |
|
198 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] => true, |
|
199 | 199 | ); |
200 | 200 | } |
201 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] += array( $post_ID => true ); |
|
201 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] += array($post_ID => true); |
|
202 | 202 | } else { |
203 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] = array( $post_ID => true ); |
|
203 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] = array($post_ID => true); |
|
204 | 204 | } |
205 | 205 | } |
206 | 206 | |
@@ -213,17 +213,17 @@ discard block |
||
213 | 213 | * @param int $ID |
214 | 214 | * @return void |
215 | 215 | */ |
216 | - public static function unset_post_shortcodes_on_delete( $ID ) |
|
216 | + public static function unset_post_shortcodes_on_delete($ID) |
|
217 | 217 | { |
218 | 218 | $update_post_shortcodes = false; |
219 | 219 | // post on frontpage ? |
220 | 220 | $page_for_posts = \EE_Config::get_page_for_posts(); |
221 | 221 | // looking for any references to this post |
222 | - foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
222 | + foreach (\EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes) { |
|
223 | 223 | // is this the "Posts Page" (blog) ? |
224 | - if ( $post_name === $page_for_posts ) { |
|
224 | + if ($post_name === $page_for_posts) { |
|
225 | 225 | // loop thru shortcodes registered for the posts page |
226 | - foreach ( $post_shortcodes as $shortcode_class => $shortcode_posts ) { |
|
226 | + foreach ($post_shortcodes as $shortcode_class => $shortcode_posts) { |
|
227 | 227 | $update_post_shortcodes = PostShortcodeTracking::unset_posts_page_shortcode_for_post( |
228 | 228 | $ID, |
229 | 229 | $shortcode_class, |
@@ -236,17 +236,17 @@ discard block |
||
236 | 236 | } |
237 | 237 | } else { |
238 | 238 | // loop thru shortcodes registered for each page |
239 | - foreach ( $post_shortcodes as $shortcode_class => $post_ID ) { |
|
239 | + foreach ($post_shortcodes as $shortcode_class => $post_ID) { |
|
240 | 240 | // if this is page is being deleted, then don't track any post shortcodes for it |
241 | - if ( $post_ID === $ID ) { |
|
242 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $post_name ] ); |
|
241 | + if ($post_ID === $ID) { |
|
242 | + unset(\EE_Registry::CFG()->core->post_shortcodes[$post_name]); |
|
243 | 243 | $update_post_shortcodes = true; |
244 | 244 | } |
245 | 245 | } |
246 | 246 | } |
247 | 247 | } |
248 | - if ( $update_post_shortcodes ) { |
|
249 | - PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
248 | + if ($update_post_shortcodes) { |
|
249 | + PostShortcodeTracking::update_post_shortcodes($page_for_posts); |
|
250 | 250 | } |
251 | 251 | } |
252 | 252 | |
@@ -271,20 +271,20 @@ discard block |
||
271 | 271 | $update_post_shortcodes = false |
272 | 272 | ) { |
273 | 273 | // make sure that an array of post IDs is being tracked for each shortcode |
274 | - if ( ! is_array( $shortcode_posts ) ) { |
|
275 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] = array( |
|
274 | + if ( ! is_array($shortcode_posts)) { |
|
275 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$shortcode_class] = array( |
|
276 | 276 | $shortcode_posts => true, |
277 | 277 | ); |
278 | 278 | $update_post_shortcodes = true; |
279 | 279 | } |
280 | 280 | // now if the ID of the post being deleted is in the $shortcode_posts array |
281 | - if ( is_array( $shortcode_posts ) && isset( $shortcode_posts[ $ID ] ) ) { |
|
282 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ][ $ID ] ); |
|
281 | + if (is_array($shortcode_posts) && isset($shortcode_posts[$ID])) { |
|
282 | + unset(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$shortcode_class][$ID]); |
|
283 | 283 | $update_post_shortcodes = true; |
284 | 284 | } |
285 | 285 | // if nothing is registered for that shortcode anymore, then delete the shortcode altogether |
286 | - if ( empty( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] ) ) { |
|
287 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] ); |
|
286 | + if (empty(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$shortcode_class])) { |
|
287 | + unset(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$shortcode_class]); |
|
288 | 288 | $update_post_shortcodes = true; |
289 | 289 | } |
290 | 290 | return $update_post_shortcodes; |
@@ -299,10 +299,10 @@ discard block |
||
299 | 299 | * @param $page_for_posts |
300 | 300 | * @return void |
301 | 301 | */ |
302 | - public static function update_post_shortcodes( $page_for_posts = '' ) |
|
302 | + public static function update_post_shortcodes($page_for_posts = '') |
|
303 | 303 | { |
304 | 304 | // make sure page_for_posts is set |
305 | - $page_for_posts = ! empty( $page_for_posts ) |
|
305 | + $page_for_posts = ! empty($page_for_posts) |
|
306 | 306 | ? $page_for_posts |
307 | 307 | : \EE_Config::get_page_for_posts(); |
308 | 308 | // allow others to mess stuff up :D |
@@ -318,40 +318,40 @@ discard block |
||
318 | 318 | $page_for_posts |
319 | 319 | ); |
320 | 320 | // verify that post_shortcodes is set |
321 | - \EE_Config::instance()->core->post_shortcodes = isset( \EE_Config::instance()->core->post_shortcodes ) |
|
322 | - && is_array( \EE_Config::instance()->core->post_shortcodes ) |
|
321 | + \EE_Config::instance()->core->post_shortcodes = isset(\EE_Config::instance()->core->post_shortcodes) |
|
322 | + && is_array(\EE_Config::instance()->core->post_shortcodes) |
|
323 | 323 | ? \EE_Config::instance()->core->post_shortcodes |
324 | 324 | : array(); |
325 | 325 | // cycle thru post_shortcodes |
326 | - foreach ( \EE_Config::instance()->core->post_shortcodes as $post_name => $shortcodes ) { |
|
326 | + foreach (\EE_Config::instance()->core->post_shortcodes as $post_name => $shortcodes) { |
|
327 | 327 | // are there any shortcodes to track ? |
328 | - if ( ! empty( $shortcodes ) ) { |
|
328 | + if ( ! empty($shortcodes)) { |
|
329 | 329 | // skip the posts page, because we want all shortcodes registered for it |
330 | - if ( $post_name === $page_for_posts ) { |
|
330 | + if ($post_name === $page_for_posts) { |
|
331 | 331 | continue; |
332 | 332 | } |
333 | 333 | // loop thru list of tracked shortcodes |
334 | - foreach ( $shortcodes as $shortcode => $post_id ) { |
|
334 | + foreach ($shortcodes as $shortcode => $post_id) { |
|
335 | 335 | // make sure post still exists |
336 | - $post = get_post( $post_id ); |
|
336 | + $post = get_post($post_id); |
|
337 | 337 | // check that the post name matches what we have saved |
338 | - if ( $post && $post->post_name === $post_name ) { |
|
338 | + if ($post && $post->post_name === $post_name) { |
|
339 | 339 | // if so, then break before hitting the unset below |
340 | 340 | continue; |
341 | 341 | } |
342 | 342 | // we don't like missing posts around here >:( |
343 | - unset( \EE_Config::instance()->core->post_shortcodes[ $post_name ] ); |
|
343 | + unset(\EE_Config::instance()->core->post_shortcodes[$post_name]); |
|
344 | 344 | } |
345 | 345 | } else { |
346 | 346 | // you got no shortcodes to keep track of ! |
347 | - unset( \EE_Config::instance()->core->post_shortcodes[ $post_name ] ); |
|
347 | + unset(\EE_Config::instance()->core->post_shortcodes[$post_name]); |
|
348 | 348 | } |
349 | 349 | } |
350 | 350 | // critical page shortcodes that we do NOT want added to the Posts page (blog) |
351 | 351 | $critical_shortcodes = \EE_Config::instance()->core->get_critical_pages_shortcodes_array(); |
352 | - $critical_shortcodes = array_flip( $critical_shortcodes ); |
|
353 | - foreach ( $critical_shortcodes as $critical_shortcode ) { |
|
354 | - unset( \EE_Config::instance()->core->post_shortcodes[ $page_for_posts ][ $critical_shortcode ] ); |
|
352 | + $critical_shortcodes = array_flip($critical_shortcodes); |
|
353 | + foreach ($critical_shortcodes as $critical_shortcode) { |
|
354 | + unset(\EE_Config::instance()->core->post_shortcodes[$page_for_posts][$critical_shortcode]); |
|
355 | 355 | } |
356 | 356 | //only show errors |
357 | 357 | \EE_Config::instance()->update_espresso_config(); |
@@ -370,9 +370,9 @@ discard block |
||
370 | 370 | * @param string $value |
371 | 371 | * @return void |
372 | 372 | */ |
373 | - public static function reset_page_for_posts_on_initial_set( $option, $value ) |
|
373 | + public static function reset_page_for_posts_on_initial_set($option, $value) |
|
374 | 374 | { |
375 | - PostShortcodeTracking::reset_page_for_posts_on_change( $option, '', $value ); |
|
375 | + PostShortcodeTracking::reset_page_for_posts_on_change($option, '', $value); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | |
@@ -388,14 +388,14 @@ discard block |
||
388 | 388 | * @param string $value |
389 | 389 | * @return void |
390 | 390 | */ |
391 | - public static function reset_page_for_posts_on_change( $option, $old_value = '', $value = '' ) |
|
391 | + public static function reset_page_for_posts_on_change($option, $old_value = '', $value = '') |
|
392 | 392 | { |
393 | - if ( $option === 'page_for_posts' ) { |
|
393 | + if ($option === 'page_for_posts') { |
|
394 | 394 | global $wpdb; |
395 | 395 | $table = $wpdb->posts; |
396 | 396 | $SQL = "SELECT post_name from $table WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
397 | - $new_page_for_posts = $value ? $wpdb->get_var( $wpdb->prepare( $SQL, $value ) ) : 'posts'; |
|
398 | - PostShortcodeTracking::set_post_shortcodes_for_posts_page( $new_page_for_posts ); |
|
397 | + $new_page_for_posts = $value ? $wpdb->get_var($wpdb->prepare($SQL, $value)) : 'posts'; |
|
398 | + PostShortcodeTracking::set_post_shortcodes_for_posts_page($new_page_for_posts); |
|
399 | 399 | } |
400 | 400 | } |
401 | 401 | |
@@ -410,10 +410,10 @@ discard block |
||
410 | 410 | * @param string $option |
411 | 411 | * @return void |
412 | 412 | */ |
413 | - public static function reset_page_for_posts_on_delete( $option ) |
|
413 | + public static function reset_page_for_posts_on_delete($option) |
|
414 | 414 | { |
415 | - if ( $option === 'page_for_posts' ) { |
|
416 | - PostShortcodeTracking::set_post_shortcodes_for_posts_page( 'posts' ); |
|
415 | + if ($option === 'page_for_posts') { |
|
416 | + PostShortcodeTracking::set_post_shortcodes_for_posts_page('posts'); |
|
417 | 417 | } |
418 | 418 | } |
419 | 419 | |
@@ -426,37 +426,37 @@ discard block |
||
426 | 426 | * the shortcodes. If false, then the returned array will be unindexed |
427 | 427 | * @return array |
428 | 428 | */ |
429 | - public static function get_post_ids_for_shortcode( $shortcodes, $index_results = true ) |
|
429 | + public static function get_post_ids_for_shortcode($shortcodes, $index_results = true) |
|
430 | 430 | { |
431 | 431 | $post_ids = array(); |
432 | - if ( is_array( $shortcodes ) ) { |
|
433 | - foreach ( $shortcodes as $shortcode ) { |
|
432 | + if (is_array($shortcodes)) { |
|
433 | + foreach ($shortcodes as $shortcode) { |
|
434 | 434 | $new_post_ids = PostShortcodeTracking::get_post_ids_for_shortcode( |
435 | 435 | $shortcode, |
436 | 436 | $index_results |
437 | 437 | ); |
438 | - foreach ( $new_post_ids as $new_post_id ) { |
|
439 | - if ( $index_results ) { |
|
440 | - $post_ids[ $shortcode ][ $new_post_id ] = $new_post_id; |
|
438 | + foreach ($new_post_ids as $new_post_id) { |
|
439 | + if ($index_results) { |
|
440 | + $post_ids[$shortcode][$new_post_id] = $new_post_id; |
|
441 | 441 | } else { |
442 | - $post_ids[ $new_post_id ] = $new_post_id; |
|
442 | + $post_ids[$new_post_id] = $new_post_id; |
|
443 | 443 | } |
444 | 444 | } |
445 | 445 | } |
446 | 446 | } else { |
447 | - $shortcode = strtoupper( $shortcodes ); |
|
448 | - $shortcode = strpos( $shortcode, 'ESPRESSO_' ) !== 0 ? "ESPRESSO_{$shortcode}" : $shortcode; |
|
447 | + $shortcode = strtoupper($shortcodes); |
|
448 | + $shortcode = strpos($shortcode, 'ESPRESSO_') !== 0 ? "ESPRESSO_{$shortcode}" : $shortcode; |
|
449 | 449 | $page_for_posts = \EE_Config::get_page_for_posts(); |
450 | 450 | // looking for any references to this post |
451 | - foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
451 | + foreach (\EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes) { |
|
452 | 452 | // if this is the "Posts Page" (blog), then skip it |
453 | - if ( $post_name === $page_for_posts ) { |
|
453 | + if ($post_name === $page_for_posts) { |
|
454 | 454 | continue; |
455 | 455 | } |
456 | 456 | // loop thru shortcodes registered for each page, and grab post id for matches |
457 | - foreach ( (array) $post_shortcodes as $post_shortcode => $post_ID ) { |
|
458 | - if ( $post_shortcode === $shortcode ) { |
|
459 | - $post_ids[ $post_ID ] = $post_ID; |
|
457 | + foreach ((array) $post_shortcodes as $post_shortcode => $post_ID) { |
|
458 | + if ($post_shortcode === $shortcode) { |
|
459 | + $post_ids[$post_ID] = $post_ID; |
|
460 | 460 | } |
461 | 461 | } |
462 | 462 | } |
@@ -5,10 +5,10 @@ discard block |
||
5 | 5 | ?> |
6 | 6 | <div class="padding"> |
7 | 7 | |
8 | - <h2 class="ee-admin-settings-hdr"><?php _e('Countries and States/Provinces', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('country_select_info');?></h2> |
|
8 | + <h2 class="ee-admin-settings-hdr"><?php _e('Countries and States/Provinces', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('country_select_info'); ?></h2> |
|
9 | 9 | <table class="form-table"> |
10 | 10 | <tbody> |
11 | - <?php echo EEH_Form_Fields::generate_form_input( $countries ); ?> |
|
11 | + <?php echo EEH_Form_Fields::generate_form_input($countries); ?> |
|
12 | 12 | </tbody> |
13 | 13 | </table> |
14 | 14 | <br/> |
@@ -16,12 +16,12 @@ discard block |
||
16 | 16 | <?php _e('The country that is selected above will populate the Country Details settings and the options for States/Provinces. This information will be used throughout Event Espresso including for registration purposes and how currency is displayed. If you make a change to the country on this page, it is important that you also update your Contact Information on the Your Organization tab.', 'event_espresso'); ?> |
17 | 17 | </p> |
18 | 18 | <div id="country-details-settings-dv"> |
19 | - <h2 class="ee-admin-settings-hdr"><?php _e('Country Details', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('country_details_info');?></h2> |
|
19 | + <h2 class="ee-admin-settings-hdr"><?php _e('Country Details', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('country_details_info'); ?></h2> |
|
20 | 20 | <div id="country-details-dv"><?php echo $country_details_settings; ?></div> |
21 | 21 | </div> |
22 | 22 | |
23 | 23 | <div id="country-states-settings-dv"> |
24 | - <h2 class="ee-admin-settings-hdr"><?php _e( 'States/Provinces', 'event_espresso' );?> <?php echo EEH_Template::get_help_tab_link('country_states_info');?></h2> |
|
24 | + <h2 class="ee-admin-settings-hdr"><?php _e('States/Provinces', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('country_states_info'); ?></h2> |
|
25 | 25 | <div id="country-states-dv"><?php echo $country_states_settings; ?></div> |
26 | 26 | </div> |
27 | 27 |
@@ -57,11 +57,11 @@ |
||
57 | 57 | |
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * @param array $req_data |
|
62 | - * @throws EE_Error |
|
63 | - */ |
|
64 | - public function _normalize( $req_data ) { |
|
60 | + /** |
|
61 | + * @param array $req_data |
|
62 | + * @throws EE_Error |
|
63 | + */ |
|
64 | + public function _normalize( $req_data ) { |
|
65 | 65 | parent::_normalize( $req_data ); |
66 | 66 | $paypal_calculates_shipping = $this->get_input_value( 'paypal_shipping' ); |
67 | 67 | $paypal_calculates_taxes = $this->get_input_value( 'paypal_taxes' ); |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
3 | - exit( 'No direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -21,35 +21,35 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * @param EE_PMT_Paypal_Standard $payment_method_type |
23 | 23 | */ |
24 | - public function __construct( $payment_method_type ){ |
|
24 | + public function __construct($payment_method_type) { |
|
25 | 25 | parent::__construct( |
26 | 26 | array( |
27 | 27 | 'payment_method_type' => $payment_method_type, |
28 | 28 | 'extra_meta_inputs' => array( |
29 | - 'paypal_id' => new EE_Text_Input( array( |
|
30 | - 'html_label_text' => sprintf( __( "Paypal Email %s", 'event_espresso' ), $payment_method_type->get_help_tab_link() ), |
|
31 | - 'html_help_text' => __( "Typically [email protected]", 'event_espresso' ), |
|
29 | + 'paypal_id' => new EE_Text_Input(array( |
|
30 | + 'html_label_text' => sprintf(__("Paypal Email %s", 'event_espresso'), $payment_method_type->get_help_tab_link()), |
|
31 | + 'html_help_text' => __("Typically [email protected]", 'event_espresso'), |
|
32 | 32 | 'required' => true |
33 | - ) ), |
|
34 | - 'image_url' => new EE_Admin_File_Uploader_Input( array( |
|
35 | - 'html_help_text' => __( "Used for your business/personal logo on the PayPal page", 'event_espresso' ), |
|
36 | - 'html_label_text' => __( 'Image URL', 'event_espresso' ) |
|
37 | - ) ), |
|
38 | - 'paypal_taxes' => new EE_Yes_No_Input( array( |
|
39 | - 'html_label_text' => sprintf( __( 'Paypal Calculates Taxes %s', 'event_espresso' ), $payment_method_type->get_help_tab_link() ), |
|
40 | - 'html_help_text' => __( 'Whether Paypal should add taxes to the order', 'event_espresso' ), |
|
33 | + )), |
|
34 | + 'image_url' => new EE_Admin_File_Uploader_Input(array( |
|
35 | + 'html_help_text' => __("Used for your business/personal logo on the PayPal page", 'event_espresso'), |
|
36 | + 'html_label_text' => __('Image URL', 'event_espresso') |
|
37 | + )), |
|
38 | + 'paypal_taxes' => new EE_Yes_No_Input(array( |
|
39 | + 'html_label_text' => sprintf(__('Paypal Calculates Taxes %s', 'event_espresso'), $payment_method_type->get_help_tab_link()), |
|
40 | + 'html_help_text' => __('Whether Paypal should add taxes to the order', 'event_espresso'), |
|
41 | 41 | 'default' => false |
42 | - ) ), |
|
43 | - 'paypal_shipping' => new EE_Yes_No_Input( array( |
|
44 | - 'html_label_text' => sprintf( __( 'Paypal Calculates Shipping %s', 'event_espresso' ), $payment_method_type->get_help_tab_link() ), |
|
45 | - 'html_help_text' => __( 'Whether Paypal should add shipping surcharges', 'event_espresso' ), |
|
42 | + )), |
|
43 | + 'paypal_shipping' => new EE_Yes_No_Input(array( |
|
44 | + 'html_label_text' => sprintf(__('Paypal Calculates Shipping %s', 'event_espresso'), $payment_method_type->get_help_tab_link()), |
|
45 | + 'html_help_text' => __('Whether Paypal should add shipping surcharges', 'event_espresso'), |
|
46 | 46 | 'default' => false |
47 | - ) ), |
|
48 | - 'shipping_details' => new EE_Select_Input( array( |
|
49 | - EE_PMT_Paypal_Standard::shipping_info_none => __( "Do not prompt for an address", 'event_espresso' ), |
|
50 | - EE_PMT_Paypal_Standard::shipping_info_optional => __( "Prompt for an address, but do not require it", 'event_espresso' ), |
|
51 | - EE_PMT_Paypal_Standard::shipping_info_required => __( "Prompt for an address, and require it", 'event_espresso' ) |
|
52 | - ) ) |
|
47 | + )), |
|
48 | + 'shipping_details' => new EE_Select_Input(array( |
|
49 | + EE_PMT_Paypal_Standard::shipping_info_none => __("Do not prompt for an address", 'event_espresso'), |
|
50 | + EE_PMT_Paypal_Standard::shipping_info_optional => __("Prompt for an address, but do not require it", 'event_espresso'), |
|
51 | + EE_PMT_Paypal_Standard::shipping_info_required => __("Prompt for an address, and require it", 'event_espresso') |
|
52 | + )) |
|
53 | 53 | ) |
54 | 54 | ) |
55 | 55 | ); |
@@ -61,28 +61,28 @@ discard block |
||
61 | 61 | * @param array $req_data |
62 | 62 | * @throws EE_Error |
63 | 63 | */ |
64 | - public function _normalize( $req_data ) { |
|
65 | - parent::_normalize( $req_data ); |
|
66 | - $paypal_calculates_shipping = $this->get_input_value( 'paypal_shipping' ); |
|
67 | - $paypal_calculates_taxes = $this->get_input_value( 'paypal_taxes' ); |
|
68 | - $paypal_requests_address_info = $this->get_input_value( 'shipping_details' ); |
|
64 | + public function _normalize($req_data) { |
|
65 | + parent::_normalize($req_data); |
|
66 | + $paypal_calculates_shipping = $this->get_input_value('paypal_shipping'); |
|
67 | + $paypal_calculates_taxes = $this->get_input_value('paypal_taxes'); |
|
68 | + $paypal_requests_address_info = $this->get_input_value('shipping_details'); |
|
69 | 69 | if ( |
70 | - ( $paypal_calculates_shipping || $paypal_calculates_taxes ) && |
|
70 | + ($paypal_calculates_shipping || $paypal_calculates_taxes) && |
|
71 | 71 | $paypal_requests_address_info == EE_PMT_Paypal_Standard::shipping_info_none |
72 | 72 | ) { |
73 | 73 | //they want paypal to calculate taxes or shipping. They need to ask for |
74 | 74 | //address info, otherwise paypal can't calculate taxes or shipping |
75 | 75 | /** @type EE_Select_Input $shipping_details_input */ |
76 | - $shipping_details_input = $this->get_input( 'shipping_details' ); |
|
77 | - $shipping_details_input->set_default( EE_PMT_Paypal_Standard::shipping_info_optional ); |
|
76 | + $shipping_details_input = $this->get_input('shipping_details'); |
|
77 | + $shipping_details_input->set_default(EE_PMT_Paypal_Standard::shipping_info_optional); |
|
78 | 78 | $shipping_details_input_options = $shipping_details_input->options(); |
79 | 79 | EE_Error::add_attention( |
80 | 80 | sprintf( |
81 | - __( 'Automatically set "%s" to "%s" because Paypal requires address info in order to calculate shipping or taxes.', 'event_espresso' ), |
|
82 | - strip_tags( $shipping_details_input->html_label_text() ), |
|
83 | - isset( $shipping_details_input_options[ EE_PMT_Paypal_Standard::shipping_info_optional ] ) |
|
84 | - ? $shipping_details_input_options[ EE_PMT_Paypal_Standard::shipping_info_optional ] |
|
85 | - : __( 'Unknown', 'event_espresso' ) |
|
81 | + __('Automatically set "%s" to "%s" because Paypal requires address info in order to calculate shipping or taxes.', 'event_espresso'), |
|
82 | + strip_tags($shipping_details_input->html_label_text()), |
|
83 | + isset($shipping_details_input_options[EE_PMT_Paypal_Standard::shipping_info_optional]) |
|
84 | + ? $shipping_details_input_options[EE_PMT_Paypal_Standard::shipping_info_optional] |
|
85 | + : __('Unknown', 'event_espresso') |
|
86 | 86 | ), |
87 | 87 | __FILE__, __FUNCTION__, __LINE__ |
88 | 88 | ); |
@@ -27,14 +27,14 @@ discard block |
||
27 | 27 | * @throws EE_Error |
28 | 28 | * @access protected |
29 | 29 | */ |
30 | - public function __construct( $data = array() ) { |
|
30 | + public function __construct($data = array()) { |
|
31 | 31 | |
32 | 32 | //validate that the first element in the array is an EE_Attendee object. Note that the array may be indexed by REG_ID so we will just shift off the first element. |
33 | - $ctc_chk = reset( $data ); |
|
34 | - if ( ! $ctc_chk instanceof EE_Attendee ) |
|
35 | - throw new EE_Error(__('The EE_Message_Contacts_incoming_data class expects an array of EE_Attendee objects.', 'event_espresso') ); |
|
33 | + $ctc_chk = reset($data); |
|
34 | + if ( ! $ctc_chk instanceof EE_Attendee) |
|
35 | + throw new EE_Error(__('The EE_Message_Contacts_incoming_data class expects an array of EE_Attendee objects.', 'event_espresso')); |
|
36 | 36 | |
37 | - parent::__construct( $data ); |
|
37 | + parent::__construct($data); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | |
@@ -43,11 +43,11 @@ discard block |
||
43 | 43 | * @param array $attendees |
44 | 44 | * @return array |
45 | 45 | */ |
46 | - public static function convert_data_for_persistent_storage( $attendees ) { |
|
46 | + public static function convert_data_for_persistent_storage($attendees) { |
|
47 | 47 | $attendee_ids = array_filter( |
48 | 48 | array_map( |
49 | - function( $attendee ) { |
|
50 | - if ( $attendee instanceof EE_Attendee ) { |
|
49 | + function($attendee) { |
|
50 | + if ($attendee instanceof EE_Attendee) { |
|
51 | 51 | return $attendee->ID(); |
52 | 52 | } |
53 | 53 | return false; |
@@ -66,11 +66,11 @@ discard block |
||
66 | 66 | * @param array $attendee_ids |
67 | 67 | * @return EE_Attendee[] |
68 | 68 | */ |
69 | - public static function convert_data_from_persistent_storage( $attendee_ids ) { |
|
69 | + public static function convert_data_from_persistent_storage($attendee_ids) { |
|
70 | 70 | $attendee_ids = (array) $attendee_ids; |
71 | 71 | $attendees = EEM_Attendee::instance()->get_all( |
72 | 72 | array( |
73 | - array( 'ATT_ID' => array( 'IN', $attendee_ids ) ) |
|
73 | + array('ATT_ID' => array('IN', $attendee_ids)) |
|
74 | 74 | ) |
75 | 75 | ); |
76 | 76 | return $attendees; |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | $this->payment = NULL; |
100 | 100 | $this->billing = array(); |
101 | 101 | $this->reg_objs = array(); |
102 | - $this->attendees = $this->events = $this->tickets = $this->datetimes = $this->questions = $this->answer = $this->registrations = array(); |
|
102 | + $this->attendees = $this->events = $this->tickets = $this->datetimes = $this->questions = $this->answer = $this->registrations = array(); |
|
103 | 103 | $this->total_ticket_count = 0; |
104 | 104 | $this->primary_attendee_data = array( |
105 | 105 | 'registration_id' => 0, |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | 'primary_reg_obj' => NULL |
110 | 110 | ); |
111 | 111 | |
112 | - foreach ( $this->_data as $contact ) { |
|
112 | + foreach ($this->_data as $contact) { |
|
113 | 113 | $id = $contact->ID(); |
114 | 114 | $reg = $contact->get_first_related('Registration'); |
115 | 115 | $this->attendees[$id]['att_obj'] = $contact; |
@@ -5,7 +5,9 @@ discard block |
||
5 | 5 | * @subpackage helpers |
6 | 6 | * @since 4.3.0 |
7 | 7 | */ |
8 | -if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
8 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
9 | + exit('No direct script access allowed'); |
|
10 | +} |
|
9 | 11 | |
10 | 12 | /** |
11 | 13 | * This prepares data for message types that send messages for multiple contacts and handles |
@@ -31,8 +33,9 @@ discard block |
||
31 | 33 | |
32 | 34 | //validate that the first element in the array is an EE_Attendee object. Note that the array may be indexed by REG_ID so we will just shift off the first element. |
33 | 35 | $ctc_chk = reset( $data ); |
34 | - if ( ! $ctc_chk instanceof EE_Attendee ) |
|
35 | - throw new EE_Error(__('The EE_Message_Contacts_incoming_data class expects an array of EE_Attendee objects.', 'event_espresso') ); |
|
36 | + if ( ! $ctc_chk instanceof EE_Attendee ) { |
|
37 | + throw new EE_Error(__('The EE_Message_Contacts_incoming_data class expects an array of EE_Attendee objects.', 'event_espresso') ); |
|
38 | + } |
|
36 | 39 | |
37 | 40 | parent::__construct( $data ); |
38 | 41 | } |
@@ -39,13 +39,13 @@ discard block |
||
39 | 39 | * @param WP_Query $wp_query |
40 | 40 | * @param array $CPT |
41 | 41 | */ |
42 | - public function __construct( $wp_query, $CPT = array() ) { |
|
43 | - if ( $wp_query instanceof WP_Query ) { |
|
42 | + public function __construct($wp_query, $CPT = array()) { |
|
43 | + if ($wp_query instanceof WP_Query) { |
|
44 | 44 | $WP_Query = $wp_query; |
45 | 45 | $this->CPT = $CPT; |
46 | 46 | } else { |
47 | - $WP_Query = isset( $wp_query[ 'WP_Query' ] ) ? $wp_query[ 'WP_Query' ] : null; |
|
48 | - $this->CPT = isset( $wp_query[ 'CPT' ] ) ? $wp_query[ 'CPT' ] : null; |
|
47 | + $WP_Query = isset($wp_query['WP_Query']) ? $wp_query['WP_Query'] : null; |
|
48 | + $this->CPT = isset($wp_query['CPT']) ? $wp_query['CPT'] : null; |
|
49 | 49 | } |
50 | 50 | // !!!!!!!!!! IMPORTANT !!!!!!!!!!!! |
51 | 51 | // here's the list of available filters in the WP_Query object |
@@ -59,10 +59,10 @@ discard block |
||
59 | 59 | // 'posts_fields' |
60 | 60 | // 'posts_join' |
61 | 61 | $this->_add_filters(); |
62 | - if ( $WP_Query instanceof WP_Query ) { |
|
63 | - $WP_Query->is_espresso_event_single = is_singular() && isset( $WP_Query->query->post_type ) && $WP_Query->query->post_type == 'espresso_events' ? TRUE : FALSE; |
|
62 | + if ($WP_Query instanceof WP_Query) { |
|
63 | + $WP_Query->is_espresso_event_single = is_singular() && isset($WP_Query->query->post_type) && $WP_Query->query->post_type == 'espresso_events' ? TRUE : FALSE; |
|
64 | 64 | $WP_Query->is_espresso_event_archive = is_post_type_archive('espresso_events') ? TRUE : FALSE; |
65 | - $WP_Query->is_espresso_event_taxonomy = is_tax( 'espresso_event_categories' ) ? TRUE : FALSE; |
|
65 | + $WP_Query->is_espresso_event_taxonomy = is_tax('espresso_event_categories') ? TRUE : FALSE; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | } |
@@ -74,13 +74,13 @@ discard block |
||
74 | 74 | * (which will get removed in case the next call to get_posts ISN'T |
75 | 75 | * for event CPTs) |
76 | 76 | */ |
77 | - protected function _add_filters(){ |
|
78 | - add_filter( 'posts_fields', array( $this, 'posts_fields' ), 1, 2 ); |
|
79 | - add_filter( 'posts_join', array( $this, 'posts_join' ), 1, 2 ); |
|
80 | - add_filter( 'posts_where', array( $this, 'posts_where' ), 10, 2 ); |
|
77 | + protected function _add_filters() { |
|
78 | + add_filter('posts_fields', array($this, 'posts_fields'), 1, 2); |
|
79 | + add_filter('posts_join', array($this, 'posts_join'), 1, 2); |
|
80 | + add_filter('posts_where', array($this, 'posts_where'), 10, 2); |
|
81 | 81 | // add_filter( 'the_posts', array( $this, 'the_posts' ), 1, 2 ); |
82 | - add_filter( 'posts_orderby', array( $this, 'posts_orderby' ), 1, 2 ); |
|
83 | - add_filter( 'posts_groupby', array( $this, 'posts_groupby' ), 1, 2 ); |
|
82 | + add_filter('posts_orderby', array($this, 'posts_orderby'), 1, 2); |
|
83 | + add_filter('posts_groupby', array($this, 'posts_groupby'), 1, 2); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | |
@@ -90,13 +90,13 @@ discard block |
||
90 | 90 | * This is to avoid applying this CPT strategy for other posts or CPTs (eg, |
91 | 91 | * we don't want to join to the datetime table when querying for venues, do we!?) |
92 | 92 | */ |
93 | - protected function _remove_filters(){ |
|
94 | - remove_filter( 'posts_fields', array( $this, 'posts_fields' ), 1 ); |
|
95 | - remove_filter( 'posts_join', array( $this, 'posts_join' ), 1 ); |
|
96 | - remove_filter( 'posts_where', array( $this, 'posts_where' ), 10 ); |
|
93 | + protected function _remove_filters() { |
|
94 | + remove_filter('posts_fields', array($this, 'posts_fields'), 1); |
|
95 | + remove_filter('posts_join', array($this, 'posts_join'), 1); |
|
96 | + remove_filter('posts_where', array($this, 'posts_where'), 10); |
|
97 | 97 | // remove_filter( 'the_posts', array( $this, 'the_posts' ), 1 ); |
98 | - remove_filter( 'posts_orderby', array( $this, 'posts_orderby' ), 1 ); |
|
99 | - remove_filter( 'posts_groupby', array( $this, 'posts_groupby' ), 1 ); |
|
98 | + remove_filter('posts_orderby', array($this, 'posts_orderby'), 1); |
|
99 | + remove_filter('posts_groupby', array($this, 'posts_groupby'), 1); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @param WP_Query $wp_query |
110 | 110 | * @return string |
111 | 111 | */ |
112 | - public function posts_fields( $SQL, WP_Query $wp_query ) { |
|
112 | + public function posts_fields($SQL, WP_Query $wp_query) { |
|
113 | 113 | if ( |
114 | 114 | $wp_query instanceof WP_Query |
115 | 115 | && |
@@ -120,11 +120,11 @@ discard block |
||
120 | 120 | ) |
121 | 121 | ) { |
122 | 122 | // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement |
123 | - $SQL .= ', ' . EEM_Datetime::instance()->table() . '.* ' ; |
|
124 | - if ( $wp_query->is_espresso_event_archive || $wp_query->is_espresso_event_taxonomy ) { |
|
123 | + $SQL .= ', '.EEM_Datetime::instance()->table().'.* '; |
|
124 | + if ($wp_query->is_espresso_event_archive || $wp_query->is_espresso_event_taxonomy) { |
|
125 | 125 | // because we only want to retrieve the next upcoming datetime for each event: |
126 | 126 | // add something like ", MIN( wp_esp_datetime.DTT_EVT_start ) as event_start_date " to WP Query SELECT statement |
127 | - $SQL .= ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ' ; |
|
127 | + $SQL .= ', MIN( '.EEM_Datetime::instance()->table().'.DTT_EVT_start ) as event_start_date '; |
|
128 | 128 | } |
129 | 129 | } |
130 | 130 | return $SQL; |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | * @internal param \WP_Query $WP_Query |
142 | 142 | * @return string |
143 | 143 | */ |
144 | - public function posts_join( $SQL, WP_Query $wp_query ) { |
|
144 | + public function posts_join($SQL, WP_Query $wp_query) { |
|
145 | 145 | if ( |
146 | 146 | $wp_query instanceof WP_Query |
147 | 147 | && |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | ) |
153 | 153 | ) { |
154 | 154 | // adds something like " LEFT JOIN wp_esp_datetime ON ( wp_esp_datetime.EVT_ID = wp_posts.ID ) " to WP Query JOIN statement |
155 | - $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table() . '.ID = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name() . ' ) '; |
|
155 | + $SQL .= ' INNER JOIN '.EEM_Datetime::instance()->table().' ON ( '.EEM_Event::instance()->table().'.ID = '.EEM_Datetime::instance()->table().'.'.EEM_Event::instance()->primary_key_name().' ) '; |
|
156 | 156 | } |
157 | 157 | return $SQL; |
158 | 158 | } |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | * @param WP_Query $wp_query |
168 | 168 | * @return string |
169 | 169 | */ |
170 | - public function posts_where( $SQL, WP_Query $wp_query ) { |
|
170 | + public function posts_where($SQL, WP_Query $wp_query) { |
|
171 | 171 | // global $wpdb; |
172 | 172 | if ( |
173 | 173 | $wp_query instanceof WP_Query |
@@ -177,8 +177,8 @@ discard block |
||
177 | 177 | || $wp_query->is_espresso_event_taxonomy |
178 | 178 | ) |
179 | 179 | ) { |
180 | - if ( ! isset( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive ) || ! isset( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events ) || ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events ) { |
|
181 | - $SQL .= ' AND ' . EEM_Datetime::instance()->table() . ".DTT_EVT_end > '" . current_time( 'mysql', true ) . "' "; |
|
180 | + if ( ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive) || ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events) || ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events) { |
|
181 | + $SQL .= ' AND '.EEM_Datetime::instance()->table().".DTT_EVT_end > '".current_time('mysql', true)."' "; |
|
182 | 182 | } |
183 | 183 | } |
184 | 184 | return $SQL; |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | * @param WP_Query $wp_query |
195 | 195 | * @return string |
196 | 196 | */ |
197 | - public function posts_orderby( $SQL, WP_Query $wp_query ) { |
|
197 | + public function posts_orderby($SQL, WP_Query $wp_query) { |
|
198 | 198 | if ( |
199 | 199 | $wp_query instanceof WP_Query |
200 | 200 | && |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | * @param WP_Query $wp_query |
219 | 219 | * @return string |
220 | 220 | */ |
221 | - public function posts_groupby( $SQL, WP_Query $wp_query ) { |
|
221 | + public function posts_groupby($SQL, WP_Query $wp_query) { |
|
222 | 222 | if ( |
223 | 223 | $wp_query instanceof WP_Query |
224 | 224 | && |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | // we're joining to the datetimes table, where there can be MANY datetimes for a single event, but we want to only show each event only once |
232 | 232 | // (whereas if we didn't group them by the post's ID, then we would end up with many repeats) |
233 | 233 | global $wpdb; |
234 | - $SQL = $wpdb->posts . '.ID '; |
|
234 | + $SQL = $wpdb->posts.'.ID '; |
|
235 | 235 | } |
236 | 236 | return $SQL; |
237 | 237 | } |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | * @param WP_Query $wp_query |
247 | 247 | * @return array |
248 | 248 | */ |
249 | - public function the_posts( $posts, WP_Query $wp_query ) { |
|
249 | + public function the_posts($posts, WP_Query $wp_query) { |
|
250 | 250 | return $posts; |
251 | 251 | } |
252 | 252 | |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * @param $single |
263 | 263 | * @return string |
264 | 264 | */ |
265 | - public function get_EE_post_type_metadata( $meta_value = NULL, $post_id, $meta_key, $single ) { |
|
265 | + public function get_EE_post_type_metadata($meta_value = NULL, $post_id, $meta_key, $single) { |
|
266 | 266 | return $meta_value; |
267 | 267 | } |
268 | 268 |
@@ -1,4 +1,6 @@ |
||
1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | +} |
|
2 | 4 | /** |
3 | 5 | * Event Espresso |
4 | 6 | * |