Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.0
3.1.1
36 changes: 23 additions & 13 deletions php/class-delivery.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,12 @@ public function generate_signature( $attachment_id ) {
if ( ! $sql ) {
$sql = Utils::get_table_sql();
}
$public_id = null;
$relationship = Relationship::get_relationship( $attachment_id );
if ( $relationship instanceof Relationship ) {
$public_id = $relationship->public_id;
}
$sizes = $this->get_sized( $attachment_id );
$public_id = $this->media->has_public_id( $attachment_id ) ? $this->media->get_public_id( $attachment_id ) : null;
$settings_signature = self::get_settings_signature();
$relation_signature = $this->media->get_post_meta( $attachment_id, Sync::META_KEYS['relationship'], true );

Expand Down Expand Up @@ -480,8 +484,6 @@ public function unsync_size_relationship( $attachment_id ) {
self::update_size_relations_public_id( $attachment_id, null );
self::update_size_relations_state( $attachment_id, 'disable' );
self::update_size_relations_transformations( $attachment_id, null );

do_action( 'cloudinary_flush_cache' );
}

/**
Expand Down Expand Up @@ -521,12 +523,13 @@ public function get_sized( $attachment_id ) {
*/
public static function update_size_relations_public_id( $attachment_id, $public_id ) {
$relationship = Relationship::get_relationship( $attachment_id );
$relationship->public_id = $public_id;
$relationship->public_hash = md5( $public_id );
$relationship->signature = self::get_settings_signature();
$relationship->save();

do_action( 'cloudinary_flush_cache' );
if ( $relationship instanceof Relationship ) {
$relationship->public_id = $public_id;
$relationship->public_hash = md5( $public_id );
$relationship->signature = self::get_settings_signature();
$relationship->save();
}
}

/**
Expand All @@ -537,8 +540,11 @@ public static function update_size_relations_public_id( $attachment_id, $public_
*/
public static function update_size_relations_state( $attachment_id, $state ) {
$relationship = Relationship::get_relationship( $attachment_id );
$relationship->post_state = $state;
$relationship->save();

if ( $relationship instanceof Relationship ) {
$relationship->post_state = $state;
$relationship->save();
}

do_action( 'cloudinary_flush_cache' );
}
Expand All @@ -551,7 +557,6 @@ public static function update_size_relations_state( $attachment_id, $state ) {
*/
public static function update_size_relations_transformations( $attachment_id, $transformations ) {
Relate::update_transformations( $attachment_id, $transformations );
do_action( 'cloudinary_flush_cache' );
}

/**
Expand Down Expand Up @@ -700,11 +705,16 @@ public function clear_cache() {
/**
* Delete cached metadata.
*
* @param bool $hard Whether to hard flush the cache.
*
* @hook cloudinary_flush_cache
*/
public function do_clear_cache() {
public function do_clear_cache( $hard = true ) {
delete_post_meta_by_key( self::META_CACHE_KEY );
wp_cache_flush();

if ( $hard ) {
wp_cache_flush();
}
}

/**
Expand Down
25 changes: 23 additions & 2 deletions php/relate/class-relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

/**
* Class Relationship
*
* @property string|null $post_state
* @property string|null $public_hash
* @property string|null $public_id
* @property string|null $signature
* @property string|null $transformations
*/
class Relationship {

Expand Down Expand Up @@ -105,6 +111,7 @@ public function save() {
if ( ! $this->save_on_shutdown ) {
$this->save_on_shutdown = true;
add_action( 'shutdown', array( $this, 'do_save' ) );
add_action( 'shutdown', array( $this, 'flush_cache' ), 100 );
}
}

Expand All @@ -115,9 +122,23 @@ public function save() {
*/
public function do_save() {
global $wpdb;
$data = $this->get_data();
$data = $this->get_data();
$update = false;

if ( ! empty( $data['id'] ) ) {
$update = $wpdb->update( Utils::get_relationship_table(), $data, array( 'id' => $data['id'] ), array( '%s' ), array( '%d' ) );// phpcs:ignore WordPress.DB
}

return $update;
}

return $wpdb->update( Utils::get_relationship_table(), $data, array( 'id' => $data['id'] ), array( '%s' ), array( '%d' ) );// phpcs:ignore WordPress.DB
/**
* Flush the cache.
*
* @return void
*/
public function flush_cache() {
do_action( 'cloudinary_flush_cache', false );
}

/**
Expand Down
9 changes: 8 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,14 @@ Your site is now setup to start using Cloudinary.

== Changelog ==

= 3.1 (22 FEBRUARY 2022) =
= 3.1.1 (06 MARCH 2023) =

Fixes and Improvements:

* Fixed the *Add transformation* on the media library for newly added assets
* Fixed PHP warning in error log after upgrading to PHP 8/8.X

= 3.1 (22 FEBRUARY 2023) =

Fixes and Improvements:

Expand Down