[wp-trac] [WordPress Trac] #49500: WordPress 5.4 messes up custom fields added to menu items they are duplicated.
WordPress Trac
noreply at wordpress.org
Mon Feb 24 13:51:13 UTC 2020
#49500: WordPress 5.4 messes up custom fields added to menu items they are
duplicated.
--------------------------+------------------------------
Reporter: BackuPs | Owner: audrasjb
Type: defect (bug) | Status: reviewing
Priority: normal | Milestone: Awaiting Review
Component: General | Version: trunk
Severity: normal | Resolution:
Keywords: needs-patch | Focuses:
--------------------------+------------------------------
Changes (by BackuPs):
* keywords: reporter-feedback => needs-patch
* component: Menus => General
Comment:
i am using the hook wp_nav_menu_item_custom_fields
{{{#!php
<?php
add_action( 'wp_nav_menu_item_custom_fields',
'theme_add_custom_fields_to_menu', 10, 4);
}}}
Please set a global parameter or a way to check that the action has been
called already by wp !! as before wp 5.3.2 wp does not call that action
and the theme and plugin developers have to call the action themselves !
Now i have to check the version and call the action. This is a bit weird.
{{{#!php
<?php
class Theme_Walker_Nav_Menu_Edit extends Walker_Nav_Menu_Edit {
function start_el( &$output, $item, $depth = 0, $args = array(), $id =
0 ) {
$item_id = esc_attr( $item->ID );
ob_start();
do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item,
$depth, $args );
$custom = ob_get_clean();
$output = $output. $custom;
}
}
add_action( 'wp_nav_menu_item_custom_fields',
'theme_add_custom_fields_to_menu', 10, 4);
function theme_add_custom_fields_to_menu( $item_id, $item, $depth, $args )
{
$custom = icon_settings($item_id);
$custom .= animation_settings($item_id,$depth);
$custom .= multicolumn_settings($item_id, $depth);
$custom .= mobile_show_settings($item_id);
$custom .= conditional_visibility($item_id);
echo $custom;
}
}}}
}}}
each function adds the fields in the correct format as wp requires in the
various tutorials.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/49500#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list