Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
7640e0e
Merge pull request #31 from cloudinary/develop
Dec 6, 2019
b292e10
Merge pull request #33 from cloudinary/develop
Dec 9, 2019
e8b3743
Merge pull request #34 from cloudinary/develop
Dec 10, 2019
1b98653
Merge pull request #35 from cloudinary/develop
Dec 11, 2019
59c90fe
Merge pull request #36 from cloudinary/develop
Dec 18, 2019
9b10a98
Update README.md
asisayag2 Jan 23, 2020
963b7b7
Merge pull request #49 from cloudinary/uat
Mar 30, 2020
003382a
Version 2.0.0
asisayag2 Mar 31, 2020
fefd155
add screenshots
asisayag2 Mar 31, 2020
9a6a3a1
update tags in readme
asisayag2 Mar 31, 2020
2aec750
fix screenshots & icons
asisayag2 Apr 1, 2020
5490077
Merge pull request #50 from cloudinary/version2.0.0-release
asisayag2 Apr 1, 2020
2c43c80
Update readme.txt
asisayag2 Apr 1, 2020
3495303
allow retries on down sync, don't delete downsync errors.
DavidCramer Apr 2, 2020
fc6c099
set error and remove on success
DavidCramer Apr 2, 2020
e22329b
use existing error
DavidCramer Apr 2, 2020
9e5d3d0
Merge pull request #51 from cloudinary/fix/down-sync
Apr 2, 2020
9b58dbf
Merge pull request #52 from cloudinary/master
Apr 2, 2020
31bc873
Version 2.0.1
asisayag2 Apr 2, 2020
78f736c
Merge branch 'master' of github.com:cloudinary/cloudinary_wordpress
asisayag2 Apr 2, 2020
beff24e
Add check after cloudinary_id filter and see if what's filtered is ap…
Apr 2, 2020
0998e57
Merge pull request #53 from cloudinary/bug/catch-bad-cloudinary-id
Apr 2, 2020
a6a4913
Rollback to 2.0.0
Apr 2, 2020
d165786
Version 2.0.2
asisayag2 Apr 2, 2020
13e0d70
rewire to have sync both ways
DavidCramer Apr 3, 2020
d5cc953
version bump
DavidCramer Apr 3, 2020
4374b49
noneed to verify
DavidCramer Apr 3, 2020
041a3c6
capture id
DavidCramer Apr 3, 2020
26bc56e
set ID and delete correct folder
DavidCramer Apr 3, 2020
4929432
video order
DavidCramer Apr 3, 2020
fafc160
remove q_auto on videos
DavidCramer Apr 3, 2020
45d3025
typo in value
DavidCramer Apr 3, 2020
ee06184
remove signature key
DavidCramer Apr 3, 2020
4eec5ce
Merge pull request #54 from cloudinary/fix/dual-sync
Apr 3, 2020
e6e6921
Version 2.0.3
asisayag2 Apr 3, 2020
31423e8
Merge pull request #56 from cloudinary/master
Apr 9, 2020
8dc11b9
Ensure 100% width for videos.
Apr 9, 2020
e6fb492
Merge pull request #58 from cloudinary/bug/cut-video
Apr 14, 2020
8f9c58a
Add check to see whether transformation is already applied
Apr 14, 2020
2359228
Simplify cache rebuild based on version update.
DavidCramer Apr 15, 2020
b072e06
add actual sync_key to uploaded items as well as down synced.
DavidCramer Apr 15, 2020
a7459d2
add video front-end style overrides
DavidCramer Apr 15, 2020
ef5785d
update readme for 5.4 support
DavidCramer Apr 15, 2020
3552218
remove green check
DavidCramer Apr 15, 2020
f88cb82
Merge pull request #60 from cloudinary/bug/duplicate-transformation-s…
Apr 15, 2020
a0e3b74
Merge pull request #61 from cloudinary/fix/CLOUD-384
Apr 15, 2020
97901ee
Merge pull request #63 from cloudinary/feature/CLOUD-382
Apr 15, 2020
4f93499
Merge pull request #64 from cloudinary/feature/CLOUD-367
Apr 15, 2020
c67a737
merge develop
DavidCramer Apr 15, 2020
5125df6
Merge pull request #62 from cloudinary/fix/CLOUD-376
Apr 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ Stay tuned for updates, tips and tutorials: [Blog](http://cloudinary.com/blog),

## License #######################################################################

Released under the MIT license.
Released under the GPL license.


Binary file removed assets/banner-772x250.jpg
Binary file not shown.
Binary file added assets/banner-772x250.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/icon-128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/icon-256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/screenshot-1.jpg
Binary file not shown.
Binary file added assets/screenshot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/screenshot-2.jpg
Binary file not shown.
Binary file added assets/screenshot-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/screenshot-3.jpg
Binary file not shown.
Binary file added assets/screenshot-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/screenshot-4.jpg
Binary file not shown.
Binary file added assets/screenshot-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/screenshot-5.jpg
Binary file not shown.
Binary file added assets/screenshot-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/screenshot-6.jpg
Binary file not shown.
Binary file added assets/screenshot-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshot-7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshot-8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshot-9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Cloudinary
* Plugin URI: https://cloudinary.com/documentation/wordpress_integration
* Description: With the Cloudinary plugin, you can upload and manage your media assets in the cloud, then deliver them to your users through a fast content delivery network, improving your website’s loading speed and overall user experience. Apply multiple transformations and take advantage of a full digital asset management solution without leaving WordPress.
* Version: 2.0.0
* Version: 2.0.3
* Author: Cloudinary Ltd., XWP
* Author URI: https://cloudinary.com/
* License: GPLv2+
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Frontend video styles.
.cld {
&-video {
&-player {
max-width: 100%;
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.cld-video-player{max-width:100%}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Cloudinary\Component\Config;
use Cloudinary\Component\Notice;
use Cloudinary\Component\Setup;
use Cloudinary\Connect\API;

/**
* Cloudinary connection class.
Expand Down Expand Up @@ -302,25 +301,33 @@ public function setup() {
*/
public function get_config() {
$signature = get_option( 'cloudinary_connection_signature', null );
if ( empty( $signature ) ) {
// Check if theres a previous version.
$version = get_option( 'cloudinary_version' );
if ( version_compare( $this->plugin->version, $version, '>' ) ) {
$version = get_option( 'cloudinary_version' );
if ( empty( $signature ) || version_compare( $this->plugin->version, $version, '>' ) ) {
// Check if there's a previous version, or missing signature.
$cld_url = get_option( 'cloudinary_url', null );
if ( is_null( $cld_url ) ) {
// Post V1.
$data = get_option( 'cloudinary_connect', array() );
if ( ! isset( $data['cloudinary_url'] ) || empty( $data['cloudinary_url'] ) ) {
return null; // return null to indicate not valid.
}
} else {
// from V1 to V2.
$data = array(
'cloudinary_url' => get_option( 'cloudinary_url' ),
'cloudinary_url' => $cld_url,
);
$test = $this->test_connection( $data['cloudinary_url'] );
if ( 'connection_success' === $test['type'] ) {
$signature = md5( $data['cloudinary_url'] );

// remove filters as we've already verified it and 'add_settings_error()' isin't available yet.
remove_filter( 'pre_update_option_cloudinary_connect', array( $this, 'verify_connection' ) );
update_option( 'cloudinary_connect', $data );
update_option( 'cloudinary_connection_signature', $signature );
update_option( 'cloudinary_version', $this->plugin->version );
delete_option( 'cloudinary_settings_cache' ); // remove the cache.
$this->plugin->config['settings']['connect'] = $data; // Set the connection url for this round.
}
}
$test = $this->test_connection( $data['cloudinary_url'] );
if ( 'connection_success' === $test['type'] ) {
$signature = md5( $data['cloudinary_url'] );

// remove filters as we've already verified it and 'add_settings_error()' isin't available yet.
remove_filter( 'pre_update_option_cloudinary_connect', array( $this, 'verify_connection' ) );
update_option( 'cloudinary_connect', $data );
update_option( 'cloudinary_connection_signature', $signature );
update_option( 'cloudinary_version', $this->plugin->version );
delete_option( 'cloudinary_settings_cache' ); // remove the cache.
$this->plugin->config['settings']['connect'] = $data; // Set the connection url for this round.
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ public function apply_default_transformations( array $transformations, $type = '
$global = $this->global_transformations->globals[ $type ];
$default = array();
if ( 'video' === $type ) {
$default['quality'] = 'auto';
if ( isset( $global['video_limit_bitrate'] ) && 'on' === $global['video_limit_bitrate'] ) {
$default['bit_rate'] = $global['video_bitrate'] . 'k';
}
Expand Down Expand Up @@ -1007,7 +1006,7 @@ public function down_sync_asset() {
}
$transformations = $this->get_transformations_from_string( $url );
if ( ! empty( $transformations ) ) {
$sync_key .= wp_json_encode( $transformations );
$sync_key .= wp_json_encode( $transformations );
$asset['transformations'] = $transformations;
}
// Check Format and url extension.
Expand Down Expand Up @@ -1229,6 +1228,14 @@ public function get_post_meta( $post_id, $key, $single = false ) {
$data = $this->build_cached_meta( $post_id, $key, $single );
}

// If public_id, ensure there's a sync_key saved.
if ( '_public_id' === $key && empty( $meta_data[ Sync::META_KEYS['cloudinary'] ]['_sync_key'] ) ) {

//$sync_key = '_' . md5( $data );
//$this->update_post_meta( $post_id, '_sync_key', $sync_key );
//update_post_meta( $post_id, $sync_key, true ); // Set sync_key.
}

return $data;
}

Expand All @@ -1243,17 +1250,19 @@ public function get_post_meta( $post_id, $key, $single = false ) {
*/
public function build_cached_meta( $post_id, $key, $single ) {
$data = get_post_meta( $post_id, $key, $single );
$this->update_post_meta( $post_id, $key, $data );
if ( '' !== $data ) {
$this->update_post_meta( $post_id, $key, $data );
}

return $data;
}

/**
* Update cloudinary metadata.
*
* @param int $post_id The attachment ID.
* @param string $key The meta key to get.
* @param array $data $the meta data to update.
* @param int $post_id The attachment ID.
* @param string $key The meta key to get.
* @param string|array $data $the meta data to update.
*/
public function update_post_meta( $post_id, $key, $data ) {
$meta_data = wp_get_attachment_metadata( $post_id, true );
Expand All @@ -1266,6 +1275,23 @@ public function update_post_meta( $post_id, $key, $data ) {
update_post_meta( $post_id, $key, $data );
}

/**
* Delete cloudinary metadata.
*
* @param int $post_id The attachment ID.
* @param string $key The meta key to get.
*/
public function delete_post_meta( $post_id, $key ) {
$meta_data = wp_get_attachment_metadata( $post_id, true );
if ( is_array( $meta_data ) && isset( $meta_data[ Sync::META_KEYS['cloudinary'] ] ) && is_array( $meta_data[ Sync::META_KEYS['cloudinary'] ] ) ) {
// Only do this side if has been set before.
unset( $meta_data[ Sync::META_KEYS['cloudinary'] ][ $key ] );
wp_update_attachment_metadata( $post_id, $meta_data );
}
// Delete meta data.
delete_post_meta( $post_id, $key );
}

/**
* Setup the hooks and base_url if configured.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,20 @@ public function background_request( $endpoint, $params, $method = 'POST' ) {
// Setup a call for a background sync.
$params['nonce'] = wp_create_nonce( 'wp_rest' );
$args = array(
'timeout' => 1,
'blocking' => false,
'method' => $method,
'headers' => array(),
'body' => $params,
'timeout' => 1,
'blocking' => false,
'sslverify' => false,
'method' => $method,
'headers' => array(),
'body' => $params,
);
if ( is_user_logged_in() ) {
// Setup cookie.
$logged_cookie = wp_parse_auth_cookie( '', 'logged_in' );
array_pop( $logged_cookie ); // remove the scheme.

// Add logged in cookie to request.
$args['cookies'] = array(
$args['cookies'] = array(
new \WP_Http_Cookie(
array(
'name' => LOGGED_IN_COOKIE,
Expand All @@ -85,8 +86,9 @@ public function background_request( $endpoint, $params, $method = 'POST' ) {
$url
),
);
$args['headers']['X-WP-Nonce'] = $params['nonce'];

}
$args['headers']['X-WP-Nonce'] = $params['nonce'];

// Send request.
wp_safe_remote_request( $url, $args );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public function check_cloudinary_version( $cloudinary_id, $attachment_id ) {
*/
if ( ! empty( $meta['cloudinary'] ) && empty( $public_id ) ) {
$cloudinary_id = $this->convert_cloudinary_version( $attachment_id );
} elseif ( ! empty( $public_id ) ) {
// Has public ID, but not fully down synced.
$cloudinary_id = $public_id;
}
}

Expand Down Expand Up @@ -103,29 +106,19 @@ function ( $val ) use ( $media ) {
// Remove extension.
$path = pathinfo( $public_id );
$public_id = strstr( $public_id, '.' . $path['extension'], true );
// Save public ID.
$this->media->update_post_meta( $attachment_id, Sync::META_KEYS['public_id'], $public_id );

// Setup a call for a background sync.
$params = array(
'attachment_id' => $attachment_id,
'src' => $file,
'transformations' => $media->get_transformations_from_string( $file ),
'filename' => basename( $file ),
);
$media->plugin->components['api']->background_request( 'asset', $params );

return $public_id;
}

/**
* Setup hooks for the filters.
*/
public function setup_hooks() {
add_filter( 'cloudinary_id', array( $this, 'check_cloudinary_version' ), 9, 2 ); // Priority 9, to take preference over prep_on_demand_upload.
add_filter( 'cloudinary_id', array( $this, 'check_cloudinary_version' ), 10, 2 ); // Priority 10, to allow prep_on_demand_upload.

// Add a redirection to the new plugin settings, from the old plugin.
if( is_admin() ) {
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' ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public function init_player() {
if ( ! empty( $has_video ) || ! empty( $video_tags ) ) {
// Setup initial scripts.
wp_enqueue_style( 'cld-player' );
wp_enqueue_style( 'cld-player-local' );
wp_enqueue_script( 'cld-player' );

// Init cld script object.
Expand Down Expand Up @@ -369,29 +370,31 @@ public function print_video_scripts() {
var cldVideos = <?php echo wp_json_encode( $cld_videos ); ?>;

for ( var videoInstance in cldVideos ) {
var cldConfig = cldVideos[ videoInstance ];
var cldId = 'cloudinary-video-' + videoInstance;
cld.videoPlayer( cldId, cldConfig );
var cldConfig = cldVideos[ videoInstance ];
var cldId = 'cloudinary-video-' + videoInstance;
cld.videoPlayer( cldId, cldConfig );
}

window.addEventListener( 'load', function() {
for ( var videoInstance in cldVideos ) {
var cldId = 'cloudinary-video-' + videoInstance;
var videoContainer = document.getElementById( cldId );
var videoElement = videoContainer.getElementsByTagName( 'video' );

if ( videoElement.length === 1 ) {
videoElement = videoElement[0];


<?php if ( $this->config['video_freeform'] ): ?>
videoElement.src = videoElement.src.replace(
'upload/',
'upload/<?php echo esc_js( $this->config['video_freeform'] ) ?>/'
);
<?php endif ?>
}
}
for ( var videoInstance in cldVideos ) {
var cldId = 'cloudinary-video-' + videoInstance;
var videoContainer = document.getElementById( cldId );
var videoElement = videoContainer.getElementsByTagName( 'video' );

if ( videoElement.length === 1 ) {
videoElement = videoElement[0];
videoElement.style.width = '100%';

<?php if ( $this->config['video_freeform'] ): ?>
if ( videoElement.src.indexOf( '<?php echo esc_js( $this->config['video_freeform'] ) ?>' ) === -1 ) {
videoElement.src = videoElement.src.replace(
'upload/',
'upload/<?php echo esc_js( $this->config['video_freeform'] ) ?>/'
);
}
<?php endif ?>
}
}
} );
<?php
$script = ob_get_clean();
Expand All @@ -414,8 +417,10 @@ public function enqueue_block_assets() {
/**
* Register assets for the player.
*/
public static function register_scripts_styles() {
public function register_scripts_styles() {
wp_register_style( 'cld-player', 'https://unpkg.com/cloudinary-video-player@' . self::PLAYER_VER . '/dist/cld-video-player.min.css', null, self::PLAYER_VER );
wp_register_style( 'cld-player-local', $this->media->plugin->dir_url . 'css/video.css', null, self::PLAYER_VER );

wp_register_script( 'cld-core', 'https://unpkg.com/cloudinary-core@' . self::CORE_VER . '/cloudinary-core-shrinkwrap.min.js', null, self::CORE_VER, true );
wp_register_script( 'cld-player', 'https://unpkg.com/cloudinary-video-player@' . self::PLAYER_VER . '/dist/cld-video-player.min.js', array( 'cld-core' ), self::PLAYER_VER, true );
}
Expand All @@ -427,13 +432,13 @@ public function setup_hooks() {
add_filter( 'wp_video_shortcode_override', array( $this, 'filter_video_shortcode' ), 10, 2 );
// only filter video tags in front end.
if ( ! is_admin() ) {
add_filter( 'the_content', array( $this, 'filter_video_tags' ), 10 );
add_filter( 'the_content', array( $this, 'filter_video_tags' ), 4 );
}
add_action( 'wp_print_styles', array( $this, 'init_player' ) );
add_action( 'wp_footer', array( $this, 'print_video_scripts' ) );

// Add inline scripts for gutenberg.
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_assets' ) );
self::register_scripts_styles();
$this->register_scripts_styles();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function delete_asset( $post_id ) {
}
// Next we need to check that the file is in the cloudinary folder.
$parts = explode( '/', $public_id );
$cloudinary_folder = $this->plugin->config['settings']['general']['cloudinary_folder'];
$cloudinary_folder = $this->plugin->config['settings']['sync_media']['cloudinary_folder'] ? $this->plugin->config['settings']['sync_media']['cloudinary_folder'] : '';
if ( $cloudinary_folder === $parts[0] ) {
$type = $this->plugin->components['sync']->managers['push']->get_resource_type( $post_id );
$options = array(
Expand Down
Loading