WordPress.org

Make WordPress Core

Ticket #22679: 22679.diff

File 22679.diff, 1.3 KB (added by jond3r, 5 years ago)
  • wp-admin/includes/ajax-actions.php

     
    19501950        if ( 'attachment' != $post->post_type )
    19511951                wp_send_json_error();
    19521952
     1953        $rel = $url = '';
     1954        if ( ! empty( $attachment['url'] ) )
     1955                $url = $attachment['url'];
     1956       
    19531957        // If this attachment is unattached, attach it. Primarily a back compat thing.
    19541958        if ( 0 == $post->post_parent && $insert_into_post_id = intval( $_POST['post_id'] ) ) {
    19551959                wp_update_post( array( 'ID' => $id, 'post_parent' => $insert_into_post_id ) );
     1960               
     1961                // Update attachment url if it contains a default query string, since it may have been 'prettified'.
     1962                if ( strpos( $url, 'attachment_id') )
     1963                        $url = get_attachment_link( $id );
    19561964        }
    19571965
    1958         $rel = $url = '';
    19591966        $html = $title = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
    1960         if ( ! empty( $attachment['url'] ) ) {
    1961                 $url = $attachment['url'];
     1967        if ( ! empty( $url ) ) {
    19621968                if ( strpos( $url, 'attachment_id') || get_attachment_link( $id ) == $url )
    19631969                        $rel = ' rel="attachment wp-att-' . $id . '"';
    19641970                $html = '<a href="' . esc_url( $url ) . '"' . $rel . '>' . $html . '</a>';