PHP Warning: Attempt to read property "post_content" on null
-
I’m using a wordpress theme which has not received updates for 2 years, and they’re not giving any support for that theme but I love this theme. After upgrading my server’s PHP version from 7.4 to 8.1 I’m getting an error_log.
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( '//', $post->post_content )
|| preg_match( '//', $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 or 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( ']]>', ']]>', $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 OR a quicktag \* AND the more link has not been added already \* then we add it now \*/ if ( ( preg\_match( '//', $post->post\_content ) || preg\_match( '//', $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 suggest a solution to fix the issue
-
I’m using a wordpress theme which has not received updates for 2 years, and they’re not giving any support for that theme but I love this theme. After upgrading my server’s PHP version from 7.4 to 8.1 I’m getting an error_log.
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( '//', $post->post_content )
|| preg_match( '//', $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 or 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( ']]>', ']]>', $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 OR a quicktag \* AND the more link has not been added already \* then we add it now \*/ if ( ( preg\_match( '//', $post->post\_content ) || preg\_match( '//', $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 suggest a solution to fix the issue