Changeset 29029
- Timestamp:
- 07/08/2014 05:47:53 PM (11 years ago)
- Location:
- trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/admin-ajax.php
r28580 r29029 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 -
trunk/src/wp-admin/includes/ajax-actions.php
r28974 r29029 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 // For each URL, try to find its corresponding post ID. 1966 foreach ( $_POST['urls'] as $url ) { 1967 $post_id = attachment_url_to_postid( $url ); 1968 if ( ! empty( $post_id ) ) { 1969 $post_ids[] = $post_id; 1970 } 1971 } 1972 1973 if ( empty( $post_ids ) ) { 1974 wp_send_json_error(); 1975 } 1976 1977 $success = 0; 1978 // For each found attachment, set its thumbnail. 1979 foreach ( $post_ids as $post_id ) { 1980 if ( ! current_user_can( 'edit_post', $post_id ) ) { 1981 continue; 1982 } 1983 1984 if ( set_post_thumbnail( $post_id, $thumbnail_id ) ) { 1985 $success++; 1986 } 1987 } 1988 1989 if ( 0 === $success ) { 1990 wp_send_json_error(); 1991 } else { 1992 wp_send_json_success(); 1993 } 1994 1995 wp_send_json_error(); 1996 } 1997 1998 /** 1950 1999 * Ajax handler for date formatting. 1951 2000 * -
trunk/src/wp-admin/includes/media.php
r28871 r29029 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 -
trunk/src/wp-includes/js/media-audiovideo.js
r28993 r29029 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 }, -
trunk/src/wp-includes/media.php
r28976 r29029 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 }
Note: See TracChangeset
for help on using the changeset viewer.