DEPRECATED: Should redirect to https://wppopupmaker.com/docs/navigation-menu-editor/i-dont-see-the-trigger-a-popup-option-in-appearance-menus/ #
Problem Description #
A site theme or plugin can change the behavior of the default WordPress navigation menu editor. Symptoms may include missing menu editor capabilities that were present before Popup Maker was installed and activated.
Problem Explanation #
WordPress does not include a way to add custom fields to the menu editor. However, WordPress allows you to override the PHP class that creates the menu editor. Only one plugin or theme at a time is allowed to override this class.
The most common solution is to copy the Walker_Nav_Menu_Edit
class from WordPress, and add it to your theme or plugin where you intend to place custom fields in the menu editor. When another plugin or theme tries to add a custom field by replacing this Class, the first custom field added to the menu editor by the previous theme or plugin will no longer appear.
The solutions presented below were created several years back, and work with dozens of plugins that modify the WordPress menu editor. These solutions are currently used in roughly 30 plugins available in the WordPress.org plugin repository and dozens of themes, as well as by many premium (paid) plugins sold on Code Canyon.
The solution makes one change to the Class used to override the Walker_Nav_Menu_Edit
class in WordPress core. It adds an action hook ( do_action()
) so that Popup Maker can add custom fields to a menu editor using add_action()
. The solution allows other plugins or themes to do the same within their codebase.
We recommend that you contact your theme or plugin author, and request that they update their code. This is the preferred solution because it can allow users of that theme (or plugin) to also use other plugins that include User Menus, Nav Menu Roles, and If Menu.
The solutions below are backward compatible with WordPress version 3.0 and work work with the current WordPress version.
Solution #1: Disable the Popups Menu Editor Feature via the Popup Maker Admin #
Follow these steps to disable the Popup Maker Menu Editor.
1. From your WordPress admin area, go to Popup Maker > Settings > Misc
2. Click Disable Popups Menu Editor
Note: A Popup Maker ‘Click Open’ trigger can still be set on a navigation link, even when the popup menu editor feature is turned off. See the related article link below. Refer to either method 1 or 3 to set a trigger.
Related article: Trigger: Click Open — Overview & Methods
Solution #2: Edit the WP_Edit_Nav_Menu_Walker Filter in a Theme or Plugin #
1. In your theme or plugin, register the callback shown below to the current wp_edit_nav_menu_walker
filter from WordPress. [ The filter is located in WordPress Core at ‘/wp-admin/includes/nav-menu.php’ within the function wp_get_nav_menu_to_edit( $menu_id = 0 )
. ] Change the file paths as needed.
<?php function custom_nav_menu_walker( $walker ) { global $wp_version; // Here to prevent false warnings from If Menu and plugins that notify you of nav menu walker replacement. if ( doing_filter( 'plugins_loaded' ) ) { return $walker; } // Return early if another plugin/theme is using the same custom fields walker we are. We are already compatible. if ( $walker == 'Walker_Nav_Menu_Edit_Custom_Fields' ) { return $walker; } // Load the proper walker class based on current WP version. if ( ! class_exists( 'Walker_Nav_Menu_Edit_Custom_Fields' ) ) { if ( version_compare( $wp_version, '3.6', '>=' ) ) { require_once 'menus/class-nav-menu-edit-custom-fields.php'; } else { require_once 'menus/class-nav-menu-edit-custom-fields-deprecated.php'; } } return 'Walker_Nav_Menu_Edit_Custom_Fields'; }
View the source on GitHub.
2. Include the following files/classes to your plugin into the paths from the function above. Do not rename the classes. There are ample checks to prevent them from being reloaded if they exist already. Keeping these names ensures long-term compatibility for all plugins using them.
To view the code used to implement this solution, refer to our plugin repository on GitHub.
3. Move your custom Nav Menu Editor fields (without modification) to a new function hooked as seen below.
<?php add_action( 'wp_nav_menu_item_custom_fields', '_my_custom_nav_menu_fields', 10, 4 ); /** * Add custom fields to WordPress navigation menu * * @since 1.0.0 * * @param $item_id * @param $item object * @param $depth * @param $args * * @return void */ function _my_custom_nav_menu_fields( $item_id, $item, $depth, $args ) { wp_nonce_field( 'pum-menu-editor-nonce', 'pum-menu-editor-nonce' ); ?> <p class="field-popup_id description description-wide"> <label for="edit-menu-item-popup_id-<?php echo $item->ID; ?>"> <?php _e( 'Trigger a Popup', 'popup-maker' ); ?><br /> <select name="menu-item-pum[<?php echo $item->ID; ?>][popup_id]" id="edit-menu-item-popup_id-<?php echo $item->ID; ?>" class="widefat edit-menu-item-popup_id"> <option value=""></option> <?php foreach ( PUM_Modules_Menu::popup_list() as $option => $label ) : ?> <option value="<?php echo $option; ?>" <?php selected( $option, $item->popup_id ); ?>> <?php echo esc_html( $label ); ?> </option> <?php endforeach; ?> </select> <span class="description"><?php _e( 'Choose a popup to trigger when this item is clicked.', 'popup-maker' ); ?></span> </label> </p> <?php }
View the source on GitHub.
4. As a bonus, you can include an option to show/hide specific fields the same way WP Core does in the Nav Editor.
<?php // Note: Priority of 11 is important, as WordPress overwrites anything before that. add_filter( 'manage_nav-menus_columns', '_my_nav_menu_columns', 11 ); /** * Description. * * @since 1.0.0 * * @param array $columns * * @return array */ function _my_nav_menu_columns( $columns = array() ) { $columns['popup_id'] = __( 'Popup', 'popup-maker' ); return $columns; }
View the source on GitHub.