From a77181aba87b8af1f0ade4b2ea2206115d68fec9 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Mon, 7 Oct 2024 13:27:26 +0100 Subject: [PATCH 01/18] Update wording so it is clear it is a Cloudinary feature --- php/media/class-global-transformations.php | 6 +++--- .../taxonomy-term-transformation-fields.php | 21 +++++++++++++++++-- ui-definitions/settings-image.php | 8 ++++--- ui-definitions/settings-video.php | 8 ++++--- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/php/media/class-global-transformations.php b/php/media/class-global-transformations.php index 11f169337..b2d0204a1 100644 --- a/php/media/class-global-transformations.php +++ b/php/media/class-global-transformations.php @@ -319,7 +319,7 @@ public function load_preview( $video = false ) { */ public function taxonomy_ordering( $type, $post ) { if ( $this->has_public_taxonomies( $post ) ) { - add_meta_box( 'cld-taxonomy-order', __( 'Categories/Tags transformations', 'cloudinary' ), array( $this, 'render_ordering_box' ), null, 'side', 'core' ); + add_meta_box( 'cld-taxonomy-order', __( 'Cloudinary terms transformations', 'cloudinary' ), array( $this, 'render_ordering_box' ), null, 'side', 'core' ); } } @@ -451,7 +451,7 @@ private function init_taxonomy_manager( $post ) { $out = array(); $out[] = '
'; - $out[] = '

' . esc_html__( 'If you placed custom transformations on categories/tags you may order them below. ', 'cloudinary' ) . ''; + $out[] = '

' . esc_html__( 'If you placed custom transformations on these terms you may order them below. ', 'cloudinary' ) . ''; $out[] = '

'; diff --git a/php/templates/taxonomy-term-transformation-fields.php b/php/templates/taxonomy-term-transformation-fields.php index 02eaf5fa0..20c75383b 100644 --- a/php/templates/taxonomy-term-transformation-fields.php +++ b/php/templates/taxonomy-term-transformation-fields.php @@ -5,14 +5,31 @@ * @package Cloudinary */ +use Cloudinary\Utils; + +$taxonomy_slug = Utils::get_sanitized_text( 'taxonomy' ); +$tax_object = get_taxonomy( $taxonomy_slug ); + +// We should be in the context of a term edit screen. +if ( ! $tax_object instanceof WP_Taxonomy ) { + return; +} + +$label = $tax_object->labels->singular_name; ?> taxonomy_fields as $context => $set ) : ?>

diff --git a/ui-definitions/settings-image.php b/ui-definitions/settings-image.php index 21600fa7b..e83c12be8 100644 --- a/ui-definitions/settings-image.php +++ b/ui-definitions/settings-image.php @@ -149,16 +149,18 @@ array( 'type' => 'text', 'slug' => 'image_freeform', - 'title' => __( 'Additional image transformations', 'cloudinary' ), + 'title' => __( 'Cloudinary global transformations', 'cloudinary' ), 'default' => '', 'tooltip_text' => sprintf( // translators: The link to transformation reference. __( - 'A set of additional transformations to apply to all images. Specify your transformations using Cloudinary URL transformation syntax. See %1$sreference%2$s for all available transformations and syntax.', + 'A set of additional transformations to apply to all images. Specify your transformations using Cloudinary URL transformation syntax. See %1$sreference%2$s for all available transformations and syntax.%3$s* The Cloudinary global transformations are only applied to assets managed in the Media Library%4$s.', 'cloudinary' ), '', - '' + '', + '

', + '' ), 'link' => array( 'text' => __( 'See examples', 'cloudinary' ), diff --git a/ui-definitions/settings-video.php b/ui-definitions/settings-video.php index 238b18b47..1332f1900 100644 --- a/ui-definitions/settings-video.php +++ b/ui-definitions/settings-video.php @@ -235,16 +235,18 @@ array( 'type' => 'text', 'slug' => 'video_freeform', - 'title' => __( 'Additional video transformations', 'cloudinary' ), + 'title' => __( 'Cloudinary global transformations', 'cloudinary' ), 'default' => '', 'tooltip_text' => sprintf( // translators: The link to transformation reference. __( - 'A set of additional transformations to apply to all videos. Specify your transformations using Cloudinary URL transformation syntax. See %1$sreference%2$s for all available transformations and syntax.', + 'A set of additional transformations to apply to all videos. Specify your transformations using Cloudinary URL transformation syntax. See %1$sreference%2$s for all available transformations and syntax.%3$s* The Cloudinary global transformations are only applied to assets managed in the Media Library%4$s.', 'cloudinary' ), '', - '' + '', + '

', + '' ), 'link' => array( 'text' => __( 'See examples', 'cloudinary' ), From ab796a62f9ec2448846b66a5b8dc9cebec484f06 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Thu, 10 Oct 2024 16:00:38 +0100 Subject: [PATCH 02/18] Update wording on term trasnformations --- ui-definitions/settings-image.php | 11 ++++++++++- ui-definitions/settings-video.php | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ui-definitions/settings-image.php b/ui-definitions/settings-image.php index e83c12be8..954907dfc 100644 --- a/ui-definitions/settings-image.php +++ b/ui-definitions/settings-image.php @@ -5,8 +5,17 @@ * @package Cloudinary */ +use Cloudinary\Utils; use function Cloudinary\get_plugin_instance; +$transformations_title = __( 'Cloudinary global transformations', 'cloudinary' ); + +$taxonomy_slug = Utils::get_sanitized_text( 'taxonomy' ); + +if ( $taxonomy_slug ) { + $transformations_title = __( 'Term transformations', 'cloudinary' ); +} + $settings = array( array( 'type' => 'panel', @@ -149,7 +158,7 @@ array( 'type' => 'text', 'slug' => 'image_freeform', - 'title' => __( 'Cloudinary global transformations', 'cloudinary' ), + 'title' => $transformations_title, 'default' => '', 'tooltip_text' => sprintf( // translators: The link to transformation reference. diff --git a/ui-definitions/settings-video.php b/ui-definitions/settings-video.php index 1332f1900..e6e7cd744 100644 --- a/ui-definitions/settings-video.php +++ b/ui-definitions/settings-video.php @@ -5,8 +5,17 @@ * @package Cloudinary */ +use Cloudinary\Utils; use function Cloudinary\get_plugin_instance; +$transformations_title = __( 'Cloudinary global transformations', 'cloudinary' ); + +$taxonomy_slug = Utils::get_sanitized_text( 'taxonomy' ); + +if ( $taxonomy_slug ) { + $transformations_title = __( 'Term transformations', 'cloudinary' ); +} + $settings = array( array( 'type' => 'panel', @@ -235,7 +244,7 @@ array( 'type' => 'text', 'slug' => 'video_freeform', - 'title' => __( 'Cloudinary global transformations', 'cloudinary' ), + 'title' => $transformations_title, 'default' => '', 'tooltip_text' => sprintf( // translators: The link to transformation reference. From a47ea0037cab2031539230458a597fd5fce427b4 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Tue, 15 Oct 2024 16:18:37 +0100 Subject: [PATCH 03/18] When on read only mode, do not assume that the checkbox is checked --- php/ui/component/class-on-off.php | 5 +++-- ui-definitions/settings-image.php | 3 ++- ui-definitions/settings-video.php | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/php/ui/component/class-on-off.php b/php/ui/component/class-on-off.php index f36304fe7..fe6beff79 100644 --- a/php/ui/component/class-on-off.php +++ b/php/ui/component/class-on-off.php @@ -123,8 +123,9 @@ protected function shadow( $struct ) { $struct = $this->get_part( 'input' ); $struct['attributes']['type'] = 'checkbox'; $struct['attributes']['disabled'] = 'disabled'; - $struct['attributes']['checked'] = 'checked'; - $struct['attributes']['type'] = 'checkbox'; + if ( 'on' === $this->setting->get_value() ) { + $struct['attributes']['checked'] = 'checked'; + } } return $struct; diff --git a/ui-definitions/settings-image.php b/ui-definitions/settings-image.php index 954907dfc..4a46a88d8 100644 --- a/ui-definitions/settings-image.php +++ b/ui-definitions/settings-image.php @@ -55,7 +55,8 @@ 'data-context' => 'image', ), 'readonly' => static function () { - return ! get_plugin_instance()->get_component( 'storage' )->is_local_full(); + $plugin = get_plugin_instance(); + return 'on' === $plugin->settings->get_value( 'image_delivery' ) && ! $plugin->get_component( 'storage' )->is_local_full(); }, 'readonly_message' => sprintf( // translators: %s is a link to the storage settings page. diff --git a/ui-definitions/settings-video.php b/ui-definitions/settings-video.php index e6e7cd744..6c70e81c9 100644 --- a/ui-definitions/settings-video.php +++ b/ui-definitions/settings-video.php @@ -55,7 +55,8 @@ 'data-context' => 'video', ), 'readonly' => static function () { - return ! get_plugin_instance()->get_component( 'storage' )->is_local_full(); + $plugin = get_plugin_instance(); + return 'on' === $plugin->settings->get_value( 'video_delivery' ) && ! $plugin->get_component( 'storage' )->is_local_full(); }, 'readonly_message' => sprintf( // translators: %s is a link to the storage settings page. From 28eb5315a11e428fc84610dd0a58862765de9d47 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Tue, 15 Oct 2024 19:04:58 +0100 Subject: [PATCH 04/18] Wrap `rest_url`, `site_url` and `home_url` so that we can filter these securely --- php/cache/class-file-system.php | 3 +- php/class-assets.php | 20 ++---- php/class-cache.php | 4 +- php/class-connect.php | 4 +- php/class-deactivation.php | 2 +- php/class-delivery.php | 2 +- php/class-extensions.php | 2 +- php/class-media-library.php | 2 +- php/class-media.php | 8 +-- php/class-rest-api.php | 2 +- php/class-sync.php | 2 +- php/class-utils.php | 88 +++++++++++++++++++++++- php/connect/class-api.php | 2 +- php/delivery/class-lazy-load.php | 2 +- php/ui/class-state.php | 3 +- php/ui/component/class-asset.php | 11 +-- php/ui/component/class-notice.php | 2 +- php/ui/component/class-progress-sync.php | 3 +- ui-definitions/components/wizard.php | 4 +- 19 files changed, 122 insertions(+), 44 deletions(-) diff --git a/php/cache/class-file-system.php b/php/cache/class-file-system.php index 7ba629e42..0baaf610a 100644 --- a/php/cache/class-file-system.php +++ b/php/cache/class-file-system.php @@ -8,6 +8,7 @@ namespace Cloudinary\Cache; use Cloudinary\Plugin; +use Cloudinary\Utils; /** * Class File System. @@ -62,7 +63,7 @@ protected function setup_paths() { content_url() => $this->wp_file_system->wp_content_dir(), admin_url() => $this->wp_file_system->abspath() . 'wp-admin/', includes_url() => $this->wp_file_system->abspath() . 'wp-includes/', - home_url() => $this->wp_file_system->abspath(), + Utils::home_url() => $this->wp_file_system->abspath(), ); foreach ( $paths as $url => $path ) { $this->paths[ trailingslashit( $url ) ] = trailingslashit( $path ); diff --git a/php/class-assets.php b/php/class-assets.php index c37e6db00..3884586ac 100644 --- a/php/class-assets.php +++ b/php/class-assets.php @@ -433,19 +433,7 @@ public function activate_parent( $url ) { * @return string */ public function clean_path( $path ) { - /** - * Filter the home url. - * - * @hook cloudinary_home_url - * @since 3.2.0 - * - * @param $home_url {string} The home url. - * - * @return {string} - */ - $home_url = apply_filters( 'cloudinary_home_url', home_url() ); - - $home = Utils::clean_url( trailingslashit( $home_url ) ); + $home = Utils::clean_url( trailingslashit( Utils::home_url() ) ); $path = str_replace( $home, '', Utils::clean_url( $path ) ); if ( empty( Utils::pathinfo( $path, PATHINFO_EXTENSION ) ) ) { $path = urldecode( trailingslashit( $path ) ); @@ -629,7 +617,7 @@ public function get_asset_storage_folder( $url_id ) { $url_id = $this->media->local_url( $url_id ); } $url = $this->clean_path( $url_id ); - $domain = wp_parse_url( home_url(), PHP_URL_HOST ); + $domain = wp_parse_url( Utils::home_url(), PHP_URL_HOST ); $folder = wp_normalize_path( dirname( trim( $url, './' ) ) ); if ( ! empty( $domain ) ) { $folder = path_join( $domain, $folder ); @@ -1101,8 +1089,8 @@ protected function create_asset( $url, $parent_id ) { require_once ABSPATH . 'wp-admin/includes/image.php'; require_once ABSPATH . 'wp-admin/includes/media.php'; - $full_url = urldecode( home_url() . wp_parse_url( $url, PHP_URL_PATH ) ); - $file_path = urldecode( str_replace( home_url(), untrailingslashit( ABSPATH ), $full_url ) ); + $full_url = urldecode( Utils::home_url() . wp_parse_url( $url, PHP_URL_PATH ) ); + $file_path = urldecode( str_replace( Utils::home_url(), untrailingslashit( ABSPATH ), $full_url ) ); if ( ! file_exists( $file_path ) ) { return false; } diff --git a/php/class-cache.php b/php/class-cache.php index 4e5257ef2..f79ceba45 100644 --- a/php/class-cache.php +++ b/php/class-cache.php @@ -102,7 +102,7 @@ public function __construct( Plugin $plugin ) { parent::__construct( $plugin ); $this->file_system = new File_System( $plugin ); if ( $this->file_system->enabled() ) { - $this->cache_folder = wp_parse_url( get_site_url(), PHP_URL_HOST ); + $this->cache_folder = wp_parse_url( Utils::site_url(), PHP_URL_HOST ); $this->media = $this->plugin->get_component( 'media' ); $this->connect = $this->plugin->get_component( 'connect' ); $this->api = $this->plugin->get_component( 'api' ); @@ -239,7 +239,7 @@ protected function register_hooks() { * @return array */ public function prevent_caching_internal_requests( $args, $url ) { - $home = strtolower( wp_parse_url( home_url(), PHP_URL_HOST ) ); + $home = strtolower( wp_parse_url( Utils::home_url(), PHP_URL_HOST ) ); $request = strtolower( wp_parse_url( $url, PHP_URL_HOST ) ); if ( $home === $request ) { $args['headers']['x-cld-cache'] = time(); diff --git a/php/class-connect.php b/php/class-connect.php index beb0f8d1b..27cd4dbe4 100644 --- a/php/class-connect.php +++ b/php/class-connect.php @@ -215,7 +215,7 @@ public function rest_save_wizard( WP_REST_Request $request ) { if ( ! empty( $url ) ) { // Warm the last uploaded items in the media library. wp_safe_remote_request( - rest_url( 'wp/v2/media' ), + Utils::rest_url( 'wp/v2/media' ), array( 'timeout' => 0.1, 'blocking' => false, @@ -1023,7 +1023,7 @@ public static function test_rest_api_connectivity() { ), ); - $url = rest_url( REST_API::BASE . '/test_rest_api' ); + $url = Utils::rest_url( REST_API::BASE . '/test_rest_api' ); $response = wp_safe_remote_get( $url, $args ); if ( is_wp_error( $response ) ) { diff --git a/php/class-deactivation.php b/php/class-deactivation.php index 58064afd9..ebdc269c7 100644 --- a/php/class-deactivation.php +++ b/php/class-deactivation.php @@ -334,7 +334,7 @@ public function enqueue_scripts() { 'cloudinary-deactivation', 'CLD_Deactivate', array( - 'endpoint' => rest_url( REST_API::BASE . '/' . self::$internal_endpoint ), + 'endpoint' => Utils::rest_url( REST_API::BASE . '/' . self::$internal_endpoint ), 'nonce' => wp_create_nonce( 'wp_rest' ), ) ); diff --git a/php/class-delivery.php b/php/class-delivery.php index 19f8bcd03..d0be263e8 100644 --- a/php/class-delivery.php +++ b/php/class-delivery.php @@ -1589,7 +1589,7 @@ protected function is_allowed_type( $ext ) { public function validate_url( $url ) { static $home; if ( ! $home ) { - $home = wp_parse_url( home_url( '/' ) ); + $home = wp_parse_url( Utils::home_url( '/' ) ); } $parts = wp_parse_url( $url ); if ( empty( $parts['host'] ) ) { diff --git a/php/class-extensions.php b/php/class-extensions.php index 37b7eb423..22099f4df 100644 --- a/php/class-extensions.php +++ b/php/class-extensions.php @@ -249,7 +249,7 @@ public function register_extensions() { */ public function setup() { $data = array( - 'url' => rest_url( REST_API::BASE . '/extension' ), + 'url' => Utils::rest_url( REST_API::BASE . '/extension' ), 'nonce' => wp_create_nonce( 'wp_rest' ), ); foreach ( $this->settings->get_settings() as $setting ) { diff --git a/php/class-media-library.php b/php/class-media-library.php index 8cdf26bf2..2241995ef 100644 --- a/php/class-media-library.php +++ b/php/class-media-library.php @@ -81,7 +81,7 @@ public function enqueue_assets() { wp_enqueue_script( 'cloudinary' ); $params = array( - 'fetch_url' => rest_url( REST_API::BASE . '/asset' ), + 'fetch_url' => Utils::rest_url( REST_API::BASE . '/asset' ), 'nonce' => wp_create_nonce( 'wp_rest' ), ); diff --git a/php/class-media.php b/php/class-media.php index 209a5b1c4..328300720 100644 --- a/php/class-media.php +++ b/php/class-media.php @@ -329,14 +329,14 @@ public function is_media( $attachment_id ) { * @return bool */ public function is_local_media( $attachment_id ) { - $local_host = wp_parse_url( get_site_url(), PHP_URL_HOST ); + $local_host = wp_parse_url( Utils::site_url(), PHP_URL_HOST ); $guid = get_the_guid( $attachment_id ); // Maybe GUID is a path. if ( ! filter_var( $guid, FILTER_VALIDATE_URL ) ) { - $url = home_url( $guid ); + $url = Utils::home_url( $guid ); if ( $this->maybe_file_exist_in_url( $url ) ) { - $guid = home_url( $guid ); + $guid = Utils::home_url( $guid ); } } @@ -2270,7 +2270,7 @@ public function down_sync_asset() { $asset = $this->get_asset_payload(); // Set a base array for pulling an asset if needed. $base_return = array( - 'fetch' => rest_url( REST_API::BASE . '/asset' ), + 'fetch' => Utils::rest_url( REST_API::BASE . '/asset' ), 'uploading' => true, 'src' => $asset['src'], 'url' => $asset['url'], diff --git a/php/class-rest-api.php b/php/class-rest-api.php index c4bfa63d5..3d70b8bcb 100644 --- a/php/class-rest-api.php +++ b/php/class-rest-api.php @@ -79,7 +79,7 @@ public static function rest_can_connect() { */ public function background_request( $endpoint, $params = array(), $method = 'POST' ) { - $url = rest_url( static::BASE . '/' . $endpoint ); + $url = Utils::rest_url( static::BASE . '/' . $endpoint ); // Setup a call for a background sync. $params['nonce'] = wp_create_nonce( 'wp_rest' ); $args = array( diff --git a/php/class-sync.php b/php/class-sync.php index 0ba1d8e9e..4ec29f346 100644 --- a/php/class-sync.php +++ b/php/class-sync.php @@ -144,7 +144,7 @@ public function __construct( Plugin $plugin ) { public function enqueue_assets() { if ( $this->plugin->settings->get_param( 'connected' ) ) { $data = array( - 'restUrl' => esc_url_raw( rest_url() ), + 'restUrl' => esc_url_raw( Utils::rest_url() ), 'nonce' => wp_create_nonce( 'wp_rest' ), ); wp_add_inline_script( 'cloudinary', 'var cloudinaryApi = ' . wp_json_encode( $data ), 'before' ); diff --git a/php/class-utils.php b/php/class-utils.php index 12735c825..42b036863 100644 --- a/php/class-utils.php +++ b/php/class-utils.php @@ -570,7 +570,7 @@ public static function is_rest_api() { } if ( ! $is ) { // Fallback if rest engine is not setup yet. - $rest_base = wp_parse_url( rest_url( '/' ), PHP_URL_PATH ); + $rest_base = wp_parse_url( static::rest_url( '/' ), PHP_URL_PATH ); $request_uri = filter_input( INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL ); $is = strpos( $request_uri, $rest_base ) === 0; } @@ -1181,4 +1181,90 @@ public static function get_media_context( $attachment_id = null ) { return sanitize_key( $context ); } + + /** + * Get the home URL. + * + * @param string $path The path to be appended to the home URL. + * @param string $scheme The scheme to give the home URL context. Accepts 'http', 'https', or 'relative'. + * + * @return string + */ + public static function home_url( $path = '', $scheme = null ) { + $blog_id = null; + if ( is_multisite() ) { + $blog_id = get_current_blog_id(); + } + $home_url = get_home_url( $blog_id, $path, $scheme ); + + /** + * Filter the home url. + * + * @hook cloudinary_home_url + * @since 3.2.0 + * + * @param $home_url {string} The home url. + * @param $path {string} The path to be appended to the home URL. + * @param $scheme {string} The scheme to give the home URL context. Accepts 'http', 'https', or 'relative'. + * + * @return {string} + */ + return apply_filters( 'cloudinary_home_url', $home_url, $path, $scheme ); + } + + /** + * Get the site URL. + * + * @param string $path The path to be appended to the site URL. + * @param string $scheme The scheme to give the site URL context. Accepts 'http', 'https', or 'relative'. + * + * @return string + */ + public static function site_url( $path = '', $scheme = null ) { + $blog_id = null; + if ( is_multisite() ) { + $blog_id = get_current_blog_id(); + } + $site_url = get_site_url( $blog_id, $path, $scheme ); + + /** + * Filter the site URL. + * + * @hook cloudinary_site_url + * @since 3.2.2 + * + * @param $site_url {string} The site URL. + * @param $path {string} The path to be appended to the site URL. + * @param $scheme {string} The scheme to give the site URL context. Accepts 'http', 'https', or 'relative'. + * + * @return {string} + */ + return apply_filters( 'cloudinary_site_url', $site_url, $path, $scheme ); + } + + /** + * Get the rest URL. + * + * @param string $path The path to be appended to the rest URL. + * @param string $scheme The scheme to give the rest URL context. Accepts 'http', 'https', or 'relative'. + * + * @return string + */ + public static function rest_url( $path = '', $scheme = null ) { + $rest_url = rest_url( $path, $scheme ); + + /** + * Filter the rest url. + * + * @hook cloudinary_rest_url + * @since 3.2.2 + * + * @param $rest_url {string} The rest url. + * @param $path {string} The path to be appended to the rest URL. + * @param $scheme {string} The scheme to give the rest URL context. Accepts 'http', 'https', or 'relative'. + * + * @return {string} + */ + return apply_filters( 'cloudinary_rest_url', $rest_url, $path, $scheme ); + } } diff --git a/php/connect/class-api.php b/php/connect/class-api.php index b348f1eae..e8d8ff3de 100644 --- a/php/connect/class-api.php +++ b/php/connect/class-api.php @@ -984,7 +984,7 @@ protected static function get_hostname( $upload_prefix ) { private function call( $url, $args = array(), $method = 'get' ) { $args['method'] = strtoupper( $method ); $args['user-agent'] = 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ) . ' (' . $this->plugin_version . ')'; - $args['headers']['referer'] = get_site_url(); + $args['headers']['referer'] = Utils::site_url(); if ( 'GET' === $args['method'] ) { $url = 'https://' . $this->credentials['api_key'] . ':' . $this->credentials['api_secret'] . '@' . $url; } else { diff --git a/php/delivery/class-lazy-load.php b/php/delivery/class-lazy-load.php index 42d687188..92b2a0c9e 100644 --- a/php/delivery/class-lazy-load.php +++ b/php/delivery/class-lazy-load.php @@ -327,7 +327,7 @@ public function add_features( $tag_element ) { $loader = 'null;'; if ( ! $has_loader && Utils::is_frontend_ajax() ) { $has_loader = true; - $url = add_query_arg( 'cloudinary_lazy_load_loader', true, trailingslashit( home_url() ) ); + $url = add_query_arg( 'cloudinary_lazy_load_loader', true, trailingslashit( Utils::home_url() ) ); $loader = 'document.body.appendChild(document.createElement(\'script\')).src=\'' . $url . '\';this.onload=null;'; } // Since we're appending to the onload, check it isn't already in, as it may run twice i.e full page caching. diff --git a/php/ui/class-state.php b/php/ui/class-state.php index 9f5c56ea5..a7f070649 100644 --- a/php/ui/class-state.php +++ b/php/ui/class-state.php @@ -11,6 +11,7 @@ use Cloudinary\REST_API; use Cloudinary\Settings; use Cloudinary\UI; +use Cloudinary\Utils; use function Cloudinary\get_plugin_instance; /** @@ -75,7 +76,7 @@ public function __construct( Plugin $plugin ) { * Setup the state. */ public function setup_state() { - $url = rest_url( REST_API::BASE . '/ui-state' ); + $url = Utils::rest_url( REST_API::BASE . '/ui-state' ); $this->plugin->add_script_data( 'stateURL', $url ); $this->plugin->add_script_data( 'stateNonce', $this->nonce ); $this->state = get_user_meta( $this->user_id, self::STATE_KEY, true ); diff --git a/php/ui/component/class-asset.php b/php/ui/component/class-asset.php index 60cc003f7..be564c505 100644 --- a/php/ui/component/class-asset.php +++ b/php/ui/component/class-asset.php @@ -10,6 +10,7 @@ use Cloudinary\REST_API; use Cloudinary\Assets; use Cloudinary\UI\Component; +use Cloudinary\Utils; use function Cloudinary\get_plugin_instance; use Cloudinary\Settings\Setting; @@ -262,11 +263,11 @@ public function enqueue_scripts() { protected function pre_render() { $plugin = get_plugin_instance(); $export = array( - 'update_url' => rest_url( REST_API::BASE . '/disable_cache_items' ), - 'fetch_url' => rest_url( REST_API::BASE . '/show_cache' ), - 'purge_url' => rest_url( REST_API::BASE . '/purge_cache' ), - 'purge_all' => rest_url( REST_API::BASE . '/purge_all' ), - 'save_url' => rest_url( REST_API::BASE . '/save_asset' ), + 'update_url' => Utils::rest_url( REST_API::BASE . '/disable_cache_items' ), + 'fetch_url' => Utils::rest_url( REST_API::BASE . '/show_cache' ), + 'purge_url' => Utils::rest_url( REST_API::BASE . '/purge_cache' ), + 'purge_all' => Utils::rest_url( REST_API::BASE . '/purge_all' ), + 'save_url' => Utils::rest_url( REST_API::BASE . '/save_asset' ), 'nonce' => wp_create_nonce( 'wp_rest' ), ); wp_add_inline_script( 'cloudinary', 'var CLDASSETS = ' . wp_json_encode( $export ), 'before' ); diff --git a/php/ui/component/class-notice.php b/php/ui/component/class-notice.php index 892723648..2f06da606 100644 --- a/php/ui/component/class-notice.php +++ b/php/ui/component/class-notice.php @@ -115,7 +115,7 @@ public function render( $echo = false ) { // Output notice endpoint data only if a dismissible notice has been shown. if ( $this->setting->get_option_parent()->has_param( 'dismissible_notice' ) && ! $this->setting->get_option_parent()->has_param( 'notice_scripts' ) ) { $args = array( - 'url' => rest_url( REST_API::BASE . '/dismiss_notice' ), + 'url' => Utils::rest_url( REST_API::BASE . '/dismiss_notice' ), 'nonce' => wp_create_nonce( 'wp_rest' ), ); wp_add_inline_script( 'cloudinary', 'var CLDIS = ' . wp_json_encode( $args ), 'before' ); diff --git a/php/ui/component/class-progress-sync.php b/php/ui/component/class-progress-sync.php index d92263b52..2415f822f 100644 --- a/php/ui/component/class-progress-sync.php +++ b/php/ui/component/class-progress-sync.php @@ -8,6 +8,7 @@ namespace Cloudinary\UI\Component; use Cloudinary\REST_API; +use Cloudinary\Utils; /** * Ring Component to render components only. @@ -33,7 +34,7 @@ class Progress_Sync extends Progress_Ring { protected function wrap( $struct ) { $struct = parent::wrap( $struct ); if ( true === $this->setting->get_param( 'poll' ) ) { - $struct['attributes']['data-url'] = rest_url( REST_API::BASE . '/stats' ); + $struct['attributes']['data-url'] = Utils::rest_url( REST_API::BASE . '/stats' ); $struct['attributes']['data-poll'] = true; } diff --git a/ui-definitions/components/wizard.php b/ui-definitions/components/wizard.php index 6e76501d4..832cd6c37 100644 --- a/ui-definitions/components/wizard.php +++ b/ui-definitions/components/wizard.php @@ -26,8 +26,8 @@ // Export settings. $export_data = array( - 'testURL' => rest_url( REST_API::BASE . '/test_connection' ), - 'saveURL' => rest_url( REST_API::BASE . '/save_wizard' ), + 'testURL' => Utils::rest_url( REST_API::BASE . '/test_connection' ), + 'saveURL' => Utils::rest_url( REST_API::BASE . '/save_wizard' ), 'saveNonce' => wp_create_nonce( 'wp_rest' ), 'config' => array( 'tab' => $current_tab, From e4063fab3bd15d514057b28ac175aaaec288dbc3 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Mon, 7 Oct 2024 17:44:37 +0100 Subject: [PATCH 05/18] Do not add the analytics argument on admin ajax requests --- php/class-media.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/php/class-media.php b/php/class-media.php index 328300720..940cc0602 100644 --- a/php/class-media.php +++ b/php/class-media.php @@ -1428,6 +1428,13 @@ public function cloudinary_url( $attachment_id, $size = array(), $transformation */ $url = apply_filters( 'cloudinary_converted_url', $url, $attachment_id, $pre_args ); + // Early bail for admin AJAX requests. + if ( defined( 'DOING_AJAX' ) && DOING_AJAX && is_admin() ) { + $cache[ $key ] = $url; + + return $cache[ $key ]; + } + // Add Cloudinary analytics. $cache[ $key ] = add_query_arg( array( From a349b7b8c15a170d97914c3b222f35da0f7ee10e Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Mon, 21 Oct 2024 17:59:25 +0100 Subject: [PATCH 06/18] Bump plugin version --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index 0444f3207..768adf03d 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -3.2.1 \ No newline at end of file +3.2.2-build-1 \ No newline at end of file From 6c50e9e5b49fe6b2cf82795691fa571659f6abad Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Mon, 21 Oct 2024 18:00:37 +0100 Subject: [PATCH 07/18] Update translations template --- languages/cloudinary.pot | 286 ++++++++++++++++++++------------------- 1 file changed, 145 insertions(+), 141 deletions(-) diff --git a/languages/cloudinary.pot b/languages/cloudinary.pot index 64adbc9a3..c86fe2e9d 100644 --- a/languages/cloudinary.pot +++ b/languages/cloudinary.pot @@ -4,7 +4,7 @@ msgid "" msgstr "" "Project-Id-Version: Cloudinary STABLETAG\n" "Report-Msgid-Bugs-To: https://github.com/cloudinary/cloudinary_wordpress\n" -"POT-Creation-Date: 2024-09-18 11:55:33+00:00\n" +"POT-Creation-Date: 2024-10-21 17:00:00+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -63,11 +63,11 @@ msgstr[1] "" msgid "No items found." msgstr "" -#: php/cache/class-cache-point.php:962 php/class-assets.php:1144 +#: php/cache/class-cache-point.php:962 php/class-assets.php:1132 msgid "Cloudinary Asset" msgstr "" -#: php/cache/class-cache-point.php:963 php/class-assets.php:1145 +#: php/cache/class-cache-point.php:963 php/class-assets.php:1133 msgid "Post type to represent a non-media library asset." msgstr "" @@ -87,114 +87,114 @@ msgstr "" msgid "Enable Cloudinary status" msgstr "" -#: php/class-assets.php:699 +#: php/class-assets.php:687 msgid "Caching" msgstr "" -#: php/class-assets.php:710 +#: php/class-assets.php:698 msgid "Creating shadow assets" msgstr "" -#: php/class-assets.php:721 +#: php/class-assets.php:709 msgid "Updating asset storage" msgstr "" -#: php/class-assets.php:1206 +#: php/class-assets.php:1194 msgid "Additional Asset Sync Settings" msgstr "" -#: php/class-assets.php:1226 +#: php/class-assets.php:1214 msgid "Additional asset sync settings" msgstr "" -#: php/class-assets.php:1227 +#: php/class-assets.php:1215 msgid "" "Enabling additional asset syncing will sync the toggled assets with " "Cloudinary to make use of advanced optimization and CDN delivery " "functionality." msgstr "" -#: php/class-assets.php:1228 +#: php/class-assets.php:1216 msgid "Enable additional asset syncing" msgstr "" -#: php/class-assets.php:1267 +#: php/class-assets.php:1255 msgid "External Asset Sync Settings" msgstr "" -#: php/class-assets.php:1292 php/class-cache.php:615 +#: php/class-assets.php:1280 php/class-cache.php:615 msgid "Plugin" msgstr "" -#: php/class-assets.php:1328 php/class-cache.php:792 +#: php/class-assets.php:1316 php/class-cache.php:792 msgid "Plugins" msgstr "" -#: php/class-assets.php:1346 php/class-cache.php:809 +#: php/class-assets.php:1334 php/class-cache.php:809 msgid "Deliver assets from all plugin folders" msgstr "" -#: php/class-assets.php:1378 php/class-cache.php:652 +#: php/class-assets.php:1366 php/class-cache.php:652 msgid "Theme" msgstr "" -#: php/class-assets.php:1410 php/class-cache.php:843 +#: php/class-assets.php:1398 php/class-cache.php:843 msgid "Themes" msgstr "" -#: php/class-assets.php:1428 php/class-cache.php:860 +#: php/class-assets.php:1416 php/class-cache.php:860 msgid "Deliver all assets from active theme." msgstr "" -#: php/class-assets.php:1453 php/class-assets.php:1488 php/class-cache.php:684 +#: php/class-assets.php:1441 php/class-assets.php:1476 php/class-cache.php:684 #: php/class-cache.php:895 msgid "WordPress" msgstr "" -#: php/class-assets.php:1462 php/class-cache.php:668 +#: php/class-assets.php:1450 php/class-cache.php:668 msgid "WordPress Admin" msgstr "" -#: php/class-assets.php:1469 php/class-cache.php:675 +#: php/class-assets.php:1457 php/class-cache.php:675 msgid "WordPress Includes" msgstr "" -#: php/class-assets.php:1506 php/class-cache.php:912 +#: php/class-assets.php:1494 php/class-cache.php:912 msgid "Deliver all assets from WordPress core." msgstr "" -#: php/class-assets.php:1532 php/class-assets.php:1558 php/class-cache.php:708 +#: php/class-assets.php:1520 php/class-assets.php:1546 php/class-cache.php:708 #: php/class-cache.php:947 msgid "Content" msgstr "" -#: php/class-assets.php:1539 php/class-cache.php:699 +#: php/class-assets.php:1527 php/class-cache.php:699 msgid "Uploads" msgstr "" -#: php/class-assets.php:1576 php/class-cache.php:964 +#: php/class-assets.php:1564 php/class-cache.php:964 msgid "Deliver all content assets from WordPress Media Library." msgstr "" -#: php/class-assets.php:1600 +#: php/class-assets.php:1588 msgid "Enable external assets" msgstr "" -#: php/class-assets.php:1601 +#: php/class-assets.php:1589 msgid "" "Enabling external assets allows you to sync assets from specific external " "sources with Cloudinary." msgstr "" -#: php/class-assets.php:1611 +#: php/class-assets.php:1599 msgid "Domains for each external source." msgstr "" -#: php/class-assets.php:1614 +#: php/class-assets.php:1602 msgid "Enter a domain" msgstr "" -#: php/class-assets.php:1615 +#: php/class-assets.php:1603 msgid "Press ENTER or SPACE or type comma or tab to continue." msgstr "" @@ -513,7 +513,7 @@ msgid "" "WordPress." msgstr "" -#: php/class-media.php:2049 +#: php/class-media.php:2057 msgid "Import" msgstr "" @@ -521,43 +521,43 @@ msgstr "" msgid "Cloudinary" msgstr "" -#: php/class-media.php:2405 +#: php/class-media.php:2413 msgid "The delivery for this asset is disabled." msgstr "" -#: php/class-media.php:2409 +#: php/class-media.php:2417 msgid "Not syncable. This is an external media." msgstr "" -#: php/class-media.php:2413 +#: php/class-media.php:2421 msgid "This media is Fetch type." msgstr "" -#: php/class-media.php:2417 +#: php/class-media.php:2425 msgid "This media is Sprite type." msgstr "" -#: php/class-media.php:2427 +#: php/class-media.php:2435 msgid "Not Synced" msgstr "" -#: php/class-media.php:2432 +#: php/class-media.php:2440 msgid "Synced" msgstr "" -#: php/class-media.php:3083 +#: php/class-media.php:3091 msgid "No Cloudinary filters" msgstr "" -#: php/class-media.php:3183 +#: php/class-media.php:3191 msgid "Media Settings" msgstr "" -#: php/class-media.php:3186 +#: php/class-media.php:3194 msgid "Media Display" msgstr "" -#: php/class-media.php:3190 php/media/class-global-transformations.php:620 +#: php/class-media.php:3198 php/media/class-global-transformations.php:620 #: php/ui/component/class-asset-preview.php:73 #: php/ui/component/class-plan-details.php:119 #: php/ui/component/class-plan-status.php:128 @@ -565,7 +565,7 @@ msgstr "" msgid "Transformations" msgstr "" -#: php/class-media.php:3191 +#: php/class-media.php:3199 msgid "" "Cloudinary allows you to easily transform your images on-the-fly to any " "required format, style and dimension, and also optimizes images for minimal " @@ -574,8 +574,8 @@ msgid "" "transformation and delivery URLs." msgstr "" -#: php/class-media.php:3196 ui-definitions/settings-image.php:164 -#: ui-definitions/settings-video.php:250 +#: php/class-media.php:3204 ui-definitions/settings-image.php:176 +#: ui-definitions/settings-video.php:262 msgid "See examples" msgstr "" @@ -771,9 +771,9 @@ msgstr "" #: php/class-sync.php:1304 php/delivery/class-lazy-load.php:538 #: php/media/class-gallery.php:416 ui-definitions/components/header.php:19 -#: ui-definitions/settings-image.php:246 ui-definitions/settings-pages.php:206 +#: ui-definitions/settings-image.php:258 ui-definitions/settings-pages.php:206 #: ui-definitions/settings-pages.php:222 ui-definitions/settings-pages.php:223 -#: ui-definitions/settings-video.php:293 +#: ui-definitions/settings-video.php:305 msgid "Need help?" msgstr "" @@ -854,15 +854,15 @@ msgstr "" msgid "Lazy Loading" msgstr "" -#: php/delivery/class-lazy-load.php:415 ui-definitions/settings-image.php:20 -#: ui-definitions/settings-pages.php:100 ui-definitions/settings-video.php:20 +#: php/delivery/class-lazy-load.php:415 ui-definitions/settings-image.php:29 +#: ui-definitions/settings-pages.php:100 ui-definitions/settings-video.php:29 msgid "Settings" msgstr "" #: php/delivery/class-lazy-load.php:419 php/delivery/class-lazy-load.php:529 -#: ui-definitions/settings-image.php:24 ui-definitions/settings-image.php:233 +#: ui-definitions/settings-image.php:33 ui-definitions/settings-image.php:245 #: ui-definitions/settings-pages.php:104 ui-definitions/settings-pages.php:197 -#: ui-definitions/settings-video.php:24 +#: ui-definitions/settings-video.php:33 msgid "Preview" msgstr "" @@ -926,7 +926,7 @@ msgid "Dominant Color" msgstr "" #: php/delivery/class-lazy-load.php:496 php/delivery/class-lazy-load.php:511 -#: ui-definitions/settings-video.php:138 +#: ui-definitions/settings-video.php:148 msgid "Off" msgstr "" @@ -1001,12 +1001,12 @@ msgid "" msgstr "" #: php/media/class-global-transformations.php:322 -msgid "Categories/Tags transformations" +msgid "Cloudinary terms transformations" msgstr "" #: php/media/class-global-transformations.php:454 msgid "" -"If you placed custom transformations on categories/tags you may order them " +"If you placed custom transformations on these terms you may order them " "below. " msgstr "" @@ -1015,7 +1015,7 @@ msgid "No terms added" msgstr "" #: php/media/class-global-transformations.php:467 -msgid "Disable global transformations" +msgid "Disable Cloudinary global transformations" msgstr "" #: php/media/class-global-transformations.php:542 @@ -1059,13 +1059,13 @@ msgstr "" msgid "Ending thread %s" msgstr "" -#: php/sync/class-storage.php:112 +#: php/sync/class-storage.php:110 msgid "" "Please ensure all media is fully synced before changing the environment " "variable URL." msgstr "" -#: php/sync/class-storage.php:117 +#: php/sync/class-storage.php:115 #. translators: Placeholders are tags. msgid "" "You can’t currently change your environment variable as your storage " @@ -1073,28 +1073,28 @@ msgid "" "%2$s and sync your assets to WordPress storage to enable this setting." msgstr "" -#: php/sync/class-storage.php:236 +#: php/sync/class-storage.php:234 msgid "Syncing" msgstr "" -#: php/sync/class-storage.php:239 +#: php/sync/class-storage.php:237 msgid "Removing asset copy from local storage" msgstr "" -#: php/sync/class-storage.php:246 +#: php/sync/class-storage.php:244 #. translators: %s is time remaining. msgid "Local asset removal in %s" msgstr "" -#: php/sync/class-storage.php:250 +#: php/sync/class-storage.php:248 msgid "Syncing low resolution asset to local storage" msgstr "" -#: php/sync/class-storage.php:253 +#: php/sync/class-storage.php:251 msgid "Syncing asset to local storage" msgstr "" -#: php/sync/class-storage.php:276 +#: php/sync/class-storage.php:274 #. translators: Placeholders are tags. msgid "" "You have reached one or more of your quota limits. Your Cloudinary media " @@ -1104,11 +1104,11 @@ msgid "" "storage settings.%2$s" msgstr "" -#: php/sync/class-storage.php:414 +#: php/sync/class-storage.php:412 msgid "Restricted file type" msgstr "" -#: php/sync/class-storage.php:548 +#: php/sync/class-storage.php:546 msgid "Calculating stats" msgstr "" @@ -1290,9 +1290,9 @@ msgstr "" msgid "60 monthly credits" msgstr "" -#: php/templates/taxonomy-term-transformation-fields.php:15 -#. translators: variable is context. -msgid "Global %s Transformations" +#: php/templates/taxonomy-term-transformation-fields.php:28 +#. translators: The taxonomy label and the context. +msgid "Cloudinary %1$s %2$s Transformations" msgstr "" #: php/templates/taxonomy-transformation-fields.php:25 @@ -1330,12 +1330,12 @@ msgstr "" msgid "Save" msgstr "" -#: php/ui/component/class-asset.php:191 +#: php/ui/component/class-asset.php:192 #: php/ui/component/class-folder-table.php:202 msgid "Search" msgstr "" -#: php/ui/component/class-asset.php:221 +#: php/ui/component/class-asset.php:222 msgid "Apply Changes" msgstr "" @@ -1771,23 +1771,31 @@ msgstr "" msgid "Next" msgstr "" -#: ui-definitions/settings-image.php:13 +#: ui-definitions/settings-image.php:11 ui-definitions/settings-video.php:11 +msgid "Cloudinary global transformations" +msgstr "" + +#: ui-definitions/settings-image.php:16 ui-definitions/settings-video.php:16 +msgid "Term transformations" +msgstr "" + +#: ui-definitions/settings-image.php:22 msgid "Image - Global Settings" msgstr "" -#: ui-definitions/settings-image.php:37 ui-definitions/settings-image.php:38 +#: ui-definitions/settings-image.php:46 ui-definitions/settings-image.php:47 msgid "Image delivery" msgstr "" -#: ui-definitions/settings-image.php:39 +#: ui-definitions/settings-image.php:48 msgid "If you turn this setting off, your images will be delivered from WordPress." msgstr "" -#: ui-definitions/settings-image.php:43 +#: ui-definitions/settings-image.php:52 msgid "Sync and deliver images from Cloudinary." msgstr "" -#: ui-definitions/settings-image.php:53 +#: ui-definitions/settings-image.php:63 #. translators: %s is a link to the storage settings page. msgid "" "This setting currently can’t be turned off. Your images must be delivered " @@ -1796,128 +1804,126 @@ msgid "" "Settings page that will enable storing your assets also in WordPress." msgstr "" -#: ui-definitions/settings-image.php:57 ui-definitions/settings-video.php:57 +#: ui-definitions/settings-image.php:67 ui-definitions/settings-video.php:67 msgid "Storage setting" msgstr "" -#: ui-definitions/settings-image.php:73 ui-definitions/settings-image.php:74 +#: ui-definitions/settings-image.php:83 ui-definitions/settings-image.php:84 msgid "Image optimization" msgstr "" -#: ui-definitions/settings-image.php:75 +#: ui-definitions/settings-image.php:85 msgid "" "Images will be delivered using Cloudinary’s automatic format and quality " "algorithms for the best tradeoff between visual quality and file size. Use " "Advanced Optimization options to manually tune format and quality." msgstr "" -#: ui-definitions/settings-image.php:79 +#: ui-definitions/settings-image.php:89 msgid "Optimize images on my site." msgstr "" -#: ui-definitions/settings-image.php:96 +#: ui-definitions/settings-image.php:106 msgid "Image format" msgstr "" -#: ui-definitions/settings-image.php:97 +#: ui-definitions/settings-image.php:107 msgid "" "The image format to use for delivery. Leave as Auto to automatically " "deliver the most optimal format based on the user's browser and device." msgstr "" -#: ui-definitions/settings-image.php:103 ui-definitions/settings-image.php:127 -#: ui-definitions/settings-video.php:192 ui-definitions/settings-video.php:211 +#: ui-definitions/settings-image.php:113 ui-definitions/settings-image.php:137 +#: ui-definitions/settings-video.php:202 ui-definitions/settings-video.php:221 msgid "Not set" msgstr "" -#: ui-definitions/settings-image.php:104 ui-definitions/settings-image.php:128 -#: ui-definitions/settings-video.php:193 ui-definitions/settings-video.php:212 +#: ui-definitions/settings-image.php:114 ui-definitions/settings-image.php:138 +#: ui-definitions/settings-video.php:203 ui-definitions/settings-video.php:222 msgid "Auto" msgstr "" -#: ui-definitions/settings-image.php:105 +#: ui-definitions/settings-image.php:115 msgid "PNG" msgstr "" -#: ui-definitions/settings-image.php:106 +#: ui-definitions/settings-image.php:116 msgid "JPG" msgstr "" -#: ui-definitions/settings-image.php:107 +#: ui-definitions/settings-image.php:117 msgid "GIF" msgstr "" -#: ui-definitions/settings-image.php:108 +#: ui-definitions/settings-image.php:118 msgid "WebP" msgstr "" -#: ui-definitions/settings-image.php:119 +#: ui-definitions/settings-image.php:129 msgid "Image quality" msgstr "" -#: ui-definitions/settings-image.php:120 +#: ui-definitions/settings-image.php:130 msgid "" "The compression quality to apply when delivering images. Leave as Auto to " "apply an algorithm that finds the best tradeoff between visual quality and " "file size." msgstr "" -#: ui-definitions/settings-image.php:129 ui-definitions/settings-video.php:213 +#: ui-definitions/settings-image.php:139 ui-definitions/settings-video.php:223 msgid "Auto best" msgstr "" -#: ui-definitions/settings-image.php:130 ui-definitions/settings-video.php:214 +#: ui-definitions/settings-image.php:140 ui-definitions/settings-video.php:224 msgid "Auto good" msgstr "" -#: ui-definitions/settings-image.php:131 ui-definitions/settings-video.php:215 +#: ui-definitions/settings-image.php:141 ui-definitions/settings-video.php:225 msgid "Auto eco" msgstr "" -#: ui-definitions/settings-image.php:132 ui-definitions/settings-video.php:216 +#: ui-definitions/settings-image.php:142 ui-definitions/settings-video.php:226 msgid "Auto low" msgstr "" -#: ui-definitions/settings-image.php:152 -msgid "Additional image transformations" -msgstr "" - -#: ui-definitions/settings-image.php:156 +#: ui-definitions/settings-image.php:166 #. translators: The link to transformation reference. msgid "" "A set of additional transformations to apply to all images. Specify your " "transformations using Cloudinary URL transformation syntax. See " -"%1$sreference%2$s for all available transformations and syntax." +"%1$sreference%2$s for all available transformations and syntax.%3$s* The " +"Cloudinary global transformations are only applied to assets managed in the " +"Media Library%4$s." msgstr "" -#: ui-definitions/settings-image.php:179 ui-definitions/settings-video.php:265 +#: ui-definitions/settings-image.php:191 ui-definitions/settings-video.php:277 msgid "What are transformations?" msgstr "" -#: ui-definitions/settings-image.php:180 ui-definitions/settings-video.php:266 +#: ui-definitions/settings-image.php:192 ui-definitions/settings-video.php:278 msgid "" "A set of parameters included in a Cloudinary URL to programmatically " "transform the visual appearance of the assets on your website." msgstr "" -#: ui-definitions/settings-image.php:192 ui-definitions/settings-image.php:193 +#: ui-definitions/settings-image.php:204 ui-definitions/settings-image.php:205 msgid "SVG Support" msgstr "" -#: ui-definitions/settings-image.php:194 +#: ui-definitions/settings-image.php:206 msgid "Enable Cloudinary's SVG Support." msgstr "" -#: ui-definitions/settings-image.php:198 +#: ui-definitions/settings-image.php:210 msgid "Enable SVG support." msgstr "" -#: ui-definitions/settings-image.php:204 +#: ui-definitions/settings-image.php:216 #: ui-definitions/settings-metaboxes.php:33 msgid "Crop and Gravity control (beta)" msgstr "" -#: ui-definitions/settings-image.php:249 +#: ui-definitions/settings-image.php:261 #. Translators: The HTML for opening and closing link tags. msgid "" "Watch free lessons on how to use the Image Global Settings in the " @@ -2239,23 +2245,23 @@ msgstr "" msgid "%s Optimized" msgstr "" -#: ui-definitions/settings-video.php:13 +#: ui-definitions/settings-video.php:22 msgid "Video - Global Settings" msgstr "" -#: ui-definitions/settings-video.php:37 ui-definitions/settings-video.php:38 +#: ui-definitions/settings-video.php:46 ui-definitions/settings-video.php:47 msgid "Video delivery" msgstr "" -#: ui-definitions/settings-video.php:39 +#: ui-definitions/settings-video.php:48 msgid "If you turn this setting off, your videos will be delivered from WordPress." msgstr "" -#: ui-definitions/settings-video.php:43 +#: ui-definitions/settings-video.php:52 msgid "Sync and deliver videos from Cloudinary." msgstr "" -#: ui-definitions/settings-video.php:53 +#: ui-definitions/settings-video.php:63 #. translators: %s is a link to the storage settings page. msgid "" "This setting currently can’t be turned off. Your videos must be delivered " @@ -2264,27 +2270,27 @@ msgid "" "Settings page that will enable storing your assets also in WordPress." msgstr "" -#: ui-definitions/settings-video.php:73 +#: ui-definitions/settings-video.php:83 msgid "Video player" msgstr "" -#: ui-definitions/settings-video.php:74 +#: ui-definitions/settings-video.php:84 msgid "Which video player to use on all videos." msgstr "" -#: ui-definitions/settings-video.php:77 +#: ui-definitions/settings-video.php:87 msgid "WordPress player" msgstr "" -#: ui-definitions/settings-video.php:78 +#: ui-definitions/settings-video.php:88 msgid "Cloudinary player" msgstr "" -#: ui-definitions/settings-video.php:88 +#: ui-definitions/settings-video.php:98 msgid "Adaptive bitrate streaming (beta)" msgstr "" -#: ui-definitions/settings-video.php:93 +#: ui-definitions/settings-video.php:103 #. translators: Placeholders are tags. msgid "" "Adaptive bitrate streaming is a video delivery technique that adjusts the " @@ -2292,39 +2298,39 @@ msgid "" "CPU capacity.%1$sRead more about Adaptive bitrate streaming%2$s" msgstr "" -#: ui-definitions/settings-video.php:103 +#: ui-definitions/settings-video.php:113 msgid "Streaming protocol" msgstr "" -#: ui-definitions/settings-video.php:107 +#: ui-definitions/settings-video.php:117 msgid "Dynamic adaptive streaming over HTTP (MPEG-DASH)" msgstr "" -#: ui-definitions/settings-video.php:108 +#: ui-definitions/settings-video.php:118 msgid "HTTP live streaming (HLS)" msgstr "" -#: ui-definitions/settings-video.php:122 +#: ui-definitions/settings-video.php:132 msgid "Show controls" msgstr "" -#: ui-definitions/settings-video.php:128 +#: ui-definitions/settings-video.php:138 msgid "Repeat video" msgstr "" -#: ui-definitions/settings-video.php:134 +#: ui-definitions/settings-video.php:144 msgid "Autoplay" msgstr "" -#: ui-definitions/settings-video.php:139 +#: ui-definitions/settings-video.php:149 msgid "Always" msgstr "" -#: ui-definitions/settings-video.php:140 +#: ui-definitions/settings-video.php:150 msgid "On-scroll (autoplay when in view)" msgstr "" -#: ui-definitions/settings-video.php:144 +#: ui-definitions/settings-video.php:154 #. translators: Placeholders are tags. msgid "" "Please note that when choosing \"always\", the video will autoplay without " @@ -2332,59 +2338,57 @@ msgid "" "browsers.%1$sRead more about muted autoplay%2$s" msgstr "" -#: ui-definitions/settings-video.php:162 +#: ui-definitions/settings-video.php:172 msgid "Video optimization" msgstr "" -#: ui-definitions/settings-video.php:163 +#: ui-definitions/settings-video.php:173 msgid "" "Videos will be delivered using Cloudinary’s automatic format and quality " "algorithms for the best tradeoff between visual quality and file size. Use " "Advanced Optimization options to manually tune format and quality." msgstr "" -#: ui-definitions/settings-video.php:167 +#: ui-definitions/settings-video.php:177 msgid "Optimize videos on my site." msgstr "" -#: ui-definitions/settings-video.php:185 +#: ui-definitions/settings-video.php:195 msgid "Video format" msgstr "" -#: ui-definitions/settings-video.php:186 +#: ui-definitions/settings-video.php:196 msgid "" "The video format to use for delivery. Leave as Auto to automatically " "deliver the most optimal format based on the user's browser and device." msgstr "" -#: ui-definitions/settings-video.php:204 +#: ui-definitions/settings-video.php:214 msgid "Video quality" msgstr "" -#: ui-definitions/settings-video.php:205 +#: ui-definitions/settings-video.php:215 msgid "" "The compression quality to apply when delivering videos. Leave as Auto to " "apply an algorithm that finds the best tradeoff between visual quality and " "file size." msgstr "" -#: ui-definitions/settings-video.php:238 -msgid "Additional video transformations" -msgstr "" - -#: ui-definitions/settings-video.php:242 +#: ui-definitions/settings-video.php:252 #. translators: The link to transformation reference. msgid "" "A set of additional transformations to apply to all videos. Specify your " "transformations using Cloudinary URL transformation syntax. See " -"%1$sreference%2$s for all available transformations and syntax." +"%1$sreference%2$s for all available transformations and syntax.%3$s* The " +"Cloudinary global transformations are only applied to assets managed in the " +"Media Library%4$s." msgstr "" -#: ui-definitions/settings-video.php:281 +#: ui-definitions/settings-video.php:293 msgid "Video preview" msgstr "" -#: ui-definitions/settings-video.php:296 +#: ui-definitions/settings-video.php:308 #. Translators: The HTML for opening and closing link tags. msgid "" "Watch free lessons on how to use the Video Global Settings in the " From 28f9b87567ef760ae77e84ff89a501de783deecf Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Tue, 22 Oct 2024 15:46:09 +0100 Subject: [PATCH 08/18] For loopback requests, do not use the safe request, as it has the side effect of removing credentials for basic auth --- php/class-connect.php | 4 ++-- php/class-deactivation.php | 2 +- php/class-rest-api.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/php/class-connect.php b/php/class-connect.php index 27cd4dbe4..24b17ed37 100644 --- a/php/class-connect.php +++ b/php/class-connect.php @@ -214,7 +214,7 @@ public function rest_save_wizard( WP_REST_Request $request ) { if ( ! empty( $url ) ) { // Warm the last uploaded items in the media library. - wp_safe_remote_request( + wp_remote_request( Utils::rest_url( 'wp/v2/media' ), array( 'timeout' => 0.1, @@ -1024,7 +1024,7 @@ public static function test_rest_api_connectivity() { ); $url = Utils::rest_url( REST_API::BASE . '/test_rest_api' ); - $response = wp_safe_remote_get( $url, $args ); + $response = wp_remote_get( $url, $args ); if ( is_wp_error( $response ) ) { $result = array( diff --git a/php/class-deactivation.php b/php/class-deactivation.php index ebdc269c7..511f34498 100644 --- a/php/class-deactivation.php +++ b/php/class-deactivation.php @@ -429,7 +429,7 @@ public function rest_callback( WP_REST_Request $request ) { $url = add_query_arg( array_filter( $args ), CLOUDINARY_ENDPOINTS_DEACTIVATION ); - $response = wp_safe_remote_get( $url ); + $response = wp_remote_get( $url ); if ( 'uninstall' === $data ) { $this->cleanup(); diff --git a/php/class-rest-api.php b/php/class-rest-api.php index 3d70b8bcb..0200ce98d 100644 --- a/php/class-rest-api.php +++ b/php/class-rest-api.php @@ -113,6 +113,6 @@ public function background_request( $endpoint, $params = array(), $method = 'POS $args['headers']['X-WP-Nonce'] = $params['nonce']; // Send request. - wp_safe_remote_request( $url, $args ); + wp_remote_request( $url, $args ); } } From 3d358834d2b662866aff5aa7c0167e4a76ca064c Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Thu, 17 Oct 2024 11:57:32 +0100 Subject: [PATCH 09/18] Update the transformations title to take context in consideration --- php/class-utils.php | 38 ++++++++++++++++++- .../taxonomy-transformation-fields.php | 5 +-- ui-definitions/settings-image.php | 8 +--- ui-definitions/settings-video.php | 8 +--- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/php/class-utils.php b/php/class-utils.php index 42b036863..076e74bf7 100644 --- a/php/class-utils.php +++ b/php/class-utils.php @@ -546,11 +546,11 @@ public static function looks_like_json( $thing ) { } $thing = trim( $thing ); - + if ( empty( $thing ) ) { return false; } - + if ( ! in_array( $thing[0], array( '{', '[' ), true ) ) { return false; } @@ -1267,4 +1267,38 @@ public static function rest_url( $path = '', $scheme = null ) { */ return apply_filters( 'cloudinary_rest_url', $rest_url, $path, $scheme ); } + + /** + * Get the transformations title. + * + * @param string $context The context. + * + * @return string + */ + public static function get_transformations_title( $context ) { + $transformations_title = __( 'Cloudinary global transformations', 'cloudinary' ); + $taxonomy_slug = static::get_sanitized_text( 'taxonomy' ); + + if ( $taxonomy_slug ) { + $taxonomy = get_taxonomy( $taxonomy_slug ); + $transformations_title = sprintf( + // translators: %1$s is the taxonomy label and the %2$s is the context of the use. + __( '%1$s %2$s transformations', 'cloudinary' ), + $taxonomy->labels->singular_name, + $context + ); + + $taxonomy_id = static::get_sanitized_text( 'tag_ID' ); + + if ( $taxonomy_id ) { + $transformations_title = sprintf( + // translators: %s is the term name. + __( '%s transformations', 'cloudinary' ), + get_term( $taxonomy_id )->name + ); + } + } + + return $transformations_title; + } } diff --git a/php/templates/taxonomy-transformation-fields.php b/php/templates/taxonomy-transformation-fields.php index 2346fa83b..1b20950e0 100644 --- a/php/templates/taxonomy-transformation-fields.php +++ b/php/templates/taxonomy-transformation-fields.php @@ -20,10 +20,7 @@

- singular_name ) ) ); - ?> +

diff --git a/ui-definitions/settings-image.php b/ui-definitions/settings-image.php index 4a46a88d8..1eea10770 100644 --- a/ui-definitions/settings-image.php +++ b/ui-definitions/settings-image.php @@ -8,13 +8,7 @@ use Cloudinary\Utils; use function Cloudinary\get_plugin_instance; -$transformations_title = __( 'Cloudinary global transformations', 'cloudinary' ); - -$taxonomy_slug = Utils::get_sanitized_text( 'taxonomy' ); - -if ( $taxonomy_slug ) { - $transformations_title = __( 'Term transformations', 'cloudinary' ); -} +$transformations_title = Utils::get_transformations_title( esc_html__( 'Image', 'cloudinary' ) ); $settings = array( array( diff --git a/ui-definitions/settings-video.php b/ui-definitions/settings-video.php index 6c70e81c9..22e67babe 100644 --- a/ui-definitions/settings-video.php +++ b/ui-definitions/settings-video.php @@ -8,13 +8,7 @@ use Cloudinary\Utils; use function Cloudinary\get_plugin_instance; -$transformations_title = __( 'Cloudinary global transformations', 'cloudinary' ); - -$taxonomy_slug = Utils::get_sanitized_text( 'taxonomy' ); - -if ( $taxonomy_slug ) { - $transformations_title = __( 'Term transformations', 'cloudinary' ); -} +$transformations_title = Utils::get_transformations_title( esc_html__( 'Video', 'cloudinary' ) ); $settings = array( array( From 6507c519f765ffc8ee25b3fd0fe1a6f0e7a70b8b Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Tue, 22 Oct 2024 15:36:17 +0100 Subject: [PATCH 10/18] Wording update --- .../taxonomy-transformation-fields.php | 18 +++++++++++------- php/ui/component/class-text.php | 4 ++++ ui-definitions/settings-image.php | 1 + ui-definitions/settings-video.php | 1 + 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/php/templates/taxonomy-transformation-fields.php b/php/templates/taxonomy-transformation-fields.php index 1b20950e0..90b04794b 100644 --- a/php/templates/taxonomy-transformation-fields.php +++ b/php/templates/taxonomy-transformation-fields.php @@ -20,19 +20,23 @@

- + singular_name ) ); + ?>