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