Make WordPress Core


Ignore:
Timestamp:
01/16/2015 05:18:17 AM (12 years ago)
Author:
wonderboymusic
Message:

In wp_ajax_parse_media_shortcode(), don't require a global $post for all passed shortcodes.

embed is the only shortcode that requires a post ID. This will allow MCE views to work for playlist, audio, and video outside of the Edit Post screen.

See #30835.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r31119 r31201  
    27262726        global $post, $wp_scripts;
    27272727
    2728         if ( ! $post = get_post( (int) $_POST['post_ID'] ) ) {
    2729                 wp_send_json_error();
    2730         }
    2731 
    2732         if ( empty( $_POST['shortcode'] ) || ! current_user_can( 'edit_post', $post->ID ) ) {
    2733                 wp_send_json_error();
    2734         }
    2735 
    2736         setup_postdata( $post );
    2737         $shortcode = do_shortcode( wp_unslash( $_POST['shortcode'] ) );
    2738 
    2739         if ( empty( $shortcode ) ) {
     2728        if ( empty( $_POST['shortcode'] ) ) {
     2729                wp_send_json_error();
     2730        }
     2731
     2732        $shortcode = wp_unslash( $_POST['shortcode'] );
     2733
     2734        if ( ! empty( $_POST['post_ID'] ) ) {
     2735                $post = get_post( (int) $_POST['post_ID'] );
     2736        }
     2737
     2738        // the embed shortcode requires a post
     2739        if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) {
     2740                if ( 'embed' === $shortcode ) {
     2741                        wp_send_json_error();
     2742                }
     2743        } else {
     2744                setup_postdata( $post );
     2745        }
     2746
     2747        $parsed = do_shortcode( $shortcode  );
     2748
     2749        if ( empty( $parsed ) ) {
    27402750                wp_send_json_error( array(
    27412751                        'type' => 'no-items',
     
    27572767        ob_start();
    27582768
    2759         echo $shortcode;
     2769        echo $parsed;
    27602770
    27612771        if ( 'playlist' === $_REQUEST['type'] ) {
Note: See TracChangeset for help on using the changeset viewer.