X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/f9001779751f83dc8a10e478bfecb4d8dd5f964c..e9d988989fe37ab8c5f903e47fbe36e6e00dc51f:/wp-includes/taxonomy.php?ds=sidebyside diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 89532dcd..d9ae2d5a 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -15,6 +15,8 @@ * Creates the initial taxonomies when 'init' action is fired. */ function create_initial_taxonomies() { + global $wp_rewrite; + register_taxonomy( 'category', 'post', array( 'hierarchical' => true, 'update_count_callback' => '_update_post_term_count', @@ -22,7 +24,7 @@ function create_initial_taxonomies() { 'rewrite' => did_action( 'init' ) ? array( 'hierarchical' => true, 'slug' => get_option('category_base') ? get_option('category_base') : 'category', - 'with_front' => false) : false, + 'with_front' => ( get_option('category_base') && ! $wp_rewrite->using_index_permalinks() ) ? false : true ) : false, 'public' => true, 'show_ui' => true, '_builtin' => true, @@ -34,7 +36,7 @@ function create_initial_taxonomies() { 'query_var' => 'tag', 'rewrite' => did_action( 'init' ) ? array( 'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag', - 'with_front' => false) : false, + 'with_front' => ( get_option('category_base') && ! $wp_rewrite->using_index_permalinks() ) ? false : true ) : false, 'public' => true, 'show_ui' => true, '_builtin' => true, @@ -329,7 +331,7 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) { $tag = '([^/]+)'; $wp_rewrite->add_rewrite_tag("%$taxonomy%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term="); - $wp_rewrite->add_permastruct($taxonomy, "{$wp_rewrite->root}{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite']['with_front']); + $wp_rewrite->add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite']['with_front']); } if ( is_null($args['show_ui']) ) @@ -887,7 +889,10 @@ function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw $value = stripslashes($value); $field = 't.name'; } else { - return get_term( (int) $value, $taxonomy, $output, $filter); + $term = get_term( (int) $value, $taxonomy, $output, $filter); + if ( is_wp_error( $term ) ) + $term = false; + return $term; } $term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND $field = %s LIMIT 1", $taxonomy, $value) ); @@ -1250,8 +1255,10 @@ function &get_terms($taxonomies, $args = '') { $where .= " AND t.slug = '$slug'"; } - if ( !empty($name__like) ) - $where .= " AND t.name LIKE '" . like_escape( $name__like ) . "%'"; + if ( !empty($name__like) ) { + $name__like = like_escape( $name__like ); + $where .= $wpdb->prepare( " AND t.name LIKE %s", $name__like . '%' ); + } if ( '' !== $parent ) { $parent = (int) $parent; @@ -1273,7 +1280,7 @@ function &get_terms($taxonomies, $args = '') { if ( !empty($search) ) { $search = like_escape($search); - $where .= " AND (t.name LIKE '%$search%')"; + $where .= $wpdb->prepare( " AND (t.name LIKE %s)", '%' . $search . '%'); } $selects = array(); @@ -2842,7 +2849,9 @@ function get_term_link( $term, $taxonomy = '') { $t = get_taxonomy($taxonomy); if ( empty($termlink) ) { - if ( $t->query_var ) + if ( 'category' == $taxonomy ) + $termlink = '?cat=' . $term->term_id; + elseif ( $t->query_var ) $termlink = "?$t->query_var=$slug"; else $termlink = "?taxonomy=$taxonomy&term=$slug";