Ticket #27891: 27891.3.diff
File 27891.3.diff, 4.2 KB (added by , 10 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
1947 1947 } 1948 1948 1949 1949 /** 1950 * Ajax handler for setting the featured image for an attachment. 1951 * 1952 * @since 4.0.0 1953 */ 1954 function wp_ajax_set_attachment_thumbnail() { 1955 if ( empty( $_POST['urls'] ) || ! is_array( $_POST['urls'] ) ) { 1956 wp_send_json_error(); 1957 } 1958 1959 $thumbnail_id = (int) $_POST['thumbnail_id']; 1960 if ( empty( $thumbnail_id ) ) { 1961 wp_send_json_error(); 1962 } 1963 1964 $post_ids = array(); 1965 foreach ( $_POST['urls'] as $url ) { 1966 $post_id = attachment_url_to_postid( $url ); 1967 if ( ! empty( $post_id ) ) { 1968 $post_ids[] = $post_id; 1969 } 1970 } 1971 1972 if ( empty( $post_ids ) ) { 1973 wp_send_json_error(); 1974 } 1975 1976 $success = 0; 1977 foreach ( $post_ids as $post_id ) { 1978 if ( ! current_user_can( 'edit_post', $post_id ) ) { 1979 continue; 1980 } 1981 1982 if ( set_post_thumbnail( $post_id, $thumbnail_id ) ) { 1983 $success++; 1984 } 1985 } 1986 1987 if ( 0 === $success ) { 1988 wp_send_json_error(); 1989 } else { 1990 wp_send_json_success(); 1991 } 1992 1993 wp_send_json_error(); 1994 } 1995 1996 /** 1950 1997 * Ajax handler for date formatting. 1951 1998 * 1952 1999 * @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
692 692 693 693 renderSelectPosterImageToolbar: function() { 694 694 this.setPrimaryButton( l10n.videoSelectPosterImageTitle, function( controller, state ) { 695 var attachment = state.get( 'selection' ).single();695 var urls = [], attachment = state.get( 'selection' ).single(); 696 696 697 697 controller.media.set( 'poster', attachment.get( 'url' ) ); 698 698 state.trigger( 'set-poster-image', controller.media.toJSON() ); 699 700 _.each( wp.media.view.settings.embedExts, function (ext) { 701 if ( controller.media.get( ext ) ) { 702 urls.push( controller.media.get( ext ) ); 703 } 704 } ); 705 706 wp.ajax.send( 'set-attachment-thumbnail', { 707 data : { 708 urls: urls, 709 thumbnail_id: attachment.get( 'id' ) 710 } 711 } ); 699 712 } ); 700 713 }, 701 714 -
src/wp-includes/media.php
3218 3218 } 3219 3219 } 3220 3220 } 3221 3222 /** 3223 * Try to convert an attachment URL into a post ID. 3224 * 3225 * @since 4.0.0 3226 * 3227 * @global wpdb $wpdb WordPress database access abstraction object. 3228 * @param string $url The URL to resolve. 3229 * @return int The found post_id. 3230 */ 3231 function attachment_url_to_postid( $url ) { 3232 global $wpdb; 3233 3234 $dir = wp_upload_dir(); 3235 $path = ltrim( $url, $dir['baseurl'] . '/' ); 3236 3237 $sql = $wpdb->prepare( 3238 "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = %s", 3239 $path 3240 ); 3241 $post_id = $wpdb->get_var( $sql ); 3242 if ( ! empty( $post_id ) ) { 3243 return (int) $post_id; 3244 } 3245 } 3246 No newline at end of file