Ticket #27891: 27891.2.diff
File 27891.2.diff, 4.4 KB (added by , 9 years ago) |
---|
-
src/wp-admin/admin-ajax.php
60 60 'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment', 61 61 'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor', 62 62 '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' 64 64 ); 65 65 66 66 // Register core Ajax calls. -
src/wp-admin/includes/ajax-actions.php
1932 1932 } 1933 1933 1934 1934 /** 1935 * Ajax handler for setting the featured image for an attachment. 1936 * 1937 * @since 4.0.0 1938 */ 1939 function 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 /** 1935 1979 * Ajax handler for date formatting. 1936 1980 * 1937 1981 * @since 3.1.0 -
src/wp-admin/includes/media.php
2642 2642 $attr['height'] = $h; 2643 2643 } 2644 2644 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 2645 2650 echo wp_video_shortcode( $attr ); 2646 2651 2647 2652 endif; ?> -
src/wp-includes/js/media-audiovideo.js
Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream
681 681 682 682 renderSelectPosterImageToolbar: function() { 683 683 this.setPrimaryButton( l10n.videoSelectPosterImageTitle, function( controller, state ) { 684 var attachment = state.get( 'selection' ).single();684 var urls = [], attachment = state.get( 'selection' ).single(); 685 685 686 686 controller.media.set( 'poster', attachment.get( 'url' ) ); 687 687 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 } ); 688 702 } ); 689 703 }, 690 704 -
src/wp-includes/media.php
Cannot display: file marked as a binary type. svn:mime-type = image/png
3189 3189 } 3190 3190 } 3191 3191 } 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 */ 3200 function 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