How to check current user before all actions and filters?
Question
I am working on a plugin with 50+ actions and filters. All actions and filters only apply to users with a specific user meta (b2b). I want to check this user meta before everything How can I do this? A simple check like get_current_user_id DOES NOT WORK before init.
I also don’t want to check this inside very single action and filter function, that seems very very inefficient.
function __construct() {
// This function user check will not work. What can I do?
if ($this->is_user_b2b()){
// Add conversations to My account WooCommerce user menu
add_filter( 'woocommerce_account_menu_items', array($this, 'b2bking_my_account_add_conversations'), 10, 1 );
// Add conversations endpoint
add_action( 'init', array($this, 'b2bking_conversations_endpoint') );
// Add content to endpoint
add_action( 'woocommerce_account_conversations_endpoint', array($this, 'b2bking_conversations_endpoint_content') );
// Add content to individual conversation endpoint
add_action( 'woocommerce_account_conversation_endpoint', array($this, 'b2bking_conversation_endpoint_content') );
/* 50 MORE ACTIONS AND FILTERS */
0
actions, filters, plugin-development, plugins, woocommerce
3 years
2020-03-30T16:51:54-05:00
2020-03-30T16:51:54-05:00 0 Answers
110 views
0
Leave an answer