#36734 closed feature request (wontfix)
Filter for preview button
Reported by: | mitogh | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Posts, Post Types | Keywords: | 2nd-opinion |
Focuses: | ui, administration | Cc: |
Description
Hey guys.
First of all thank you for the great job you do every day with this project. Before I created a PR I would like to ask if we can have a filter for the Preview button. At the moment we can "hide" the button via inline CSS on the admin or JS but I would like to know if there is a chance to include a filter that we can use from our themes or plugins to hide this button where is required.. Since I saw the only way to hide this field is if the publicly_queryable is false.
I think if we have a filter that we can use to easily hide this button under certain circumstances might be useful for some scenarios such as:
- WP is used only to manage and create and API and the view is consumed via a APP or a FE that is not linked with the WP Themes such as an Angular or React project.
Plus this filter will not have any side effect on the current or normal sites that still uses the normal WP Themes.
Thank you for your work again, and please let me know what are the next steps on this one and I will be happy to send a PR for adding the required filter, just wanted to make sure you are ok with this type of changes.
So far this might be a possible approach:
<?php $show_preview_button = apply_filters( 'show_preview_button', true, $post ); if ( $show_preview_button && is_post_type_viewable( $post_type_object ) ) : // Preview button here endif;
Thank you!
Hi @mitogh. This is possible at the post type level by setting
publicly_queryable
tofalse
. Does this not suit your use case?I don't think it makes sense to hide the Preview button but still allow previewing. Setting
publicly_queryable
tofalse
will properly disable both.