• Resolved jrvcosta

    (@jrvcosta)


    The OneSignal plugin always adds fields in postmeta (like ‘onesignal_meta_box_present’) and sometimes these fields are empty even when we just update a post. So I ask if it’s safe to use a filter, like the one below, to automatically delete when these fields are empty.

    add_filter('update_post_metadata', function($check, $object_id, $meta_key, $meta_value, $prev_value) {
        if(strpos($meta_key, 'onesignal_send_notification') || strpos($meta_key, 'onesignal_meta_box_present') || strpos($meta_key, 'onesignal_modify_title_and_content') || strpos($meta_key, 'onesignal_notification_custom_content') || strpos($meta_key, 'onesignal_notification_custom_heading')) {
            if(empty($meta_value)) {
                delete_post_meta($object_id, $meta_key, $prev_value);
                return true; 
            }
        }
        return null;  
    }, 10, 5);

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Is it safe to delete these empty postmeta?’ is closed to new replies.