• Resolved grafis

    (@snackmaster)


    The following warning appears in my error logs 24,852 times in the last 3 months, no issues viewing the site. Anything I can or should do?

    PHP Warning: Attempt to read property "ID" on null in /var/www/domain.com/public_html/wp-content/themes/astrid/functions.php on line 269

Viewing 6 replies - 1 through 6 (of 6 total)
  • @snackmaster I am sorry to hear about the issue you’re experiencing.

    To fix it, try editing the Astrid theme’s functions.php file to find this line:

    $single_toggle = get_post_meta( $post->ID, '_astrid_single_header_shortcode', true );

    Replace it with:

    if ( is_singular() ) {
    	$single_toggle = get_post_meta( $post->ID, '_astrid_single_header_shortcode', true );
    }

    Hope that helps.

    Regards,
    Kharis

    Thread Starter grafis

    (@snackmaster)

    Appreciate the help! After updating the functions file the error on line 269 is gone but I have a new one on line 276 – Undefined variable $single_toggle in /var/www/domain.com/public_html/wp-content/themes/astrid/functions.php on line 276

    
    
    /**
     * Header image check
     */
    function astrid_has_header() {
    	$front_header = get_theme_mod('front_header_type' ,'image');
    	$site_header = get_theme_mod('site_header_type', 'nothing');
    	global $post;
    	if ( !is_404() || !is_search() ) {
    		if ( is_singular() ) {
    	$single_toggle = get_post_meta( $post->ID, '_astrid_single_header_shortcode', true );
    }
    	} else {
    		$single_toggle = false;
    	}
    
    	if ($single_toggle != '') {
    		return 'has-single';
    	} else {
    		if ( get_header_image() && ( $front_header == 'image' && is_front_page() ) || ( $site_header == 'image' && !is_front_page() ) ) {
    			return 'has-header';
    		} elseif ( ($front_header == 'shortcode' && is_front_page()) || ($site_header == 'shortcode' && !is_front_page()) ) {
    			return 'has-shortcode';
    		} elseif ( ($front_header == 'video' && is_front_page()) || ($site_header == 'video' && !is_front_page()) ) {
    			return 'has-video';
    		}		
    	}
    }
    • This reply was modified 2 years, 11 months ago by grafis.
    • This reply was modified 2 years, 11 months ago by grafis.
    Thread Starter grafis

    (@snackmaster)

    Anyone else experience this issue? It’s an endless stream in my error log.
    @kharisblank fix posted above worked for the original error but created a new one.

    I am sorry for the delay @snackmaster.

    Try adding this line right after the function opening.

    $single_toggle = false;

    So the function will look like this:

    /**
     * Header image check
     */
    function astrid_has_header() {
      $single_toggle = false;
    	$front_header = get_theme_mod('front_header_type' ,'image');
    	$site_header = get_theme_mod('site_header_type', 'nothing');
    	global $post;
    	if ( !is_404() || !is_search() ) {
    		if ( is_singular() ) {
    	$single_toggle = get_post_meta( $post->ID, '_astrid_single_header_shortcode', true );
    }
    	} else {
    		$single_toggle = false;
    	}
    
    	if ($single_toggle != '') {
    		return 'has-single';
    	} else {
    		if ( get_header_image() && ( $front_header == 'image' && is_front_page() ) || ( $site_header == 'image' && !is_front_page() ) ) {
    			return 'has-header';
    		} elseif ( ($front_header == 'shortcode' && is_front_page()) || ($site_header == 'shortcode' && !is_front_page()) ) {
    			return 'has-shortcode';
    		} elseif ( ($front_header == 'video' && is_front_page()) || ($site_header == 'video' && !is_front_page()) ) {
    			return 'has-video';
    		}		
    	}
    }

    Hope that helps.

    Regards,
    Kharis

    Thread Starter grafis

    (@snackmaster)

    @kharisblank – Thank you! That worked perfectly!

    You’re welcome @snackmaster!

    Please let us know in a new topic if you have any further questions, or if we can provide you with any other assistance.

    Regards,
    Kharis

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘PHP Warning Errors – functions.php line 269’ is closed to new replies.