Ticket #15192: 15192.diff

File 15192.diff, 2.9 KB (added by sorich87, 3 years ago)
  • wp-includes/post.php

     
    52115211        endif; 
    52125212} 
    52135213 
     5214/** 
     5215 * Attach a thumbnail to a post. 
     5216 * 
     5217 * @since 3.1 
     5218 * 
     5219 * @param int int|object $post The post for which to assign a thumbnail. 
     5220 * @param int $thumbnail_id. The thumbnail to assign ID. 
     5221 * @return bool Whether post has an image attached. 
     5222 */ 
     5223function set_post_thumbnail( $post, $thumbnail_id ) { 
     5224        $post = get_post($post); 
     5225        if ( empty($post) ) 
     5226                return new WP_Error('invalid_post', __('Invalid post')); 
     5227 
     5228        if ( !wp_attachment_is_image($thumbnail_id) ) 
     5229                return new WP_Error('invalid_attachment', __('The attachment is not an image')); 
     5230 
     5231        return update_post_meta($post->ID, '_thumbnail_id', $thumbnail_id); 
     5232} 
     5233 
    52145234?> 
  • wp-admin/admin-ajax.php

     
    744744        require_once ABSPATH . 'wp-admin/includes/nav-menu.php'; 
    745745 
    746746        /** 
    747          * For performance reasons, we omit some object properties from the checklist. 
     747         * For performance reasons, we omit some object properties from the checklist. 
    748748         * The following is a hacky way to restore them when adding non-custom items. 
    749749         */ 
    750750        $menu_items_data = (array) $_POST['menu-item']; 
    751         $menu_item_data = array_shift( $menu_items_data ); 
    752         if ( 
    753                 ! empty( $menu_item_data['menu-item-type'] ) && 
     751        $menu_item_data = array_shift( $menu_items_data ); 
     752        if ( 
     753                ! empty( $menu_item_data['menu-item-type'] ) && 
    754754                'custom' != $menu_item_data['menu-item-type'] && 
    755755                ! empty( $menu_item_data['menu-item-object-id'] ) 
    756756        ) { 
     
    760760                        break; 
    761761 
    762762                        case 'taxonomy' : 
    763                                 $_object = get_term( $menu_item_data['menu-item-object-id'], $menu_item_data['menu-item-object'] ); 
     763                                $_object = get_term( $menu_item_data['menu-item-object-id'], $menu_item_data['menu-item-object'] ); 
    764764                        break; 
    765765                } 
    766766 
    767                 $_menu_items = array_map( 'wp_setup_nav_menu_item', array( $_object ) ); 
     767                $_menu_items = array_map( 'wp_setup_nav_menu_item', array( $_object ) ); 
    768768                $_menu_item = array_shift( $_menu_items ); 
    769769 
    770770                /** Restore the missing menu item properties **/ 
     
    10971097        require_once ABSPATH . WPINC . '/js/tinymce/wp-mce-link-includes.php'; 
    10981098 
    10991099        wp_link_ajax( $_POST ); 
    1100  
     1100 
    11011101        exit; 
    11021102        break; 
    11031103case 'menu-locations-save': 
     
    14521452                die( _wp_post_thumbnail_html() ); 
    14531453        } 
    14541454 
    1455         if ( $thumbnail_id && get_post( $thumbnail_id ) ) { 
    1456                 $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'thumbnail' ); 
    1457                 if ( !empty( $thumbnail_html ) ) { 
    1458                         update_post_meta( $post_ID, '_thumbnail_id', $thumbnail_id ); 
     1455        if ( $thumbnail_id ) { 
     1456                $set_post_thumbnail = set_post_thumbnail( $post_ID, $thumbnail_id ); 
     1457                if ( $set_post_thumbnail && !is_wp_error( $set_post_thumbnail ) ) 
    14591458                        die( _wp_post_thumbnail_html( $thumbnail_id ) ); 
    1460                 } 
    14611459        } 
    14621460        die( '0' ); 
    14631461        break;