Batch Create not creating users that show up for other plugins

We tried using batch create to add users simultaneously to multiple subsites on a multisite install (directory-based multisite).
When looking in the WP Users list, they show up, but other plugins cannot see them. e.g. when wanting to add users to a forum using Simple Press forums, the newly added users are not visible. SP says this is because the plugin likely bypasses the usual standard WP user add process and so the users are not universally visible.
Is it possible to configure / patch / get an update to Batch Create so it complies with WP standards when creating users? Otherwise, it is not very useful.

  • Vaughan

    Hi bdienes

    Hope you're well?

    I'm not sure what you mean, the plugin should be using wordpress standards, if the users appear in the Users list of the subsite then they are added to the site or they would not be visible in that list.

    The plugin uses the following wp functions:

    wp_create_user()
    add_user_to_blog()

    Could you grant support access from the dashboard plugin, so we can take a closer look? See https://premium.wpmudev.org/manuals/wpmu-dev-dashboard-enabling-staff-login/

    Thanks

  • bdienes

    We created user glentest11 using your plugin
    We created glentest12 using the normal WP user creation process from the WP dashboard
    (Both were added to the Business subsite)
    Both of them show as users on the Business subsite.
    Only glentest12 shows up as a user in the Simple Press forum users on the Business subsite
    So clearly, the plugin is adding users in a different way from the WP standard.
    I have given you access. Don't do anything drastic....

  • Vaughan

    Hi,

    I've been trying to figure this out for a while now, i'm almost sure this is not something wrong with our plugin.

    I will certainly pass this to our SLS developers to look into, but i'm sure they will say the same, however I could certainly be wrong, and if I am, my apologies in advance.

    Hopefully they should respond shortly, but it could take a little longer than usual depending on their workload.

    Thanks

  • Ash

    Hello bdienes

    Please add the following code in your themes functions.php:

    add_action( 'add_user_to_blog', 'wpmu_sp_create_member_data', 99, 3 );
    function wpmu_sp_create_member_data( $user_id, $role, $blog_id )
    {
        require_once WP_PLUGIN_DIR . '/simple-press/sp-control.php';
        require_once WP_PLUGIN_DIR . '/simple-press/sp-api/sp-api-wpdb.php';
        require_once WP_PLUGIN_DIR . '/simple-press/sp-api/sp-api-users.php';
    
        sp_create_member_data( $user_id );
    }

    It has to be in that subsite theme where you have simple press activated and adding users to.

    This is highly recommended to use a child theme in this case, as the changes will be lost when you will update the theme. You can learn more about child theme here: http://codex.wordpress.org/Child_Themes

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

  • Vaughan

    Hi,

    Was just thinking, if you have the same theme used on all subsites, this will give an error if batch create is used to add users to a subsite where simplepress isn't activated.

    So, we can first check if simplepress is active by instead using the below code.

    add_action( 'add_user_to_blog', 'wpmu_sp_create_member_data', 99, 3 );
    function wpmu_sp_create_member_data( $user_id, $role, $blog_id )
    {
        switch_to_blog($blog_id);
        if(is_admin() && is_plugin_active('simple-press/sp-control.php') {
            require_once WP_PLUGIN_DIR . '/simple-press/sp-control.php';
            require_once WP_PLUGIN_DIR . '/simple-press/sp-api/sp-api-wpdb.php';
            require_once WP_PLUGIN_DIR . '/simple-press/sp-api/sp-api-users.php';
    
            sp_create_member_data( $user_id );
        }
        restore_current_blog();
    }

    Now that function will only work when adding users to blogs where simplepress is activated.

    Hope this helps

  • bdienes

    Tried that code, but no joy...
    Here's what I got from the Simple-Press folks:

    WordPress communicates via a system of program ‘hooks’ – which I always suggest people think of as a messaging system. This system informs plugins of actions and events that are taking place so that plugins can respond accordingly.
    When a plugin is written that takes over a normal. core WP function, then it is imperative that it also uses the same hooks to inform plugins of the usual events. My initial guess is that your member creation plugin is not doing this.
    For reference and so you can go back to the authors and ask them this question – these are the hooks that WordPress actions and that Simple:stuck_out_tongue:ress responds to:
    View Raw Code
    1 add_action('wpmu_new_user', 'sp_create_member_data', 99);
    2 add_action('wpmu_activate_user', 'sp_create_member_data', 99);
    3 add_action('added_existing_user', 'sp_create_member_data', 99);
    4 add_action('wpmu_delete_user', 'sp_delete_member_data');
    5 add_action('remove_user_from_blog', 'sp_delete_member_data', 10, 2);
    6 add_action('user_register', 'sp_create_member_data', 99);
    7 add_action('delete_user', 'sp_delete_member_data');
    8 add_action('profile_update', 'sp_update_member_data');
    9 add_action('set_user_role', 'sp_map_role_to_ug', 10, 2);
    10 add_action('add_user_role', 'sp_map_role_to_ug', 10, 2);
    11 add_action('delete_user_form', 'sp_delete_user_form', 10, 2);
    These show the hook (left argument) and the SP function that is invoked when a hook is called (right argument)

    Does that help to know how to patch Batch Create to make it compliant with other plugins?

  • Ash

    Hello bdienes

    Would you please use just the following code:

    add_action( 'add_user_to_blog', 'wpmu_sp_create_member_data', 99, 3 );
    function wpmu_sp_create_member_data( $user_id, $role, $blog_id )
    {
        require_once WP_PLUGIN_DIR . '/simple-press/sp-control.php';
        require_once WP_PLUGIN_DIR . '/simple-press/sp-api/sp-api-wpdb.php';
        require_once WP_PLUGIN_DIR . '/simple-press/sp-api/sp-api-users.php';
    
        sp_create_member_data( $user_id );
    }

    Please remove Vaughan's code and try the above one.

    Have a good day!

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.