| 1 |
<?php |
| 2 |
/** |
| 3 |
* The Events Calendar |
| 4 |
* |
| 5 |
* @package ContentControl |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace ContentControl\Controllers\Compatibility; |
| 9 |
|
| 10 |
use ContentControl\Base\Controller; |
| 11 |
|
| 12 |
/** |
| 13 |
* TheEventsCalendar controller class. |
| 14 |
*/ |
| 15 |
class TheEventsCalendar extends Controller { |
| 16 |
|
| 17 |
/** |
| 18 |
* Initiate hooks & filter. |
| 19 |
* |
| 20 |
* @return void |
| 21 |
*/ |
| 22 |
public function init() { |
| 23 |
// 'wp_redirect' |
| 24 |
add_action( 'content_control/restrict_main_query', [ $this, 'restrict_main_query' ], 10 ); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Check if controller is enabled. |
| 29 |
* |
| 30 |
* @return bool |
| 31 |
*/ |
| 32 |
public function controller_enabled() { |
| 33 |
return class_exists( '\Tribe__Events__Main' ) && defined( 'TRIBE_EVENTS_FILE' ); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Handle restrictions on the main query. |
| 38 |
* |
| 39 |
* When the main query is set to be redirected, TEC was cancelling the redirect. Returing true will allow the redirect to happen. |
| 40 |
* |
| 41 |
* @return void |
| 42 |
*/ |
| 43 |
public function restrict_main_query() { |
| 44 |
// If during the main query, a redirect is called on the events page, we need to allow it to happen. |
| 45 |
add_filter( 'wp_redirect', function ( $location ) { |
| 46 |
// Only call this filter within the redirect filter. Limiting the scope of the filter. |
| 47 |
add_filter( 'tec_events_views_v2_redirected', '__return_true' ); |
| 48 |
return $location; |
| 49 |
}, 0 ); |
| 50 |
} |
| 51 |
} |
| 52 |
|