• Recently I upgraded my PHP version from 7.4 to 8.1.

    Now I’m getting error_log as given below:

    PHP Warning: Attempt to read property "post_content" on null in /some-path/wp-content/themes/boldr-lite/functions.php on line 267

    PHP Warning: Attempt to read property "post_content" on null in /some-path/wp-content/themes/boldr-lite/functions.php on line 268

    I checked the functions.php and line number 267 and 268 as given below:

    preg_match( '/<!--more(.*?)?-->/', $post->post_content )

    || preg_match( '/<!--nextpage-->/', $post->post_content )

    And the full function including the above two lines as given below:

    /*
     * Rewrite and replace wp_trim_excerpt() so it adds a relevant read more link
     * when the <!--more--> or <!--nextpage--> quicktags are used
     * This new function preserves every features and filters from the original wp_trim_excerpt
     */
    function boldr_trim_excerpt( $text = '' ) {
    	global $post;
    	$raw_excerpt = $text;
    	if ( '' === $text ) {
    		$text = get_the_content( '' );
    		$text = strip_shortcodes( $text );
    		$text = apply_filters( 'the_content', $text );
    		$text = str_replace( ']]>', ']]&gt;', $text );
    		$excerpt_length = apply_filters( 'excerpt_length', 55 );
    		$excerpt_more = apply_filters( 'excerpt_more', ' [...]' );
    		$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
    
    		/* If the post_content contains a <!--more--> OR a <!--nextpage--> quicktag
    		 * AND the more link has not been added already
    		 * then we add it now
    		 */
    		if (
    			(
    				preg_match( '/<!--more(.*?)?-->/', $post->post_content )
    				|| preg_match( '/<!--nextpage-->/', $post->post_content )
    			)
    			&& strpos( $text, $excerpt_more ) === false
    		) :
    			$text .= $excerpt_more;
    		endif;
    
    	}
    	return apply_filters( 'boldr_trim_excerpt', $text, $raw_excerpt );
    }
    remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' );
    add_filter( 'get_the_excerpt', 'boldr_trim_excerpt' );

    Please help me to solve this issue, suggest me a corrected code

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator t-p

    (@t-p)

    Your boldr-lite theme seems to be the error.

    I recommend reporting the issue at https://www.ads-software.com/support/theme/boldr-lite

    Please note this theme hasn’t been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.

    If you don’t get any response from the theme developers, then look for another theme.

    Thread Starter onlanka

    (@onlanka)

    @t-p Yes they have not released any update for 2 years, so I decided to fix errors of this theme and bring it forward because I love this theme.

    • This reply was modified 1 year, 7 months ago by onlanka.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘PHP Warning: Attempt to read property “post_content” on null’ is closed to new replies.