Make WordPress Core


Ignore:
Timestamp:
10/06/2015 04:58:21 AM (9 years ago)
Author:
wonderboymusic
Message:

Merge the Responsive Images feature plugin into core, initial commit. See: https://github.com/ResponsiveImagesCG/wp-tevko-responsive-images/

New functions in media.php:

  • wp_get_attachment_image_srcset_array() - Returns an array of image candidate string data used to build a srcset value for an attachment given an $attachement_id and $size.
  • wp_get_attachment_image_srcset() - Returns the srcset value for an attachment given an $attachement_id and $size.
  • wp_get_attachment_image_sizes() - Returns the sizes value for an attachment given an $attachement_id and $size and optional arguments used to alter its output.
  • wp_make_content_images_responsive() - A display filter for adding srcset and sizes to images embedded in content.
  • wp_img_add_srcset_and_sizes() - A utility function used by wp_make_content_images_responsive() to add srcset and sizes to a single <img> element.

Modifies existing core functions:

  • Modify wp_get_attachment_image() so the HTML returned for an image includes srcset and sizes.
  • Modify get_media_embedded_in_content() (sup, 3.6 leftover) by adding <img> to the list of accepted tags that can be matched in content. This is used in wp_make_content_images_responsive() to find all of the images embedded in content before passing them off to wp_img_add_srcset_and_sizes().

Tests:

  • Add a new factory method to WP_UnitTest_Factory_For_Attachment named create_upload_object()
  • Adds unit tests
  • Updates unit tests

Props joemcgill, tevko, jaspermdegroot, mdmcginn, barryceelen, peterwilsoncc, fsylum, wonderboymusic, chriscoyier, benjaminpick, jrfnl, #12kingkool68, janhenckens, ryanmarkel, side777, ryelle, wturrell, micahmills, mattbagwell, coliff, DrewAPicture.
See #33641.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/xmlrpc/wp/editPost.php

    r31983 r34855  
    114114        $this->assertEquals( $editor_id, $out->post_author );
    115115    }
    116    
     116
    117117    function test_post_thumbnail() {
    118118        add_theme_support( 'post-thumbnails' );
     
    127127        // create attachment
    128128        $filename = ( DIR_TESTDATA.'/images/a2-small.jpg' );
    129         $contents = file_get_contents( $filename );
    130         $upload = wp_upload_bits( $filename, null, $contents );
    131         $this->assertTrue( empty( $upload['error'] ) );
    132 
    133         $attachment = array(
    134             'post_title' => 'Post Thumbnail',
    135             'post_type' => 'attachment',
    136             'post_mime_type' => 'image/jpeg',
    137             'guid' => $upload['url']
    138         );
    139         $attachment_id = wp_insert_attachment( $attachment, $upload['file'], $post_id );
     129        $attachment_id = $this->factory->attachment->create_upload_object( $filename, $post_id );
    140130
    141131        // add post thumbnail to post that does not have one
     
    159149
    160150        // create another attachment
    161         $attachment2 = array_merge( $attachment, array( 'post_title' => 'Post Thumbnail 2' ) );
    162         $attachment2_id = wp_insert_attachment( $attachment2, $upload['file'], $post_id );
     151        $attachment2_id = $this->factory->attachment->create_upload_object( $filename, $post_id );
    163152
    164153        // change the post's post_thumbnail
Note: See TracChangeset for help on using the changeset viewer.