PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 11.2
Jetpack – WP Security, Backup, Speed, & Growth v11.2
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / shortcodes / unavailable.php

unavailable.php in Jetpack – WP Security, Backup, Speed, & Growth 11.2, at modules/shortcodes/unavailable.php

83 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 /**
10 * Class Jetpack_Shortcode_Unavailable
11 */
12 class Jetpack_Shortcode_Unavailable {
13 /**
14 * Set up the actions and filters for the class to listen to.
15 *
16 * @param array $shortcodes An associative array of keys being the shortcodes that are unavailable, and a string explaining why.
17 */
18 public function __construct( $shortcodes ) {
19 $this->shortcodes = $shortcodes;
20
21 add_action( 'template_redirect', array( $this, 'add_shortcodes' ) );
22 }
23
24 /**
25 * For all of our defined unavailable shortcodes, if something else hasn't
26 * already claimed them, add a handler to nullify their output.
27 */
28 public function add_shortcodes() {
29 foreach ( array_keys( $this->shortcodes ) as $shortcode ) {
30 if ( ! shortcode_exists( $shortcode ) ) {
31 add_shortcode( $shortcode, array( $this, 'stub_shortcode' ) );
32 }
33 }
34 }
35
36 /**
37 * Nullify the output of unavailable shortcodes. Includes a filter to make
38 * it easier to notify admins that a shortcode that they used is unavailable.
39 *
40 * @param array $atts Shortcode attributes.
41 * @param string $content Post content.
42 * @param string $shortcode Shortcode name.
43 *
44 * @return mixed|void
45 */
46 public function stub_shortcode( $atts, $content = '', $shortcode = '' ) {
47 $str = '';
48 if ( current_user_can( 'edit_posts' ) && ! empty( $this->shortcodes[ $shortcode ] ) ) {
49 $str = sprintf( '<div><strong>%s</strong></div>', $this->shortcodes[ $shortcode ] );
50 }
51 /**
52 * Filter the front-end output of unavailable shortcodes.
53 *
54 * @module shortcodes
55 *
56 * @since 4.5.0
57 *
58 * @param string $str The html displayed in lieu of the shortcode.
59 * @param array $atts The attributes (numeric or named) passed to the shortcode.
60 * @param string $content The content (if any) between the opening and closing tags.
61 * @param string $shortcode The shortcode tag used to invoke this.
62 */
63 return apply_filters( 'jetpack_stub_shortcode', $str, $atts, $content, $shortcode );
64 }
65 }
66
67 /**
68 * Init class.
69 */
70 function jetpack_init_shortcode_unavailable() {
71 new Jetpack_Shortcode_Unavailable(
72 array(
73 'digg' => __( 'The Digg API was shut down in 2014.', 'jetpack' ),
74 'hulu' => __( 'Hulu no longer allows embedding content.', 'jetpack' ),
75 'blip.tv' => __( 'The Blip.tv service has been shut down since August 20th, 2015.', 'jetpack' ),
76 'googlevideo' => __( 'The Google Video embed service is not available anymore, it has been replaced by YouTube.', 'jetpack' ),
77 'jetpack-email-subscribe' => __( 'The Email Subscribe shortcode is now available as a block in the Block editor.', 'jetpack' ),
78 'lytro' => __( 'Lytro has been shut down since March 2019.', 'jetpack' ),
79 )
80 );
81 }
82 add_action( 'init', 'jetpack_init_shortcode_unavailable' );
83