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