mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-16 19:46:21 +00:00
Add option to check if term exists with given parent. Update ajax add-cat check to pass parent when checking if cat exists.
git-svn-id: http://svn.automattic.com/wordpress/trunk@10905 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
e20fd21b39
commit
6f431038f2
@ -445,7 +445,7 @@ case 'add-cat' : // From Manage->Categories
|
||||
$x->send();
|
||||
}
|
||||
|
||||
if ( category_exists( trim( $_POST['cat_name'] ) ) ) {
|
||||
if ( category_exists( trim( $_POST['cat_name'] ), $_POST['category_parent'] ) ) {
|
||||
$x = new WP_Ajax_Response( array(
|
||||
'what' => 'cat',
|
||||
'id' => new WP_Error( 'cat_exists', __('The category you are trying to create already exists.'), array( 'form-field' => 'cat_name' ) ),
|
||||
|
@ -18,8 +18,10 @@
|
||||
* @param unknown_type $cat_name
|
||||
* @return unknown
|
||||
*/
|
||||
function category_exists($cat_name) {
|
||||
$id = is_term($cat_name, 'category');
|
||||
function category_exists($cat_name, $parent = 0) {
|
||||
$id = is_term($cat_name, 'category', $parent);
|
||||
global $wpdb;
|
||||
error_log(var_export($wpdb->queries, true));
|
||||
if ( is_array($id) )
|
||||
$id = $id['term_id'];
|
||||
return $id;
|
||||
|
@ -834,9 +834,10 @@ function &get_terms($taxonomies, $args = '') {
|
||||
*
|
||||
* @param int|string $term The term to check
|
||||
* @param string $taxonomy The taxonomy name to use
|
||||
* @param int $parent ID of parent term under which to confine the exists search.
|
||||
* @return mixed Get the term id or Term Object, if exists.
|
||||
*/
|
||||
function is_term($term, $taxonomy = '') {
|
||||
function is_term($term, $taxonomy = '', $parent = 0) {
|
||||
global $wpdb;
|
||||
|
||||
$select = "SELECT term_id FROM $wpdb->terms as t WHERE ";
|
||||
@ -857,18 +858,30 @@ function is_term($term, $taxonomy = '') {
|
||||
|
||||
$where = 't.slug = %s';
|
||||
$else_where = 't.name = %s';
|
||||
|
||||
$where_fields = array($slug);
|
||||
$else_where_fields = array($term);
|
||||
if ( !empty($taxonomy) ) {
|
||||
if ( $result = $wpdb->get_row( $wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $where AND tt.taxonomy = %s", $slug, $taxonomy), ARRAY_A) )
|
||||
$parent = (int) $parent;
|
||||
if ( $parent > 0 ) {
|
||||
$where_fields[] = $parent;
|
||||
$else_where_fields[] = $parent;
|
||||
$where .= ' AND tt.parent = %d';
|
||||
$else_where .= ' AND tt.parent = %d';
|
||||
}
|
||||
|
||||
$where_fields[] = $taxonomy;
|
||||
$else_where_fields[] = $taxonomy;
|
||||
|
||||
if ( $result = $wpdb->get_row( $wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $where AND tt.taxonomy = %s", $where_fields), ARRAY_A) )
|
||||
return $result;
|
||||
|
||||
return $wpdb->get_row( $wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $else_where AND tt.taxonomy = %s", $term, $taxonomy), ARRAY_A);
|
||||
return $wpdb->get_row( $wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $else_where AND tt.taxonomy = %s", $else_where_fields), ARRAY_A);
|
||||
}
|
||||
|
||||
if ( $result = $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $where", $slug) ) )
|
||||
if ( $result = $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $where", $where_fields) ) )
|
||||
return $result;
|
||||
|
||||
return $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $else_where", $term) );
|
||||
return $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $else_where", $else_where_fields) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user