| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * Module Name: Shortcode Embeds |
| 4 | - * Module Description: Shortcodes are WordPress-specific markup that let you add media from popular sites. This feature is no longer necessary as the editor now handles media embeds rather gracefully. | |
| 4 | + * Module Description: Easily embed rich media like YouTube videos and tweets using simple shortcodes. | |
| 5 | 5 | * Sort Order: 3 |
| 6 | 6 | * First Introduced: 1.1 |
| 7 | 7 | * Major Changes In: 1.2 |
| 8 | 8 | * Requires Connection: No |
| @@ -13,8 +13,15 @@ | ||
| 13 | 13 | * |
| 14 | 14 | * @package automattic/jetpack |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 18 | + exit( 0 ); | |
| 19 | +} | |
| 20 | + | |
| 21 | +// Load shortcode utils. | |
| 22 | +require_once __DIR__ . '/shortcodes/shortcode-utils.php'; | |
| 23 | + | |
| 17 | 24 | /** |
| 18 | 25 | * Transforms the $atts array into a string that the old functions expected |
| 19 | 26 | * |
| 20 | 27 | * The old way was: |
| @@ -45,20 +52,29 @@ | ||
| 45 | 52 | /** |
| 46 | 53 | * Load all available Jetpack shortcode files. |
| 47 | 54 | */ |
| 48 | 55 | function jetpack_load_shortcodes() { |
| 56 | + // Prevent third-party shortcode plugins when loading shortcode files. | |
| 57 | + // Format: shortcode => condition_when_to_skip | |
| 58 | + $shortcode_skips = array( | |
| 59 | + 'shortcode-utils' => true, // Utils aren't shortcodes. | |
| 60 | + 'soundcloud' => function_exists( 'soundcloud_shortcode' ), // SoundCloud Shortcodes plugin | |
| 61 | + ); | |
| 62 | + | |
| 49 | 63 | $shortcode_includes = array(); |
| 50 | 64 | |
| 51 | 65 | foreach ( Jetpack::glob_php( __DIR__ . '/shortcodes' ) as $file ) { |
| 52 | 66 | $filename = substr( basename( $file ), 0, -4 ); |
| 53 | 67 | |
| 54 | - $shortcode_includes[ $filename ] = $file; | |
| 68 | + if ( empty( $shortcode_skips[ $filename ] ) ) { | |
| 69 | + $shortcode_includes[ $filename ] = $file; | |
| 70 | + } | |
| 55 | 71 | } |
| 56 | 72 | |
| 57 | 73 | /** |
| 58 | 74 | * This filter allows other plugins to override which shortcodes Jetpack loads. |
| 59 | 75 | * |
| 60 | - * Fires as part of the `plugins_loaded` WP hook, so modifying code needs to be in a plugin, not in a theme's functions.php. | |
| 76 | + * Fires as part of the `after_setup_theme` WP hook, so modifying code needs to be in a plugin, not in a theme's functions.php. | |
| 61 | 77 | * |
| 62 | 78 | * @module shortcodes |
| 63 | 79 | * |
| 64 | 80 | * @since 2.2.1 |
| @@ -84,9 +100,9 @@ | ||
| 84 | 100 | * |
| 85 | 101 | * @return string $content Replaced post content. |
| 86 | 102 | */ |
| 87 | 103 | function jetpack_preg_replace_outside_tags( $pattern, $replacement, $content, $search = null ) { |
| 88 | - if ( $search && false === strpos( $content, $search ) ) { | |
| 104 | + if ( $search && ! str_contains( $content, $search ) ) { | |
| 89 | 105 | return $content; |
| 90 | 106 | } |
| 91 | 107 | |
| 92 | 108 | $textarr = wp_html_split( $content ); |
| @@ -112,9 +128,9 @@ | ||
| 112 | 128 | * |
| 113 | 129 | * @return string $content Replaced post content. |
| 114 | 130 | */ |
| 115 | 131 | function jetpack_preg_replace_callback_outside_tags( $pattern, $callback, $content, $search = null ) { |
| 116 | - if ( $search && false === strpos( $content, $search ) ) { | |
| 132 | + if ( $search && ! str_contains( $content, $search ) ) { | |
| 117 | 133 | return $content; |
| 118 | 134 | } |
| 119 | 135 | |
| 120 | 136 | $textarr = wp_html_split( $content ); |