From 043715e8a4c111814215649ef08b3a357c2b328c Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 15 Jul 2014 22:08:14 +0000 Subject: [PATCH] Add a new AJAX action: `parse-media-shortcode`. This async call will replace JS rendering of audio/video/playlist shortcodes. See #28905. Built from https://develop.svn.wordpress.org/trunk@29178 git-svn-id: http://core.svn.wordpress.org/trunk@28962 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin-ajax.php | 3 ++- wp-admin/includes/ajax-actions.php | 33 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index f4cafd0c30..60f1778cd1 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -60,7 +60,8 @@ $core_actions_post = array( 'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment', 'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor', 'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'get-revision-diffs', - 'save-user-color-scheme', 'update-widget', 'query-themes', 'parse-embed', 'set-attachment-thumbnail' + 'save-user-color-scheme', 'update-widget', 'query-themes', 'parse-embed', 'set-attachment-thumbnail', + 'parse-media-shortcode' ); // Register core Ajax calls. diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index 478dcb004f..db53ad7b6a 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -2684,3 +2684,36 @@ function wp_ajax_parse_embed() { wp_send_json_success( $parsed ); } + +function wp_ajax_parse_media_shortcode() { + global $post, $wp_scripts; + + if ( ! $post = get_post( (int) $_REQUEST['post_ID'] ) ) { + wp_send_json_error(); + } + + setup_postdata( $post ); + + ob_start(); + + $styles = wp_media_mce_styles(); + foreach ( $styles as $style ) { + printf( '', $style ); + } + + echo do_shortcode( wp_unslash( $_REQUEST['shortcode'] ) ); + + if ( ! empty( $wp_scripts ) ) { + $wp_scripts->done = array(); + } + + if ( 'playlist' === $_REQUEST['type'] ) { + wp_underscore_playlist_templates(); + + wp_print_scripts( 'wp-playlist' ); + } else { + wp_print_scripts( 'wp-mediaelement' ); + } + + wp_send_json_success( ob_get_clean() ); +} \ No newline at end of file