| 1 | Index: wp-includes/taxonomy.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-includes/taxonomy.php (revision 20037) |
|---|
| 4 | +++ wp-includes/taxonomy.php (working copy) |
|---|
| 5 | @@ -43,73 +43,80 @@ |
|---|
| 6 | |
|---|
| 7 | register_taxonomy( 'category', 'post', array( |
|---|
| 8 | 'hierarchical' => true, |
|---|
| 9 | - 'query_var' => 'category_name', |
|---|
| 10 | - 'rewrite' => $rewrite['category'], |
|---|
| 11 | - 'public' => true, |
|---|
| 12 | - 'show_ui' => true, |
|---|
| 13 | - '_builtin' => true, |
|---|
| 14 | + 'query_var' => 'category_name', |
|---|
| 15 | + 'rewrite' => $rewrite['category'], |
|---|
| 16 | + 'public' => true, |
|---|
| 17 | + 'show_ui' => true, |
|---|
| 18 | + '_builtin' => true, |
|---|
| 19 | + 'input' => 'checkbox', |
|---|
| 20 | ) ); |
|---|
| 21 | |
|---|
| 22 | register_taxonomy( 'post_tag', 'post', array( |
|---|
| 23 | - 'hierarchical' => false, |
|---|
| 24 | - 'query_var' => 'tag', |
|---|
| 25 | - 'rewrite' => $rewrite['post_tag'], |
|---|
| 26 | - 'public' => true, |
|---|
| 27 | - 'show_ui' => true, |
|---|
| 28 | - '_builtin' => true, |
|---|
| 29 | + 'hierarchical' => false, |
|---|
| 30 | + 'query_var' => 'tag', |
|---|
| 31 | + 'rewrite' => $rewrite['post_tag'], |
|---|
| 32 | + 'public' => true, |
|---|
| 33 | + 'show_ui' => true, |
|---|
| 34 | + '_builtin' => true, |
|---|
| 35 | + 'input' => 'text', |
|---|
| 36 | ) ); |
|---|
| 37 | |
|---|
| 38 | register_taxonomy( 'nav_menu', 'nav_menu_item', array( |
|---|
| 39 | - 'public' => false, |
|---|
| 40 | - 'hierarchical' => false, |
|---|
| 41 | - 'labels' => array( |
|---|
| 42 | - 'name' => __( 'Navigation Menus' ), |
|---|
| 43 | - 'singular_name' => __( 'Navigation Menu' ), |
|---|
| 44 | + 'public' => false, |
|---|
| 45 | + 'hierarchical' => false, |
|---|
| 46 | + 'labels' => array( |
|---|
| 47 | + 'name' => __( 'Navigation Menus' ), |
|---|
| 48 | + 'singular_name' => __( 'Navigation Menu' ), |
|---|
| 49 | ), |
|---|
| 50 | - 'query_var' => false, |
|---|
| 51 | - 'rewrite' => false, |
|---|
| 52 | - 'show_ui' => false, |
|---|
| 53 | - '_builtin' => true, |
|---|
| 54 | + 'query_var' => false, |
|---|
| 55 | + 'rewrite' => false, |
|---|
| 56 | + 'show_ui' => false, |
|---|
| 57 | + '_builtin' => true, |
|---|
| 58 | 'show_in_nav_menus' => false, |
|---|
| 59 | + 'input' => null, |
|---|
| 60 | ) ); |
|---|
| 61 | |
|---|
| 62 | register_taxonomy( 'link_category', 'link', array( |
|---|
| 63 | - 'hierarchical' => false, |
|---|
| 64 | - 'labels' => array( |
|---|
| 65 | - 'name' => __( 'Link Categories' ), |
|---|
| 66 | - 'singular_name' => __( 'Link Category' ), |
|---|
| 67 | - 'search_items' => __( 'Search Link Categories' ), |
|---|
| 68 | - 'popular_items' => null, |
|---|
| 69 | - 'all_items' => __( 'All Link Categories' ), |
|---|
| 70 | - 'edit_item' => __( 'Edit Link Category' ), |
|---|
| 71 | - 'update_item' => __( 'Update Link Category' ), |
|---|
| 72 | - 'add_new_item' => __( 'Add New Link Category' ), |
|---|
| 73 | - 'new_item_name' => __( 'New Link Category Name' ), |
|---|
| 74 | + 'hierarchical' => false, |
|---|
| 75 | + 'labels' => array( |
|---|
| 76 | + 'name' => __( 'Link Categories' ), |
|---|
| 77 | + 'singular_name' => __( 'Link Category' ), |
|---|
| 78 | + 'search_items' => __( 'Search Link Categories' ), |
|---|
| 79 | + 'popular_items' => null, |
|---|
| 80 | + 'all_items' => __( 'All Link Categories' ), |
|---|
| 81 | + 'edit_item' => __( 'Edit Link Category' ), |
|---|
| 82 | + 'update_item' => __( 'Update Link Category' ), |
|---|
| 83 | + 'add_new_item' => __( 'Add New Link Category' ), |
|---|
| 84 | + 'new_item_name' => __( 'New Link Category Name' ), |
|---|
| 85 | 'separate_items_with_commas' => null, |
|---|
| 86 | - 'add_or_remove_items' => null, |
|---|
| 87 | - 'choose_from_most_used' => null, |
|---|
| 88 | + 'add_or_remove_items' => null, |
|---|
| 89 | + 'choose_from_most_used' => null, |
|---|
| 90 | ), |
|---|
| 91 | - 'query_var' => false, |
|---|
| 92 | - 'rewrite' => false, |
|---|
| 93 | - 'public' => false, |
|---|
| 94 | - 'show_ui' => false, |
|---|
| 95 | - '_builtin' => true, |
|---|
| 96 | + 'query_var' => false, |
|---|
| 97 | + 'rewrite' => false, |
|---|
| 98 | + 'public' => false, |
|---|
| 99 | + 'show_ui' => false, |
|---|
| 100 | + '_builtin' => true, |
|---|
| 101 | + 'input' => null, |
|---|
| 102 | ) ); |
|---|
| 103 | |
|---|
| 104 | register_taxonomy( 'post_format', 'post', array( |
|---|
| 105 | - 'public' => true, |
|---|
| 106 | - 'hierarchical' => false, |
|---|
| 107 | - 'labels' => array( |
|---|
| 108 | - 'name' => _x( 'Format', 'post format' ), |
|---|
| 109 | - 'singular_name' => _x( 'Format', 'post format' ), |
|---|
| 110 | + 'public' => true, |
|---|
| 111 | + 'hierarchical' => false, |
|---|
| 112 | + 'labels' => array( |
|---|
| 113 | + 'name' => _x( 'Format', 'post format' ), |
|---|
| 114 | + 'singular_name' => _x( 'Format', 'post format' ), |
|---|
| 115 | ), |
|---|
| 116 | - 'query_var' => true, |
|---|
| 117 | - 'rewrite' => $rewrite['post_format'], |
|---|
| 118 | - 'show_ui' => false, |
|---|
| 119 | - '_builtin' => true, |
|---|
| 120 | + 'query_var' => true, |
|---|
| 121 | + 'rewrite' => $rewrite['post_format'], |
|---|
| 122 | + 'show_ui' => false, |
|---|
| 123 | + '_builtin' => true, |
|---|
| 124 | 'show_in_nav_menus' => current_theme_supports( 'post-formats' ), |
|---|
| 125 | + 'input' => null, |
|---|
| 126 | ) ); |
|---|
| 127 | + |
|---|
| 128 | } |
|---|
| 129 | + |
|---|
| 130 | add_action( 'init', 'create_initial_taxonomies', 0 ); // highest priority |
|---|
| 131 | |
|---|
| 132 | /** |
|---|
| 133 | @@ -292,6 +299,8 @@ |
|---|
| 134 | * |
|---|
| 135 | * labels - An array of labels for this taxonomy. You can see accepted values in {@link get_taxonomy_labels()}. By default tag labels are used for non-hierarchical types and category labels for hierarchical ones. |
|---|
| 136 | * |
|---|
| 137 | + * input - the type of metabox to display on the post edit screen. Choices include text (tags), checkbox (categories), radio (exclusive), or dropdown (exclusive). Note: exclusive inputs limit the user to selecting only one term. |
|---|
| 138 | + * |
|---|
| 139 | * @package WordPress |
|---|
| 140 | * @subpackage Taxonomy |
|---|
| 141 | * @since 2.3.0 |
|---|
| 142 | @@ -308,18 +317,21 @@ |
|---|
| 143 | if ( ! is_array($wp_taxonomies) ) |
|---|
| 144 | $wp_taxonomies = array(); |
|---|
| 145 | |
|---|
| 146 | - $defaults = array( 'hierarchical' => false, |
|---|
| 147 | + $defaults = array( |
|---|
| 148 | + 'hierarchical' => false, |
|---|
| 149 | 'update_count_callback' => '', |
|---|
| 150 | - 'rewrite' => true, |
|---|
| 151 | - 'query_var' => $taxonomy, |
|---|
| 152 | - 'public' => true, |
|---|
| 153 | - 'show_ui' => null, |
|---|
| 154 | - 'show_tagcloud' => null, |
|---|
| 155 | - '_builtin' => false, |
|---|
| 156 | - 'labels' => array(), |
|---|
| 157 | - 'capabilities' => array(), |
|---|
| 158 | - 'show_in_nav_menus' => null, |
|---|
| 159 | + 'rewrite' => true, |
|---|
| 160 | + 'query_var' => $taxonomy, |
|---|
| 161 | + 'public' => true, |
|---|
| 162 | + 'show_ui' => null, |
|---|
| 163 | + 'show_tagcloud' => null, |
|---|
| 164 | + '_builtin' => false, |
|---|
| 165 | + 'labels' => array(), |
|---|
| 166 | + 'capabilities' => array(), |
|---|
| 167 | + 'show_in_nav_menus' => null, |
|---|
| 168 | + 'input' => 'input', |
|---|
| 169 | ); |
|---|
| 170 | + |
|---|
| 171 | $args = wp_parse_args($args, $defaults); |
|---|
| 172 | |
|---|
| 173 | if ( false !== $args['query_var'] && !empty($wp) ) { |
|---|
| 174 | @@ -348,6 +360,10 @@ |
|---|
| 175 | |
|---|
| 176 | if ( is_null($args['show_ui']) ) |
|---|
| 177 | $args['show_ui'] = $args['public']; |
|---|
| 178 | + |
|---|
| 179 | + //if no input is specified and UI is not used, set default to null to avoid confusion |
|---|
| 180 | + if ( !$args['show_ui'] && is_null( $args['input'] ) ) |
|---|
| 181 | + $args['input'] = null; |
|---|
| 182 | |
|---|
| 183 | // Whether to show this type in nav-menus.php. Defaults to the setting for public. |
|---|
| 184 | if ( null === $args['show_in_nav_menus'] ) |
|---|
| 185 | @@ -1881,7 +1897,7 @@ |
|---|
| 186 | $object_ids = array($object_ids); |
|---|
| 187 | $object_ids = array_map('intval', $object_ids); |
|---|
| 188 | |
|---|
| 189 | - $defaults = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'all'); |
|---|
| 190 | + $defaults = array( 'orderby' => 'name', 'order' => 'ASC', 'fields' => 'all' ); |
|---|
| 191 | $args = wp_parse_args( $args, $defaults ); |
|---|
| 192 | |
|---|
| 193 | $terms = array(); |
|---|
| 194 | @@ -2146,6 +2162,10 @@ |
|---|
| 195 | |
|---|
| 196 | if ( ! taxonomy_exists($taxonomy) ) |
|---|
| 197 | return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy')); |
|---|
| 198 | + |
|---|
| 199 | + //if this is an exclusive taxonomy, and users has passed more than 1 term, only accept the first |
|---|
| 200 | + if ( is_array( $terms ) && in_array( get_taxonomy( $taxonomy )->input, array( 'dropdown', 'radio' ) ) ) |
|---|
| 201 | + $terms = array_shift( $terms ); |
|---|
| 202 | |
|---|
| 203 | if ( !is_array($terms) ) |
|---|
| 204 | $terms = array($terms); |
|---|
| 205 | Index: wp-includes/post.php |
|---|
| 206 | =================================================================== |
|---|
| 207 | --- wp-includes/post.php (revision 20037) |
|---|
| 208 | +++ wp-includes/post.php (working copy) |
|---|
| 209 | @@ -2410,7 +2410,7 @@ |
|---|
| 210 | * @param bool $wp_error Optional. Allow return of WP_Error on failure. |
|---|
| 211 | * @return int|WP_Error The value 0 or WP_Error on failure. The post ID on success. |
|---|
| 212 | */ |
|---|
| 213 | -function wp_insert_post($postarr, $wp_error = false) { |
|---|
| 214 | +function wp_insert_post($postarr, $wp_error = false) { |
|---|
| 215 | global $wpdb, $user_ID; |
|---|
| 216 | |
|---|
| 217 | $defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_ID, |
|---|
| 218 | @@ -2611,10 +2611,18 @@ |
|---|
| 219 | if ( !empty($tax_input) ) { |
|---|
| 220 | foreach ( $tax_input as $taxonomy => $tags ) { |
|---|
| 221 | $taxonomy_obj = get_taxonomy($taxonomy); |
|---|
| 222 | - if ( is_array($tags) ) // array = hierarchical, string = non-hierarchical. |
|---|
| 223 | + |
|---|
| 224 | + // array = hierarchical, string = non-hierarchical. |
|---|
| 225 | + if ( is_array($tags) ) |
|---|
| 226 | $tags = array_filter($tags); |
|---|
| 227 | + |
|---|
| 228 | + //exclusive taxonomies pass IDs rather than slugs, typecast to prevent confusion |
|---|
| 229 | + if ( $taxonomy_obj->input == 'radio' || $taxonomy_obj->input == 'dropdown' ) |
|---|
| 230 | + $tags = array( (int) $tags ); |
|---|
| 231 | + |
|---|
| 232 | if ( current_user_can($taxonomy_obj->cap->assign_terms) ) |
|---|
| 233 | wp_set_post_terms( $post_ID, $tags, $taxonomy ); |
|---|
| 234 | + |
|---|
| 235 | } |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | Index: wp-admin/includes/template.php |
|---|
| 239 | =================================================================== |
|---|
| 240 | --- wp-admin/includes/template.php (revision 20037) |
|---|
| 241 | +++ wp-admin/includes/template.php (working copy) |
|---|
| 242 | @@ -40,9 +40,13 @@ |
|---|
| 243 | $name = 'post_category'; |
|---|
| 244 | else |
|---|
| 245 | $name = 'tax_input['.$taxonomy.']'; |
|---|
| 246 | - |
|---|
| 247 | + |
|---|
| 248 | + //if this is not a radio input, each checkbox should be individually named with []'s |
|---|
| 249 | + if ( $input != 'radio' ) |
|---|
| 250 | + $name .= '[]'; |
|---|
| 251 | + |
|---|
| 252 | $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : ''; |
|---|
| 253 | - $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' . checked( in_array( $category->term_id, $selected_cats ), true, false ) . disabled( empty( $args['disabled'] ), false, false ) . ' /> ' . esc_html( apply_filters('the_category', $category->name )) . '</label>'; |
|---|
| 254 | + $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="'.$input.'" name="'.$name.'" id="in-'.$taxonomy.'-' . $category->term_id . '"' . checked( in_array( $category->term_id, $selected_cats ), true, false ) . disabled( empty( $args['disabled'] ), false, false ) . ' /> ' . esc_html( apply_filters('the_category', $category->name )) . '</label>'; |
|---|
| 255 | } |
|---|
| 256 | |
|---|
| 257 | function end_el( &$output, $category, $depth = 0, $args = array() ) { |
|---|
| 258 | @@ -87,7 +91,7 @@ |
|---|
| 259 | 'popular_cats' => false, |
|---|
| 260 | 'walker' => null, |
|---|
| 261 | 'taxonomy' => 'category', |
|---|
| 262 | - 'checked_ontop' => true |
|---|
| 263 | + 'checked_ontop' => true, |
|---|
| 264 | ); |
|---|
| 265 | extract( wp_parse_args($args, $defaults), EXTR_SKIP ); |
|---|
| 266 | |
|---|
| 267 | @@ -120,6 +124,12 @@ |
|---|
| 268 | } else { |
|---|
| 269 | $categories = (array) get_terms($taxonomy, array('get' => 'all')); |
|---|
| 270 | } |
|---|
| 271 | + |
|---|
| 272 | + //set input type |
|---|
| 273 | + if ( $tax->input == 'radio' ) |
|---|
| 274 | + $args['input'] = 'radio'; |
|---|
| 275 | + else |
|---|
| 276 | + $args['input'] = 'checkbox'; |
|---|
| 277 | |
|---|
| 278 | if ( $checked_ontop ) { |
|---|
| 279 | // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache) |
|---|
| 280 | Index: wp-admin/includes/meta-boxes.php |
|---|
| 281 | =================================================================== |
|---|
| 282 | --- wp-admin/includes/meta-boxes.php (revision 20037) |
|---|
| 283 | +++ wp-admin/includes/meta-boxes.php (working copy) |
|---|
| 284 | @@ -232,51 +232,44 @@ |
|---|
| 285 | } |
|---|
| 286 | |
|---|
| 287 | /** |
|---|
| 288 | - * Display post format form elements. |
|---|
| 289 | - * |
|---|
| 290 | - * @since 3.1.0 |
|---|
| 291 | - * |
|---|
| 292 | + * Renders metabox for a given taxonomy |
|---|
| 293 | + * Taxonomy should be passed via the initial filter as an argument within the box array |
|---|
| 294 | + * @since 3.4 |
|---|
| 295 | * @param object $post |
|---|
| 296 | + * @param array $box |
|---|
| 297 | */ |
|---|
| 298 | -function post_format_meta_box( $post, $box ) { |
|---|
| 299 | - if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) ) : |
|---|
| 300 | - $post_formats = get_theme_support( 'post-formats' ); |
|---|
| 301 | +function post_taxonomy_meta_box( $post, $box ) { |
|---|
| 302 | |
|---|
| 303 | - if ( is_array( $post_formats[0] ) ) : |
|---|
| 304 | - $post_format = get_post_format( $post->ID ); |
|---|
| 305 | - if ( !$post_format ) |
|---|
| 306 | - $post_format = '0'; |
|---|
| 307 | - // Add in the current one if it isn't there yet, in case the current theme doesn't support it |
|---|
| 308 | - if ( $post_format && !in_array( $post_format, $post_formats[0] ) ) |
|---|
| 309 | - $post_formats[0][] = $post_format; |
|---|
| 310 | - ?> |
|---|
| 311 | - <div id="post-formats-select"> |
|---|
| 312 | - <input type="radio" name="post_format" class="post-format" id="post-format-0" value="0" <?php checked( $post_format, '0' ); ?> /> <label for="post-format-0"><?php _e('Standard'); ?></label> |
|---|
| 313 | - <?php foreach ( $post_formats[0] as $format ) : ?> |
|---|
| 314 | - <br /><input type="radio" name="post_format" class="post-format" id="post-format-<?php echo esc_attr( $format ); ?>" value="<?php echo esc_attr( $format ); ?>" <?php checked( $post_format, $format ); ?> /> <label for="post-format-<?php echo esc_attr( $format ); ?>"><?php echo esc_html( get_post_format_string( $format ) ); ?></label> |
|---|
| 315 | - <?php endforeach; ?><br /> |
|---|
| 316 | - </div> |
|---|
| 317 | - <?php endif; endif; |
|---|
| 318 | + //default to tags if no taxonomy is passed |
|---|
| 319 | + if ( !is_array( $box['args'] ) || !isset( $box['args']['taxonomy'] ) ) |
|---|
| 320 | + $box['args']['taxonomy'] = 'post_tag'; |
|---|
| 321 | + |
|---|
| 322 | + $taxonomy = get_taxonomy( $box['args']['taxonomy'] ); |
|---|
| 323 | + |
|---|
| 324 | + if ( !$taxonomy ) |
|---|
| 325 | + return; |
|---|
| 326 | + |
|---|
| 327 | + //try to call a native function for built-in input types |
|---|
| 328 | + //otherwise, allow users to hook in and fire their own callback |
|---|
| 329 | + if ( function_exists( "_{$taxonomy->input}_taxonomy_meta_box" ) ) |
|---|
| 330 | + call_user_func( "_{$taxonomy->input}_taxonomy_meta_box", $post, $taxonomy ); |
|---|
| 331 | + else |
|---|
| 332 | + do_action( '{$taxonomy->input}_taxonomy_meta_box', $post, $taxonomy ); |
|---|
| 333 | + |
|---|
| 334 | } |
|---|
| 335 | |
|---|
| 336 | /** |
|---|
| 337 | - * Display post tags form fields. |
|---|
| 338 | - * |
|---|
| 339 | - * @since 2.6.0 |
|---|
| 340 | - * |
|---|
| 341 | - * @param object $post |
|---|
| 342 | + * Help function to render text (tag-like) input taxonomy metaboxes |
|---|
| 343 | + * @param object $post the post object |
|---|
| 344 | + * @param object $taxonomy the taxonomy object |
|---|
| 345 | + * @since 3.4 |
|---|
| 346 | */ |
|---|
| 347 | -function post_tags_meta_box($post, $box) { |
|---|
| 348 | - $defaults = array('taxonomy' => 'post_tag'); |
|---|
| 349 | - if ( !isset($box['args']) || !is_array($box['args']) ) |
|---|
| 350 | - $args = array(); |
|---|
| 351 | - else |
|---|
| 352 | - $args = $box['args']; |
|---|
| 353 | - extract( wp_parse_args($args, $defaults), EXTR_SKIP ); |
|---|
| 354 | - $tax_name = esc_attr($taxonomy); |
|---|
| 355 | - $taxonomy = get_taxonomy($taxonomy); |
|---|
| 356 | +function _text_taxonomy_meta_box( $post, $taxonomy ) { |
|---|
| 357 | + |
|---|
| 358 | + $tax_name = esc_attr( $taxonomy->name ); |
|---|
| 359 | $disabled = !current_user_can($taxonomy->cap->assign_terms) ? 'disabled="disabled"' : ''; |
|---|
| 360 | $comma = _x( ',', 'tag delimiter' ); |
|---|
| 361 | + |
|---|
| 362 | ?> |
|---|
| 363 | <div class="tagsdiv" id="<?php echo $tax_name; ?>"> |
|---|
| 364 | <div class="jaxtag"> |
|---|
| 365 | @@ -295,78 +288,248 @@ |
|---|
| 366 | </div> |
|---|
| 367 | <div class="tagchecklist"></div> |
|---|
| 368 | </div> |
|---|
| 369 | -<?php if ( current_user_can($taxonomy->cap->assign_terms) ) : ?> |
|---|
| 370 | +<?php if ( current_user_can( $taxonomy->cap->assign_terms ) ) : ?> |
|---|
| 371 | <p class="hide-if-no-js"><a href="#titlediv" class="tagcloud-link" id="link-<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->choose_from_most_used; ?></a></p> |
|---|
| 372 | -<?php endif; ?> |
|---|
| 373 | -<?php |
|---|
| 374 | +<?php endif; |
|---|
| 375 | } |
|---|
| 376 | |
|---|
| 377 | /** |
|---|
| 378 | - * Display post categories form fields. |
|---|
| 379 | - * |
|---|
| 380 | - * @since 2.6.0 |
|---|
| 381 | - * |
|---|
| 382 | - * @param object $post |
|---|
| 383 | + * Helper function to create checkbox (category) input metaboxes |
|---|
| 384 | + * @param object $post the post object |
|---|
| 385 | + * @param object $taxonomy the taxonomy object |
|---|
| 386 | + * @since 3.4 |
|---|
| 387 | */ |
|---|
| 388 | -function post_categories_meta_box( $post, $box ) { |
|---|
| 389 | - $defaults = array('taxonomy' => 'category'); |
|---|
| 390 | - if ( !isset($box['args']) || !is_array($box['args']) ) |
|---|
| 391 | - $args = array(); |
|---|
| 392 | - else |
|---|
| 393 | - $args = $box['args']; |
|---|
| 394 | - extract( wp_parse_args($args, $defaults), EXTR_SKIP ); |
|---|
| 395 | - $tax = get_taxonomy($taxonomy); |
|---|
| 396 | - |
|---|
| 397 | - ?> |
|---|
| 398 | - <div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv"> |
|---|
| 399 | - <ul id="<?php echo $taxonomy; ?>-tabs" class="category-tabs"> |
|---|
| 400 | - <li class="tabs"><a href="#<?php echo $taxonomy; ?>-all" tabindex="3"><?php echo $tax->labels->all_items; ?></a></li> |
|---|
| 401 | - <li class="hide-if-no-js"><a href="#<?php echo $taxonomy; ?>-pop" tabindex="3"><?php _e( 'Most Used' ); ?></a></li> |
|---|
| 402 | +function _checkbox_taxonomy_meta_box( $post, $taxonomy ) { |
|---|
| 403 | +?> |
|---|
| 404 | + <div id="taxonomy-<?php echo $taxonomy->name; ?>" class="categorydiv"> |
|---|
| 405 | + <ul id="<?php echo $taxonomy->name; ?>-tabs" class="category-tabs"> |
|---|
| 406 | + <li class="tabs"><a href="#<?php echo $taxonomy->name; ?>-all" tabindex="3"><?php echo $taxonomy->labels->all_items; ?></a></li> |
|---|
| 407 | + <li class="hide-if-no-js"><a href="#<?php echo $taxonomy->name; ?>-pop" tabindex="3"><?php _e( 'Most Used' ); ?></a></li> |
|---|
| 408 | </ul> |
|---|
| 409 | |
|---|
| 410 | - <div id="<?php echo $taxonomy; ?>-pop" class="tabs-panel" style="display: none;"> |
|---|
| 411 | - <ul id="<?php echo $taxonomy; ?>checklist-pop" class="categorychecklist form-no-clear" > |
|---|
| 412 | - <?php $popular_ids = wp_popular_terms_checklist($taxonomy); ?> |
|---|
| 413 | + <div id="<?php echo $taxonomy->name; ?>-pop" class="tabs-panel" style="display: none;"> |
|---|
| 414 | + <ul id="<?php echo $taxonomy->name; ?>checklist-pop" class="categorychecklist form-no-clear" > |
|---|
| 415 | + <?php $popular_ids = wp_popular_terms_checklist( $taxonomy->name ); ?> |
|---|
| 416 | </ul> |
|---|
| 417 | </div> |
|---|
| 418 | |
|---|
| 419 | - <div id="<?php echo $taxonomy; ?>-all" class="tabs-panel"> |
|---|
| 420 | - <?php |
|---|
| 421 | - $name = ( $taxonomy == 'category' ) ? 'post_category' : 'tax_input[' . $taxonomy . ']'; |
|---|
| 422 | + <div id="<?php echo $taxonomy->name; ?>-all" class="tabs-panel"> |
|---|
| 423 | +<?php |
|---|
| 424 | + $name = ( $taxonomy->name == 'category' ) ? 'post_category' : 'tax_input[' . $taxonomy->name . ']'; |
|---|
| 425 | echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. |
|---|
| 426 | ?> |
|---|
| 427 | - <ul id="<?php echo $taxonomy; ?>checklist" class="list:<?php echo $taxonomy?> categorychecklist form-no-clear"> |
|---|
| 428 | - <?php wp_terms_checklist($post->ID, array( 'taxonomy' => $taxonomy, 'popular_cats' => $popular_ids ) ) ?> |
|---|
| 429 | + <ul id="<?php echo $taxonomy->name; ?>checklist" class="list:<?php echo $taxonomy->name?> categorychecklist form-no-clear"> |
|---|
| 430 | + <?php wp_terms_checklist($post->ID, array( 'taxonomy' => $taxonomy->name, 'popular_cats' => $popular_ids ) ) ?> |
|---|
| 431 | </ul> |
|---|
| 432 | </div> |
|---|
| 433 | - <?php if ( current_user_can($tax->cap->edit_terms) ) : ?> |
|---|
| 434 | - <div id="<?php echo $taxonomy; ?>-adder" class="wp-hidden-children"> |
|---|
| 435 | +<?php if ( current_user_can($taxonomy->cap->edit_terms) ) : ?> |
|---|
| 436 | + <div id="<?php echo $taxonomy->name; ?>-adder" class="wp-hidden-children"> |
|---|
| 437 | <h4> |
|---|
| 438 | - <a id="<?php echo $taxonomy; ?>-add-toggle" href="#<?php echo $taxonomy; ?>-add" class="hide-if-no-js" tabindex="3"> |
|---|
| 439 | + <a id="<?php echo $taxonomy->name; ?>-add-toggle" href="#<?php echo $taxonomy->name; ?>-add" class="hide-if-no-js" tabindex="3"> |
|---|
| 440 | <?php |
|---|
| 441 | /* translators: %s: add new taxonomy label */ |
|---|
| 442 | - printf( __( '+ %s' ), $tax->labels->add_new_item ); |
|---|
| 443 | + printf( __( '+ %s' ), $taxonomy->labels->add_new_item ); |
|---|
| 444 | ?> |
|---|
| 445 | </a> |
|---|
| 446 | </h4> |
|---|
| 447 | - <p id="<?php echo $taxonomy; ?>-add" class="category-add wp-hidden-child"> |
|---|
| 448 | - <label class="screen-reader-text" for="new<?php echo $taxonomy; ?>"><?php echo $tax->labels->add_new_item; ?></label> |
|---|
| 449 | - <input type="text" name="new<?php echo $taxonomy; ?>" id="new<?php echo $taxonomy; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $tax->labels->new_item_name ); ?>" tabindex="3" aria-required="true"/> |
|---|
| 450 | - <label class="screen-reader-text" for="new<?php echo $taxonomy; ?>_parent"> |
|---|
| 451 | - <?php echo $tax->labels->parent_item_colon; ?> |
|---|
| 452 | + <p id="<?php echo $taxonomy->name; ?>-add" class="category-add wp-hidden-child"> |
|---|
| 453 | + <label class="screen-reader-text" for="new<?php echo $taxonomy->name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label> |
|---|
| 454 | + <input type="text" name="new<?php echo $taxonomy->name; ?>" id="new<?php echo $taxonomy->name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $taxonomy->labels->new_item_name ); ?>" tabindex="3" aria-required="true"/> |
|---|
| 455 | + <label class="screen-reader-text" for="new<?php echo $taxonomy->name; ?>_parent"> |
|---|
| 456 | + <?php echo $taxonomy->name->labels->parent_item_colon; ?> |
|---|
| 457 | </label> |
|---|
| 458 | - <?php wp_dropdown_categories( array( 'taxonomy' => $taxonomy, 'hide_empty' => 0, 'name' => 'new'.$taxonomy.'_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '— ' . $tax->labels->parent_item . ' —', 'tab_index' => 3 ) ); ?> |
|---|
| 459 | - <input type="button" id="<?php echo $taxonomy; ?>-add-submit" class="add:<?php echo $taxonomy ?>checklist:<?php echo $taxonomy ?>-add button category-add-sumbit" value="<?php echo esc_attr( $tax->labels->add_new_item ); ?>" tabindex="3" /> |
|---|
| 460 | - <?php wp_nonce_field( 'add-'.$taxonomy, '_ajax_nonce-add-'.$taxonomy, false ); ?> |
|---|
| 461 | - <span id="<?php echo $taxonomy; ?>-ajax-response"></span> |
|---|
| 462 | + <?php wp_dropdown_categories( array( 'taxonomy' => $taxonomy->name, 'hide_empty' => 0, 'name' => 'new'.$taxonomy->name.'_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '— ' . $taxonomy->labels->parent_item . ' —', 'tab_index' => 3 ) ); ?> |
|---|
| 463 | + <input type="button" id="<?php echo $taxonomy->name; ?>-add-submit" class="add:<?php echo $taxonomy->name ?>checklist:<?php echo $taxonomy->name ?>-add button category-add-sumbit" value="<?php echo esc_attr( $taxonomy->labels->add_new_item ); ?>" tabindex="3" /> |
|---|
| 464 | + <?php wp_nonce_field( 'add-'.$taxonomy->name, '_ajax_nonce-add-'.$taxonomy->name, false ); ?> |
|---|
| 465 | + <span id="<?php echo $taxonomy->name; ?>-ajax-response"></span> |
|---|
| 466 | </p> |
|---|
| 467 | </div> |
|---|
| 468 | <?php endif; ?> |
|---|
| 469 | </div> |
|---|
| 470 | - <?php |
|---|
| 471 | +<?php |
|---|
| 472 | } |
|---|
| 473 | |
|---|
| 474 | /** |
|---|
| 475 | + * Helper function to create radio (exclusive) input taxonomy metaboxes |
|---|
| 476 | + * @param object $post the post object |
|---|
| 477 | + * @param object $taxonomy the taxonomy object |
|---|
| 478 | + * @since 3.4 |
|---|
| 479 | + */ |
|---|
| 480 | +function _radio_taxonomy_meta_box( $post, $taxonomy ) { |
|---|
| 481 | + |
|---|
| 482 | + $selected = wp_get_post_terms( $post->ID, $taxonomy->name ); |
|---|
| 483 | + if ( $selected ) |
|---|
| 484 | + $selected = array( $selected[0]->ID ); |
|---|
| 485 | + |
|---|
| 486 | +?> |
|---|
| 487 | + <div id="taxonomy-<?php echo $taxonomy->name; ?>" class="categorydiv"> |
|---|
| 488 | + <ul id="<?php echo $taxonomy->name; ?>checklist" class="list:<?php echo $taxonomy->name?> categorychecklist form-no-clear"> |
|---|
| 489 | + <li id='<?php echo $taxonomy->name; ?>-none'><label class="selectit"><input value="" type="radio" name="tax_input[radio]" id="in-radio-none" <?php checked( !$selected ); ?> /> <?php _e( 'None' ); ?></label></li> |
|---|
| 490 | +<?php |
|---|
| 491 | + |
|---|
| 492 | + wp_terms_checklist( $post->ID, array( |
|---|
| 493 | + 'taxonomy' => $taxonomy->name, |
|---|
| 494 | + 'popular_cats' => $selected, |
|---|
| 495 | + ) ); |
|---|
| 496 | + |
|---|
| 497 | + ?> |
|---|
| 498 | + </ul> |
|---|
| 499 | +<?php if ( current_user_can($taxonomy->cap->edit_terms) ) : ?> |
|---|
| 500 | + <div id="<?php echo $taxonomy->name; ?>-adder" class="wp-hidden-children"> |
|---|
| 501 | + <h4> |
|---|
| 502 | + <a id="<?php echo $taxonomy->name; ?>-add-toggle" href="#<?php echo $taxonomy->name; ?>-add" class="hide-if-no-js" tabindex="3"> |
|---|
| 503 | + <?php |
|---|
| 504 | + /* translators: %s: add new taxonomy label */ |
|---|
| 505 | + printf( __( '+ %s' ), $taxonomy->labels->add_new_item ); |
|---|
| 506 | + ?> |
|---|
| 507 | + </a> |
|---|
| 508 | + </h4> |
|---|
| 509 | + <p id="<?php echo $taxonomy->name; ?>-add" class="category-add wp-hidden-child"> |
|---|
| 510 | + <label class="screen-reader-text" for="new<?php echo $taxonomy->name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label> |
|---|
| 511 | + <input type="text" name="new<?php echo $taxonomy->name; ?>" id="new<?php echo $taxonomy->name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $taxonomy->labels->new_item_name ); ?>" tabindex="3" aria-required="true"/> |
|---|
| 512 | + <label class="screen-reader-text" for="new<?php echo $taxonomy->name; ?>_parent"> |
|---|
| 513 | + <?php echo $taxonomy->name->labels->parent_item_colon; ?> |
|---|
| 514 | + </label> |
|---|
| 515 | + <?php wp_dropdown_categories( array( 'taxonomy' => $taxonomy->name, 'hide_empty' => 0, 'name' => 'new'.$taxonomy->name.'_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '— ' . $taxonomy->labels->parent_item . ' —', 'tab_index' => 3 ) ); ?> |
|---|
| 516 | + <input type="button" id="<?php echo $taxonomy->name; ?>-add-submit" class="add:<?php echo $taxonomy->name ?>checklist:<?php echo $taxonomy->name ?>-add button category-add-sumbit" value="<?php echo esc_attr( $taxonomy->labels->add_new_item ); ?>" tabindex="3" /> |
|---|
| 517 | + <?php wp_nonce_field( 'add-'.$taxonomy->name, '_ajax_nonce-add-'.$taxonomy->name, false ); ?> |
|---|
| 518 | + <span id="<?php echo $taxonomy->name; ?>-ajax-response"></span> |
|---|
| 519 | + </p> |
|---|
| 520 | + </div> |
|---|
| 521 | + <?php endif; ?> |
|---|
| 522 | + </div> |
|---|
| 523 | +<?php |
|---|
| 524 | + |
|---|
| 525 | +} |
|---|
| 526 | + |
|---|
| 527 | +/** |
|---|
| 528 | + * Helper function to create dropdown (exclusive) input taxonomy metaboxes |
|---|
| 529 | + * @param object $post the post object |
|---|
| 530 | + * @param object $taxonomy the taxonomy object |
|---|
| 531 | + * @since 3.4 |
|---|
| 532 | + */ |
|---|
| 533 | +function _dropdown_taxonomy_meta_box( $post, $taxonomy ) { |
|---|
| 534 | +?> |
|---|
| 535 | + <div id="taxonomy-<?php echo $taxonomy->name; ?>" class="categorydiv"> |
|---|
| 536 | +<?php |
|---|
| 537 | + |
|---|
| 538 | + $selected = wp_get_post_terms( $post->ID, $taxonomy->name ); |
|---|
| 539 | + if ( $selected ) |
|---|
| 540 | + $selected = $selected[0]->term_id; |
|---|
| 541 | + |
|---|
| 542 | + wp_dropdown_categories( array( |
|---|
| 543 | + 'taxonomy' => $taxonomy->name, |
|---|
| 544 | + 'show_option_none' => ' ', |
|---|
| 545 | + 'orderby' => 'slug', |
|---|
| 546 | + 'selected' => $selected, |
|---|
| 547 | + 'hierarchical' => $taxonomy->hierarchical, |
|---|
| 548 | + 'hide_empty' => false, |
|---|
| 549 | + 'name' => "tax_input[{$taxonomy->name}]", |
|---|
| 550 | + ) ); |
|---|
| 551 | + |
|---|
| 552 | + if ( current_user_can($taxonomy->cap->edit_terms) ) : |
|---|
| 553 | + ?> |
|---|
| 554 | + <div id="<?php echo $taxonomy->name; ?>-adder" class="wp-hidden-children"> |
|---|
| 555 | + <h4> |
|---|
| 556 | + <a id="<?php echo $taxonomy->name; ?>-add-toggle" href="#<?php echo $taxonomy->name; ?>-add" class="hide-if-no-js" tabindex="3"> |
|---|
| 557 | + <?php |
|---|
| 558 | + /* translators: %s: add new taxonomy label */ |
|---|
| 559 | + printf( __( '+ %s' ), $taxonomy->labels->add_new_item ); |
|---|
| 560 | + ?> |
|---|
| 561 | + </a> |
|---|
| 562 | + </h4> |
|---|
| 563 | + <p id="<?php echo $taxonomy->name; ?>-add" class="category-add wp-hidden-child"> |
|---|
| 564 | + <label class="screen-reader-text" for="new<?php echo $taxonomy->name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label> |
|---|
| 565 | + <input type="text" name="new<?php echo $taxonomy->name; ?>" id="new<?php echo $taxonomy->name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $taxonomy->labels->new_item_name ); ?>" tabindex="3" aria-required="true"/> |
|---|
| 566 | + <label class="screen-reader-text" for="new<?php echo $taxonomy->name; ?>_parent"> |
|---|
| 567 | + <?php echo $taxonomy->name->labels->parent_item_colon; ?> |
|---|
| 568 | + </label> |
|---|
| 569 | + <?php wp_dropdown_categories( array( 'taxonomy' => $taxonomy->name, 'hide_empty' => 0, 'name' => 'new'.$taxonomy->name.'_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '— ' . $taxonomy->labels->parent_item . ' —', 'tab_index' => 3 ) ); ?> |
|---|
| 570 | + <input type="button" id="<?php echo $taxonomy->name; ?>-add-submit" class="add:<?php echo $taxonomy->name ?>checklist:<?php echo $taxonomy->name ?>-add button category-add-sumbit" value="<?php echo esc_attr( $taxonomy->labels->add_new_item ); ?>" tabindex="3" /> |
|---|
| 571 | + <?php wp_nonce_field( 'add-'.$taxonomy->name, '_ajax_nonce-add-'.$taxonomy->name, false ); ?> |
|---|
| 572 | + <span id="<?php echo $taxonomy->name; ?>-ajax-response"></span> |
|---|
| 573 | + </p> |
|---|
| 574 | + </div> |
|---|
| 575 | + <?php endif; ?> |
|---|
| 576 | + </div> |
|---|
| 577 | +<?php |
|---|
| 578 | +} |
|---|
| 579 | + |
|---|
| 580 | +/** |
|---|
| 581 | + * Display post format form elements. |
|---|
| 582 | + * |
|---|
| 583 | + * @since 3.1.0 |
|---|
| 584 | + * |
|---|
| 585 | + * @param object $post |
|---|
| 586 | + */ |
|---|
| 587 | +function post_format_meta_box( $post, $box ) { |
|---|
| 588 | + |
|---|
| 589 | + if ( !current_theme_supports( 'post-formats' ) || !post_type_supports( $post->post_type, 'post-formats' ) ) |
|---|
| 590 | + return; |
|---|
| 591 | + |
|---|
| 592 | + $post_formats = get_theme_support( 'post-formats' ); |
|---|
| 593 | + |
|---|
| 594 | + if ( !is_array( $post_formats[0] ) ) |
|---|
| 595 | + return; |
|---|
| 596 | + |
|---|
| 597 | + $post_format = get_post_format( $post->ID ); |
|---|
| 598 | + |
|---|
| 599 | + if ( !$post_format ) |
|---|
| 600 | + $post_format = '0'; |
|---|
| 601 | + // Add in the current one if it isn't there yet, in case the current theme doesn't support it |
|---|
| 602 | + if ( $post_format && !in_array( $post_format, $post_formats[0] ) ) |
|---|
| 603 | + $post_formats[0][] = $post_format; |
|---|
| 604 | + |
|---|
| 605 | + ?> |
|---|
| 606 | + <div id="post-formats-select"> |
|---|
| 607 | + <input type="radio" name="post_format" class="post-format" id="post-format-0" value="0" <?php checked( $post_format, '0' ); ?> /> <label for="post-format-0"><?php _e('Standard'); ?></label> |
|---|
| 608 | + <?php foreach ( $post_formats[0] as $format ) : ?> |
|---|
| 609 | + <br /><input type="radio" name="post_format" class="post-format" id="post-format-<?php echo esc_attr( $format ); ?>" value="<?php echo esc_attr( $format ); ?>" <?php checked( $post_format, $format ); ?> /> <label for="post-format-<?php echo esc_attr( $format ); ?>"><?php echo esc_html( get_post_format_string( $format ) ); ?></label> |
|---|
| 610 | + <?php endforeach; ?><br /> |
|---|
| 611 | + </div> |
|---|
| 612 | +<?php |
|---|
| 613 | +} |
|---|
| 614 | + |
|---|
| 615 | +/** |
|---|
| 616 | + * Display post tags form fields. |
|---|
| 617 | + * |
|---|
| 618 | + * @since 2.6.0 |
|---|
| 619 | + * |
|---|
| 620 | + * @param object $post |
|---|
| 621 | + * |
|---|
| 622 | + */ |
|---|
| 623 | +function post_tags_meta_box($post, $box) { |
|---|
| 624 | + |
|---|
| 625 | + if ( !isset( $box['args'] ) || !is_array( $box['args'] ) ) |
|---|
| 626 | + $box['args'] = array(); |
|---|
| 627 | + |
|---|
| 628 | + $box['args']['taxonomy'] = 'post_tag'; |
|---|
| 629 | + |
|---|
| 630 | + _deprecated_function( 'post_tags_meta_box', '3.4', 'post_taxonomy_meta_box' ); |
|---|
| 631 | + post_taxonomy_meta_box( $post, $box ); |
|---|
| 632 | + |
|---|
| 633 | +} |
|---|
| 634 | + |
|---|
| 635 | +/** |
|---|
| 636 | + * Display post categories form fields. |
|---|
| 637 | + * |
|---|
| 638 | + * @since 2.6.0 |
|---|
| 639 | + * |
|---|
| 640 | + * @param object $post |
|---|
| 641 | + */ |
|---|
| 642 | +function post_categories_meta_box( $post, $box ) { |
|---|
| 643 | + |
|---|
| 644 | + if ( !isset( $box['args'] ) || !is_array( $box['args'] ) ) |
|---|
| 645 | + $box['args'] = array(); |
|---|
| 646 | + |
|---|
| 647 | + $box['args']['taxonomy'] = 'category'; |
|---|
| 648 | + |
|---|
| 649 | + _deprecated_function( 'post_categories_meta_box', '3.4', 'post_taxonomy_meta_box' ); |
|---|
| 650 | + post_taxonomy_meta_box( $post, $box ); |
|---|
| 651 | + |
|---|
| 652 | +} |
|---|
| 653 | + |
|---|
| 654 | +/** |
|---|
| 655 | * Display post excerpt form fields. |
|---|
| 656 | * |
|---|
| 657 | * @since 2.6.0 |
|---|
| 658 | Index: wp-admin/edit-form-advanced.php |
|---|
| 659 | =================================================================== |
|---|
| 660 | --- wp-admin/edit-form-advanced.php (revision 20037) |
|---|
| 661 | +++ wp-admin/edit-form-advanced.php (working copy) |
|---|
| 662 | @@ -109,13 +109,9 @@ |
|---|
| 663 | $taxonomy = get_taxonomy($tax_name); |
|---|
| 664 | if ( ! $taxonomy->show_ui ) |
|---|
| 665 | continue; |
|---|
| 666 | - |
|---|
| 667 | - $label = $taxonomy->labels->name; |
|---|
| 668 | - |
|---|
| 669 | - if ( !is_taxonomy_hierarchical($tax_name) ) |
|---|
| 670 | - add_meta_box('tagsdiv-' . $tax_name, $label, 'post_tags_meta_box', null, 'side', 'core', array( 'taxonomy' => $tax_name )); |
|---|
| 671 | - else |
|---|
| 672 | - add_meta_box($tax_name . 'div', $label, 'post_categories_meta_box', null, 'side', 'core', array( 'taxonomy' => $tax_name )); |
|---|
| 673 | + |
|---|
| 674 | + add_meta_box( $tax_name . 'div', $taxonomy->labels->name, 'post_taxonomy_meta_box', null, 'side', 'core', array( 'taxonomy' => $tax_name )); |
|---|
| 675 | + |
|---|
| 676 | } |
|---|
| 677 | |
|---|
| 678 | if ( post_type_supports($post_type, 'page-attributes') ) |
|---|