| @@ 168-215 (lines=48) @@ | ||
| 165 | $terms = explode( ',', $input[$key] ); |
|
| 166 | } |
|
| 167 | ||
| 168 | foreach ( $terms as $term ) { |
|
| 169 | /** |
|
| 170 | * `curl --data 'category[]=123'` should be interpreted as a category ID, |
|
| 171 | * not a category whose name is '123'. |
|
| 172 | * |
|
| 173 | * Consequence: To add a category/tag whose name is '123', the client must |
|
| 174 | * first look up its ID. |
|
| 175 | */ |
|
| 176 | $term = (string) $term; // ctype_digit compat |
|
| 177 | if ( ctype_digit( $term ) ) { |
|
| 178 | $term = (int) $term; |
|
| 179 | } |
|
| 180 | ||
| 181 | $term_info = term_exists( $term, $taxonomy ); |
|
| 182 | ||
| 183 | if ( ! $term_info ) { |
|
| 184 | // A term ID that doesn't already exist. Ignore it: we don't know what name to give it. |
|
| 185 | if ( is_int( $term ) ){ |
|
| 186 | continue; |
|
| 187 | } |
|
| 188 | // only add a new tag/cat if the user has access to |
|
| 189 | $tax = get_taxonomy( $taxonomy ); |
|
| 190 | ||
| 191 | // see https://core.trac.wordpress.org/ticket/26409 |
|
| 192 | if ( 'category' === $taxonomy && ! current_user_can( $tax->cap->edit_terms ) ) { |
|
| 193 | continue; |
|
| 194 | } else if ( ! current_user_can( $tax->cap->assign_terms ) ) { |
|
| 195 | continue; |
|
| 196 | } |
|
| 197 | ||
| 198 | $term_info = wp_insert_term( $term, $taxonomy ); |
|
| 199 | } |
|
| 200 | ||
| 201 | if ( ! is_wp_error( $term_info ) ) { |
|
| 202 | if ( $is_hierarchical ) { |
|
| 203 | // Categories must be added by ID |
|
| 204 | $tax_input[$taxonomy][] = (int) $term_info['term_id']; |
|
| 205 | } else { |
|
| 206 | // Tags must be added by name |
|
| 207 | if ( is_int( $term ) ) { |
|
| 208 | $term = get_term( $term, $taxonomy ); |
|
| 209 | $tax_input[$taxonomy][] = $term->name; |
|
| 210 | } else { |
|
| 211 | $tax_input[$taxonomy][] = $term; |
|
| 212 | } |
|
| 213 | } |
|
| 214 | } |
|
| 215 | } |
|
| 216 | } |
|
| 217 | ||
| 218 | if ( isset( $input['categories'] ) && empty( $tax_input['category'] ) && 'revision' !== $post_type->name ) { |
|
| @@ 209-256 (lines=48) @@ | ||
| 206 | $tax_input[ $taxonomy ] = array(); |
|
| 207 | $is_hierarchical = is_taxonomy_hierarchical( $taxonomy ); |
|
| 208 | ||
| 209 | foreach ( $terms as $term ) { |
|
| 210 | /** |
|
| 211 | * `curl --data 'terms[category][]=123'` should be interpreted as a category ID, |
|
| 212 | * not a category whose name is '123'. |
|
| 213 | * |
|
| 214 | * Consequence: To add a category/tag whose name is '123', the client must |
|
| 215 | * first look up its ID. |
|
| 216 | */ |
|
| 217 | $term = (string) $term; // ctype_digit compat |
|
| 218 | if ( ctype_digit( $term ) ) { |
|
| 219 | $term = (int) $term; |
|
| 220 | } |
|
| 221 | ||
| 222 | $term_info = term_exists( $term, $taxonomy ); |
|
| 223 | ||
| 224 | if ( ! $term_info ) { |
|
| 225 | // A term ID that doesn't already exist. Ignore it: we don't know what name to give it. |
|
| 226 | if ( is_int( $term ) ){ |
|
| 227 | continue; |
|
| 228 | } |
|
| 229 | // only add a new tag/cat if the user has access to |
|
| 230 | $tax = get_taxonomy( $taxonomy ); |
|
| 231 | ||
| 232 | // see https://core.trac.wordpress.org/ticket/26409 |
|
| 233 | if ( $is_hierarchical && ! current_user_can( $tax->cap->edit_terms ) ) { |
|
| 234 | continue; |
|
| 235 | } else if ( ! current_user_can( $tax->cap->assign_terms ) ) { |
|
| 236 | continue; |
|
| 237 | } |
|
| 238 | ||
| 239 | $term_info = wp_insert_term( $term, $taxonomy ); |
|
| 240 | } |
|
| 241 | ||
| 242 | if ( ! is_wp_error( $term_info ) ) { |
|
| 243 | if ( $is_hierarchical ) { |
|
| 244 | // Hierarchical terms must be added by ID |
|
| 245 | $tax_input[$taxonomy][] = (int) $term_info['term_id']; |
|
| 246 | } else { |
|
| 247 | // Non-hierarchical terms must be added by name |
|
| 248 | if ( is_int( $term ) ) { |
|
| 249 | $term = get_term( $term, $taxonomy ); |
|
| 250 | $tax_input[$taxonomy][] = $term->name; |
|
| 251 | } else { |
|
| 252 | $tax_input[$taxonomy][] = $term; |
|
| 253 | } |
|
| 254 | } |
|
| 255 | } |
|
| 256 | } |
|
| 257 | } |
|
| 258 | ||
| 259 | if ( isset( $input['terms']['category'] ) && empty( $tax_input['category'] ) && 'revision' !== $post_type->name ) { |
|