From 477f41440ee5938720a289f64bef6719ae0f87ae 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..2b4df74a 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.