Handle $_POST containing an empty term array, Fixes saving of deselecting all hierarchical terms. Fixes #10122
git-svn-id: https://develop.svn.wordpress.org/trunk@14426 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
fb0fffbce5
commit
52cdae0385
|
@ -307,6 +307,10 @@ function post_categories_meta_box( $post, $box ) {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="<?php echo $taxonomy; ?>-all" class="tabs-panel">
|
<div id="<?php echo $taxonomy; ?>-all" class="tabs-panel">
|
||||||
|
<?php
|
||||||
|
$name = ( $taxonomy == 'category' ) ? 'post_category' : 'tax_input[' . $taxonomy . ']';
|
||||||
|
echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
|
||||||
|
?>
|
||||||
<ul id="<?php echo $taxonomy; ?>checklist" class="list:<?php echo $taxonomy?> categorychecklist form-no-clear">
|
<ul id="<?php echo $taxonomy; ?>checklist" class="list:<?php echo $taxonomy?> categorychecklist form-no-clear">
|
||||||
<?php wp_terms_checklist($post->ID, array( 'taxonomy' => $taxonomy, 'popular_cats' => $popular_ids ) ) ?>
|
<?php wp_terms_checklist($post->ID, array( 'taxonomy' => $taxonomy, 'popular_cats' => $popular_ids ) ) ?>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -2071,6 +2071,9 @@ function wp_insert_post($postarr = array(), $wp_error = false) {
|
||||||
if ( empty($post_type) )
|
if ( empty($post_type) )
|
||||||
$post_type = 'post';
|
$post_type = 'post';
|
||||||
|
|
||||||
|
if ( !empty($post_category) )
|
||||||
|
$post_category = array_filter($post_category); // Filter out empty terms
|
||||||
|
|
||||||
// Make sure we set a valid category.
|
// Make sure we set a valid category.
|
||||||
if ( empty($post_category) || 0 == count($post_category) || !is_array($post_category) ) {
|
if ( empty($post_category) || 0 == count($post_category) || !is_array($post_category) ) {
|
||||||
// 'post' requires at least one category.
|
// 'post' requires at least one category.
|
||||||
|
@ -2225,12 +2228,16 @@ function wp_insert_post($postarr = array(), $wp_error = false) {
|
||||||
|
|
||||||
wp_set_post_categories( $post_ID, $post_category );
|
wp_set_post_categories( $post_ID, $post_category );
|
||||||
// old-style tags_input
|
// old-style tags_input
|
||||||
if ( isset( $tags_input ) )
|
if ( isset( $tags_input ) ) {
|
||||||
|
$tags_input = array_filter($tags_input);
|
||||||
wp_set_post_tags( $post_ID, $tags_input );
|
wp_set_post_tags( $post_ID, $tags_input );
|
||||||
// new-style support for all tag-like taxonomies
|
}
|
||||||
|
// new-style support for all custom taxonomies
|
||||||
if ( !empty($tax_input) ) {
|
if ( !empty($tax_input) ) {
|
||||||
foreach ( $tax_input as $taxonomy => $tags ) {
|
foreach ( $tax_input as $taxonomy => $tags ) {
|
||||||
$taxonomy_obj = get_taxonomy($taxonomy);
|
$taxonomy_obj = get_taxonomy($taxonomy);
|
||||||
|
if ( is_array($tags) ) // array = hierarchical, string = non-hierarchical.
|
||||||
|
$tags = array_filter($tags);
|
||||||
if ( current_user_can($taxonomy_obj->assign_cap) )
|
if ( current_user_can($taxonomy_obj->assign_cap) )
|
||||||
wp_set_post_terms( $post_ID, $tags, $taxonomy );
|
wp_set_post_terms( $post_ID, $tags, $taxonomy );
|
||||||
}
|
}
|
||||||
|
@ -3668,7 +3675,7 @@ function wp_mime_type_icon( $mime = 0 ) {
|
||||||
* @return int Same as $post_id
|
* @return int Same as $post_id
|
||||||
*/
|
*/
|
||||||
function wp_check_for_changed_slugs($post_id) {
|
function wp_check_for_changed_slugs($post_id) {
|
||||||
if ( !isset($_POST['wp-old-slug']) || !strlen($_POST['wp-old-slug']) )
|
if ( empty($_POST['wp-old-slug']) )
|
||||||
return $post_id;
|
return $post_id;
|
||||||
|
|
||||||
$post = &get_post($post_id);
|
$post = &get_post($post_id);
|
||||||
|
|
Loading…
Reference in New Issue