xwp / wp-customize-posts

Edit posts and postmeta in the WordPress Customizer
https://wordpress.org/plugins/customize-posts/
144 stars 42 forks source link

Optionally filter edit_post_link on frontend to deep-link to post in Customizer #34

Open westonruter opened 8 years ago

westonruter commented 8 years ago

Deep links to posts in the Customizer look like this: http://src.wordpress-develop.dev/wp-admin/customize.php?autofocus[section]=post[post][1234]&url=http%3A%2F%2Fsrc.wordpress-develop.dev%2F%3Fpost_type%3Dpost%26p%3D1234.

westonruter commented 8 years ago

The url param should be added here as well and it should be the current URL on which the edit_post_link() appears, as opposed to the permalink for the post. This would allow the Customizer preview to initially load in the same view and when the link was clicked.

stuartshields commented 8 years ago

@westonruter This doesn't appear to support custom post types... Is that correct?

Even though the URL is formatted correctly, it gives us a error 404. http://vip.local/wp-admin/customize.php?url=http%3A%2F%2Fvip.local%2F%3Fpreview%3Dtrue%26p%3D22&previewed_post=22&autofocus[section]=post[movies][22]&customize_preview_post_nonce=8745488e02

FYI: I haven't added the new URL markup yet

westonruter commented 8 years ago

@stuartshields it does work with custom post types.

Your URL here looks like it has HTML encoding of entities.

westonruter commented 8 years ago

Good on you for ensuring the url of the post being previewed is also included in the edit post link, with the autofocus to open the section when the customizer loads. I didn't note that in the description.

stuartshields commented 8 years ago

@westonruter I haven't done anything that was already in the code as references here: https://github.com/xwp/wp-customize-posts/blob/develop/php/class-edit-post-preview.php#L108

I don't like repeating myself so I'm thinking I'll build on what's already done. You can't see any issues with me doing this can you? I should have this and #93 ready by the end of the week. I also noticed when using this deep link with #93 that no Save/Publish button appears have you come across that issue?

westonruter commented 8 years ago

@stuartshields yes, extracting that logic into a separate get_customize_url method is great.

I also noticed when using this deep link with #93 that no Save/Publish button appears have you come across that issue?

Yes. I see that too. This is due to \Edit_Post_Preview::can_load_customize_post_preview() incorrectly returning true in this instance. Basically, since you're re-using the same logic to generate the URL to access that post in the preview, the existing URL generated is expecting that you are loading it from the edit post screen via clicking the Preview Changes button. When opening the Customizer via the Preview Changes button, it disables the Save & Publish button and removes all controls/sections/panels not relevant to the current post. This is undesirable when clicking Edit in Customizer generally. The quickest workaround is to prevent previewed_post from being added as a query var expect in the URL generated for clicking the Preview Changes button.