Can we access the REST request parameters from within the permission_callback to enforce a 401 by returning false?

I’ve created a reduced test case that demonstrates that what you want to do is achievable: add_action( ‘rest_api_init’, function() { register_rest_route( ‘wpse/343039’, ‘route’, [ ‘methods’ => [ ‘POST’ ], ‘permission_callback’ => function( WP_REST_Request $request ) { if ( ‘1’ == $request->get_param( ‘param’ ) ) { return true; } else { return false; } }, ‘callback’ … Read more

Reference external file as a function

You can’t. Create a function that loads that file: function load_admin_page_file() { require ‘admin-members.php’; } Then use that function name as callback argument. In PHP 5.3 you can use a lambda: add_menu_page( ‘Members’, ‘Members’, ‘manage_options’, ‘members’, function() { require ‘admin-members.php’; } );

How to Override default update_count_callback for category

In your update_count_callback function do a check for $post->post_status and don’t increment your count if post_status is not private. See this excellent answer on writing a custom update_count_callback callback function. Edit: Misread the question. To override the existing default for the category taxonomy you can create a function that overrides the global $wp_taxonomies variable function … Read more

Extend Woocommerce rest api routes fails

What if in your register_rest_route() call you can pass it the permission_callback option: ‘permission_callback’ => function () { return current_user_can(‘customer’); // OR return current_user_can(‘shop_manager’); } That way you are sure that you are dealing with a logged in Woocommerce user?? These are the two roles that Woocommerce is adding to your site. https://docs.woocommerce.com/document/roles-capabilities/ I know … Read more

Is it possible to create an action hook using do_action() within add_action()?

Creating an answer based upon responses via comments on original question of: Is it possible to create an action hook using do_action() within add_action()? Yes it is possible to create an action hook using do_action() on a call to add_action(). For clarification, the following code does NOT work: add_action(‘init’, do_action(‘my-hook-name’)); As stated by @IvanHanák in … Read more

Update term count using a callback function

I think I’ve worked this out. First of all, you need to define your taxonomy. I’m pulling this code directly from the codex; however, I’ve added one parameter update_count_callback. I’ve set this to the cleverly titled my_update_count_callback. This just specifies that when a post of type post (this will be whatever CPTs you associate the … Read more

How to get control choices from $setting object passed to sanitize_callback

This is correct: $control = $setting->manager->get_control($setting->id); $choices = $control->choices; However, in your example, $setting->id will be theme_oenology_options[name]. So, get_control(‘theme_oenology_options[name]’) will return null because there’s no control with that name. You gave the control the id of oenology_name instead. I always give the same ID to settings and their matching controls for that reason.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)