From b55855661b137275eff066c5630c7f0459518233 Mon Sep 17 00:00:00 2001
From: Marco Pereirinha
Date: Mon, 5 Oct 2020 11:17:19 +0100
Subject: [PATCH 01/19] Move files to the root of the plugin repository
---
package.json | 184 ++++++++++++++++++++++++---------------------------
1 file changed, 88 insertions(+), 96 deletions(-)
diff --git a/package.json b/package.json
index 65d9834b5..59693ac4b 100644
--- a/package.json
+++ b/package.json
@@ -1,98 +1,90 @@
{
- "name": "cloudinary",
- "title": "Cloudinary",
- "private": true,
- "homepage": "https://github.com/cloudinary/cloudinary_wordpress",
- "repository": {
- "type": "git",
- "url": "https://github.com/cloudinary/cloudinary_wordpress.git"
- },
- "engines": {
- "node": ">=12"
- },
- "scripts": {
- "postinstall": "composer install",
- "dev": "webpack --mode=development --watch",
- "build": "webpack --mode=production",
- "lint": "composer lint",
- "package": "npm run build && grunt package",
- "deploy": "npm run build && grunt deploy",
- "deploy-assets": "grunt deploy-assets"
- },
- "author": "XWP",
- "license": "GPL-2.0+",
- "devDependencies": {
- "@babel/cli": "7.4.4",
- "@babel/core": "7.4.5",
- "@babel/plugin-proposal-object-rest-spread": "7.4.4",
- "@babel/plugin-transform-react-jsx": "7.3.0",
- "@wordpress/babel-preset-default": "4.2.0",
- "@wordpress/block-editor": "2.1.0",
- "@wordpress/blocks": "6.3.0",
- "@wordpress/browserslist-config": "2.4.0",
- "@wordpress/components": "7.4.0",
- "@wordpress/compose": "3.3.0",
- "@wordpress/data": "4.5.0",
- "@wordpress/date": "3.3.0",
- "@wordpress/dom-ready": "2.3.0",
- "@wordpress/e2e-test-utils": "2.0.0",
- "@wordpress/edit-post": "3.4.0",
- "@wordpress/editor": "9.3.0",
- "@wordpress/element": "2.4.0",
- "@wordpress/eslint-plugin": "2.2.0",
- "@wordpress/hooks": "2.3.0",
- "@wordpress/i18n": "3.4.0",
- "@wordpress/keycodes": "2.3.0",
- "@wordpress/plugins": "2.3.0",
- "@wordpress/postcss-themes": "2.1.0",
- "@wordpress/scripts": "3.2.1",
- "@wordpress/url": "2.6.0",
- "@wordpress/wordcount": "2.3.0",
- "autoprefixer": "9.6.0",
- "babel-eslint": "10.0.1",
- "babel-jest": "24.8.0",
- "babel-loader": "8.0.6",
- "babel-plugin-inline-react-svg": "1.1.0",
- "babel-plugin-transform-react-remove-prop-types": "0.4.24",
- "browserslist": "4.6.2",
- "core-js": "3.1.3",
- "css-loader": "3.0.0",
- "cssnano": "4.1.10",
- "enzyme": "3.10.0",
- "eslint": "5.16.0",
- "eslint-plugin-jest": "22.6.4",
- "eslint-plugin-react": "7.13.0",
- "file-loader": "^4.0.0",
- "grunt": "1.3.0",
- "grunt-contrib-clean": "2.0.0",
- "grunt-contrib-compress": "1.6.0",
- "grunt-contrib-copy": "1.0.0",
- "grunt-wp-deploy": "2.1.2",
- "loading-attribute-polyfill": "^1.5.4",
- "lodash": "4.17.19",
- "mini-css-extract-plugin": "0.7.0",
- "moment": "2.24.0",
- "node-sass": "^4.9.0",
- "npm-run-all": "4.1.5",
- "null-loader": "3.0.0",
- "optimize-css-assets-webpack-plugin": "5.0.1",
- "postcss": "7.0.17",
- "postcss-color-function": "4.1.0",
- "postcss-import": "12.0.1",
- "postcss-loader": "3.0.0",
- "postcss-nested": "4.1.2",
- "postcss-preset-env": "6.6.0",
- "raw-loader": "^0.5.1",
- "rtlcss-webpack-plugin": "4.0.0",
- "sass-loader": "^6.0.7",
- "source-map-loader": "0.2.4",
- "svg-inline-loader": "0.8.0",
- "terser-webpack-plugin": "1.3.0",
- "uuid": "3.3.2",
- "webpack": "4.33.0",
- "webpack-cli": "3.3.4"
- },
- "dependencies": {
- "@wordpress/i18n": "^1.2.1"
- }
+ "name": "cloudinary",
+ "title": "Cloudinary",
+ "homepage": "https://github.com/CloudinaryLtd/cloudinary_wordpress_v2",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/CloudinaryLtd/cloudinary_wordpress_v2.git"
+ },
+ "scripts": {
+ "dev": "cross-env webpack --mode=development --watch",
+ "build": "cross-env webpack --mode=production"
+ },
+ "author": "XWP",
+ "license": "GPL-2.0+",
+ "devDependencies": {
+ "@babel/cli": "7.4.4",
+ "@babel/core": "7.4.5",
+ "@babel/plugin-proposal-object-rest-spread": "7.4.4",
+ "@babel/plugin-transform-react-jsx": "7.3.0",
+ "@wordpress/babel-preset-default": "4.2.0",
+ "@wordpress/block-editor": "2.1.0",
+ "@wordpress/blocks": "6.3.0",
+ "@wordpress/browserslist-config": "2.4.0",
+ "@wordpress/components": "7.4.0",
+ "@wordpress/compose": "3.3.0",
+ "@wordpress/data": "4.5.0",
+ "@wordpress/date": "3.3.0",
+ "@wordpress/dom-ready": "2.3.0",
+ "@wordpress/e2e-test-utils": "2.0.0",
+ "@wordpress/edit-post": "3.4.0",
+ "@wordpress/editor": "9.3.0",
+ "@wordpress/element": "2.4.0",
+ "@wordpress/eslint-plugin": "2.2.0",
+ "@wordpress/hooks": "2.3.0",
+ "@wordpress/i18n": "3.4.0",
+ "@wordpress/keycodes": "2.3.0",
+ "@wordpress/plugins": "2.3.0",
+ "@wordpress/postcss-themes": "2.1.0",
+ "@wordpress/scripts": "3.2.1",
+ "@wordpress/url": "2.6.0",
+ "@wordpress/wordcount": "2.3.0",
+ "autoprefixer": "9.6.0",
+ "babel-eslint": "10.0.1",
+ "babel-jest": "24.8.0",
+ "babel-loader": "8.0.6",
+ "babel-plugin-inline-react-svg": "1.1.0",
+ "babel-plugin-transform-react-remove-prop-types": "0.4.24",
+ "browserslist": "4.6.2",
+ "core-js": "3.1.3",
+ "cross-env": "5.2.0",
+ "css-loader": "3.0.0",
+ "cssnano": "4.1.10",
+ "enzyme": "3.10.0",
+ "eslint": "5.16.0",
+ "eslint-plugin-jest": "22.6.4",
+ "eslint-plugin-react": "7.13.0",
+ "file-loader": "^4.0.0",
+ "grunt": "1.0.4",
+ "grunt-contrib-clean": "2.0.0",
+ "grunt-contrib-copy": "1.0.0",
+ "grunt-shell": "3.0.1",
+ "grunt-wp-deploy": "2.0.0",
+ "loading-attribute-polyfill": "^1.5.4",
+ "lodash": "4.17.19",
+ "mini-css-extract-plugin": "0.7.0",
+ "moment": "2.24.0",
+ "node-sass": "^4.9.0",
+ "npm-run-all": "4.1.5",
+ "null-loader": "3.0.0",
+ "optimize-css-assets-webpack-plugin": "5.0.1",
+ "postcss": "7.0.17",
+ "postcss-color-function": "4.1.0",
+ "postcss-import": "12.0.1",
+ "postcss-loader": "3.0.0",
+ "postcss-nested": "4.1.2",
+ "postcss-preset-env": "6.6.0",
+ "raw-loader": "^0.5.1",
+ "rtlcss-webpack-plugin": "4.0.0",
+ "sass-loader": "^6.0.7",
+ "source-map-loader": "0.2.4",
+ "svg-inline-loader": "0.8.0",
+ "terser-webpack-plugin": "1.3.0",
+ "uuid": "3.3.2",
+ "webpack": "4.33.0",
+ "webpack-cli": "3.3.4"
+ },
+ "dependencies": {
+ "@wordpress/i18n": "^1.2.1"
+ }
}
From 907bc1c883b235750526c5896bf0513340dfb756 Mon Sep 17 00:00:00 2001
From: Marco Pereirinha
Date: Sun, 4 Oct 2020 00:49:46 +0100
Subject: [PATCH 02/19] Use proper filter on filter input
---
php/class-settings-page.php | 2 +-
php/media/class-global-transformations.php | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/php/class-settings-page.php b/php/class-settings-page.php
index e07bab9c2..259f48d0c 100644
--- a/php/class-settings-page.php
+++ b/php/class-settings-page.php
@@ -889,7 +889,7 @@ public function active_tab() {
}
$tab = filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_STRING );
if ( ! $this->validate_tab( $tab ) ) { // Tab is invalid or not set, check if in a POST.
- $tab = filter_input( INPUT_POST, 'tab', FILTER_DEFAULT );
+ $tab = filter_input( INPUT_POST, 'tab', FILTER_SANITIZE_STRING );
if ( ! $this->validate_tab( $tab ) ) { // Tab is invalid or not set, load the default/first tab.
$tab = array_keys( $page['tabs'] );
$tab = array_shift( $tab );
diff --git a/php/media/class-global-transformations.php b/php/media/class-global-transformations.php
index 65ae8f5d2..51c27105d 100644
--- a/php/media/class-global-transformations.php
+++ b/php/media/class-global-transformations.php
@@ -175,7 +175,7 @@ public function get_transformations( $type ) {
// check screen context.
switch ( $screen->base ) {
case 'term':
- $term_id = filter_input( INPUT_GET, 'tag_ID', FILTER_DEFAULT );
+ $term_id = filter_input( INPUT_GET, 'tag_ID', FILTER_SANITIZE_NUMBER_INT );
$transformations = $this->get_term_transformations( $term_id, $type );
break;
case 'toplevel_page_cloudinary':
From b13d727dc9861596b1f3d8a4329ec82779ba3386 Mon Sep 17 00:00:00 2001
From: Marco Pereirinha
Date: Sun, 4 Oct 2020 00:50:16 +0100
Subject: [PATCH 03/19] Add PHPCS ignore note
---
php/class-connect.php | 2 +-
php/sync/class-upload-sync.php | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/php/class-connect.php b/php/class-connect.php
index 0c2596634..b74778705 100644
--- a/php/class-connect.php
+++ b/php/class-connect.php
@@ -102,7 +102,7 @@ class Connect implements Config, Setup, Notice {
public function __construct( Plugin $plugin ) {
$this->plugin = $plugin;
add_filter( 'pre_update_option_cloudinary_connect', array( $this, 'verify_connection' ) );
- add_filter( 'cron_schedules', array( $this, 'get_status_schedule' ) );
+ add_filter( 'cron_schedules', array( $this, 'get_status_schedule' ) ); // phpcs:ignore WordPress.WP.CronInterval
add_action( 'cloudinary_status', array( $this, 'check_status' ) );
}
diff --git a/php/sync/class-upload-sync.php b/php/sync/class-upload-sync.php
index c4d29cbed..f3d31d562 100644
--- a/php/sync/class-upload-sync.php
+++ b/php/sync/class-upload-sync.php
@@ -344,7 +344,7 @@ public function update_breakpoints( $attachment_id, $breakpoints ) {
*/
public function update_content( $attachment_id ) {
// Search and update link references in content.
- $content_search = new \WP_Query( array( 's' => 'wp-image-' . $attachment_id, 'fields' => 'ids', 'posts_per_page' => 1000 ) );
+ $content_search = new \WP_Query( array( 's' => 'wp-image-' . $attachment_id, 'fields' => 'ids', 'posts_per_page' => 1000 ) ); // phpcs:ignore WordPress.WP.PostsPerPage
if ( ! empty( $content_search->found_posts ) ) {
$content_posts = array_unique( $content_search->get_posts() ); // ensure post only gets updated once.
foreach ( $content_posts as $content_id ) {
From ef97077eeb0a44564495cfc7ce96c1f513131aa6 Mon Sep 17 00:00:00 2001
From: Marco Pereirinha
Date: Sun, 4 Oct 2020 00:51:37 +0100
Subject: [PATCH 04/19] Initialize var to improve readability
---
php/sync/class-push-sync.php | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/php/sync/class-push-sync.php b/php/sync/class-push-sync.php
index 023906c7f..fecd45143 100644
--- a/php/sync/class-push-sync.php
+++ b/php/sync/class-push-sync.php
@@ -201,7 +201,8 @@ public function process_assets( $attachments = array() ) {
foreach ( $ids as $attachment_id ) {
// Flag attachment as being processed.
update_post_meta( $attachment_id, Sync::META_KEYS['syncing'], time() );
- while ( $type = $this->sync->get_sync_type( $attachment_id, false ) ) {
+ $type = $this->sync->get_sync_type( $attachment_id, false );
+ while ( $type ) {
if ( isset( $stat[ $attachment_id ][ $type ] ) ) {
// Loop prevention.
break;
@@ -267,7 +268,8 @@ public function process_queue( \WP_REST_Request $request ) {
$queue = $this->queue->get_thread_queue( $thread );
if ( ! empty( $queue ) && $this->queue->is_running() ) {
- while ( $attachment_id = $this->queue->get_post( $thread ) ) {
+ $attachment_id = $this->queue->get_post( $thread );
+ while ( $attachment_id ) {
$this->process_assets( $attachment_id );
$this->queue->mark( $attachment_id, 'done' );
}
From ae83302fce8178e956837f03a8bb907ae84f0b7e Mon Sep 17 00:00:00 2001
From: Marco Pereirinha
Date: Sun, 4 Oct 2020 00:52:00 +0100
Subject: [PATCH 05/19] Cleanup
---
php/templates/taxonomy-term-transformation-fields.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/php/templates/taxonomy-term-transformation-fields.php b/php/templates/taxonomy-term-transformation-fields.php
index eac29da74..28e259fed 100644
--- a/php/templates/taxonomy-term-transformation-fields.php
+++ b/php/templates/taxonomy-term-transformation-fields.php
@@ -38,4 +38,3 @@
-
From 31a6e4b998be365e787dbd52f05367a709448d07 Mon Sep 17 00:00:00 2001
From: Marco Pereirinha
Date: Sun, 4 Oct 2020 01:52:05 +0100
Subject: [PATCH 06/19] Add PHPCS ignore for current_time
---
php/class-connect.php | 4 ++--
php/sync/class-sync-queue.php | 17 ++++++++---------
2 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/php/class-connect.php b/php/class-connect.php
index b74778705..66331fb2f 100644
--- a/php/class-connect.php
+++ b/php/class-connect.php
@@ -126,7 +126,7 @@ public function media_library_script() {
// sign maybe.
if ( ! empty( $this->credentials['user_email'] ) ) {
- $timestamp = current_time( 'timestamp' );
+ $timestamp = current_time( 'timestamp' ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
$params['mloptions']['username'] = $this->credentials['user_email'];
$params['mloptions']['timestamp'] = (string) $timestamp;
$query = array(
@@ -495,7 +495,7 @@ public function get_status_schedule( $schedules ) {
*/
protected function setup_status_cron() {
if ( false === wp_get_schedule( 'cloudinary_status' ) ) {
- $now = current_time( 'timestamp' );
+ $now = current_time( 'timestamp' ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
wp_schedule_event( $now + ( MINUTE_IN_SECONDS ), 'every_minute', 'cloudinary_status' );
}
}
diff --git a/php/sync/class-sync-queue.php b/php/sync/class-sync-queue.php
index 34c50a353..5c364adb1 100644
--- a/php/sync/class-sync-queue.php
+++ b/php/sync/class-sync-queue.php
@@ -117,13 +117,13 @@ public function get_post( $thread ) {
if ( ! empty( $queue[ $thread ] ) ) {
$id = array_shift( $queue[ $thread ] );
$queue['processing'][] = $id;
- $queue['last_update'] = current_time( 'timestamp' );
+ $queue['last_update'] = current_time( 'timestamp' ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
if ( ! empty( $queue['run_status'][ $thread ]['last_update'] ) ) {
- $queue['run_status'][ $thread ]['posts'][] = current_time( 'timestamp' ) - $queue['run_status'][ $thread ]['last_update'];
+ $queue['run_status'][ $thread ]['posts'][] = current_time( 'timestamp' ) - $queue['run_status'][ $thread ]['last_update']; // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
$queue['run_status'][ $thread ]['average'] = round( array_sum( $queue['run_status'][ $thread ]['posts'] ) / count( $queue['run_status'][ $thread ]['posts'] ), 2 );
}
- $queue['run_status'][ $thread ]['last_update'] = current_time( 'timestamp' );
+ $queue['run_status'][ $thread ]['last_update'] = current_time( 'timestamp' ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
$this->set_queue( $queue );
}
@@ -143,7 +143,7 @@ protected function thread_running( $thread ) {
$running = false;
if ( in_array( $thread, $this->threads, true ) ) {
$queue = $this->get_queue();
- $now = current_time( 'timestamp' );
+ $now = current_time( 'timestamp' ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
if ( $this->is_running() && ! empty( $queue[ $thread ] ) && $now - $queue['run_status'][ $thread ]['last_update'] < $this->cron_start_offset ) {
$running = true;
}
@@ -160,14 +160,13 @@ protected function thread_running( $thread ) {
*/
public function mark( $id, $type = 'done' ) {
$queue = $this->get_queue();
- $queue['last_update'] = current_time( 'timestamp' );
+ $queue['last_update'] = current_time( 'timestamp' ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
$key = array_search( (int) $id, $queue['processing'], true );
if ( false !== $key ) {
unset( $queue['processing'][ $key ] );
if ( ! in_array( $id, $queue[ $type ], true ) ) {
$queue[ $type ][] = $id;
}
-
}
$this->set_queue( $queue );
@@ -360,8 +359,8 @@ public function start_queue() {
return $status;
}
// Mark as started.
- $queue['started'] = current_time( 'timestamp' );
- $queue['last_update'] = current_time( 'timestamp' );
+ $queue['started'] = current_time( 'timestamp' ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
+ $queue['last_update'] = current_time( 'timestamp' ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
$this->set_queue( $queue );
@@ -408,7 +407,7 @@ public function get_thread_queue( $thread ) {
* Schedule a resume queue check.
*/
protected function schedule_resume() {
- $now = current_time( 'timestamp' );
+ $now = current_time( 'timestamp' ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
wp_schedule_single_event( $now + $this->cron_frequency, 'cloudinary_resume_queue' );
}
From 27cb183574805067499b96fb43b56cf45b9f8e6f Mon Sep 17 00:00:00 2001
From: Marco Pereirinha
Date: Mon, 5 Oct 2020 11:37:48 +0100
Subject: [PATCH 07/19] Add ending period
---
php/class-connect.php | 8 ++++----
php/class-plugin.php | 2 +-
php/class-settings-page.php | 2 +-
php/class-sync.php | 8 ++++----
php/connect/class-api.php | 2 +-
php/media/class-global-transformations.php | 2 +-
php/sync/class-download-sync.php | 8 ++++----
php/sync/class-storage.php | 4 +++-
php/sync/class-upload-sync.php | 2 +-
9 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/php/class-connect.php b/php/class-connect.php
index 66331fb2f..502c4379e 100644
--- a/php/class-connect.php
+++ b/php/class-connect.php
@@ -172,7 +172,7 @@ public function verify_connection( $data ) {
return $data;
}
- // Pattern match to ensure validity of the provided url
+ // Pattern match to ensure validity of the provided url.
if ( ! preg_match( '~' . self::CLOUDINARY_VARIABLE_REGEX . '~', $data['cloudinary_url'] ) ) {
add_settings_error(
'cloudinary_connect',
@@ -348,7 +348,7 @@ public function test_ping() {
/**
* Extracts the CNAME from a parsed connection URL.
*
- * @param array $parsed_url
+ * @param array $parsed_url Parsed URL.
*
* @return string|null
*/
@@ -369,7 +369,7 @@ protected function extract_cname( $parsed_url ) {
/**
* Safely validate a domain.
*
- * @param string $domain
+ * @param string $domain The domain.
*
* @return bool
*/
@@ -451,7 +451,7 @@ public function config_from_url( $url ) {
}
}
- // Specifically set CNAME
+ // Specifically set CNAME.
$cname = $this->extract_cname( $parts );
if ( ! empty( $cname ) ) {
$this->set_credentials( array( 'cname' => $cname ) );
diff --git a/php/class-plugin.php b/php/class-plugin.php
index d8bd8b35c..4feaf3f49 100644
--- a/php/class-plugin.php
+++ b/php/class-plugin.php
@@ -130,7 +130,7 @@ public function init() {
/**
* Get a plugin component.
*
- * @param $component
+ * @param mixed $component The component.
*
* @return \Cloudinary\Connect|\Cloudinary\Media|\Cloudinary\REST_API|\Cloudinary\Settings_Page|\Cloudinary\Sync|null
*/
diff --git a/php/class-settings-page.php b/php/class-settings-page.php
index 259f48d0c..48c92f464 100644
--- a/php/class-settings-page.php
+++ b/php/class-settings-page.php
@@ -476,7 +476,7 @@ public function sanitize( $setting, $fields ) {
$field,
static function ( $field_value ) {
// WP 4.9 compatibility, as _sanitize_text_fields() didn't have this check yet, and this prevents an error.
- // @see https://github.com/WordPress/wordpress-develop/blob/b30baca3ca2feb7f44b3615262ca55fcd87ae232/src/wp-includes/formatting.php#L5307
+ // @see https://github.com/WordPress/wordpress-develop/blob/b30baca3ca2feb7f44b3615262ca55fcd87ae232/src/wp-includes/formatting.php#L5307.
if ( is_object( $field_value ) || is_array( $field_value ) ) {
return '';
}
diff --git a/php/class-sync.php b/php/class-sync.php
index b9b912d58..2f378f8f1 100644
--- a/php/class-sync.php
+++ b/php/class-sync.php
@@ -347,7 +347,7 @@ public function setup_sync_base_struct() {
$base_struct = array(
'upgrade' => array(
- 'generate' => array( $this, 'get_sync_version' ), // Method to generate a signature. Which
+ 'generate' => array( $this, 'get_sync_version' ), // Method to generate a signature.
'validate' => array( $this, 'been_synced' ),
'priority' => 0,
'sync' => array( $this->managers['media']->upgrade, 'convert_cloudinary_version' ),
@@ -398,7 +398,7 @@ public function setup_sync_base_struct() {
return false === $public_id;
},
'priority' => 20,
- 'sync' => array( $this->managers['media']->upgrade, 'convert_cloudinary_version' ), // Rename
+ 'sync' => array( $this->managers['media']->upgrade, 'convert_cloudinary_version' ), // Rename.
'state' => 'info syncing',
'note' => __( 'Updating metadata', 'cloudinary' ),
'required' => true,
@@ -621,7 +621,7 @@ function ( $item, $key ) use ( $required_signature ) {
public function validate_sync_type( $type, $attachment_id ) {
// Validate that this sync type applied (for optional types like upgrade).
if ( false === $this->run_sync_method( $type, 'validate', $attachment_id ) ) {
- // If invalid, save the new signature
+ // If invalid, save the new signature.
$this->set_signature_item( $attachment_id, $type );
$type = $this->get_sync_type( $attachment_id, false ); // Set cache to false to get the new signature.
@@ -749,7 +749,7 @@ public function sync_signature_by_type( $attachment_id, $type ) {
*
* @param int $attachment_id The attachment ID.
* @param string $type The sync type.
- * @param null $value
+ * @param null $value The value.
*/
public function set_signature_item( $attachment_id, $type, $value = null ) {
diff --git a/php/connect/class-api.php b/php/connect/class-api.php
index 27ce0434f..6bab6b002 100644
--- a/php/connect/class-api.php
+++ b/php/connect/class-api.php
@@ -137,7 +137,7 @@ class Api {
* API constructor.
*
* @param \Cloudinary\Connect $connect The connect object.
- * @param string The plugin version.
+ * @param string $version The plugin version.
*/
public function __construct( $connect, $version ) {
$this->credentials = $connect->get_credentials();
diff --git a/php/media/class-global-transformations.php b/php/media/class-global-transformations.php
index 51c27105d..93eb55e10 100644
--- a/php/media/class-global-transformations.php
+++ b/php/media/class-global-transformations.php
@@ -514,7 +514,7 @@ public function classic_overwrite_transformations_featured_image( $content, $pos
/**
* Updates appropriate meta for overwriting transformations of a featured image.
*
- * @param int $post_id
+ * @param int $post_id The post ID.
*/
public function save_overwrite_transformations_featured_image( $post_id ) {
$field_value = filter_input( INPUT_POST, self::META_FEATURED_IMAGE_KEY, FILTER_VALIDATE_BOOLEAN );
diff --git a/php/sync/class-download-sync.php b/php/sync/class-download-sync.php
index 0e9f17673..bf93f674c 100644
--- a/php/sync/class-download-sync.php
+++ b/php/sync/class-download-sync.php
@@ -128,7 +128,7 @@ public function rest_download_asset( \WP_REST_Request $request ) {
/**
* Prepare and sync down an asset stored remotely.
*
- * @param $attachment_id
+ * @param int $attachment_id The attachment ID.
*
* @return array|\WP_Error
*/
@@ -264,9 +264,9 @@ public function download_asset( $attachment_id, $source = null, $date = null ) {
/**
* Download an attachment source to the file system.
*
- * @param int $attachment_id The attachment ID.
- * @param string $file_path The path of the file.
- * @param array|null $transformations
+ * @param int $attachment_id The attachment ID.
+ * @param string $file_path The path of the file.
+ * @param array|null $transformations The transformations.
*
* @return array|\WP_Error
*/
diff --git a/php/sync/class-storage.php b/php/sync/class-storage.php
index 795d5054c..198ea5537 100644
--- a/php/sync/class-storage.php
+++ b/php/sync/class-storage.php
@@ -157,6 +157,8 @@ public function validate_file_folder_sync( $attachment_id ) {
/**
* Generate a signature for this sync type.
*
+ * @param int $attachment_id The attachment ID.
+ *
* @return string
*/
public function generate_signature( $attachment_id ) {
@@ -226,7 +228,7 @@ public function sync( $attachment_id ) {
/**
* Remove all local files from an asset/attachment.
*
- * @param $attachment_id
+ * @param int $attachment_id The attachment ID.
*
* @return bool
*/
diff --git a/php/sync/class-upload-sync.php b/php/sync/class-upload-sync.php
index f3d31d562..c5eb3ea4d 100644
--- a/php/sync/class-upload-sync.php
+++ b/php/sync/class-upload-sync.php
@@ -262,7 +262,7 @@ function( $is_synced, $post_id ) use ( $attachment_id ) {
update_post_meta( $attachment_id, '_' . md5( 'base_' . $options['public_id'] ), true );
// Update signature for all that use the same method.
$this->sync->sync_signature_by_type( $attachment_id, $type );
- // Update options and public_id as well (full sync)
+ // Update options and public_id as well (full sync).
$this->sync->set_signature_item( $attachment_id, 'options' );
$this->sync->set_signature_item( $attachment_id, 'public_id' );
From e220b40f9f063cb5cd4f48b3ff549942b7a86193 Mon Sep 17 00:00:00 2001
From: Marco Pereirinha
Date: Mon, 5 Oct 2020 11:38:48 +0100
Subject: [PATCH 08/19] Apply phpcbf changes
---
php/class-connect.php | 8 +++---
php/class-media.php | 25 +++++++++++--------
php/class-plugin.php | 7 +++---
php/class-settings-page.php | 6 ++++-
php/class-sync.php | 22 ++++++++--------
php/media/class-filter.php | 5 ++--
php/media/class-upgrade.php | 19 ++++++++------
php/media/class-video.php | 19 +++++++-------
php/sync/class-download-sync.php | 2 +-
php/sync/class-storage.php | 2 +-
php/sync/class-upload-sync.php | 25 +++++++++++++------
php/templates/settings-tabs.php | 3 +--
.../taxonomy-transformation-fields.php | 1 +
ui-definitions/tabs/dashboard-content.php | 10 ++++----
ui-definitions/tabs/settings-sync-media.php | 13 +++++-----
ui-definitions/tabs/sync-media-content.php | 6 ++---
16 files changed, 97 insertions(+), 76 deletions(-)
diff --git a/php/class-connect.php b/php/class-connect.php
index 502c4379e..6a3250d32 100644
--- a/php/class-connect.php
+++ b/php/class-connect.php
@@ -216,7 +216,7 @@ public function is_connected() {
return false;
}
- $connect_data = get_option( self::META_KEYS['connect'], [] );
+ $connect_data = get_option( self::META_KEYS['connect'], array() );
$current_url = isset( $connect_data['cloudinary_url'] ) ? $connect_data['cloudinary_url'] : null;
if ( null === $current_url ) {
@@ -279,7 +279,7 @@ public function test_connection( $url ) {
$valid = array_filter(
array_keys( $test ),
function ( $a ) {
- return in_array( $a, [ 'scheme', 'host', 'user', 'pass' ], true );
+ return in_array( $a, array( 'scheme', 'host', 'user', 'pass' ), true );
}
);
@@ -620,7 +620,7 @@ public function usage_notices() {
continue;
}
$usage = $this->get_usage_stat( $stat, 'used_percent' );
- if ( empty ( $usage ) ) {
+ if ( empty( $usage ) ) {
continue;
}
$link = null;
@@ -640,7 +640,7 @@ public function usage_notices() {
continue;
}
// translators: Placeholders are URLS and percentage values.
- $message = sprintf(
+ $message = sprintf(
/* translators: %1$s quota size, %2$s amount in percent, %3$s link URL, %4$s link anchor text. */
__(
' You are %2$s of the way through your monthly quota for %1$s on your Cloudinary account. If you exceed your quota, the Cloudinary plugin will be deactivated until your next billing cycle and your media assets will be served from your WordPress Media Library. You may wish to %4$s and increase your quota to ensure you maintain full functionality.',
diff --git a/php/class-media.php b/php/class-media.php
index 835136560..9434e7055 100644
--- a/php/class-media.php
+++ b/php/class-media.php
@@ -686,7 +686,7 @@ public function apply_default_transformations( array $transformations, $type = '
$default['fetch_format'] = 'auto';
}
if ( isset( $global[ $type . '_quality' ] ) ) {
- $default['quality'] = $global[ $type . '_quality' ] !== 'none' ? $global[ $type . '_quality' ] : null;
+ $default['quality'] = 'none' !== $global[ $type . '_quality' ] ? $global[ $type . '_quality' ] : null;
} else {
$default['quality'] = 'auto';
}
@@ -985,7 +985,6 @@ public function cloudinary_id( $attachment_id ) {
*
* @return array The image array of size and url.
* @uses filter:image_downsize
- *
*/
public function filter_downsize( $image, $attachment_id, $size ) {
// Don't do this while saving.
@@ -1281,22 +1280,25 @@ public function get_asset_payload() {
$asset['url'] = filter_var( $data['asset']['derived'][0]['secure_url'], FILTER_SANITIZE_URL );
}
- //convert_media_extension
+ // convert_media_extension.
if ( ! $this->is_file_compatible( $asset['url'] ) ) {
$asset['url'] = $this->convert_media_extension( $asset['url'] );
}
// Move all context data into the meta key.
if ( ! empty( $data['asset']['context'] ) ) {
- array_walk_recursive( $data['asset']['context'], function ( $value, $key ) use ( &$asset ) {
- $asset['meta'][ $key ] = filter_var( $value, FILTER_SANITIZE_STRING );
- } );
+ array_walk_recursive(
+ $data['asset']['context'],
+ function ( $value, $key ) use ( &$asset ) {
+ $asset['meta'][ $key ] = filter_var( $value, FILTER_SANITIZE_STRING );
+ }
+ );
}
// Check for transformations.
$transformations = $this->get_transformations_from_string( $asset['url'] );
if ( ! empty( $transformations ) ) {
- $asset['sync_key'] .= wp_json_encode( $transformations );
+ $asset['sync_key'] .= wp_json_encode( $transformations );
$asset['transformations'] = $transformations;
}
// Attempt to find attachment ID.
@@ -1773,9 +1775,12 @@ public function maybe_overwrite_featured_image( $attachment_id ) {
*/
public function set_doing_featured( $post_id, $attachment_id ) {
$this->doing_featured_image = (int) $attachment_id;
- add_action( 'end_fetch_post_thumbnail_html', function () {
- $this->doing_featured_image = false;
- } );
+ add_action(
+ 'end_fetch_post_thumbnail_html',
+ function () {
+ $this->doing_featured_image = false;
+ }
+ );
}
/**
diff --git a/php/class-plugin.php b/php/class-plugin.php
index 4feaf3f49..a03a849f0 100644
--- a/php/class-plugin.php
+++ b/php/class-plugin.php
@@ -340,9 +340,9 @@ public function rest_dismiss_notice( \WP_REST_Request $request ) {
*/
public function admin_notices() {
/**
- * @var $components Notice[]
- *
* An array of classes that implement the Notice interface.
+ *
+ * @var $components Notice[]
*/
$components = array_filter( $this->components, array( $this, 'is_notice_component' ) );
$default = array(
@@ -520,7 +520,8 @@ public function trigger_warning( $message, $code = \E_USER_WARNING ) {
*/
public function force_visit_plugin_site_link( $plugin_meta, $plugin_file, $plugin_data, $status ) {
if ( 'Cloudinary' === $plugin_data['Name'] ) {
- $plugin_site_link = sprintf( '%s',
+ $plugin_site_link = sprintf(
+ '%s',
esc_url( $plugin_data['PluginURI'] ),
__( 'Visit plugin site' )
);
diff --git a/php/class-settings-page.php b/php/class-settings-page.php
index 48c92f464..9a18fedd7 100644
--- a/php/class-settings-page.php
+++ b/php/class-settings-page.php
@@ -310,7 +310,11 @@ public function render_field( $field, $value = null, $show_description = true )
// Place a hidden field before it, to set unchecked value to off.
?>
- pattern="" data-condition="" data-context="" >
+
+ pattern="" data-condition="" data-context="" >
get_sync_type( $attachment_id );
if ( ! empty( $sync_type ) && isset( $this->sync_base_struct[ $sync_type ] ) ) {
// check process log in case theres an error.
- $log = $this->managers['media']->get_post_meta( $attachment_id, Sync::META_KEYS['process_log'] );
+ $log = $this->managers['media']->get_post_meta( $attachment_id, self::META_KEYS['process_log'] );
if ( ! empty( $log[ $sync_type ] ) && is_wp_error( $log[ $sync_type ] ) ) {
// Use error instead of sync note.
$status['state'] = 'error';
@@ -666,7 +666,7 @@ public function filter_status( $status, $attachment_id ) {
// Check if there's an error.
- $has_error = $this->managers['media']->get_post_meta( $attachment_id, Sync::META_KEYS['sync_error'], true );
+ $has_error = $this->managers['media']->get_post_meta( $attachment_id, self::META_KEYS['sync_error'], true );
if ( ! empty( $has_error ) && $this->get_sync_type( $attachment_id ) ) {
$status['state'] = 'error';
$status['note'] = $has_error;
@@ -704,7 +704,7 @@ public function filter_media_states( $media_states, $post ) {
public function is_pending( $attachment_id ) {
// Check if it's not already in the to sync array.
if ( ! in_array( $attachment_id, $this->to_sync, true ) ) {
- $is_pending = get_post_meta( $attachment_id, Sync::META_KEYS['pending'], true );
+ $is_pending = get_post_meta( $attachment_id, self::META_KEYS['pending'], true );
if ( empty( $is_pending ) || $is_pending < time() - 5 * 60 ) {
// No need to delete pending meta, since it will be updated with the new timestamp anyway.
return false;
@@ -722,7 +722,7 @@ public function is_pending( $attachment_id ) {
public function add_to_sync( $attachment_id ) {
if ( ! in_array( $attachment_id, $this->to_sync, true ) ) {
// Flag image as pending to prevent duplicate upload.
- update_post_meta( $attachment_id, Sync::META_KEYS['pending'], time() );
+ update_post_meta( $attachment_id, self::META_KEYS['pending'], time() );
$this->to_sync[] = $attachment_id;
}
}
@@ -758,8 +758,8 @@ public function set_signature_item( $attachment_id, $type, $value = null ) {
if ( ! is_array( $meta ) ) {
$meta = array();
}
- if ( empty( $meta[ Sync::META_KEYS['cloudinary'] ] ) ) {
- $meta[ Sync::META_KEYS['cloudinary'] ] = array();
+ if ( empty( $meta[ self::META_KEYS['cloudinary'] ] ) ) {
+ $meta[ self::META_KEYS['cloudinary'] ] = array();
}
// Set the specific value.
if ( is_null( $value ) ) {
diff --git a/php/media/class-filter.php b/php/media/class-filter.php
index 2837ca47a..59e4a6c5d 100644
--- a/php/media/class-filter.php
+++ b/php/media/class-filter.php
@@ -381,7 +381,6 @@ public function filter_out_local( $content ) {
*
* @return array
* @uses filter:wp_prepare_attachment_for_js
- *
*/
public function filter_attachment_for_js( $attachment ) {
$cloudinary_id = $this->media->get_cloudinary_id( $attachment['id'] );
@@ -424,7 +423,6 @@ public function filter_attachment_for_js( $attachment ) {
*
* @return \WP_REST_Response
* @uses filter:rest_prepare_attachment
- *
*/
public function filter_attachment_for_rest( $attachment ) {
if ( ! isset( $attachment->data['id'] ) ) {
@@ -437,7 +435,8 @@ public function filter_attachment_for_rest( $attachment ) {
$attachment->data['source_url'] = $this->media->cloudinary_url( $attachment->data['id'], false );
}
- if ( $has_transformations = ! empty( $this->media->get_transformation_from_meta( $attachment->data['id'] ) ) ) {
+ $has_transformations = ! empty( $this->media->get_transformation_from_meta( $attachment->data['id'] ) );
+ if ( $has_transformations ) {
$attachment->data['transformations'] = $has_transformations;
}
diff --git a/php/media/class-upgrade.php b/php/media/class-upgrade.php
index 2345583b2..b262832f5 100644
--- a/php/media/class-upgrade.php
+++ b/php/media/class-upgrade.php
@@ -73,7 +73,7 @@ public function convert_cloudinary_version( $attachment_id ) {
$cloud_name = md5( $val );
continue;
}
- if ( in_array( $val, [ 'image', 'video', 'upload' ], true ) ) {
+ if ( in_array( $val, array( 'image', 'video', 'upload' ), true ) ) {
continue;
}
$transformation_maybe = $media->get_transformations_from_string( $val );
@@ -144,13 +144,16 @@ public function setup_hooks() {
// Add a redirection to the new plugin settings, from the old plugin.
if ( is_admin() ) {
- add_action( 'admin_menu', function () {
- global $plugin_page;
- if ( ! empty( $plugin_page ) && false !== strpos( $plugin_page, 'cloudinary-image-management-and-manipulation-in-the-cloud-cdn' ) ) {
- wp_safe_redirect( admin_url( '?page=cloudinary' ) );
- die;
- }
- } );
+ add_action(
+ 'admin_menu',
+ function () {
+ global $plugin_page;
+ if ( ! empty( $plugin_page ) && false !== strpos( $plugin_page, 'cloudinary-image-management-and-manipulation-in-the-cloud-cdn' ) ) {
+ wp_safe_redirect( admin_url( '?page=cloudinary' ) );
+ die;
+ }
+ }
+ );
}
}
}
diff --git a/php/media/class-video.php b/php/media/class-video.php
index 4064385ed..36668df46 100644
--- a/php/media/class-video.php
+++ b/php/media/class-video.php
@@ -220,7 +220,7 @@ public function filter_video_shortcode( $html, $attr ) {
if ( isset( $attr['autoplay'] ) ) {
$args['autoplay'] = 'true' === $attr['autoplay'];
- $args['muted'] = 'true' === $attr['autoplay'];
+ $args['muted'] = 'true' === $attr['autoplay'];
}
if ( isset( $attr['loop'] ) ) {
$args['loop'] = 'true' === $attr['loop'];
@@ -286,7 +286,7 @@ public function filter_video_tags( $content ) {
// Enable Autoplay for this video.
if ( false !== strpos( $tag, 'autoplay' ) ) {
$args['autoplayMode'] = $this->config['video_autoplay_mode']; // if on, use defined mode.
- $args['muted'] = 'always' === $this->config['video_autoplay_mode'];
+ $args['muted'] = 'always' === $this->config['video_autoplay_mode'];
}
// Enable Loop.
if ( false !== strpos( $tag, 'loop' ) ) {
@@ -312,7 +312,7 @@ public function filter_video_tags( $content ) {
}
$args['overwrite_transformations'] = $overwrite_transformations;
- $cloudinary_url = $this->media->cloudinary_url( $attachment_id, false, false, null, $overwrite_transformations );
+ $cloudinary_url = $this->media->cloudinary_url( $attachment_id, false, false, null, $overwrite_transformations );
// Bail replacing the video URL for cases where it doesn't exist.
// Cases are, for instance, when the file size is larger than the API limits — free accounts.
if ( ! empty( $cloudinary_url ) ) {
@@ -354,7 +354,7 @@ public function print_video_scripts() {
'loop' => 'on' === $this->config['video_loop'] ? true : false,
);
- $valid_autoplay_modes = [ 'never', 'always', 'on-scroll' ];
+ $valid_autoplay_modes = array( 'never', 'always', 'on-scroll' );
if ( $default['autoplay'] && in_array( $this->config['video_autoplay_mode'], $valid_autoplay_modes, true ) ) {
$default['autoplayMode'] = $this->config['video_autoplay_mode'];
}
@@ -365,7 +365,7 @@ public function print_video_scripts() {
$config['fluid'] = true;
}
- $config['controls'] = 'on' === $this->config['video_controls'] ? true : false;
+ $config['controls'] = 'on' === $this->config['video_controls'] ? true : false;
$cld_videos[ $instance ] = $config;
}
@@ -392,15 +392,15 @@ public function print_video_scripts() {
if ( videoElement.length === 1 ) {
videoElement = videoElement[0];
videoElement.style.width = '100%';
- config['video_freeform'] ): ?>
+ config['video_freeform'] ) : ?>
if (
- videoElement.src.indexOf( 'config['video_freeform'] ) ?>' ) === -1 &&
+ videoElement.src.indexOf( 'config['video_freeform'] ); ?>' ) === -1 &&
! cldVideos[videoInstance]['overwrite_transformations']
) {
videoElement.src = videoElement.src.replace(
'upload/',
- 'upload/config['video_freeform'] ) ?>/'
+ 'upload/config['video_freeform'] ); ?>/'
);
}
@@ -461,8 +461,7 @@ public function filter_video_block_pre_render( $block, $source_block ) {
$content = str_replace( 'class="', 'class="' . $classes . ' ', $content );
} else {
$content = str_replace( '
- disabled ) : ?>
+ disabled ) : ?>
-
+
@@ -95,8 +95,8 @@
diff --git a/ui-definitions/tabs/settings-sync-media.php b/ui-definitions/tabs/settings-sync-media.php
index 883573a84..f4c89c020 100644
--- a/ui-definitions/tabs/settings-sync-media.php
+++ b/ui-definitions/tabs/settings-sync-media.php
@@ -4,6 +4,7 @@
*
* @package Cloudinary
*/
+
$dirs = wp_get_upload_dir();
$base = wp_parse_url( $dirs['baseurl'] );
@@ -18,10 +19,10 @@
'description' => __( 'Auto Sync: Media is synchronized automatically on demand; Manual Sync: Manually synchronize assets from the Media page.', 'cloudinary' ),
'type' => 'radio',
'default' => 'on',
- 'choices' => array(
+ 'choices' => array(
'on' => __( 'Auto Sync', 'cloudinary' ),
'off' => __( 'Manual Sync', 'cloudinary' ),
- )
+ ),
),
'cloudinary_folder' => array(
'label' => __( 'Cloudinary folder path', 'cloudinary' ),
@@ -29,16 +30,16 @@
'description' => __( 'Specify the folder in your Cloudinary account where WordPress assets are uploaded to. All assets uploaded to WordPress from this point on will be synced to the specified folder in Cloudinary. Leave blank to use the root of your Cloudinary library.', 'cloudinary' ),
'sanitize_callback' => array( '\Cloudinary\Media', 'sanitize_cloudinary_folder' ),
),
- 'offload' => array(
- 'label' => __( 'Storage', 'cloudinary' ),
+ 'offload' => array(
+ 'label' => __( 'Storage', 'cloudinary' ),
'description' => sprintf(
// translators: Placeholders are tags.
__( 'Choose where to store your assets. Assets stored in both Cloudinary and WordPress will enable local WordPress delivery if the Cloudinary plugin is disabled or uninstalled. Storing assets with WordPress in lower resolution will save on local WordPress storage and enable low resolution local WordPress delivery if the plugin is disabled. Storing assets with Cloudinary only will require additional steps to enable backwards compatibility. For help managing your storage, submit a %1$s support request.%2$s', 'cloudinary' ),
'',
''
),
- 'type' => 'select',
- 'default' => 'dual_full',
+ 'type' => 'select',
+ 'default' => 'dual_full',
'choices' => array(
'dual_full' => __( 'Cloudinary and WordPress', 'cloudinary' ),
'dual_low' => __( 'Cloudinary and WordPress (low resolution)', 'cloudinary' ),
diff --git a/ui-definitions/tabs/sync-media-content.php b/ui-definitions/tabs/sync-media-content.php
index 8a5a57b09..a79351b1d 100644
--- a/ui-definitions/tabs/sync-media-content.php
+++ b/ui-definitions/tabs/sync-media-content.php
@@ -11,10 +11,10 @@
plugin->config['connect'] ) ) : ?>