Restrict Add Listing button to vendors only

Hello! I found another thread on this topic, but the snippet caused a critical error on my site. Is there another way that only my vendors can see the Create a Listing button??

Please send a link to a topic with a suggested snippet, if it was a 2-part snippet please make sure that you added the CSS one to Additional CSS and the PHP one via the Code Snippets plugin. Please note that if you have direct vendor registration disabled, you’d have to add vendors manually because by default users become vendors by adding listings.

Yes, I plan to add vendors manually because the field I am creating this site in must have licensed vendors. The snippet I used is linked below. It was working fine before I switched to GoDaddy hosting.

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
);
1 Like

If it is possible please share the error message which you get

The code snippet was tested locally and it seems to be ok

I figured it out, when I switched over the GoDaddy it was having the site use PHP 8.1, I had to revert to PHP 7.4 to make it function! Thank you!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.