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
4 changes: 2 additions & 2 deletions php/assets/class-rest-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ public function rest_handle_state( $request ) {
$state = $request['state'];
foreach ( $ids as $id ) {
$where = array(
'post_id' => $id,
'post_state' => 'asset',
'post_id' => $id,
'sync_type' => 'asset',
);
if ( 'delete' === $state ) {
$data = array(
Expand Down
23 changes: 23 additions & 0 deletions php/class-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,32 @@ public function can_sync( $can, $asset_id ) {
$can = false;
}

// If the asset is set to a 'disable' state, we do not allow syncing.
if ( $can && self::is_asset_type( $asset_id ) && $this->is_disable_state( $asset_id ) ) {
$can = false;
}

return $can;
}

/**
* Verify if the asset is set to a 'disable' state.
*
* @param int $asset_id The asset ID to check.
*
* @return bool
*/
protected function is_disable_state( $asset_id ) {
global $wpdb;

$wpdb->cld_table = Utils::get_relationship_table();
$media_context = Utils::get_media_context( $asset_id );
$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
$state = $wpdb->get_var( $prepare ); // phpcs:ignore WordPress.DB

return 'disable' === $state;
}

/**
* Check if the post is a asset post type.
*
Expand Down
5 changes: 5 additions & 0 deletions php/class-delivery.php
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,11 @@ public function convert_tags( $content, $context = 'view' ) {
if ( empty( $relation['public_id'] || $url === $relation['public_id'] ) ) {
continue; // We don't need the public_id relation item.
}

if ( 'disable' === $relation['post_state'] ) {
continue; // We should not deliver disabled items.
}

$base = $type . ':' . $url;
$public_id = ! is_admin() ? $relation['public_id'] . '.' . $relation['format'] : null;
$cloudinary_url = $this->media->cloudinary_url( $relation['post_id'], array(), $relation['transformations'], $public_id );
Expand Down