PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 6.3.2
Jetpack – WP Security, Backup, Speed, & Growth v6.3.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 6.3.2, at modules/shortcodes/unavailable.php

63 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class Jetpack_Shortcode_Unavailable
5 */
6 class Jetpack_Shortcode_Unavailable {
7 /**
8 * Set up the actions and filters for the class to listen to.
9 *
10 * @param array $shortcodes An associative array of keys being the shortcodes that are unavailable, and a string explaining why.
11 */
12 public function __construct( $shortcodes ) {
13 $this->shortcodes = $shortcodes;
14
15 add_action( 'template_redirect', array( $this, 'add_shortcodes' ) );
16 }
17
18 /**
19 * For all of our defined unavailable shortcodes, if something else hasn't
20 * already claimed them, add a handler to nullify their output.
21 */
22 public function add_shortcodes() {
23 foreach ( $this->shortcodes as $shortcode => $message ) {
24 if ( ! shortcode_exists( $shortcode ) ) {
25 add_shortcode( $shortcode, array( $this, 'stub_shortcode' ) );
26 }
27 }
28 }
29
30 /**
31 * Nullify the output of unavailable shortcodes. Includes a filter to make
32 * it easier to notify admins that a shortcode that they used is unavailable.
33 *
34 * @param $atts
35 * @param string $content
36 * @param string $shortcode
37 * @return mixed|void
38 */
39 public function stub_shortcode( $atts, $content = '', $shortcode = '' ) {
40 $str = '';
41 if ( current_user_can( 'edit_posts' ) && ! empty( $this->shortcodes[ $shortcode ] ) ) {
42 $str = sprintf( '<div><strong>%s</strong></div>', $this->shortcodes[ $shortcode ] );
43 }
44 /**
45 * Filter the front-end output of unavailable shortcodes.
46 *
47 * @module shortcodes
48 *
49 * @since 4.5.0
50 *
51 * @param string $str The html displayed in lieu of the shortcode.
52 * @param array $atts The attributes (numeric or named) passed to the shortcode.
53 * @param string $content The content (if any) between the opening and closing tags.
54 * @param string $shortcode The shortcode tag used to invoke this.
55 */
56 return apply_filters( 'jetpack_stub_shortcode', $str, $atts, $content, $shortcode );
57 }
58 }
59
60 new Jetpack_Shortcode_Unavailable( array(
61 'blip.tv' => __( 'The Blip.tv service has been shut down since August 20th, 2015.', 'jetpack' ),
62 ) );
63