Adding custom fields to WordPress nav menus

I’m added new custom checkbox field to the nav menu items. the check box added without any problem when i check it it’s work but when i want uncheck it not work and stay in checked state.

the code below show the steps to create the checkbox custom field>

it is contains any error?

first i created check box key within database

function YPE_setup_custom_fields($item) {
    $item->divider = get_post_meta($item->ID, '_menu_item_divider', true);
add_filter('wp_setup_nav_menu_item', 'YPE_setup_custom_fields');

then i created the update value for it

function YPE_update_custom_fields($menu_id, $menu_item_db_id, $menu_item_data) {
    if (is_array($_REQUEST['menu-item-divider'])) {
        $YPE_divider_value = $_REQUEST['menu-item-divider'][$menu_item_db_id];
        update_post_meta($menu_item_db_id, '_menu_item_divider', $YPE_divider_value);
add_action('wp_update_nav_menu_item', 'YPE_update_custom_fields', 10, 3);

then i created the new (Walker_Nav_Menu_Edit_Custom) class

function YPE_edit_custom_walker($walker, $item_id) {
    return 'Walker_Nav_Menu_Edit_Custom';
add_filter('wp_edit_nav_menu_walker', 'YPE_edit_custom_walker', 10, 2);

then i added the check box within my new class (Walker_Nav_Menu_Edit_Custom)

<p class="field-link-divider description">
    <label for="edit-menu-item-divider-<?php echo $item_id; ?>">
        <input type="checkbox" id="edit-menu-item-divider-<?php echo $item_id; ?>" value="_blank" name="menu-item-divider[<?php echo $item_id; ?>]"<?php checked( $item->divider, '_blank' ); ?> />
        <?php _e( 'Show divider' ); ?>

Solutions Collecting From Web of "Adding custom fields to WordPress nav menus"

After some search for solving this problem i found the correct answer for solving this problem in update meta box values specially in checkbox a little bit different from other Html input tags such us text , select tags

when we use update_post_meta box values for checked checkbox. must in the same time we use update_post_meta for unchecking of checkbox value

i solved my problem such as below. only i deleted post meta when i uncheck the checkbox value

function YPE_update_custom_fields($menu_id, $menu_item_db_id, $menu_item_data) {
if (is_array($_REQUEST['menu-item-divider'])) {
    $YPE_divider_value = ;
    update_post_meta($menu_item_db_id, '_menu_item_divider', $_REQUEST['menu-item-divider'][$menu_item_db_id]);
} else {
    delete_post_meta($menu_item_db_id, '_menu_item_divider');
add_action('wp_update_nav_menu_item', 'YPE_update_custom_fields', 10, 3);