Advanced Custom Fields: Nav Menu Field - Version 1.1.2

Version Description

  • Fixed a silly mistake related to allowing Null for a Nav Menu Field. Basically, it was storing the string "null" when you don't select a menu, that's taken care of now.
Download this release

Release Info

Developer Faison
Plugin Icon wp plugin Advanced Custom Fields: Nav Menu Field
Version 1.1.2
Comparing to
See all releases

Code changes from version 1.0.0 to 1.1.2

Files changed (3) hide show
  1. fz-acf-nav-menu.php +1 -1
  2. nav-menu-v4.php +37 -4
  3. readme.txt +40 -6
fz-acf-nav-menu.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Advanced Custom Fields: Nav Menu Field
4
  Plugin URI: http://faisonz.com/wordpress-plugins/advanced-custom-fields-nav-menu-field/
5
  Description: Add-On plugin for Advanced Custom Fields (ACF) that adds a 'Nav Menu' Field type.
6
- Version: 1.0.0
7
  Author: Faison Zutavern
8
  Author URI: http://faisonz.com
9
  License: GPL2 or later
3
  Plugin Name: Advanced Custom Fields: Nav Menu Field
4
  Plugin URI: http://faisonz.com/wordpress-plugins/advanced-custom-fields-nav-menu-field/
5
  Description: Add-On plugin for Advanced Custom Fields (ACF) that adds a 'Nav Menu' Field type.
6
+ Version: 1.1.0
7
  Author: Faison Zutavern
8
  Author URI: http://faisonz.com
9
  License: GPL2 or later
nav-menu-v4.php CHANGED
@@ -24,7 +24,8 @@ class acf_field_nav_menu extends acf_field
24
  $this->category = __("Relational",'acf'); // Basic, Content, Choice, etc
25
  $this->defaults = array(
26
  'save_format' => 'id',
27
- 'allow_null' => 0
 
28
  );
29
 
30
 
@@ -36,7 +37,7 @@ class acf_field_nav_menu extends acf_field
36
  $this->settings = array(
37
  'path' => apply_filters('acf/helpers/get_path', __FILE__),
38
  'dir' => apply_filters('acf/helpers/get_dir', __FILE__),
39
- 'version' => '0.1.0'
40
  );
41
 
42
  }
@@ -88,6 +89,26 @@ class acf_field_nav_menu extends acf_field
88
  ?>
89
  </td>
90
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  <tr class="field_option field_option_<?php echo $this->name; ?>">
92
  <td class="label">
93
  <label><?php _e("Allow Null?",'acf'); ?></label>
@@ -137,7 +158,7 @@ class acf_field_nav_menu extends acf_field
137
  // null
138
  if( $field['allow_null'] )
139
  {
140
- echo '<option value="null"> - Select - </option>';
141
  }
142
 
143
  // Nav Menus
@@ -161,6 +182,17 @@ class acf_field_nav_menu extends acf_field
161
 
162
  return $nav_menus;
163
  }
 
 
 
 
 
 
 
 
 
 
 
164
 
165
  function format_value_for_api( $value, $post_id, $field )
166
  {
@@ -193,7 +225,8 @@ class acf_field_nav_menu extends acf_field
193
  ob_start();
194
 
195
  wp_nav_menu( array(
196
- 'menu' => $value
 
197
  ) );
198
 
199
  return ob_get_clean();
24
  $this->category = __("Relational",'acf'); // Basic, Content, Choice, etc
25
  $this->defaults = array(
26
  'save_format' => 'id',
27
+ 'allow_null' => 0,
28
+ 'container' => 'div'
29
  );
30
 
31
 
37
  $this->settings = array(
38
  'path' => apply_filters('acf/helpers/get_path', __FILE__),
39
  'dir' => apply_filters('acf/helpers/get_dir', __FILE__),
40
+ 'version' => '1.1.2'
41
  );
42
 
43
  }
89
  ?>
90
  </td>
91
  </tr>
92
+ <tr class="field_option field_option_<?php echo $this->name; ?>">
93
+ <td class="label">
94
+ <label><?php _e("Menu Container",'acf'); ?></label>
95
+ <p class="description">What to wrap the Menu's ul with.<br />Only used when returning HTML.</p>
96
+ </td>
97
+ <td>
98
+ <?php
99
+
100
+ $choices = $this->get_allowed_nav_container_tags();
101
+
102
+ do_action('acf/create_field', array(
103
+ 'type' => 'select',
104
+ 'name' => 'fields['.$key.'][container]',
105
+ 'value' => $field['container'],
106
+ 'choices' => $choices
107
+ ));
108
+
109
+ ?>
110
+ </td>
111
+ </tr>
112
  <tr class="field_option field_option_<?php echo $this->name; ?>">
113
  <td class="label">
114
  <label><?php _e("Allow Null?",'acf'); ?></label>
158
  // null
159
  if( $field['allow_null'] )
160
  {
161
+ echo '<option value=""> - Select - </option>';
162
  }
163
 
164
  // Nav Menus
182
 
183
  return $nav_menus;
184
  }
185
+
186
+ function get_allowed_nav_container_tags() {
187
+ $tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) );
188
+ $formatted_tags = array(
189
+ array( '0' => 'None' )
190
+ );
191
+ foreach( $tags as $tag ) {
192
+ $formatted_tags[0][$tag] = ucfirst( $tag );
193
+ }
194
+ return $formatted_tags;
195
+ }
196
 
197
  function format_value_for_api( $value, $post_id, $field )
198
  {
225
  ob_start();
226
 
227
  wp_nav_menu( array(
228
+ 'menu' => $value,
229
+ 'container' => $field['container']
230
  ) );
231
 
232
  return ob_get_clean();
readme.txt CHANGED
@@ -4,8 +4,8 @@ Tags: Advanced Custom Fields, acf, acf4, custom fields, admin, menu, nav menu, n
4
  Author: Faison Zutavern
5
  Author URI: http://faisonz.com
6
  Requires at least: 3.4
7
- Tested up to: 3.5.1
8
- Stable tag: 1.0.0
9
  License: GPL2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -36,24 +36,43 @@ This add-on will work with:
36
  This add-on can be treated as both a WP plugin and a theme include.
37
 
38
  = Plugin =
39
- 1. Copy the 'fz-acf-nav-menu' folder into your plugins folder
40
  2. Activate the plugin via the Plugins admin page
41
 
42
  = Include =
43
- 1. Copy the 'fz-acf-nav-menu' folder into your theme folder (can use sub folders). You can place the folder anywhere inside the 'wp-content' directory
44
- 2. Edit your functions.php file and add the code below (Make sure the path is correct to include the fz-acf-nav-menu.php file)
45
 
46
  `
47
  add_action('acf/register_fields', 'my_register_fields');
48
 
49
  function my_register_fields()
50
  {
51
- include_once('fz-acf-nav-menu/fz-acf-nav-menu.php');
52
  }
53
  `
54
 
55
  == Frequently Asked Questions ==
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  = Will you make this plugin compatible with Advanced Custom Fields v3? =
58
 
59
  I will do that soon, but you really should think about upgrading Advanced Custom Fields. ACF has seen a lot of great changes from v3 to the most current version.
@@ -78,10 +97,25 @@ First, check that you added the necessary ACF code to your templates. If you don
78
 
79
  == Changelog ==
80
 
 
 
 
 
 
 
 
 
 
81
  = 1.0.0 =
82
  * Initial Release.
83
 
84
  == Upgrade Notice ==
85
 
 
 
 
 
 
 
86
  = 1.0.0 =
87
  If you have a version less than 0.1.0, something went really, really wrong. Upgrade now, because I have no idea what will happen if you don't!
4
  Author: Faison Zutavern
5
  Author URI: http://faisonz.com
6
  Requires at least: 3.4
7
+ Tested up to: 3.9
8
+ Stable tag: 1.1.2
9
  License: GPL2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
36
  This add-on can be treated as both a WP plugin and a theme include.
37
 
38
  = Plugin =
39
+ 1. Copy the 'advanced-custom-fields-nav-menu-field' folder into your plugins folder
40
  2. Activate the plugin via the Plugins admin page
41
 
42
  = Include =
43
+ 1. Copy the 'advanced-custom-fields-nav-menu-field' folder into your theme folder (can use sub folders). You can place the folder anywhere inside the 'wp-content' directory
44
+ 2. Edit your functions.php file and add the code below (Make sure the path is correct to include the nav-menu-v4.php file)
45
 
46
  `
47
  add_action('acf/register_fields', 'my_register_fields');
48
 
49
  function my_register_fields()
50
  {
51
+ include_once('advanced-custom-fields-nav-menu-field/nav-menu-v4.php');
52
  }
53
  `
54
 
55
  == Frequently Asked Questions ==
56
 
57
+ = Can you show a quick example of how to use this? =
58
+
59
+ Sure can!
60
+
61
+ 1. Create a new field group
62
+ 2. Add a Nav Menu and set the Field Label to `Side Menu` (this will cause the Field Name to be `side_menu`)
63
+ 3. Set the Nav Menu's Return Value to `Nav Menu HTML`
64
+ 4. Set the Location Rules to Show if "Post Type" "is equal to" "Page"
65
+ 5. Save the Field Group
66
+ 6. Now in your themes sidebar.php, put the following code before or after any of the div's with class="widget-area"
67
+ `
68
+ <?php if( get_field( 'side_menu' ) ) : ?>
69
+ <div class="widget-area">
70
+ <?php the_field( 'side_menu' ); ?>
71
+ </div>
72
+ <?php endif; ?>
73
+ `
74
+ Finally, create or edit a page, select a menu in the Side Menu field, and view the page to see that menu in the sidebar!
75
+
76
  = Will you make this plugin compatible with Advanced Custom Fields v3? =
77
 
78
  I will do that soon, but you really should think about upgrading Advanced Custom Fields. ACF has seen a lot of great changes from v3 to the most current version.
97
 
98
  == Changelog ==
99
 
100
+ = 1.1.2 =
101
+ * Fixed a silly mistake related to allowing Null for a Nav Menu Field. Basically, it was storing the string "null" when you don't select a menu, that's taken care of now.
102
+
103
+ = 1.1.1 =
104
+ * I forgot to add a default value for the Menu Container field, so I added 'div' as the default value. If you upgraded from 1.0.0 to 1.1.0 and had WP_DEBUG enabled, you would receive a warning about an unknown index. Since I like debug mode to run without warnings, I fixed this.
105
+
106
+ = 1.1.0 =
107
+ * Added a field which allows users to choose the containing element for the Menu's ul. See [wp_nav_menu's container parameter](http://codex.wordpress.org/Function_Reference/wp_nav_menu#Parameters)
108
+
109
  = 1.0.0 =
110
  * Initial Release.
111
 
112
  == Upgrade Notice ==
113
 
114
+ = 1.1.1 =
115
+ I forgot to add a default value for the Menu Container field. So to eliminate WP_DEBUG warnings, I added 'div' as the default value. Please upgrade to avoid the warnings.
116
+
117
+ = 1.1.0 =
118
+ Added a new minor feature for selecting the Menu's containing element.
119
+
120
  = 1.0.0 =
121
  If you have a version less than 0.1.0, something went really, really wrong. Upgrade now, because I have no idea what will happen if you don't!