remove_action conditionally for Custom Post Type

Query variable only can be accessed after wp_query has been called. In you call, the get_post_type() function is actually returning an empty value. It should be working, if you change the hook to something which fires after wp_query is called. So, You should use – add_action(‘wp’, ‘kiwi_remove_post_author_box’); OR add_action(‘template_redirect’, ‘kiwi_remove_post_author_box’); Also, hooks can removed with … Read more

Nav menu items disappearing (but not immediately)

Log queries As the question says “it doesn’t happen always”, it’s hard to tell what’s really going on. When you can’t see what happens (query in background) and don’t know when it happens, then it’s best to log it. The logger On activation, the plugin will try to create a log directory named ‘nav_log’ in … Read more

Edit postmeta when user changes user role?

Well, you’re not entirely correct. This code will run, when the action called basic will be called using do_action(‘basic’, …). But… There is no such action in WP core, so your code won’t run at all, I’m afraid. There is hook that might be helpful in your case. It’s called set_user_role and it has 3 … Read more

Create subpage /user/ or /my-profile/ like /author/ with additional query like /user/user123

If I understand you well, you can do that with add_rewrite_rule(); function to map the url to specific query variables. https://codex.wordpress.org/Rewrite_API/add_rewrite_rule function myfunc_rewrite_rules() { add_rewrite_rule(‘user/?([^/]*)’, ‘index.php?pagename=user&username=$matches[1]’, ‘top’); } function myfunc_username_query_vars($vars) { $vars[] = ‘username’; return $vars; } add_action(‘init’, ‘myfunc_rewrite_rules’); //add query vars (username) to wordpress add_filter(‘query_vars’, ‘myfunc_username_query_vars’); function myfunc_display() { $userpage = get_query_var(‘pagename’); $username = … Read more

How to get input_attrs in the sanitize function?

Your control is named custom_num but your setting is named my_custom_num. Modify your setting’s sanitize function to use the former: $input_attrs = $setting->manager->get_control( ‘custom_num’ )->input_attrs; See also the Customize Input Validity Constraints plugin, where you can see how to obtain the control for a given setting without having to hard-code it: $controls = array(); foreach … Read more