WordPress.org

Make WordPress Core

Opened 18 months ago

Last modified 15 months ago

#35428 new enhancement

Allow the suppression of errors if user already exists

Reported by: pbearne Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Login and Registration Keywords: reporter-feedback
Focuses: multisite Cc:

Description

The install instructions for s2members requires that we add a filter to suppress errors
it seems to be we should add the filter to allow this.

Attachments (3)

ms-functions.php.patch (945 bytes) - added by pbearne 18 months ago.
patch
ms-functions.php.2.patch (2.5 KB) - added by pbearne 18 months ago.
moved filter to the setting of $user_already_exists
ms-functions.php.3.patch (870 bytes) - added by pbearne 18 months ago.
removed extra whitespace changes and fix format

Download all attachments as: .zip

Change History (12)

@pbearne
18 months ago

patch

#1 @pbearne
18 months ago

  • Keywords has-patch needs-codex dev-feedback added

#2 follow-up: @ericlewis
18 months ago

This error is helpful feedback, and could break backwards compatibility with other code that expects the error when this happens.

Why is it useful for the plugin want to suppress the error?

#3 @swissspidy
18 months ago

  • Focuses multisite added
  • Keywords needs-codex removed
  • Summary changed from allow the suppression of errors if user already exists. on mulit sites to Allow the suppression of errors if user already exists

Apart from the usefulness of this, I'd rather add a filter for $user_already_exists instead of the WP_Error.

@pbearne
18 months ago

moved filter to the setting of $user_already_exists

#4 @pbearne
18 months ago

related patches

#35422
only exit if the redirect is true when registering on multisites
#35427
add filter on the wpmu_signup_user() meta values in user-new
#35428
Allow the suppression of errors if user already exists
#35443
Allow selective plugins to load for wp-activate.php


Last edited 17 months ago by SergeyBiryukov (previous) (diff)

@pbearne
18 months ago

removed extra whitespace changes and fix format

#5 in reply to: ↑ 2 @jeremyfelt
17 months ago

  • Keywords reporter-feedback added; has-patch dev-feedback removed

Replying to ericlewis:

Why is it useful for the plugin want to suppress the error?

I think this question needs to be answered before we know the right way to approach this.

#6 @pbearne
17 months ago

I will try to find way

#7 @pbearne
17 months ago

Below is the code in S2 member that would be called for this filter

from quick read it seems to add an existing User

I hope this help understand why the filter is needed

<?php
/**
 * Intersects with ``wpmu_activate_signup()`` through s2Member's Multisite Networking patch.
 *
 * This function should return the same array that `wpmu_activate_signup()` returns; with the assumption that ``$user_already_exists``.
 *   Which is exactly where this function intersects inside the `/wp-includes/ms-functions.php`.
 *
 * This can ONLY be fired through `/wp-activate.php` on the front-side.
 *   Or through `/activate` via BuddyPress.
 *
 * @package s2Member\Registrations
 * @since 3.5
 *
 * @attaches-to ``add_filter('_wpmu_activate_existing_error_');``
 *
 * @param WP_Error $_error Expects a `WP_Error` object to be passed through by the Filter.
 * @param array    $vars Expects the defined variables from the scope of the calling Filter.
 *
 * @return WP_Error|array If unable to add an existing User, the original ``$_error`` obj is returned.
 *   Otherwise we return an array of User details for continued processing by the caller.
 */
public static function ms_activate_existing_user($_error = NULL, $vars = array())
{
        foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v;
        do_action('ws_plugin__s2member_before_ms_activate_existing_user', get_defined_vars());
        unset($__refs, $__v); // Housekeeping.

        extract($vars); // Extract all variables from ``wpmu_activate_signup()`` function.

        $ci = $GLOBALS['WS_PLUGIN__']['s2member']['o']['ruris_case_sensitive'] ? '' : 'i';

        if(is_multisite()) // This event should ONLY be processed with Multisite Networking.
                if(!is_admin() && ((preg_match('/\/wp-activate\.php/'.$ci, $_SERVER['REQUEST_URI'])) || (c_ws_plugin__s2member_utils_conds::bp_is_installed() && bp_is_activation_page())))
                {
                        if(!empty($user_id) && !empty($user_login) && !empty($user_email) && !empty($password) && !empty($meta) && !empty($meta['add_to_blog']) && !empty($meta['new_role']))
                                if(!empty($user_already_exists) && c_ws_plugin__s2member_utils_users::ms_user_login_email_exists_but_not_on_blog($user_login, $user_email, $meta['add_to_blog']))
                                {
                                        add_user_to_blog($meta['add_to_blog'], $user_id, $meta['new_role']); // Add this User to the specified Blog.
                                        wp_update_user(wp_slash(array('ID' => $user_id, 'user_pass' => $password))); // Update Password so it's the same as in the following msg.
                                        wpmu_welcome_user_notification($user_id, $password, $meta); // Send welcome letter via email just like ``wpmu_activate_signup()`` does.

                                        do_action('wpmu_activate_user', $user_id, $password, $meta); // Process Hook that would have been fired inside ``wpmu_activate_signup()``.

                                        return apply_filters('ws_plugin__s2member_ms_activate_existing_user', array('user_id' => $user_id, 'password' => $password, 'meta' => $meta), get_defined_vars());
                                }
                }
        return apply_filters('ws_plugin__s2member_ms_activate_existing_user', $_error, get_defined_vars()); // Else, return the standardized error.
}

This ticket was mentioned in Slack in #core by chriscct7. View the logs.


17 months ago

#9 @chriscct7
15 months ago

  • Version trunk deleted
Note: See TracTickets for help on using tickets.