On this page
wp_ajax_parse_media_shortcode()
Source
File: wp-admin/includes/ajax-actions.php. View all references
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(),
)
);
}
Related
Uses
| Uses | Description |
|---|---|
| wpview_media_sandbox_styles() wp-includes/media.php | Returns the URLs for CSS files used in an iframe-sandbox’d TinyMCE media view. |
| setup_postdata() wp-includes/query.php | Set up global post data. |
| wp_print_scripts() wp-includes/functions.wp-scripts.php | Prints scripts in document head that are in the $handles queue. |
| do_shortcode() wp-includes/shortcodes.php | Searches content for shortcodes and filter shortcodes through their hooks. |
| wp_underscore_playlist_templates() wp-includes/media.php | Outputs the templates used by playlists. |
| current_user_can() wp-includes/capabilities.php | Returns whether the current user has the specified capability. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| wp_unslash() wp-includes/formatting.php | Removes slashes from a string or recursively removes slashes from strings within an array. |
| wp_send_json_error() wp-includes/functions.php | Sends a JSON response back to an Ajax request, indicating failure. |
| wp_send_json_success() wp-includes/functions.php | Sends a JSON response back to an Ajax request, indicating success. |
| get_post() wp-includes/post.php | Retrieves post data given a post ID or post object. |
Changelog
| Version | Description |
|---|---|
| 4.0.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_ajax_parse_media_shortcode