Make WordPress Core

Opened 7 weeks ago

Last modified 6 weeks ago

#65511 new feature request

Introduce has_content() helper function

Reported by: salmanshafiq8630 Owned by:
Priority: normal Milestone: Awaiting Review
Component: Posts, Post Types Version: 7.0
Severity: normal Keywords: 2nd-opinion has-patch
Cc: Focuses:

Description (last modified by westonruter)

Currently, there is no dedicated helper function for determining whether a post contains content.

Developers typically check the post_content property directly:

<?php
$post = get_post( $post );

if ( $post && '' !== trim( $post->post_content ) ) {
    // The post has content.
}

This proposal introduces a new has_content() helper function, similar to has_excerpt(), that provides a consistent API for checking whether a post contains non-empty content.

The function would:

  • Accept a post ID, WP_Post object, or null.
  • Return true if the post contains non-empty content after trimming whitespace.
  • Return false if the post does not exist or its content is empty.

Change History (2)

#2 @westonruter
6 weeks ago

  • Description modified (diff)
Note: See TracTickets for help on using tickets.