Make WordPress Core

Opened 3 years ago

Last modified 3 months ago

#37462 new enhancement

Introduce is_private() conditional

Reported by: sillybean Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: has-patch
Focuses: template Cc:
PR Number:


Add a quick conditional tag to check whether the post is private.

Attachments (4)

is_private.diff (820 bytes) - added by sillybean 3 years ago.
is_private.2.diff (819 bytes) - added by sillybean 3 years ago.
37462.diff (1.9 KB) - added by donmhico 3 months ago.
Added new function is_private_post() and unit test for it.
37462.2.diff (1.9 KB) - added by donmhico 2 months ago.
Correct @since to adhere to WPCS.

Download all attachments as: .zip

Change History (7)

3 years ago

#1 @SergeyBiryukov
3 years ago

  • Component changed from General to Posts, Post Types

#2 @johnbillion
3 years ago

  • Keywords needs-patch needs-unit-tests added
  • Version trunk deleted

Thanks for the patch, @sillybean. Some feedback for you:

  • This probably needs a more descriptive function name, such as is_private_post().
  • Have you tested this function? It's checking the value of the post_password field.
  • This will need unit tests to avoid the above.

3 months ago

Added new function is_private_post() and unit test for it.

#3 @donmhico
3 months ago

  • Keywords has-patch added; needs-patch needs-unit-tests removed

My attached patch, 37462.diff, introduced a new function - is_private_post( $post ) - which returns true if the $post passed is private and false if otherwise. It uses the function get_post_status().


2 months ago

Correct @since to adhere to WPCS.

Note: See TracTickets for help on using tickets.