Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breadcrumb includes parents that aren't published #38

Open
kraftner opened this issue Mar 7, 2018 · 0 comments
Open

Breadcrumb includes parents that aren't published #38

kraftner opened this issue Mar 7, 2018 · 0 comments

Comments

@kraftner
Copy link

kraftner commented Mar 7, 2018

Although rare sometimes a post can have a parent that itself doesn't have status publish. This might occur under (at least) the following conditions:

  1. You change the post status of a published post with existing children. The children then for now* still has the post as parent.

  2. If you alter the page attributes/parent dropdown to intentionally include e.g. private or draft posts using the page_attributes_dropdown_pages_args and quick_edit_dropdown_pages_args.

* As the page attributes/parent dropdown doesn't list anything but published posts the next time you save any of those children they loose the connection and become a root post themselves. See core issue #8592 for details.


I think the fix could be this:

if( 'publish' === $post->post_status ) break;

here:

// Get the post by ID.
$post = get_post( $post_id );
// If we hit a page that's set as the front page, bail.
if ( 'page' == $post->post_type && 'page' == get_option( 'show_on_front' ) && $post_id == get_option( 'page_on_front' ) )
break;

What I am a little bit unsure is how to handle private:

if( in_array( $post->post_status, array( 'publish', 'private' ) ) ) break;

I guess there would need to be some further check to see if the user can see it, but I didn't have time yet to look into that. So leaving this as a hint for now which I hope to revisit later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant