Skip to content

Loading…

Add handling of "sticky" data parameter for creating or editing posts. #218

Merged
merged 4 commits into from

2 participants

@rachelbaker
WordPress REST API Team member

Allow "sticky" posts to be created or sticky status to be updated.

@rachelbaker
WordPress REST API Team member

Will also require tests and updated docs.

@rachelbaker rachelbaker added this to the 1.1 milestone
@rachelbaker rachelbaker self-assigned this
@rmccue
WordPress REST API Team member

Looks like this is just using the wrong variable in insert_post. Should work on post update already, but broken on new posts.

@rmccue rmccue referenced this pull request
Merged

Test post endpoints #99

@rachelbaker
WordPress REST API Team member

@rmccue #reviewmerge

@rachelbaker rachelbaker removed their assignment
@rmccue rmccue was assigned by rachelbaker
@rmccue rmccue removed the Has Patch label
@rmccue rmccue merged commit ea87f36 into master

1 check passed

Details continuous-integration/travis-ci The Travis CI build passed
@rmccue rmccue deleted the sticky-handling branch
@rmccue
WordPress REST API Team member

Working well for me. Awesome! :octopus:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 8 additions and 5 deletions.
  1. +4 −0 docs/routes/posts.md
  2. +4 −4 lib/class-wp-json-posts.php
  3. +0 −1 tests/test_json_posts.php
View
4 docs/routes/posts.md
@@ -69,6 +69,8 @@ pairs:
* `ping_status` - Ping status for the post: `open` or `closed`. Indicates
whether users can submit pingbacks or trackbacks to the post. Default is the
option 'default_ping_status'. (string) *optional*
+* `sticky` - Sticky status for the post: `true` or `false`. Default is
+ `false`. (boolean) *optional*
### Response
@@ -215,6 +217,8 @@ pairs:
* `ping_status` - Ping status for the post: `open` or `closed`. Indicates
whether users can submit pingbacks or trackbacks to the post. Default is the
option 'default_ping_status'. (string) *optional*
+* `sticky` - Sticky status for the post: `true` or `false`. Default is
+ `false`. (boolean) *optional*
### Response
View
8 lib/class-wp-json-posts.php
@@ -1463,11 +1463,11 @@ protected function insert_post( $data ) {
}
// Sticky
- if ( isset( $post['sticky'] ) ) {
- if ( $post['sticky'] ) {
- stick_post( $data['ID'] );
+ if ( isset( $data['sticky'] ) ) {
+ if ( $data['sticky'] ) {
+ stick_post( $post_ID );
} else {
- unstick_post( $data['ID'] );
+ unstick_post( $post_ID );
}
}
View
1 tests/test_json_posts.php
@@ -494,7 +494,6 @@ function test_create_post_menu_order_noninteger() {
}
function test_create_post_sticky() {
- $this->markTestSkipped('https://github.com/WP-API/WP-API/issues/218');
$data = $this->set_data(array(
'sticky' => true,
));
Something went wrong with that request. Please try again.