WordPress.org

Make WordPress Core

Ticket #4015: cat_scope.diff

File cat_scope.diff, 5.0 KB (added by Tjworld, 11 years ago)

cat_scope patch for 2.1.3

  • wp-admin/admin-db.php

    diff -Naur wordpress-2.1.3/wp-admin/admin-db.php wordpress-2.1.3-p-cat_scope/wp-admin/admin-db.php
    old new  
    111111        if ( empty($category_parent) || !get_category( $category_parent ) || ($cat_ID && cat_is_ancestor_of($cat_ID, $category_parent) ) )
    112112                $category_parent = 0;
    113113
     114        if ( isset($cat_scope) ) // *** Patch Category Scope ***
     115                $cat_scope = (int) $cat_scope;
     116        else
     117                $cat_scope = 0; // *** Patch End ***
     118
    114119        if ( isset($posts_private) )
    115120                $posts_private = (int) $posts_private;
    116121        else
     
    121126        else
    122127                $links_private = 0;
    123128
    124         if (!$update) {
    125                 $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent, links_private, posts_private) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', '$category_parent', '$links_private', '$posts_private')");
     129        if (!$update) { // *** Patch Category Scope ***
     130                $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent, links_private, posts_private, cat_scope) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', '$category_parent', '$links_private', '$posts_private', '$cat_scope')");
    126131                $cat_ID = (int) $wpdb->insert_id;
    127132        } else {
    128                 $wpdb->query ("UPDATE $wpdb->categories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$category_parent', links_private = '$links_private', posts_private = '$posts_private' WHERE cat_ID = '$cat_ID'");
    129         }
     133                $wpdb->query ("UPDATE $wpdb->categories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$category_parent', links_private = '$links_private', posts_private = '$posts_private', cat_scope = '$cat_scope' WHERE cat_ID = '$cat_ID'");
     134        } // *** Patch End ***
    130135
    131136        if ( $category_nicename == '' ) {
    132137                $category_nicename = sanitize_title($cat_name, $cat_ID );
  • wp-admin/admin-functions.php

    diff -Naur wordpress-2.1.3/wp-admin/admin-functions.php wordpress-2.1.3-p-cat_scope/wp-admin/admin-functions.php
    old new  
    634634}
    635635
    636636function return_categories_list( $parent = 0 ) {
    637         global $wpdb;
    638         return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND ( link_count = 0 OR category_count != 0 OR ( link_count = 0 AND category_count = 0 ) ) ORDER BY category_count DESC" );
     637        global $wpdb;
     638        // *** Patch Category Scope ***
     639        return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND (cat_scope = 0 OR cat_scope = 1) ORDER BY category_count DESC" );
     640        // *** Patch End ***
    639641}
    640642
    641643function sort_cats( $cat1, $cat2 ) {
     
    709711
    710712function return_link_categories_list( $parent = 0 ) {
    711713        global $wpdb;
    712         return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND ( category_count = 0  OR link_count != 0 OR ( link_count = 0 AND category_count = 0 ) ) ORDER BY link_count DESC" );
     714        // *** Patch Category Scope ***
     715        return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND (cat_scope = 0 OR cat_scope = 2) ORDER BY link_count DESC" );
     716        // *** Patch End
    713717}
    714718
    715719function get_nested_link_categories( $default = 0, $parent = 0 ) {
  • wp-admin/edit-category-form.php

    diff -Naur wordpress-2.1.3/wp-admin/edit-category-form.php wordpress-2.1.3-p-cat_scope/wp-admin/edit-category-form.php
    old new  
    3333                        <td><input name="category_nicename" id="category_nicename" type="text" value="<?php echo attribute_escape($category->category_nicename); ?>" size="40" /></td>
    3434                </tr>
    3535                <tr>
     36                        <th scope="row" valign="top"><label for="cat_scope"><?php _e('Category scope:') ?></label></th>
     37                        <td>
     38                                <label for="cat_scope-0"><input id="cat_scope-0" name="cat_scope" type="radio" value="0" <?php checked($category->cat_scope, '0'); ?> /> <?php _e('Both') ?></label>
     39                                <label for="cat_scope-1"><input id="cat_scope-1" name="cat_scope" type="radio" value="1" <?php checked($category->cat_scope, '1'); ?> /> <?php _e('Post') ?></label>
     40                                <label for="cat_scope-2"><input id="cat_scope-2" name="cat_scope" type="radio" value="2" <?php checked($category->cat_scope, '2'); ?> /> <?php _e('Link') ?></label>
     41                    </td>
     42                </tr>
     43                <tr>
    3644                        <th scope="row" valign="top"><label for="category_parent"><?php _e('Category parent:') ?></label></th>
    3745                        <td>       
    3846                                <?php wp_dropdown_categories('hide_empty=0&name=category_parent&selected=' . $category->category_parent . '&hierarchical=1&show_option_none=' . __('None')); ?>