I've been trying to write a plugin that adds a checkbox (below the "Open in New Window/Tab" checkbox) to the Custom Menu pages/links. I've been able to add the Checkbox and change the
wp-includes/nav-menu-template.php file accordingly so that when the checkbox is ticked, it disables the link and just posts the item as an
<li> without the
<a href="..."> ... </a> tag.
However, I can't seem to get the checkbox to save it's answer for each individual item: I tick the box, press save, and it just reverts to being unticked again. Here is my code:
<p class="field-disable-link description"> <label for="edit-menu-item-disable-link-<?php echo $item_id; ?>"> <input type="checkbox" id="edit-menu-item-disable-link-<?php echo $item_id; ?>" value="" name="menu-item-disable-link[<?php echo $item_id; ?>]"<?php checked( $item->disablelink, "" ); ?> /> <?php _e( 'Disable Link in Menu' ); ?> </label> </p>
I have also added the
menu-item-disable-link in all the places in the
wp-admin/nav-menu.php file, as below (for now, I have been editing the core files - I know this is a bad practice but right now, just as a proof of concept I have been doing it this way. If I am successful, I will create a plugin for it and return the core files to their original state):
(about line 332): $output .= '<input type="hidden" class="menu-item-disable-link" name="menu-item[' . $possible_object_id . '][menu-item-disable-link]" value="'. esc_attr( $item->disablelink ) .'" />'; (about line 1100): 'menu-item-disable-link' => ( isset( $_item_object_data['menu-item-disable-link'] ) ? $_item_object_data['menu-item-disable-link'] : '' ) (about line 1231): 'disable-link' => __('Disable Link') (about line 1278): ..., 'menu-item-disable-link', ...
If I change the second parameter of
<?php checked( $item->disablelink, false ); ?>), all the checkboxes will now be ticked in each one, disabling the links on the front-end menu. However, if I try to untick them and then save, it just reverts back to being ticked (essentially the opposite of the above i.e tick them, save -> unticked).
I think the problem lies in that
$item->disablelink doesn't exist, where-as things like
$item->target (another checkbox in the Custom Menu pages which defines if it opens in a new window/tab or not), does. When the target checkbox is ticked, the value of
$item->target changes to
_blank. What I need is a true/false variable where if it's ticked it's true and unticked is false.
Please forgive me if I've made any horrendous mistakes, I am a WordPress developer but I haven't done much delving around in the core files so I don't really know how they work. Also, for reasons I can't go into here (client issues) I can't use a Custom Menu Item with no link, so I have to develop this and I couldn't find a suitably light-weight plugin to do so.
Thanks for any help :)