function my_picu_maybe_close_collection( $collection_id, $ident ) {
$all_approved = true;
$clients = get_post_meta( $collection_id, '_picu_collection_hashes', true );
foreach( $clients as $ident => $client ) {
if ( $client['status'] != 'approved' ) {
$all_approved = false;
}
}
if ( $all_approved ) {
wp_update_post( [
'ID' => $collection_id,
'post_status' => 'approved'
] );
if ( function_exists( 'picu_update_collection_history' ) ) {
picu_update_collection_history( $collection_id, 'approved' );
}
}
}
add_action( 'picu_after_approval', 'my_picu_maybe_close_collection', 10, 2 );
Code language: PHP (php)