• Resolved ewd910

    (@ewd910)


    Hi, we’ve been using the wp_dropdown_users_args as a filter to add users to the dropdown based on user role in order to assign blog posts to them. However, it seems that that filter is being skipped and only admins are appearing in the dropdown. This is true for both the page builder and the quick edit function. Is this a bug in wordpress or is there a new way of doing this? Thanks in advance. Below is the code we were using, but the function is no longer being called at all

    add_action('wp_dropdown_users_args', 'filter_authors');
    function filter_authors($args)
    {
    if (isset($args['who'])) {
    $args['role__in'] = ['administrator', 'employee', 'blog_author'];
    unset($args['who']);
    }
    return $args;
    }
Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator bcworkz

    (@bcworkz)

    The filter still fires. I think what is different is “who” is no longer set, so your “role_in” assignment never executes. I don’t have the same roles on my site, but I can manage which of my roles are listed with something similar to your code with the if() conditional commented out.

    Thread Starter ewd910

    (@ewd910)

    Strange, I tried what you suggested and it’s not doing anything differently. Another thing to note is the author field is missing from quick edit, and the author dropdown takes slightly longer to load than the other elements on the page edit. So I’m thinking there may be a plugin I have installed that’s interfering somehow

    Edit: Tried this again with the default theme and all plugins disabled and it’s still doing the same thing. Also put a breakpoint in wp-user.php wp_dropdown_users function and it was never reached. Really seems like that filter isn’t being called and I’m not sure why

    • This reply was modified 1 year, 6 months ago by ewd910.
    Moderator bcworkz

    (@bcworkz)

    My test site is now v6.2.1, it was 6.2 for my previous test. The following works for me with 2023 theme and no plugins but for my test plugin which contains this code, but all other plugin code is currently non-operational:

    add_action('wp_dropdown_users_args', 'filter_authors');
    function filter_authors($args)
    {
    $args['role__in'] = ['administrator', 'editor', 'author'];
    var_dump($args);
    return $args;
    }

    The dump was:

    array (size=12)
      'blog_id' => int 1
      'include' => string '' (length=0)
      'exclude' => string '' (length=0)
      'orderby' => string 'display_name' (length=12)
      'order' => string 'ASC' (length=3)
      'who' => string '' (length=0)
      'role' => string '' (length=0)
      'role__in' => 
        array (size=3)
          0 => string 'administrator' (length=13)
          1 => string 'editor' (length=6)
          2 => string 'author' (length=6)
      'role__not_in' => 
        array (size=0)
          empty
      'capability' => 
        array (size=1)
          0 => string 'edit_posts' (length=10)
      'capability__in' => 
        array (size=0)
          empty
      'capability__not_in' => 
        array (size=0)
          empty
      'fields' => 
        array (size=3)
          0 => string 'ID' (length=2)
          1 => string 'user_login' (length=10)
          2 => string 'display_name' (length=12)

    If you’ve customized roles, perhaps the default “capability” arg could have an impact? But I don’t know why a breakpoint wouldn’t fire, the var_dump certainly did, at least for me.

    Thread Starter ewd910

    (@ewd910)

    Seems like wherever react is getting “coreData” from (to populate the author comboBox) is not causing the hooks to be fired. That’s as far as I’ve been able to trace it so far, I don’t know what call it makes to the server to get that data

    • This reply was modified 1 year, 6 months ago by ewd910.
    Moderator bcworkz

    (@bcworkz)

    React? Oh! You’re not testing via quick edit then. …re-reads OP… The filter does work for quick edit. I cannot speak to other page builder plugins. If by “page builder” you mean the block editor (Gutenberg), it does not call the wp_dropdown_users() function, it gets the users via API request. There may be a better way to alter API responses from the /user route, but the ‘rest_pre_echo_response’ filter can be used in general on any request. Set and unset data array elements as desired. If it’s important to alter the query and not results, try ‘pre_get_users’ action (untested).

    Thread Starter ewd910

    (@ewd910)

    I’m testing with both, it doesn’t work for quick edit either. In fact, quick edit doesn’t even have an authors dropdown. Only place I can get the filter to work is in the classic editor. I will try that rest_pre_echo_response if all else fails but there’s definitely something strange going on here

    • This reply was modified 1 year, 6 months ago by ewd910.
    Thread Starter ewd910

    (@ewd910)

    Figured it out, thanks to Google bard.

    add_filter( 'wp_is_large_user_count', '__return_false' );

    My website has a large number of users, and even though the vast majority get filtered out of the dropdown I have to disable the “wp_is_large_user_count” check.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘wp_dropdown_users_args filter no longer being called’ is closed to new replies.