Make WordPress Core

Ticket #27891: 27891.2.diff

File 27891.2.diff, 4.4 KB (added by wonderboymusic, 9 years ago)
  • src/wp-admin/admin-ajax.php

     
    6060        'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment',
    6161        'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor',
    6262        'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'get-revision-diffs',
    63         'save-user-color-scheme', 'update-widget', 'query-themes', 'parse-embed'
     63        'save-user-color-scheme', 'update-widget', 'query-themes', 'parse-embed', 'set-attachment-thumbnail'
    6464);
    6565
    6666// Register core Ajax calls.
  • src/wp-admin/includes/ajax-actions.php

     
    19321932}
    19331933
    19341934/**
     1935 * Ajax handler for setting the featured image for an attachment.
     1936 *
     1937 * @since 4.0.0
     1938 */
     1939function wp_ajax_set_attachment_thumbnail() {
     1940        if ( empty( $_POST['urls'] ) ) {
     1941                wp_die( -1 );
     1942        }
     1943
     1944        $post_ids = array();
     1945        foreach ( $_POST['urls'] as $url ) {
     1946                $post_id = attachment_url_to_postid( $url );
     1947                if ( ! empty( $post_id ) ) {
     1948                        $post_ids[] = $post_id;
     1949                }
     1950        }
     1951
     1952        if ( empty( $post_ids ) ) {
     1953                wp_die( -1 );
     1954        }
     1955
     1956        $thumbnail_id = (int) $_POST['thumbnail_id'];
     1957
     1958        $success = 0;
     1959        foreach ( $post_ids as $post_id ) {
     1960                if ( ! current_user_can( 'edit_post', $post_id ) ) {
     1961                        continue;
     1962                }
     1963
     1964                if ( set_post_thumbnail( $post_id, $thumbnail_id ) ) {
     1965                        $success++;
     1966                }
     1967        }
     1968
     1969        if ( 0 === $success ) {
     1970                wp_die( -1 );
     1971        } else {
     1972                wp_send_json_success();
     1973        }
     1974
     1975        wp_die( 0 );
     1976}
     1977
     1978/**
    19351979 * Ajax handler for date formatting.
    19361980 *
    19371981 * @since 3.1.0
  • src/wp-admin/includes/media.php

     
    26422642                        $attr['height'] = $h;
    26432643                }
    26442644
     2645                $thumb_id = get_post_thumbnail_id( $attachment_id );
     2646                if ( ! empty( $thumb_id ) ) {
     2647                        $attr['poster'] = wp_get_attachment_url( $thumb_id );
     2648                }
     2649
    26452650                echo wp_video_shortcode( $attr );
    26462651
    26472652        endif; ?>
  • src/wp-includes/js/media-audiovideo.js

    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
     
    681681
    682682                renderSelectPosterImageToolbar: function() {
    683683                        this.setPrimaryButton( l10n.videoSelectPosterImageTitle, function( controller, state ) {
    684                                 var attachment = state.get( 'selection' ).single();
     684                                var urls = [], attachment = state.get( 'selection' ).single();
    685685
    686686                                controller.media.set( 'poster', attachment.get( 'url' ) );
    687687                                state.trigger( 'set-poster-image', controller.media.toJSON() );
     688
     689                                _.each( wp.media.view.settings.embedExts, function (ext) {
     690                                        if ( controller.media.get( ext ) ) {
     691                                                urls.push( controller.media.get( ext ) );
     692                                        }
     693                                } );
     694
     695                                wp.ajax.send( 'set-attachment-thumbnail', {
     696                                        data : {
     697                                                urls: urls,
     698                                                thumbnail_id: attachment.get( 'id' ),
     699                                                _ajax_nonce: ''
     700                                        }
     701                                } );
    688702                        } );
    689703                },
    690704
  • src/wp-includes/media.php

    Cannot display: file marked as a binary type.
    svn:mime-type = image/png
     
    31893189                }
    31903190        }
    31913191}
     3192
     3193/**
     3194 * Try to convert an attachment URL into a post ID.
     3195 *
     3196 * @global wpdb $wpdb
     3197 * @param string $url The URL to resolve.
     3198 * @return int The found post_id.
     3199 */
     3200function attachment_url_to_postid( $url ) {
     3201        global $wpdb;
     3202
     3203        $dir = wp_upload_dir();
     3204        $path = ltrim( $url, $dir['baseurl'] . '/' );
     3205
     3206        $sql = $wpdb->prepare(
     3207                "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = %s",
     3208                $path
     3209        );
     3210        $post_id = $wpdb->get_var( $sql );
     3211        if ( ! empty( $post_id ) ) {
     3212                return (int) $post_id;
     3213        }
     3214}
     3215 No newline at end of file