Make WordPress Core

Opened 7 years ago

Last modified 4 years ago

#37462 new enhancement

Introduce is_private() conditional

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

Description

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

Attachments (4)

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

Download all attachments as: .zip

Change History (7)

@sillybean
7 years ago

#1 @SergeyBiryukov
7 years ago

  • Component changed from General to Posts, Post Types

#2 @johnbillion
7 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.

@donmhico
4 years ago

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

#3 @donmhico
4 years 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().

Reference:
https://developer.wordpress.org/reference/functions/get_post_status/

@donmhico
4 years ago

Correct @since to adhere to WPCS.

Note: See TracTickets for help on using tickets.