From a58ea2a51c7ff72fab1e2e31926d7f032df045dc Mon Sep 17 00:00:00 2001 From: Joseph Fusco Date: Wed, 5 Aug 2020 16:13:30 -0400 Subject: [PATCH] Release 2.6.0 --- CHANGELOG.md | 12 ++++ README.md | 29 ++++++++ languages/widen-media.pot | 148 ++++++++++++++++++++++++++------------ lib/Admin.php | 138 ++++++++++++++++++++++++----------- widen-media.php | 2 +- 5 files changed, 243 insertions(+), 86 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1051df6..2c62791 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.6.0] - 2020-08-05 + +### Added + +- New default image sizes. +- New filter, `wm_defined_image_sizes`, that allows users to define custom image sizes from within another plugin or theme. +- Disabled WordPress responsive images (srcset). + +### Fixed + +- Prevent GET/POST from throwing error when dealing with custom post types. + ## [2.5.2] - 2020-02-27 ### Fixed diff --git a/README.md b/README.md index 8dc8199..c515746 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,35 @@ Within the main search page under "Add New", users can toggle "collection" when When searching for a collection, a _Save Collection_ button will be displayed. This button saves the current result page's collection to the metadata of a new post under the `wp_collection` post type. Note that a collection large than 100 assets will only save the 100 assets on the current results page. +## Defining Custom Image Sizes + +This plugin ships with some default image sizes however a filter has been included if you wish to change those defined sizes from within another plugin or theme. + +Example function defining 2 image sizes: + +```php +function filter_defined_image_sizes( $default_image_sizes ) { + $sizes = [ + 'banner-sm' => [ + 'label' => __( 'Small Banner', 'textdomain' ), + 'width' => 820, + 'height' => 312, + ], + 'banner-lg' => [ + 'label' => __( 'Large Banner', 'textdomain' ), + 'width' => 1500, + 'height' => 500, + ], + ]; + + // Uncomment to append sizes to the plugin's already defined sizes. + // $sizes = array_merge( $sizes, $default_image_sizes ); + + return $sizes; +} +add_filter( 'wm_defined_image_sizes', 'filter_defined_image_sizes', 10, 1 ); +``` + ## Plugin API This plugin provides some function to allow other plugins to easly interact with Widen data imported into WordPress as well as the Widen API. diff --git a/languages/widen-media.pot b/languages/widen-media.pot index 1c4fa7e..17a1558 100644 --- a/languages/widen-media.pot +++ b/languages/widen-media.pot @@ -1,23 +1,35 @@ -# Copyright (C) 2019 Masonite +# Copyright (C) 2020 Masonite # This file is distributed under the GPL-2.0+. msgid "" msgstr "" -"Project-Id-Version: Widen Media 2.1.0\n" +"Project-Id-Version: Widen Media 2.6.0\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/widen-media\n" -"POT-Creation-Date: 2019-07-26 20:55:53+00:00\n" +"POT-Creation-Date: 2020-08-05 20:12:55+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" -"PO-Revision-Date: 2019-MO-DA HO:MI+ZONE\n" +"PO-Revision-Date: 2020-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "X-Generator: node-wp-i18n 1.2.3\n" -#: lib/Admin/tiles/image.php:52 +#: lib/Admin/meta-boxes/collection-submit.php:17 +msgid "Name: " +msgstr "" + +#: lib/Admin/meta-boxes/collection-submit.php:20 +msgid "ID: " +msgstr "" + +#: lib/Admin/meta-boxes/collection-submit.php:25 +msgid "Sync Collection" +msgstr "" + +#: lib/Admin/tiles/image.php:47 msgid "View In Media Library" msgstr "" -#: lib/Admin/tiles/image.php:67 +#: lib/Admin/tiles/image.php:62 msgid "Add to Media Library" msgstr "" @@ -35,122 +47,166 @@ msgstr "" msgid "Search Widen Collections" msgstr "" -#: lib/Admin/widen-media.php:36 lib/Admin.php:680 lib/Admin.php:706 +#: lib/Admin/widen-media.php:36 lib/Admin.php:770 lib/Admin.php:796 msgid "Collection" msgstr "" +#: lib/Admin.php:40 +msgid "Widen Media: Thumbnail" +msgstr "" + +#: lib/Admin.php:45 +msgid "Widen Media: Pager" +msgstr "" + +#: lib/Admin.php:50 +msgid "Widen Media: Logo" +msgstr "" + +#: lib/Admin.php:55 +msgid "Widen Media: Icon" +msgstr "" + +#: lib/Admin.php:60 +msgid "Widen Media: Door A" +msgstr "" + +#: lib/Admin.php:65 +msgid "Widen Media: Door B" +msgstr "" + +#: lib/Admin.php:70 +msgid "Widen Media: Glass" +msgstr "" + #: lib/Admin.php:75 +msgid "Widen Media: Slider" +msgstr "" + +#: lib/Admin.php:80 +msgid "Widen Media: Card" +msgstr "" + +#: lib/Admin.php:85 +msgid "Widen Media: Card - Full Size" +msgstr "" + +#: lib/Admin.php:142 msgid "The options below are readonly and can only be set via wp-config.php." msgstr "" -#: lib/Admin.php:87 +#: lib/Admin.php:154 msgid "WIDEN_MEDIA_ACCESS_TOKEN must be defined within wp-config.php." msgstr "" -#: lib/Admin.php:160 +#: lib/Admin.php:316 msgid "Widen Media Library" msgstr "" -#: lib/Admin.php:161 lib/Admin.php:686 +#: lib/Admin.php:317 lib/Admin.php:776 msgid "Add New" msgstr "" -#: lib/Admin.php:198 +#: lib/Admin.php:354 msgid "Settings" msgstr "" -#: lib/Admin.php:666 +#: lib/Admin.php:756 msgid "Direct file uploads are not allowed. Please add media via Widen." msgstr "" -#: lib/Admin.php:679 lib/Admin.php:684 +#: lib/Admin.php:769 lib/Admin.php:774 msgid "Collections" msgstr "" -#: lib/Admin.php:681 +#: lib/Admin.php:771 msgid "Collection Archives" msgstr "" -#: lib/Admin.php:682 +#: lib/Admin.php:772 msgid "Collection Attributes" msgstr "" -#: lib/Admin.php:683 +#: lib/Admin.php:773 msgid "Parent Collection:" msgstr "" -#: lib/Admin.php:685 +#: lib/Admin.php:775 msgid "Add New Collection" msgstr "" -#: lib/Admin.php:687 +#: lib/Admin.php:777 msgid "New Collection" msgstr "" -#: lib/Admin.php:689 +#: lib/Admin.php:779 msgid "Update Collection" msgstr "" -#: lib/Admin.php:690 +#: lib/Admin.php:780 lib/Paginator.php:324 msgid "View Collection" msgstr "" -#: lib/Admin.php:691 +#: lib/Admin.php:781 msgid "View Collections" msgstr "" -#: lib/Admin.php:692 +#: lib/Admin.php:782 msgid "Search Collections" msgstr "" -#: lib/Admin.php:693 +#: lib/Admin.php:783 msgid "Not found" msgstr "" -#: lib/Admin.php:694 +#: lib/Admin.php:784 msgid "Not found in Trash" msgstr "" -#: lib/Admin.php:695 +#: lib/Admin.php:785 msgid "Featured Image" msgstr "" -#: lib/Admin.php:696 +#: lib/Admin.php:786 msgid "Set featured image" msgstr "" -#: lib/Admin.php:697 +#: lib/Admin.php:787 msgid "Remove featured image" msgstr "" -#: lib/Admin.php:698 +#: lib/Admin.php:788 msgid "Use as featured image" msgstr "" -#: lib/Admin.php:699 +#: lib/Admin.php:789 msgid "Insert into collection" msgstr "" -#: lib/Admin.php:700 +#: lib/Admin.php:790 msgid "Uploaded to this collection" msgstr "" -#: lib/Admin.php:701 +#: lib/Admin.php:791 msgid "Collection list" msgstr "" -#: lib/Admin.php:702 +#: lib/Admin.php:792 msgid "Collection list navigation" msgstr "" -#: lib/Admin.php:703 +#: lib/Admin.php:793 msgid "Filter collection list" msgstr "" -#: lib/Admin.php:707 +#: lib/Admin.php:797 msgid "Widen Media Collections" msgstr "" +#: lib/Admin.php:854 +msgid "Publish" +msgstr "" + #: lib/Paginator.php:286 #. translators: %1$s: Total item count for current page, %2$s: Total item #. count, %3$s: Search query @@ -166,35 +222,39 @@ msgstr "" msgid "Search results navigation" msgstr "" -#: lib/Paginator.php:313 +#: lib/Paginator.php:323 +msgid "This collection already exists:" +msgstr "" + +#: lib/Paginator.php:331 msgid "Save Collection" msgstr "" -#: lib/Paginator.php:327 +#: lib/Paginator.php:347 msgid "First page" msgstr "" -#: lib/Paginator.php:340 +#: lib/Paginator.php:360 msgid "Previous page" msgstr "" -#: lib/Paginator.php:347 +#: lib/Paginator.php:367 msgid "Current page" msgstr "" -#: lib/Paginator.php:349 +#: lib/Paginator.php:369 msgid "of" msgstr "" -#: lib/Paginator.php:361 +#: lib/Paginator.php:381 msgid "Next page" msgstr "" -#: lib/Paginator.php:374 +#: lib/Paginator.php:394 msgid "Last page" msgstr "" -#: lib/Widen.php:81 lib/Widen.php:120 lib/Widen.php:160 +#: lib/Widen.php:88 lib/Widen.php:127 lib/Widen.php:167 msgid "An unknown error occurred" msgstr "" @@ -214,12 +274,12 @@ msgstr "" msgid "https://www.masonite.com/" msgstr "" -#: lib/Admin.php:677 +#: lib/Admin.php:767 msgctxt "Post Type General Name" msgid "Collections" msgstr "" -#: lib/Admin.php:678 +#: lib/Admin.php:768 msgctxt "Post Type Singular Name" msgid "Collection" msgstr "" \ No newline at end of file diff --git a/lib/Admin.php b/lib/Admin.php index 92488b0..9c5c9ab 100644 --- a/lib/Admin.php +++ b/lib/Admin.php @@ -31,6 +31,73 @@ public function __construct() { $this->widen = new Widen( self::get_access_token() ); } + /** + * Returns the defined image sizes. + */ + private static function get_defined_image_sizes(): array { + $default_image_sizes = [ + 'wm-thumbnail' => [ + 'label' => __( 'Widen Media: Thumbnail', 'widen-media' ), + 'width' => 500, + 'height' => 500, + ], + 'wm-pager' => [ + 'label' => __( 'Widen Media: Pager', 'widen-media' ), + 'width' => 64, + 'height' => 64, + ], + 'wm-logo' => [ + 'label' => __( 'Widen Media: Logo', 'widen-media' ), + 'width' => 203, + 'height' => 49, + ], + 'wm-icon' => [ + 'label' => __( 'Widen Media: Icon', 'widen-media' ), + 'width' => 103, + 'height' => 103, + ], + 'wm-door-a' => [ + 'label' => __( 'Widen Media: Door A', 'widen-media' ), + 'width' => 125, + 'height' => 333, + ], + 'wm-door-b' => [ + 'label' => __( 'Widen Media: Door B', 'widen-media' ), + 'width' => 216, + 'height' => 454, + ], + 'wm-glass' => [ + 'label' => __( 'Widen Media: Glass', 'widen-media' ), + 'width' => 300, + 'height' => 300, + ], + 'wm-slider' => [ + 'label' => __( 'Widen Media: Slider', 'widen-media' ), + 'width' => 240, + 'height' => 342, + ], + 'wm-card' => [ + 'label' => __( 'Widen Media: Card', 'widen-media' ), + 'width' => 640, + 'height' => 425, + ], + 'wm-card-full-size' => [ + 'label' => __( 'Widen Media: Card - Full Size', 'widen-media' ), + 'width' => 816, + 'height' => 550, + ], + ]; + + /** + * Filter the plugin's defined image sizes. + * + * @param array $default_image_sizes The array of default image sizes. + */ + $defined_image_sizes = apply_filters( 'wm_defined_image_sizes', $default_image_sizes ); + + return $defined_image_sizes; + } + /** * Check to see if we are able to load our plugin's admin scripts & styles. * @@ -93,16 +160,11 @@ public function access_token_setting_cb(): void { * Register our image sizes with WordPress. */ public function register_image_sizes(): void { - add_image_size( 'wm-thumbnail', 500, 500 ); - add_image_size( 'wm-pager', 64, 64 ); - add_image_size( 'wm-logo', 203, 49 ); - add_image_size( 'wm-icon', 103, 103 ); - add_image_size( 'wm-door-a', 125, 333 ); - add_image_size( 'wm-door-b', 216, 454 ); - add_image_size( 'wm-glass', 300, 300 ); - add_image_size( 'wm-slider', 240, 342 ); - add_image_size( 'wm-card', 640, 425 ); - add_image_size( 'wm-card-full-size', 816, 550 ); + $sizes = self::get_defined_image_sizes(); + + foreach ( $sizes as $key => $size ) { + add_image_size( $key, $size['width'], $size['height'] ); + } } /** @@ -113,22 +175,34 @@ public function register_image_sizes(): void { * @param array $sizes The array of available image sizes. */ public function add_selectable_image_sizes( $sizes ): array { - $widen_media_image_sizes = [ - 'wm-thumbnail' => __( 'Widen Media: Thumbnail', 'widen-media' ), - 'wm-pager' => __( 'Widen Media: Pager', 'widen-media' ), - 'wm-logo' => __( 'Widen Media: Logo', 'widen-media' ), - 'wm-icon' => __( 'Widen Media: Icon', 'widen-media' ), - 'wm-door-a' => __( 'Widen Media: Door A', 'widen-media' ), - 'wm-door-b' => __( 'Widen Media: Door B', 'widen-media' ), - 'wm-glass' => __( 'Widen Media: Glass', 'widen-media' ), - 'wm-slider' => __( 'Widen Media: Slider', 'widen-media' ), - 'wm-card' => __( 'Widen Media: Card', 'widen-media' ), - 'wm-card-full-size' => __( 'Widen Media: Full Size Card', 'widen-media' ), - ]; + $defined_image_sizes = self::get_defined_image_sizes(); + $widen_media_image_sizes = []; + + foreach ( $defined_image_sizes as $key => $defined_image_size ) { + $widen_media_image_sizes[ $key ] = $defined_image_size['label']; + } return array_merge( $sizes, $widen_media_image_sizes ); } + /** + * Returns an array with all of the sizes data for a given templated URL. + * + * @param string $templated_url The templated URL from Widen. + */ + private static function get_attachment_sizes( $templated_url ): array { + $defined_sizes = self::get_defined_image_sizes(); + $attachment_sizes = [ + 'full' => Widen::get_size_meta( $templated_url ), + ]; + + foreach ( $defined_sizes as $key => $size ) { + $attachment_sizes[ $key ] = Widen::get_size_meta( $templated_url, $size['width'], $size['height'] ); + } + + return $attachment_sizes; + } + /** * Disable responsive images in WordPress. * @@ -496,41 +570,23 @@ public function add_image_to_library(): void { 'width' => $asset_data['width'], 'height' => $asset_data['height'], 'file' => self::get_widen_url_path( $asset_data['url'] ), - 'sizes' => [ - 'full' => Widen::get_size_meta( $asset_data['templated_url'] ), - 'wm-thumbnail' => Widen::get_size_meta( $asset_data['templated_url'], 500, 500 ), - 'wm-pager' => Widen::get_size_meta( $asset_data['templated_url'], 64, 64 ), - 'wm-logo' => Widen::get_size_meta( $asset_data['templated_url'], 203, 49 ), - 'wm-icon' => Widen::get_size_meta( $asset_data['templated_url'], 103, 103 ), - 'wm-door-a' => Widen::get_size_meta( $asset_data['templated_url'], 125, 333 ), - 'wm-door-b' => Widen::get_size_meta( $asset_data['templated_url'], 216, 454 ), - 'wm-glass' => Widen::get_size_meta( $asset_data['templated_url'], 300, 300 ), - 'wm-slider' => Widen::get_size_meta( $asset_data['templated_url'], 240, 342 ), - 'wm-card' => Widen::get_size_meta( $asset_data['templated_url'], 640, 425 ), - 'wm-card-full-size' => Widen::get_size_meta( $asset_data['templated_url'], 816, 550 ), - ], + 'sizes' => self::get_attachment_sizes( $asset_data['templated_url'] ), ]; wp_update_attachment_metadata( $attachment_id, $attachment_metadata ); /** * Update the attachment's file. - * - * @link https://developer.wordpress.org/reference/functions/update_post_meta/ */ update_post_meta( $attachment_id, '_wp_attached_file', self::get_widen_url_path( $asset_data['url'] ) ); /** * Update the attachment's Alternative Text. - * - * @link https://developer.wordpress.org/reference/functions/update_post_meta/ */ update_post_meta( $attachment_id, '_wp_attachment_image_alt', $asset_data['description'] ); /** * Store the asset's ID from Widen as post_meta. * This is also used throughout this plugin in checking if an image is from Widen. - * - * @link https://developer.wordpress.org/reference/functions/update_post_meta/ */ update_post_meta( $attachment_id, 'widen_media_id', $asset_data['id'] ); diff --git a/widen-media.php b/widen-media.php index d37dad5..3c8bd57 100644 --- a/widen-media.php +++ b/widen-media.php @@ -2,7 +2,7 @@ /** * Plugin Name: Widen Media * Description: Search and add Widen digital assets to your WordPress media library. - * Version: 2.5.2 + * Version: 2.6.0 * Author: Masonite * Author URI: https://www.masonite.com/ * License: GPL-2.0+