Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| jetpack_init_shortcode_unavailable | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
| Jetpack_Shortcode_Unavailable | |
0.00% |
0 / 9 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| add_shortcodes | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
| stub_shortcode | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | /** |
| 3 | * Display a message on the frontend when we retire a shortcode, |
| 4 | * explaining why the shortcode is not available anymore. |
| 5 | * |
| 6 | * @package automattic/jetpack |
| 7 | */ |
| 8 | |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit( 0 ); |
| 11 | } |
| 12 | |
| 13 | // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. |
| 14 | |
| 15 | /** |
| 16 | * Class Jetpack_Shortcode_Unavailable |
| 17 | * |
| 18 | * @phan-constructor-used-for-side-effects |
| 19 | */ |
| 20 | class Jetpack_Shortcode_Unavailable { |
| 21 | /** |
| 22 | * Shortcodes that are unavailable. |
| 23 | * |
| 24 | * Key is the shortcode, value is string explaining why. |
| 25 | * |
| 26 | * @var array |
| 27 | */ |
| 28 | public $shortcodes; |
| 29 | |
| 30 | /** |
| 31 | * Set up the actions and filters for the class to listen to. |
| 32 | * |
| 33 | * @param array $shortcodes An associative array of keys being the shortcodes that are unavailable, and a string explaining why. |
| 34 | */ |
| 35 | public function __construct( $shortcodes ) { |
| 36 | $this->shortcodes = $shortcodes; |
| 37 | |
| 38 | add_action( 'template_redirect', array( $this, 'add_shortcodes' ) ); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * For all of our defined unavailable shortcodes, if something else hasn't |
| 43 | * already claimed them, add a handler to nullify their output. |
| 44 | */ |
| 45 | public function add_shortcodes() { |
| 46 | foreach ( array_keys( $this->shortcodes ) as $shortcode ) { |
| 47 | if ( ! shortcode_exists( $shortcode ) ) { |
| 48 | add_shortcode( $shortcode, array( $this, 'stub_shortcode' ) ); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Nullify the output of unavailable shortcodes. Includes a filter to make |
| 55 | * it easier to notify admins that a shortcode that they used is unavailable. |
| 56 | * |
| 57 | * @param array $atts Shortcode attributes. |
| 58 | * @param string $content Post content. |
| 59 | * @param string $shortcode Shortcode name. |
| 60 | * |
| 61 | * @return mixed|void |
| 62 | */ |
| 63 | public function stub_shortcode( $atts, $content = '', $shortcode = '' ) { |
| 64 | $str = ''; |
| 65 | if ( current_user_can( 'edit_posts' ) && ! empty( $this->shortcodes[ $shortcode ] ) ) { |
| 66 | $str = sprintf( '<div><strong>%s</strong></div>', $this->shortcodes[ $shortcode ] ); |
| 67 | } |
| 68 | /** |
| 69 | * Filter the front-end output of unavailable shortcodes. |
| 70 | * |
| 71 | * @module shortcodes |
| 72 | * |
| 73 | * @since 4.5.0 |
| 74 | * |
| 75 | * @param string $str The html displayed in lieu of the shortcode. |
| 76 | * @param array $atts The attributes (numeric or named) passed to the shortcode. |
| 77 | * @param string $content The content (if any) between the opening and closing tags. |
| 78 | * @param string $shortcode The shortcode tag used to invoke this. |
| 79 | */ |
| 80 | return apply_filters( 'jetpack_stub_shortcode', $str, $atts, $content, $shortcode ); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Init class. |
| 86 | */ |
| 87 | function jetpack_init_shortcode_unavailable() { |
| 88 | new Jetpack_Shortcode_Unavailable( |
| 89 | array( |
| 90 | 'digg' => __( 'The Digg API was shut down in 2014.', 'jetpack' ), |
| 91 | 'hulu' => __( 'Hulu no longer allows embedding content.', 'jetpack' ), |
| 92 | 'blip.tv' => __( 'The Blip.tv service has been shut down since August 20th, 2015.', 'jetpack' ), |
| 93 | 'googlevideo' => __( 'The Google Video embed service is not available anymore, it has been replaced by YouTube.', 'jetpack' ), |
| 94 | 'jetpack-email-subscribe' => __( 'The Email Subscribe shortcode is now available as a block in the Block editor.', 'jetpack' ), |
| 95 | 'lytro' => __( 'Lytro has been shut down since March 2019.', 'jetpack' ), |
| 96 | ) |
| 97 | ); |
| 98 | } |
| 99 | add_action( 'init', 'jetpack_init_shortcode_unavailable' ); |