Untitled

 avatar
unknown
plain_text
9 months ago
3.3 kB
2
Indexable
function is_agent($user_id){
	$agent_group = get_user_meta($user_id,'salesking_group',true);
	if ($agent_group !== 'none' && !empty($agent_group)){
		return true;
	} else {
		return false;
	}
}

add_filter('b2bking_offer_type_args', function($args){

    $args['capability_type'] = 'b2bking_offer';
    $args['capabilities'] = array(
        'edit_post'          => 'edit_b2bking_offer',
        'read_post'          => 'read_b2bking_offer',
        'delete_post'        => 'delete_b2bking_offer',
        'edit_posts'         => 'edit_b2bking_offers',
        'edit_others_posts'  => 'edit_others_b2bking_offers',
        'publish_posts'      => 'publish_b2bking_offers',
        'read_private_posts' => 'read_private_b2bking_offers',
    );

	return $args;
	
}, 10, 1);

add_action('admin_head', function(){
	$user_id = get_current_user_id();

	if (is_agent($user_id)){
		?>
		<style type="text/css">
			#toplevel_page_b2bking{
				display:block !important;
			}
			#toplevel_page_salesking, a[href="admin.php?page=b2bking_groups"], a[href="admin.php?page=b2bking_dashboard"], a[href="admin.php?page=b2bking_customers"], a[href="admin.php?page=b2bking_reports"], a[href="admin.php?page=b2bking_tools"], a[href="admin.php?page=wc-settings"], a[href="admin.php?page=wc-status"], a[href="admin.php?page=b2bking"], a[href="edit.php?post_type=b2bking_grule"], a[href="edit.php?post_type=b2bking_conversation"], a[href="edit.php?post_type=b2bking_rule"], a[href="edit.php?post_type=b2bking_custom_role"], a[href="edit.php?post_type=b2bking_custom_field"], a[href="woocommerce-marketing"], #wp-admin-bar-root-default, .woocommerce-message, .is-dismissible{
				display:none !important;
			}
		</style>
		<?php
	}

});
add_filter( 'user_has_cap',  'agents_caps_manage_orders', 10000000, 3 );
function agents_caps_manage_orders( $allcaps, $caps, $args ){

	$continue = false;
	if (isset($_GET['post_type'])){
		if ($_GET['post_type'] === 'b2bking_offer'){
			$continue = true;
		}
	}
	if (isset($_GET['post'])){
		if (get_post_type($_GET['post']) === 'b2bking_offer'){
			$continue = true;
		}
	}
	
	if ($continue){
		$caps = array('manage_woocommerce', 'edit_products', 'publish_products', 'read_private_products', 'edit_others_products', 'create_posts', 'edit_posts', 'publish_posts', 'edit_published_posts', 'edit_private_posts', 'edit_private_products', 'edit_others_posts', 'read_private_posts', 'edit_b2bking_offer', 'read_b2bking_offer', 'delete_b2bking_offer', 'edit_b2bking_offers', 'edit_others_b2bking_offers', 'publish_b2bking_offers', 'read_private_b2bking_offers', 'edit_product', 'edit_product_terms', 'edit_published_products', 'manage_product_terms', 'read_product', 'delete_published_products', 'delete_products', 'delete_product', 'delete_product_terms', 'delete_private_products', 'delete_others_products', 'assign_product_terms');

		foreach ($caps as $cap){
			$allcaps[$cap] = 1;
		}
	}

	return $allcaps;
}

add_action('salesking_extend_menu', function($menu){
	?>
	<li class="nk-menu-item">
		<a href="<?php echo admin_url('edit.php?post_type=b2bking_offer');?>" class="nk-menu-link">
			<span class="nk-menu-icon"><em class="icon ni ni-tag-fill"></em></span>
			<span class="nk-menu-text">Offers</span>
		</a>
	</li><!-- .nk-menu-item -->
	<?php
}, 10, 1);
Editor is loading...
Leave a Comment