wp_ajax_parse_embed

Apply Ajax handlers to a string.

Description

wp_ajax_parse_embed(); 

Usage

  1. if ( !function_exists( 'wp_ajax_parse_embed' ) ) { 
  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_embed(); 
  7.  

Defined (1)

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

/wp-admin/includes/ajax-actions.php  
  1. function wp_ajax_parse_embed() { 
  2. global $post, $wp_embed; 
  3.  
  4. if ( ! $post = get_post( (int) $_POST['post_ID'] ) ) { 
  5.  
  6. if ( empty( $_POST['shortcode'] ) || ! current_user_can( 'edit_post', $post->ID ) ) { 
  7.  
  8. $shortcode = wp_unslash( $_POST['shortcode'] ); 
  9.  
  10. preg_match( '/' . get_shortcode_regex() . '/s', $shortcode, $matches ); 
  11. $atts = shortcode_parse_atts( $matches[3] ); 
  12. if ( ! empty( $matches[5] ) ) { 
  13. $url = $matches[5]; 
  14. } elseif ( ! empty( $atts['src'] ) ) { 
  15. $url = $atts['src']; 
  16. } else { 
  17. $url = ''; 
  18.  
  19. $parsed = false; 
  20. setup_postdata( $post ); 
  21.  
  22. $wp_embed->return_false_on_fail = true; 
  23.  
  24. if ( is_ssl() && 0 === strpos( $url, 'http://' ) ) { 
  25. // Admin is ssl and the user pasted non-ssl URL. 
  26. // Check if the provider supports ssl embeds and use that for the preview. 
  27. $ssl_shortcode = preg_replace( '%^(\\[embed[^\\]]*\\])http://%i', '$1https://', $shortcode ); 
  28. $parsed = $wp_embed->run_shortcode( $ssl_shortcode ); 
  29.  
  30. if ( ! $parsed ) { 
  31. $no_ssl_support = true; 
  32.  
  33. if ( $url && ! $parsed ) { 
  34. $parsed = $wp_embed->run_shortcode( $shortcode ); 
  35.  
  36. if ( ! $parsed ) { 
  37. 'type' => 'not-embeddable',  
  38. 'message' => sprintf( __( '%s failed to embed.' ), '<code>' . esc_html( $url ) . '</code>' ),  
  39. ) ); 
  40.  
  41. if ( has_shortcode( $parsed, 'audio' ) || has_shortcode( $parsed, 'video' ) ) { 
  42. $styles = ''; 
  43. $mce_styles = wpview_media_sandbox_styles(); 
  44. foreach ( $mce_styles as $style ) { 
  45. $styles .= sprintf( '<link rel="stylesheet" href="%s"/>', $style ); 
  46.  
  47. $html = do_shortcode( $parsed ); 
  48.  
  49. global $wp_scripts; 
  50. if ( ! empty( $wp_scripts ) ) { 
  51. $wp_scripts->done = array(); 
  52. ob_start(); 
  53. wp_print_scripts( 'wp-mediaelement' ); 
  54. $scripts = ob_get_clean(); 
  55.  
  56. $parsed = $styles . $html . $scripts; 
  57.  
  58.  
  59. if ( ! empty( $no_ssl_support ) || ( is_ssl() && ( preg_match( '%<(iframe|script|embed) [^>]*src="http://%', $parsed ) || 
  60. preg_match( '%<link [^>]*href="http://%', $parsed ) ) ) ) { 
  61. // Admin is ssl and the embed is not. Iframes, scripts, and other "active content" will be blocked. 
  62. 'type' => 'not-ssl',  
  63. 'message' => __( 'This preview is unavailable in the editor.' ),  
  64. ) ); 
  65.  
  66. 'body' => $parsed,  
  67. 'attr' => $wp_embed->last_attr 
  68. ) );