diff --git src/wp-admin/options-writing.php src/wp-admin/options-writing.php
index 8134c2fb83..e5f36d7be7 100644
|
|
require_once ABSPATH . 'wp-admin/admin-header.php'; |
80 | 80 | <?php |
81 | 81 | wp_dropdown_categories( |
82 | 82 | array( |
83 | | 'hide_empty' => 0, |
84 | | 'name' => 'default_category', |
85 | | 'orderby' => 'name', |
86 | | 'selected' => get_option( 'default_category' ), |
87 | | 'hierarchical' => true, |
| 83 | 'hide_empty' => 0, |
| 84 | 'name' => 'default_category', |
| 85 | 'orderby' => 'name', |
| 86 | 'selected' => get_option( 'default_category' ), |
| 87 | 'hierarchical' => true, |
| 88 | 'show_option_none' => __( '-- none --' ), |
| 89 | 'option_none_value' => 0, |
88 | 90 | ) |
89 | 91 | ); |
90 | 92 | ?> |
… |
… |
if ( apply_filters( 'enable_post_by_email_configuration', true ) ) { |
174 | 176 | <?php |
175 | 177 | wp_dropdown_categories( |
176 | 178 | array( |
177 | | 'hide_empty' => 0, |
178 | | 'name' => 'default_email_category', |
179 | | 'orderby' => 'name', |
180 | | 'selected' => get_option( 'default_email_category' ), |
181 | | 'hierarchical' => true, |
| 179 | 'hide_empty' => 0, |
| 180 | 'name' => 'default_email_category', |
| 181 | 'orderby' => 'name', |
| 182 | 'selected' => get_option( 'default_email_category' ), |
| 183 | 'hierarchical' => true, |
| 184 | 'show_option_none' => __( '-- none --' ), |
| 185 | 'option_none_value' => 0, |
182 | 186 | ) |
183 | 187 | ); |
184 | 188 | ?> |
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
index 88ab53b258..c941159dae 100644
|
|
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1402 | 1402 | continue; |
1403 | 1403 | } |
1404 | 1404 | |
| 1405 | // Empty terms checks. |
| 1406 | if ( empty( $request[ $base ] ) ) { |
| 1407 | |
| 1408 | $default_term = null; |
| 1409 | |
| 1410 | // Built-in taxonomy. |
| 1411 | if ( 'category' === $taxonomy->name ) { |
| 1412 | $default_term = get_option( 'default_category' ); |
| 1413 | } |
| 1414 | // Custom taxonomies. |
| 1415 | elseif ( ! empty( $taxonomy->default_term ) ) { |
| 1416 | $default_term = get_option( 'default_term_' . $taxonomy->name ); |
| 1417 | } |
| 1418 | |
| 1419 | if ( ! empty( $default_term ) ) { |
| 1420 | $request[ $base ] = array( (int)$default_term ); |
| 1421 | } |
| 1422 | } |
| 1423 | |
1405 | 1424 | $result = wp_set_object_terms( $post_id, $request[ $base ], $taxonomy->name ); |
1406 | 1425 | |
1407 | 1426 | if ( is_wp_error( $result ) ) { |
diff --git tests/phpunit/tests/rest-api/rest-posts-controller.php tests/phpunit/tests/rest-api/rest-posts-controller.php
index 3c6c668ff0..cb7f6135f9 100644
|
|
class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te |
3445 | 3445 | $request->set_body_params( $params ); |
3446 | 3446 | $response = rest_get_server()->dispatch( $request ); |
3447 | 3447 | $new_data = $response->get_data(); |
| 3448 | $this->assertEquals( array( 1 ), $new_data['categories'] ); |
| 3449 | |
| 3450 | // Check with empty default category settings. |
| 3451 | $default_term = get_option( 'default_category' ); |
| 3452 | update_option( 'default_category', 0 ); |
| 3453 | $request->set_body_params( $params ); |
| 3454 | $response = rest_get_server()->dispatch( $request ); |
| 3455 | $new_data = $response->get_data(); |
3448 | 3456 | $this->assertEquals( array(), $new_data['categories'] ); |
| 3457 | update_option( 'default_category', $default_term ); |
3449 | 3458 | } |
3450 | 3459 | |
3451 | 3460 | /** |