wp-subtitle icon indicating copy to clipboard operation
wp-subtitle copied to clipboard

Preview of custom post type doesn't show subtitle

Open hatsumatsu opened this issue 6 years ago • 4 comments

When previewing a custom post type post (via the preview link on the edit post screen) the subtitle doesn't appear.

Looking at the code of includes/subtitle.php (Link) you're checking for a preview_id GET parameter. It seems that this parameter is not present in custom post types where the URL looks like https://example.com?post_type={custom_post_type}&p={post_id}&preview=true .

I can prepare a PR if required.

hatsumatsu avatar Aug 27 '18 10:08 hatsumatsu

If you are able to prepare a PR that would be very welcome.

Thank you

benhuson avatar Aug 28 '18 06:08 benhuson

I'm currently running some tests and in my case both wp_get_post_autosave() and wp_get_post_revisions() return false on a custom post type preview.

Everything runs smoothly when I remove the whole if ( is_preview() ) { ... } block in get_raw_subtitle(). Do you remember the reason for this block?

hatsumatsu avatar Aug 28 '18 10:08 hatsumatsu

It was originally added by a contributor in this commit to support revisions: https://github.com/benhuson/wp-subtitle/commit/523c9cad1335b7e05fe8e81cae762650cc9293cc#diff-d2289bcd07fd410250cf5d7b237d9d25

It was then reworking in this commit: https://github.com/benhuson/wp-subtitle/commit/b097220cfc08e8c33147fa0b382b30f8c99917cb

I think it may relate to browsing revisions of a page rather that previewing the page (?) To test, change the subtitle a few times, then click into a revision of the page and browser the different revisions.

benhuson avatar Aug 29 '18 21:08 benhuson

I was able to narrow down the bug: If a draft post has revisions the subtitle is missing in the preview. If there are no revisions (no changes saved in draft mode) the subtitle displays correctly in the preview.

So in the current logic if a post has a revision the latest revision is pulled correctly but it has no subtitle meta data. Could be that it's not saved correctly. I also guess that the problem occurs in custom post types that do not support revisions at all.

In general the nested logic in the function is a little bit confusing since the preview of a post is not nessacarrily related to post revisions.

As another observation I could not get if ( isset( $_GET['preview_id'] ) ) { in Line 84 to return true.

hatsumatsu avatar Aug 30 '18 08:08 hatsumatsu