Discussion:
Incorrect documentation for register_post_status
Nikola Nikolov
2014-07-04 13:38:27 UTC
Permalink
I had to add a new custom post status and so I looked-up the documentation
for the register_post_status()
<http://codex.wordpress.org/Function_Reference/register_post_status>
function and adjusted the sample code from there.

I found a way to add the post status to the status drop-down on the
add/edit posts screens and changed the status of one of the posts.

It all worked as expected - the post status was now updated for that post.

Then I went back to the posts screen for my custom post type and I saw the
post status link on top, showing me that there's 1 post with that post
status. That's also correct.

However the post disappeared from the list of posts, even though I've set
"show_in_admin_all_list" to true in the arguments for the post status.

So I looked around and found out that in /wp-includes/query.php on line
#2819
<https://github.com/WordPress/WordPress/blob/3.9-branch/wp-includes/query.php#L2819>
,
WordPress is getting registered post statuses with show_in_admin_all_list =
true AND protected = true

The *protected* argument is not documented anywhere, but after I set that
to true in my arguments list, the post appeared again.

I would go in and document that myself, but I really have no clue what
*protected* is used for and I don't want to advise people to add it in just
because it works.

If anyone has more insight, I'd be happy to hear it.

Nikola
Pascal Birchler
2014-07-07 07:26:31 UTC
Permalink
How does your code look like? It seems like setting the `public` argument
to true should be enough. See the lines above:
https://github.com/WordPress/WordPress/blob/3.9-branch/wp-includes/query.php#L2810
Post by Nikola Nikolov
I had to add a new custom post status and so I looked-up the documentation
for the register_post_status()
<http://codex.wordpress.org/Function_Reference/register_post_status>
function and adjusted the sample code from there.
I found a way to add the post status to the status drop-down on the
add/edit posts screens and changed the status of one of the posts.
It all worked as expected - the post status was now updated for that post.
Then I went back to the posts screen for my custom post type and I saw the
post status link on top, showing me that there's 1 post with that post
status. That's also correct.
However the post disappeared from the list of posts, even though I've set
"show_in_admin_all_list" to true in the arguments for the post status.
So I looked around and found out that in /wp-includes/query.php on line
#2819
<
https://github.com/WordPress/WordPress/blob/3.9-branch/wp-includes/query.php#L2819
,
WordPress is getting registered post statuses with show_in_admin_all_list =
true AND protected = true
The *protected* argument is not documented anywhere, but after I set that
to true in my arguments list, the post appeared again.
I would go in and document that myself, but I really have no clue what
*protected* is used for and I don't want to advise people to add it in just
because it works.
If anyone has more insight, I'd be happy to hear it.
Nikola
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Nikola Nikolov
2014-07-07 11:43:16 UTC
Permalink
That's the thing - I don't want posts with that status to be public.

However, in theory(according to the documentation), setting
"show_in_admin_all_list" to true should make posts with that post status
visible in the "All" section of the posts list.

What I'm not sure about is what the "protected" property of a post status
is used for.
Post by Pascal Birchler
How does your code look like? It seems like setting the `public` argument
https://github.com/WordPress/WordPress/blob/3.9-branch/wp-includes/query.php#L2810
Post by Nikola Nikolov
I had to add a new custom post status and so I looked-up the
documentation
Post by Nikola Nikolov
for the register_post_status()
<http://codex.wordpress.org/Function_Reference/register_post_status>
function and adjusted the sample code from there.
I found a way to add the post status to the status drop-down on the
add/edit posts screens and changed the status of one of the posts.
It all worked as expected - the post status was now updated for that
post.
Post by Nikola Nikolov
Then I went back to the posts screen for my custom post type and I saw
the
Post by Nikola Nikolov
post status link on top, showing me that there's 1 post with that post
status. That's also correct.
However the post disappeared from the list of posts, even though I've set
"show_in_admin_all_list" to true in the arguments for the post status.
So I looked around and found out that in /wp-includes/query.php on line
#2819
<
https://github.com/WordPress/WordPress/blob/3.9-branch/wp-includes/query.php#L2819
Post by Nikola Nikolov
,
WordPress is getting registered post statuses with
show_in_admin_all_list =
Post by Nikola Nikolov
true AND protected = true
The *protected* argument is not documented anywhere, but after I set that
to true in my arguments list, the post appeared again.
I would go in and document that myself, but I really have no clue what
*protected* is used for and I don't want to advise people to add it in
just
Post by Nikola Nikolov
because it works.
If anyone has more insight, I'd be happy to hear it.
Nikola
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
J.D. Grimes
2014-07-07 13:12:51 UTC
Permalink
Take a look at the registration of the core post types: https://core.trac.wordpress.org/browser/trunk/src/wp-includes/post.php#L111

public => true is used for publish.
protected => true is used for future, draft, and pending.
private => true is used for private.
internal => true is used for trash, auto-draft, and inherit.

So the protected property means that a post status shouldn’t be visible on the front end to users without the required caps. In other words, it would make the status behave like a draft or pending post.

The docs should be updated to say that a post status should be registered with one of these set to true. They basically represent a ‘visibility’ property for the status, but instead they are each a separate property (but they probably shouldn’t have been, IMHO). I think it is intended that one of them should always be used, and not more than one.

-J.D.
Post by Nikola Nikolov
That's the thing - I don't want posts with that status to be public.
However, in theory(according to the documentation), setting
"show_in_admin_all_list" to true should make posts with that post status
visible in the "All" section of the posts list.
What I'm not sure about is what the "protected" property of a post status
is used for.
Post by Pascal Birchler
How does your code look like? It seems like setting the `public` argument
https://github.com/WordPress/WordPress/blob/3.9-branch/wp-includes/query.php#L2810
Post by Nikola Nikolov
I had to add a new custom post status and so I looked-up the
documentation
Post by Nikola Nikolov
for the register_post_status()
<http://codex.wordpress.org/Function_Reference/register_post_status>
function and adjusted the sample code from there.
I found a way to add the post status to the status drop-down on the
add/edit posts screens and changed the status of one of the posts.
It all worked as expected - the post status was now updated for that
post.
Post by Nikola Nikolov
Then I went back to the posts screen for my custom post type and I saw
the
Post by Nikola Nikolov
post status link on top, showing me that there's 1 post with that post
status. That's also correct.
However the post disappeared from the list of posts, even though I've set
"show_in_admin_all_list" to true in the arguments for the post status.
So I looked around and found out that in /wp-includes/query.php on line
#2819
<
https://github.com/WordPress/WordPress/blob/3.9-branch/wp-includes/query.php#L2819
Post by Nikola Nikolov
,
WordPress is getting registered post statuses with
show_in_admin_all_list =
Post by Nikola Nikolov
true AND protected = true
The *protected* argument is not documented anywhere, but after I set that
to true in my arguments list, the post appeared again.
I would go in and document that myself, but I really have no clue what
*protected* is used for and I don't want to advise people to add it in
just
Post by Nikola Nikolov
because it works.
If anyone has more insight, I'd be happy to hear it.
Nikola
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Loading...