Make WordPress Core

Ticket #10122: hierarchical_metaboxes-2.patch

File hierarchical_metaboxes-2.patch, 12.3 KB (added by prettyboymp, 15 years ago)
  • wp-includes/taxonomy.php

     
    192192        $args['name'] = $taxonomy;
    193193        $args['object_type'] = $object_type;
    194194        $wp_taxonomies[$taxonomy] = (object) $args;
     195
     196        //register meta_box
     197        add_filter('wp_ajax_add-'.$taxonomy, '_wp_ajax_add_hierarchical_term');
    195198}
    196199
    197200//
     
    15301533 * slug has to be globally unique for every taxonomy.
    15311534 *
    15321535 * The way this works is that if the taxonomy that the term belongs to is
    1533  * heirarchical and has a parent, it will append that parent to the $slug.
     1536 * hierarchical and has a parent, it will append that parent to the $slug.
    15341537 *
    15351538 * If that still doesn't return an unique slug, then it try to append a number
    15361539 * until it finds a number that is truely unique.
  • wp-includes/post.php

     
    20622062                $tags = array();
    20632063
    20642064        $tags = is_array($tags) ? $tags : explode( ',', trim($tags, " \n\t\r\0\x0B,") );
     2065
     2066        $taxonomy_obj = get_taxonomy($taxonomy);
     2067        if($taxonomy_obj->hierarchical)
     2068        {
     2069                $tags = array_map('intval', $tags);
     2070                $tags = array_unique($tags);
     2071        }
     2072
    20652073        wp_set_object_terms($post_id, $tags, $taxonomy, $append);
    20662074}
    20672075
  • wp-includes/category-template.php

     
    331331 */
    332332function wp_dropdown_categories( $args = '' ) {
    333333        $defaults = array(
     334                'taxonomy' => 'category',
    334335                'show_option_all' => '', 'show_option_none' => '',
    335336                'orderby' => 'id', 'order' => 'ASC',
    336337                'show_last_update' => 0, 'show_count' => 0,
     
    356357        if ( (int) $tab_index > 0 )
    357358                $tab_index_attribute = " tabindex=\"$tab_index\"";
    358359
    359         $categories = get_categories( $r );
     360        $categories = get_terms( $taxonomy, $r );
    360361        $name = esc_attr($name);
    361362        $class = esc_attr($class);
    362363
  • wp-admin/admin-ajax.php

     
    197197        $x->send();
    198198}
    199199
     200/**
     201 * Handles hierarchical taxonomy meta_box add functions.  Called via admin_ajax
     202 * posts with action: add-{taxonomy name}
     203 *
     204 * @since 2.9
     205 *
     206 */
     207function _wp_ajax_add_hierarchical_term()
     208{
     209        $action = $_POST['action'];
     210        $taxonomy = get_taxonomy(substr($action, 4));
     211        if(!$taxonomy)
     212                die('-1');
     213        check_ajax_referer( $action );
     214        if ( !current_user_can( 'manage_categories' ) )
     215                die('-1');
     216        $names = explode(',', $_POST['new'.$taxonomy->name]);
     217        if ( 0 > $parent = (int) $_POST['new'.$taxonomy->name.'_parent'] )
     218                $parent = 0;
     219        $post_category = isset($_POST['post_category'])? (array) $_POST['post_category'] : array();
     220        $checked_categories = array_map( 'absint', (array) $post_category );
     221        $popular_ids = isset( $_POST['popular_ids'] ) ?
     222                        array_map( 'absint', explode( ',', $_POST['popular_ids'] ) ) :
     223                        false;
     224
     225        $x = new WP_Ajax_Response();
     226        foreach ( $names as $cat_name ) {
     227                $cat_name = trim($cat_name);
     228                $category_nicename = sanitize_title($cat_name);
     229                if ( '' === $category_nicename )
     230                        continue;
     231
     232                if(!($cat_id = is_term($cat_name, $taxonomy->name, $parent))) {
     233                        $cat_id = wp_insert_term($cat_name, $taxonomy->name, array('parent'=>$parent));
     234                }
     235                if ( is_array($cat_id) )
     236                                $cat_id = $cat_id['term_id'];
     237                $checked_categories[] = $cat_id;
     238                if ( $parent ) // Do these all at once in a second
     239                        continue;
     240                $category = get_term( $cat_id, $taxonomy->name);
     241                ob_start();
     242                        wp_terms_checklist( 0, array('taxonomy'=>$taxonomy->name, 'descendants_and_self'=>$cat_id, 'selected_cats'=>$checked_categories, 'popular_cats'=>$popular_ids));
     243                $data = ob_get_contents();
     244                ob_end_clean();
     245                $x->add( array(
     246                        'what' =>       $taxonomy->name,
     247                        'id' => $cat_id,
     248                        'data' => $data,
     249                        'position' => -1
     250                ) );
     251        }
     252        if ( $parent ) { // Foncy - replace the parent and all its children
     253                $parent = get_term($parent, $taxonomy->name);
     254                ob_start();
     255                        global $post_ID;
     256                        wp_terms_checklist($post_ID, array('taxonomy' => $taxonomy->name));
     257                $data = ob_get_contents();
     258                ob_end_clean();
     259                $x->add( array(
     260                        'what' => $taxonomy->name,
     261                        'id' => $parent->term_id,
     262                        'old_id' => $parent->term_id,
     263                        'data' => $data,
     264                        'position' => -1
     265                ) );
     266
     267        }
     268        $x->send();
     269        die();
     270}
     271
    200272$id = isset($_POST['id'])? (int) $_POST['id'] : 0;
    201273switch ( $action = $_POST['action'] ) :
    202274case 'delete-comment' : // On success, die with time() instead of 1
  • wp-admin/includes/template.php

     
    467467
    468468        function start_el(&$output, $category, $depth, $args) {
    469469                extract($args);
     470                if(empty($taxonomy))
     471                        $taxonomy = 'category';
    470472
     473                if($taxonomy == 'category')
     474                        $name = 'post_category';
     475                else
     476                        $name = 'tax_input['.$taxonomy.']';
    471477                $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : '';
    472                 $output .= "\n<li id='category-$category->term_id'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="post_category[]" id="in-category-' . $category->term_id . '"' . (in_array( $category->term_id, $selected_cats ) ? ' checked="checked"' : "" ) . '/> ' . esc_html( apply_filters('the_category', $category->name )) . '</label>';
     478                $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 . '"' . (in_array( $category->term_id, $selected_cats ) ? ' checked="checked"' : "" ) . '/> ' . esc_html( apply_filters('the_category', $category->name )) . '</label>';
    473479        }
    474480
    475481        function end_el(&$output, $category, $depth, $args) {
  • wp-admin/wp-admin.dev.css

     
    19251925
    19261926/* Categories */
    19271927
    1928 #category-adder {
     1928.category-adder {
    19291929        margin-left: 120px;
    19301930        padding: 4px 0;
    19311931}
    19321932
    1933 #category-adder h4 {
     1933.category-adder h4 {
    19341934        margin: 0 0 8px;
    19351935}
    19361936
    1937 #side-sortables #category-adder {
     1937#side-sortables .category-adder {
    19381938        margin: 0;
    19391939}
    19401940
    1941 #post-body #category-add input, #category-add select {
     1941#post-body .category-add input, .category-add select {
    19421942        width: 30%;
    19431943}
    19441944
    1945 #side-sortables #category-add input {
     1945#side-sortables .category-add input {
    19461946        width: 94%;
    19471947}
    19481948
    1949 #side-sortables #category-add select {
     1949#side-sortables .category-add select {
    19501950        width: 100%;
    19511951}
    19521952
    1953 #category-add input#category-add-sumbit {
     1953#side-sortables .category-add input.category-add-sumbit, #post-body .category-add input.category-add-sumbit {
    19541954        width: auto;
    19551955}
    19561956
    1957 #post-body ul#category-tabs {
     1957#post-body ul.category-tabs {
    19581958        float: left;
    19591959        width: 120px;
    19601960        text-align: right;
     
    19631963        padding: 0;
    19641964}
    19651965
    1966 #post-body ul#category-tabs li {
     1966#post-body ul.category-tabs li {
    19671967        padding: 8px;
    19681968}
    19691969
    1970 #post-body ul#category-tabs li.tabs {
     1970#post-body ul.category-tabs li.tabs {
    19711971        -moz-border-radius: 3px 0 0 3px;
    19721972        -webkit-border-top-left-radius: 3px;
    19731973        -webkit-border-bottom-left-radius: 3px;
     
    19771977        border-bottom-left-radius: 3px;
    19781978}
    19791979
    1980 #post-body ul#category-tabs li.tabs a {
     1980#post-body ul.category-tabs li.tabs a {
    19811981        font-weight: bold;
    19821982        text-decoration: none;
    19831983}
    19841984
    1985 #categorydiv div.tabs-panel,
     1985.categorydiv div.tabs-panel,
    19861986#linkcategorydiv div.tabs-panel {
    19871987        height: 200px;
    19881988        overflow: auto;
     
    19911991        border-width: 1px;
    19921992}
    19931993
    1994 #post-body #categorydiv div.tabs-panel,
     1994#post-body .categorydiv div.tabs-panel,
    19951995#post-body #linkcategorydiv div.tabs-panel {
    19961996        margin: 0 5px 0 125px;
    19971997}
    19981998
    1999 #side-sortables #category-tabs li {
     1999#side-sortables .category-tabs li {
    20002000        display: inline;
    20012001        padding-right: 8px;
    20022002}
    20032003
    2004 #side-sortables #category-tabs a {
     2004#side-sortables .category-tabs a {
    20052005        text-decoration: none;
    20062006}
    20072007
    2008 #side-sortables #category-tabs {
     2008#side-sortables .category-tabs {
    20092009        margin-bottom: 3px;
    20102010}
    20112011
    2012 #categorydiv ul,
     2012.categorydiv ul,
    20132013#linkcategorydiv ul {
    20142014        list-style: none;
    20152015        padding: 0;
    20162016        margin: 0;
    20172017}
    20182018
    2019 #categorydiv ul.categorychecklist ul,
     2019.categorydiv ul.categorychecklist ul,
    20202020#linkcategorydiv ul.categorychecklist ul {
    20212021        margin-left: 18px;
    20222022}
     
    20272027        line-height: 19px;
    20282028}
    20292029
    2030 #category-adder h4 {
     2030.category-adder h4 {
    20312031        margin-top: 4px;
    20322032        margin-bottom: 0px;
    20332033}
    20342034
    2035 #categorydiv .tabs-panel {
     2035.categorydiv .tabs-panel {
    20362036        border-width: 3px;
    20372037        border-style: solid;
    20382038}
    20392039
    2040 ul#category-tabs {
     2040ul.category-tabs {
    20412041        margin-top: 12px;
    20422042}
    20432043
    2044 ul#category-tabs li.tabs {
     2044ul.category-tabs li.tabs {
    20452045        border-style: solid solid none;
    20462046        border-width: 1px 1px 0;
    20472047}
    20482048
    2049 #post-body #category-tabs li.tabs {
     2049#post-body .category-tabs li.tabs {
    20502050        border-style: solid none solid solid;
    20512051        border-width: 1px 0 1px 1px;
    20522052        margin-right: -1px;
    20532053}
    20542054
    2055 ul#category-tabs li {
     2055ul.category-tabs li {
    20562056        padding: 5px 8px;
    20572057        -moz-border-radius: 3px 3px 0 0;
    20582058        -webkit-border-top-left-radius: 3px;
  • wp-admin/css/colors-classic.dev.css

     
    105105}
    106106
    107107div.tabs-panel,
    108 ul#category-tabs li.tabs {
     108ul.category-tabs li.tabs {
    109109        border-color: #dfdfdf;
    110110}
    111111
    112 ul#category-tabs li.tabs {
     112ul.category-tabs li.tabs {
    113113        background-color: #f1f1f1;
    114114}
    115115
     
    384384        background:#faf9f7 !important;
    385385}
    386386
    387 #side-sortables #category-tabs .tabs a {
     387#side-sortables .category-tabs .tabs a {
    388388        color: #333;
    389389}
    390390
     
    14591459        background-color: #f5f5f5;
    14601460}
    14611461
    1462 #post-body ul#category-tabs li.tabs a {
     1462#post-body ul.category-tabs li.tabs a {
    14631463        color: #333;
    14641464}
    14651465
  • wp-admin/css/press-this.dev.css

     
    308308        display: none;
    309309}
    310310
    311 #category-adder {
     311.category-adder {
    312312        padding: 4px 0;
    313313}
    314314
    315 #category-adder h4 {
     315.category-adder h4 {
    316316        margin: 0 0 8px;
    317317}
    318318
     
    339339}
    340340
    341341#category-add input,
    342 #category-add-sumbit {
     342.category-add-sumbit {
    343343        width: auto;
    344344}
    345345
    346346/* Categories */
    347 #categorydiv ul,
     347.categorydiv ul,
    348348#linkcategorydiv ul {
    349349        list-style: none;
    350350        padding: 0;
    351351        margin: 0;
    352352}
    353353
    354 #categorydiv ul.categorychecklist ul {
     354.categorydiv ul.categorychecklist ul {
    355355        margin-left: 18px;
    356356}
    357357
    358 #categorydiv div.tabs-panel {
     358.categorydiv div.tabs-panel {
    359359        height: 140px;
    360360        overflow: auto;
    361361}
  • wp-admin/css/colors-fresh.dev.css

     
    105105}
    106106
    107107div.tabs-panel,
    108 ul#category-tabs li.tabs {
     108ul.category-tabs li.tabs {
    109109        border-color: #dfdfdf;
    110110}
    111111
    112 ul#category-tabs li.tabs {
     112ul.category-tabs li.tabs {
    113113        background-color: #f1f1f1;
    114114}
    115115
     
    380380        border-color: #dfdfdf;
    381381}
    382382
    383 #side-sortables #category-tabs .tabs a {
     383#side-sortables .category-tabs .tabs a {
    384384        color: #333;
    385385}
    386386
     
    14541454        background-color: #f5f5f5;
    14551455}
    14561456
    1457 #post-body ul#category-tabs li.tabs a {
     1457#post-body ul.category-tabs li.tabs a {
    14581458        color: #333;
    14591459}
    14601460
  • wp-admin/rtl.dev.css

     
    298298        margin-left: 0;
    299299        margin-right: 120px;
    300300}
    301 #post-body ul#category-tabs li.tabs {
     301#post-body ul.category-tabs li.tabs {
    302302        -moz-border-radius: 0 3px 3px 0;
    303303        -webkit-border-top-left-radius: 0;
    304304        -webkit-border-top-right-radius: 3px;
     
    309309        border-bottom-left-radius: 0;
    310310        border-bottom-right-radius: 3px;
    311311}
    312 #post-body ul#category-tabs {
     312#post-body ul.category-tabs {
    313313        float: right;
    314314        text-align: left;
    315315        margin: 0 0 0 -120px;
     
    320320}
    321321/* 1800 - 2000
    322322=================================== */
    323 #side-sortables #category-tabs li {
     323#side-sortables .category-tabs li {
    324324        padding-right: 0;
    325325        padding-left: 8px;
    326326}