wp_ajax_parse_media_shortcode

The timeline below displays how wordpress function wp_ajax_parse_media_shortcode has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 3.2

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post       Global post object.
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    // Only process previews for media related shortcodes:
    $found_shortcodes = get_shortcode_tags_in_content($shortcode);
    $media_shortcodes = array('audio', 'embed', 'playlist', 'video', 'gallery');
    $other_shortcodes = array_diff($found_shortcodes, $media_shortcodes);
    if (!empty($other_shortcodes)) {
        wp_send_json_error();
    }
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // The embed shortcode requires a post.
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if (in_array('embed', $found_shortcodes, true)) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 6.3

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post       Global post object.
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // The embed shortcode requires a post.
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 2.3

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post       Global post object.
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    // Only process previews for media related shortcodes:
    $found_shortcodes = get_shortcode_tags_in_content($shortcode);
    $media_shortcodes = array('audio', 'embed', 'playlist', 'video', 'gallery');
    $other_shortcodes = array_diff($found_shortcodes, $media_shortcodes);
    if (!empty($other_shortcodes)) {
        wp_send_json_error();
    }
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // The embed shortcode requires a post.
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if (in_array('embed', $found_shortcodes, true)) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 6.2

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post       Global post object.
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // The embed shortcode requires a post.
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 1.4

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post       Global post object.
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    // Only process previews for media related shortcodes:
    $found_shortcodes = get_shortcode_tags_in_content($shortcode);
    $media_shortcodes = array('audio', 'embed', 'playlist', 'video', 'gallery');
    $other_shortcodes = array_diff($found_shortcodes, $media_shortcodes);
    if (!empty($other_shortcodes)) {
        wp_send_json_error();
    }
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // The embed shortcode requires a post.
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if (in_array('embed', $found_shortcodes, true)) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 6.1

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post       Global post object.
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // The embed shortcode requires a post.
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 9.8

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post       Global post object.
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    // Only process previews for media related shortcodes:
    $found_shortcodes = get_shortcode_tags_in_content($shortcode);
    $media_shortcodes = array('audio', 'embed', 'playlist', 'video', 'gallery');
    $other_shortcodes = array_diff($found_shortcodes, $media_shortcodes);
    if (!empty($other_shortcodes)) {
        wp_send_json_error();
    }
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // The embed shortcode requires a post.
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if (in_array('embed', $found_shortcodes, true)) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 5.9

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post       Global post object.
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // The embed shortcode requires a post.
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 8.8

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post       Global post object.
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    // Only process previews for media related shortcodes:
    $found_shortcodes = get_shortcode_tags_in_content($shortcode);
    $media_shortcodes = array('audio', 'embed', 'playlist', 'video', 'gallery');
    $other_shortcodes = array_diff($found_shortcodes, $media_shortcodes);
    if (!empty($other_shortcodes)) {
        wp_send_json_error();
    }
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // The embed shortcode requires a post.
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if (in_array('embed', $found_shortcodes, true)) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 7.2

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post       Global post object.
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // The embed shortcode requires a post.
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: .10

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post       Global post object.
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    // Only process previews for media related shortcodes:
    $found_shortcodes = get_shortcode_tags_in_content($shortcode);
    $media_shortcodes = array('audio', 'embed', 'playlist', 'video', 'gallery');
    $other_shortcodes = array_diff($found_shortcodes, $media_shortcodes);
    if (!empty($other_shortcodes)) {
        wp_send_json_error();
    }
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // The embed shortcode requires a post.
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if (in_array('embed', $found_shortcodes, true)) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 6.2

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post       Global post object.
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // The embed shortcode requires a post.
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: .12

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post       Global post object.
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    // Only process previews for media related shortcodes:
    $found_shortcodes = get_shortcode_tags_in_content($shortcode);
    $media_shortcodes = array('audio', 'embed', 'playlist', 'video', 'gallery');
    $other_shortcodes = array_diff($found_shortcodes, $media_shortcodes);
    if (!empty($other_shortcodes)) {
        wp_send_json_error();
    }
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // The embed shortcode requires a post.
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if (in_array('embed', $found_shortcodes, true)) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 5.2

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post       Global post object.
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // The embed shortcode requires a post.
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: .13

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post       Global post object.
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    // Only process previews for media related shortcodes:
    $found_shortcodes = get_shortcode_tags_in_content($shortcode);
    $media_shortcodes = array('audio', 'embed', 'playlist', 'video', 'gallery');
    $other_shortcodes = array_diff($found_shortcodes, $media_shortcodes);
    if (!empty($other_shortcodes)) {
        wp_send_json_error();
    }
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // The embed shortcode requires a post.
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if (in_array('embed', $found_shortcodes, true)) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 4.2

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post       Global post object.
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // The embed shortcode requires a post.
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: .14

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post       Global post object.
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    // Only process previews for media related shortcodes:
    $found_shortcodes = get_shortcode_tags_in_content($shortcode);
    $media_shortcodes = array('audio', 'embed', 'playlist', 'video', 'gallery');
    $other_shortcodes = array_diff($found_shortcodes, $media_shortcodes);
    if (!empty($other_shortcodes)) {
        wp_send_json_error();
    }
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // The embed shortcode requires a post.
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if (in_array('embed', $found_shortcodes, true)) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 5.4

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post       Global post object.
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // The embed shortcode requires a post.
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 3.2

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post       Global post object.
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: .16

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post       Global post object.
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    // Only process previews for media related shortcodes:
    $found_shortcodes = get_shortcode_tags_in_content($shortcode);
    $media_shortcodes = array('audio', 'embed', 'playlist', 'video', 'gallery');
    $other_shortcodes = array_diff($found_shortcodes, $media_shortcodes);
    if (!empty($other_shortcodes)) {
        wp_send_json_error();
    }
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if (in_array('embed', $found_shortcodes, true)) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 5.3

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post       Global post object.
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 2.3

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: .20

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    // Only process previews for media related shortcodes:
    $found_shortcodes = get_shortcode_tags_in_content($shortcode);
    $media_shortcodes = array('audio', 'embed', 'playlist', 'video', 'gallery');
    $other_shortcodes = array_diff($found_shortcodes, $media_shortcodes);
    if (!empty($other_shortcodes)) {
        wp_send_json_error();
    }
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if (in_array('embed', $found_shortcodes, true)) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 2.2

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: .19

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    // Only process previews for media related shortcodes:
    $found_shortcodes = get_shortcode_tags_in_content($shortcode);
    $media_shortcodes = array('audio', 'embed', 'playlist', 'video', 'gallery');
    $other_shortcodes = array_diff($found_shortcodes, $media_shortcodes);
    if (!empty($other_shortcodes)) {
        wp_send_json_error();
    }
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if (in_array('embed', $found_shortcodes, true)) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 1.2

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: .17

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    // Only process previews for media related shortcodes:
    $found_shortcodes = get_shortcode_tags_in_content($shortcode);
    $media_shortcodes = array('audio', 'embed', 'playlist', 'video', 'gallery');
    $other_shortcodes = array_diff($found_shortcodes, $media_shortcodes);
    if (!empty($other_shortcodes)) {
        wp_send_json_error();
    }
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if (in_array('embed', $found_shortcodes, true)) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 0.3

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: .20

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    // Only process previews for media related shortcodes:
    $found_shortcodes = get_shortcode_tags_in_content($shortcode);
    $media_shortcodes = array('audio', 'embed', 'playlist', 'video', 'gallery');
    $other_shortcodes = array_diff($found_shortcodes, $media_shortcodes);
    if (!empty($other_shortcodes)) {
        wp_send_json_error();
    }
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if (in_array('embed', $found_shortcodes, true)) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 9.3

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: .24

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    // Only process previews for media related shortcodes:
    $found_shortcodes = get_shortcode_tags_in_content($shortcode);
    $media_shortcodes = array('audio', 'embed', 'playlist', 'video', 'gallery');
    $other_shortcodes = array_diff($found_shortcodes, $media_shortcodes);
    if (!empty($other_shortcodes)) {
        wp_send_json_error();
    }
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if (in_array('embed', $found_shortcodes, true)) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 4.9

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('mediaelement-vimeo', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 6.3

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('froogaloop', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: .27

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    // Only process previews for media related shortcodes:
    $found_shortcodes = get_shortcode_tags_in_content($shortcode);
    $media_shortcodes = array('audio', 'embed', 'playlist', 'video', 'gallery');
    $other_shortcodes = array_diff($found_shortcodes, $media_shortcodes);
    if (!empty($other_shortcodes)) {
        wp_send_json_error();
    }
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if (in_array('embed', $found_shortcodes, true)) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('froogaloop', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 5.4

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('froogaloop', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: .30

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    // Only process previews for media related shortcodes:
    $found_shortcodes = get_shortcode_tags_in_content($shortcode);
    $media_shortcodes = array('audio', 'embed', 'playlist', 'video', 'gallery');
    $other_shortcodes = array_diff($found_shortcodes, $media_shortcodes);
    if (!empty($other_shortcodes)) {
        wp_send_json_error();
    }
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if (in_array('embed', $found_shortcodes, true)) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('froogaloop', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 4.4

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('froogaloop', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: .31

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    // Only process previews for media related shortcodes:
    $found_shortcodes = get_shortcode_tags_in_content($shortcode);
    $media_shortcodes = array('audio', 'embed', 'playlist', 'video', 'gallery');
    $other_shortcodes = array_diff($found_shortcodes, $media_shortcodes);
    if (!empty($other_shortcodes)) {
        wp_send_json_error();
    }
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if (in_array('embed', $found_shortcodes, true)) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('froogaloop', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 3.4

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('froogaloop', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: .32

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    // Only process previews for media related shortcodes:
    $found_shortcodes = get_shortcode_tags_in_content($shortcode);
    $media_shortcodes = array('audio', 'embed', 'playlist', 'video', 'gallery');
    $other_shortcodes = array_diff($found_shortcodes, $media_shortcodes);
    if (!empty($other_shortcodes)) {
        wp_send_json_error();
    }
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if (in_array('embed', $found_shortcodes, true)) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('froogaloop', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 4.3

/**
 * @since 4.0.0
 *
 * @global WP_Post    $post
 * @global WP_Scripts $wp_scripts
 */
function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('froogaloop', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 2.4

function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('froogaloop', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: .36

function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    // Only process previews for media related shortcodes:
    $found_shortcodes = get_shortcode_tags_in_content($shortcode);
    $media_shortcodes = array('audio', 'embed', 'playlist', 'video', 'gallery');
    $other_shortcodes = array_diff($found_shortcodes, $media_shortcodes);
    if (!empty($other_shortcodes)) {
        wp_send_json_error();
    }
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if (in_array('embed', $found_shortcodes, true)) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('froogaloop', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 4.2

function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if ('embed' === $shortcode) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    $parsed = do_shortcode($shortcode);
    if (empty($parsed)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $parsed;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts(array('froogaloop', 'wp-mediaelement'));
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 1.5

function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (!$post = get_post((int) $_POST['post_ID'])) {
        wp_send_json_error();
    }
    if (empty($_POST['shortcode']) || !current_user_can('edit_post', $post->ID)) {
        wp_send_json_error();
    }
    setup_postdata($post);
    $shortcode = do_shortcode(wp_unslash($_POST['shortcode']));
    if (empty($shortcode)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $shortcode;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts('wp-mediaelement');
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: .40

function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (!$post = get_post((int) $_POST['post_ID'])) {
        wp_send_json_error();
    }
    if (empty($_POST['shortcode']) || !current_user_can('edit_post', $post->ID)) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    // Only process previews for media related shortcodes:
    $found_shortcodes = get_shortcode_tags_in_content($shortcode);
    $media_shortcodes = array('audio', 'embed', 'playlist', 'video', 'gallery');
    $other_shortcodes = array_diff($found_shortcodes, $media_shortcodes);
    if (!empty($other_shortcodes)) {
        wp_send_json_error();
    }
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if (in_array('embed', $found_shortcodes, true)) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    if (empty($shortcode)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $shortcode;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts('wp-mediaelement');
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 1.4

function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (!$post = get_post((int) $_POST['post_ID'])) {
        wp_send_json_error();
    }
    if (empty($_POST['shortcode']) || !current_user_can('edit_post', $post->ID)) {
        wp_send_json_error();
    }
    setup_postdata($post);
    $shortcode = do_shortcode(wp_unslash($_POST['shortcode']));
    if (empty($shortcode)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $shortcode;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts('wp-mediaelement');
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: .39

function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (!$post = get_post((int) $_POST['post_ID'])) {
        wp_send_json_error();
    }
    if (empty($_POST['shortcode']) || !current_user_can('edit_post', $post->ID)) {
        wp_send_json_error();
    }
    $shortcode = wp_unslash($_POST['shortcode']);
    // Only process previews for media related shortcodes:
    $found_shortcodes = get_shortcode_tags_in_content($shortcode);
    $media_shortcodes = array('audio', 'embed', 'playlist', 'video', 'gallery');
    $other_shortcodes = array_diff($found_shortcodes, $media_shortcodes);
    if (!empty($other_shortcodes)) {
        wp_send_json_error();
    }
    if (!empty($_POST['post_ID'])) {
        $post = get_post((int) $_POST['post_ID']);
    }
    // the embed shortcode requires a post
    if (!$post || !current_user_can('edit_post', $post->ID)) {
        if (in_array('embed', $found_shortcodes, true)) {
            wp_send_json_error();
        }
    } else {
        setup_postdata($post);
    }
    if (empty($shortcode)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $shortcode;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts('wp-mediaelement');
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}

WordPress Version: 4.0

function wp_ajax_parse_media_shortcode()
{
    global $post, $wp_scripts;
    if (!$post = get_post((int) $_POST['post_ID'])) {
        wp_send_json_error();
    }
    if (empty($_POST['shortcode']) || !current_user_can('edit_post', $post->ID)) {
        wp_send_json_error();
    }
    setup_postdata($post);
    $shortcode = do_shortcode(wp_unslash($_POST['shortcode']));
    if (empty($shortcode)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $shortcode;
    if ('playlist' === $_REQUEST['type']) {
        wp_underscore_playlist_templates();
        wp_print_scripts('wp-playlist');
    } else {
        wp_print_scripts('wp-mediaelement');
    }
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}