@@ -16,445 +16,445 @@ |
||
| 16 | 16 | class EE_CPT_Strategy extends EE_Base |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var EE_CPT_Strategy $_instance |
|
| 21 | - */ |
|
| 22 | - private static $_instance; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * the current page, if it utilizes CPTs |
|
| 26 | - * |
|
| 27 | - * @var array $CPT |
|
| 28 | - */ |
|
| 29 | - protected $CPT; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * return value from CustomPostTypeDefinitions::getDefinitions() |
|
| 33 | - * |
|
| 34 | - * @var array $_CPTs |
|
| 35 | - */ |
|
| 36 | - protected $_CPTs = array(); |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var array $_CPT_taxonomies |
|
| 40 | - */ |
|
| 41 | - protected $_CPT_taxonomies = array(); |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var array $_CPT_terms |
|
| 45 | - */ |
|
| 46 | - protected $_CPT_terms = array(); |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var array $_CPT_endpoints |
|
| 50 | - */ |
|
| 51 | - protected $_CPT_endpoints = array(); |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var EEM_Base $CPT_model |
|
| 55 | - */ |
|
| 56 | - protected $CPT_model; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var EventEspresso\Core\CPTs\CptQueryModifier $query_modifier |
|
| 60 | - */ |
|
| 61 | - protected $query_modifier; |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @singleton method used to instantiate class object |
|
| 66 | - * @param CustomPostTypeDefinitions|null $custom_post_types |
|
| 67 | - * @param CustomTaxonomyDefinitions|null $taxonomies |
|
| 68 | - * @return EE_CPT_Strategy |
|
| 69 | - */ |
|
| 70 | - public static function instance( |
|
| 71 | - CustomPostTypeDefinitions $custom_post_types = null, |
|
| 72 | - CustomTaxonomyDefinitions $taxonomies = null |
|
| 73 | - ) { |
|
| 74 | - // check if class object is instantiated |
|
| 75 | - if (! self::$_instance instanceof EE_CPT_Strategy |
|
| 76 | - && $custom_post_types instanceof CustomPostTypeDefinitions |
|
| 77 | - && $taxonomies instanceof CustomTaxonomyDefinitions |
|
| 78 | - ) { |
|
| 79 | - self::$_instance = new self($custom_post_types, $taxonomies); |
|
| 80 | - } |
|
| 81 | - return self::$_instance; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @param CustomPostTypeDefinitions $custom_post_types |
|
| 87 | - * @param CustomTaxonomyDefinitions $taxonomies |
|
| 88 | - */ |
|
| 89 | - protected function __construct( |
|
| 90 | - CustomPostTypeDefinitions $custom_post_types, |
|
| 91 | - CustomTaxonomyDefinitions $taxonomies |
|
| 92 | - ) { |
|
| 93 | - // get CPT data |
|
| 94 | - $this->_CPTs = $custom_post_types->getDefinitions(); |
|
| 95 | - $this->_CPT_endpoints = $this->_set_CPT_endpoints(); |
|
| 96 | - $this->_CPT_taxonomies = $taxonomies->getCustomTaxonomyDefinitions(); |
|
| 97 | - add_action('pre_get_posts', array($this, 'pre_get_posts'), 5); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @return array |
|
| 103 | - */ |
|
| 104 | - public function get_CPT_endpoints() |
|
| 105 | - { |
|
| 106 | - return $this->_CPT_endpoints; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @return array |
|
| 112 | - */ |
|
| 113 | - public function get_CPT_taxonomies() |
|
| 114 | - { |
|
| 115 | - return $this->_CPT_taxonomies; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * add CPT "slugs" to array of default espresso "pages" |
|
| 121 | - * |
|
| 122 | - * @return array |
|
| 123 | - */ |
|
| 124 | - private function _set_CPT_endpoints() |
|
| 125 | - { |
|
| 126 | - $_CPT_endpoints = array(); |
|
| 127 | - if (is_array($this->_CPTs)) { |
|
| 128 | - foreach ($this->_CPTs as $CPT_type => $CPT) { |
|
| 129 | - $_CPT_endpoints [ $CPT['plural_slug'] ] = $CPT_type; |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - return $_CPT_endpoints; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * If this query (not just "main" queries (ie, for WP's infamous "loop")) is for an EE CPT, then we want to |
|
| 138 | - * supercharge the get_posts query to add our EE stuff (like joining to our tables, selecting extra columns, and |
|
| 139 | - * adding EE objects to the post to facilitate further querying of related data etc) |
|
| 140 | - * |
|
| 141 | - * @param WP_Query $WP_Query |
|
| 142 | - * @return void |
|
| 143 | - * @throws \EE_Error |
|
| 144 | - * @throws \InvalidArgumentException |
|
| 145 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 146 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 147 | - */ |
|
| 148 | - public function pre_get_posts($WP_Query) |
|
| 149 | - { |
|
| 150 | - // check that post-type is set |
|
| 151 | - if (! $WP_Query instanceof WP_Query) { |
|
| 152 | - return; |
|
| 153 | - } |
|
| 154 | - // add our conditionals |
|
| 155 | - $this->_set_EE_tags_on_WP_Query($WP_Query); |
|
| 156 | - // check for terms |
|
| 157 | - $this->_set_post_type_for_terms($WP_Query); |
|
| 158 | - // make sure paging is always set |
|
| 159 | - $this->_set_paging($WP_Query); |
|
| 160 | - // is a taxonomy set ? |
|
| 161 | - $this->_set_CPT_taxonomies_on_WP_Query($WP_Query); |
|
| 162 | - // loop thru post_types if set |
|
| 163 | - $this->_process_WP_Query_post_types($WP_Query); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * @param WP_Query $WP_Query |
|
| 169 | - * @return void |
|
| 170 | - */ |
|
| 171 | - private function _set_EE_tags_on_WP_Query(WP_Query $WP_Query) |
|
| 172 | - { |
|
| 173 | - $WP_Query->is_espresso_event_single = false; |
|
| 174 | - $WP_Query->is_espresso_event_archive = false; |
|
| 175 | - $WP_Query->is_espresso_event_taxonomy = false; |
|
| 176 | - $WP_Query->is_espresso_venue_single = false; |
|
| 177 | - $WP_Query->is_espresso_venue_archive = false; |
|
| 178 | - $WP_Query->is_espresso_venue_taxonomy = false; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * @return void |
|
| 184 | - * @throws EE_Error |
|
| 185 | - * @throws InvalidArgumentException |
|
| 186 | - * @throws InvalidDataTypeException |
|
| 187 | - * @throws InvalidInterfaceException |
|
| 188 | - */ |
|
| 189 | - private function _set_CPT_terms() |
|
| 190 | - { |
|
| 191 | - if (empty($this->_CPT_terms)) { |
|
| 192 | - $terms = EEM_Term::instance()->get_all_CPT_post_tags(); |
|
| 193 | - foreach ($terms as $term) { |
|
| 194 | - if ($term instanceof EE_Term) { |
|
| 195 | - $this->_CPT_terms[ $term->slug() ] = $term; |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * @param WP_Query $WP_Query |
|
| 204 | - * @return void |
|
| 205 | - * @throws EE_Error |
|
| 206 | - * @throws InvalidArgumentException |
|
| 207 | - * @throws InvalidDataTypeException |
|
| 208 | - * @throws InvalidInterfaceException |
|
| 209 | - */ |
|
| 210 | - private function _set_post_type_for_terms(WP_Query $WP_Query) |
|
| 211 | - { |
|
| 212 | - // is a tag set ? |
|
| 213 | - if (isset($WP_Query->query['tag'])) { |
|
| 214 | - // get term for tag |
|
| 215 | - $term = EEM_Term::instance()->get_post_tag_for_event_or_venue($WP_Query->query['tag']); |
|
| 216 | - // verify the term |
|
| 217 | - if ($term instanceof EE_Term) { |
|
| 218 | - $term->post_type = array_merge(array('post', 'page'), (array) $term->post_type); |
|
| 219 | - $term->post_type = apply_filters( |
|
| 220 | - 'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type', |
|
| 221 | - $term->post_type, |
|
| 222 | - $term |
|
| 223 | - ); |
|
| 224 | - // if a post type is already set |
|
| 225 | - if (isset($WP_Query->query_vars['post_type'])) { |
|
| 226 | - // add to existing array |
|
| 227 | - $term->post_type = array_merge((array) $WP_Query->query_vars['post_type'], $term->post_type); |
|
| 228 | - } |
|
| 229 | - // just set post_type to our CPT |
|
| 230 | - $WP_Query->set('post_type', array_unique($term->post_type)); |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * @param WP_Query $WP_Query |
|
| 238 | - * @return void |
|
| 239 | - */ |
|
| 240 | - public function _set_paging($WP_Query) |
|
| 241 | - { |
|
| 242 | - if ($WP_Query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', true)) { |
|
| 243 | - $page = get_query_var('page') ? get_query_var('page') : null; |
|
| 244 | - $paged = get_query_var('paged') ? get_query_var('paged') : $page; |
|
| 245 | - $WP_Query->set('paged', $paged); |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * @param \WP_Query $WP_Query |
|
| 252 | - */ |
|
| 253 | - protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $WP_Query) |
|
| 254 | - { |
|
| 255 | - // is a taxonomy set ? |
|
| 256 | - if ($WP_Query->is_tax) { |
|
| 257 | - // loop thru our taxonomies |
|
| 258 | - foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) { |
|
| 259 | - // check if one of our taxonomies is set as a query var |
|
| 260 | - if (isset($WP_Query->query[ $CPT_taxonomy ])) { |
|
| 261 | - // but which CPT does that correspond to??? hmmm... guess we gotta go looping |
|
| 262 | - foreach ($this->_CPTs as $post_type => $CPT) { |
|
| 263 | - // verify our CPT has args, is public and has taxonomies set |
|
| 264 | - if (isset($CPT['args']['public']) |
|
| 265 | - && $CPT['args']['public'] |
|
| 266 | - && ! empty($CPT['args']['taxonomies']) |
|
| 267 | - && in_array($CPT_taxonomy, $CPT['args']['taxonomies'], true) |
|
| 268 | - ) { |
|
| 269 | - // if so, then add this CPT post_type to the current query's array of post_types' |
|
| 270 | - $WP_Query->query_vars['post_type'] = isset($WP_Query->query_vars['post_type']) |
|
| 271 | - ? (array) $WP_Query->query_vars['post_type'] |
|
| 272 | - : array(); |
|
| 273 | - $WP_Query->query_vars['post_type'][] = $post_type; |
|
| 274 | - switch ($post_type) { |
|
| 275 | - case 'espresso_events': |
|
| 276 | - $WP_Query->is_espresso_event_taxonomy = true; |
|
| 277 | - break; |
|
| 278 | - case 'espresso_venues': |
|
| 279 | - $WP_Query->is_espresso_venue_taxonomy = true; |
|
| 280 | - break; |
|
| 281 | - default: |
|
| 282 | - do_action( |
|
| 283 | - 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type', |
|
| 284 | - $WP_Query, |
|
| 285 | - $this |
|
| 286 | - ); |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * @param \WP_Query $WP_Query |
|
| 298 | - * @throws InvalidArgumentException |
|
| 299 | - * @throws InvalidDataTypeException |
|
| 300 | - * @throws InvalidInterfaceException |
|
| 301 | - */ |
|
| 302 | - protected function _process_WP_Query_post_types(WP_Query $WP_Query) |
|
| 303 | - { |
|
| 304 | - if (isset($WP_Query->query_vars['post_type'])) { |
|
| 305 | - // loop thru post_types as array |
|
| 306 | - foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) { |
|
| 307 | - // is current query for an EE CPT ? |
|
| 308 | - if (isset($this->_CPTs[ $post_type ])) { |
|
| 309 | - // is EE on or off ? |
|
| 310 | - if (EE_Maintenance_Mode::instance()->level()) { |
|
| 311 | - // reroute CPT template view to maintenance_mode.template.php |
|
| 312 | - if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
| 313 | - add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999); |
|
| 314 | - } |
|
| 315 | - if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) { |
|
| 316 | - add_filter('the_content', array($this, 'inject_EE_shortcode_placeholder'), 1); |
|
| 317 | - } |
|
| 318 | - return; |
|
| 319 | - } |
|
| 320 | - $this->_generate_CptQueryModifier($WP_Query, $post_type); |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * @param \WP_Query $WP_Query |
|
| 329 | - * @param string $post_type |
|
| 330 | - * @throws InvalidArgumentException |
|
| 331 | - * @throws InvalidDataTypeException |
|
| 332 | - * @throws InvalidInterfaceException |
|
| 333 | - */ |
|
| 334 | - protected function _generate_CptQueryModifier(WP_Query $WP_Query, $post_type) |
|
| 335 | - { |
|
| 336 | - $this->query_modifier = LoaderFactory::getLoader()->getShared( |
|
| 337 | - 'EventEspresso\core\CPTs\CptQueryModifier', |
|
| 338 | - array( |
|
| 339 | - $post_type, |
|
| 340 | - $this->_CPTs[ $post_type ], |
|
| 341 | - $WP_Query, |
|
| 342 | - ) |
|
| 343 | - ); |
|
| 344 | - $this->_CPT_taxonomies = $this->query_modifier->taxonomies(); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * inject_EE_shortcode_placeholder |
|
| 350 | - * in order to display the M-Mode notice on our CPT routes, |
|
| 351 | - * we need to first inject what looks like one of our shortcodes, |
|
| 352 | - * so that it can be replaced with the actual M-Mode notice |
|
| 353 | - * |
|
| 354 | - * @return string |
|
| 355 | - */ |
|
| 356 | - public function inject_EE_shortcode_placeholder() |
|
| 357 | - { |
|
| 358 | - return '[ESPRESSO_'; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * @deprecated |
|
| 364 | - * @since 4.8.41 |
|
| 365 | - * @return void |
|
| 366 | - */ |
|
| 367 | - public function _possibly_set_ee_request_var() |
|
| 368 | - { |
|
| 369 | - $this->query_modifier->setRequestVarsIfCpt(); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * @deprecated |
|
| 375 | - * @since 4.8.41 |
|
| 376 | - * @param $SQL |
|
| 377 | - * @return string |
|
| 378 | - */ |
|
| 379 | - public function posts_fields($SQL) |
|
| 380 | - { |
|
| 381 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 382 | - return $this->query_modifier->postsFields($SQL); |
|
| 383 | - } |
|
| 384 | - return $SQL; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * @deprecated |
|
| 390 | - * @since 4.8.41 |
|
| 391 | - * @param $SQL |
|
| 392 | - * @return string |
|
| 393 | - */ |
|
| 394 | - public function posts_join($SQL) |
|
| 395 | - { |
|
| 396 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 397 | - return $this->query_modifier->postsJoin($SQL); |
|
| 398 | - } |
|
| 399 | - return $SQL; |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * @deprecated |
|
| 405 | - * @since 4.8.41 |
|
| 406 | - * @param \WP_Post[] $posts |
|
| 407 | - * @return \WP_Post[] |
|
| 408 | - */ |
|
| 409 | - public function the_posts($posts) |
|
| 410 | - { |
|
| 411 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 412 | - $this->query_modifier->thePosts($posts); |
|
| 413 | - } |
|
| 414 | - return $posts; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - * @deprecated |
|
| 420 | - * @since 4.8.41 |
|
| 421 | - * @param $url |
|
| 422 | - * @param $ID |
|
| 423 | - * @return string |
|
| 424 | - */ |
|
| 425 | - public function get_edit_post_link($url, $ID) |
|
| 426 | - { |
|
| 427 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 428 | - return $this->query_modifier->getEditPostLink($url, $ID); |
|
| 429 | - } |
|
| 430 | - return ''; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * @deprecated |
|
| 436 | - * @since 4.8.41 |
|
| 437 | - * @param null $WP_Query |
|
| 438 | - */ |
|
| 439 | - protected function _do_template_filters($WP_Query = null) |
|
| 440 | - { |
|
| 441 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 442 | - $this->query_modifier->addTemplateFilters(); |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * @deprecated |
|
| 449 | - * @since 4.8.41 |
|
| 450 | - * @param string $current_template Existing default template path derived for this page call. |
|
| 451 | - * @return string the path to the full template file. |
|
| 452 | - */ |
|
| 453 | - public function single_cpt_template($current_template) |
|
| 454 | - { |
|
| 455 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 456 | - return $this->query_modifier->singleCptTemplate($current_template); |
|
| 457 | - } |
|
| 458 | - return $current_template; |
|
| 459 | - } |
|
| 19 | + /** |
|
| 20 | + * @var EE_CPT_Strategy $_instance |
|
| 21 | + */ |
|
| 22 | + private static $_instance; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * the current page, if it utilizes CPTs |
|
| 26 | + * |
|
| 27 | + * @var array $CPT |
|
| 28 | + */ |
|
| 29 | + protected $CPT; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * return value from CustomPostTypeDefinitions::getDefinitions() |
|
| 33 | + * |
|
| 34 | + * @var array $_CPTs |
|
| 35 | + */ |
|
| 36 | + protected $_CPTs = array(); |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var array $_CPT_taxonomies |
|
| 40 | + */ |
|
| 41 | + protected $_CPT_taxonomies = array(); |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var array $_CPT_terms |
|
| 45 | + */ |
|
| 46 | + protected $_CPT_terms = array(); |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var array $_CPT_endpoints |
|
| 50 | + */ |
|
| 51 | + protected $_CPT_endpoints = array(); |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var EEM_Base $CPT_model |
|
| 55 | + */ |
|
| 56 | + protected $CPT_model; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var EventEspresso\Core\CPTs\CptQueryModifier $query_modifier |
|
| 60 | + */ |
|
| 61 | + protected $query_modifier; |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @singleton method used to instantiate class object |
|
| 66 | + * @param CustomPostTypeDefinitions|null $custom_post_types |
|
| 67 | + * @param CustomTaxonomyDefinitions|null $taxonomies |
|
| 68 | + * @return EE_CPT_Strategy |
|
| 69 | + */ |
|
| 70 | + public static function instance( |
|
| 71 | + CustomPostTypeDefinitions $custom_post_types = null, |
|
| 72 | + CustomTaxonomyDefinitions $taxonomies = null |
|
| 73 | + ) { |
|
| 74 | + // check if class object is instantiated |
|
| 75 | + if (! self::$_instance instanceof EE_CPT_Strategy |
|
| 76 | + && $custom_post_types instanceof CustomPostTypeDefinitions |
|
| 77 | + && $taxonomies instanceof CustomTaxonomyDefinitions |
|
| 78 | + ) { |
|
| 79 | + self::$_instance = new self($custom_post_types, $taxonomies); |
|
| 80 | + } |
|
| 81 | + return self::$_instance; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @param CustomPostTypeDefinitions $custom_post_types |
|
| 87 | + * @param CustomTaxonomyDefinitions $taxonomies |
|
| 88 | + */ |
|
| 89 | + protected function __construct( |
|
| 90 | + CustomPostTypeDefinitions $custom_post_types, |
|
| 91 | + CustomTaxonomyDefinitions $taxonomies |
|
| 92 | + ) { |
|
| 93 | + // get CPT data |
|
| 94 | + $this->_CPTs = $custom_post_types->getDefinitions(); |
|
| 95 | + $this->_CPT_endpoints = $this->_set_CPT_endpoints(); |
|
| 96 | + $this->_CPT_taxonomies = $taxonomies->getCustomTaxonomyDefinitions(); |
|
| 97 | + add_action('pre_get_posts', array($this, 'pre_get_posts'), 5); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @return array |
|
| 103 | + */ |
|
| 104 | + public function get_CPT_endpoints() |
|
| 105 | + { |
|
| 106 | + return $this->_CPT_endpoints; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @return array |
|
| 112 | + */ |
|
| 113 | + public function get_CPT_taxonomies() |
|
| 114 | + { |
|
| 115 | + return $this->_CPT_taxonomies; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * add CPT "slugs" to array of default espresso "pages" |
|
| 121 | + * |
|
| 122 | + * @return array |
|
| 123 | + */ |
|
| 124 | + private function _set_CPT_endpoints() |
|
| 125 | + { |
|
| 126 | + $_CPT_endpoints = array(); |
|
| 127 | + if (is_array($this->_CPTs)) { |
|
| 128 | + foreach ($this->_CPTs as $CPT_type => $CPT) { |
|
| 129 | + $_CPT_endpoints [ $CPT['plural_slug'] ] = $CPT_type; |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + return $_CPT_endpoints; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * If this query (not just "main" queries (ie, for WP's infamous "loop")) is for an EE CPT, then we want to |
|
| 138 | + * supercharge the get_posts query to add our EE stuff (like joining to our tables, selecting extra columns, and |
|
| 139 | + * adding EE objects to the post to facilitate further querying of related data etc) |
|
| 140 | + * |
|
| 141 | + * @param WP_Query $WP_Query |
|
| 142 | + * @return void |
|
| 143 | + * @throws \EE_Error |
|
| 144 | + * @throws \InvalidArgumentException |
|
| 145 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 146 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 147 | + */ |
|
| 148 | + public function pre_get_posts($WP_Query) |
|
| 149 | + { |
|
| 150 | + // check that post-type is set |
|
| 151 | + if (! $WP_Query instanceof WP_Query) { |
|
| 152 | + return; |
|
| 153 | + } |
|
| 154 | + // add our conditionals |
|
| 155 | + $this->_set_EE_tags_on_WP_Query($WP_Query); |
|
| 156 | + // check for terms |
|
| 157 | + $this->_set_post_type_for_terms($WP_Query); |
|
| 158 | + // make sure paging is always set |
|
| 159 | + $this->_set_paging($WP_Query); |
|
| 160 | + // is a taxonomy set ? |
|
| 161 | + $this->_set_CPT_taxonomies_on_WP_Query($WP_Query); |
|
| 162 | + // loop thru post_types if set |
|
| 163 | + $this->_process_WP_Query_post_types($WP_Query); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * @param WP_Query $WP_Query |
|
| 169 | + * @return void |
|
| 170 | + */ |
|
| 171 | + private function _set_EE_tags_on_WP_Query(WP_Query $WP_Query) |
|
| 172 | + { |
|
| 173 | + $WP_Query->is_espresso_event_single = false; |
|
| 174 | + $WP_Query->is_espresso_event_archive = false; |
|
| 175 | + $WP_Query->is_espresso_event_taxonomy = false; |
|
| 176 | + $WP_Query->is_espresso_venue_single = false; |
|
| 177 | + $WP_Query->is_espresso_venue_archive = false; |
|
| 178 | + $WP_Query->is_espresso_venue_taxonomy = false; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * @return void |
|
| 184 | + * @throws EE_Error |
|
| 185 | + * @throws InvalidArgumentException |
|
| 186 | + * @throws InvalidDataTypeException |
|
| 187 | + * @throws InvalidInterfaceException |
|
| 188 | + */ |
|
| 189 | + private function _set_CPT_terms() |
|
| 190 | + { |
|
| 191 | + if (empty($this->_CPT_terms)) { |
|
| 192 | + $terms = EEM_Term::instance()->get_all_CPT_post_tags(); |
|
| 193 | + foreach ($terms as $term) { |
|
| 194 | + if ($term instanceof EE_Term) { |
|
| 195 | + $this->_CPT_terms[ $term->slug() ] = $term; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * @param WP_Query $WP_Query |
|
| 204 | + * @return void |
|
| 205 | + * @throws EE_Error |
|
| 206 | + * @throws InvalidArgumentException |
|
| 207 | + * @throws InvalidDataTypeException |
|
| 208 | + * @throws InvalidInterfaceException |
|
| 209 | + */ |
|
| 210 | + private function _set_post_type_for_terms(WP_Query $WP_Query) |
|
| 211 | + { |
|
| 212 | + // is a tag set ? |
|
| 213 | + if (isset($WP_Query->query['tag'])) { |
|
| 214 | + // get term for tag |
|
| 215 | + $term = EEM_Term::instance()->get_post_tag_for_event_or_venue($WP_Query->query['tag']); |
|
| 216 | + // verify the term |
|
| 217 | + if ($term instanceof EE_Term) { |
|
| 218 | + $term->post_type = array_merge(array('post', 'page'), (array) $term->post_type); |
|
| 219 | + $term->post_type = apply_filters( |
|
| 220 | + 'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type', |
|
| 221 | + $term->post_type, |
|
| 222 | + $term |
|
| 223 | + ); |
|
| 224 | + // if a post type is already set |
|
| 225 | + if (isset($WP_Query->query_vars['post_type'])) { |
|
| 226 | + // add to existing array |
|
| 227 | + $term->post_type = array_merge((array) $WP_Query->query_vars['post_type'], $term->post_type); |
|
| 228 | + } |
|
| 229 | + // just set post_type to our CPT |
|
| 230 | + $WP_Query->set('post_type', array_unique($term->post_type)); |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * @param WP_Query $WP_Query |
|
| 238 | + * @return void |
|
| 239 | + */ |
|
| 240 | + public function _set_paging($WP_Query) |
|
| 241 | + { |
|
| 242 | + if ($WP_Query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', true)) { |
|
| 243 | + $page = get_query_var('page') ? get_query_var('page') : null; |
|
| 244 | + $paged = get_query_var('paged') ? get_query_var('paged') : $page; |
|
| 245 | + $WP_Query->set('paged', $paged); |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * @param \WP_Query $WP_Query |
|
| 252 | + */ |
|
| 253 | + protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $WP_Query) |
|
| 254 | + { |
|
| 255 | + // is a taxonomy set ? |
|
| 256 | + if ($WP_Query->is_tax) { |
|
| 257 | + // loop thru our taxonomies |
|
| 258 | + foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) { |
|
| 259 | + // check if one of our taxonomies is set as a query var |
|
| 260 | + if (isset($WP_Query->query[ $CPT_taxonomy ])) { |
|
| 261 | + // but which CPT does that correspond to??? hmmm... guess we gotta go looping |
|
| 262 | + foreach ($this->_CPTs as $post_type => $CPT) { |
|
| 263 | + // verify our CPT has args, is public and has taxonomies set |
|
| 264 | + if (isset($CPT['args']['public']) |
|
| 265 | + && $CPT['args']['public'] |
|
| 266 | + && ! empty($CPT['args']['taxonomies']) |
|
| 267 | + && in_array($CPT_taxonomy, $CPT['args']['taxonomies'], true) |
|
| 268 | + ) { |
|
| 269 | + // if so, then add this CPT post_type to the current query's array of post_types' |
|
| 270 | + $WP_Query->query_vars['post_type'] = isset($WP_Query->query_vars['post_type']) |
|
| 271 | + ? (array) $WP_Query->query_vars['post_type'] |
|
| 272 | + : array(); |
|
| 273 | + $WP_Query->query_vars['post_type'][] = $post_type; |
|
| 274 | + switch ($post_type) { |
|
| 275 | + case 'espresso_events': |
|
| 276 | + $WP_Query->is_espresso_event_taxonomy = true; |
|
| 277 | + break; |
|
| 278 | + case 'espresso_venues': |
|
| 279 | + $WP_Query->is_espresso_venue_taxonomy = true; |
|
| 280 | + break; |
|
| 281 | + default: |
|
| 282 | + do_action( |
|
| 283 | + 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type', |
|
| 284 | + $WP_Query, |
|
| 285 | + $this |
|
| 286 | + ); |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * @param \WP_Query $WP_Query |
|
| 298 | + * @throws InvalidArgumentException |
|
| 299 | + * @throws InvalidDataTypeException |
|
| 300 | + * @throws InvalidInterfaceException |
|
| 301 | + */ |
|
| 302 | + protected function _process_WP_Query_post_types(WP_Query $WP_Query) |
|
| 303 | + { |
|
| 304 | + if (isset($WP_Query->query_vars['post_type'])) { |
|
| 305 | + // loop thru post_types as array |
|
| 306 | + foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) { |
|
| 307 | + // is current query for an EE CPT ? |
|
| 308 | + if (isset($this->_CPTs[ $post_type ])) { |
|
| 309 | + // is EE on or off ? |
|
| 310 | + if (EE_Maintenance_Mode::instance()->level()) { |
|
| 311 | + // reroute CPT template view to maintenance_mode.template.php |
|
| 312 | + if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
| 313 | + add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999); |
|
| 314 | + } |
|
| 315 | + if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) { |
|
| 316 | + add_filter('the_content', array($this, 'inject_EE_shortcode_placeholder'), 1); |
|
| 317 | + } |
|
| 318 | + return; |
|
| 319 | + } |
|
| 320 | + $this->_generate_CptQueryModifier($WP_Query, $post_type); |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * @param \WP_Query $WP_Query |
|
| 329 | + * @param string $post_type |
|
| 330 | + * @throws InvalidArgumentException |
|
| 331 | + * @throws InvalidDataTypeException |
|
| 332 | + * @throws InvalidInterfaceException |
|
| 333 | + */ |
|
| 334 | + protected function _generate_CptQueryModifier(WP_Query $WP_Query, $post_type) |
|
| 335 | + { |
|
| 336 | + $this->query_modifier = LoaderFactory::getLoader()->getShared( |
|
| 337 | + 'EventEspresso\core\CPTs\CptQueryModifier', |
|
| 338 | + array( |
|
| 339 | + $post_type, |
|
| 340 | + $this->_CPTs[ $post_type ], |
|
| 341 | + $WP_Query, |
|
| 342 | + ) |
|
| 343 | + ); |
|
| 344 | + $this->_CPT_taxonomies = $this->query_modifier->taxonomies(); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * inject_EE_shortcode_placeholder |
|
| 350 | + * in order to display the M-Mode notice on our CPT routes, |
|
| 351 | + * we need to first inject what looks like one of our shortcodes, |
|
| 352 | + * so that it can be replaced with the actual M-Mode notice |
|
| 353 | + * |
|
| 354 | + * @return string |
|
| 355 | + */ |
|
| 356 | + public function inject_EE_shortcode_placeholder() |
|
| 357 | + { |
|
| 358 | + return '[ESPRESSO_'; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * @deprecated |
|
| 364 | + * @since 4.8.41 |
|
| 365 | + * @return void |
|
| 366 | + */ |
|
| 367 | + public function _possibly_set_ee_request_var() |
|
| 368 | + { |
|
| 369 | + $this->query_modifier->setRequestVarsIfCpt(); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * @deprecated |
|
| 375 | + * @since 4.8.41 |
|
| 376 | + * @param $SQL |
|
| 377 | + * @return string |
|
| 378 | + */ |
|
| 379 | + public function posts_fields($SQL) |
|
| 380 | + { |
|
| 381 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 382 | + return $this->query_modifier->postsFields($SQL); |
|
| 383 | + } |
|
| 384 | + return $SQL; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * @deprecated |
|
| 390 | + * @since 4.8.41 |
|
| 391 | + * @param $SQL |
|
| 392 | + * @return string |
|
| 393 | + */ |
|
| 394 | + public function posts_join($SQL) |
|
| 395 | + { |
|
| 396 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 397 | + return $this->query_modifier->postsJoin($SQL); |
|
| 398 | + } |
|
| 399 | + return $SQL; |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * @deprecated |
|
| 405 | + * @since 4.8.41 |
|
| 406 | + * @param \WP_Post[] $posts |
|
| 407 | + * @return \WP_Post[] |
|
| 408 | + */ |
|
| 409 | + public function the_posts($posts) |
|
| 410 | + { |
|
| 411 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 412 | + $this->query_modifier->thePosts($posts); |
|
| 413 | + } |
|
| 414 | + return $posts; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + |
|
| 418 | + /** |
|
| 419 | + * @deprecated |
|
| 420 | + * @since 4.8.41 |
|
| 421 | + * @param $url |
|
| 422 | + * @param $ID |
|
| 423 | + * @return string |
|
| 424 | + */ |
|
| 425 | + public function get_edit_post_link($url, $ID) |
|
| 426 | + { |
|
| 427 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 428 | + return $this->query_modifier->getEditPostLink($url, $ID); |
|
| 429 | + } |
|
| 430 | + return ''; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * @deprecated |
|
| 436 | + * @since 4.8.41 |
|
| 437 | + * @param null $WP_Query |
|
| 438 | + */ |
|
| 439 | + protected function _do_template_filters($WP_Query = null) |
|
| 440 | + { |
|
| 441 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 442 | + $this->query_modifier->addTemplateFilters(); |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * @deprecated |
|
| 449 | + * @since 4.8.41 |
|
| 450 | + * @param string $current_template Existing default template path derived for this page call. |
|
| 451 | + * @return string the path to the full template file. |
|
| 452 | + */ |
|
| 453 | + public function single_cpt_template($current_template) |
|
| 454 | + { |
|
| 455 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 456 | + return $this->query_modifier->singleCptTemplate($current_template); |
|
| 457 | + } |
|
| 458 | + return $current_template; |
|
| 459 | + } |
|
| 460 | 460 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | CustomTaxonomyDefinitions $taxonomies = null |
| 73 | 73 | ) { |
| 74 | 74 | // check if class object is instantiated |
| 75 | - if (! self::$_instance instanceof EE_CPT_Strategy |
|
| 75 | + if ( ! self::$_instance instanceof EE_CPT_Strategy |
|
| 76 | 76 | && $custom_post_types instanceof CustomPostTypeDefinitions |
| 77 | 77 | && $taxonomies instanceof CustomTaxonomyDefinitions |
| 78 | 78 | ) { |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | $_CPT_endpoints = array(); |
| 127 | 127 | if (is_array($this->_CPTs)) { |
| 128 | 128 | foreach ($this->_CPTs as $CPT_type => $CPT) { |
| 129 | - $_CPT_endpoints [ $CPT['plural_slug'] ] = $CPT_type; |
|
| 129 | + $_CPT_endpoints [$CPT['plural_slug']] = $CPT_type; |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | return $_CPT_endpoints; |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | public function pre_get_posts($WP_Query) |
| 149 | 149 | { |
| 150 | 150 | // check that post-type is set |
| 151 | - if (! $WP_Query instanceof WP_Query) { |
|
| 151 | + if ( ! $WP_Query instanceof WP_Query) { |
|
| 152 | 152 | return; |
| 153 | 153 | } |
| 154 | 154 | // add our conditionals |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | $terms = EEM_Term::instance()->get_all_CPT_post_tags(); |
| 193 | 193 | foreach ($terms as $term) { |
| 194 | 194 | if ($term instanceof EE_Term) { |
| 195 | - $this->_CPT_terms[ $term->slug() ] = $term; |
|
| 195 | + $this->_CPT_terms[$term->slug()] = $term; |
|
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | 198 | } |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | // loop thru our taxonomies |
| 258 | 258 | foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) { |
| 259 | 259 | // check if one of our taxonomies is set as a query var |
| 260 | - if (isset($WP_Query->query[ $CPT_taxonomy ])) { |
|
| 260 | + if (isset($WP_Query->query[$CPT_taxonomy])) { |
|
| 261 | 261 | // but which CPT does that correspond to??? hmmm... guess we gotta go looping |
| 262 | 262 | foreach ($this->_CPTs as $post_type => $CPT) { |
| 263 | 263 | // verify our CPT has args, is public and has taxonomies set |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | break; |
| 281 | 281 | default: |
| 282 | 282 | do_action( |
| 283 | - 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type', |
|
| 283 | + 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_'.$post_type.'_post_type', |
|
| 284 | 284 | $WP_Query, |
| 285 | 285 | $this |
| 286 | 286 | ); |
@@ -305,11 +305,11 @@ discard block |
||
| 305 | 305 | // loop thru post_types as array |
| 306 | 306 | foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) { |
| 307 | 307 | // is current query for an EE CPT ? |
| 308 | - if (isset($this->_CPTs[ $post_type ])) { |
|
| 308 | + if (isset($this->_CPTs[$post_type])) { |
|
| 309 | 309 | // is EE on or off ? |
| 310 | 310 | if (EE_Maintenance_Mode::instance()->level()) { |
| 311 | 311 | // reroute CPT template view to maintenance_mode.template.php |
| 312 | - if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
| 312 | + if ( ! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
| 313 | 313 | add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999); |
| 314 | 314 | } |
| 315 | 315 | if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) { |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | 'EventEspresso\core\CPTs\CptQueryModifier', |
| 338 | 338 | array( |
| 339 | 339 | $post_type, |
| 340 | - $this->_CPTs[ $post_type ], |
|
| 340 | + $this->_CPTs[$post_type], |
|
| 341 | 341 | $WP_Query, |
| 342 | 342 | ) |
| 343 | 343 | ); |
@@ -14,263 +14,263 @@ |
||
| 14 | 14 | class EEM_Term extends EEM_Base |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - // private instance of the Attendee object |
|
| 18 | - protected static $_instance = null; |
|
| 17 | + // private instance of the Attendee object |
|
| 18 | + protected static $_instance = null; |
|
| 19 | 19 | |
| 20 | 20 | |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - *__construct |
|
| 24 | - * |
|
| 25 | - * @param string $timezone |
|
| 26 | - */ |
|
| 27 | - protected function __construct($timezone = null) |
|
| 28 | - { |
|
| 29 | - $this->singular_item = __('Term', 'event_espresso'); |
|
| 30 | - $this->plural_item = __('Terms', 'event_espresso'); |
|
| 31 | - $this->_tables = array( |
|
| 32 | - 'Term' => new EE_Primary_Table('terms', 'term_id'), |
|
| 33 | - ); |
|
| 34 | - $this->_fields = array( |
|
| 35 | - 'Term' => array( |
|
| 36 | - 'term_id' => new EE_Primary_Key_Int_Field('term_id', __('Term ID', 'event_espresso')), |
|
| 37 | - 'name' => new EE_Plain_Text_Field('name', __('Term Name', 'event_espresso'), false, ''), |
|
| 38 | - 'slug' => new EE_Slug_Field('slug', __('Term Slug', 'event_espresso'), false), |
|
| 39 | - 'term_group' => new EE_Integer_Field('term_group', __("Term Group", "event_espresso"), false, 0), |
|
| 40 | - ), |
|
| 41 | - ); |
|
| 42 | - $this->_model_relations = array( |
|
| 43 | - 'Term_Taxonomy' => new EE_Has_Many_Relation(), |
|
| 44 | - ); |
|
| 45 | - $this->_wp_core_model = true; |
|
| 46 | - $path_to_tax_model = 'Term_Taxonomy'; |
|
| 47 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 48 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
| 49 | - $path_to_tax_model |
|
| 50 | - ); |
|
| 51 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
| 52 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
| 53 | - $path_to_tax_model = $path_to_tax_model . '.'; |
|
| 54 | - // add cap restrictions for editing relating to the "ee_edit_*" |
|
| 55 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
| 56 | - array( |
|
| 57 | - $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
| 58 | - ) |
|
| 59 | - ); |
|
| 60 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
| 61 | - array( |
|
| 62 | - $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
| 63 | - ) |
|
| 64 | - ); |
|
| 65 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
| 66 | - array( |
|
| 67 | - $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
| 68 | - ) |
|
| 69 | - ); |
|
| 70 | - // add cap restrictions for deleting relating to the "ee_deleting_*" |
|
| 71 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
| 72 | - array( |
|
| 73 | - $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
| 74 | - ) |
|
| 75 | - ); |
|
| 76 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
| 77 | - array( |
|
| 78 | - $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
| 79 | - ) |
|
| 80 | - ); |
|
| 81 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
| 82 | - array( |
|
| 83 | - $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
| 84 | - ) |
|
| 85 | - ); |
|
| 86 | - parent::__construct($timezone); |
|
| 87 | - add_filter('FHEE__Read__create_model_query_params', array('EEM_Term', 'rest_api_query_params'), 10, 3); |
|
| 88 | - } |
|
| 22 | + /** |
|
| 23 | + *__construct |
|
| 24 | + * |
|
| 25 | + * @param string $timezone |
|
| 26 | + */ |
|
| 27 | + protected function __construct($timezone = null) |
|
| 28 | + { |
|
| 29 | + $this->singular_item = __('Term', 'event_espresso'); |
|
| 30 | + $this->plural_item = __('Terms', 'event_espresso'); |
|
| 31 | + $this->_tables = array( |
|
| 32 | + 'Term' => new EE_Primary_Table('terms', 'term_id'), |
|
| 33 | + ); |
|
| 34 | + $this->_fields = array( |
|
| 35 | + 'Term' => array( |
|
| 36 | + 'term_id' => new EE_Primary_Key_Int_Field('term_id', __('Term ID', 'event_espresso')), |
|
| 37 | + 'name' => new EE_Plain_Text_Field('name', __('Term Name', 'event_espresso'), false, ''), |
|
| 38 | + 'slug' => new EE_Slug_Field('slug', __('Term Slug', 'event_espresso'), false), |
|
| 39 | + 'term_group' => new EE_Integer_Field('term_group', __("Term Group", "event_espresso"), false, 0), |
|
| 40 | + ), |
|
| 41 | + ); |
|
| 42 | + $this->_model_relations = array( |
|
| 43 | + 'Term_Taxonomy' => new EE_Has_Many_Relation(), |
|
| 44 | + ); |
|
| 45 | + $this->_wp_core_model = true; |
|
| 46 | + $path_to_tax_model = 'Term_Taxonomy'; |
|
| 47 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 48 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
| 49 | + $path_to_tax_model |
|
| 50 | + ); |
|
| 51 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
| 52 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
| 53 | + $path_to_tax_model = $path_to_tax_model . '.'; |
|
| 54 | + // add cap restrictions for editing relating to the "ee_edit_*" |
|
| 55 | + $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
| 56 | + array( |
|
| 57 | + $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
| 58 | + ) |
|
| 59 | + ); |
|
| 60 | + $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
| 61 | + array( |
|
| 62 | + $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
| 63 | + ) |
|
| 64 | + ); |
|
| 65 | + $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
| 66 | + array( |
|
| 67 | + $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
| 68 | + ) |
|
| 69 | + ); |
|
| 70 | + // add cap restrictions for deleting relating to the "ee_deleting_*" |
|
| 71 | + $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
| 72 | + array( |
|
| 73 | + $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
| 74 | + ) |
|
| 75 | + ); |
|
| 76 | + $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
| 77 | + array( |
|
| 78 | + $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
| 79 | + ) |
|
| 80 | + ); |
|
| 81 | + $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
| 82 | + array( |
|
| 83 | + $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
| 84 | + ) |
|
| 85 | + ); |
|
| 86 | + parent::__construct($timezone); |
|
| 87 | + add_filter('FHEE__Read__create_model_query_params', array('EEM_Term', 'rest_api_query_params'), 10, 3); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | 90 | |
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * retrieves a list of all EE event categories |
|
| 94 | - * |
|
| 95 | - * @access public |
|
| 96 | - * @param bool $show_uncategorized |
|
| 97 | - * @return \EE_Base_Class[] |
|
| 98 | - */ |
|
| 99 | - public function get_all_ee_categories($show_uncategorized = false) |
|
| 100 | - { |
|
| 101 | - $where_params = array( |
|
| 102 | - 'Term_Taxonomy.taxonomy' => 'espresso_event_categories', |
|
| 103 | - 'NOT' => array('name' => __('Uncategorized', 'event_espresso')), |
|
| 104 | - ); |
|
| 105 | - if ($show_uncategorized) { |
|
| 106 | - unset($where_params['NOT']); |
|
| 107 | - } |
|
| 108 | - return EEM_Term::instance()->get_all( |
|
| 109 | - array( |
|
| 110 | - $where_params, |
|
| 111 | - 'order_by' => array('name' => 'ASC'), |
|
| 112 | - ) |
|
| 113 | - ); |
|
| 114 | - } |
|
| 92 | + /** |
|
| 93 | + * retrieves a list of all EE event categories |
|
| 94 | + * |
|
| 95 | + * @access public |
|
| 96 | + * @param bool $show_uncategorized |
|
| 97 | + * @return \EE_Base_Class[] |
|
| 98 | + */ |
|
| 99 | + public function get_all_ee_categories($show_uncategorized = false) |
|
| 100 | + { |
|
| 101 | + $where_params = array( |
|
| 102 | + 'Term_Taxonomy.taxonomy' => 'espresso_event_categories', |
|
| 103 | + 'NOT' => array('name' => __('Uncategorized', 'event_espresso')), |
|
| 104 | + ); |
|
| 105 | + if ($show_uncategorized) { |
|
| 106 | + unset($where_params['NOT']); |
|
| 107 | + } |
|
| 108 | + return EEM_Term::instance()->get_all( |
|
| 109 | + array( |
|
| 110 | + $where_params, |
|
| 111 | + 'order_by' => array('name' => 'ASC'), |
|
| 112 | + ) |
|
| 113 | + ); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | 116 | |
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * retrieves a list of all post_tags associated with an EE CPT |
|
| 120 | - * |
|
| 121 | - * @access public |
|
| 122 | - * @param string $post_type |
|
| 123 | - * @return array |
|
| 124 | - */ |
|
| 125 | - public function get_all_CPT_post_tags($post_type = '') |
|
| 126 | - { |
|
| 127 | - switch ($post_type) { |
|
| 128 | - case 'espresso_events': |
|
| 129 | - return $this->get_all_event_post_tags(); |
|
| 130 | - break; |
|
| 131 | - case 'espresso_venues': |
|
| 132 | - return $this->get_all_venue_post_tags(); |
|
| 133 | - break; |
|
| 134 | - default: |
|
| 135 | - $event_tags = $this->get_all_event_post_tags(); |
|
| 136 | - $venue_tags = $this->get_all_venue_post_tags(); |
|
| 137 | - return array_merge($event_tags, $venue_tags); |
|
| 138 | - } |
|
| 139 | - } |
|
| 118 | + /** |
|
| 119 | + * retrieves a list of all post_tags associated with an EE CPT |
|
| 120 | + * |
|
| 121 | + * @access public |
|
| 122 | + * @param string $post_type |
|
| 123 | + * @return array |
|
| 124 | + */ |
|
| 125 | + public function get_all_CPT_post_tags($post_type = '') |
|
| 126 | + { |
|
| 127 | + switch ($post_type) { |
|
| 128 | + case 'espresso_events': |
|
| 129 | + return $this->get_all_event_post_tags(); |
|
| 130 | + break; |
|
| 131 | + case 'espresso_venues': |
|
| 132 | + return $this->get_all_venue_post_tags(); |
|
| 133 | + break; |
|
| 134 | + default: |
|
| 135 | + $event_tags = $this->get_all_event_post_tags(); |
|
| 136 | + $venue_tags = $this->get_all_venue_post_tags(); |
|
| 137 | + return array_merge($event_tags, $venue_tags); |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * returns an EE_Term object for the given tag |
|
| 144 | - * if it has been utilized by any EE_Events or EE_Venues |
|
| 145 | - * |
|
| 146 | - * @param string $tag |
|
| 147 | - * @return EE_Term|null |
|
| 148 | - * @throws EE_Error |
|
| 149 | - * @throws InvalidArgumentException |
|
| 150 | - * @throws InvalidDataTypeException |
|
| 151 | - * @throws InvalidInterfaceException |
|
| 152 | - */ |
|
| 153 | - public function get_post_tag_for_event_or_venue($tag) |
|
| 154 | - { |
|
| 155 | - $post_tag_results = $this->get_all_wpdb_results( |
|
| 156 | - array( |
|
| 157 | - array( |
|
| 158 | - 'slug' => $tag, |
|
| 159 | - 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
| 160 | - 'OR' => array( |
|
| 161 | - 'Term_Taxonomy.Venue.post_type' => 'espresso_venues', |
|
| 162 | - 'Term_Taxonomy.Event.post_type' => 'espresso_events', |
|
| 163 | - ), |
|
| 164 | - ), |
|
| 165 | - 'default_where_conditions' => 'none', |
|
| 166 | - 'extra_selects' => array( |
|
| 167 | - 'event_post_type' => array('Term_Taxonomy___Event_CPT.post_type', '%s'), |
|
| 168 | - 'venue_post_type' => array('Term_Taxonomy___Venue_CPT.post_type', '%s') |
|
| 169 | - ), |
|
| 170 | - 'group_by' => array( |
|
| 171 | - 'event_post_type', |
|
| 172 | - 'venue_post_type', |
|
| 173 | - ), |
|
| 174 | - 'limit' => 2 |
|
| 175 | - ) |
|
| 176 | - ); |
|
| 142 | + /** |
|
| 143 | + * returns an EE_Term object for the given tag |
|
| 144 | + * if it has been utilized by any EE_Events or EE_Venues |
|
| 145 | + * |
|
| 146 | + * @param string $tag |
|
| 147 | + * @return EE_Term|null |
|
| 148 | + * @throws EE_Error |
|
| 149 | + * @throws InvalidArgumentException |
|
| 150 | + * @throws InvalidDataTypeException |
|
| 151 | + * @throws InvalidInterfaceException |
|
| 152 | + */ |
|
| 153 | + public function get_post_tag_for_event_or_venue($tag) |
|
| 154 | + { |
|
| 155 | + $post_tag_results = $this->get_all_wpdb_results( |
|
| 156 | + array( |
|
| 157 | + array( |
|
| 158 | + 'slug' => $tag, |
|
| 159 | + 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
| 160 | + 'OR' => array( |
|
| 161 | + 'Term_Taxonomy.Venue.post_type' => 'espresso_venues', |
|
| 162 | + 'Term_Taxonomy.Event.post_type' => 'espresso_events', |
|
| 163 | + ), |
|
| 164 | + ), |
|
| 165 | + 'default_where_conditions' => 'none', |
|
| 166 | + 'extra_selects' => array( |
|
| 167 | + 'event_post_type' => array('Term_Taxonomy___Event_CPT.post_type', '%s'), |
|
| 168 | + 'venue_post_type' => array('Term_Taxonomy___Venue_CPT.post_type', '%s') |
|
| 169 | + ), |
|
| 170 | + 'group_by' => array( |
|
| 171 | + 'event_post_type', |
|
| 172 | + 'venue_post_type', |
|
| 173 | + ), |
|
| 174 | + 'limit' => 2 |
|
| 175 | + ) |
|
| 176 | + ); |
|
| 177 | 177 | |
| 178 | - $post_types = array(); |
|
| 179 | - foreach ((array) $post_tag_results as $row) { |
|
| 180 | - if ($row['event_post_type'] === 'espresso_events') { |
|
| 181 | - $post_types[] = EEM_Event::instance()->post_type(); |
|
| 182 | - } elseif ($row['venue_post_type'] === 'espresso_venues') { |
|
| 183 | - $post_types[] = EEM_Venue::instance()->post_type(); |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - $post_tag_row = reset($post_tag_results); |
|
| 187 | - $post_tag = $this->instantiate_class_from_array_or_object($post_tag_row); |
|
| 188 | - if (! $post_tag instanceof EE_Term) { |
|
| 189 | - return null; |
|
| 190 | - } |
|
| 178 | + $post_types = array(); |
|
| 179 | + foreach ((array) $post_tag_results as $row) { |
|
| 180 | + if ($row['event_post_type'] === 'espresso_events') { |
|
| 181 | + $post_types[] = EEM_Event::instance()->post_type(); |
|
| 182 | + } elseif ($row['venue_post_type'] === 'espresso_venues') { |
|
| 183 | + $post_types[] = EEM_Venue::instance()->post_type(); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + $post_tag_row = reset($post_tag_results); |
|
| 187 | + $post_tag = $this->instantiate_class_from_array_or_object($post_tag_row); |
|
| 188 | + if (! $post_tag instanceof EE_Term) { |
|
| 189 | + return null; |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - if ($post_tag->post_type === null) { |
|
| 193 | - $post_tag->post_type = array(); |
|
| 194 | - } |
|
| 195 | - $post_tag->post_type = array_merge($post_tag->post_type, array_unique($post_types)); |
|
| 196 | - return $post_tag; |
|
| 197 | - } |
|
| 192 | + if ($post_tag->post_type === null) { |
|
| 193 | + $post_tag->post_type = array(); |
|
| 194 | + } |
|
| 195 | + $post_tag->post_type = array_merge($post_tag->post_type, array_unique($post_types)); |
|
| 196 | + return $post_tag; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | 199 | |
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * get_all_event_post_tags |
|
| 203 | - * |
|
| 204 | - * @return EE_Base_Class[] |
|
| 205 | - */ |
|
| 206 | - public function get_all_event_post_tags() |
|
| 207 | - { |
|
| 208 | - $post_tags = EEM_Term::instance()->get_all( |
|
| 209 | - array( |
|
| 210 | - array( |
|
| 211 | - 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
| 212 | - 'Term_Taxonomy.Event.post_type' => 'espresso_events', |
|
| 213 | - ), |
|
| 214 | - 'order_by' => array('name' => 'ASC'), |
|
| 215 | - 'force_join' => array('Term_Taxonomy.Event'), |
|
| 216 | - ) |
|
| 217 | - ); |
|
| 218 | - foreach ($post_tags as $key => $post_tag) { |
|
| 219 | - if (! isset($post_tags[ $key ]->post_type)) { |
|
| 220 | - $post_tags[ $key ]->post_type = array(); |
|
| 221 | - } |
|
| 222 | - $post_tags[ $key ]->post_type[] = 'espresso_events'; |
|
| 223 | - } |
|
| 224 | - return $post_tags; |
|
| 225 | - } |
|
| 201 | + /** |
|
| 202 | + * get_all_event_post_tags |
|
| 203 | + * |
|
| 204 | + * @return EE_Base_Class[] |
|
| 205 | + */ |
|
| 206 | + public function get_all_event_post_tags() |
|
| 207 | + { |
|
| 208 | + $post_tags = EEM_Term::instance()->get_all( |
|
| 209 | + array( |
|
| 210 | + array( |
|
| 211 | + 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
| 212 | + 'Term_Taxonomy.Event.post_type' => 'espresso_events', |
|
| 213 | + ), |
|
| 214 | + 'order_by' => array('name' => 'ASC'), |
|
| 215 | + 'force_join' => array('Term_Taxonomy.Event'), |
|
| 216 | + ) |
|
| 217 | + ); |
|
| 218 | + foreach ($post_tags as $key => $post_tag) { |
|
| 219 | + if (! isset($post_tags[ $key ]->post_type)) { |
|
| 220 | + $post_tags[ $key ]->post_type = array(); |
|
| 221 | + } |
|
| 222 | + $post_tags[ $key ]->post_type[] = 'espresso_events'; |
|
| 223 | + } |
|
| 224 | + return $post_tags; |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | 227 | |
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * get_all_venue_post_tags |
|
| 231 | - * |
|
| 232 | - * @return EE_Base_Class[] |
|
| 233 | - */ |
|
| 234 | - public function get_all_venue_post_tags() |
|
| 235 | - { |
|
| 236 | - $post_tags = EEM_Term::instance()->get_all( |
|
| 237 | - array( |
|
| 238 | - array( |
|
| 239 | - 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
| 240 | - 'Term_Taxonomy.Venue.post_type' => 'espresso_venues', |
|
| 241 | - ), |
|
| 242 | - 'order_by' => array('name' => 'ASC'), |
|
| 243 | - 'force_join' => array('Term_Taxonomy'), |
|
| 244 | - ) |
|
| 245 | - ); |
|
| 246 | - foreach ($post_tags as $key => $post_tag) { |
|
| 247 | - if (! isset($post_tags[ $key ]->post_type)) { |
|
| 248 | - $post_tags[ $key ]->post_type = array(); |
|
| 249 | - } |
|
| 250 | - $post_tags[ $key ]->post_type[] = 'espresso_venues'; |
|
| 251 | - } |
|
| 252 | - return $post_tags; |
|
| 253 | - } |
|
| 229 | + /** |
|
| 230 | + * get_all_venue_post_tags |
|
| 231 | + * |
|
| 232 | + * @return EE_Base_Class[] |
|
| 233 | + */ |
|
| 234 | + public function get_all_venue_post_tags() |
|
| 235 | + { |
|
| 236 | + $post_tags = EEM_Term::instance()->get_all( |
|
| 237 | + array( |
|
| 238 | + array( |
|
| 239 | + 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
| 240 | + 'Term_Taxonomy.Venue.post_type' => 'espresso_venues', |
|
| 241 | + ), |
|
| 242 | + 'order_by' => array('name' => 'ASC'), |
|
| 243 | + 'force_join' => array('Term_Taxonomy'), |
|
| 244 | + ) |
|
| 245 | + ); |
|
| 246 | + foreach ($post_tags as $key => $post_tag) { |
|
| 247 | + if (! isset($post_tags[ $key ]->post_type)) { |
|
| 248 | + $post_tags[ $key ]->post_type = array(); |
|
| 249 | + } |
|
| 250 | + $post_tags[ $key ]->post_type[] = 'espresso_venues'; |
|
| 251 | + } |
|
| 252 | + return $post_tags; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | 255 | |
| 256 | 256 | |
| 257 | - /** |
|
| 258 | - * Makes sure that during REST API queries, we only return terms |
|
| 259 | - * for term taxonomies which should be shown in the rest api |
|
| 260 | - * |
|
| 261 | - * @param array $model_query_params |
|
| 262 | - * @param array $querystring_query_params |
|
| 263 | - * @param EEM_Base $model |
|
| 264 | - * @return array |
|
| 265 | - */ |
|
| 266 | - public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
| 267 | - { |
|
| 268 | - if ($model === EEM_Term::instance()) { |
|
| 269 | - $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
| 270 | - if (! empty($taxonomies)) { |
|
| 271 | - $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - return $model_query_params; |
|
| 275 | - } |
|
| 257 | + /** |
|
| 258 | + * Makes sure that during REST API queries, we only return terms |
|
| 259 | + * for term taxonomies which should be shown in the rest api |
|
| 260 | + * |
|
| 261 | + * @param array $model_query_params |
|
| 262 | + * @param array $querystring_query_params |
|
| 263 | + * @param EEM_Base $model |
|
| 264 | + * @return array |
|
| 265 | + */ |
|
| 266 | + public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
| 267 | + { |
|
| 268 | + if ($model === EEM_Term::instance()) { |
|
| 269 | + $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
| 270 | + if (! empty($taxonomies)) { |
|
| 271 | + $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + return $model_query_params; |
|
| 275 | + } |
|
| 276 | 276 | } |
@@ -44,43 +44,43 @@ discard block |
||
| 44 | 44 | ); |
| 45 | 45 | $this->_wp_core_model = true; |
| 46 | 46 | $path_to_tax_model = 'Term_Taxonomy'; |
| 47 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 48 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
| 47 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
| 48 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
| 49 | 49 | $path_to_tax_model |
| 50 | 50 | ); |
| 51 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
| 52 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
| 53 | - $path_to_tax_model = $path_to_tax_model . '.'; |
|
| 51 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = false; |
|
| 52 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = false; |
|
| 53 | + $path_to_tax_model = $path_to_tax_model.'.'; |
|
| 54 | 54 | // add cap restrictions for editing relating to the "ee_edit_*" |
| 55 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
| 55 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
| 56 | 56 | array( |
| 57 | - $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
| 57 | + $path_to_tax_model.'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
| 58 | 58 | ) |
| 59 | 59 | ); |
| 60 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
| 60 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
| 61 | 61 | array( |
| 62 | - $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
| 62 | + $path_to_tax_model.'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
| 63 | 63 | ) |
| 64 | 64 | ); |
| 65 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
| 65 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
| 66 | 66 | array( |
| 67 | - $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
| 67 | + $path_to_tax_model.'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
| 68 | 68 | ) |
| 69 | 69 | ); |
| 70 | 70 | // add cap restrictions for deleting relating to the "ee_deleting_*" |
| 71 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
| 71 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
| 72 | 72 | array( |
| 73 | - $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
| 73 | + $path_to_tax_model.'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
| 74 | 74 | ) |
| 75 | 75 | ); |
| 76 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
| 76 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
| 77 | 77 | array( |
| 78 | - $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
| 78 | + $path_to_tax_model.'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
| 79 | 79 | ) |
| 80 | 80 | ); |
| 81 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
| 81 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
| 82 | 82 | array( |
| 83 | - $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
| 83 | + $path_to_tax_model.'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
| 84 | 84 | ) |
| 85 | 85 | ); |
| 86 | 86 | parent::__construct($timezone); |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | } |
| 186 | 186 | $post_tag_row = reset($post_tag_results); |
| 187 | 187 | $post_tag = $this->instantiate_class_from_array_or_object($post_tag_row); |
| 188 | - if (! $post_tag instanceof EE_Term) { |
|
| 188 | + if ( ! $post_tag instanceof EE_Term) { |
|
| 189 | 189 | return null; |
| 190 | 190 | } |
| 191 | 191 | |
@@ -216,10 +216,10 @@ discard block |
||
| 216 | 216 | ) |
| 217 | 217 | ); |
| 218 | 218 | foreach ($post_tags as $key => $post_tag) { |
| 219 | - if (! isset($post_tags[ $key ]->post_type)) { |
|
| 220 | - $post_tags[ $key ]->post_type = array(); |
|
| 219 | + if ( ! isset($post_tags[$key]->post_type)) { |
|
| 220 | + $post_tags[$key]->post_type = array(); |
|
| 221 | 221 | } |
| 222 | - $post_tags[ $key ]->post_type[] = 'espresso_events'; |
|
| 222 | + $post_tags[$key]->post_type[] = 'espresso_events'; |
|
| 223 | 223 | } |
| 224 | 224 | return $post_tags; |
| 225 | 225 | } |
@@ -244,10 +244,10 @@ discard block |
||
| 244 | 244 | ) |
| 245 | 245 | ); |
| 246 | 246 | foreach ($post_tags as $key => $post_tag) { |
| 247 | - if (! isset($post_tags[ $key ]->post_type)) { |
|
| 248 | - $post_tags[ $key ]->post_type = array(); |
|
| 247 | + if ( ! isset($post_tags[$key]->post_type)) { |
|
| 248 | + $post_tags[$key]->post_type = array(); |
|
| 249 | 249 | } |
| 250 | - $post_tags[ $key ]->post_type[] = 'espresso_venues'; |
|
| 250 | + $post_tags[$key]->post_type[] = 'espresso_venues'; |
|
| 251 | 251 | } |
| 252 | 252 | return $post_tags; |
| 253 | 253 | } |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | { |
| 268 | 268 | if ($model === EEM_Term::instance()) { |
| 269 | 269 | $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
| 270 | - if (! empty($taxonomies)) { |
|
| 270 | + if ( ! empty($taxonomies)) { |
|
| 271 | 271 | $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
| 272 | 272 | } |
| 273 | 273 | } |
@@ -12,274 +12,274 @@ |
||
| 12 | 12 | { |
| 13 | 13 | |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * generates JSON-based linked data for an event |
|
| 17 | - * |
|
| 18 | - * @param EE_Event $event |
|
| 19 | - * @throws EE_Error |
|
| 20 | - */ |
|
| 21 | - public static function add_json_linked_data_for_event(EE_Event $event) |
|
| 22 | - { |
|
| 23 | - // Check we have a valid datetime for the event |
|
| 24 | - if (! $event->primary_datetime() instanceof EE_Datetime) { |
|
| 25 | - return; |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - $template_args = array( |
|
| 29 | - 'event_permalink' => '', |
|
| 30 | - 'event_name' => '', |
|
| 31 | - 'event_description' => '', |
|
| 32 | - 'event_start' => '', |
|
| 33 | - 'event_end' => '', |
|
| 34 | - 'currency' => '', |
|
| 35 | - 'event_tickets' => array(), |
|
| 36 | - 'venue_name' => '', |
|
| 37 | - 'venue_url' => '', |
|
| 38 | - 'venue_locality' => '', |
|
| 39 | - 'venue_region' => '', |
|
| 40 | - 'event_image' => '', |
|
| 41 | - ); |
|
| 42 | - $template_args['event_permalink'] = $event->get_permalink(); |
|
| 43 | - $template_args['event_name'] = $event->name(); |
|
| 44 | - $template_args['event_description'] = wp_strip_all_tags($event->short_description(200)); |
|
| 45 | - // clone datetime so that date formats don't override those for the original datetime |
|
| 46 | - $primary_datetime = clone $event->primary_datetime(); |
|
| 47 | - $template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM); |
|
| 48 | - $template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM); |
|
| 49 | - unset($primary_datetime); |
|
| 50 | - $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
| 51 | - foreach ($event->tickets() as $original_ticket) { |
|
| 52 | - // clone tickets so that date formats don't override those for the original ticket |
|
| 53 | - $ticket= clone $original_ticket; |
|
| 54 | - $ID = $ticket->ID(); |
|
| 55 | - $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
| 56 | - $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
| 57 | - $template_args['event_tickets'][ $ID ]['price'] = number_format( |
|
| 58 | - $ticket->price(), |
|
| 59 | - EE_Registry::instance()->CFG->currency->dec_plc, |
|
| 60 | - EE_Registry::instance()->CFG->currency->dec_mrk, |
|
| 61 | - EE_Registry::instance()->CFG->currency->thsnds |
|
| 62 | - ); |
|
| 63 | - switch ($ticket->ticket_status()) { |
|
| 64 | - case 'TKO': |
|
| 65 | - $availability = 'InStock'; |
|
| 66 | - break; |
|
| 67 | - case 'TKS': |
|
| 68 | - $availability = 'SoldOut'; |
|
| 69 | - break; |
|
| 70 | - default: |
|
| 71 | - $availability = null; |
|
| 72 | - break; |
|
| 73 | - } |
|
| 74 | - $template_args['event_tickets'][ $ID ]['availability'] = $availability; |
|
| 75 | - unset($ticket); |
|
| 76 | - } |
|
| 77 | - $VNU_ID = espresso_venue_id(); |
|
| 78 | - if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
| 79 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 80 | - $template_args['venue_name'] = get_the_title($VNU_ID); |
|
| 81 | - $template_args['venue_url'] = get_permalink($VNU_ID); |
|
| 82 | - $template_args['venue_locality'] = $venue->city(); |
|
| 83 | - $template_args['venue_region'] = $venue->state_name(); |
|
| 84 | - } |
|
| 85 | - $template_args['event_image'] = $event->feature_image_url(); |
|
| 86 | - $template_args = apply_filters( |
|
| 87 | - 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
| 88 | - $template_args, |
|
| 89 | - $event, |
|
| 90 | - $VNU_ID |
|
| 91 | - ); |
|
| 92 | - extract($template_args, EXTR_OVERWRITE); |
|
| 93 | - include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * location |
|
| 99 | - * The location of the event, organization or action. |
|
| 100 | - * Should include the Venue name AND schema formatted address info |
|
| 101 | - * |
|
| 102 | - * @access public |
|
| 103 | - * @param string $location |
|
| 104 | - * @return string |
|
| 105 | - */ |
|
| 106 | - public static function location($location = null) |
|
| 107 | - { |
|
| 108 | - return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
|
| 109 | - . $location |
|
| 110 | - . '</div>' : ''; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * name |
|
| 117 | - * The name of the Event or Venue. |
|
| 118 | - * |
|
| 119 | - * @access public |
|
| 120 | - * @param string $name |
|
| 121 | - * @return string |
|
| 122 | - */ |
|
| 123 | - public static function name($name = null) |
|
| 124 | - { |
|
| 125 | - return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * streetAddress |
|
| 132 | - * The street address. For example, 1600 Amphitheatre Pkwy. |
|
| 133 | - * |
|
| 134 | - * @access public |
|
| 135 | - * @param EEI_Address $obj_with_address |
|
| 136 | - * @return string |
|
| 137 | - */ |
|
| 138 | - public static function streetAddress(EEI_Address $obj_with_address = null) |
|
| 139 | - { |
|
| 140 | - return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
|
| 141 | - ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * postOfficeBoxNumber |
|
| 148 | - * The post office box number for PO box addresses. |
|
| 149 | - * |
|
| 150 | - * @access public |
|
| 151 | - * @param EEI_Address $obj_with_address |
|
| 152 | - * @return string |
|
| 153 | - */ |
|
| 154 | - public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null) |
|
| 155 | - { |
|
| 156 | - // regex check for some form of PO Box or P.O. Box, etc, etc, etc |
|
| 157 | - if (preg_match( |
|
| 158 | - "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
|
| 159 | - $obj_with_address->address2() |
|
| 160 | - ) ) { |
|
| 161 | - return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
|
| 162 | - ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
| 163 | - } else { |
|
| 164 | - return $obj_with_address->address2(); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * addressLocality |
|
| 172 | - * The locality (city, town, etc). For example, Mountain View. |
|
| 173 | - * |
|
| 174 | - * @access public |
|
| 175 | - * @param EEI_Address $obj_with_address |
|
| 176 | - * @return string |
|
| 177 | - */ |
|
| 178 | - public static function addressLocality(EEI_Address $obj_with_address = null) |
|
| 179 | - { |
|
| 180 | - return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
|
| 181 | - ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * addressRegion |
|
| 188 | - * The region (state, province, etc). For example, CA. |
|
| 189 | - * |
|
| 190 | - * @access public |
|
| 191 | - * @param EEI_Address $obj_with_address |
|
| 192 | - * @return string |
|
| 193 | - */ |
|
| 194 | - public static function addressRegion(EEI_Address $obj_with_address = null) |
|
| 195 | - { |
|
| 196 | - $state = $obj_with_address->state_name(); |
|
| 197 | - if (! empty($state)) { |
|
| 198 | - return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
| 199 | - } else { |
|
| 200 | - return ''; |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * addressCountry |
|
| 208 | - * The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code. |
|
| 209 | - * |
|
| 210 | - * @access public |
|
| 211 | - * @param EEI_Address $obj_with_address |
|
| 212 | - * @return string |
|
| 213 | - */ |
|
| 214 | - public static function addressCountry(EEI_Address $obj_with_address = null) |
|
| 215 | - { |
|
| 216 | - $country = $obj_with_address->country_name(); |
|
| 217 | - if (! empty($country)) { |
|
| 218 | - return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
| 219 | - } else { |
|
| 220 | - return ''; |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * postalCode |
|
| 228 | - * The postal code. For example, 94043. |
|
| 229 | - * |
|
| 230 | - * @access public |
|
| 231 | - * @param EEI_Address $obj_with_address |
|
| 232 | - * @return string |
|
| 233 | - */ |
|
| 234 | - public static function postalCode(EEI_Address $obj_with_address = null) |
|
| 235 | - { |
|
| 236 | - return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">' |
|
| 237 | - . $obj_with_address->zip() |
|
| 238 | - . '</span>' : ''; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * telephone |
|
| 245 | - * The telephone number. |
|
| 246 | - * |
|
| 247 | - * @access public |
|
| 248 | - * @param string $phone_nmbr |
|
| 249 | - * @return string |
|
| 250 | - */ |
|
| 251 | - public static function telephone($phone_nmbr = null) |
|
| 252 | - { |
|
| 253 | - return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
| 254 | - : ''; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * URL |
|
| 261 | - * URL of the item as a clickable link |
|
| 262 | - * |
|
| 263 | - * @access public |
|
| 264 | - * @param string $url - the URL that the link will resolve to |
|
| 265 | - * @param string $text - the text that will be used for the visible link |
|
| 266 | - * @param array $attributes - array of additional link attributes in attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' ) |
|
| 267 | - * @return string (link) |
|
| 268 | - */ |
|
| 269 | - public static function url($url = null, $text = null, $attributes = array()) |
|
| 270 | - { |
|
| 271 | - // Check the URL includes a scheme |
|
| 272 | - $parsed_url = parse_url($url); |
|
| 273 | - if (empty($parsed_url['scheme'])) { |
|
| 274 | - $url = 'http://' . ltrim($url, '/'); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - $atts = ''; |
|
| 278 | - foreach ($attributes as $attribute => $value) { |
|
| 279 | - $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
| 280 | - } |
|
| 281 | - $text = $text !== null && $text !== '' ? $text : $url; |
|
| 282 | - return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>' |
|
| 283 | - : ''; |
|
| 284 | - } |
|
| 15 | + /** |
|
| 16 | + * generates JSON-based linked data for an event |
|
| 17 | + * |
|
| 18 | + * @param EE_Event $event |
|
| 19 | + * @throws EE_Error |
|
| 20 | + */ |
|
| 21 | + public static function add_json_linked_data_for_event(EE_Event $event) |
|
| 22 | + { |
|
| 23 | + // Check we have a valid datetime for the event |
|
| 24 | + if (! $event->primary_datetime() instanceof EE_Datetime) { |
|
| 25 | + return; |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + $template_args = array( |
|
| 29 | + 'event_permalink' => '', |
|
| 30 | + 'event_name' => '', |
|
| 31 | + 'event_description' => '', |
|
| 32 | + 'event_start' => '', |
|
| 33 | + 'event_end' => '', |
|
| 34 | + 'currency' => '', |
|
| 35 | + 'event_tickets' => array(), |
|
| 36 | + 'venue_name' => '', |
|
| 37 | + 'venue_url' => '', |
|
| 38 | + 'venue_locality' => '', |
|
| 39 | + 'venue_region' => '', |
|
| 40 | + 'event_image' => '', |
|
| 41 | + ); |
|
| 42 | + $template_args['event_permalink'] = $event->get_permalink(); |
|
| 43 | + $template_args['event_name'] = $event->name(); |
|
| 44 | + $template_args['event_description'] = wp_strip_all_tags($event->short_description(200)); |
|
| 45 | + // clone datetime so that date formats don't override those for the original datetime |
|
| 46 | + $primary_datetime = clone $event->primary_datetime(); |
|
| 47 | + $template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM); |
|
| 48 | + $template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM); |
|
| 49 | + unset($primary_datetime); |
|
| 50 | + $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
| 51 | + foreach ($event->tickets() as $original_ticket) { |
|
| 52 | + // clone tickets so that date formats don't override those for the original ticket |
|
| 53 | + $ticket= clone $original_ticket; |
|
| 54 | + $ID = $ticket->ID(); |
|
| 55 | + $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
| 56 | + $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
| 57 | + $template_args['event_tickets'][ $ID ]['price'] = number_format( |
|
| 58 | + $ticket->price(), |
|
| 59 | + EE_Registry::instance()->CFG->currency->dec_plc, |
|
| 60 | + EE_Registry::instance()->CFG->currency->dec_mrk, |
|
| 61 | + EE_Registry::instance()->CFG->currency->thsnds |
|
| 62 | + ); |
|
| 63 | + switch ($ticket->ticket_status()) { |
|
| 64 | + case 'TKO': |
|
| 65 | + $availability = 'InStock'; |
|
| 66 | + break; |
|
| 67 | + case 'TKS': |
|
| 68 | + $availability = 'SoldOut'; |
|
| 69 | + break; |
|
| 70 | + default: |
|
| 71 | + $availability = null; |
|
| 72 | + break; |
|
| 73 | + } |
|
| 74 | + $template_args['event_tickets'][ $ID ]['availability'] = $availability; |
|
| 75 | + unset($ticket); |
|
| 76 | + } |
|
| 77 | + $VNU_ID = espresso_venue_id(); |
|
| 78 | + if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
| 79 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 80 | + $template_args['venue_name'] = get_the_title($VNU_ID); |
|
| 81 | + $template_args['venue_url'] = get_permalink($VNU_ID); |
|
| 82 | + $template_args['venue_locality'] = $venue->city(); |
|
| 83 | + $template_args['venue_region'] = $venue->state_name(); |
|
| 84 | + } |
|
| 85 | + $template_args['event_image'] = $event->feature_image_url(); |
|
| 86 | + $template_args = apply_filters( |
|
| 87 | + 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
| 88 | + $template_args, |
|
| 89 | + $event, |
|
| 90 | + $VNU_ID |
|
| 91 | + ); |
|
| 92 | + extract($template_args, EXTR_OVERWRITE); |
|
| 93 | + include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * location |
|
| 99 | + * The location of the event, organization or action. |
|
| 100 | + * Should include the Venue name AND schema formatted address info |
|
| 101 | + * |
|
| 102 | + * @access public |
|
| 103 | + * @param string $location |
|
| 104 | + * @return string |
|
| 105 | + */ |
|
| 106 | + public static function location($location = null) |
|
| 107 | + { |
|
| 108 | + return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
|
| 109 | + . $location |
|
| 110 | + . '</div>' : ''; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * name |
|
| 117 | + * The name of the Event or Venue. |
|
| 118 | + * |
|
| 119 | + * @access public |
|
| 120 | + * @param string $name |
|
| 121 | + * @return string |
|
| 122 | + */ |
|
| 123 | + public static function name($name = null) |
|
| 124 | + { |
|
| 125 | + return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * streetAddress |
|
| 132 | + * The street address. For example, 1600 Amphitheatre Pkwy. |
|
| 133 | + * |
|
| 134 | + * @access public |
|
| 135 | + * @param EEI_Address $obj_with_address |
|
| 136 | + * @return string |
|
| 137 | + */ |
|
| 138 | + public static function streetAddress(EEI_Address $obj_with_address = null) |
|
| 139 | + { |
|
| 140 | + return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
|
| 141 | + ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * postOfficeBoxNumber |
|
| 148 | + * The post office box number for PO box addresses. |
|
| 149 | + * |
|
| 150 | + * @access public |
|
| 151 | + * @param EEI_Address $obj_with_address |
|
| 152 | + * @return string |
|
| 153 | + */ |
|
| 154 | + public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null) |
|
| 155 | + { |
|
| 156 | + // regex check for some form of PO Box or P.O. Box, etc, etc, etc |
|
| 157 | + if (preg_match( |
|
| 158 | + "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
|
| 159 | + $obj_with_address->address2() |
|
| 160 | + ) ) { |
|
| 161 | + return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
|
| 162 | + ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
| 163 | + } else { |
|
| 164 | + return $obj_with_address->address2(); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * addressLocality |
|
| 172 | + * The locality (city, town, etc). For example, Mountain View. |
|
| 173 | + * |
|
| 174 | + * @access public |
|
| 175 | + * @param EEI_Address $obj_with_address |
|
| 176 | + * @return string |
|
| 177 | + */ |
|
| 178 | + public static function addressLocality(EEI_Address $obj_with_address = null) |
|
| 179 | + { |
|
| 180 | + return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
|
| 181 | + ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * addressRegion |
|
| 188 | + * The region (state, province, etc). For example, CA. |
|
| 189 | + * |
|
| 190 | + * @access public |
|
| 191 | + * @param EEI_Address $obj_with_address |
|
| 192 | + * @return string |
|
| 193 | + */ |
|
| 194 | + public static function addressRegion(EEI_Address $obj_with_address = null) |
|
| 195 | + { |
|
| 196 | + $state = $obj_with_address->state_name(); |
|
| 197 | + if (! empty($state)) { |
|
| 198 | + return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
| 199 | + } else { |
|
| 200 | + return ''; |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * addressCountry |
|
| 208 | + * The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code. |
|
| 209 | + * |
|
| 210 | + * @access public |
|
| 211 | + * @param EEI_Address $obj_with_address |
|
| 212 | + * @return string |
|
| 213 | + */ |
|
| 214 | + public static function addressCountry(EEI_Address $obj_with_address = null) |
|
| 215 | + { |
|
| 216 | + $country = $obj_with_address->country_name(); |
|
| 217 | + if (! empty($country)) { |
|
| 218 | + return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
| 219 | + } else { |
|
| 220 | + return ''; |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * postalCode |
|
| 228 | + * The postal code. For example, 94043. |
|
| 229 | + * |
|
| 230 | + * @access public |
|
| 231 | + * @param EEI_Address $obj_with_address |
|
| 232 | + * @return string |
|
| 233 | + */ |
|
| 234 | + public static function postalCode(EEI_Address $obj_with_address = null) |
|
| 235 | + { |
|
| 236 | + return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">' |
|
| 237 | + . $obj_with_address->zip() |
|
| 238 | + . '</span>' : ''; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * telephone |
|
| 245 | + * The telephone number. |
|
| 246 | + * |
|
| 247 | + * @access public |
|
| 248 | + * @param string $phone_nmbr |
|
| 249 | + * @return string |
|
| 250 | + */ |
|
| 251 | + public static function telephone($phone_nmbr = null) |
|
| 252 | + { |
|
| 253 | + return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
| 254 | + : ''; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * URL |
|
| 261 | + * URL of the item as a clickable link |
|
| 262 | + * |
|
| 263 | + * @access public |
|
| 264 | + * @param string $url - the URL that the link will resolve to |
|
| 265 | + * @param string $text - the text that will be used for the visible link |
|
| 266 | + * @param array $attributes - array of additional link attributes in attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' ) |
|
| 267 | + * @return string (link) |
|
| 268 | + */ |
|
| 269 | + public static function url($url = null, $text = null, $attributes = array()) |
|
| 270 | + { |
|
| 271 | + // Check the URL includes a scheme |
|
| 272 | + $parsed_url = parse_url($url); |
|
| 273 | + if (empty($parsed_url['scheme'])) { |
|
| 274 | + $url = 'http://' . ltrim($url, '/'); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + $atts = ''; |
|
| 278 | + foreach ($attributes as $attribute => $value) { |
|
| 279 | + $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
| 280 | + } |
|
| 281 | + $text = $text !== null && $text !== '' ? $text : $url; |
|
| 282 | + return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>' |
|
| 283 | + : ''; |
|
| 284 | + } |
|
| 285 | 285 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | public static function add_json_linked_data_for_event(EE_Event $event) |
| 22 | 22 | { |
| 23 | 23 | // Check we have a valid datetime for the event |
| 24 | - if (! $event->primary_datetime() instanceof EE_Datetime) { |
|
| 24 | + if ( ! $event->primary_datetime() instanceof EE_Datetime) { |
|
| 25 | 25 | return; |
| 26 | 26 | } |
| 27 | 27 | |
@@ -50,11 +50,11 @@ discard block |
||
| 50 | 50 | $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
| 51 | 51 | foreach ($event->tickets() as $original_ticket) { |
| 52 | 52 | // clone tickets so that date formats don't override those for the original ticket |
| 53 | - $ticket= clone $original_ticket; |
|
| 53 | + $ticket = clone $original_ticket; |
|
| 54 | 54 | $ID = $ticket->ID(); |
| 55 | - $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
| 56 | - $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
| 57 | - $template_args['event_tickets'][ $ID ]['price'] = number_format( |
|
| 55 | + $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
| 56 | + $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
| 57 | + $template_args['event_tickets'][$ID]['price'] = number_format( |
|
| 58 | 58 | $ticket->price(), |
| 59 | 59 | EE_Registry::instance()->CFG->currency->dec_plc, |
| 60 | 60 | EE_Registry::instance()->CFG->currency->dec_mrk, |
@@ -71,11 +71,11 @@ discard block |
||
| 71 | 71 | $availability = null; |
| 72 | 72 | break; |
| 73 | 73 | } |
| 74 | - $template_args['event_tickets'][ $ID ]['availability'] = $availability; |
|
| 74 | + $template_args['event_tickets'][$ID]['availability'] = $availability; |
|
| 75 | 75 | unset($ticket); |
| 76 | 76 | } |
| 77 | 77 | $VNU_ID = espresso_venue_id(); |
| 78 | - if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
| 78 | + if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
| 79 | 79 | $venue = EEH_Venue_View::get_venue($VNU_ID); |
| 80 | 80 | $template_args['venue_name'] = get_the_title($VNU_ID); |
| 81 | 81 | $template_args['venue_url'] = get_permalink($VNU_ID); |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $VNU_ID |
| 91 | 91 | ); |
| 92 | 92 | extract($template_args, EXTR_OVERWRITE); |
| 93 | - include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
| 93 | + include EE_TEMPLATES.'json_linked_data_for_event.template.php'; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | public static function name($name = null) |
| 124 | 124 | { |
| 125 | - return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
| 125 | + return ! empty($name) ? '<span itemprop="name">'.$name.'</span>' : ''; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | public static function streetAddress(EEI_Address $obj_with_address = null) |
| 139 | 139 | { |
| 140 | 140 | return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
| 141 | - ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
| 141 | + ? '<span itemprop="streetAddress">'.$obj_with_address->address().'</span>' : ''; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | |
@@ -157,9 +157,9 @@ discard block |
||
| 157 | 157 | if (preg_match( |
| 158 | 158 | "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
| 159 | 159 | $obj_with_address->address2() |
| 160 | - ) ) { |
|
| 160 | + )) { |
|
| 161 | 161 | return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
| 162 | - ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
| 162 | + ? '<span itemprop="postOfficeBoxNumber">'.$obj_with_address->address2().'</span>' : ''; |
|
| 163 | 163 | } else { |
| 164 | 164 | return $obj_with_address->address2(); |
| 165 | 165 | } |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | public static function addressLocality(EEI_Address $obj_with_address = null) |
| 179 | 179 | { |
| 180 | 180 | return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
| 181 | - ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
| 181 | + ? '<span itemprop="addressLocality">'.$obj_with_address->city().'</span>' : ''; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | |
@@ -194,8 +194,8 @@ discard block |
||
| 194 | 194 | public static function addressRegion(EEI_Address $obj_with_address = null) |
| 195 | 195 | { |
| 196 | 196 | $state = $obj_with_address->state_name(); |
| 197 | - if (! empty($state)) { |
|
| 198 | - return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
| 197 | + if ( ! empty($state)) { |
|
| 198 | + return '<span itemprop="addressRegion">'.$state.'</span>'; |
|
| 199 | 199 | } else { |
| 200 | 200 | return ''; |
| 201 | 201 | } |
@@ -214,8 +214,8 @@ discard block |
||
| 214 | 214 | public static function addressCountry(EEI_Address $obj_with_address = null) |
| 215 | 215 | { |
| 216 | 216 | $country = $obj_with_address->country_name(); |
| 217 | - if (! empty($country)) { |
|
| 218 | - return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
| 217 | + if ( ! empty($country)) { |
|
| 218 | + return '<span itemprop="addressCountry">'.$country.'</span>'; |
|
| 219 | 219 | } else { |
| 220 | 220 | return ''; |
| 221 | 221 | } |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | */ |
| 251 | 251 | public static function telephone($phone_nmbr = null) |
| 252 | 252 | { |
| 253 | - return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
| 253 | + return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">'.$phone_nmbr.'</span>' |
|
| 254 | 254 | : ''; |
| 255 | 255 | } |
| 256 | 256 | |
@@ -271,15 +271,15 @@ discard block |
||
| 271 | 271 | // Check the URL includes a scheme |
| 272 | 272 | $parsed_url = parse_url($url); |
| 273 | 273 | if (empty($parsed_url['scheme'])) { |
| 274 | - $url = 'http://' . ltrim($url, '/'); |
|
| 274 | + $url = 'http://'.ltrim($url, '/'); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | $atts = ''; |
| 278 | 278 | foreach ($attributes as $attribute => $value) { |
| 279 | - $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
| 279 | + $atts .= ' '.$attribute.'="'.$value.'"'; |
|
| 280 | 280 | } |
| 281 | 281 | $text = $text !== null && $text !== '' ? $text : $url; |
| 282 | - return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>' |
|
| 282 | + return $url !== null && $url !== '' ? '<a itemprop="url" href="'.$url.'"'.$atts.'>'.$text.'</a>' |
|
| 283 | 283 | : ''; |
| 284 | 284 | } |
| 285 | 285 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | "url": "<?php echo $event_permalink; ?>", |
| 25 | 25 | "offers": [ |
| 26 | 26 | <?php |
| 27 | - foreach ($event_tickets as $ticket) {?> |
|
| 27 | + foreach ($event_tickets as $ticket) {?> |
|
| 28 | 28 | { |
| 29 | 29 | "@type": "Offer", |
| 30 | 30 | "url": "<?php echo $event_permalink; ?>", |
@@ -33,17 +33,17 @@ discard block |
||
| 33 | 33 | "price": "<?php echo $ticket['price']; ?>", |
| 34 | 34 | "priceCurrency": "<?php echo $currency; ?>" |
| 35 | 35 | <?php if (isset($ticket['availability'])) { |
| 36 | - ?>,"availability": "http://schema.org/<?php echo $ticket['availability']; ?>" |
|
| 36 | + ?>,"availability": "http://schema.org/<?php echo $ticket['availability']; ?>" |
|
| 37 | 37 | <?php } ?> |
| 38 | 38 | }<?php |
| 39 | - if (is_array($event_tickets) && end($event_tickets) !== $ticket) { |
|
| 40 | - echo ','; |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - ?> |
|
| 39 | + if (is_array($event_tickets) && end($event_tickets) !== $ticket) { |
|
| 40 | + echo ','; |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + ?> |
|
| 44 | 44 | ]<?php |
| 45 | - if ($venue_name) { |
|
| 46 | - ?>, |
|
| 45 | + if ($venue_name) { |
|
| 46 | + ?>, |
|
| 47 | 47 | "location": { |
| 48 | 48 | "@type": "Place", |
| 49 | 49 | "name": <?php echo wp_json_encode($venue_name); ?>, |
@@ -55,13 +55,13 @@ discard block |
||
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | <?php |
| 58 | - } ?> |
|
| 58 | + } ?> |
|
| 59 | 59 | <?php |
| 60 | - if ($event_image) { |
|
| 61 | - ?>, |
|
| 60 | + if ($event_image) { |
|
| 61 | + ?>, |
|
| 62 | 62 | "image": "<?php echo $event_image; ?>" |
| 63 | 63 | <?php |
| 64 | - } ?> |
|
| 64 | + } ?> |
|
| 65 | 65 | <?php do_action('AHEE__json_linked_data_for_event__template'); ?> |
| 66 | 66 | } |
| 67 | 67 | |
@@ -38,103 +38,103 @@ |
||
| 38 | 38 | * @since 4.0 |
| 39 | 39 | */ |
| 40 | 40 | if (function_exists('espresso_version')) { |
| 41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | - /** |
|
| 43 | - * espresso_duplicate_plugin_error |
|
| 44 | - * displays if more than one version of EE is activated at the same time |
|
| 45 | - */ |
|
| 46 | - function espresso_duplicate_plugin_error() |
|
| 47 | - { |
|
| 48 | - ?> |
|
| 41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | + /** |
|
| 43 | + * espresso_duplicate_plugin_error |
|
| 44 | + * displays if more than one version of EE is activated at the same time |
|
| 45 | + */ |
|
| 46 | + function espresso_duplicate_plugin_error() |
|
| 47 | + { |
|
| 48 | + ?> |
|
| 49 | 49 | <div class="error"> |
| 50 | 50 | <p> |
| 51 | 51 | <?php |
| 52 | - echo esc_html__( |
|
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 52 | + echo esc_html__( |
|
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | } else { |
| 64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
| 65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | - /** |
|
| 67 | - * espresso_minimum_php_version_error |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
| 65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | + /** |
|
| 67 | + * espresso_minimum_php_version_error |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + function espresso_minimum_php_version_error() |
|
| 72 | + { |
|
| 73 | + ?> |
|
| 74 | 74 | <div class="error"> |
| 75 | 75 | <p> |
| 76 | 76 | <?php |
| 77 | - printf( |
|
| 78 | - esc_html__( |
|
| 79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | - 'event_espresso' |
|
| 81 | - ), |
|
| 82 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | - PHP_VERSION, |
|
| 84 | - '<br/>', |
|
| 85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | - ); |
|
| 87 | - ?> |
|
| 77 | + printf( |
|
| 78 | + esc_html__( |
|
| 79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | + 'event_espresso' |
|
| 81 | + ), |
|
| 82 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | + PHP_VERSION, |
|
| 84 | + '<br/>', |
|
| 85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | + ); |
|
| 87 | + ?> |
|
| 88 | 88 | </p> |
| 89 | 89 | </div> |
| 90 | 90 | <?php |
| 91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | - } |
|
| 91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | - } else { |
|
| 96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | - /** |
|
| 98 | - * espresso_version |
|
| 99 | - * Returns the plugin version |
|
| 100 | - * |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - function espresso_version() |
|
| 104 | - { |
|
| 105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.69.rc.004'); |
|
| 106 | - } |
|
| 94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | + } else { |
|
| 96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | + /** |
|
| 98 | + * espresso_version |
|
| 99 | + * Returns the plugin version |
|
| 100 | + * |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + function espresso_version() |
|
| 104 | + { |
|
| 105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.69.rc.004'); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * espresso_plugin_activation |
|
| 110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | - */ |
|
| 112 | - function espresso_plugin_activation() |
|
| 113 | - { |
|
| 114 | - update_option('ee_espresso_activation', true); |
|
| 115 | - } |
|
| 108 | + /** |
|
| 109 | + * espresso_plugin_activation |
|
| 110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | + */ |
|
| 112 | + function espresso_plugin_activation() |
|
| 113 | + { |
|
| 114 | + update_option('ee_espresso_activation', true); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 118 | 118 | |
| 119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | - bootstrap_espresso(); |
|
| 121 | - } |
|
| 119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | + bootstrap_espresso(); |
|
| 121 | + } |
|
| 122 | 122 | } |
| 123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
| 124 | - /** |
|
| 125 | - * deactivate_plugin |
|
| 126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | - * |
|
| 128 | - * @access public |
|
| 129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | - * @return void |
|
| 131 | - */ |
|
| 132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | - { |
|
| 134 | - if (! function_exists('deactivate_plugins')) { |
|
| 135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | - } |
|
| 137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | - deactivate_plugins($plugin_basename); |
|
| 139 | - } |
|
| 124 | + /** |
|
| 125 | + * deactivate_plugin |
|
| 126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | + * |
|
| 128 | + * @access public |
|
| 129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | + * @return void |
|
| 131 | + */ |
|
| 132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | + { |
|
| 134 | + if (! function_exists('deactivate_plugins')) { |
|
| 135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | + } |
|
| 137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | + deactivate_plugins($plugin_basename); |
|
| 139 | + } |
|
| 140 | 140 | } |