Skip to content

Commit 14d3ee4

Browse files
Merge pull request #1084 from cloudinary/fix-disable-additional-assets
Fix the feature to disable additional assets
2 parents 53e18ee + 7e817a1 commit 14d3ee4

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

php/assets/class-rest-assets.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ public function rest_handle_state( $request ) {
258258
$state = $request['state'];
259259
foreach ( $ids as $id ) {
260260
$where = array(
261-
'post_id' => $id,
262-
'post_state' => 'asset',
261+
'post_id' => $id,
262+
'sync_type' => 'asset',
263263
);
264264
if ( 'delete' === $state ) {
265265
$data = array(

php/class-assets.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,32 @@ public function can_sync( $can, $asset_id ) {
273273
$can = false;
274274
}
275275

276+
// If the asset is set to a 'disable' state, we do not allow syncing.
277+
if ( $can && self::is_asset_type( $asset_id ) && $this->is_disable_state( $asset_id ) ) {
278+
$can = false;
279+
}
280+
276281
return $can;
277282
}
278283

284+
/**
285+
* Verify if the asset is set to a 'disable' state.
286+
*
287+
* @param int $asset_id The asset ID to check.
288+
*
289+
* @return bool
290+
*/
291+
protected function is_disable_state( $asset_id ) {
292+
global $wpdb;
293+
294+
$wpdb->cld_table = Utils::get_relationship_table();
295+
$media_context = Utils::get_media_context( $asset_id );
296+
$prepare = $wpdb->prepare( "SELECT `post_state` FROM $wpdb->cld_table WHERE post_id = %d AND media_context = %s;", (int) $asset_id, $media_context ); // phpcs:ignore WordPress.DB.PreparedSQL
297+
$state = $wpdb->get_var( $prepare ); // phpcs:ignore WordPress.DB
298+
299+
return 'disable' === $state;
300+
}
301+
279302
/**
280303
* Check if the post is a asset post type.
281304
*

php/class-delivery.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,11 @@ public function convert_tags( $content, $context = 'view' ) {
10691069
if ( empty( $relation['public_id'] || $url === $relation['public_id'] ) ) {
10701070
continue; // We don't need the public_id relation item.
10711071
}
1072+
1073+
if ( 'disable' === $relation['post_state'] ) {
1074+
continue; // We should not deliver disabled items.
1075+
}
1076+
10721077
$base = $type . ':' . $url;
10731078
$public_id = ! is_admin() ? $relation['public_id'] . '.' . $relation['format'] : null;
10741079
$cloudinary_url = $this->media->cloudinary_url( $relation['post_id'], array(), $relation['transformations'], $public_id );

0 commit comments

Comments
 (0)