Ticket #9674: inline-edit-custom-taxonomies.diff
File inline-edit-custom-taxonomies.diff, 9.6 KB (added by , 15 years ago) |
---|
-
wp-admin/includes/post.php
254 254 255 255 $post_IDs = array_map( 'intval', (array) $post_data['post'] ); 256 256 257 $reset = array( 'post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'ta gs_input', 'post_category', 'sticky' );257 $reset = array( 'post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tax_input', 'post_category', 'sticky' ); 258 258 foreach ( $reset as $field ) { 259 259 if ( isset($post_data[$field]) && ( '' == $post_data[$field] || -1 == $post_data[$field] ) ) 260 260 unset($post_data[$field]); … … 266 266 else 267 267 unset($post_data['post_category']); 268 268 } 269 270 if ( isset($post_data['tags_input']) ) { 271 $new_tags = preg_replace( '/\s*,\s*/', ',', rtrim( trim($post_data['tags_input']), ' ,' ) ); 272 $new_tags = explode(',', $new_tags); 269 270 $tax_input = array(); 271 if ( isset($post_data['tax_input'])) { 272 foreach ( $post_data['tax_input'] as $tax_name => $terms ) { 273 if ( empty($terms) ) 274 continue; 275 $taxonomy = get_taxonomy( $tax_name ); 276 if ( $taxonomy->hierarchical ) 277 $tax_input[$tax_name] = array_map( 'absint', $terms ); 278 else { 279 $tax_input[$tax_name] = preg_replace( '/\s*,\s*/', ',', rtrim( trim($terms), ' ,' ) ); 280 $tax_input[$tax_name] = explode(',', $tax_input[$tax_name]); 281 } 282 } 273 283 } 274 284 275 285 if ( isset($post_data['post_parent']) && ($parent = (int) $post_data['post_parent']) ) { … … 300 310 $locked[] = $post_ID; 301 311 continue; 302 312 } 303 304 if ( isset($new_cats) ) { 313 314 $tax_names = get_object_taxonomies( get_post($post_ID) ); 315 316 if ( isset($new_cats) && in_array( 'category', $tax_names ) ) { 305 317 $cats = (array) wp_get_post_categories($post_ID); 306 318 $post_data['post_category'] = array_unique( array_merge($cats, $new_cats) ); 307 319 } 308 309 if ( isset($new_tags) ) { 310 $tags = wp_get_post_tags($post_ID, array('fields' => 'names')); 311 $post_data['tags_input'] = array_unique( array_merge($tags, $new_tags) ); 320 321 foreach ( $tax_names as $tax_name ) { 322 if( isset( $tax_input[$tax_name]) ) { 323 $taxonomy = get_taxonomy( $tax_name ); 324 if( $taxonomy->hierarchical ) 325 $terms = (array) wp_get_object_terms( $post_ID, $tax_name, array('fields' => 'ids') ); 326 else 327 $terms = (array) wp_get_object_terms( $post_ID, $tax_name, array('fields' => 'names') ); 328 $post_data['tax_input'][$tax_name] = array_merge( $terms, $tax_input[$tax_name] ); 329 } 312 330 } 313 331 314 332 $post_data['ID'] = $post_ID; -
wp-admin/includes/template.php
907 907 $post = get_default_post_to_edit( $screen->post_type ); 908 908 $post_type_object = get_post_type_object( $screen->post_type ); 909 909 910 $taxonomy_names = get_object_taxonomies( $screen->post_type ); 911 $hierarchical_taxonomies = array(); 912 $flat_taxonomies = array(); 913 foreach ( $taxonomy_names as $taxonomy_name ) { 914 $taxonomy = get_taxonomy( $taxonomy_name); 915 916 if( !$taxonomy->show_ui ) continue; 917 918 if( $taxonomy->hierarchical ) 919 $hierarchical_taxonomies[] = $taxonomy; 920 else 921 $flat_taxonomies[] = $taxonomy; 922 } 923 910 924 $columns = wp_manage_posts_columns($screen); 911 925 $hidden = array_intersect( array_keys( $columns ), array_filter( get_hidden_columns($screen) ) ); 912 926 $col_count = count($columns) - count($hidden); … … 998 1012 999 1013 </div></fieldset> 1000 1014 1001 <?php if ( is_object_in_taxonomy($screen->post_type, 'category') && !$bulk ) : ?>1015 <?php if ( count($hierarchical_taxonomies) && !$bulk ) : ?> 1002 1016 1003 1017 <fieldset class="inline-edit-col-center inline-edit-categories"><div class="inline-edit-col"> 1004 <span class="title inline-edit-categories-label"><?php _e( 'Categories' ); ?> 1018 1019 <?php foreach ( $hierarchical_taxonomies as $taxonomy ) : ?> 1020 1021 <span class="title inline-edit-categories-label"><?php echo esc_html($taxonomy->label) ?> 1005 1022 <span class="catshow"><?php _e('[more]'); ?></span> 1006 1023 <span class="cathide" style="display:none;"><?php _e('[less]'); ?></span> 1007 1024 </span> 1008 <ul class="cat-checklist ">1009 <?php wp_ category_checklist();?>1025 <ul class="cat-checklist <?php echo esc_attr($taxonomy->name)?>-checklist"> 1026 <?php wp_terms_checklist(null, array('taxonomy' => $taxonomy->name)) ?> 1010 1027 </ul> 1028 1029 <?php endforeach; //$hierarchical_taxonomies as $taxonomy ?> 1030 1011 1031 </div></fieldset> 1012 1032 1013 <?php endif; // is_object_in_taxonomy($screen->post_type, 'category') && !$bulk ?>1033 <?php endif; // count($hierarchical_taxonomies) && !$bulk ?> 1014 1034 1015 1035 <fieldset class="inline-edit-col-right"><div class="inline-edit-col"> 1016 1036 … … 1054 1074 1055 1075 <?php endif; // $post_type_object->hierarchical ?> 1056 1076 1057 <?php if ( is_object_in_taxonomy($screen->post_type, 'post_tag') && !$bulk ) : ?>1077 <?php if ( count($flat_taxonomies) && !$bulk ) : ?> 1058 1078 1079 <?php foreach ( $flat_taxonomies as $taxonomy ) : ?> 1080 1059 1081 <label class="inline-edit-tags"> 1060 <span class="title"><?php _e( 'Tags' );?></span>1061 <textarea cols="22" rows="1" name="ta gs_input" class="tags_input"></textarea>1082 <span class="title"><?php echo esc_html($taxonomy->label) ?></span> 1083 <textarea cols="22" rows="1" name="tax_input[<?php echo esc_attr($taxonomy->name)?>]" class="tax_input_<?php echo esc_attr($taxonomy->name)?>"></textarea> 1062 1084 </label> 1063 1085 1064 <?php end if; // is_object_in_taxonomy($screen->post_type, 'post_tag') && !$bulk?>1086 <?php endforeach; //$flat_taxonomies as $taxonomy ?> 1065 1087 1088 <?php endif; // count($flat_taxonomies) && !$bulk ?> 1089 1066 1090 <?php if ( $bulk ) : ?> 1067 1091 1068 1092 <div class="inline-edit-group"> … … 1221 1245 if ( $post_type_object->hierarchical ) 1222 1246 echo '<div class="menu_order">' . $post->menu_order . '</div>'; 1223 1247 1224 if ( is_object_in_taxonomy($post->post_type, 'post_tag') ) 1225 echo '<div class="tags_input">' . esc_html( str_replace( ',', ', ', get_tags_to_edit($post->ID) ) ) . '</div>'; 1248 $taxonomy_names = get_object_taxonomies( $post->post_type ); 1249 foreach ( $taxonomy_names as $taxonomy_name) { 1250 $taxonomy = get_taxonomy( $taxonomy_name ); 1226 1251 1227 if ( is_object_in_taxonomy($post->post_type, 'post_tag') ) 1228 echo '<div class="post_category">' . implode( ',', wp_get_post_categories( $post->ID ) ) . '</div>'; 1252 if ( $taxonomy->hierarchical && $taxonomy->show_ui ) 1253 echo '<div class="post_category" id="'.$taxonomy_name.'_'.$post->ID.'">' . implode( ',', wp_get_object_terms( $post->ID, $taxonomy_name, array('fields'=>'ids')) ) . '</div>'; 1254 elseif ( $taxonomy->show_ui ) 1255 echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">' . esc_html( str_replace( ',', ', ', get_terms_to_edit($post->ID, $taxonomy_name) ) ) . '</div>'; 1256 } 1229 1257 1230 if ( $post->post_type == 'post')1258 if ( !$post_type_object->hierarchical ) 1231 1259 echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>'; 1232 1260 1233 1261 echo '</div>'; -
wp-admin/js/inline-edit-post.dev.js
36 36 $('#inline-edit label.inline-edit-tags').clone() 37 37 ); 38 38 39 // categories expandable?39 // hiearchical taxonomies expandable? 40 40 $('span.catshow').click(function() { 41 $('.inline-editor ul.cat-checklist').addClass("cat-hover"); 42 $('.inline-editor span.cathide').show(); 43 $(this).hide(); 41 $(this).hide().next().show().parent().next().addClass("cat-hover"); 44 42 }); 45 43 46 44 $('span.cathide').click(function() { 47 $('.inline-editor ul.cat-checklist').removeClass("cat-hover"); 48 $('.inline-editor span.catshow').show(); 49 $(this).hide(); 45 $(this).hide().prev().show().parent().next().removeClass("cat-hover"); 50 46 }); 51 47 52 48 $('select[name="_status"] option[value="future"]', bulkRow).remove(); … … 118 114 119 115 fields = ['post_title', 'post_name', 'post_author', '_status', 'jj', 'mm', 'aa', 'hh', 'mn', 'ss', 'post_password']; 120 116 if ( t.type == 'page' ) fields.push('post_parent', 'menu_order', 'page_template'); 121 if ( t.type == 'post' ) fields.push('tags_input');122 117 123 118 // add the new blank row 124 119 editRow = $('#inline-edit').clone(true); … … 146 141 if ( $('.sticky', rowData).text() == 'sticky' ) 147 142 $('input[name="sticky"]', editRow).attr("checked", "checked"); 148 143 149 // categories 150 if ( cats = $('.post_category', rowData).text() ) 151 $('ul.cat-checklist :checkbox', editRow).val(cats.split(',')); 144 // hierarchical taxonomies 145 $('.post_category', rowData).each(function(){ 146 if( term_ids = $(this).text() ) 147 { 148 taxname = $(this).attr('id').replace('_'+id, ''); 149 $('ul.'+taxname+'-checklist :checkbox', editRow).val(term_ids.split(',')); 150 } 151 }); 152 //flat taxonomies 153 $('.tags_input', rowData).each(function(){ 154 if( terms = $(this).text() ) 155 { 156 taxname = $(this).attr('id').replace('_'+id, ''); 157 $('textarea.tax_input_'+taxname, editRow).val(terms); 158 $('textarea.tax_input_'+taxname, editRow).suggest( 'admin-ajax.php?action=ajax-tag-search&tax='+taxname, { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } ); 159 } 160 }); 161 152 162 153 163 // handle the post status 154 164 status = $('._status', rowData).text(); … … 180 190 $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show(); 181 191 $('.ptitle', editRow).focus(); 182 192 183 // enable autocomplete for tags184 if ( t.type == 'post' ) {185 tax = 'post_tag';186 $('tr.inline-editor textarea[name="tags_input"]').suggest( 'admin-ajax.php?action=ajax-tag-search&tax='+tax, { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );187 }188 189 193 return false; 190 194 }, 191 195