-
Notifications
You must be signed in to change notification settings - Fork 13
/
acf-menu-chooser-v5.php
102 lines (62 loc) · 1.97 KB
/
acf-menu-chooser-v5.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
class acf_field_menu_chooser extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function __construct() {
/*
* name (string) Single word, no spaces. Underscores allowed
*/
$this->name = 'menu-chooser';
/*
* label (string) Multiple words, can include spaces, visible when selecting a field type
*/
$this->label = __('Menu Chooser', 'acf-menu-chooser');
/*
* category (string) basic | content | choice | relational | jquery | layout | CUSTOM GROUP NAME
*/
$this->category = 'choice';
/*
* defaults (array) Array of default settings which are merged into the field object. These are used later in settings
*/
$this->defaults = array();
/*
* l10n (array) Array of strings that are used in JavaScript. This allows JS strings to be translated in PHP and loaded via:
* var message = acf._e('menu-chooser', 'error');
*/
$this->l10n = array(
'error' => __('Error! Please enter a higher value', 'acf-menu-chooser'),
);
// do not delete!
parent::__construct();
}
function render_field_settings( $field ) {
//Noting
}
function render_field( $field ) {
$field_value = $field['value'];
$field['choices'] = array();
$menus = wp_get_nav_menus();
echo '<select name="' . $field['name'] . '" class="acf-menu-chooser">';
if ( ! empty( $menus ) ) {
foreach ( $menus as $choice ) {
$field['choices'][ $choice->menu_id ] = $choice->term_id;
$field['choices'][ $choice->name ] = $choice->name;
echo '<option value="' . $field['choices'][ $choice->menu_id ] . '" ' . selected($field_value, $field['choices'][ $choice->menu_id ], false) . ' >' . $field['choices'][ $choice->name ] . '</option>' ;
}
}
echo '</select>';
}
}
// create field
new acf_field_menu_chooser();
?>