{"id":27526,"date":"2014-01-28T23:37:59","date_gmt":"2014-01-28T23:37:59","guid":{"rendered":"https:\/\/wordpress.org\/plugins-wp\/custom-menu-fields\/"},"modified":"2021-09-20T20:50:32","modified_gmt":"2021-09-20T20:50:32","slug":"custom-menu-fields","status":"closed","type":"plugin","link":"https:\/\/wordpress.org\/plugins\/custom-menu-fields\/","author":226111,"comment_status":"closed","ping_status":"closed","template":"","meta":{"version":"0.2","stable_tag":"0.2","tested":"3.7.41","requires":"3.5","requires_php":"","requires_plugins":"","header_name":"Custom Menu Fields","header_author":"Dani Llewellyn","header_description":"","assets_banners_color":"","last_updated":"2021-09-20 20:50:32","external_support_url":"","external_repository_url":"","donate_link":"","header_plugin_uri":"http:\/\/bowlhat.net\/","header_author_uri":"http:\/\/bowlhat.net\/","rating":5,"author_block_rating":0,"active_installs":10,"downloads":3761,"num_ratings":2,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation","changelog"],"tags":{"0.1":{"tag":"0.1","author":"diddledani","date":"2021-09-07 12:58:03"},"0.2":{"tag":"0.2","author":"diddledani","date":"2021-09-20 20:50:32"}},"upgrade_notice":[],"ratings":{"1":0,"2":0,"3":0,"4":0,"5":"2"},"assets_icons":[],"assets_banners":[],"assets_blueprints":{},"all_blocks":[],"tagged_versions":["0.1","0.2"],"block_files":[],"assets_screenshots":[],"screenshots":[]},"plugin_section":[],"plugin_tags":[1556,2240,2235,1865],"plugin_category":[43],"plugin_contributors":[203376],"plugin_business_model":[],"class_list":["post-27526","plugin","type-plugin","status-closed","hentry","plugin_tags-api","plugin_tags-field","plugin_tags-fields","plugin_tags-menu","plugin_category-customization","plugin_contributors-diddledani","plugin_committers-bowlhat","plugin_committers-diddledan","plugin_committers-diddledani"],"banners":[],"icons":{"svg":false,"icon":"https:\/\/s.w.org\/plugins\/geopattern-icon\/custom-menu-fields.svg","icon_2x":false,"generated":true},"screenshots":[],"raw_content":"<!--section=description-->\n<p>This plugin provides an API which allows the developer of a site to add custom fields on the default menu editor.<\/p>\n\n<h4>Example Initialisation<\/h4>\n\n<pre><code>&lt;?php\nadd_action('init', 'menu_excerpt__add_menu_field');\nfunction menu_excerpt__add_menu_field() {\n    if (!is_callable('bh_add_custom_menu_fields'))\n        return;\n\n    bh_add_custom_menu_fields(array(\n        'excerpt' =&gt; array(\n            'description' =&gt; 'Excerpt',\n            'type' =&gt; 'textarea',\n            )));\n}\n?&gt;\n<\/code><\/pre>\n\n<h4>Accessing the fields<\/h4>\n\n<p>The easiest way to access the field(s) you've added is to use something along the lines of:<\/p>\n\n<pre><code>$menu = 'menuName';\n$posts = wp_get_nav_menu_items($menu);\nforeach ($posts as $p) {\n    $myitem = get_post_meta($p-&gt;ID, '_menu_item_youritem', true);\n    \/\/ do with $myitem what you like - it should be a string,\n    \/\/ so the simplest thing is to \"echo\" it\n}\n<\/code><\/pre>\n\n<p>you can use menu locations to get the menu name if you prefer - replace the first line above with:<\/p>\n\n<pre><code>$locations = get_nav_menu_locations();\n$menu = $locations['locationName'];\n<\/code><\/pre>\n\n<p>menu locations are useful if you like to swap your menus about.<\/p>\n\n<p>Unfortunately these examples don't allow the use of wordpress' inbuilt menu walkers. To use those you will need to create a custom walker_nav_menu class and access the custom fields with something along the lines of (very stripped down example will need fleshing out for full walker functionality - there are tutorials on the net for custom nav walkers):<\/p>\n\n<pre><code>class mywalker extends Walker_Nav_Menu {\n    function start_el(&amp;$output, $item, $depth, $args) {\n        echo $item-&gt;custom_field\n    }\n}\n<\/code><\/pre>\n\n<p>The important bit here is that the field is placed on the second variable which behaves like an object. the custom_field part is the name you gave your field with dashes replaced with underscores (to allow the name to be used in an accessor).<\/p>\n\n<h4>NOTE<\/h4>\n\n<p>This plugin does nothing by itself. It provides an API only.<\/p>\n\n<!--section=installation-->\n<p>This section describes how to install the plugin and get it working.<\/p>\n\n<ol>\n<li>Upload the folder from the zip to the <code>\/wp-content\/plugins\/<\/code> directory<\/li>\n<li>Activate the plugin through the 'Plugins' menu in WordPress<\/li>\n<li>Once activated the API is available in the \u2018init\u2019 and later phases of the WordPress lifecycle.<\/li>\n<\/ol>\n\n<!--section=changelog-->\n<h4>0.2<\/h4>\n\n<p>version bump to attempt to rectify auto-update mechanism<\/p>\n\n<h4>0.1<\/h4>\n\n<p>first release<\/p>","raw_excerpt":"Provides an API to add custom fields to the menu editor.","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/27526","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=27526"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/diddledani"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=27526"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=27526"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=27526"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=27526"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=27526"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=27526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}