Support General Using Custom Attributes from rwmb_before_save_post action Reply To: Using Custom Attributes from rwmb_before_save_post action

#8926
Anh TranAnh Tran
Keymaster

Hello,

I've just added rwmb_after_save_field hook, that can help you ease the pain 🙂

Here is the code using it:

add_action( 'rwmb_after_save_field', function ( $null, $field, $new, $old, $post_id ) {
	$pre = '';
	if ( ! empty( $field['attributes']['mod_lock'] ) ) {
		$pre = 'pending_';
	}
	$storage = $field['storage'];

	if ( $new !== $old ) {
		$storage->update( $post_id, $pre . $field['id'], $new );
	}

	if ( empty( $new ) ) {
		$storage->delete( $post_id, $pre . $field['id'] );
	}
}, 10, 5 );