Plugin Directory

Changeset 1815404


Ignore:
Timestamp:
02/05/2018 02:01:27 AM (8 years ago)
Author:
tazziedave
Message:

Fixed bug that affected image sizing. Added workaround because WooCommerce returns a different image array size in it's application of the 'wp_get_attachment_image_src' filter.

Location:
wysiwyg-custom-products
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • wysiwyg-custom-products/tags/1.1/admin/class-ajax.php

    r1677949 r1815404  
    2121 *
    2222 * @since      1.0.0
    23  * @updated    1.1.2
     23 * @updated    1.1.4
    2424 */
    2525class Ajax {
     
    6969     *
    7070     * @since   1.0.0
    71      * @updated 1.1.0
     71     * @updated 1.1.4
    7272     */
    7373    public function get_image_attr() {
     
    7878        $image = wp_get_attachment_image_src( $attachmentId, $size );
    7979        // Overriding WP's resizing of image in admin for "editing"
    80         $attributes = wc_get_image_size( $size );
     80        $attributes = wcp_get_image_size( $size, $attachmentId );
    8181        if ( $attributes ) {
    8282            $image['width']  = maybe_get( $attributes, 'width', $image['width'] );
  • wysiwyg-custom-products/tags/1.1/common/class-wp-html-helper.php

    r1603224 r1815404  
    1515 *
    1616 * @since   1.0.1
    17  * @updated 1.1.0
     17 * @updated 1.1.4
    1818 */
    1919
     
    263263     *
    264264     * @since   1.0.8
    265      * @updated 1.1.0
     265     * @updated 1.1.4
    266266     */
    267267    public function svg_sized_img(
     
    273273//      Overriding WP's resizing of image in admin for "editing"
    274274        if ( $forceSize ) {
    275             $attributes = wc_get_image_size( $size );
     275            $attributes = wcp_get_image_size( $size, $attachmentId );
    276276            if ( $attributes ) {
    277277                $image['width']  = maybe_get( $attributes, 'width', $image['width'] );
     
    283283        return $this->svg_img( $image['url'], $image['width'], $image['height'], $classes, $id, $attributes,
    284284            $styles );
     285    }
     286
     287    /** @noinspection MoreThanThreeArgumentsInspection */
     288    /**
     289     * Creates SVG <image ... /> tag getting the correct image and size from the WP size string
     290     * Escapes href
     291     *
     292     * @param int    $attachmentId
     293     * @param string $size
     294     * @param bool   $forceSize Forces image size based on $size with no manipulation by WP for admin editing
     295     * @param string $classes
     296     * @param string $id
     297     * @param array  $attributes
     298     * @param array  $styles
     299     *
     300     * @return null|string
     301     *
     302     * @since   1.1.4
     303     */
     304    public function frontend_svg_sized_img(
     305        $attachmentId, $size, $forceSize = false, $classes = '', $id = '', array $attributes = [],
     306        array $styles = []
     307    ) {
     308        $image = wp_get_attachment_image_src( $attachmentId, $size );
     309
     310        if ( $forceSize ) {
     311            $attributes = wcp_get_image_size( $size );
     312            if ( $attributes ) {
     313                $image['width']  = maybe_get( $attributes, 'width', $image['width'] );
     314                $image['height'] = maybe_get( $attributes, 'height', $image['height'] );
     315            }
     316
     317        }
     318
     319        return $this->svg_img( $image['url'], $image['width'], $image['height'], $classes, $id, $attributes,
     320                               $styles );
    285321    }
    286322
  • wysiwyg-custom-products/tags/1.1/common/utilities.php

    r1812372 r1815404  
    77 *
    88 * @since   1.0.0
    9  * @updated 1.1.3
     9 * @updated 1.1.4
    1010 */
    1111
     
    169169    return '#' . substr( '000000' . dechex( $colorValue ), - 6 );
    170170}
     171
     172/**
     173 * Get an image size by name or defined dimensions. Or use $id to get actual image size.
     174 *
     175 * The returned variable is filtered by woocommerce_get_image_size_{image_size} filter to
     176 * allow 3rd party customisation.
     177 *
     178 * Sizes defined by the theme take priority over settings. Settings are hidden when a theme
     179 * defines sizes.
     180 *
     181 * @param array|string $image_size    Name of the image size to get, or an array of dimensions.
     182 * @param null|int     $attachmentId  image attachment id
     183 *
     184 * @return array Array of dimensions including width, height, and cropping mode. Cropping mode is 0 for no crop, and 1 for hard crop.
     185 *
     186 * @since 1.1.4
     187 */
     188function wcp_get_image_size( $image_size, $attachmentId = null ) {
     189    $size = array(
     190        'width'  => 600,
     191        'height' => 600,
     192        'crop'   => 0,
     193    );
     194
     195    if ((null !== $attachmentId) && \wp_attachment_is_image($attachmentId)) {
     196        $meta = wp_get_attachment_metadata( $attachmentId);
     197        $size['width']  = maybe_get( $meta, 'width', $size['width'] );
     198        $size['height'] = maybe_get( $meta, 'height', $size['height'] );
     199        return $size;
     200    }
     201
     202    return \wc_get_image_size($image_size);
     203}
  • wysiwyg-custom-products/tags/1.1/common/wp-helpers.php

    r1603224 r1815404  
    77 *
    88 * @since   1.0.0
    9  * @updated 1.0.6
     9 * @updated 1.1.4
    1010 */
    1111
     
    394394 *
    395395 * @since   1.0.8
     396 * @updated 1.1.4
    396397 */
    397398function wp_get_attachment_image_src( $attachmentId, $size ) {
     
    399400    if ( ! $image ) {
    400401        $image = [ '', 0, 0, false ];
     402    } elseif (3 === \count( $image)) { // Needed because WooCommerce does not include 'intermediate' parameter
     403        $image[] = false;
    401404    }
    402405
  • wysiwyg-custom-products/tags/1.1/frontend/class-frontend.php

    r1812372 r1815404  
    1919 *
    2020 * @since      1.0.0
    21  * @updated    1.1.3
     21 * @updated    1.1.4
    2222 */
    2323class Frontend {
     
    166166    }
    167167
     168    /** @noinspection MoreThanThreeArgumentsInspection */
    168169    /**
    169170     * Builds SVG html in $this->h
     
    174175     * @param string|null $divId
    175176     * @param string|null $imageId
    176      *
    177      * @since   1.0.0
    178      * @updated 1.1.0
    179      */
    180     private function svg_html( $liveLines, $message = null, $formats = null, $divId = null, $imageId = null ) {
     177     * @param bool        $forceSize
     178     *
     179     * @since   1.0.0
     180     * @updated 1.1.4
     181     */
     182    private function svg_html( $liveLines, $message = null, $formats = null, $divId = null, $imageId = null,
     183                               $forceSize = false
     184    ) {
    181185        $h = $this->h;
    182186        $l = $this->layout;
     
    202206        $h->o_tag( 'g' );
    203207
    204         $h->svg_sized_img( $l->image, $l->size, false, '', 'svg_image' );
     208        $h->frontend_svg_sized_img( $l->image, $l->size, $forceSize, '', 'svg_image' );
    205209
    206210        if ( $formats ) {
     
    291295        $message = $productText ? explode( '|', $productText ) : false;
    292296
    293         $this->svg_html( $liveUpdate, $message, $formats, 'front_svg', 'svg_image' );
     297        $this->svg_html( $liveUpdate, $message, $formats, 'front_svg', 'svg_image', true );
    294298        $h->tag( 'p', $l->getMultiLineReformatMsg(), 'wcp-hidden wcp-lost-text', 'wcp_multiline' );
    295299        $h->tag( 'p', $l->getNumberOfLinesMsg(), 'wcp-hidden wcp-lost-text', 'wcp_too_many_lines' );
  • wysiwyg-custom-products/tags/1.1/readme.txt

    r1812372 r1815404  
    124124
    125125= 1.1.3 =
    126 * Added workaround for changes in woocommerce core functions and image size names.
     126* Added workaround for changes in WooCommerce core functions and image size names.
     127
     128= 1.1.4 =
     129* Fixed bug in image sizing from Admin to Frontend.
     130* Added workaround because WooCommerce returns a different image array size in it's application of the 'wp_get_attachment_image_src' filter.
    127131
    128132== Upgrade Notice ==
    129 Fixed for WooCommerce 3.3.0 changes.
     133Fixed for WooCommerce 3.3.0 changes. Fixed bug that affected image sizing.
    130134
    131135== Creating Layouts - Instructions ==
  • wysiwyg-custom-products/tags/1.1/wysiwyg-custom-products.php

    r1812372 r1815404  
    44 * Plugin URI: https://tazziedave.com/wp-plugins/wysiwyg-custom-products
    55 * Description: Enables a live WYSIWYG preview of custom products where text is edited in text area or text field in woo commerce.
    6  * Version: 1.1.3
     6 * Version: 1.1.4
    77 * Author: Tazziedave
    88 * Author URI: https://tazziedave.com
     
    6262 *
    6363 * @since   1.0.0
    64  * @updated 1.1.3
     64 * @updated 1.1.4
    6565 */
    6666class Wcp_Plugin {
     
    7474     *  Plug in version
    7575     */
    76     const VER = '1.1.3';
     76    const VER = '1.1.4';
    7777    /**
    7878     * Database version. Used in class-plugin to run updates as necessary
  • wysiwyg-custom-products/trunk/admin/class-ajax.php

    r1677949 r1815404  
    2121 *
    2222 * @since      1.0.0
    23  * @updated    1.1.2
     23 * @updated    1.1.4
    2424 */
    2525class Ajax {
     
    6969     *
    7070     * @since   1.0.0
    71      * @updated 1.1.0
     71     * @updated 1.1.4
    7272     */
    7373    public function get_image_attr() {
     
    7878        $image = wp_get_attachment_image_src( $attachmentId, $size );
    7979        // Overriding WP's resizing of image in admin for "editing"
    80         $attributes = wc_get_image_size( $size );
     80        $attributes = wcp_get_image_size( $size, $attachmentId );
    8181        if ( $attributes ) {
    8282            $image['width']  = maybe_get( $attributes, 'width', $image['width'] );
  • wysiwyg-custom-products/trunk/common/class-wp-html-helper.php

    r1603224 r1815404  
    1515 *
    1616 * @since   1.0.1
    17  * @updated 1.1.0
     17 * @updated 1.1.4
    1818 */
    1919
     
    263263     *
    264264     * @since   1.0.8
    265      * @updated 1.1.0
     265     * @updated 1.1.4
    266266     */
    267267    public function svg_sized_img(
     
    273273//      Overriding WP's resizing of image in admin for "editing"
    274274        if ( $forceSize ) {
    275             $attributes = wc_get_image_size( $size );
     275            $attributes = wcp_get_image_size( $size, $attachmentId );
    276276            if ( $attributes ) {
    277277                $image['width']  = maybe_get( $attributes, 'width', $image['width'] );
     
    283283        return $this->svg_img( $image['url'], $image['width'], $image['height'], $classes, $id, $attributes,
    284284            $styles );
     285    }
     286
     287    /** @noinspection MoreThanThreeArgumentsInspection */
     288    /**
     289     * Creates SVG <image ... /> tag getting the correct image and size from the WP size string
     290     * Escapes href
     291     *
     292     * @param int    $attachmentId
     293     * @param string $size
     294     * @param bool   $forceSize Forces image size based on $size with no manipulation by WP for admin editing
     295     * @param string $classes
     296     * @param string $id
     297     * @param array  $attributes
     298     * @param array  $styles
     299     *
     300     * @return null|string
     301     *
     302     * @since   1.1.4
     303     */
     304    public function frontend_svg_sized_img(
     305        $attachmentId, $size, $forceSize = false, $classes = '', $id = '', array $attributes = [],
     306        array $styles = []
     307    ) {
     308        $image = wp_get_attachment_image_src( $attachmentId, $size );
     309
     310        if ( $forceSize ) {
     311            $attributes = wcp_get_image_size( $size );
     312            if ( $attributes ) {
     313                $image['width']  = maybe_get( $attributes, 'width', $image['width'] );
     314                $image['height'] = maybe_get( $attributes, 'height', $image['height'] );
     315            }
     316
     317        }
     318
     319        return $this->svg_img( $image['url'], $image['width'], $image['height'], $classes, $id, $attributes,
     320                               $styles );
    285321    }
    286322
  • wysiwyg-custom-products/trunk/common/utilities.php

    r1812372 r1815404  
    77 *
    88 * @since   1.0.0
    9  * @updated 1.1.3
     9 * @updated 1.1.4
    1010 */
    1111
     
    169169    return '#' . substr( '000000' . dechex( $colorValue ), - 6 );
    170170}
     171
     172/**
     173 * Get an image size by name or defined dimensions. Or use $id to get actual image size.
     174 *
     175 * The returned variable is filtered by woocommerce_get_image_size_{image_size} filter to
     176 * allow 3rd party customisation.
     177 *
     178 * Sizes defined by the theme take priority over settings. Settings are hidden when a theme
     179 * defines sizes.
     180 *
     181 * @param array|string $image_size    Name of the image size to get, or an array of dimensions.
     182 * @param null|int     $attachmentId  image attachment id
     183 *
     184 * @return array Array of dimensions including width, height, and cropping mode. Cropping mode is 0 for no crop, and 1 for hard crop.
     185 *
     186 * @since 1.1.4
     187 */
     188function wcp_get_image_size( $image_size, $attachmentId = null ) {
     189    $size = array(
     190        'width'  => 600,
     191        'height' => 600,
     192        'crop'   => 0,
     193    );
     194
     195    if ((null !== $attachmentId) && \wp_attachment_is_image($attachmentId)) {
     196        $meta = wp_get_attachment_metadata( $attachmentId);
     197        $size['width']  = maybe_get( $meta, 'width', $size['width'] );
     198        $size['height'] = maybe_get( $meta, 'height', $size['height'] );
     199        return $size;
     200    }
     201
     202    return \wc_get_image_size($image_size);
     203}
  • wysiwyg-custom-products/trunk/common/wp-helpers.php

    r1592084 r1815404  
    77 *
    88 * @since   1.0.0
    9  * @updated 1.0.6
     9 * @updated 1.1.4
    1010 */
    1111
     
    394394 *
    395395 * @since   1.0.8
     396 * @updated 1.1.4
    396397 */
    397398function wp_get_attachment_image_src( $attachmentId, $size ) {
     
    399400    if ( ! $image ) {
    400401        $image = [ '', 0, 0, false ];
     402    } elseif (3 === \count( $image)) { // Needed because WooCommerce does not include 'intermediate' parameter
     403        $image[] = false;
    401404    }
    402405
  • wysiwyg-custom-products/trunk/frontend/class-frontend.php

    r1812372 r1815404  
    1919 *
    2020 * @since      1.0.0
    21  * @updated    1.1.3
     21 * @updated    1.1.4
    2222 */
    2323class Frontend {
     
    166166    }
    167167
     168    /** @noinspection MoreThanThreeArgumentsInspection */
    168169    /**
    169170     * Builds SVG html in $this->h
     
    174175     * @param string|null $divId
    175176     * @param string|null $imageId
    176      *
    177      * @since   1.0.0
    178      * @updated 1.1.0
    179      */
    180     private function svg_html( $liveLines, $message = null, $formats = null, $divId = null, $imageId = null ) {
     177     * @param bool        $forceSize
     178     *
     179     * @since   1.0.0
     180     * @updated 1.1.4
     181     */
     182    private function svg_html( $liveLines, $message = null, $formats = null, $divId = null, $imageId = null,
     183                               $forceSize = false
     184    ) {
    181185        $h = $this->h;
    182186        $l = $this->layout;
     
    202206        $h->o_tag( 'g' );
    203207
    204         $h->svg_sized_img( $l->image, $l->size, false, '', 'svg_image' );
     208        $h->frontend_svg_sized_img( $l->image, $l->size, $forceSize, '', 'svg_image' );
    205209
    206210        if ( $formats ) {
     
    291295        $message = $productText ? explode( '|', $productText ) : false;
    292296
    293         $this->svg_html( $liveUpdate, $message, $formats, 'front_svg', 'svg_image' );
     297        $this->svg_html( $liveUpdate, $message, $formats, 'front_svg', 'svg_image', true );
    294298        $h->tag( 'p', $l->getMultiLineReformatMsg(), 'wcp-hidden wcp-lost-text', 'wcp_multiline' );
    295299        $h->tag( 'p', $l->getNumberOfLinesMsg(), 'wcp-hidden wcp-lost-text', 'wcp_too_many_lines' );
  • wysiwyg-custom-products/trunk/readme.txt

    r1812372 r1815404  
    124124
    125125= 1.1.3 =
    126 * Added workaround for changes in woocommerce core functions and image size names.
     126* Added workaround for changes in WooCommerce core functions and image size names.
     127
     128= 1.1.4 =
     129* Fixed bug in image sizing from Admin to Frontend.
     130* Added workaround because WooCommerce returns a different image array size in it's application of the 'wp_get_attachment_image_src' filter.
    127131
    128132== Upgrade Notice ==
    129 Fixed for WooCommerce 3.3.0 changes.
     133Fixed for WooCommerce 3.3.0 changes. Fixed bug that affected image sizing.
    130134
    131135== Creating Layouts - Instructions ==
  • wysiwyg-custom-products/trunk/wysiwyg-custom-products.php

    r1812372 r1815404  
    44 * Plugin URI: https://tazziedave.com/wp-plugins/wysiwyg-custom-products
    55 * Description: Enables a live WYSIWYG preview of custom products where text is edited in text area or text field in woo commerce.
    6  * Version: 1.1.3
     6 * Version: 1.1.4
    77 * Author: Tazziedave
    88 * Author URI: https://tazziedave.com
     
    6262 *
    6363 * @since   1.0.0
    64  * @updated 1.1.3
     64 * @updated 1.1.4
    6565 */
    6666class Wcp_Plugin {
     
    7474     *  Plug in version
    7575     */
    76     const VER = '1.1.3';
     76    const VER = '1.1.4';
    7777    /**
    7878     * Database version. Used in class-plugin to run updates as necessary
Note: See TracChangeset for help on using the changeset viewer.