author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:52:52 +0200 | |
changeset 22 | 8c2e4d02f4ef |
parent 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* Core Navigation Menu API |
0 | 4 |
* |
5 |
* @package WordPress |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6 |
* @subpackage Nav_Menus |
0 | 7 |
* @since 3.0.0 |
8 |
*/ |
|
9 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
10 |
/** Walker_Nav_Menu_Edit class */ |
16 | 11 |
require_once ABSPATH . 'wp-admin/includes/class-walker-nav-menu-edit.php'; |
0 | 12 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
/** Walker_Nav_Menu_Checklist class */ |
16 | 14 |
require_once ABSPATH . 'wp-admin/includes/class-walker-nav-menu-checklist.php'; |
0 | 15 |
|
16 |
/** |
|
17 |
* Prints the appropriate response to a menu quick search. |
|
18 |
* |
|
19 |
* @since 3.0.0 |
|
20 |
* |
|
21 |
* @param array $request The unsanitized request values. |
|
22 |
*/ |
|
23 |
function _wp_ajax_menu_quick_search( $request = array() ) { |
|
9 | 24 |
$args = array(); |
25 |
$type = isset( $request['type'] ) ? $request['type'] : ''; |
|
26 |
$object_type = isset( $request['object_type'] ) ? $request['object_type'] : ''; |
|
27 |
$query = isset( $request['q'] ) ? $request['q'] : ''; |
|
16 | 28 |
$response_format = isset( $request['response-format'] ) ? $request['response-format'] : ''; |
0 | 29 |
|
16 | 30 |
if ( ! $response_format || ! in_array( $response_format, array( 'json', 'markup' ), true ) ) { |
31 |
$response_format = 'json'; |
|
32 |
} |
|
33 |
||
34 |
if ( 'markup' === $response_format ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
35 |
$args['walker'] = new Walker_Nav_Menu_Checklist(); |
0 | 36 |
} |
37 |
||
16 | 38 |
if ( 'get-post-item' === $type ) { |
0 | 39 |
if ( post_type_exists( $object_type ) ) { |
40 |
if ( isset( $request['ID'] ) ) { |
|
41 |
$object_id = (int) $request['ID']; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
42 |
|
16 | 43 |
if ( 'markup' === $response_format ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
44 |
echo walk_nav_menu_tree( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
45 |
array_map( 'wp_setup_nav_menu_item', array( get_post( $object_id ) ) ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
46 |
0, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
47 |
(object) $args |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
48 |
); |
16 | 49 |
} elseif ( 'json' === $response_format ) { |
5 | 50 |
echo wp_json_encode( |
0 | 51 |
array( |
9 | 52 |
'ID' => $object_id, |
0 | 53 |
'post_title' => get_the_title( $object_id ), |
9 | 54 |
'post_type' => get_post_type( $object_id ), |
0 | 55 |
) |
56 |
); |
|
57 |
echo "\n"; |
|
58 |
} |
|
59 |
} |
|
60 |
} elseif ( taxonomy_exists( $object_type ) ) { |
|
61 |
if ( isset( $request['ID'] ) ) { |
|
62 |
$object_id = (int) $request['ID']; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
63 |
|
16 | 64 |
if ( 'markup' === $response_format ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
65 |
echo walk_nav_menu_tree( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
66 |
array_map( 'wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
67 |
0, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
68 |
(object) $args |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
69 |
); |
16 | 70 |
} elseif ( 'json' === $response_format ) { |
0 | 71 |
$post_obj = get_term( $object_id, $object_type ); |
5 | 72 |
echo wp_json_encode( |
0 | 73 |
array( |
9 | 74 |
'ID' => $object_id, |
0 | 75 |
'post_title' => $post_obj->name, |
9 | 76 |
'post_type' => $object_type, |
0 | 77 |
) |
78 |
); |
|
79 |
echo "\n"; |
|
80 |
} |
|
81 |
} |
|
82 |
} |
|
9 | 83 |
} elseif ( preg_match( '/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches ) ) { |
16 | 84 |
if ( 'posttype' === $matches[1] && get_post_type_object( $matches[2] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
85 |
$post_type_obj = _wp_nav_menu_meta_box_object( get_post_type_object( $matches[2] ) ); |
9 | 86 |
$args = array_merge( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
87 |
$args, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
88 |
array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
89 |
'no_found_rows' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
'update_post_meta_cache' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
91 |
'update_post_term_cache' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
92 |
'posts_per_page' => 10, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
'post_type' => $matches[2], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
94 |
's' => $query, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
95 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
96 |
); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
97 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
98 |
if ( isset( $post_type_obj->_default_query ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
99 |
$args = array_merge( $args, (array) $post_type_obj->_default_query ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
100 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
101 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
102 |
$search_results_query = new WP_Query( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
if ( ! $search_results_query->have_posts() ) { |
0 | 104 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
105 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
106 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
107 |
while ( $search_results_query->have_posts() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
108 |
$post = $search_results_query->next_post(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
109 |
|
16 | 110 |
if ( 'markup' === $response_format ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
$var_by_ref = $post->ID; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
112 |
echo walk_nav_menu_tree( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
113 |
array_map( 'wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
114 |
0, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
115 |
(object) $args |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
116 |
); |
16 | 117 |
} elseif ( 'json' === $response_format ) { |
5 | 118 |
echo wp_json_encode( |
0 | 119 |
array( |
9 | 120 |
'ID' => $post->ID, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
121 |
'post_title' => get_the_title( $post->ID ), |
9 | 122 |
'post_type' => $matches[2], |
0 | 123 |
) |
124 |
); |
|
125 |
echo "\n"; |
|
126 |
} |
|
127 |
} |
|
16 | 128 |
} elseif ( 'taxonomy' === $matches[1] ) { |
9 | 129 |
$terms = get_terms( |
130 |
array( |
|
131 |
'taxonomy' => $matches[2], |
|
132 |
'name__like' => $query, |
|
133 |
'number' => 10, |
|
16 | 134 |
'hide_empty' => false, |
9 | 135 |
) |
136 |
); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
137 |
|
9 | 138 |
if ( empty( $terms ) || is_wp_error( $terms ) ) { |
0 | 139 |
return; |
9 | 140 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
141 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
foreach ( (array) $terms as $term ) { |
16 | 143 |
if ( 'markup' === $response_format ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
144 |
echo walk_nav_menu_tree( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
145 |
array_map( 'wp_setup_nav_menu_item', array( $term ) ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
146 |
0, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
147 |
(object) $args |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
148 |
); |
16 | 149 |
} elseif ( 'json' === $response_format ) { |
5 | 150 |
echo wp_json_encode( |
0 | 151 |
array( |
9 | 152 |
'ID' => $term->term_id, |
0 | 153 |
'post_title' => $term->name, |
9 | 154 |
'post_type' => $matches[2], |
0 | 155 |
) |
156 |
); |
|
157 |
echo "\n"; |
|
158 |
} |
|
159 |
} |
|
160 |
} |
|
161 |
} |
|
162 |
} |
|
163 |
||
164 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
165 |
* Register nav menu meta boxes and advanced menu items. |
0 | 166 |
* |
167 |
* @since 3.0.0 |
|
9 | 168 |
*/ |
0 | 169 |
function wp_nav_menu_setup() { |
16 | 170 |
// Register meta boxes. |
0 | 171 |
wp_nav_menu_post_type_meta_boxes(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
172 |
add_meta_box( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
173 |
'add-custom-links', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
174 |
__( 'Custom Links' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
175 |
'wp_nav_menu_item_link_meta_box', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
176 |
'nav-menus', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
177 |
'side', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
178 |
'default' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
179 |
); |
0 | 180 |
wp_nav_menu_taxonomy_meta_boxes(); |
181 |
||
16 | 182 |
// Register advanced menu items (columns). |
0 | 183 |
add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns' ); |
184 |
||
185 |
// If first time editing, disable advanced items by default. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
186 |
if ( false === get_user_option( 'managenav-menuscolumnshidden' ) ) { |
0 | 187 |
$user = wp_get_current_user(); |
18 | 188 |
update_user_meta( |
9 | 189 |
$user->ID, |
190 |
'managenav-menuscolumnshidden', |
|
191 |
array( |
|
192 |
0 => 'link-target', |
|
193 |
1 => 'css-classes', |
|
194 |
2 => 'xfn', |
|
195 |
3 => 'description', |
|
196 |
4 => 'title-attribute', |
|
18 | 197 |
) |
9 | 198 |
); |
0 | 199 |
} |
200 |
} |
|
201 |
||
202 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
203 |
* Limit the amount of meta boxes to pages, posts, links, and categories for first time users. |
0 | 204 |
* |
205 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
206 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
207 |
* @global array $wp_meta_boxes Global meta box state. |
9 | 208 |
*/ |
0 | 209 |
function wp_initial_nav_menu_meta_boxes() { |
210 |
global $wp_meta_boxes; |
|
211 |
||
9 | 212 |
if ( get_user_option( 'metaboxhidden_nav-menus' ) !== false || ! is_array( $wp_meta_boxes ) ) { |
0 | 213 |
return; |
9 | 214 |
} |
0 | 215 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
216 |
$initial_meta_boxes = array( 'add-post-type-page', 'add-post-type-post', 'add-custom-links', 'add-category' ); |
9 | 217 |
$hidden_meta_boxes = array(); |
0 | 218 |
|
9 | 219 |
foreach ( array_keys( $wp_meta_boxes['nav-menus'] ) as $context ) { |
220 |
foreach ( array_keys( $wp_meta_boxes['nav-menus'][ $context ] ) as $priority ) { |
|
221 |
foreach ( $wp_meta_boxes['nav-menus'][ $context ][ $priority ] as $box ) { |
|
16 | 222 |
if ( in_array( $box['id'], $initial_meta_boxes, true ) ) { |
0 | 223 |
unset( $box['id'] ); |
224 |
} else { |
|
225 |
$hidden_meta_boxes[] = $box['id']; |
|
226 |
} |
|
227 |
} |
|
228 |
} |
|
229 |
} |
|
230 |
||
231 |
$user = wp_get_current_user(); |
|
18 | 232 |
update_user_meta( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes ); |
0 | 233 |
} |
234 |
||
235 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
* Creates meta boxes for any post type menu item.. |
0 | 237 |
* |
238 |
* @since 3.0.0 |
|
239 |
*/ |
|
240 |
function wp_nav_menu_post_type_meta_boxes() { |
|
241 |
$post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'object' ); |
|
242 |
||
9 | 243 |
if ( ! $post_types ) { |
0 | 244 |
return; |
9 | 245 |
} |
0 | 246 |
|
247 |
foreach ( $post_types as $post_type ) { |
|
5 | 248 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
249 |
* Filters whether a menu items meta box will be added for the current |
5 | 250 |
* object type. |
251 |
* |
|
252 |
* If a falsey value is returned instead of an object, the menu items |
|
253 |
* meta box for the current meta box object will not be added. |
|
254 |
* |
|
255 |
* @since 3.0.0 |
|
256 |
* |
|
16 | 257 |
* @param WP_Post_Type|false $post_type The current object to add a menu items |
258 |
* meta box for. |
|
5 | 259 |
*/ |
0 | 260 |
$post_type = apply_filters( 'nav_menu_meta_box_object', $post_type ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
261 |
|
0 | 262 |
if ( $post_type ) { |
263 |
$id = $post_type->name; |
|
5 | 264 |
// Give pages a higher priority. |
16 | 265 |
$priority = ( 'page' === $post_type->name ? 'core' : 'default' ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
266 |
add_meta_box( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
267 |
"add-post-type-{$id}", |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
268 |
$post_type->labels->name, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
269 |
'wp_nav_menu_item_post_type_meta_box', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
270 |
'nav-menus', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
271 |
'side', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
272 |
$priority, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
273 |
$post_type |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
274 |
); |
0 | 275 |
} |
276 |
} |
|
277 |
} |
|
278 |
||
279 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
280 |
* Creates meta boxes for any taxonomy menu item. |
0 | 281 |
* |
282 |
* @since 3.0.0 |
|
283 |
*/ |
|
284 |
function wp_nav_menu_taxonomy_meta_boxes() { |
|
285 |
$taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'object' ); |
|
286 |
||
9 | 287 |
if ( ! $taxonomies ) { |
0 | 288 |
return; |
9 | 289 |
} |
0 | 290 |
|
291 |
foreach ( $taxonomies as $tax ) { |
|
5 | 292 |
/** This filter is documented in wp-admin/includes/nav-menu.php */ |
0 | 293 |
$tax = apply_filters( 'nav_menu_meta_box_object', $tax ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
294 |
|
0 | 295 |
if ( $tax ) { |
296 |
$id = $tax->name; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
297 |
add_meta_box( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
298 |
"add-{$id}", |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
299 |
$tax->labels->name, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
300 |
'wp_nav_menu_item_taxonomy_meta_box', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
301 |
'nav-menus', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
302 |
'side', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
303 |
'default', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
304 |
$tax |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
305 |
); |
0 | 306 |
} |
307 |
} |
|
308 |
} |
|
309 |
||
310 |
/** |
|
16 | 311 |
* Check whether to disable the Menu Locations meta box submit button and inputs. |
0 | 312 |
* |
313 |
* @since 3.6.0 |
|
19 | 314 |
* @since 5.3.1 The `$display` parameter was added. |
0 | 315 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
316 |
* @global bool $one_theme_location_no_menus to determine if no menus exist |
0 | 317 |
* |
16 | 318 |
* @param int|string $nav_menu_selected_id ID, name, or slug of the currently selected menu. |
19 | 319 |
* @param bool $display Whether to display or just return the string. |
16 | 320 |
* @return string|false Disabled attribute if at least one menu exists, false if not. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
*/ |
19 | 322 |
function wp_nav_menu_disabled_check( $nav_menu_selected_id, $display = true ) { |
0 | 323 |
global $one_theme_location_no_menus; |
324 |
||
9 | 325 |
if ( $one_theme_location_no_menus ) { |
0 | 326 |
return false; |
9 | 327 |
} |
0 | 328 |
|
19 | 329 |
return disabled( $nav_menu_selected_id, 0, $display ); |
0 | 330 |
} |
331 |
||
332 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
333 |
* Displays a meta box for the custom links menu item. |
0 | 334 |
* |
335 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
337 |
* @global int $_nav_menu_placeholder |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
338 |
* @global int|string $nav_menu_selected_id |
0 | 339 |
*/ |
340 |
function wp_nav_menu_item_link_meta_box() { |
|
341 |
global $_nav_menu_placeholder, $nav_menu_selected_id; |
|
342 |
||
343 |
$_nav_menu_placeholder = 0 > $_nav_menu_placeholder ? $_nav_menu_placeholder - 1 : -1; |
|
344 |
||
345 |
?> |
|
346 |
<div class="customlinkdiv" id="customlinkdiv"> |
|
347 |
<input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" /> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
348 |
<p id="menu-item-url-wrap" class="wp-clearfix"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
349 |
<label class="howto" for="custom-menu-item-url"><?php _e( 'URL' ); ?></label> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
350 |
<input id="custom-menu-item-url" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-url]" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
351 |
type="text"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
352 |
class="code menu-item-textbox form-required" placeholder="https://" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
353 |
/> |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
354 |
<span id="custom-url-error" class="error-message" style="display: none;"><?php _e( 'Please provide a valid link.' ); ?></span> |
0 | 355 |
</p> |
356 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
357 |
<p id="menu-item-name-wrap" class="wp-clearfix"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
358 |
<label class="howto" for="custom-menu-item-name"><?php _e( 'Link Text' ); ?></label> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
359 |
<input id="custom-menu-item-name" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-title]" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
360 |
type="text"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
361 |
class="regular-text menu-item-textbox" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
362 |
/> |
0 | 363 |
</p> |
364 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
365 |
<p class="button-controls wp-clearfix"> |
0 | 366 |
<span class="add-to-menu"> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
367 |
<input id="submit-customlinkdiv" name="add-custom-menu-item" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
368 |
type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
369 |
class="button submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
370 |
/> |
0 | 371 |
<span class="spinner"></span> |
372 |
</span> |
|
373 |
</p> |
|
374 |
||
375 |
</div><!-- /.customlinkdiv --> |
|
376 |
<?php |
|
377 |
} |
|
378 |
||
379 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
* Displays a meta box for a post type menu item. |
0 | 381 |
* |
382 |
* @since 3.0.0 |
|
383 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
* @global int $_nav_menu_placeholder |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
* @global int|string $nav_menu_selected_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
* |
19 | 387 |
* @param string $data_object Not used. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
388 |
* @param array $box { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
* Post type menu item meta box arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
390 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
* @type string $id Meta box 'id' attribute. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
392 |
* @type string $title Meta box title. |
16 | 393 |
* @type callable $callback Meta box display callback. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
394 |
* @type WP_Post_Type $args Extra meta box arguments (the post type object for this meta box). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
395 |
* } |
0 | 396 |
*/ |
19 | 397 |
function wp_nav_menu_item_post_type_meta_box( $data_object, $box ) { |
0 | 398 |
global $_nav_menu_placeholder, $nav_menu_selected_id; |
399 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
400 |
$post_type_name = $box['args']->name; |
16 | 401 |
$post_type = get_post_type_object( $post_type_name ); |
402 |
$tab_name = $post_type_name . '-tab'; |
|
0 | 403 |
|
5 | 404 |
// Paginate browsing for large numbers of post objects. |
0 | 405 |
$per_page = 50; |
16 | 406 |
$pagenum = isset( $_REQUEST[ $tab_name ] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; |
9 | 407 |
$offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; |
0 | 408 |
|
409 |
$args = array( |
|
9 | 410 |
'offset' => $offset, |
411 |
'order' => 'ASC', |
|
412 |
'orderby' => 'title', |
|
413 |
'posts_per_page' => $per_page, |
|
414 |
'post_type' => $post_type_name, |
|
415 |
'suppress_filters' => true, |
|
0 | 416 |
'update_post_term_cache' => false, |
9 | 417 |
'update_post_meta_cache' => false, |
0 | 418 |
); |
419 |
||
9 | 420 |
if ( isset( $box['args']->_default_query ) ) { |
421 |
$args = array_merge( $args, (array) $box['args']->_default_query ); |
|
422 |
} |
|
0 | 423 |
|
16 | 424 |
/* |
425 |
* If we're dealing with pages, let's prioritize the Front Page, |
|
426 |
* Posts Page and Privacy Policy Page at the top of the list. |
|
427 |
*/ |
|
428 |
$important_pages = array(); |
|
429 |
if ( 'page' === $post_type_name ) { |
|
430 |
$suppress_page_ids = array(); |
|
431 |
||
432 |
// Insert Front Page or custom Home link. |
|
433 |
$front_page = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0; |
|
434 |
||
435 |
$front_page_obj = null; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
436 |
|
16 | 437 |
if ( ! empty( $front_page ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
438 |
$front_page_obj = get_post( $front_page ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
439 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
440 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
441 |
if ( $front_page_obj ) { |
16 | 442 |
$front_page_obj->front_or_home = true; |
443 |
||
444 |
$important_pages[] = $front_page_obj; |
|
445 |
$suppress_page_ids[] = $front_page_obj->ID; |
|
446 |
} else { |
|
18 | 447 |
$_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? (int) $_nav_menu_placeholder - 1 : -1; |
16 | 448 |
$front_page_obj = (object) array( |
449 |
'front_or_home' => true, |
|
450 |
'ID' => 0, |
|
451 |
'object_id' => $_nav_menu_placeholder, |
|
452 |
'post_content' => '', |
|
453 |
'post_excerpt' => '', |
|
454 |
'post_parent' => '', |
|
455 |
'post_title' => _x( 'Home', 'nav menu home label' ), |
|
456 |
'post_type' => 'nav_menu_item', |
|
457 |
'type' => 'custom', |
|
458 |
'url' => home_url( '/' ), |
|
459 |
); |
|
460 |
||
461 |
$important_pages[] = $front_page_obj; |
|
462 |
} |
|
463 |
||
464 |
// Insert Posts Page. |
|
465 |
$posts_page = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_for_posts' ) : 0; |
|
466 |
||
467 |
if ( ! empty( $posts_page ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
468 |
$posts_page_obj = get_post( $posts_page ); |
16 | 469 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
470 |
if ( $posts_page_obj ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
471 |
$front_page_obj->posts_page = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
472 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
473 |
$important_pages[] = $posts_page_obj; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
474 |
$suppress_page_ids[] = $posts_page_obj->ID; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
475 |
} |
16 | 476 |
} |
477 |
||
478 |
// Insert Privacy Policy Page. |
|
479 |
$privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); |
|
480 |
||
481 |
if ( ! empty( $privacy_policy_page_id ) ) { |
|
482 |
$privacy_policy_page = get_post( $privacy_policy_page_id ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
483 |
|
16 | 484 |
if ( $privacy_policy_page instanceof WP_Post && 'publish' === $privacy_policy_page->post_status ) { |
485 |
$privacy_policy_page->privacy_policy_page = true; |
|
486 |
||
487 |
$important_pages[] = $privacy_policy_page; |
|
488 |
$suppress_page_ids[] = $privacy_policy_page->ID; |
|
489 |
} |
|
490 |
} |
|
491 |
||
492 |
// Add suppression array to arguments for WP_Query. |
|
493 |
if ( ! empty( $suppress_page_ids ) ) { |
|
494 |
$args['post__not_in'] = $suppress_page_ids; |
|
495 |
} |
|
496 |
} |
|
497 |
||
498 |
// @todo Transient caching of these results with proper invalidation on updating of a post of this type. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
499 |
$get_posts = new WP_Query(); |
9 | 500 |
$posts = $get_posts->query( $args ); |
16 | 501 |
|
502 |
// Only suppress and insert when more than just suppression pages available. |
|
0 | 503 |
if ( ! $get_posts->post_count ) { |
16 | 504 |
if ( ! empty( $suppress_page_ids ) ) { |
505 |
unset( $args['post__not_in'] ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
506 |
$get_posts = new WP_Query(); |
16 | 507 |
$posts = $get_posts->query( $args ); |
508 |
} else { |
|
509 |
echo '<p>' . __( 'No items.' ) . '</p>'; |
|
510 |
return; |
|
511 |
} |
|
512 |
} elseif ( ! empty( $important_pages ) ) { |
|
513 |
$posts = array_merge( $important_pages, $posts ); |
|
0 | 514 |
} |
515 |
||
516 |
$num_pages = $get_posts->max_num_pages; |
|
517 |
||
9 | 518 |
$page_links = paginate_links( |
519 |
array( |
|
520 |
'base' => add_query_arg( |
|
521 |
array( |
|
16 | 522 |
$tab_name => 'all', |
523 |
'paged' => '%#%', |
|
524 |
'item-type' => 'post_type', |
|
525 |
'item-object' => $post_type_name, |
|
9 | 526 |
) |
527 |
), |
|
528 |
'format' => '', |
|
529 |
'prev_text' => '<span aria-label="' . esc_attr__( 'Previous page' ) . '">' . __( '«' ) . '</span>', |
|
530 |
'next_text' => '<span aria-label="' . esc_attr__( 'Next page' ) . '">' . __( '»' ) . '</span>', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
531 |
/* translators: Hidden accessibility text. */ |
9 | 532 |
'before_page_number' => '<span class="screen-reader-text">' . __( 'Page' ) . '</span> ', |
533 |
'total' => $num_pages, |
|
534 |
'current' => $pagenum, |
|
535 |
) |
|
536 |
); |
|
0 | 537 |
|
538 |
$db_fields = false; |
|
539 |
if ( is_post_type_hierarchical( $post_type_name ) ) { |
|
9 | 540 |
$db_fields = array( |
541 |
'parent' => 'post_parent', |
|
542 |
'id' => 'ID', |
|
543 |
); |
|
0 | 544 |
} |
545 |
||
546 |
$walker = new Walker_Nav_Menu_Checklist( $db_fields ); |
|
547 |
||
548 |
$current_tab = 'most-recent'; |
|
16 | 549 |
|
550 |
if ( isset( $_REQUEST[ $tab_name ] ) && in_array( $_REQUEST[ $tab_name ], array( 'all', 'search' ), true ) ) { |
|
551 |
$current_tab = $_REQUEST[ $tab_name ]; |
|
0 | 552 |
} |
553 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
554 |
if ( ! empty( $_REQUEST[ "quick-search-posttype-{$post_type_name}" ] ) ) { |
0 | 555 |
$current_tab = 'search'; |
556 |
} |
|
557 |
||
558 |
$removed_args = array( |
|
559 |
'action', |
|
560 |
'customlink-tab', |
|
561 |
'edit-menu-item', |
|
562 |
'menu-item', |
|
563 |
'page-tab', |
|
564 |
'_wpnonce', |
|
565 |
); |
|
566 |
||
16 | 567 |
$most_recent_url = ''; |
568 |
$view_all_url = ''; |
|
569 |
$search_url = ''; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
570 |
|
9 | 571 |
if ( $nav_menu_selected_id ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
572 |
$most_recent_url = add_query_arg( $tab_name, 'most-recent', remove_query_arg( $removed_args ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
573 |
$view_all_url = add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
574 |
$search_url = add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) ); |
9 | 575 |
} |
0 | 576 |
?> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
577 |
<div id="<?php echo esc_attr( "posttype-{$post_type_name}" ); ?>" class="posttypediv"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
578 |
<ul id="<?php echo esc_attr( "posttype-{$post_type_name}-tabs" ); ?>" class="posttype-tabs add-menu-item-tabs"> |
16 | 579 |
<li <?php echo ( 'most-recent' === $current_tab ? ' class="tabs"' : '' ); ?>> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
580 |
<a class="nav-tab-link" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
581 |
data-type="<?php echo esc_attr( "tabs-panel-posttype-{$post_type_name}-most-recent" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
582 |
href="<?php echo esc_url( $most_recent_url . "#tabs-panel-posttype-{$post_type_name}-most-recent" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
583 |
> |
0 | 584 |
<?php _e( 'Most Recent' ); ?> |
585 |
</a> |
|
586 |
</li> |
|
16 | 587 |
<li <?php echo ( 'all' === $current_tab ? ' class="tabs"' : '' ); ?>> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
588 |
<a class="nav-tab-link" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
589 |
data-type="<?php echo esc_attr( "{$post_type_name}-all" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
590 |
href="<?php echo esc_url( $view_all_url . "#{$post_type_name}-all" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
591 |
> |
0 | 592 |
<?php _e( 'View All' ); ?> |
593 |
</a> |
|
594 |
</li> |
|
16 | 595 |
<li <?php echo ( 'search' === $current_tab ? ' class="tabs"' : '' ); ?>> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
596 |
<a class="nav-tab-link" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
597 |
data-type="<?php echo esc_attr( "tabs-panel-posttype-{$post_type_name}-search" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
598 |
href="<?php echo esc_url( $search_url . "#tabs-panel-posttype-{$post_type_name}-search" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
599 |
> |
9 | 600 |
<?php _e( 'Search' ); ?> |
0 | 601 |
</a> |
602 |
</li> |
|
603 |
</ul><!-- .posttype-tabs --> |
|
604 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
605 |
<div id="<?php echo esc_attr( "tabs-panel-posttype-{$post_type_name}-most-recent" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
606 |
class="tabs-panel <?php echo ( 'most-recent' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
607 |
role="region" aria-label="<?php esc_attr_e( 'Most Recent' ); ?>" tabindex="0" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
608 |
> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
609 |
<ul id="<?php echo esc_attr( "{$post_type_name}checklist-most-recent" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
610 |
class="categorychecklist form-no-clear" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
611 |
> |
0 | 612 |
<?php |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
613 |
$recent_args = array_merge( |
9 | 614 |
$args, |
615 |
array( |
|
616 |
'orderby' => 'post_date', |
|
617 |
'order' => 'DESC', |
|
618 |
'posts_per_page' => 15, |
|
619 |
) |
|
620 |
); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
621 |
$most_recent = $get_posts->query( $recent_args ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
622 |
|
0 | 623 |
$args['walker'] = $walker; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
624 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
625 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
* Filters the posts displayed in the 'Most Recent' tab of the current |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
* post type's menu items meta box. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
628 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
629 |
* The dynamic portion of the hook name, `$post_type_name`, refers to the post type name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
630 |
* |
18 | 631 |
* Possible hook names include: |
632 |
* |
|
633 |
* - `nav_menu_items_post_recent` |
|
634 |
* - `nav_menu_items_page_recent` |
|
635 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
636 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
637 |
* @since 4.9.0 Added the `$recent_args` parameter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
638 |
* |
9 | 639 |
* @param WP_Post[] $most_recent An array of post objects being listed. |
640 |
* @param array $args An array of `WP_Query` arguments for the meta box. |
|
641 |
* @param array $box Arguments passed to `wp_nav_menu_item_post_type_meta_box()`. |
|
642 |
* @param array $recent_args An array of `WP_Query` arguments for 'Most Recent' tab. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
643 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
644 |
$most_recent = apply_filters( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
645 |
"nav_menu_items_{$post_type_name}_recent", |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
646 |
$most_recent, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
647 |
$args, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
648 |
$box, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
649 |
$recent_args |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
650 |
); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
651 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
652 |
echo walk_nav_menu_tree( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
653 |
array_map( 'wp_setup_nav_menu_item', $most_recent ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
654 |
0, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
655 |
(object) $args |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
656 |
); |
0 | 657 |
?> |
658 |
</ul> |
|
659 |
</div><!-- /.tabs-panel --> |
|
660 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
661 |
<div id="<?php echo esc_attr( "tabs-panel-posttype-{$post_type_name}-search" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
662 |
class="tabs-panel <?php echo ( 'search' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
663 |
role="region" aria-label="<?php echo esc_attr( $post_type->labels->search_items ); ?>" tabindex="0" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
664 |
> |
0 | 665 |
<?php |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
666 |
if ( isset( $_REQUEST[ "quick-search-posttype-{$post_type_name}" ] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
667 |
$searched = esc_attr( $_REQUEST[ "quick-search-posttype-{$post_type_name}" ] ); |
9 | 668 |
$search_results = get_posts( |
669 |
array( |
|
670 |
's' => $searched, |
|
671 |
'post_type' => $post_type_name, |
|
672 |
'fields' => 'all', |
|
673 |
'order' => 'DESC', |
|
674 |
) |
|
675 |
); |
|
0 | 676 |
} else { |
9 | 677 |
$searched = ''; |
0 | 678 |
$search_results = array(); |
679 |
} |
|
680 |
?> |
|
681 |
<p class="quick-search-wrap"> |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
682 |
<label for="<?php echo esc_attr( "quick-search-posttype-{$post_type_name}" ); ?>" class="screen-reader-text"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
683 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
684 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
685 |
_e( 'Search' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
686 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
687 |
</label> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
688 |
<input type="search"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
689 |
class="quick-search" value="<?php echo $searched; ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
690 |
name="<?php echo esc_attr( "quick-search-posttype-{$post_type_name}" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
691 |
id="<?php echo esc_attr( "quick-search-posttype-{$post_type_name}" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
692 |
/> |
0 | 693 |
<span class="spinner"></span> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
694 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
695 |
submit_button( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
696 |
__( 'Search' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
697 |
'small quick-search-submit hide-if-js', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
698 |
'submit', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
699 |
false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
700 |
array( 'id' => "submit-quick-search-posttype-{$post_type_name}" ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
701 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
702 |
?> |
0 | 703 |
</p> |
704 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
705 |
<ul id="<?php echo esc_attr( "{$post_type_name}-search-checklist" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
706 |
data-wp-lists="<?php echo esc_attr( "list:{$post_type_name}" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
707 |
class="categorychecklist form-no-clear" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
708 |
> |
0 | 709 |
<?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?> |
710 |
<?php |
|
711 |
$args['walker'] = $walker; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
712 |
echo walk_nav_menu_tree( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
713 |
array_map( 'wp_setup_nav_menu_item', $search_results ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
714 |
0, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
715 |
(object) $args |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
716 |
); |
0 | 717 |
?> |
718 |
<?php elseif ( is_wp_error( $search_results ) ) : ?> |
|
719 |
<li><?php echo $search_results->get_error_message(); ?></li> |
|
720 |
<?php elseif ( ! empty( $searched ) ) : ?> |
|
9 | 721 |
<li><?php _e( 'No results found.' ); ?></li> |
0 | 722 |
<?php endif; ?> |
723 |
</ul> |
|
724 |
</div><!-- /.tabs-panel --> |
|
725 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
726 |
<div id="<?php echo esc_attr( "{$post_type_name}-all" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
727 |
class="tabs-panel tabs-panel-view-all <?php echo ( 'all' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
728 |
role="region" aria-label="<?php echo esc_attr( $post_type->labels->all_items ); ?>" tabindex="0" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
729 |
> |
0 | 730 |
<?php if ( ! empty( $page_links ) ) : ?> |
731 |
<div class="add-menu-item-pagelinks"> |
|
732 |
<?php echo $page_links; ?> |
|
733 |
</div> |
|
734 |
<?php endif; ?> |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
735 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
736 |
<ul id="<?php echo esc_attr( "{$post_type_name}checklist" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
737 |
data-wp-lists="<?php echo esc_attr( "list:{$post_type_name}" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
738 |
class="categorychecklist form-no-clear" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
739 |
> |
0 | 740 |
<?php |
741 |
$args['walker'] = $walker; |
|
742 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
743 |
if ( $post_type->has_archive ) { |
18 | 744 |
$_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? (int) $_nav_menu_placeholder - 1 : -1; |
9 | 745 |
array_unshift( |
746 |
$posts, |
|
747 |
(object) array( |
|
748 |
'ID' => 0, |
|
749 |
'object_id' => $_nav_menu_placeholder, |
|
750 |
'object' => $post_type_name, |
|
751 |
'post_content' => '', |
|
752 |
'post_excerpt' => '', |
|
753 |
'post_title' => $post_type->labels->archives, |
|
754 |
'post_type' => 'nav_menu_item', |
|
755 |
'type' => 'post_type_archive', |
|
756 |
'url' => get_post_type_archive_link( $post_type_name ), |
|
757 |
) |
|
758 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
759 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
760 |
|
5 | 761 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
762 |
* Filters the posts displayed in the 'View All' tab of the current |
5 | 763 |
* post type's menu items meta box. |
764 |
* |
|
765 |
* The dynamic portion of the hook name, `$post_type_name`, refers |
|
766 |
* to the slug of the current post type. |
|
767 |
* |
|
18 | 768 |
* Possible hook names include: |
769 |
* |
|
770 |
* - `nav_menu_items_post` |
|
771 |
* - `nav_menu_items_page` |
|
772 |
* |
|
5 | 773 |
* @since 3.2.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
774 |
* @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object. |
5 | 775 |
* |
776 |
* @see WP_Query::query() |
|
777 |
* |
|
9 | 778 |
* @param object[] $posts The posts for the current post type. Mostly `WP_Post` objects, but |
779 |
* can also contain "fake" post objects to represent other menu items. |
|
780 |
* @param array $args An array of `WP_Query` arguments. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
781 |
* @param WP_Post_Type $post_type The current post type object for this menu item meta box. |
5 | 782 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
783 |
$posts = apply_filters( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
784 |
"nav_menu_items_{$post_type_name}", |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
785 |
$posts, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
786 |
$args, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
787 |
$post_type |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
788 |
); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
789 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
790 |
$checkbox_items = walk_nav_menu_tree( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
791 |
array_map( 'wp_setup_nav_menu_item', $posts ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
792 |
0, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
793 |
(object) $args |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
794 |
); |
0 | 795 |
|
796 |
echo $checkbox_items; |
|
797 |
?> |
|
798 |
</ul> |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
799 |
|
0 | 800 |
<?php if ( ! empty( $page_links ) ) : ?> |
801 |
<div class="add-menu-item-pagelinks"> |
|
802 |
<?php echo $page_links; ?> |
|
803 |
</div> |
|
804 |
<?php endif; ?> |
|
805 |
</div><!-- /.tabs-panel --> |
|
806 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
807 |
<p class="button-controls wp-clearfix" data-items-type="<?php echo esc_attr( "posttype-{$post_type_name}" ); ?>"> |
16 | 808 |
<span class="list-controls hide-if-no-js"> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
809 |
<input type="checkbox"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
810 |
id="<?php echo esc_attr( $tab_name ); ?>" class="select-all" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
811 |
/> |
16 | 812 |
<label for="<?php echo esc_attr( $tab_name ); ?>"><?php _e( 'Select All' ); ?></label> |
0 | 813 |
</span> |
814 |
||
815 |
<span class="add-to-menu"> |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
816 |
<input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
817 |
class="button submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
818 |
name="add-post-type-menu-item" id="<?php echo esc_attr( "submit-posttype-{$post_type_name}" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
819 |
/> |
0 | 820 |
<span class="spinner"></span> |
821 |
</span> |
|
822 |
</p> |
|
823 |
||
824 |
</div><!-- /.posttypediv --> |
|
825 |
<?php |
|
826 |
} |
|
827 |
||
828 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
829 |
* Displays a meta box for a taxonomy menu item. |
0 | 830 |
* |
831 |
* @since 3.0.0 |
|
832 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
833 |
* @global int|string $nav_menu_selected_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
834 |
* |
19 | 835 |
* @param string $data_object Not used. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
836 |
* @param array $box { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
837 |
* Taxonomy menu item meta box arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
838 |
* |
16 | 839 |
* @type string $id Meta box 'id' attribute. |
840 |
* @type string $title Meta box title. |
|
841 |
* @type callable $callback Meta box display callback. |
|
842 |
* @type object $args Extra meta box arguments (the taxonomy object for this meta box). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
843 |
* } |
0 | 844 |
*/ |
19 | 845 |
function wp_nav_menu_item_taxonomy_meta_box( $data_object, $box ) { |
0 | 846 |
global $nav_menu_selected_id; |
16 | 847 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
848 |
$taxonomy_name = $box['args']->name; |
9 | 849 |
$taxonomy = get_taxonomy( $taxonomy_name ); |
16 | 850 |
$tab_name = $taxonomy_name . '-tab'; |
0 | 851 |
|
5 | 852 |
// Paginate browsing for large numbers of objects. |
0 | 853 |
$per_page = 50; |
16 | 854 |
$pagenum = isset( $_REQUEST[ $tab_name ] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; |
9 | 855 |
$offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; |
0 | 856 |
|
857 |
$args = array( |
|
16 | 858 |
'taxonomy' => $taxonomy_name, |
9 | 859 |
'child_of' => 0, |
860 |
'exclude' => '', |
|
861 |
'hide_empty' => false, |
|
0 | 862 |
'hierarchical' => 1, |
9 | 863 |
'include' => '', |
864 |
'number' => $per_page, |
|
865 |
'offset' => $offset, |
|
866 |
'order' => 'ASC', |
|
867 |
'orderby' => 'name', |
|
868 |
'pad_counts' => false, |
|
0 | 869 |
); |
870 |
||
16 | 871 |
$terms = get_terms( $args ); |
0 | 872 |
|
9 | 873 |
if ( ! $terms || is_wp_error( $terms ) ) { |
0 | 874 |
echo '<p>' . __( 'No items.' ) . '</p>'; |
875 |
return; |
|
876 |
} |
|
877 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
878 |
$num_pages = (int) ceil( |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
879 |
(int) wp_count_terms( |
9 | 880 |
array_merge( |
881 |
$args, |
|
882 |
array( |
|
883 |
'number' => '', |
|
884 |
'offset' => '', |
|
885 |
) |
|
886 |
) |
|
887 |
) / $per_page |
|
888 |
); |
|
0 | 889 |
|
9 | 890 |
$page_links = paginate_links( |
891 |
array( |
|
892 |
'base' => add_query_arg( |
|
893 |
array( |
|
16 | 894 |
$tab_name => 'all', |
895 |
'paged' => '%#%', |
|
896 |
'item-type' => 'taxonomy', |
|
897 |
'item-object' => $taxonomy_name, |
|
9 | 898 |
) |
899 |
), |
|
900 |
'format' => '', |
|
901 |
'prev_text' => '<span aria-label="' . esc_attr__( 'Previous page' ) . '">' . __( '«' ) . '</span>', |
|
902 |
'next_text' => '<span aria-label="' . esc_attr__( 'Next page' ) . '">' . __( '»' ) . '</span>', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
903 |
/* translators: Hidden accessibility text. */ |
9 | 904 |
'before_page_number' => '<span class="screen-reader-text">' . __( 'Page' ) . '</span> ', |
905 |
'total' => $num_pages, |
|
906 |
'current' => $pagenum, |
|
907 |
) |
|
908 |
); |
|
0 | 909 |
|
910 |
$db_fields = false; |
|
911 |
if ( is_taxonomy_hierarchical( $taxonomy_name ) ) { |
|
9 | 912 |
$db_fields = array( |
913 |
'parent' => 'parent', |
|
914 |
'id' => 'term_id', |
|
915 |
); |
|
0 | 916 |
} |
917 |
||
918 |
$walker = new Walker_Nav_Menu_Checklist( $db_fields ); |
|
919 |
||
920 |
$current_tab = 'most-used'; |
|
16 | 921 |
|
922 |
if ( isset( $_REQUEST[ $tab_name ] ) && in_array( $_REQUEST[ $tab_name ], array( 'all', 'most-used', 'search' ), true ) ) { |
|
923 |
$current_tab = $_REQUEST[ $tab_name ]; |
|
0 | 924 |
} |
925 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
926 |
if ( ! empty( $_REQUEST[ "quick-search-taxonomy-{$taxonomy_name}" ] ) ) { |
0 | 927 |
$current_tab = 'search'; |
928 |
} |
|
929 |
||
930 |
$removed_args = array( |
|
931 |
'action', |
|
932 |
'customlink-tab', |
|
933 |
'edit-menu-item', |
|
934 |
'menu-item', |
|
935 |
'page-tab', |
|
936 |
'_wpnonce', |
|
937 |
); |
|
938 |
||
16 | 939 |
$most_used_url = ''; |
940 |
$view_all_url = ''; |
|
941 |
$search_url = ''; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
942 |
|
9 | 943 |
if ( $nav_menu_selected_id ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
944 |
$most_used_url = add_query_arg( $tab_name, 'most-used', remove_query_arg( $removed_args ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
945 |
$view_all_url = add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
946 |
$search_url = add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) ); |
9 | 947 |
} |
0 | 948 |
?> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
949 |
<div id="<?php echo esc_attr( "taxonomy-{$taxonomy_name}" ); ?>" class="taxonomydiv"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
950 |
<ul id="<?php echo esc_attr( "taxonomy-{$taxonomy_name}-tabs" ); ?>" class="taxonomy-tabs add-menu-item-tabs"> |
16 | 951 |
<li <?php echo ( 'most-used' === $current_tab ? ' class="tabs"' : '' ); ?>> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
952 |
<a class="nav-tab-link" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
953 |
data-type="<?php echo esc_attr( "tabs-panel-{$taxonomy_name}-pop" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
954 |
href="<?php echo esc_url( $most_used_url . "#tabs-panel-{$taxonomy_name}-pop" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
955 |
> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
956 |
<?php echo esc_html( $taxonomy->labels->most_used ); ?> |
0 | 957 |
</a> |
958 |
</li> |
|
16 | 959 |
<li <?php echo ( 'all' === $current_tab ? ' class="tabs"' : '' ); ?>> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
960 |
<a class="nav-tab-link" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
961 |
data-type="<?php echo esc_attr( "tabs-panel-{$taxonomy_name}-all" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
962 |
href="<?php echo esc_url( $view_all_url . "#tabs-panel-{$taxonomy_name}-all" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
963 |
> |
0 | 964 |
<?php _e( 'View All' ); ?> |
965 |
</a> |
|
966 |
</li> |
|
16 | 967 |
<li <?php echo ( 'search' === $current_tab ? ' class="tabs"' : '' ); ?>> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
968 |
<a class="nav-tab-link" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
969 |
data-type="<?php echo esc_attr( "tabs-panel-search-taxonomy-{$taxonomy_name}" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
970 |
href="<?php echo esc_url( $search_url . "#tabs-panel-search-taxonomy-{$taxonomy_name}" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
971 |
> |
0 | 972 |
<?php _e( 'Search' ); ?> |
973 |
</a> |
|
974 |
</li> |
|
975 |
</ul><!-- .taxonomy-tabs --> |
|
976 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
977 |
<div id="<?php echo esc_attr( "tabs-panel-{$taxonomy_name}-pop" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
978 |
class="tabs-panel <?php echo ( 'most-used' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
979 |
role="region" aria-label="<?php echo esc_attr( $taxonomy->labels->most_used ); ?>" tabindex="0" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
980 |
> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
981 |
<ul id="<?php echo esc_attr( "{$taxonomy_name}checklist-pop" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
982 |
class="categorychecklist form-no-clear" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
983 |
> |
0 | 984 |
<?php |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
985 |
$popular_terms = get_terms( |
9 | 986 |
array( |
16 | 987 |
'taxonomy' => $taxonomy_name, |
9 | 988 |
'orderby' => 'count', |
989 |
'order' => 'DESC', |
|
990 |
'number' => 10, |
|
991 |
'hierarchical' => false, |
|
992 |
) |
|
993 |
); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
994 |
|
0 | 995 |
$args['walker'] = $walker; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
996 |
echo walk_nav_menu_tree( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
997 |
array_map( 'wp_setup_nav_menu_item', $popular_terms ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
998 |
0, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
999 |
(object) $args |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1000 |
); |
0 | 1001 |
?> |
1002 |
</ul> |
|
1003 |
</div><!-- /.tabs-panel --> |
|
1004 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1005 |
<div id="<?php echo esc_attr( "tabs-panel-{$taxonomy_name}-all" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1006 |
class="tabs-panel tabs-panel-view-all <?php echo ( 'all' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1007 |
role="region" aria-label="<?php echo esc_attr( $taxonomy->labels->all_items ); ?>" tabindex="0" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1008 |
> |
0 | 1009 |
<?php if ( ! empty( $page_links ) ) : ?> |
1010 |
<div class="add-menu-item-pagelinks"> |
|
1011 |
<?php echo $page_links; ?> |
|
1012 |
</div> |
|
1013 |
<?php endif; ?> |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1014 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1015 |
<ul id="<?php echo esc_attr( "{$taxonomy_name}checklist" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1016 |
data-wp-lists="<?php echo esc_attr( "list:{$taxonomy_name}" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1017 |
class="categorychecklist form-no-clear" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1018 |
> |
0 | 1019 |
<?php |
1020 |
$args['walker'] = $walker; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1021 |
echo walk_nav_menu_tree( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1022 |
array_map( 'wp_setup_nav_menu_item', $terms ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1023 |
0, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1024 |
(object) $args |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1025 |
); |
0 | 1026 |
?> |
1027 |
</ul> |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1028 |
|
0 | 1029 |
<?php if ( ! empty( $page_links ) ) : ?> |
1030 |
<div class="add-menu-item-pagelinks"> |
|
1031 |
<?php echo $page_links; ?> |
|
1032 |
</div> |
|
1033 |
<?php endif; ?> |
|
1034 |
</div><!-- /.tabs-panel --> |
|
1035 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1036 |
<div id="<?php echo esc_attr( "tabs-panel-search-taxonomy-{$taxonomy_name}" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1037 |
class="tabs-panel <?php echo ( 'search' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1038 |
role="region" aria-label="<?php echo esc_attr( $taxonomy->labels->search_items ); ?>" tabindex="0"> |
0 | 1039 |
<?php |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1040 |
if ( isset( $_REQUEST[ "quick-search-taxonomy-{$taxonomy_name}" ] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1041 |
$searched = esc_attr( $_REQUEST[ "quick-search-taxonomy-{$taxonomy_name}" ] ); |
9 | 1042 |
$search_results = get_terms( |
1043 |
array( |
|
16 | 1044 |
'taxonomy' => $taxonomy_name, |
9 | 1045 |
'name__like' => $searched, |
1046 |
'fields' => 'all', |
|
1047 |
'orderby' => 'count', |
|
1048 |
'order' => 'DESC', |
|
1049 |
'hierarchical' => false, |
|
1050 |
) |
|
1051 |
); |
|
0 | 1052 |
} else { |
9 | 1053 |
$searched = ''; |
0 | 1054 |
$search_results = array(); |
1055 |
} |
|
1056 |
?> |
|
1057 |
<p class="quick-search-wrap"> |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1058 |
<label for="<?php echo esc_attr( "quick-search-taxonomy-{$taxonomy_name}" ); ?>" class="screen-reader-text"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1059 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1060 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1061 |
_e( 'Search' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1062 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1063 |
</label> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1064 |
<input type="search" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1065 |
class="quick-search" value="<?php echo $searched; ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1066 |
name="<?php echo esc_attr( "quick-search-taxonomy-{$taxonomy_name}" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1067 |
id="<?php echo esc_attr( "quick-search-taxonomy-{$taxonomy_name}" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1068 |
/> |
0 | 1069 |
<span class="spinner"></span> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1070 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1071 |
submit_button( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1072 |
__( 'Search' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1073 |
'small quick-search-submit hide-if-js', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1074 |
'submit', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1075 |
false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1076 |
array( 'id' => "submit-quick-search-taxonomy-{$taxonomy_name}" ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1077 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1078 |
?> |
0 | 1079 |
</p> |
1080 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1081 |
<ul id="<?php echo esc_attr( "{$taxonomy_name}-search-checklist" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1082 |
data-wp-lists="<?php echo esc_attr( "list:{$taxonomy_name}" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1083 |
class="categorychecklist form-no-clear" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1084 |
> |
0 | 1085 |
<?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?> |
1086 |
<?php |
|
1087 |
$args['walker'] = $walker; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1088 |
echo walk_nav_menu_tree( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1089 |
array_map( 'wp_setup_nav_menu_item', $search_results ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1090 |
0, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1091 |
(object) $args |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1092 |
); |
0 | 1093 |
?> |
1094 |
<?php elseif ( is_wp_error( $search_results ) ) : ?> |
|
1095 |
<li><?php echo $search_results->get_error_message(); ?></li> |
|
1096 |
<?php elseif ( ! empty( $searched ) ) : ?> |
|
9 | 1097 |
<li><?php _e( 'No results found.' ); ?></li> |
0 | 1098 |
<?php endif; ?> |
1099 |
</ul> |
|
1100 |
</div><!-- /.tabs-panel --> |
|
1101 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1102 |
<p class="button-controls wp-clearfix" data-items-type="<?php echo esc_attr( "taxonomy-{$taxonomy_name}" ); ?>"> |
16 | 1103 |
<span class="list-controls hide-if-no-js"> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1104 |
<input type="checkbox"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1105 |
id="<?php echo esc_attr( $tab_name ); ?>" class="select-all" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1106 |
/> |
16 | 1107 |
<label for="<?php echo esc_attr( $tab_name ); ?>"><?php _e( 'Select All' ); ?></label> |
0 | 1108 |
</span> |
1109 |
||
1110 |
<span class="add-to-menu"> |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1111 |
<input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1112 |
class="button submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1113 |
name="add-taxonomy-menu-item" id="<?php echo esc_attr( "submit-taxonomy-{$taxonomy_name}" ); ?>" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1114 |
/> |
0 | 1115 |
<span class="spinner"></span> |
1116 |
</span> |
|
1117 |
</p> |
|
1118 |
||
1119 |
</div><!-- /.taxonomydiv --> |
|
1120 |
<?php |
|
1121 |
} |
|
1122 |
||
1123 |
/** |
|
1124 |
* Save posted nav menu item data. |
|
1125 |
* |
|
1126 |
* @since 3.0.0 |
|
1127 |
* |
|
9 | 1128 |
* @param int $menu_id The menu ID for which to save this item. Value of 0 makes a draft, orphaned menu item. Default 0. |
1129 |
* @param array[] $menu_data The unsanitized POSTed menu item data. |
|
1130 |
* @return int[] The database IDs of the items saved |
|
0 | 1131 |
*/ |
1132 |
function wp_save_nav_menu_items( $menu_id = 0, $menu_data = array() ) { |
|
9 | 1133 |
$menu_id = (int) $menu_id; |
0 | 1134 |
$items_saved = array(); |
1135 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1136 |
if ( 0 === $menu_id || is_nav_menu( $menu_id ) ) { |
0 | 1137 |
|
5 | 1138 |
// Loop through all the menu items' POST values. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1139 |
foreach ( (array) $menu_data as $_possible_db_id => $_item_object_data ) { |
0 | 1140 |
if ( |
5 | 1141 |
// Checkbox is not checked. |
1142 |
empty( $_item_object_data['menu-item-object-id'] ) && |
|
0 | 1143 |
( |
5 | 1144 |
// And item type either isn't set. |
1145 |
! isset( $_item_object_data['menu-item-type'] ) || |
|
1146 |
// Or URL is the default. |
|
16 | 1147 |
in_array( $_item_object_data['menu-item-url'], array( 'https://', 'http://', '' ), true ) || |
1148 |
// Or it's not a custom menu item (but not the custom home page). |
|
1149 |
! ( 'custom' === $_item_object_data['menu-item-type'] && ! isset( $_item_object_data['menu-item-db-id'] ) ) || |
|
5 | 1150 |
// Or it *is* a custom menu item that already exists. |
1151 |
! empty( $_item_object_data['menu-item-db-id'] ) |
|
0 | 1152 |
) |
1153 |
) { |
|
5 | 1154 |
// Then this potential menu item is not getting added to this menu. |
1155 |
continue; |
|
0 | 1156 |
} |
1157 |
||
5 | 1158 |
// If this possible menu item doesn't actually have a menu database ID yet. |
0 | 1159 |
if ( |
1160 |
empty( $_item_object_data['menu-item-db-id'] ) || |
|
1161 |
( 0 > $_possible_db_id ) || |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1162 |
$_possible_db_id !== (int) $_item_object_data['menu-item-db-id'] |
0 | 1163 |
) { |
1164 |
$_actual_db_id = 0; |
|
1165 |
} else { |
|
1166 |
$_actual_db_id = (int) $_item_object_data['menu-item-db-id']; |
|
1167 |
} |
|
1168 |
||
1169 |
$args = array( |
|
9 | 1170 |
'menu-item-db-id' => ( isset( $_item_object_data['menu-item-db-id'] ) ? $_item_object_data['menu-item-db-id'] : '' ), |
1171 |
'menu-item-object-id' => ( isset( $_item_object_data['menu-item-object-id'] ) ? $_item_object_data['menu-item-object-id'] : '' ), |
|
1172 |
'menu-item-object' => ( isset( $_item_object_data['menu-item-object'] ) ? $_item_object_data['menu-item-object'] : '' ), |
|
1173 |
'menu-item-parent-id' => ( isset( $_item_object_data['menu-item-parent-id'] ) ? $_item_object_data['menu-item-parent-id'] : '' ), |
|
1174 |
'menu-item-position' => ( isset( $_item_object_data['menu-item-position'] ) ? $_item_object_data['menu-item-position'] : '' ), |
|
1175 |
'menu-item-type' => ( isset( $_item_object_data['menu-item-type'] ) ? $_item_object_data['menu-item-type'] : '' ), |
|
1176 |
'menu-item-title' => ( isset( $_item_object_data['menu-item-title'] ) ? $_item_object_data['menu-item-title'] : '' ), |
|
1177 |
'menu-item-url' => ( isset( $_item_object_data['menu-item-url'] ) ? $_item_object_data['menu-item-url'] : '' ), |
|
0 | 1178 |
'menu-item-description' => ( isset( $_item_object_data['menu-item-description'] ) ? $_item_object_data['menu-item-description'] : '' ), |
9 | 1179 |
'menu-item-attr-title' => ( isset( $_item_object_data['menu-item-attr-title'] ) ? $_item_object_data['menu-item-attr-title'] : '' ), |
1180 |
'menu-item-target' => ( isset( $_item_object_data['menu-item-target'] ) ? $_item_object_data['menu-item-target'] : '' ), |
|
1181 |
'menu-item-classes' => ( isset( $_item_object_data['menu-item-classes'] ) ? $_item_object_data['menu-item-classes'] : '' ), |
|
1182 |
'menu-item-xfn' => ( isset( $_item_object_data['menu-item-xfn'] ) ? $_item_object_data['menu-item-xfn'] : '' ), |
|
0 | 1183 |
); |
1184 |
||
1185 |
$items_saved[] = wp_update_nav_menu_item( $menu_id, $_actual_db_id, $args ); |
|
1186 |
||
1187 |
} |
|
1188 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1189 |
|
0 | 1190 |
return $items_saved; |
1191 |
} |
|
1192 |
||
1193 |
/** |
|
1194 |
* Adds custom arguments to some of the meta box object types. |
|
1195 |
* |
|
1196 |
* @since 3.0.0 |
|
1197 |
* |
|
1198 |
* @access private |
|
1199 |
* |
|
19 | 1200 |
* @param object $data_object The post type or taxonomy meta-object. |
16 | 1201 |
* @return object The post type or taxonomy object. |
0 | 1202 |
*/ |
19 | 1203 |
function _wp_nav_menu_meta_box_object( $data_object = null ) { |
1204 |
if ( isset( $data_object->name ) ) { |
|
0 | 1205 |
|
19 | 1206 |
if ( 'page' === $data_object->name ) { |
1207 |
$data_object->_default_query = array( |
|
9 | 1208 |
'orderby' => 'menu_order title', |
0 | 1209 |
'post_status' => 'publish', |
1210 |
); |
|
1211 |
||
9 | 1212 |
// Posts should show only published items. |
19 | 1213 |
} elseif ( 'post' === $data_object->name ) { |
1214 |
$data_object->_default_query = array( |
|
0 | 1215 |
'post_status' => 'publish', |
1216 |
); |
|
1217 |
||
9 | 1218 |
// Categories should be in reverse chronological order. |
19 | 1219 |
} elseif ( 'category' === $data_object->name ) { |
1220 |
$data_object->_default_query = array( |
|
0 | 1221 |
'orderby' => 'id', |
9 | 1222 |
'order' => 'DESC', |
0 | 1223 |
); |
1224 |
||
9 | 1225 |
// Custom post types should show only published items. |
0 | 1226 |
} else { |
19 | 1227 |
$data_object->_default_query = array( |
0 | 1228 |
'post_status' => 'publish', |
1229 |
); |
|
1230 |
} |
|
1231 |
} |
|
1232 |
||
19 | 1233 |
return $data_object; |
0 | 1234 |
} |
1235 |
||
1236 |
/** |
|
1237 |
* Returns the menu formatted to edit. |
|
1238 |
* |
|
1239 |
* @since 3.0.0 |
|
1240 |
* |
|
5 | 1241 |
* @param int $menu_id Optional. The ID of the menu to format. Default 0. |
16 | 1242 |
* @return string|WP_Error The menu formatted to edit or error object on failure. |
0 | 1243 |
*/ |
1244 |
function wp_get_nav_menu_to_edit( $menu_id = 0 ) { |
|
1245 |
$menu = wp_get_nav_menu_object( $menu_id ); |
|
1246 |
||
1247 |
// If the menu exists, get its items. |
|
1248 |
if ( is_nav_menu( $menu ) ) { |
|
9 | 1249 |
$menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'post_status' => 'any' ) ); |
1250 |
$result = '<div id="menu-instructions" class="post-body-plain'; |
|
1251 |
$result .= ( ! empty( $menu_items ) ) ? ' menu-instructions-inactive">' : '">'; |
|
1252 |
$result .= '<p>' . __( 'Add menu items from the column on the left.' ) . '</p>'; |
|
1253 |
$result .= '</div>'; |
|
0 | 1254 |
|
9 | 1255 |
if ( empty( $menu_items ) ) { |
0 | 1256 |
return $result . ' <ul class="menu" id="menu-to-edit"> </ul>'; |
9 | 1257 |
} |
0 | 1258 |
|
5 | 1259 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1260 |
* Filters the Walker class used when adding nav menu items. |
5 | 1261 |
* |
1262 |
* @since 3.0.0 |
|
1263 |
* |
|
1264 |
* @param string $class The walker class to use. Default 'Walker_Nav_Menu_Edit'. |
|
1265 |
* @param int $menu_id ID of the menu being rendered. |
|
1266 |
*/ |
|
0 | 1267 |
$walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $menu_id ); |
1268 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1269 |
if ( class_exists( $walker_class_name ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1270 |
$walker = new $walker_class_name(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1271 |
} else { |
9 | 1272 |
return new WP_Error( |
1273 |
'menu_walker_not_exist', |
|
1274 |
sprintf( |
|
16 | 1275 |
/* translators: %s: Walker class name. */ |
9 | 1276 |
__( 'The Walker class named %s does not exist.' ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1277 |
'<strong>' . $walker_class_name . '</strong>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1278 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1279 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1280 |
} |
0 | 1281 |
|
16 | 1282 |
$some_pending_menu_items = false; |
1283 |
$some_invalid_menu_items = false; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1284 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1285 |
foreach ( (array) $menu_items as $menu_item ) { |
16 | 1286 |
if ( isset( $menu_item->post_status ) && 'draft' === $menu_item->post_status ) { |
0 | 1287 |
$some_pending_menu_items = true; |
9 | 1288 |
} |
1289 |
if ( ! empty( $menu_item->_invalid ) ) { |
|
0 | 1290 |
$some_invalid_menu_items = true; |
9 | 1291 |
} |
0 | 1292 |
} |
1293 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1294 |
if ( $some_pending_menu_items ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1295 |
$message = __( 'Click Save Menu to make pending menu items public.' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1296 |
$notice_args = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1297 |
'type' => 'info', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1298 |
'additional_classes' => array( 'notice-alt', 'inline' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1299 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1300 |
$result .= wp_get_admin_notice( $message, $notice_args ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1301 |
} |
0 | 1302 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1303 |
if ( $some_invalid_menu_items ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1304 |
$message = __( 'There are some invalid menu items. Please check or delete them.' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1305 |
$notice_args = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1306 |
'type' => 'error', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1307 |
'additional_classes' => array( 'notice-alt', 'inline' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1308 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1309 |
$result .= wp_get_admin_notice( $message, $notice_args ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1310 |
} |
0 | 1311 |
|
1312 |
$result .= '<ul class="menu" id="menu-to-edit"> '; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1313 |
$result .= walk_nav_menu_tree( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1314 |
array_map( 'wp_setup_nav_menu_item', $menu_items ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1315 |
0, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1316 |
(object) array( 'walker' => $walker ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1317 |
); |
0 | 1318 |
$result .= ' </ul> '; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1319 |
|
0 | 1320 |
return $result; |
1321 |
} elseif ( is_wp_error( $menu ) ) { |
|
1322 |
return $menu; |
|
1323 |
} |
|
1324 |
} |
|
1325 |
||
1326 |
/** |
|
1327 |
* Returns the columns for the nav menus page. |
|
1328 |
* |
|
1329 |
* @since 3.0.0 |
|
1330 |
* |
|
16 | 1331 |
* @return string[] Array of column titles keyed by their column name. |
0 | 1332 |
*/ |
1333 |
function wp_nav_menu_manage_columns() { |
|
1334 |
return array( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1335 |
'_title' => __( 'Show advanced menu properties' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1336 |
'cb' => '<input type="checkbox" />', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1337 |
'link-target' => __( 'Link Target' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1338 |
'title-attribute' => __( 'Title Attribute' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1339 |
'css-classes' => __( 'CSS Classes' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1340 |
'xfn' => __( 'Link Relationship (XFN)' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1341 |
'description' => __( 'Description' ), |
0 | 1342 |
); |
1343 |
} |
|
1344 |
||
1345 |
/** |
|
1346 |
* Deletes orphaned draft menu items |
|
1347 |
* |
|
1348 |
* @access private |
|
1349 |
* @since 3.0.0 |
|
1350 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1351 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 1352 |
*/ |
1353 |
function _wp_delete_orphaned_draft_menu_items() { |
|
1354 |
global $wpdb; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1355 |
|
0 | 1356 |
$delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); |
1357 |
||
5 | 1358 |
// Delete orphaned draft menu items. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1359 |
$menu_items_to_delete = $wpdb->get_col( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1360 |
$wpdb->prepare( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1361 |
"SELECT ID FROM $wpdb->posts AS p |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1362 |
LEFT JOIN $wpdb->postmeta AS m ON p.ID = m.post_id |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1363 |
WHERE post_type = 'nav_menu_item' AND post_status = 'draft' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1364 |
AND meta_key = '_menu_item_orphaned' AND meta_value < %d", |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1365 |
$delete_timestamp |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1366 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1367 |
); |
0 | 1368 |
|
9 | 1369 |
foreach ( (array) $menu_items_to_delete as $menu_item_id ) { |
0 | 1370 |
wp_delete_post( $menu_item_id, true ); |
9 | 1371 |
} |
0 | 1372 |
} |
1373 |
||
1374 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1375 |
* Saves nav menu items. |
0 | 1376 |
* |
1377 |
* @since 3.6.0 |
|
1378 |
* |
|
16 | 1379 |
* @param int|string $nav_menu_selected_id ID, slug, or name of the currently-selected menu. |
1380 |
* @param string $nav_menu_selected_title Title of the currently-selected menu. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1381 |
* @return string[] The menu updated messages. |
0 | 1382 |
*/ |
9 | 1383 |
function wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title ) { |
1384 |
$unsorted_menu_items = wp_get_nav_menu_items( |
|
1385 |
$nav_menu_selected_id, |
|
1386 |
array( |
|
1387 |
'orderby' => 'ID', |
|
1388 |
'output' => ARRAY_A, |
|
1389 |
'output_key' => 'ID', |
|
1390 |
'post_status' => 'draft,publish', |
|
1391 |
) |
|
1392 |
); |
|
16 | 1393 |
|
1394 |
$messages = array(); |
|
1395 |
$menu_items = array(); |
|
1396 |
||
1397 |
// Index menu items by DB ID. |
|
9 | 1398 |
foreach ( $unsorted_menu_items as $_item ) { |
1399 |
$menu_items[ $_item->db_id ] = $_item; |
|
1400 |
} |
|
0 | 1401 |
|
1402 |
$post_fields = array( |
|
9 | 1403 |
'menu-item-db-id', |
1404 |
'menu-item-object-id', |
|
1405 |
'menu-item-object', |
|
1406 |
'menu-item-parent-id', |
|
1407 |
'menu-item-position', |
|
1408 |
'menu-item-type', |
|
1409 |
'menu-item-title', |
|
1410 |
'menu-item-url', |
|
1411 |
'menu-item-description', |
|
1412 |
'menu-item-attr-title', |
|
1413 |
'menu-item-target', |
|
1414 |
'menu-item-classes', |
|
1415 |
'menu-item-xfn', |
|
0 | 1416 |
); |
1417 |
||
1418 |
wp_defer_term_counting( true ); |
|
16 | 1419 |
|
1420 |
// Loop through all the menu items' POST variables. |
|
0 | 1421 |
if ( ! empty( $_POST['menu-item-db-id'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1422 |
foreach ( (array) $_POST['menu-item-db-id'] as $_key => $k ) { |
0 | 1423 |
|
16 | 1424 |
// Menu item title can't be blank. |
1425 |
if ( ! isset( $_POST['menu-item-title'][ $_key ] ) || '' === $_POST['menu-item-title'][ $_key ] ) { |
|
0 | 1426 |
continue; |
9 | 1427 |
} |
0 | 1428 |
|
1429 |
$args = array(); |
|
9 | 1430 |
foreach ( $post_fields as $field ) { |
1431 |
$args[ $field ] = isset( $_POST[ $field ][ $_key ] ) ? $_POST[ $field ][ $_key ] : ''; |
|
1432 |
} |
|
0 | 1433 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1434 |
$menu_item_db_id = wp_update_nav_menu_item( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1435 |
$nav_menu_selected_id, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1436 |
( (int) $_POST['menu-item-db-id'][ $_key ] !== $_key ? 0 : $_key ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1437 |
$args |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1438 |
); |
0 | 1439 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1440 |
if ( is_wp_error( $menu_item_db_id ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1441 |
$messages[] = wp_get_admin_notice( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1442 |
$menu_item_db_id->get_error_message(), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1443 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1444 |
'id' => 'message', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1445 |
'additional_classes' => array( 'error' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1446 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1447 |
); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1448 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1449 |
unset( $menu_items[ $menu_item_db_id ] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1450 |
} |
0 | 1451 |
} |
1452 |
} |
|
1453 |
||
16 | 1454 |
// Remove menu items from the menu that weren't in $_POST. |
0 | 1455 |
if ( ! empty( $menu_items ) ) { |
1456 |
foreach ( array_keys( $menu_items ) as $menu_item_id ) { |
|
1457 |
if ( is_nav_menu_item( $menu_item_id ) ) { |
|
1458 |
wp_delete_post( $menu_item_id ); |
|
1459 |
} |
|
1460 |
} |
|
1461 |
} |
|
1462 |
||
1463 |
// Store 'auto-add' pages. |
|
9 | 1464 |
$auto_add = ! empty( $_POST['auto-add-pages'] ); |
0 | 1465 |
$nav_menu_option = (array) get_option( 'nav_menu_options' ); |
16 | 1466 |
|
9 | 1467 |
if ( ! isset( $nav_menu_option['auto_add'] ) ) { |
0 | 1468 |
$nav_menu_option['auto_add'] = array(); |
9 | 1469 |
} |
16 | 1470 |
|
0 | 1471 |
if ( $auto_add ) { |
16 | 1472 |
if ( ! in_array( $nav_menu_selected_id, $nav_menu_option['auto_add'], true ) ) { |
0 | 1473 |
$nav_menu_option['auto_add'][] = $nav_menu_selected_id; |
9 | 1474 |
} |
0 | 1475 |
} else { |
16 | 1476 |
$key = array_search( $nav_menu_selected_id, $nav_menu_option['auto_add'], true ); |
1477 |
if ( false !== $key ) { |
|
9 | 1478 |
unset( $nav_menu_option['auto_add'][ $key ] ); |
1479 |
} |
|
0 | 1480 |
} |
16 | 1481 |
|
1482 |
// Remove non-existent/deleted menus. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1483 |
$nav_menu_option['auto_add'] = array_intersect( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1484 |
$nav_menu_option['auto_add'], |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1485 |
wp_get_nav_menus( array( 'fields' => 'ids' ) ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1486 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1487 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1488 |
update_option( 'nav_menu_options', $nav_menu_option, false ); |
0 | 1489 |
|
1490 |
wp_defer_term_counting( false ); |
|
1491 |
||
5 | 1492 |
/** This action is documented in wp-includes/nav-menu.php */ |
0 | 1493 |
do_action( 'wp_update_nav_menu', $nav_menu_selected_id ); |
1494 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1495 |
/* translators: %s: Nav menu title. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1496 |
$message = sprintf( __( '%s has been updated.' ), '<strong>' . $nav_menu_selected_title . '</strong>' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1497 |
$notice_args = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1498 |
'id' => 'message', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1499 |
'dismissible' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1500 |
'additional_classes' => array( 'updated' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1501 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1502 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1503 |
$messages[] = wp_get_admin_notice( $message, $notice_args ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1504 |
|
0 | 1505 |
unset( $menu_items, $unsorted_menu_items ); |
1506 |
||
1507 |
return $messages; |
|
1508 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1509 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1510 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1511 |
* If a JSON blob of navigation menu data is in POST data, expand it and inject |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1512 |
* it into `$_POST` to avoid PHP `max_input_vars` limitations. See #14134. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1513 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1514 |
* @ignore |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1515 |
* @since 4.5.3 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1516 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1517 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1518 |
function _wp_expand_nav_menu_post_data() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1519 |
if ( ! isset( $_POST['nav-menu-data'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1520 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1521 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1522 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1523 |
$data = json_decode( stripslashes( $_POST['nav-menu-data'] ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1524 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1525 |
if ( ! is_null( $data ) && $data ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1526 |
foreach ( $data as $post_input_data ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1527 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1528 |
* For input names that are arrays (e.g. `menu-item-db-id[3][4][5]`), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1529 |
* derive the array path keys via regex and set the value in $_POST. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1530 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1531 |
preg_match( '#([^\[]*)(\[(.+)\])?#', $post_input_data->name, $matches ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1532 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1533 |
$array_bits = array( $matches[1] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1534 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1535 |
if ( isset( $matches[3] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1536 |
$array_bits = array_merge( $array_bits, explode( '][', $matches[3] ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1537 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1538 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1539 |
$new_post_data = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1540 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1541 |
// Build the new array value from leaf to trunk. |
16 | 1542 |
for ( $i = count( $array_bits ) - 1; $i >= 0; $i-- ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1543 |
if ( count( $array_bits ) - 1 === $i ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1544 |
$new_post_data[ $array_bits[ $i ] ] = wp_slash( $post_input_data->value ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1545 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1546 |
$new_post_data = array( $array_bits[ $i ] => $new_post_data ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1547 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1548 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1549 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1550 |
$_POST = array_replace_recursive( $_POST, $new_post_data ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1551 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1552 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1553 |
} |