Skip to content

Commit 7e817a1

Browse files
Ensure disabled assets aren't re-enabled after a plugin update
1 parent 6aa2020 commit 7e817a1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

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
*

0 commit comments

Comments
 (0)