From 594c08d6ab5694da640b9e2f580cdf49f37a6e90 Mon Sep 17 00:00:00 2001 From: Joseadrian Ochoa Date: Sat, 26 Aug 2017 04:18:42 -0500 Subject: [PATCH] Adds `shortcode_ui_preview` filter Added `shortcode_ui_preview` filter to give the option to modify the preview in the WYSIWYG. --- inc/class-shortcode-ui.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/inc/class-shortcode-ui.php b/inc/class-shortcode-ui.php index 6e08d476..85b49ab3 100644 --- a/inc/class-shortcode-ui.php +++ b/inc/class-shortcode-ui.php @@ -440,6 +440,25 @@ private function render_shortcode_for_preview( $shortcode, $post_id = null ) { // @codingStandardsIgnoreEnd } + // Get the Shortcode tag and set the response if any + preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $shortcode, $matches ); + $shortcode_tag = isset( $matches[1][0] ) ? $matches[1][0] : ''; + + /** + * Filter the shortcode preview + * + * Used to render a custom preview for the shortcodes on the editor + * + * @param string $pre_option The default value to return if the custom preview hasn't been set. + * @param string $shortcode_tag Shortcode tag name. + * @param string $shortcode Shortcode used. + * @param array $options Shortcode UI options for the shortcode tag + */ + $response = apply_filters( 'shortcode_ui_preview', false, $shortcode_tag, $shortcode, $this->get_shortcode( $shortcode_tag ) ); + if ( false !== $response ) { + return $response; + } + ob_start(); /** * Fires before shortcode is rendered in preview.