wp_ajax_parse_media_shortcode

The WordPress Core wp ajax parse media shortcode function.

Description

wp_ajax_parse_media_shortcode(); 

Usage

  1. if ( !function_exists( 'wp_ajax_parse_media_shortcode' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/ajax-actions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_ajax_parse_media_shortcode(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/ajax-actions.php  
  1. function wp_ajax_parse_media_shortcode() { 
  2. global $post, $wp_scripts; 
  3.  
  4. if ( empty( $_POST['shortcode'] ) ) { 
  5.  
  6. $shortcode = wp_unslash( $_POST['shortcode'] ); 
  7.  
  8. if ( ! empty( $_POST['post_ID'] ) ) { 
  9. $post = get_post( (int) $_POST['post_ID'] ); 
  10.  
  11. // the embed shortcode requires a post 
  12. if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) { 
  13. if ( 'embed' === $shortcode ) { 
  14. } else { 
  15. setup_postdata( $post ); 
  16.  
  17. $parsed = do_shortcode( $shortcode ); 
  18.  
  19. if ( empty( $parsed ) ) { 
  20. 'type' => 'no-items',  
  21. 'message' => __( 'No items found.' ),  
  22. ) ); 
  23.  
  24. $head = ''; 
  25.  
  26. foreach ( $styles as $style ) { 
  27. $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">'; 
  28.  
  29. if ( ! empty( $wp_scripts ) ) { 
  30. $wp_scripts->done = array(); 
  31.  
  32. ob_start(); 
  33.  
  34. echo $parsed; 
  35.  
  36. if ( 'playlist' === $_REQUEST['type'] ) { 
  37.  
  38. wp_print_scripts( 'wp-playlist' ); 
  39. } else { 
  40. wp_print_scripts( array( 'froogaloop', 'wp-mediaelement' ) ); 
  41.  
  42. 'head' => $head,  
  43. 'body' => ob_get_clean() 
  44. ) );