Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds shortcode_ui_preview filter #769

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions inc/class-shortcode-ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down