WordPress.org

Ready to get started?Download WordPress

Forums

Edit Flow
[resolved] Retrieve Users in Usergroup (10 posts)

  1. CoastalP47
    Member
    Posted 1 year ago #

    I have a plugin for a client that uses Edit Flow and Formidable to accept documents for review and organizes/assigns them using Edit Flow. The plugin intercepts a "submit" command by a particular Formidable form and sets that particular post in the form as "expedited". That part works, no problem at all. The problem is that the client wants one of their usergroups to be notified when this happens. I've been hitting my head with this for a while and cannot come to a solution at all.

    Is there a way to get the users in a user group for me to run a foreach loop to send a batch of emails?

    http://wordpress.org/extend/plugins/edit-flow/

  2. thomask
    Member
    Posted 1 year ago #

    if you would be using standard WP roles, not user groups, you could use those functions (imo self explanatory):

    function get_users_with_role( $role ) {
    $wp_user_search = new WP_User_Search( '', '', $role );
    return $wp_user_search->get_results();
    }

    function mail_users_with_role( $role,$subject, $message ) {
    $users = (get_users_with_role($role));
    foreach ($users as $user) {
    wp_mail($user->user_email,$subject,$message);
    }
    }

    for EF roles i do not know, as i do not know what are they using for storing EF group to user - i guess it will be user_meta, so you can just slightly modify the WP_User_Search to search not by role, but using meta (see http://codex.wordpress.org/Class_Reference/WP_User_Query)

  3. thomask
    Member
    Posted 1 year ago #

    so just for claryfing that second row - you need to find what key is used in ef for storing user group (if it is in usermeta), let's call it some_ef_role_key and you need to know id of the role, lets call it $ef_role_id:
    $wp_user_search = new WP_User_Query( array('meta_key' => 'some_ef_role_key', 'meta_value' => $ef_role_id) );

  4. CoastalP47
    Member
    Posted 1 year ago #

    The usergroup isn't located in usermeta, I went there first. The usergroup is saved in a separate table with a key of "description" and a value of "{"description":"","user_ids":["1","3"]}" for example. I just need to be able to pull the id's from that array or use some built in Edit Flow function to get those users.

  5. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    There's a get_usergroups_for_user() method you can use on the $editflow->user_groups object.

  6. thomask
    Member
    Posted 1 year ago #

    is there any reason why don't you use built-in tables? this is a typical user meta information

  7. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    You can also use get_usergroup_by() to retrieve a given user group, and $users will be a key on the object.

  8. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    @thomask we refactored a bit to get it work on WordPress.com VIP, and in that context it's better to store outside the user meta table. Also, the lookups are more often seeing which users are in a user group, rather than which user groups a user has, so it's a better lookup.

  9. CoastalP47
    Member
    Posted 1 year ago #

    Could you explain how to use that, Daniel? I'd greatly appreciate it. A small example of how to pull the $users from the output?

  10. thomask
    Member
    Posted 1 year ago #

    thank you - please could you look at http://wordpress.org/support/topic/plugin-edit-flow-some-transition_post_status-action?replies=2#post-3248739 and confirm, that your code does not work so that i do not try to find out?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags