Body_Classes.php
2 weeks ago
Crons.php
2 weeks ago
Debug_Bar.php
2 weeks ago
Dialog.php
2 weeks ago
PUE.php
2 weeks ago
Processes.php
2 weeks ago
Promoter.php
2 weeks ago
Shortcodes.php
2 weeks ago
Tooltip.php
2 weeks ago
Widgets.php
2 weeks ago
Shortcodes.php
122 lines
| 1 | <?php |
| 2 | namespace Tribe\Service_Providers; |
| 3 | |
| 4 | use Tribe\Shortcode\Manager; |
| 5 | |
| 6 | /** |
| 7 | * Class Shortcode |
| 8 | * |
| 9 | * @since 4.12.0 |
| 10 | * |
| 11 | * @package Tribe\Service_Providers |
| 12 | */ |
| 13 | class Shortcodes extends \tad_DI52_ServiceProvider { |
| 14 | |
| 15 | /** |
| 16 | * Binds and sets up implementations. |
| 17 | * |
| 18 | * @since 4.12.0 |
| 19 | */ |
| 20 | public function register() { |
| 21 | if ( ! static::is_active() ) { |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | $this->container->singleton( Manager::class, Manager::class ); |
| 26 | $this->container->singleton( |
| 27 | 'shortcode.manager', |
| 28 | function() { |
| 29 | return $this->container->make( Manager::class ); |
| 30 | } |
| 31 | ); |
| 32 | |
| 33 | $this->register_hooks(); |
| 34 | $this->register_assets(); |
| 35 | |
| 36 | $this->container->singleton( static::class, $this ); |
| 37 | |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Static method wrapper around a filter to allow full deactivation of this provider |
| 42 | * |
| 43 | * @since 4.12.0 |
| 44 | * |
| 45 | * @return boolean If this service provider is active. |
| 46 | */ |
| 47 | public static function is_active() { |
| 48 | /** |
| 49 | * Allows filtering to deactivate all shortcodes loading. |
| 50 | * |
| 51 | * @since 4.12.0 |
| 52 | * |
| 53 | * @param boolean $is_active If shortcodes should be loaded or not. |
| 54 | */ |
| 55 | return apply_filters( 'tribe_shortcodes_is_active', true ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Register all the assets associated with this service provider. |
| 60 | * |
| 61 | * @since 4.12.0 |
| 62 | */ |
| 63 | protected function register_assets() { |
| 64 | |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Registers the provider handling all the 1st level filters and actions for this service provider. |
| 69 | * |
| 70 | * @since 4.12.0 |
| 71 | */ |
| 72 | protected function register_hooks() { |
| 73 | add_action( 'init', [ $this, 'action_add_shortcodes' ], 20 ); |
| 74 | add_filter( 'pre_do_shortcode_tag', [ $this, 'filter_pre_do_shortcode_tag' ], 10, 4 ); |
| 75 | add_filter( 'do_shortcode_tag', [ $this, 'filter_do_shortcode_tag' ], 10, 4 ); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Adds the new shortcodes, this normally will trigger on `init@P20` due to how we the |
| 80 | * v1 is added on `init@P10` and we remove them on `init@P15`. |
| 81 | * |
| 82 | * It's important to leave gaps on priority for better injection. |
| 83 | * |
| 84 | * @since 4.12.0 |
| 85 | */ |
| 86 | public function action_add_shortcodes() { |
| 87 | $this->container->make( Manager::class )->add_shortcodes(); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Filters `pre_do_shortcode_tag` to mark that a tribe shortcode is currently being done. |
| 92 | * |
| 93 | * @since 4.12.9 |
| 94 | * |
| 95 | * @param bool|string $return Short-circuit return value. Either false or the value to replace the shortcode with. |
| 96 | * @param string $tag Shortcode name. |
| 97 | * @param array $attr Shortcode attributes array, |
| 98 | * @param array $m Regular expression match array. |
| 99 | * |
| 100 | * @return bool|string Short-circuit return value. |
| 101 | */ |
| 102 | public function filter_pre_do_shortcode_tag( $false, $tag, $attr, $m ) { |
| 103 | return $this->container->make( Manager::class )->filter_pre_do_shortcode_tag( $false, $tag, $attr, $m ); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * * Filters `do_shortcode_tag` to mark that a tribe shortcode is complete, and remove it from the current list. |
| 108 | * |
| 109 | * @since 4.12.9 |
| 110 | * |
| 111 | * @param string $output Shortcode output. |
| 112 | * @param string $tag Shortcode name. |
| 113 | * @param array|string $attr Shortcode attributes array or empty string. |
| 114 | * @param array $m Regular expression match array. |
| 115 | * |
| 116 | * @return string Shortcode output. |
| 117 | */ |
| 118 | public function filter_do_shortcode_tag( $output, $tag, $attr, $m ) { |
| 119 | return $this->container->make( Manager::class )->filter_do_shortcode_tag( $output, $tag, $attr, $m ); |
| 120 | } |
| 121 | } |
| 122 |