WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 2 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:

Description

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 2 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)

@sillybean
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.

@donmhico
2 months ago

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

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

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

@donmhico
2 months ago

Correct @since to adhere to WPCS.

Note: See TracTickets for help on using tickets.