PHP 8 Incompatibility

Hello!
When I updated PHP from 7.4 to 8.0 (or 8.1) my website doesn’t show any content, only the header. When switching back to 7.4 everything works as expected but just seems to be fairly slow to load. I was hoping upgrading to PHP 8 would help speed things up a little. Any tips on resolving this?

I have no issues with 8,1 running taskhive + extra extensions.

What is your setup?

Try to disable third party plugins first.

I am running rentalhive with some customizations and third party plugins. I will disable other plugins and try!

The plugin causing the issue is Code Snippets. How can I fix this??

Probably will have to wait for an update to code snippet

Okay, thank you!

There are a few deprecation notices if you have WP_DEBUG enabled, but no actual known issues (we’ll fix notices in the upcoming updates). Please share recent entries from the PHP error log, this way it’s possible to check which snippet causes this issue.

I found which snippet is causing the issue. I was using this snippet to hide the “Create a Listing” button in the header from regular users so only the vendors would be able to create listings. Is there another way to do this??

add_filter(
    'hivepress/v1/templates/site_header_block',
    function( $template ) {
		
		if(is_user_logged_in()){
			if(hivepress()->get_version('memberships')){
				$membership = \HivePress\Models\Membership::query()->filter(['user' => get_current_user_id()])->get_first();

        		if(!$membership || your_membership_plan_id === $membership->get_plan__id()){
            		$template = hivepress()->helper->merge_trees(
						$template,
						[
							'blocks' => [
								'listing_submit_link' => [
									'type' => 'content',
								],
							],
						]
					);
        		}
    		}
		}else{
			$template = hivepress()->helper->merge_trees(
				$template,
				[
					'blocks' => [
						'listing_submit_link' => [
							'type' => 'content',
						],
					],
				]
			);
		}

    return $template;
    },
    1000
);

The snippet seems to be ok, but make sure that you replaced this part with an ID:

your_membership_plan_id

Otherwise the snippet will cause a fatal PHP error with any PHP version.

Where can I find the plan IDs?

Please edit any plan in Memberships/Plans, the ID should be displayed in the browser address bar, something like “…post=123…”.

The plan ID is post=551, How can I implement this in the snippet?? I tried to replace it in the your_membership_plan_id
spot, but it triggered a fatal error.
I am just using the membership as a way to block regular users from seeing the “Create a Listing” button.

If the plan ID is equal to 551 then please try this PHP snippet

add_filter(
    'hivepress/v1/templates/site_header_block',
    function( $template ) {
		
		if(is_user_logged_in()){
			if(hivepress()->get_version('memberships')){
				$membership = \HivePress\Models\Membership::query()->filter(['user' => get_current_user_id()])->get_first();

        		if(!$membership || 551 === $membership->get_plan__id()){
            		$template = hivepress()->helper->merge_trees(
						$template,
						[
							'blocks' => [
								'listing_submit_link' => [
									'type' => 'content',
								],
							],
						]
					);
        		}
    		}
		}else{
			$template = hivepress()->helper->merge_trees(
				$template,
				[
					'blocks' => [
						'listing_submit_link' => [
							'type' => 'content',
						],
					],
				]
			);
		}

    return $template;
    },
    1000
);
1 Like