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

Preview button does not work in combination with this plugin #13

Open
paulhuisman opened this issue Sep 5, 2014 · 2 comments
Open

Preview button does not work in combination with this plugin #13

paulhuisman opened this issue Sep 5, 2014 · 2 comments

Comments

@paulhuisman
Copy link

Hey KLicheR,

First of: amazing work on adding the possibility for archive slugs! it works great!

I have a question: when using your plugin, i am not able to preview a post.

When i create a news post with slug "test-page" and i click Preview i am redirected to http://testsite.com/nieuws/test-page?preview=true and i get an 404 page. This should be http://testsite.com/nl/nieuws/test-preview?preview=true (because my default language is NL).

I tried looking for a clue but didnt find one yet. Can you help?

Thanks!

@idflood
Copy link
Contributor

idflood commented Dec 15, 2014

I got the same issue and I found the problematic function. It's the post_type_link_filter here:
https://github.com/KLicheR/wp-polylang-translate-rewrite-slugs/blob/master/polylang-translate-rewrite-slugs.php#L158

When the post is a draft it looks like the $post-post_name is not defined so I think it might be good to take the same condition as the one in worpdress > wp-includes/link-template.php > get_post_permalink:

$draft_or_pending = isset($post->post_status) && in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );

and then do somethink like this:

// Check if the post type is handle.
if (( !$draft_or_pending || $sample ) && isset($this->post_types[$post->post_type])) {
  // Build URL. Lang prefix is already handle.
  return home_url('/'.$this->post_types[$post->post_type]->translated_slugs[$lang]->rewrite['slug'].'/'.($leavename?"%$post->post_type%":$post->post_name));
}

This change fix the issue for me but since I don't understand why this function exist and the usage of the $leavename and $sample parameters this might as well break other things.

If this looks right and doesn't break everything I can do a pull request : )

edit: I found one issue with the proposed solution. When you try to access the draft preview as anonymous there is a redirect loop... (the url looks like mywordpress/?post_type=project&p=15426 ). Without the modification I'm redirected to the archive page.

@paulhuisman
Copy link
Author

Nice find @idflood !

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

2 participants