function include_professors() { $admin_id = get_user_id_from_string(get_blog_option($current_blog->blog_id, 'admin_email')); $blog_major = get_user_major(); //get_the_user_major($admin_id); //var_dump($blog_major); if ($GLOBALS['blog_id'] != 1) { //makes sure it's not the root blog $args = array('blog_id' => 1, 'role' => 'professor'); $professors = get_users($args); //get all profs from root blog //loop through profs, add as user if same major, delete if different major foreach ($professors as $professor) { $prof_major = get_the_user_major($professor->ID); //var_dump($prof_major); if ($prof_major == $blog_major) { $current_role = get_the_user_role($professor); if ($current_role != 'Administrator') { $result = add_existing_user_to_blog(array('user_id' => $professor->ID, 'role' => 'professor')); } } else { $result = remove_user_from_blog($professor->ID, $current_blog->blog_id); } } } //end if }
/** * @ticket 38355 */ public function test_get_active_blog_for_user_with_no_sites() { $current_site_id = get_current_blog_id(); remove_user_from_blog(self::$user_id, $current_site_id); $result = get_active_blog_for_user(self::$user_id); $this->assertNull($result); }
/** * Removes a user from the current site. * @param int $user_id * @return array|WP_Error */ function remove_user($user_id) { if (!current_user_can('remove_users')) { return new WP_Error('unauthorized', 'User cannot remove users for specified site.', 403); } if (!is_user_member_of_blog($user_id, get_current_blog_id())) { return new WP_Error('invalid_input', 'User is not a member of the specified site.', 400); } return array('success' => remove_user_from_blog($user_id, get_current_blog_id())); }
/** * On author pages, the queried object should only be set * to a user that's not a member of the blog if they * have at least one published post. This matches core behavior. * * @see https://core.trac.wordpress.org/changeset/27290 */ function test_author_queried_object_fix() { global $wp_rewrite, $coauthors_plus; /** * Set up */ $author1 = $this->factory->user->create(array('user_login' => 'msauthor1')); $author2 = $this->factory->user->create(array('user_login' => 'msauthor2')); $blog2 = $this->factory->blog->create(array('user_id' => $author1)); switch_to_blog($blog2); $wp_rewrite->init(); $blog2_post1 = $this->factory->post->create(array('post_status' => 'publish', 'post_content' => rand_str(), 'post_title' => rand_str(), 'post_author' => $author1)); /** * Author 1 is an author on the blog */ $this->go_to(get_author_posts_url($author1)); $this->assertQueryTrue('is_author', 'is_archive'); /** * Author 2 is not yet an author on the blog */ $this->go_to(get_author_posts_url($author2)); $this->assertQueryTrue('is_404'); // Add the user to the blog add_user_to_blog($blog2, $author2, 'author'); /** * Author 2 is now on the blog, but not yet published */ $this->go_to(get_author_posts_url($author2)); $this->assertQueryTrue('is_author', 'is_archive'); // Add the user as an author on the original post $author2_obj = get_user_by('id', $author2); $coauthors_plus->add_coauthors($blog2_post1, array($author2_obj->user_login), true); /** * Author 2 is now on the blog, and published */ $this->go_to(get_author_posts_url($author2)); $this->assertQueryTrue('is_author', 'is_archive'); // Remove the user from the blog remove_user_from_blog($author2, $blog2); /** * Author 2 was removed from the blog, but still a published author */ $this->go_to(get_author_posts_url($author2)); $this->assertQueryTrue('is_author', 'is_archive'); // Delete the user from the network wpmu_delete_user($author2); /** * Author 2 is no more */ $this->go_to(get_author_posts_url($author2)); $this->assertQueryTrue('is_404'); $this->assertEquals(false, get_user_by('id', $author2)); restore_current_blog(); }
/** * @ticket 39065 */ public function test_get_dashboard_url_for_administrator_of_different_site() { if (!is_multisite()) { $this->markTestSkipped('Test only runs in multisite.'); } $site_id = self::factory()->blog->create(array('user_id' => self::$user_id)); remove_user_from_blog(self::$user_id, get_current_blog_id()); $expected = get_admin_url($site_id); $result = get_dashboard_url(self::$user_id); remove_user_from_blog(self::$user_id, $site_id); add_user_to_blog(get_current_blog_id(), self::$user_id, 'administrator'); wpmu_delete_blog($site_id, true); $this->assertEquals($expected, $result); }
/** * Mods the admin bar */ function thatcamp_clear_boone() { if (is_super_admin() && !empty($_GET['clear_boone'])) { global $wpdb; $blogs = $wpdb->get_results("SELECT blog_id, domain FROM {$wpdb->blogs}"); $boone = $wpdb->get_var("SELECT ID FROM {$wpdb->users} WHERE user_login = '******'"); $boone_camps = array(2, 3, 21, 57, 77, 122); foreach ($blogs as $blog) { if (!in_array($blog->blog_id, $boone_camps)) { remove_user_from_blog($boone, $blog->blog_id); echo $blog->domain . '<br />'; } } } }
function thatcamp_remove_users_from_blog_i() { $blog_id = 168; $users_to_keep = array(852); $users = get_users(array('blog_id' => $blog_id, 'number' => 5, 'fields' => '')); foreach ($users as $user) { if (in_array($user, $users_to_keep)) { // echo 'Keeping ' . $user; } else { // echo 'Dumping ' . $user; remove_user_from_blog($user, $blog_id); // $user_object = new WP_User( $user ); // $user_object->set_role( '' ); } echo '<br />'; } }
function widget_suscribe() { global $wpdb, $current_user; $options = get_option('widget_suscribe'); $before_widget = "<li id='subscribe'>"; $before_title = "<h2>"; $title = empty($options['title']) ? 'Suscríbete a este blog' : $options['title']; $after_title = "</h2>"; $content = ""; $after_widget = "</li>"; //error_log("[widget subscribe] current blog: ". $wpdb->blogid); //error_log("[widget subscribe] current user: "******"[widget subscribe] is blog user"); // User wants to unsubscribe if (isset($_POST['unsuscribe'])) { //error_log("[widget subscribe] POST[unsuscribe]"); remove_user_from_blog($current_user->ID, $wpdb->blogid); $content .= '<p>Te has desuscrito de este blog</p>'; $content .= widget_subscribe_form(); } elseif ($current_user->has_cap('subscriber')) { //error_log("[widget subscribe] has_cap('subscriber')"); $content .= widget_unsubscribe_form(); } elseif ($current_user->has_cap('edit_posts')) { $content .= "<p>Este blog tiene activado el widget de suscripción</p>"; } } else { //error_log("[widget subscribe] not in log"); // User wants to subscribe if (isset($_POST['suscribe'])) { //error_log("[widget subscribe] POST[suscribe]"); add_user_to_blog($wpdb->blogid, $current_user->ID, 'subscriber'); $content .= '<p>Te has suscrito a este blog</p>'; $content .= widget_unsubscribe_form(); } else { //error_log("[widget subscribe] subscribe form"); $content .= widget_subscribe_form(); } } echo $before_widget . $before_title . $title . $after_title . $content . $after_widget; }
/** * @subcommand add-network-users */ public function add_network_users() { global $wpdb; $users = get_users(array('blog_id' => 1)); $blogs = $wpdb->get_results("SELECT * FROM {$wpdb->blogs} where blog_id <> 1"); foreach ($users as $user) { if (empty($user)) { continue; } foreach ($blogs as $blog) { if (empty($blog)) { continue; } foreach ($user->roles as $role) { remove_user_from_blog($user->ID, $blog->blog_id, 1); add_user_to_blog($blog->blog_id, $user->ID, $role); } printf("add user %s to %s\n", $user->user_login, $blog->domain); } } }
/** * Remove user and optionally reassign posts and links to another user. * * If the $reassign parameter is not assigned to an User ID, then all posts will * be deleted of that user. The action 'delete_user' that is passed the User ID * being deleted will be run after the posts are either reassigned or deleted. * The user meta will also be deleted that are for that User ID. * * @since 2.0.0 * * @param int $id User ID. * @param int $reassign Optional. Reassign posts and links to new User ID. * @return bool True when finished. */ function wp_delete_user($id, $reassign = 'novalue') { global $wpdb; $id = (int) $id; $user = new WP_User($id); // allow for transaction statement do_action('delete_user', $id); if ('novalue' === $reassign || null === $reassign) { $post_types_to_delete = array(); foreach (get_post_types(array(), 'objects') as $post_type) { if ($post_type->delete_with_user) { $post_types_to_delete[] = $post_type->name; } elseif (null === $post_type->delete_with_user && post_type_supports($post_type->name, 'author')) { $post_types_to_delete[] = $post_type->name; } } $post_types_to_delete = apply_filters('post_types_to_delete_with_user', $post_types_to_delete, $id); $post_types_to_delete = implode("', '", $post_types_to_delete); $post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_type IN ('{$post_types_to_delete}')", $id)); if ($post_ids) { foreach ($post_ids as $post_id) { wp_delete_post($post_id); } } // Clean links $link_ids = $wpdb->get_col($wpdb->prepare("SELECT link_id FROM {$wpdb->links} WHERE link_owner = %d", $id)); if ($link_ids) { foreach ($link_ids as $link_id) { wp_delete_link($link_id); } } } else { $reassign = (int) $reassign; $wpdb->update($wpdb->posts, array('post_author' => $reassign), array('post_author' => $id)); $wpdb->update($wpdb->links, array('link_owner' => $reassign), array('link_owner' => $id)); } // FINALLY, delete user if (is_multisite()) { remove_user_from_blog($id, get_current_blog_id()); } else { $meta = $wpdb->get_col($wpdb->prepare("SELECT umeta_id FROM {$wpdb->usermeta} WHERE user_id = %d", $id)); foreach ($meta as $mid) { delete_metadata_by_mid('user', $mid); } $wpdb->delete($wpdb->users, array('ID' => $id)); } clean_user_cache($user); // allow for commit transaction do_action('deleted_user', $id); return true; }
function wpmu_delete_user( $id ) { global $wpdb; $id = (int) $id; do_action( 'wpmu_delete_user', $id ); $blogs = get_blogs_of_user( $id ); if ( ! empty( $blogs ) ) { foreach ( $blogs as $blog ) { switch_to_blog( $blog->userblog_id ); remove_user_from_blog( $id, $blog->userblog_id ); $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) ); foreach ( (array) $post_ids as $post_id ) { wp_delete_post( $post_id ); } // Clean links $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) ); if ( $link_ids ) { foreach ( $link_ids as $link_id ) wp_delete_link( $link_id ); } restore_current_blog(); } } $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->users WHERE ID = %d", $id ) ); $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id = %d", $id ) ); clean_user_cache( $id ); // allow for commit transaction do_action( 'deleted_user', $id ); return true; }
break; case 'dodelete': check_admin_referer('ms-users-delete'); if (!(current_user_can('manage_network_users') && current_user_can('delete_users'))) { wp_die(__('You do not have permission to access this page.')); } if (!empty($_POST['blog']) && is_array($_POST['blog'])) { foreach ($_POST['blog'] as $id => $users) { foreach ($users as $blogid => $user_id) { if (!current_user_can('delete_user', $id)) { continue; } if (!empty($_POST['delete']) && 'reassign' == $_POST['delete'][$blogid][$id]) { remove_user_from_blog($id, $blogid, $user_id); } else { remove_user_from_blog($id, $blogid); } } } } $i = 0; if (is_array($_POST['user']) && !empty($_POST['user'])) { foreach ($_POST['user'] as $id) { if (!current_user_can('delete_user', $id)) { continue; } wpmu_delete_user($id); $i++; } } if ($i == 1) {
/** * Add a newly created user to the appropriate blog * * To add a user in general, use add_user_to_blog(). This function * is specifically hooked into the wpmu_activate_user action. * * @since MU * @see add_user_to_blog() * * @param int $user_id * @param mixed $password Ignored. * @param array $meta */ function add_new_user_to_blog($user_id, $password, $meta) { if (!empty($meta['add_to_blog'])) { $blog_id = $meta['add_to_blog']; $role = $meta['new_role']; remove_user_from_blog($user_id, get_current_site()->blog_id); // remove user from main blog. add_user_to_blog($blog_id, $user_id, $role); update_user_meta($user_id, 'primary_blog', $blog_id); } }
} break; case 'remove': if (!current_user_can('remove_users')) { die(__('You can’t remove users.')); } check_admin_referer('bulk-users'); $update = 'remove'; if (isset($_REQUEST['users'])) { $userids = $_REQUEST['users']; foreach ($userids as $user_id) { $user_id = (int) $user_id; remove_user_from_blog($user_id, $id); } } elseif (isset($_GET['user'])) { remove_user_from_blog($_GET['user']); } else { $update = 'err_remove'; } break; case 'promote': check_admin_referer('bulk-users'); $editable_roles = get_editable_roles(); if (empty($editable_roles[$_REQUEST['new_role']])) { wp_die(__('You can’t give users that role.')); } if (isset($_REQUEST['users'])) { $userids = $_REQUEST['users']; $update = 'promote'; foreach ($userids as $user_id) { $user_id = (int) $user_id;
/** * Remove user and optionally reassign posts and links to another user. * * If the $reassign parameter is not assigned to a User ID, then all posts will * be deleted of that user. The action 'delete_user' that is passed the User ID * being deleted will be run after the posts are either reassigned or deleted. * The user meta will also be deleted that are for that User ID. * * @since 2.0.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $id User ID. * @param int $reassign Optional. Reassign posts and links to new User ID. * @return bool True when finished. */ function wp_delete_user($id, $reassign = null) { global $wpdb; if (!is_numeric($id)) { return false; } $id = (int) $id; $user = new WP_User($id); if (!$user->exists()) { return false; } // Normalize $reassign to null or a user ID. 'novalue' was an older default. if ('novalue' === $reassign) { $reassign = null; } elseif (null !== $reassign) { $reassign = (int) $reassign; } /** * Fires immediately before a user is deleted from the database. * * @since 2.0.0 * * @param int $id ID of the user to delete. * @param int|null $reassign ID of the user to reassign posts and links to. * Default null, for no reassignment. */ do_action('delete_user', $id, $reassign); if (null === $reassign) { $post_types_to_delete = array(); foreach (get_post_types(array(), 'objects') as $post_type) { if ($post_type->delete_with_user) { $post_types_to_delete[] = $post_type->name; } elseif (null === $post_type->delete_with_user && post_type_supports($post_type->name, 'author')) { $post_types_to_delete[] = $post_type->name; } } /** * Filter the list of post types to delete with a user. * * @since 3.4.0 * * @param array $post_types_to_delete Post types to delete. * @param int $id User ID. */ $post_types_to_delete = apply_filters('post_types_to_delete_with_user', $post_types_to_delete, $id); $post_types_to_delete = implode("', '", $post_types_to_delete); $post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_type IN ('{$post_types_to_delete}')", $id)); if ($post_ids) { foreach ($post_ids as $post_id) { wp_delete_post($post_id); } } // Clean links $link_ids = $wpdb->get_col($wpdb->prepare("SELECT link_id FROM {$wpdb->links} WHERE link_owner = %d", $id)); if ($link_ids) { foreach ($link_ids as $link_id) { wp_delete_link($link_id); } } } else { $post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d", $id)); $wpdb->update($wpdb->posts, array('post_author' => $reassign), array('post_author' => $id)); if (!empty($post_ids)) { foreach ($post_ids as $post_id) { clean_post_cache($post_id); } } $link_ids = $wpdb->get_col($wpdb->prepare("SELECT link_id FROM {$wpdb->links} WHERE link_owner = %d", $id)); $wpdb->update($wpdb->links, array('link_owner' => $reassign), array('link_owner' => $id)); if (!empty($link_ids)) { foreach ($link_ids as $link_id) { clean_bookmark_cache($link_id); } } } // FINALLY, delete user if (is_multisite()) { remove_user_from_blog($id, get_current_blog_id()); } else { $meta = $wpdb->get_col($wpdb->prepare("SELECT umeta_id FROM {$wpdb->usermeta} WHERE user_id = %d", $id)); foreach ($meta as $mid) { delete_metadata_by_mid('user', $mid); } $wpdb->delete($wpdb->users, array('ID' => $id)); } clean_user_cache($user); /** * Fires immediately after a user is deleted from the database. * * @since 2.9.0 * * @param int $id ID of the deleted user. * @param int|null $reassign ID of the user to reassign posts and links to. * Default null, for no reassignment. */ do_action('deleted_user', $id, $reassign); return true; }
function wpmu_delete_user($id) { global $wpdb; $id = (int) $id; $user = new WP_User($id); do_action('wpmu_delete_user', $id); $blogs = get_blogs_of_user($id); if (!empty($blogs)) { foreach ($blogs as $blog) { switch_to_blog($blog->userblog_id); remove_user_from_blog($id, $blog->userblog_id); $post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d", $id)); foreach ((array) $post_ids as $post_id) { wp_delete_post($post_id); } // Clean links $link_ids = $wpdb->get_col($wpdb->prepare("SELECT link_id FROM {$wpdb->links} WHERE link_owner = %d", $id)); if ($link_ids) { foreach ($link_ids as $link_id) { wp_delete_link($link_id); } } restore_current_blog(); } } $meta = $wpdb->get_col($wpdb->prepare("SELECT umeta_id FROM {$wpdb->usermeta} WHERE user_id = %d", $id)); foreach ($meta as $mid) { delete_metadata_by_mid('user', $mid); } $wpdb->delete($wpdb->users, array('ID' => $id)); clean_user_cache($user); // allow for commit transaction do_action('deleted_user', $id); return true; }
public function test_deletes_users_removed_from_multisite() { if (!is_multisite()) { $this->markTestSkipped('Run it in multi site mode'); } $original_blog_id = get_current_blog_id(); // NOTE this is necessary because WPMU causes certain assumptions about transients // to be wrong, and tests to explode. @see: https://github.com/sheabunge/WordPress/commit/ff4f1bb17095c6af8a0f35ac304f79074f3c3ff6 global $wpdb; $suppress = $wpdb->suppress_errors(); $other_blog_id = wpmu_create_blog('foo.com', '', "My Blog", $this->user_id); $wpdb->suppress_errors($suppress); $other_blog_user_id = $this->factory->user->create(); add_user_to_blog($other_blog_id, $other_blog_user_id, 'administrator'); remove_user_from_blog($other_blog_user_id, $original_blog_id); $this->sender->do_sync(); $this->assertNull($this->server_replica_storage->get_user($other_blog_user_id)); }
/** * Processed by WP_Cron; this handles Auto-EOTs *(EOT = End Of Term)*. * * If you have a HUGE userbase, increase the max EOTs per process. * But NOTE, this runs ``$per_process`` *(per Blog)* on a Multisite Network. * To increase, use: ``add_filter ("ws_plugin__s2member_auto_eot_system_per_process");``. * * This function makes an important Hook available: `ws_plugin__s2member_after_auto_eot_system`. * This Hook is used by some of s2Member Pro's Gateway integrations; allowing CRON processing * to run for important communications; which poll Payment Gateway APIs for possible EOTs. * * @package s2Member\Auto_EOT_System * @since 3.5 * * @param int $per_process Number of database records to process each time. * Can also be Filtered with `ws_plugin__s2member_auto_eot_system_per_process`. * @return null */ public static function auto_eot_system($per_process = 3) { global $wpdb; global $current_site, $current_blog; include_once ABSPATH . "wp-admin/includes/admin.php"; @set_time_limit(0); @ini_set("memory_limit", apply_filters("admin_memory_limit", WP_MAX_MEMORY_LIMIT)); foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action("ws_plugin__s2member_before_auto_eot_system", get_defined_vars()); unset($__refs, $__v); if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["auto_eot_system_enabled"]) { $per_process = apply_filters("ws_plugin__s2member_auto_eot_system_per_process", $per_process, get_defined_vars()); if (is_array($eots = $wpdb->get_results("SELECT `user_id` AS `ID` FROM `" . $wpdb->usermeta . "` WHERE `meta_key` = '" . $wpdb->prefix . "s2member_auto_eot_time' AND `meta_value` != '' AND `meta_value` <= '" . esc_sql(strtotime("now")) . "' LIMIT " . $per_process))) { foreach ($eots as $eot) { if (($user_id = $eot->ID) && is_object($user = new WP_User($user_id)) && $user->ID) { delete_user_option($user_id, "s2member_auto_eot_time"); if (!$user->has_cap("administrator")) { if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_eot_behavior"] === "demote") { $eot_del_type = "auto-eot-cancellation-expiration-demotion"; $custom = get_user_option("s2member_custom", $user_id); $subscr_gateway = get_user_option("s2member_subscr_gateway", $user_id); $subscr_id = get_user_option("s2member_subscr_id", $user_id); $fields = get_user_option("s2member_custom_fields", $user_id); $user_reg_ip = get_user_option("s2member_registration_ip", $user_id); $demotion_role = c_ws_plugin__s2member_option_forces::force_demotion_role("subscriber"); $existing_role = c_ws_plugin__s2member_user_access::user_access_role($user); foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action("ws_plugin__s2member_during_auto_eot_system_during_before_demote", get_defined_vars()); do_action("ws_plugin__s2member_during_collective_mods", $user_id, get_defined_vars(), $eot_del_type, "modification", $demotion_role); do_action("ws_plugin__s2member_during_collective_eots", $user_id, get_defined_vars(), $eot_del_type, "modification"); unset($__refs, $__v); if ($existing_role !== $demotion_role) { $user->set_role($demotion_role); } if (apply_filters("ws_plugin__s2member_remove_ccaps_during_eot_events", (bool) $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["eots_remove_ccaps"], get_defined_vars())) { foreach ($user->allcaps as $cap => $cap_enabled) { if (preg_match("/^access_s2member_ccap_/", $cap)) { $user->remove_cap($ccap = $cap); } } } delete_user_option($user_id, "s2member_custom"); delete_user_option($user_id, "s2member_subscr_id"); delete_user_option($user_id, "s2member_subscr_gateway"); delete_user_option($user_id, "s2member_ipn_signup_vars"); if (!apply_filters("ws_plugin__s2member_preserve_paid_registration_times", true, get_defined_vars())) { delete_user_option($user_id, "s2member_paid_registration_times"); } delete_user_option($user_id, "s2member_last_status_scan"); delete_user_option($user_id, "s2member_first_payment_txn_id"); delete_user_option($user_id, "s2member_last_payment_time"); delete_user_option($user_id, "s2member_auto_eot_time"); delete_user_option($user_id, "s2member_file_download_access_log"); c_ws_plugin__s2member_user_notes::append_user_notes($user_id, "Demoted by s2Member: " . date("D M j, Y g:i a T")); if ($subscr_gateway && $subscr_id) { // Also note the Paid Subscr. Gateway/ID so there is a reference left behind here. c_ws_plugin__s2member_user_notes::append_user_notes($user_id, "Paid Subscr. ID @ time of demotion: " . $subscr_gateway . " -› " . $subscr_id); } if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["eot_del_notification_urls"] && is_array($cv = preg_split("/\\|/", $custom))) { foreach (preg_split("/[\r\n\t]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["eot_del_notification_urls"]) as $url) { // Handle EOT Notifications. if (($url = preg_replace("/%%cv([0-9]+)%%/ei", 'urlencode(trim($cv[$1]))', $url)) && ($url = preg_replace("/%%eot_del_type%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode("auto-eot-cancellation-expiration-demotion")), $url)) && ($url = preg_replace("/%%subscr_id%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($subscr_id)), $url))) { if (($url = preg_replace("/%%user_first_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($user->first_name)), $url)) && ($url = preg_replace("/%%user_last_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($user->last_name)), $url))) { if ($url = preg_replace("/%%user_full_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode(trim($user->first_name . " " . $user->last_name))), $url)) { if ($url = preg_replace("/%%user_email%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($user->user_email)), $url)) { if ($url = preg_replace("/%%user_login%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($user->user_login)), $url)) { if ($url = preg_replace("/%%user_ip%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($user_reg_ip)), $url)) { if ($url = preg_replace("/%%user_id%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($user_id)), $url)) { if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { if (!($url = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode(maybe_serialize($val))), $url))) { break; } } } if ($url = trim(preg_replace("/%%(.+?)%%/i", "", $url))) { c_ws_plugin__s2member_utils_urls::remote($url); } } } } } } } } } } if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["eot_del_notification_recipients"] && is_array($cv = preg_split("/\\|/", $custom))) { $email_configs_were_on = c_ws_plugin__s2member_email_configs::email_config_status(); c_ws_plugin__s2member_email_configs::email_config_release(); $msg = $sbj = "(s2Member / API Notification Email) - EOT/Deletion"; $msg .= "\n\n"; $msg .= "eot_del_type: %%eot_del_type%%\n"; $msg .= "subscr_id: %%subscr_id%%\n"; $msg .= "user_first_name: %%user_first_name%%\n"; $msg .= "user_last_name: %%user_last_name%%\n"; $msg .= "user_full_name: %%user_full_name%%\n"; $msg .= "user_email: %%user_email%%\n"; $msg .= "user_login: %%user_login%%\n"; $msg .= "user_ip: %%user_ip%%\n"; $msg .= "user_id: %%user_id%%\n"; if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { $msg .= $var . ": %%" . $var . "%%\n"; } } $msg .= "cv0: %%cv0%%\n"; $msg .= "cv1: %%cv1%%\n"; $msg .= "cv2: %%cv2%%\n"; $msg .= "cv3: %%cv3%%\n"; $msg .= "cv4: %%cv4%%\n"; $msg .= "cv5: %%cv5%%\n"; $msg .= "cv6: %%cv6%%\n"; $msg .= "cv7: %%cv7%%\n"; $msg .= "cv8: %%cv8%%\n"; $msg .= "cv9: %%cv9%%"; if (($msg = preg_replace("/%%cv([0-9]+)%%/ei", 'trim($cv[$1])', $msg)) && ($msg = preg_replace("/%%eot_del_type%%/i", c_ws_plugin__s2member_utils_strings::esc_ds("auto-eot-cancellation-expiration-demotion"), $msg)) && ($msg = preg_replace("/%%subscr_id%%/i", c_ws_plugin__s2member_utils_strings::esc_ds($subscr_id), $msg))) { if (($msg = preg_replace("/%%user_first_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds($user->first_name), $msg)) && ($msg = preg_replace("/%%user_last_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds($user->last_name), $msg))) { if ($msg = preg_replace("/%%user_full_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(trim($user->first_name . " " . $user->last_name)), $msg)) { if ($msg = preg_replace("/%%user_email%%/i", c_ws_plugin__s2member_utils_strings::esc_ds($user->user_email), $msg)) { if ($msg = preg_replace("/%%user_login%%/i", c_ws_plugin__s2member_utils_strings::esc_ds($user->user_login), $msg)) { if ($msg = preg_replace("/%%user_ip%%/i", c_ws_plugin__s2member_utils_strings::esc_ds($user_reg_ip), $msg)) { if ($msg = preg_replace("/%%user_id%%/i", c_ws_plugin__s2member_utils_strings::esc_ds($user_id), $msg)) { if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { if (!($msg = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(maybe_serialize($val)), $msg))) { break; } } } if ($sbj && ($msg = trim(preg_replace("/%%(.+?)%%/i", "", $msg)))) { foreach (c_ws_plugin__s2member_utils_strings::parse_emails($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["eot_del_notification_recipients"]) as $recipient) { wp_mail($recipient, apply_filters("ws_plugin__s2member_eot_del_notification_email_sbj", $sbj, get_defined_vars()), apply_filters("ws_plugin__s2member_eot_del_notification_email_msg", $msg, get_defined_vars()), "Content-Type: text/plain; charset=UTF-8"); } } } } } } } } } if ($email_configs_were_on) { c_ws_plugin__s2member_email_configs::email_config(); } } foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action("ws_plugin__s2member_during_auto_eot_system_during_demote", get_defined_vars()); unset($__refs, $__v); } else { if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_eot_behavior"] === "delete") { $eot_del_type = $GLOBALS["ws_plugin__s2member_eot_del_type"] = "auto-eot-cancellation-expiration-deletion"; foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action("ws_plugin__s2member_during_auto_eot_system_during_before_delete", get_defined_vars()); do_action("ws_plugin__s2member_during_collective_eots", $user_id, get_defined_vars(), $eot_del_type, "removal-deletion"); unset($__refs, $__v); if (is_multisite()) { remove_user_from_blog($user_id, $current_blog->blog_id); // This will automatically trigger `eot_del_notification_urls`. c_ws_plugin__s2member_user_deletions::handle_ms_user_deletions($user_id, $current_blog->blog_id, "s2says"); } else { // Otherwise, we can actually delete them. // This will automatically trigger `eot_del_notification_urls` wp_delete_user($user_id); } foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action("ws_plugin__s2member_during_auto_eot_system_during_delete", get_defined_vars()); unset($__refs, $__v); } } foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action("ws_plugin__s2member_during_auto_eot_system", get_defined_vars()); unset($__refs, $__v); } } } } } c_ws_plugin__s2member_utils_logs::cleanup_expired_s2m_transients(); foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action("ws_plugin__s2member_after_auto_eot_system", get_defined_vars()); unset($__refs, $__v); return; }
/** * Delete a user from the network and remove from all sites. * * @since 3.0.0 * * @todo Merge with wp_delete_user() ? * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $id The user ID. * @return bool True if the user was deleted, otherwise false. */ function wpmu_delete_user($id) { global $wpdb; if (!is_numeric($id)) { return false; } $id = (int) $id; $user = new WP_User($id); if (!$user->exists()) { return false; } // Global super-administrators are protected, and cannot be deleted. $_super_admins = get_super_admins(); if (in_array($user->user_login, $_super_admins, true)) { return false; } /** * Fires before a user is deleted from the network. * * @since MU * * @param int $id ID of the user about to be deleted from the network. */ do_action('wpmu_delete_user', $id); $blogs = get_blogs_of_user($id); if (!empty($blogs)) { foreach ($blogs as $blog) { switch_to_blog($blog->userblog_id); remove_user_from_blog($id, $blog->userblog_id); $post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d", $id)); foreach ((array) $post_ids as $post_id) { wp_delete_post($post_id); } // Clean links $link_ids = $wpdb->get_col($wpdb->prepare("SELECT link_id FROM {$wpdb->links} WHERE link_owner = %d", $id)); if ($link_ids) { foreach ($link_ids as $link_id) { wp_delete_link($link_id); } } restore_current_blog(); } } $meta = $wpdb->get_col($wpdb->prepare("SELECT umeta_id FROM {$wpdb->usermeta} WHERE user_id = %d", $id)); foreach ($meta as $mid) { delete_metadata_by_mid('user', $mid); } $wpdb->delete($wpdb->users, array('ID' => $id)); clean_user_cache($user); /** This action is documented in wp-admin/includes/user.php */ do_action('deleted_user', $id); return true; }
/** * Configures all new Users. * * The Hook `user_register` is also fired by calling: * ``c_ws_plugin__s2member_registrations::ms_create_existing_user()`` and/or ``wpmu_create_user()``. * * This function also receives hand-offs from s2Member's handlers for these two Hooks: * `wpmu_activate_user` and `wpmu_activate_blog`. * * @package s2Member\Registrations * @since 3.5 * * @attaches-to ``add_action('user_register');`` * * @param int|string $user_id A numeric WordPress User ID. * @param string $password Optional in most cases. A User's plain text Password. If unspecified, attempts are made to collect the plain text Password from other sources. * @param array $meta Optional in most cases. Defaults to false. An array of meta data for a User/Member. * * @TODO Impossible to delete cookies when fired inside: `/wp-activate.php`? */ public static function configure_user_registration($user_id = '', $password = '', $meta = array()) { global $wpdb; // Global database object reference. global $pagenow; // We need this to detect the current administration page. global $current_site, $current_blog; // Adds support for Multisite Networking. static $email_config, $processed; // Static vars prevent duplicate processing. foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_before_configure_user_registration', get_defined_vars()); unset($__refs, $__v); // Housekeeping. // With Multisite Networking, we need this to run on `user_register` ahead of `wpmu_activate_[user|blog]`. if (!isset($email_config) && ($email_config = TRUE)) { // Anytime this routine is fired; we configure email. c_ws_plugin__s2member_email_configs::email_config(); } // Configures `From:` email header. $_p = isset($_POST) ? $_POST : NULL; // Grab global ``$_POST`` array here, if it's possible to do so. $rvs = isset($GLOBALS['ws_plugin__s2member_registration_vars']) ? $GLOBALS['ws_plugin__s2member_registration_vars'] : NULL; if (!$processed) { if (is_array($_p) || is_array($meta) || is_array($rvs)) { if (!(is_multisite() && is_blog_admin() && $pagenow === 'user-new.php' && isset($_p['noconfirmation']) && is_super_admin() && !is_array($meta))) { if (!(preg_match('/\\/wp-activate\\.php/', $_SERVER['REQUEST_URI']) && !is_array($meta))) { if (!(c_ws_plugin__s2member_utils_conds::bp_is_installed() && bp_is_activation_page() && !is_array($meta))) { if (!(c_ws_plugin__s2member_utils_conds::pro_is_installed() && c_ws_plugin__s2member_pro_remote_ops::is_remote_op('create_user') && !is_array($rvs))) { if ($user_id && is_object($user = new WP_User($user_id)) && !empty($user->ID) && ($user_id = $user->ID) && ($processed = TRUE)) { settype($_p, 'array') . settype($meta, 'array') . settype($rvs, 'array'); // Force arrays here. $_p = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_p)); $meta = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($meta)); $rvs = c_ws_plugin__s2member_utils_strings::trim_deep($rvs); foreach ($_p as $_key => $_value) { // Scan ``$_p`` vars; adding `custom_reg_field` keys. if (preg_match('/^ws_plugin__s2member_user_new_/', $_key)) { // Look for keys. if ($_key = str_replace('_user_new_', '_custom_reg_field_', $_key)) { $_p[$_key] = $_value; } } } // Add each of these key conversions. unset($_key, $_value); if (!is_admin() && (isset($_p['ws_plugin__s2member_custom_reg_field_s2member_subscr_gateway']) || isset($_p['ws_plugin__s2member_custom_reg_field_s2member_subscr_id']) || isset($_p['ws_plugin__s2member_custom_reg_field_s2member_subscr_baid']) || isset($_p['ws_plugin__s2member_custom_reg_field_s2member_subscr_cid']) || isset($_p['ws_plugin__s2member_custom_reg_field_s2member_custom']) || isset($_p['ws_plugin__s2member_custom_reg_field_s2member_ccaps']) || isset($_p['ws_plugin__s2member_custom_reg_field_s2member_auto_eot_time']) || isset($_p['ws_plugin__s2member_custom_reg_field_s2member_notes']))) { exit(_x('s2Member security violation. You attempted to POST administrative variables that will NOT be trusted in a NON-administrative zone!', 's2member-front', 's2member')); } $_pmr = array_merge($_p, $meta, $rvs); // Merge all of these arrays together now, in this specific order. unset($_p, $meta, $rvs); // These variables can all be unset now; we have them all in the ``$_pmr`` array. $custom_reg_display_name = $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_display_name']; // Can be configured by the site owner. if (!is_admin() && (!c_ws_plugin__s2member_utils_conds::pro_is_installed() || !c_ws_plugin__s2member_pro_remote_ops::is_remote_op('create_user')) && ($reg_cookies = c_ws_plugin__s2member_register_access::reg_cookies_ok()) && extract($reg_cookies)) { /* This routine could be processed through `/wp-login.php?action=register`, `/wp-activate.php`, or `/activate` via BuddyPress`. This may also be processed through a standard BuddyPress installation, or another plugin calling `user_register`. If processed through `/wp-activate.php`, it could've originated inside the admin—via `/user-new.php`. */ /** * @var $subscr_gateway string Reference for IDEs. * @var $subscr_id string Reference for IDEs. * @var $custom string Reference for IDEs. * @var $item_number string Reference for IDEs. */ $processed = 'yes'; // Mark this as yes. $current_role = c_ws_plugin__s2member_user_access::user_access_role($user); @(list($level, $ccaps, $eotper) = preg_split('/\\:/', $item_number, 3)); $role = 's2member_level' . $level; // Membership Level. $email = $user->user_email; $login = $user->user_login; $ip = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_registration_ip']; $ip = !$ip ? $_SERVER['REMOTE_ADDR'] : $ip; // Else use environment variable. $subscr_baid = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_subscr_baid']; $subscr_cid = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_subscr_cid']; $cv = preg_split('/\\|/', $custom); if (!($auto_eot_time = '') && $eotper) { // If a specific EOT Period is included. $auto_eot_time = c_ws_plugin__s2member_utils_time::auto_eot_time('', '', '', $eotper); } $notes = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_notes']; $opt_in = !$GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_opt_in'] ? TRUE : FALSE; $opt_in = !$opt_in && !empty($_pmr['ws_plugin__s2member_custom_reg_field_opt_in']) ? TRUE : $opt_in; if (!($fname = $user->first_name)) { if (!empty($_pmr['ws_plugin__s2member_custom_reg_field_first_name'])) { $fname = (string) $_pmr['ws_plugin__s2member_custom_reg_field_first_name']; } } if (!$fname) { // Also try BuddyPress. if (!empty($_pmr['field_1'])) { // BuddyPress? $fname = trim(preg_replace('/ (.*)$/', '', (string) $_pmr['field_1'])); } } if (!($lname = $user->last_name)) { if (!empty($_pmr['ws_plugin__s2member_custom_reg_field_last_name'])) { $lname = (string) $_pmr['ws_plugin__s2member_custom_reg_field_last_name']; } } if (!$lname) { // Also try BuddyPress. if (!empty($_pmr['field_1']) && preg_match('/^(.+?) (.+)$/', (string) $_pmr['field_1'])) { $lname = trim(preg_replace('/^(.+?) (.+)$/', '$2', (string) $_pmr['field_1'])); } } if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_names'] && !$fname && $login) { $fname = trim($login); $lname = ''; // Username and empty Last Name. } $name = trim($fname . ' ' . $lname); // Both names. if (!($pass = $password)) { // Try s2Member's generator. if (!empty($GLOBALS['ws_plugin__s2member_plain_text_pass'])) { $pass = (string) $GLOBALS['ws_plugin__s2member_plain_text_pass']; } } if (!$pass) { // Also try BuddyPress Password. if (!empty($_pmr['signup_password'])) { // BuddyPress? $pass = (string) $_pmr['signup_password']; } } if ($pass) { !headers_sent() ? delete_user_setting('default_password_nag', $user_id) : NULL; update_user_option($user_id, 'default_password_nag', FALSE, TRUE); } update_user_option($user_id, 's2member_registration_ip', $ip); update_user_option($user_id, 's2member_auto_eot_time', $auto_eot_time); update_user_option($user_id, 's2member_subscr_gateway', $subscr_gateway); update_user_option($user_id, 's2member_subscr_id', $subscr_id); update_user_option($user_id, 's2member_subscr_baid', $subscr_baid); update_user_option($user_id, 's2member_subscr_cid', $subscr_cid); update_user_option($user_id, 's2member_custom', $custom); update_user_option($user_id, 's2member_notes', $notes); if (!$user->first_name && $fname) { update_user_meta($user_id, 'first_name', $fname); } if (!$user->last_name && $lname) { update_user_meta($user_id, 'last_name', $lname); } if (!$user->display_name || $user->display_name === $user->user_login) { if ($custom_reg_display_name === 'full' && $name) { wp_update_user(wp_slash(array('ID' => $user_id, 'display_name' => $name))); } else { if ($custom_reg_display_name === 'first' && $fname) { wp_update_user(wp_slash(array('ID' => $user_id, 'display_name' => $fname))); } else { if ($custom_reg_display_name === 'last' && $lname) { wp_update_user(wp_slash(array('ID' => $user_id, 'display_name' => $lname))); } else { if ($custom_reg_display_name === 'login' && $login) { wp_update_user(wp_slash(array('ID' => $user_id, 'display_name' => $login))); } } } } } if (is_multisite()) { if (!is_main_site() && strtotime($user->user_registered) >= strtotime('-10 seconds')) { remove_user_from_blog($user_id, $current_site->blog_id); } // No Main Site Role. if (!get_user_meta($user_id, 's2member_originating_blog', TRUE)) { // Recorded yet? update_user_meta($user_id, 's2member_originating_blog', $current_blog->blog_id); } } if ($current_role !== $role) { // Only if NOT the current Role. $user->set_role($role); } // s2Member. if ($ccaps && preg_match('/^-all/', str_replace('+', '', $ccaps))) { foreach ($user->allcaps as $cap => $cap_enabled) { if (preg_match('/^access_s2member_ccap_/', $cap)) { $user->remove_cap($ccap = $cap); } } } if ($ccaps && preg_replace('/^-all[' . "\r\n\t" . '\\s;,]*/', '', str_replace('+', '', $ccaps))) { foreach (preg_split('/[' . "\r\n\t" . '\\s;,]+/', preg_replace('/^-all[' . "\r\n\t" . '\\s;,]*/', '', str_replace('+', '', $ccaps))) as $ccap) { if (strlen($ccap = trim(strtolower(preg_replace('/[^a-z_0-9]/i', '', $ccap))))) { $user->add_cap('access_s2member_ccap_' . $ccap); } } } if (!($fields = array()) && $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields']) { foreach (json_decode($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields'], TRUE) as $field) { $field_var = preg_replace('/[^a-z0-9]/i', '_', strtolower($field['id'])); $field_id_class = preg_replace('/_/', '-', $field_var); if (isset($_pmr['ws_plugin__s2member_custom_reg_field_' . $field_var])) { $fields[$field_var] = $_pmr['ws_plugin__s2member_custom_reg_field_' . $field_var]; } } } unset($field, $field_var, $field_id_class); // Housekeeping. if (!empty($fields)) { // Only if NOT empty. update_user_option($user_id, 's2member_custom_fields', $fields); } if ($level > 0) { $pr_times = get_user_option('s2member_paid_registration_times', $user_id); $pr_times['level'] = empty($pr_times['level']) ? time() : $pr_times['level']; $pr_times['level' . $level] = empty($pr_times['level' . $level]) ? time() : $pr_times['level' . $level]; update_user_option($user_id, 's2member_paid_registration_times', $pr_times); // Update now. } if (!is_multisite() && c_ws_plugin__s2member_utils_conds::bp_is_installed() && bp_is_register_page()) { update_user_option($user_id, 's2member_bp_activation_role', $role); update_user_option($user_id, 's2member_bp_activation_ccaps', c_ws_plugin__s2member_user_access::user_access_ccaps($user)); } if (($transient = 's2m_' . md5('s2member_transient_ipn_signup_vars_' . $subscr_id)) && is_array($ipn_signup_vars = get_transient($transient))) { update_user_option($user_id, 's2member_ipn_signup_vars', $ipn_signup_vars); // For future reference. delete_transient($transient); // This can be deleted now. } if (($transient = 's2m_' . md5('s2member_transient_ipn_subscr_payment_' . $subscr_id)) && is_array($subscr_payment = get_transient($transient)) && !empty($subscr_payment['subscr_gateway'])) { $proxy = array('s2member_paypal_proxy' => stripslashes((string) $subscr_payment['subscr_gateway']), 's2member_paypal_proxy_verification' => c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen()); c_ws_plugin__s2member_utils_urls::remote(home_url('/?s2member_paypal_notify=1'), array_merge(stripslashes_deep($subscr_payment), $proxy), array('timeout' => 20)); delete_transient($transient); // This can be deleted now. } if (($transient = 's2m_' . md5('s2member_transient_ipn_subscr_eot_' . $subscr_id)) && is_array($subscr_eot = get_transient($transient)) && !empty($subscr_eot['subscr_gateway'])) { $proxy = array('s2member_paypal_proxy' => stripslashes((string) $subscr_eot['subscr_gateway']), 's2member_paypal_proxy_verification' => c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen()); c_ws_plugin__s2member_utils_urls::remote(home_url('/?s2member_paypal_notify=1'), array_merge(stripslashes_deep($subscr_eot), $proxy), array('timeout' => 20)); delete_transient($transient); // This can be deleted now. } if (!headers_sent()) { // Only if headers are NOT yet sent. Here we establish both Signup and Payment Tracking Cookies. @setcookie('s2member_tracking', $s2member_tracking = c_ws_plugin__s2member_utils_encryption::encrypt($subscr_id), time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . @setcookie('s2member_tracking', $s2member_tracking, time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN) . ($_COOKIE['s2member_tracking'] = $s2member_tracking); } foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_during_configure_user_registration_front_side_paid', get_defined_vars()); do_action('ws_plugin__s2member_during_configure_user_registration_front_side', get_defined_vars()); unset($__refs, $__v); } else { if (!is_admin() && (!c_ws_plugin__s2member_utils_conds::pro_is_installed() || !c_ws_plugin__s2member_pro_remote_ops::is_remote_op('create_user'))) { /* This routine could be processed through `/wp-login.php?action=register`, `/wp-activate.php`, or `/activate` via BuddyPress`. This may also be processed through a standard BuddyPress installation, or another plugin calling `user_register`. If processed through `/wp-activate.php`, it could've originated inside the admin, via `/user-new.php`. */ $processed = 'yes'; // Mark this as yes. $current_role = c_ws_plugin__s2member_user_access::user_access_role($user); $role = ''; // Initialize ``$role`` to an empty string here, before processing. $role = !$role && ($level = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_level']) > 0 ? 's2member_level' . $level : $role; $role = !$role && ($level = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_level']) === '0' ? 'subscriber' : $role; $role = !$role && $current_role ? $current_role : $role; // Use existing Role? $role = !$role ? get_option('default_role') : $role; // Otherwise default. $level = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_level']; $level = !$level && preg_match('/^(administrator|editor|author|contributor)$/i', $role) ? $GLOBALS['WS_PLUGIN__']['s2member']['c']['levels'] : $level; $level = !$level && preg_match('/^s2member_level[1-9][0-9]*$/i', $role) ? preg_replace('/^s2member_level/', '', $role) : $level; $level = !$level && preg_match('/^subscriber$/i', $role) ? '0' : $level; $level = !$level ? '0' : $level; $ccaps = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_ccaps']; $email = $user->user_email; $login = $user->user_login; $ip = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_registration_ip']; $ip = !$ip ? $_SERVER['REMOTE_ADDR'] : $ip; // Else use environment variable. $custom = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_custom']; $subscr_id = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_subscr_id']; $subscr_baid = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_subscr_baid']; $subscr_cid = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_subscr_cid']; $subscr_gateway = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_subscr_gateway']; $cv = preg_split('/\\|/', (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_custom']); $auto_eot_time = ($eot = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_auto_eot_time']) ? strtotime($eot) : ''; $notes = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_notes']; $opt_in = !$GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_opt_in'] ? TRUE : FALSE; $opt_in = !$opt_in && !empty($_pmr['ws_plugin__s2member_custom_reg_field_opt_in']) ? TRUE : $opt_in; if (!($fname = $user->first_name)) { if (!empty($_pmr['ws_plugin__s2member_custom_reg_field_first_name'])) { $fname = (string) $_pmr['ws_plugin__s2member_custom_reg_field_first_name']; } } if (!$fname) { // Also try BuddyPress. if (!empty($_pmr['field_1'])) { // BuddyPress? $fname = trim(preg_replace('/ (.*)$/', '', (string) $_pmr['field_1'])); } } if (!($lname = $user->last_name)) { if (!empty($_pmr['ws_plugin__s2member_custom_reg_field_last_name'])) { $lname = (string) $_pmr['ws_plugin__s2member_custom_reg_field_last_name']; } } if (!$lname) { // Also try BuddyPress. if (!empty($_pmr['field_1']) && preg_match('/^(.+?) (.+)$/', (string) $_pmr['field_1'])) { $lname = trim(preg_replace('/^(.+?) (.+)$/', '$2', (string) $_pmr['field_1'])); } } if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_names'] && !$fname && $login) { $fname = trim($login); $lname = ''; // Username and empty Last Name. } $name = trim($fname . ' ' . $lname); // Both names. if (!($pass = $password)) { // Try s2Member's generator. if (!empty($GLOBALS['ws_plugin__s2member_plain_text_pass'])) { $pass = (string) $GLOBALS['ws_plugin__s2member_plain_text_pass']; } } if (!$pass) { // Also try BuddyPress Password. if (!empty($_pmr['signup_password'])) { // BuddyPress? $pass = (string) $_pmr['signup_password']; } } if ($pass) { !headers_sent() ? delete_user_setting('default_password_nag', $user_id) : NULL; update_user_option($user_id, 'default_password_nag', FALSE, TRUE); } update_user_option($user_id, 's2member_registration_ip', $ip); update_user_option($user_id, 's2member_auto_eot_time', $auto_eot_time); update_user_option($user_id, 's2member_subscr_gateway', $subscr_gateway); update_user_option($user_id, 's2member_subscr_id', $subscr_id); update_user_option($user_id, 's2member_subscr_baid', $subscr_baid); update_user_option($user_id, 's2member_subscr_cid', $subscr_cid); update_user_option($user_id, 's2member_custom', $custom); update_user_option($user_id, 's2member_notes', $notes); if (!$user->first_name && $fname) { update_user_meta($user_id, 'first_name', $fname); } if (!$user->last_name && $lname) { update_user_meta($user_id, 'last_name', $lname); } if (!$user->display_name || $user->display_name === $user->user_login) { if ($custom_reg_display_name === 'full' && $name) { wp_update_user(wp_slash(array('ID' => $user_id, 'display_name' => $name))); } else { if ($custom_reg_display_name === 'first' && $fname) { wp_update_user(wp_slash(array('ID' => $user_id, 'display_name' => $fname))); } else { if ($custom_reg_display_name === 'last' && $lname) { wp_update_user(wp_slash(array('ID' => $user_id, 'display_name' => $lname))); } else { if ($custom_reg_display_name === 'login' && $login) { wp_update_user(wp_slash(array('ID' => $user_id, 'display_name' => $login))); } } } } } if (is_multisite()) { if (!is_main_site() && strtotime($user->user_registered) >= strtotime('-10 seconds')) { remove_user_from_blog($user_id, $current_site->blog_id); } // No Main Site Role. if (!get_user_meta($user_id, 's2member_originating_blog', TRUE)) { // Recorded yet? update_user_meta($user_id, 's2member_originating_blog', $current_blog->blog_id); } } if ($current_role !== $role) { // Only if NOT the current Role. $user->set_role($role); } // s2Member. if ($ccaps && preg_match('/^-all/', str_replace('+', '', $ccaps))) { foreach ($user->allcaps as $cap => $cap_enabled) { if (preg_match('/^access_s2member_ccap_/', $cap)) { $user->remove_cap($ccap = $cap); } } } if ($ccaps && preg_replace('/^-all[' . "\r\n\t" . '\\s;,]*/', '', str_replace('+', '', $ccaps))) { foreach (preg_split('/[' . "\r\n\t" . '\\s;,]+/', preg_replace('/^-all[' . "\r\n\t" . '\\s;,]*/', '', str_replace('+', '', $ccaps))) as $ccap) { if (strlen($ccap = trim(strtolower(preg_replace('/[^a-z_0-9]/i', '', $ccap))))) { $user->add_cap('access_s2member_ccap_' . $ccap); } } } if (!($fields = array()) && $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields']) { foreach (json_decode($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields'], TRUE) as $field) { $field_var = preg_replace('/[^a-z0-9]/i', '_', strtolower($field['id'])); $field_id_class = preg_replace('/_/', '-', $field_var); if (isset($_pmr['ws_plugin__s2member_custom_reg_field_' . $field_var])) { $fields[$field_var] = $_pmr['ws_plugin__s2member_custom_reg_field_' . $field_var]; } } } unset($field, $field_var, $field_id_class); // Housekeeping. if (!empty($fields)) { // Only if NOT empty. update_user_option($user_id, 's2member_custom_fields', $fields); } if ($level > 0) { $pr_times = get_user_option('s2member_paid_registration_times', $user_id); $pr_times['level'] = empty($pr_times['level']) ? time() : $pr_times['level']; $pr_times['level' . $level] = empty($pr_times['level' . $level]) ? time() : $pr_times['level' . $level]; update_user_option($user_id, 's2member_paid_registration_times', $pr_times); // Update now. } if (!is_multisite() && c_ws_plugin__s2member_utils_conds::bp_is_installed() && bp_is_register_page()) { update_user_option($user_id, 's2member_bp_activation_role', $role); update_user_option($user_id, 's2member_bp_activation_ccaps', c_ws_plugin__s2member_user_access::user_access_ccaps($user)); } foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_during_configure_user_registration_front_side_free', get_defined_vars()); do_action('ws_plugin__s2member_during_configure_user_registration_front_side', get_defined_vars()); unset($__refs, $__v); } else { if (is_blog_admin() && $pagenow === 'user-new.php' || c_ws_plugin__s2member_utils_conds::pro_is_installed() && c_ws_plugin__s2member_pro_remote_ops::is_remote_op('create_user')) { // Can only be processed through `/user-new.php` in the Admin panel, or through Remote Op: `create_user`. $processed = 'yes'; // Mark this as yes, to indicate that a routine was processed. $current_role = c_ws_plugin__s2member_user_access::user_access_role($user); $role = ''; // Initialize $role to an empty string here, before processing. $role = !$role && ($level = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_level']) > 0 ? 's2member_level' . $level : $role; $role = !$role && ($level = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_level']) === '0' ? 'subscriber' : $role; $role = !$role && $current_role ? $current_role : $role; // Use existing Role? $role = !$role ? get_option('default_role') : $role; // Otherwise default. $level = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_level']; $level = !$level && preg_match('/^(administrator|editor|author|contributor)$/i', $role) ? $GLOBALS['WS_PLUGIN__']['s2member']['c']['levels'] : $level; $level = !$level && preg_match('/^s2member_level[1-9][0-9]*$/i', $role) ? preg_replace('/^s2member_level/', '', $role) : $level; $level = !$level && preg_match('/^subscriber$/i', $role) ? '0' : $level; $level = !$level ? '0' : $level; $ccaps = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_ccaps']; $email = $user->user_email; $login = $user->user_login; $ip = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_registration_ip']; $custom = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_custom']; $subscr_id = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_subscr_id']; $subscr_baid = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_subscr_baid']; $subscr_cid = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_subscr_cid']; $subscr_gateway = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_subscr_gateway']; $cv = preg_split('/\\|/', (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_custom']); $auto_eot_time = ($eot = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_auto_eot_time']) ? strtotime($eot) : ''; $notes = (string) @$_pmr['ws_plugin__s2member_custom_reg_field_s2member_notes']; $opt_in = !empty($_pmr['ws_plugin__s2member_custom_reg_field_opt_in']) ? TRUE : FALSE; if (!($fname = $user->first_name)) { // `Users → Add New`. if (!empty($_pmr['ws_plugin__s2member_custom_reg_field_first_name'])) { $fname = (string) $_pmr['ws_plugin__s2member_custom_reg_field_first_name']; } } if (!($lname = $user->last_name)) { // `Users → Add New`. if (!empty($_pmr['ws_plugin__s2member_custom_reg_field_last_name'])) { $lname = (string) $_pmr['ws_plugin__s2member_custom_reg_field_last_name']; } } if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_names'] && !$fname && $login) { $fname = trim($login); $lname = ''; // Username and empty Last Name. } $name = trim($fname . ' ' . $lname); // Both names. if (!($pass = $password)) { // Try s2Member's generator. if (!empty($GLOBALS['ws_plugin__s2member_plain_text_pass'])) { $pass = (string) $GLOBALS['ws_plugin__s2member_plain_text_pass']; } } if (!$pass) { // Also try the `Users → Add New` form. if (!empty($_pmr['pass1'])) { // Field in `/user-new.php`. $pass = (string) $_pmr['pass1']; } } if ($pass) { !headers_sent() ? delete_user_setting('default_password_nag', $user_id) : NULL; update_user_option($user_id, 'default_password_nag', FALSE, TRUE); } update_user_option($user_id, 's2member_registration_ip', $ip); update_user_option($user_id, 's2member_auto_eot_time', $auto_eot_time); update_user_option($user_id, 's2member_subscr_gateway', $subscr_gateway); update_user_option($user_id, 's2member_subscr_id', $subscr_id); update_user_option($user_id, 's2member_subscr_baid', $subscr_baid); update_user_option($user_id, 's2member_subscr_cid', $subscr_cid); update_user_option($user_id, 's2member_custom', $custom); update_user_option($user_id, 's2member_notes', $notes); if (!$user->first_name && $fname) { update_user_meta($user_id, 'first_name', $fname); } if (!$user->last_name && $lname) { update_user_meta($user_id, 'last_name', $lname); } if (!$user->display_name || $user->display_name === $user->user_login) { if ($custom_reg_display_name === 'full' && $name) { wp_update_user(wp_slash(array('ID' => $user_id, 'display_name' => $name))); } else { if ($custom_reg_display_name === 'first' && $fname) { wp_update_user(wp_slash(array('ID' => $user_id, 'display_name' => $fname))); } else { if ($custom_reg_display_name === 'last' && $lname) { wp_update_user(wp_slash(array('ID' => $user_id, 'display_name' => $lname))); } else { if ($custom_reg_display_name === 'login' && $login) { wp_update_user(wp_slash(array('ID' => $user_id, 'display_name' => $login))); } } } } } if (is_multisite()) { if (!is_main_site() && strtotime($user->user_registered) >= strtotime('-10 seconds')) { remove_user_from_blog($user_id, $current_site->blog_id); } // No Main Site Role. if (!get_user_meta($user_id, 's2member_originating_blog', TRUE)) { // Recorded yet? update_user_meta($user_id, 's2member_originating_blog', $current_blog->blog_id); } } if ($current_role !== $role) { // Only if NOT the current Role. $user->set_role($role); } // s2Member. if ($ccaps && preg_match('/^-all/', str_replace('+', '', $ccaps))) { foreach ($user->allcaps as $cap => $cap_enabled) { if (preg_match('/^access_s2member_ccap_/', $cap)) { $user->remove_cap($ccap = $cap); } } } if ($ccaps && preg_replace('/^-all[' . "\r\n\t" . '\\s;,]*/', '', str_replace('+', '', $ccaps))) { foreach (preg_split('/[' . "\r\n\t" . '\\s;,]+/', preg_replace('/^-all[' . "\r\n\t" . '\\s;,]*/', '', str_replace('+', '', $ccaps))) as $ccap) { if (strlen($ccap = trim(strtolower(preg_replace('/[^a-z_0-9]/i', '', $ccap))))) { $user->add_cap('access_s2member_ccap_' . $ccap); } } } if (!($fields = array()) && $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields']) { foreach (json_decode($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields'], TRUE) as $field) { $field_var = preg_replace('/[^a-z0-9]/i', '_', strtolower($field['id'])); $field_id_class = preg_replace('/_/', '-', $field_var); if (isset($_pmr['ws_plugin__s2member_custom_reg_field_' . $field_var])) { $fields[$field_var] = $_pmr['ws_plugin__s2member_custom_reg_field_' . $field_var]; } } } unset($field, $field_var, $field_id_class); // Housekeeping. if (!empty($fields)) { // Only if NOT empty. update_user_option($user_id, 's2member_custom_fields', $fields); } if ($level > 0) { $pr_times = get_user_option('s2member_paid_registration_times', $user_id); $pr_times['level'] = empty($pr_times['level']) ? time() : $pr_times['level']; $pr_times['level' . $level] = empty($pr_times['level' . $level]) ? time() : $pr_times['level' . $level]; update_user_option($user_id, 's2member_paid_registration_times', $pr_times); // Update now. } foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_during_configure_user_registration_admin_side', get_defined_vars()); unset($__refs, $__v); } } } if ($processed === 'yes') { /** * If processed, all of these will have been defined by now. * * @var $role string Reference for IDEs. * @var $level string Reference for IDEs. * @var $ccaps string Reference for IDEs. * @var $auto_eot_time string|integer Reference for IDEs. * @var $fname string Reference for IDEs. * @var $lname string Reference for IDEs. * @var $name string Reference for IDEs. * @var $email string Reference for IDEs. * @var $login string Reference for IDEs. * @var $pass string Reference for IDEs. * @var $ip string Reference for IDEs. * @var $opt_in boolean Reference for IDEs. * @var $fields array Reference for IDEs. */ if ($urls = $GLOBALS['WS_PLUGIN__']['s2member']['o']['registration_notification_urls']) { foreach (preg_split('/[' . "\r\n\t" . ']+/', $urls) as $url) { // Notify each of the URLs. if ($url = preg_replace('/%%cv([0-9]+)%%/ei', 'urlencode(trim(@$cv[$1]))', $url)) { if ($url = preg_replace('/%%role%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($role)), $url)) { if ($url = preg_replace('/%%level%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($level)), $url)) { if ($url = preg_replace('/%%ccaps%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($ccaps)), $url)) { if ($url = preg_replace('/%%auto_eot_time%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($auto_eot_time)), $url)) { if ($url = preg_replace('/%%user_first_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($fname)), $url)) { if ($url = preg_replace('/%%user_last_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($lname)), $url)) { if ($url = preg_replace('/%%user_full_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($name)), $url)) { if ($url = preg_replace('/%%user_email%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($email)), $url)) { if ($url = preg_replace('/%%user_login%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($login)), $url)) { if ($url = preg_replace('/%%user_pass%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($pass)), $url)) { if ($url = preg_replace('/%%user_ip%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($ip)), $url)) { if ($url = preg_replace('/%%user_id%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($user_id)), $url)) { foreach ($fields as $var => $val) { // Custom Fields. if (!($url = preg_replace('/%%' . preg_quote($var, '/') . '%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode(maybe_serialize($val))), $url))) { break; } } if ($url = trim(preg_replace('/%%(.+?)%%/i', '', $url))) { c_ws_plugin__s2member_utils_urls::remote($url); } } } } } } } } } } } } } } } } unset($urls, $url, $var, $val); // Housekeeping. if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['registration_notification_recipients']) { $email_configs_were_on = c_ws_plugin__s2member_email_configs::email_config_status(); c_ws_plugin__s2member_email_configs::email_config_release(); $msg = $sbj = '(s2Member / API Notification Email) - Registration'; $msg .= "\n\n"; // Spacing in the message body. $msg .= 'role: %%role%%' . "\n"; $msg .= 'level: %%level%%' . "\n"; $msg .= 'ccaps: %%ccaps%%' . "\n"; $msg .= 'auto_eot_time: %%auto_eot_time%%' . "\n"; $msg .= 'user_first_name: %%user_first_name%%' . "\n"; $msg .= 'user_last_name: %%user_last_name%%' . "\n"; $msg .= 'user_full_name: %%user_full_name%%' . "\n"; $msg .= 'user_email: %%user_email%%' . "\n"; $msg .= 'user_login: %%user_login%%' . "\n"; $msg .= 'user_pass: %%user_pass%%' . "\n"; $msg .= 'user_ip: %%user_ip%%' . "\n"; $msg .= 'user_id: %%user_id%%' . "\n"; foreach ($fields as $var => $val) { $msg .= $var . ': %%' . $var . '%%' . "\n"; } $msg .= 'cv0: %%cv0%%' . "\n"; $msg .= 'cv1: %%cv1%%' . "\n"; $msg .= 'cv2: %%cv2%%' . "\n"; $msg .= 'cv3: %%cv3%%' . "\n"; $msg .= 'cv4: %%cv4%%' . "\n"; $msg .= 'cv5: %%cv5%%' . "\n"; $msg .= 'cv6: %%cv6%%' . "\n"; $msg .= 'cv7: %%cv7%%' . "\n"; $msg .= 'cv8: %%cv8%%' . "\n"; $msg .= 'cv9: %%cv9%%'; if ($msg = preg_replace('/%%cv([0-9]+)%%/ei', 'trim(@$cv[$1])', $msg)) { if ($msg = preg_replace('/%%role%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($role), $msg)) { if ($msg = preg_replace('/%%level%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($level), $msg)) { if ($msg = preg_replace('/%%ccaps%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($ccaps), $msg)) { if ($msg = preg_replace('/%%auto_eot_time%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($auto_eot_time), $msg)) { if ($msg = preg_replace('/%%user_first_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($fname), $msg)) { if ($msg = preg_replace('/%%user_last_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($lname), $msg)) { if ($msg = preg_replace('/%%user_full_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($name), $msg)) { if ($msg = preg_replace('/%%user_email%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($email), $msg)) { if ($msg = preg_replace('/%%user_login%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($login), $msg)) { if ($msg = preg_replace('/%%user_pass%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($pass), $msg)) { if ($msg = preg_replace('/%%user_ip%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($ip), $msg)) { if ($msg = preg_replace('/%%user_id%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($user_id), $msg)) { foreach ($fields as $var => $val) { // Custom Fields. if (!($msg = preg_replace('/%%' . preg_quote($var, '/') . '%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(maybe_serialize($val)), $msg))) { break; } } if ($sbj && ($msg = trim(preg_replace('/%%(.+?)%%/i', '', $msg)))) { // Still have a ``$sbj`` and a ``$msg``? foreach (c_ws_plugin__s2member_utils_strings::parse_emails($GLOBALS['WS_PLUGIN__']['s2member']['o']['registration_notification_recipients']) as $recipient) { wp_mail($recipient, apply_filters('ws_plugin__s2member_registration_notification_email_sbj', $sbj, get_defined_vars()), apply_filters('ws_plugin__s2member_registration_notification_email_msg', $msg, get_defined_vars()), 'Content-Type: text/plain; charset=UTF-8'); } } } } } } } } } } } } } } } if ($email_configs_were_on) { // Back on? c_ws_plugin__s2member_email_configs::email_config(); } unset($sbj, $msg, $var, $val, $recipient, $email_configs_were_on); // Housekeeping. } if (!empty($GLOBALS['ws_plugin__s2member_registration_return_url']) && ($url = $GLOBALS['ws_plugin__s2member_registration_return_url'])) { if ($url = preg_replace('/%%cv([0-9]+)%%/ei', 'urlencode(trim(@$cv[$1]))', $url)) { if ($url = preg_replace('/%%role%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($role)), $url)) { if ($url = preg_replace('/%%level%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($level)), $url)) { if ($url = preg_replace('/%%ccaps%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($ccaps)), $url)) { if ($url = preg_replace('/%%auto_eot_time%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($auto_eot_time)), $url)) { if ($url = preg_replace('/%%user_first_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($fname)), $url)) { if ($url = preg_replace('/%%user_last_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($lname)), $url)) { if ($url = preg_replace('/%%user_full_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($name)), $url)) { if ($url = preg_replace('/%%user_email%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($email)), $url)) { if ($url = preg_replace('/%%user_login%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($login)), $url)) { if ($url = preg_replace('/%%user_pass%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($pass)), $url)) { if ($url = preg_replace('/%%user_ip%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($ip)), $url)) { if ($url = preg_replace('/%%user_id%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($user_id)), $url)) { foreach ($fields as $var => $val) { // Custom Fields. if (!($url = preg_replace('/%%' . preg_quote($var, '/') . '%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode(maybe_serialize($val))), $url))) { break; } } if ($url = trim($url)) { // Preserve remaining Replacements; because the parent routine may perform replacements too. $GLOBALS['ws_plugin__s2member_registration_return_url'] = $url; } } } } } } } } } } } } } } } unset($url, $var, $val); // Housekeeping. c_ws_plugin__s2member_list_servers::process_list_servers($role, $level, $login, $pass, $email, $fname, $lname, $ip, $opt_in, TRUE, $user_id); /* Suppress errors here in case this routine is fired in unexpected locations; or with odd output buffering techniques. @TODO It may also be impossible to delete cookies when fired inside: `/wp-activate.php`. */ if (!headers_sent()) { @setcookie('s2member_subscr_gateway', '', time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . @setcookie('s2member_subscr_gateway', '', time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN); @setcookie('s2member_subscr_id', '', time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . @setcookie('s2member_subscr_id', '', time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN); @setcookie('s2member_custom', '', time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . @setcookie('s2member_custom', '', time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN); @setcookie('s2member_item_number', '', time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . @setcookie('s2member_item_number', '', time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN); } /* If debugging/logging is enabled; we need to append ``$reg_vars`` to the log file. Logging now supports Multisite Networking as well. */ $reg_vars = get_defined_vars(); // All defined vars. $reg_vars['_COOKIE'] = $_COOKIE; // Record cookies also. // No need to include these in the logs. Unset before log entry. unset($reg_vars['wpdb'], $reg_vars['current_site'], $reg_vars['current_blog']); c_ws_plugin__s2member_utils_logs::log_entry('reg-handler', $reg_vars); foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_during_configure_user_registration', get_defined_vars()); unset($__refs, $__v); } } } } } } } } foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_after_configure_user_registration', get_defined_vars()); unset($__refs, $__v); // Housekeeping. }
/** * @ticket 20601 */ function test_user_member_of_blog() { global $wp_rewrite; $this->factory->blog->create(); $user_id = $this->factory->user->create(); $this->factory->blog->create( array( 'user_id' => $user_id ) ); $blogs = get_blogs_of_user( $user_id ); $this->assertCount( 2, $blogs ); $first = reset( $blogs )->userblog_id; remove_user_from_blog( $user_id, $first ); $blogs = get_blogs_of_user( $user_id ); $second = reset( $blogs )->userblog_id; $this->assertCount( 1, $blogs ); switch_to_blog( $first ); $wp_rewrite->init(); $this->go_to( get_author_posts_url( $user_id ) ); $this->assertQueryTrue( 'is_404' ); switch_to_blog( $second ); $wp_rewrite->init(); $this->go_to( get_author_posts_url( $user_id ) ); $this->assertQueryTrue( 'is_author', 'is_archive' ); add_user_to_blog( $first, $user_id, 'administrator' ); $blogs = get_blogs_of_user( $user_id ); $this->assertCount( 2, $blogs ); switch_to_blog( $first ); $wp_rewrite->init(); $this->go_to( get_author_posts_url( $user_id ) ); $this->assertQueryTrue( 'is_author', 'is_archive' ); }
pb_backupbuddy::status('details', 'Inserting user with parameters: `' . implode(', ', $new_destination_user_args) . '`.'); $user_id = wp_insert_user($new_destination_user_args); // Create new user into network. pb_backupbuddy::status('details', 'Sleeping 15 seconds'); // Only add user into this specific blog subsite if they had a capability on the source site. if ($new_user_role == '') { pb_backupbuddy::status('warning', 'WARNING: User with old user ID of `' . $old_user_id . '` did not have a role assigned on source site. This user was imported into the network but NOT assigned to this blog with a capability.'); $users_skipped_blog++; } else { add_user_to_blog($blog_id, $user_id, $new_user_role); // Add this user to the destination blog. $wpdb->update($wpdb->users, array('user_pass' => $old_user_pass), array('ID' => $user_id)); // Keep password the same. pb_backupbuddy::status('details', 'Added user `' . $user->user_login . '` with ID `' . $user_id . '` and role `' . $new_user_role . '` to blog ID `' . $blog_id . '`.'); // Remove user from main site (wp_insert_user() added to main site by default earlier. remove_user_from_blog($user_id, 1); // Remove user from main site. pb_backupbuddy::status('details', 'Removed user\'s temporary assignment to main Network site.'); // Update post author IDs with the user's new user ID. pb_backupbuddy::status('details', 'Updating post author ID from old user ID `' . $old_user_id . '` to new ID `' . $user_id . '` in table `' . $new_db_prefix . 'posts`.'); $rows_updated = $wpdb->update($new_db_prefix . 'posts', array('post_author' => absint($user_id)), array('post_author' => $old_user_id), array('%d')); pb_backupbuddy::status('details', 'Row(s) modified: `' . $rows_updated . '`.'); // Update comment author IDs with the user's new user ID. pb_backupbuddy::status('details', 'Updating comment author ID from old user ID `' . $old_user_id . '` to new ID `' . $user_id . '` in table `' . $new_db_prefix . 'comments`.'); $rows_updated = $wpdb->update($new_db_prefix . 'comments', array('user_id' => absint($user_id)), array('user_id' => $old_user_id), array('%d')); pb_backupbuddy::status('details', 'Row(s) modified: `' . $rows_updated . '`.'); } // Handle usermeta. $sql = "select meta_key,meta_value from `{$new_db_prefix}usermeta` WHERE user_id={$old_user_id} AND meta_key NOT LIKE '%\\_capabilities'"; pb_backupbuddy::status('details', 'Getting usermeta data. SQL query: `' . $sql . '`.'); $usermetas = $wpdb->get_results($sql);
public static function create_new_multisite($user_id, $config, $lead, $password) { global $current_site; $form = RGFormsModel::get_form_meta($lead['form_id']); $ms_options = rgars($config, 'meta/multisite_options'); $is_update_feed = rgars($config, 'meta/feed_type') == 'update'; $user = new WP_User($user_id); $password_field = rgars($config, 'meta/password'); $set_password = $password_field && rgar($lead, $password_field); $password = $password ? $password : rgar($lead, $password_field); // @review, verify what this is doing and notate here if (!$set_password) { remove_filter('update_welcome_email', 'bp_core_filter_blog_welcome_email'); } // is create site option enabled? if (!rgar($ms_options, 'create_site')) { return false; } $site_data = self::get_site_data($lead, $form, $config, $is_update_feed); if (!$site_data) { return false; } // create the new site! $meta = apply_filters('gform_user_registration_new_site_meta', array('public' => 1), $form, $lead, $config, $user_id, $is_update_feed); $blog_id = wpmu_create_blog($site_data['domain'], $site_data['path'], $site_data['title'], $user_id, $meta, $current_site->id); if (is_wp_error($blog_id)) { return false; } // add entry ID to site meta for new site GFUserData::update_site_meta($blog_id, 'entry_id', $lead['id']); if (!is_super_admin($user_id) && get_user_option('primary_blog', $user_id) == $current_site->blog_id) { update_user_option($user_id, 'primary_blog', $blog_id, true); } if (rgar($ms_options, 'site_role')) { $user = new WP_User($user_id, null, $blog_id); $user->set_role(rgar($ms_options, 'site_role')); } $root_role = rgar($ms_options, 'root_role'); // if no root role, remove user from current site if (!$root_role) { remove_user_from_blog($user_id); } else { if ($root_role == 'gfur_preserve_role') { } else { $user = new WP_User($user_id); $user->set_role($root_role); } } self::log_debug("Calling wpmu_welcome_notification to send multisite welcome - blog_id: {$blog_id} user_id: {$user_id}"); wpmu_welcome_notification($blog_id, $user_id, $password, $site_data['title'], array('public' => 1)); self::log_debug("Done with wpmu_welcome_notification"); do_action('gform_site_created', $blog_id, $user_id, $lead, $config, $password); // return new blog ID return $blog_id; }
/** * Configures all new Users. * * The Hook `user_register` is also fired by calling: * ``c_ws_plugin__s2member_registrations::ms_create_existing_user()`` and/or ``wpmu_create_user()``. * * This function also receives hand-offs from s2Member's handlers for these two Hooks: * `wpmu_activate_user` and `wpmu_activate_blog`. * * @package s2Member\Registrations * @since 3.5 * * @attaches-to ``add_action("user_register");`` * * @param int|str $user_id A numeric WordPress User ID. * @param str $password Optional in most cases. A User's plain text Password. If unspecified, attempts are made to collect the plain text Password from other sources. * @param array $meta Optional in most cases. Defaults to false. An array of meta data for a User/Member. * @return null No return value. Returns `null` in possible every scenario. * * @todo Impossible to delete cookies when fired inside: `/wp-activate.php`? */ public static function configure_user_registration($user_id = FALSE, $password = FALSE, $meta = FALSE) { global $wpdb; global $pagenow; // We need this to detect the current administration page. global $current_site, $current_blog; // Adds support for Multisite Networking. static $email_config, $processed; // Static vars prevent duplicate processing. foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action("ws_plugin__s2member_before_configure_user_registration", get_defined_vars()); unset($__refs, $__v); // With Multisite Networking, we need this to run on `user_register` ahead of `wpmu_activate_[user|blog]`. if (!isset($email_config) && ($email_config = true)) { // Anytime this routine is fired; we configure email. c_ws_plugin__s2member_email_configs::email_config(); } // Configures `From:` email header. $_p = isset($_POST) ? $_POST : null; $rvs = isset($GLOBALS["ws_plugin__s2member_registration_vars"]) ? $GLOBALS["ws_plugin__s2member_registration_vars"] : null; if (!$processed) { if (is_array($_p) || is_array($meta) || is_array($rvs)) { if (!(is_multisite() && is_blog_admin() && $pagenow === "user-new.php" && isset($_p["noconfirmation"]) && is_super_admin() && !is_array($meta))) { if (!(preg_match("/\\/wp-activate\\.php/", $_SERVER["REQUEST_URI"]) && !is_array($meta))) { if (!(c_ws_plugin__s2member_utils_conds::bp_is_installed() && bp_is_activation_page() && !is_array($meta))) { if (!(c_ws_plugin__s2member_utils_conds::pro_is_installed() && c_ws_plugin__s2member_pro_remote_ops::is_remote_op("create_user") && !is_array($rvs))) { if ($user_id && is_object($user = new WP_User($user_id)) && !empty($user->ID) && ($user_id = $user->ID) && ($processed = true)) { settype($_p, "array") . settype($meta, "array") . settype($rvs, "array"); $_p = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_p)); $meta = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($meta)); $rvs = c_ws_plugin__s2member_utils_strings::trim_deep($rvs); foreach ($_p as $_key => $_value) { // Scan ``$_p`` vars; adding `custom_reg_field` keys. if (preg_match("/^ws_plugin__s2member_user_new_/", $_key)) { // Look for keys. if ($_key = str_replace("_user_new_", "_custom_reg_field_", $_key)) { $_p[$_key] = $_value; } } } // Add each of these key conversions. unset($_key, $_value); if (!is_admin() && (isset($_p["ws_plugin__s2member_custom_reg_field_s2member_subscr_gateway"]) || isset($_p["ws_plugin__s2member_custom_reg_field_s2member_subscr_id"]) || isset($_p["ws_plugin__s2member_custom_reg_field_s2member_custom"]) || isset($_p["ws_plugin__s2member_custom_reg_field_s2member_ccaps"]) || isset($_p["ws_plugin__s2member_custom_reg_field_s2member_auto_eot_time"]) || isset($_p["ws_plugin__s2member_custom_reg_field_s2member_notes"]))) { exit(_x("s2Member security violation. You attempted to POST administrative variables that will NOT be trusted in a NON-administrative zone!", "s2member-front", "s2member")); } $_pmr = array_merge($_p, $meta, $rvs); // Merge all of these arrays together now, in this specific order. unset($_p, $meta, $rvs); // These variables can all be unset now; we have them all in the ``$_pmr`` array. $custom_reg_display_name = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_display_name"]; // Can be configured by the site owner. if (!is_admin() && (!c_ws_plugin__s2member_utils_conds::pro_is_installed() || !c_ws_plugin__s2member_pro_remote_ops::is_remote_op("create_user")) && ($reg_cookies = c_ws_plugin__s2member_register_access::reg_cookies_ok()) && extract($reg_cookies)) { /* This routine could be processed through `/wp-login.php?action=register`, `/wp-activate.php`, or `/activate` via BuddyPress`. This may also be processed through a standard BuddyPress installation, or another plugin calling `user_register`. If processed through `/wp-activate.php`, it could've originated inside the admin — via `/user-new.php`. */ $processed = "yes"; // Mark this as yes. $current_role = c_ws_plugin__s2member_user_access::user_access_role($user); @(list($level, $ccaps, $eotper) = preg_split("/\\:/", $item_number, 3)); $role = "s2member_level" . $level; // Membership Level. $email = $user->user_email; $login = $user->user_login; $ip = (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_registration_ip"]; $ip = !$ip ? $_SERVER["REMOTE_ADDR"] : $ip; // Else use environment variable. $cv = preg_split("/\\|/", $custom); if (!($auto_eot_time = "") && $eotper) { // If a specific EOT Period is included. $auto_eot_time = c_ws_plugin__s2member_utils_time::auto_eot_time("", "", "", $eotper); } $notes = (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_notes"]; $opt_in = !$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_opt_in"] ? true : false; $opt_in = !$opt_in && !empty($_pmr["ws_plugin__s2member_custom_reg_field_opt_in"]) ? true : $opt_in; if (!($fname = $user->first_name)) { if (!empty($_pmr["ws_plugin__s2member_custom_reg_field_first_name"])) { $fname = (string) $_pmr["ws_plugin__s2member_custom_reg_field_first_name"]; } } if (!$fname) { // Also try BuddyPress. if (!empty($_pmr["field_1"])) { // BuddyPress? $fname = trim(preg_replace("/ (.*)\$/", "", (string) $_pmr["field_1"])); } } if (!($lname = $user->last_name)) { if (!empty($_pmr["ws_plugin__s2member_custom_reg_field_last_name"])) { $lname = (string) $_pmr["ws_plugin__s2member_custom_reg_field_last_name"]; } } if (!$lname) { // Also try BuddyPress. if (!empty($_pmr["field_1"]) && preg_match("/^(.+?) (.+)\$/", (string) $_pmr["field_1"])) { $lname = trim(preg_replace("/^(.+?) (.+)\$/", "\$2", (string) $_pmr["field_1"])); } } if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_names"] && !$fname && $login) { $fname = trim($login); $lname = ""; } // Username and empty Last Name. $name = trim($fname . " " . $lname); // Both names. if (!($pass = $password)) { // Try s2Member's generator. if (!empty($GLOBALS["ws_plugin__s2member_generate_password_return"])) { $pass = (string) $GLOBALS["ws_plugin__s2member_generate_password_return"]; } } if (!$pass) { // Also try BuddyPress Password. if (!empty($_pmr["signup_password"])) { // BuddyPress? $pass = (string) $_pmr["signup_password"]; } } if ($pass) { !headers_sent() ? delete_user_setting("default_password_nag", $user_id) : null; update_user_option($user_id, "default_password_nag", false, true); } update_user_option($user_id, "s2member_registration_ip", $ip); update_user_option($user_id, "s2member_auto_eot_time", $auto_eot_time); update_user_option($user_id, "s2member_subscr_gateway", $subscr_gateway); update_user_option($user_id, "s2member_subscr_id", $subscr_id); update_user_option($user_id, "s2member_custom", $custom); update_user_option($user_id, "s2member_notes", $notes); if (!$user->first_name && $fname) { update_user_meta($user_id, "first_name", $fname); } if (!$user->last_name && $lname) { update_user_meta($user_id, "last_name", $lname); } if (!$user->display_name || $user->display_name === $user->user_login) { if ($custom_reg_display_name === "full" && $name) { wp_update_user(array("ID" => $user_id, "display_name" => $name)); } else { if ($custom_reg_display_name === "first" && $fname) { wp_update_user(array("ID" => $user_id, "display_name" => $fname)); } else { if ($custom_reg_display_name === "last" && $lname) { wp_update_user(array("ID" => $user_id, "display_name" => $lname)); } else { if ($custom_reg_display_name === "login" && $login) { wp_update_user(array("ID" => $user_id, "display_name" => $login)); } } } } } if (is_multisite()) { if (!is_main_site() && strtotime($user->user_registered) >= strtotime("-10 seconds")) { remove_user_from_blog($user_id, $current_site->blog_id); } // No Main Site Role. if (!get_user_meta($user_id, "s2member_originating_blog", true)) { // Recorded yet? update_user_meta($user_id, "s2member_originating_blog", $current_blog->blog_id); } } if ($current_role !== $role) { // Only if NOT the current Role. $user->set_role($role); } // s2Member. if ($ccaps && preg_match("/^-all/", str_replace("+", "", $ccaps))) { foreach ($user->allcaps as $cap => $cap_enabled) { if (preg_match("/^access_s2member_ccap_/", $cap)) { $user->remove_cap($ccap = $cap); } } } if ($ccaps && preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", $ccaps))) { foreach (preg_split("/[\r\n\t\\s;,]+/", preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", $ccaps))) as $ccap) { if (strlen($ccap = trim(strtolower(preg_replace("/[^a-z_0-9]/i", "", $ccap))))) { $user->add_cap("access_s2member_ccap_" . $ccap); } } } if (!($fields = array()) && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"]) { foreach (json_decode($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field) { $field_var = preg_replace("/[^a-z0-9]/i", "_", strtolower($field["id"])); $field_id_class = preg_replace("/_/", "-", $field_var); if (isset($_pmr["ws_plugin__s2member_custom_reg_field_" . $field_var])) { $fields[$field_var] = $_pmr["ws_plugin__s2member_custom_reg_field_" . $field_var]; } } } unset($field, $field_var, $field_id_class); // Housekeeping. if (!empty($fields)) { // Only if NOT empty. update_user_option($user_id, "s2member_custom_fields", $fields); } if ($level > 0) { $pr_times = get_user_option("s2member_paid_registration_times", $user_id); $pr_times["level"] = empty($pr_times["level"]) ? time() : $pr_times["level"]; $pr_times["level" . $level] = empty($pr_times["level" . $level]) ? time() : $pr_times["level" . $level]; update_user_option($user_id, "s2member_paid_registration_times", $pr_times); // Update now. } if (($transient = "s2m_" . md5("s2member_transient_ipn_signup_vars_" . $subscr_id)) && is_array($ipn_signup_vars = get_transient($transient))) { update_user_option($user_id, "s2member_ipn_signup_vars", $ipn_signup_vars); // For future reference. delete_transient($transient); // This can be deleted now. } if (($transient = "s2m_" . md5("s2member_transient_ipn_subscr_payment_" . $subscr_id)) && is_array($subscr_payment = get_transient($transient)) && !empty($subscr_payment["subscr_gateway"])) { $proxy = array("s2member_paypal_proxy" => stripslashes((string) $subscr_payment["subscr_gateway"]), "s2member_paypal_proxy_verification" => c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen()); c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), array_merge(stripslashes_deep($subscr_payment), $proxy), array("timeout" => 20)); delete_transient($transient); // This can be deleted now. } if (($transient = "s2m_" . md5("s2member_transient_ipn_subscr_eot_" . $subscr_id)) && is_array($subscr_eot = get_transient($transient)) && !empty($subscr_eot["subscr_gateway"])) { $proxy = array("s2member_paypal_proxy" => stripslashes((string) $subscr_eot["subscr_gateway"]), "s2member_paypal_proxy_verification" => c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen()); c_ws_plugin__s2member_utils_urls::remote(site_url("/?s2member_paypal_notify=1"), array_merge(stripslashes_deep($subscr_eot), $proxy), array("timeout" => 20)); delete_transient($transient); // This can be deleted now. } if (!headers_sent()) { // Only if headers are NOT yet sent. Here we establish both Signup and Payment Tracking Cookies. @setcookie("s2member_tracking", $s2member_tracking = c_ws_plugin__s2member_utils_encryption::encrypt($subscr_id), time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . @setcookie("s2member_tracking", $s2member_tracking, time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN) . ($_COOKIE["s2member_tracking"] = $s2member_tracking); } foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action("ws_plugin__s2member_during_configure_user_registration_front_side_paid", get_defined_vars()); do_action("ws_plugin__s2member_during_configure_user_registration_front_side", get_defined_vars()); unset($__refs, $__v); } else { if (!is_admin() && (!c_ws_plugin__s2member_utils_conds::pro_is_installed() || !c_ws_plugin__s2member_pro_remote_ops::is_remote_op("create_user"))) { /* This routine could be processed through `/wp-login.php?action=register`, `/wp-activate.php`, or `/activate` via BuddyPress`. This may also be processed through a standard BuddyPress installation, or another plugin calling `user_register`. If processed through `/wp-activate.php`, it could've originated inside the admin, via `/user-new.php`. */ $processed = "yes"; // Mark this as yes. $current_role = c_ws_plugin__s2member_user_access::user_access_role($user); $role = ""; // Initialize ``$role`` to an empty string here, before processing. $role = !$role && ($level = (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_level"]) > 0 ? "s2member_level" . $level : $role; $role = !$role && ($level = (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_level"]) === "0" ? "subscriber" : $role; $role = !$role && $current_role ? $current_role : $role; // Use existing Role? $role = !$role ? get_option("default_role") : $role; // Otherwise default. $level = (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_level"]; $level = !$level && preg_match("/^(administrator|editor|author|contributor)\$/i", $role) ? $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"] : $level; $level = !$level && preg_match("/^s2member_level[1-9][0-9]*\$/i", $role) ? preg_replace("/^s2member_level/", "", $role) : $level; $level = !$level && preg_match("/^subscriber\$/i", $role) ? "0" : $level; $level = !$level ? "0" : $level; $ccaps = (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_ccaps"]; $email = $user->user_email; $login = $user->user_login; $ip = (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_registration_ip"]; $ip = !$ip ? $_SERVER["REMOTE_ADDR"] : $ip; // Else use environment variable. $custom = (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_custom"]; $subscr_id = (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_subscr_id"]; $subscr_gateway = (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_subscr_gateway"]; $cv = preg_split("/\\|/", (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_custom"]); $auto_eot_time = ($eot = (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_auto_eot_time"]) ? strtotime($eot) : ""; $notes = (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_notes"]; $opt_in = !$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_opt_in"] ? true : false; $opt_in = !$opt_in && !empty($_pmr["ws_plugin__s2member_custom_reg_field_opt_in"]) ? true : $opt_in; if (!($fname = $user->first_name)) { if (!empty($_pmr["ws_plugin__s2member_custom_reg_field_first_name"])) { $fname = (string) $_pmr["ws_plugin__s2member_custom_reg_field_first_name"]; } } if (!$fname) { // Also try BuddyPress. if (!empty($_pmr["field_1"])) { // BuddyPress? $fname = trim(preg_replace("/ (.*)\$/", "", (string) $_pmr["field_1"])); } } if (!($lname = $user->last_name)) { if (!empty($_pmr["ws_plugin__s2member_custom_reg_field_last_name"])) { $lname = (string) $_pmr["ws_plugin__s2member_custom_reg_field_last_name"]; } } if (!$lname) { // Also try BuddyPress. if (!empty($_pmr["field_1"]) && preg_match("/^(.+?) (.+)\$/", (string) $_pmr["field_1"])) { $lname = trim(preg_replace("/^(.+?) (.+)\$/", "\$2", (string) $_pmr["field_1"])); } } if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_names"] && !$fname && $login) { $fname = trim($login); $lname = ""; } // Username and empty Last Name. $name = trim($fname . " " . $lname); // Both names. if (!($pass = $password)) { // Try s2Member's generator. if (!empty($GLOBALS["ws_plugin__s2member_generate_password_return"])) { $pass = (string) $GLOBALS["ws_plugin__s2member_generate_password_return"]; } } if (!$pass) { // Also try BuddyPress Password. if (!empty($_pmr["signup_password"])) { // BuddyPress? $pass = (string) $_pmr["signup_password"]; } } if ($pass) { !headers_sent() ? delete_user_setting("default_password_nag", $user_id) : null; update_user_option($user_id, "default_password_nag", false, true); } update_user_option($user_id, "s2member_registration_ip", $ip); update_user_option($user_id, "s2member_auto_eot_time", $auto_eot_time); update_user_option($user_id, "s2member_subscr_gateway", $subscr_gateway); update_user_option($user_id, "s2member_subscr_id", $subscr_id); update_user_option($user_id, "s2member_custom", $custom); update_user_option($user_id, "s2member_notes", $notes); if (!$user->first_name && $fname) { update_user_meta($user_id, "first_name", $fname); } if (!$user->last_name && $lname) { update_user_meta($user_id, "last_name", $lname); } if (!$user->display_name || $user->display_name === $user->user_login) { if ($custom_reg_display_name === "full" && $name) { wp_update_user(array("ID" => $user_id, "display_name" => $name)); } else { if ($custom_reg_display_name === "first" && $fname) { wp_update_user(array("ID" => $user_id, "display_name" => $fname)); } else { if ($custom_reg_display_name === "last" && $lname) { wp_update_user(array("ID" => $user_id, "display_name" => $lname)); } else { if ($custom_reg_display_name === "login" && $login) { wp_update_user(array("ID" => $user_id, "display_name" => $login)); } } } } } if (is_multisite()) { if (!is_main_site() && strtotime($user->user_registered) >= strtotime("-10 seconds")) { remove_user_from_blog($user_id, $current_site->blog_id); } if (!get_user_meta($user_id, "s2member_originating_blog", true)) { update_user_meta($user_id, "s2member_originating_blog", $current_blog->blog_id); } } if ($current_role !== $role) { // Only if NOT the current Role. $user->set_role($role); } // s2Member. if ($ccaps && preg_match("/^-all/", str_replace("+", "", $ccaps))) { foreach ($user->allcaps as $cap => $cap_enabled) { if (preg_match("/^access_s2member_ccap_/", $cap)) { $user->remove_cap($ccap = $cap); } } } if ($ccaps && preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", $ccaps))) { foreach (preg_split("/[\r\n\t\\s;,]+/", preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", $ccaps))) as $ccap) { if (strlen($ccap = trim(strtolower(preg_replace("/[^a-z_0-9]/i", "", $ccap))))) { $user->add_cap("access_s2member_ccap_" . $ccap); } } } if (!($fields = array()) && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"]) { foreach (json_decode($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field) { $field_var = preg_replace("/[^a-z0-9]/i", "_", strtolower($field["id"])); $field_id_class = preg_replace("/_/", "-", $field_var); if (isset($_pmr["ws_plugin__s2member_custom_reg_field_" . $field_var])) { $fields[$field_var] = $_pmr["ws_plugin__s2member_custom_reg_field_" . $field_var]; } } } unset($field, $field_var, $field_id_class); // Housekeeping. if (!empty($fields)) { // Only if NOT empty. update_user_option($user_id, "s2member_custom_fields", $fields); } if ($level > 0) { $pr_times = get_user_option("s2member_paid_registration_times", $user_id); $pr_times["level"] = empty($pr_times["level"]) ? time() : $pr_times["level"]; $pr_times["level" . $level] = empty($pr_times["level" . $level]) ? time() : $pr_times["level" . $level]; update_user_option($user_id, "s2member_paid_registration_times", $pr_times); // Update now. } foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action("ws_plugin__s2member_during_configure_user_registration_front_side_free", get_defined_vars()); do_action("ws_plugin__s2member_during_configure_user_registration_front_side", get_defined_vars()); unset($__refs, $__v); } else { if (is_blog_admin() && $pagenow === "user-new.php" || c_ws_plugin__s2member_utils_conds::pro_is_installed() && c_ws_plugin__s2member_pro_remote_ops::is_remote_op("create_user")) { // Can only be processed through `/user-new.php` in the Admin panel, or through Remote Op: `create_user`. $processed = "yes"; // Mark this as yes, to indicate that a routine was processed. $current_role = c_ws_plugin__s2member_user_access::user_access_role($user); $role = ""; // Initialize $role to an empty string here, before processing. $role = !$role && ($level = (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_level"]) > 0 ? "s2member_level" . $level : $role; $role = !$role && ($level = (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_level"]) === "0" ? "subscriber" : $role; $role = !$role && $current_role ? $current_role : $role; // Use existing Role? $role = !$role ? get_option("default_role") : $role; // Otherwise default. $level = (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_level"]; $level = !$level && preg_match("/^(administrator|editor|author|contributor)\$/i", $role) ? $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"] : $level; $level = !$level && preg_match("/^s2member_level[1-9][0-9]*\$/i", $role) ? preg_replace("/^s2member_level/", "", $role) : $level; $level = !$level && preg_match("/^subscriber\$/i", $role) ? "0" : $level; $level = !$level ? "0" : $level; $ccaps = (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_ccaps"]; $email = $user->user_email; $login = $user->user_login; $ip = (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_registration_ip"]; $custom = (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_custom"]; $subscr_id = (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_subscr_id"]; $subscr_gateway = (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_subscr_gateway"]; $cv = preg_split("/\\|/", (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_custom"]); $auto_eot_time = ($eot = (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_auto_eot_time"]) ? strtotime($eot) : ""; $notes = (string) @$_pmr["ws_plugin__s2member_custom_reg_field_s2member_notes"]; $opt_in = !empty($_pmr["ws_plugin__s2member_custom_reg_field_opt_in"]) ? true : false; if (!($fname = $user->first_name)) { // `Users -› Add New`. if (!empty($_pmr["ws_plugin__s2member_custom_reg_field_first_name"])) { $fname = (string) $_pmr["ws_plugin__s2member_custom_reg_field_first_name"]; } } if (!($lname = $user->last_name)) { // `Users -› Add New`. if (!empty($_pmr["ws_plugin__s2member_custom_reg_field_last_name"])) { $lname = (string) $_pmr["ws_plugin__s2member_custom_reg_field_last_name"]; } } if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_names"] && !$fname && $login) { $fname = trim($login); $lname = ""; } // Username and empty Last Name. $name = trim($fname . " " . $lname); // Both names. if (!($pass = $password)) { // Try s2Member's generator. if (!empty($GLOBALS["ws_plugin__s2member_generate_password_return"])) { $pass = (string) $GLOBALS["ws_plugin__s2member_generate_password_return"]; } } if (!$pass) { // Also try the `Users -› Add New` form. if (!empty($_pmr["pass1"])) { // Field in `/user-new.php`. $pass = (string) $_pmr["pass1"]; } } if ($pass) { !headers_sent() ? delete_user_setting("default_password_nag", $user_id) : null; update_user_option($user_id, "default_password_nag", false, true); } update_user_option($user_id, "s2member_registration_ip", $ip); update_user_option($user_id, "s2member_auto_eot_time", $auto_eot_time); update_user_option($user_id, "s2member_subscr_gateway", $subscr_gateway); update_user_option($user_id, "s2member_subscr_id", $subscr_id); update_user_option($user_id, "s2member_custom", $custom); update_user_option($user_id, "s2member_notes", $notes); if (!$user->first_name && $fname) { update_user_meta($user_id, "first_name", $fname); } if (!$user->last_name && $lname) { update_user_meta($user_id, "last_name", $lname); } if (!$user->display_name || $user->display_name === $user->user_login) { if ($custom_reg_display_name === "full" && $name) { wp_update_user(array("ID" => $user_id, "display_name" => $name)); } else { if ($custom_reg_display_name === "first" && $fname) { wp_update_user(array("ID" => $user_id, "display_name" => $fname)); } else { if ($custom_reg_display_name === "last" && $lname) { wp_update_user(array("ID" => $user_id, "display_name" => $lname)); } else { if ($custom_reg_display_name === "login" && $login) { wp_update_user(array("ID" => $user_id, "display_name" => $login)); } } } } } if (is_multisite()) { if (!is_main_site() && strtotime($user->user_registered) >= strtotime("-10 seconds")) { remove_user_from_blog($user_id, $current_site->blog_id); } // No Main Site Role. if (!get_user_meta($user_id, "s2member_originating_blog", true)) { // Recorded yet? update_user_meta($user_id, "s2member_originating_blog", $current_blog->blog_id); } } if ($current_role !== $role) { // Only if NOT the current Role. $user->set_role($role); } // s2Member. if ($ccaps && preg_match("/^-all/", str_replace("+", "", $ccaps))) { foreach ($user->allcaps as $cap => $cap_enabled) { if (preg_match("/^access_s2member_ccap_/", $cap)) { $user->remove_cap($ccap = $cap); } } } if ($ccaps && preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", $ccaps))) { foreach (preg_split("/[\r\n\t\\s;,]+/", preg_replace("/^-all[\r\n\t\\s;,]*/", "", str_replace("+", "", $ccaps))) as $ccap) { if (strlen($ccap = trim(strtolower(preg_replace("/[^a-z_0-9]/i", "", $ccap))))) { $user->add_cap("access_s2member_ccap_" . $ccap); } } } if (!($fields = array()) && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"]) { foreach (json_decode($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field) { $field_var = preg_replace("/[^a-z0-9]/i", "_", strtolower($field["id"])); $field_id_class = preg_replace("/_/", "-", $field_var); if (isset($_pmr["ws_plugin__s2member_custom_reg_field_" . $field_var])) { $fields[$field_var] = $_pmr["ws_plugin__s2member_custom_reg_field_" . $field_var]; } } } unset($field, $field_var, $field_id_class); // Housekeeping. if (!empty($fields)) { // Only if NOT empty. update_user_option($user_id, "s2member_custom_fields", $fields); } if ($level > 0) { $pr_times = get_user_option("s2member_paid_registration_times", $user_id); $pr_times["level"] = empty($pr_times["level"]) ? time() : $pr_times["level"]; $pr_times["level" . $level] = empty($pr_times["level" . $level]) ? time() : $pr_times["level" . $level]; update_user_option($user_id, "s2member_paid_registration_times", $pr_times); // Update now. } foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action("ws_plugin__s2member_during_configure_user_registration_admin_side", get_defined_vars()); unset($__refs, $__v); } } } if ($processed === "yes") { if ($urls = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["registration_notification_urls"]) { foreach (preg_split("/[\r\n\t]+/", $urls) as $url) { // Notify each of the URLs. if ($url = preg_replace("/%%cv([0-9]+)%%/ei", 'urlencode(trim($cv[$1]))', $url)) { if ($url = preg_replace("/%%role%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($role)), $url)) { if ($url = preg_replace("/%%level%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($level)), $url)) { if ($url = preg_replace("/%%ccaps%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($ccaps)), $url)) { if ($url = preg_replace("/%%auto_eot_time%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($auto_eot_time)), $url)) { if ($url = preg_replace("/%%user_first_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($fname)), $url)) { if ($url = preg_replace("/%%user_last_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($lname)), $url)) { if ($url = preg_replace("/%%user_full_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($name)), $url)) { if ($url = preg_replace("/%%user_email%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($email)), $url)) { if ($url = preg_replace("/%%user_login%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($login)), $url)) { if ($url = preg_replace("/%%user_pass%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($pass)), $url)) { if ($url = preg_replace("/%%user_ip%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($ip)), $url)) { if ($url = preg_replace("/%%user_id%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($user_id)), $url)) { foreach ($fields as $var => $val) { // Custom Fields. if (!($url = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode(maybe_serialize($val))), $url))) { break; } } if ($url = trim(preg_replace("/%%(.+?)%%/i", "", $url))) { c_ws_plugin__s2member_utils_urls::remote($url); } } } } } } } } } } } } } } } } unset($urls, $url, $var, $val); // Housekeeping. if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["registration_notification_recipients"]) { $email_configs_were_on = c_ws_plugin__s2member_email_configs::email_config_status(); c_ws_plugin__s2member_email_configs::email_config_release(); $msg = $sbj = "(s2Member / API Notification Email) - Registration"; $msg .= "\n\n"; // Spacing in the message body. $msg .= "role: %%role%%\n"; $msg .= "level: %%level%%\n"; $msg .= "ccaps: %%ccaps%%\n"; $msg .= "auto_eot_time: %%auto_eot_time%%\n"; $msg .= "user_first_name: %%user_first_name%%\n"; $msg .= "user_last_name: %%user_last_name%%\n"; $msg .= "user_full_name: %%user_full_name%%\n"; $msg .= "user_email: %%user_email%%\n"; $msg .= "user_login: %%user_login%%\n"; $msg .= "user_pass: %%user_pass%%\n"; $msg .= "user_ip: %%user_ip%%\n"; $msg .= "user_id: %%user_id%%\n"; foreach ($fields as $var => $val) { $msg .= $var . ": %%" . $var . "%%\n"; } $msg .= "cv0: %%cv0%%\n"; $msg .= "cv1: %%cv1%%\n"; $msg .= "cv2: %%cv2%%\n"; $msg .= "cv3: %%cv3%%\n"; $msg .= "cv4: %%cv4%%\n"; $msg .= "cv5: %%cv5%%\n"; $msg .= "cv6: %%cv6%%\n"; $msg .= "cv7: %%cv7%%\n"; $msg .= "cv8: %%cv8%%\n"; $msg .= "cv9: %%cv9%%"; if ($msg = preg_replace("/%%cv([0-9]+)%%/ei", 'trim($cv[$1])', $msg)) { if ($msg = preg_replace("/%%role%%/i", c_ws_plugin__s2member_utils_strings::esc_ds($role), $msg)) { if ($msg = preg_replace("/%%level%%/i", c_ws_plugin__s2member_utils_strings::esc_ds($level), $msg)) { if ($msg = preg_replace("/%%ccaps%%/i", c_ws_plugin__s2member_utils_strings::esc_ds($ccaps), $msg)) { if ($msg = preg_replace("/%%auto_eot_time%%/i", c_ws_plugin__s2member_utils_strings::esc_ds($auto_eot_time), $msg)) { if ($msg = preg_replace("/%%user_first_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds($fname), $msg)) { if ($msg = preg_replace("/%%user_last_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds($lname), $msg)) { if ($msg = preg_replace("/%%user_full_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds($name), $msg)) { if ($msg = preg_replace("/%%user_email%%/i", c_ws_plugin__s2member_utils_strings::esc_ds($email), $msg)) { if ($msg = preg_replace("/%%user_login%%/i", c_ws_plugin__s2member_utils_strings::esc_ds($login), $msg)) { if ($msg = preg_replace("/%%user_pass%%/i", c_ws_plugin__s2member_utils_strings::esc_ds($pass), $msg)) { if ($msg = preg_replace("/%%user_ip%%/i", c_ws_plugin__s2member_utils_strings::esc_ds($ip), $msg)) { if ($msg = preg_replace("/%%user_id%%/i", c_ws_plugin__s2member_utils_strings::esc_ds($user_id), $msg)) { foreach ($fields as $var => $val) { // Custom Fields. if (!($msg = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(maybe_serialize($val)), $msg))) { break; } } if ($sbj && ($msg = trim(preg_replace("/%%(.+?)%%/i", "", $msg)))) { // Still have a ``$sbj`` and a ``$msg``? foreach (c_ws_plugin__s2member_utils_strings::parse_emails($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["registration_notification_recipients"]) as $recipient) { wp_mail($recipient, apply_filters("ws_plugin__s2member_registration_notification_email_sbj", $sbj, get_defined_vars()), apply_filters("ws_plugin__s2member_registration_notification_email_msg", $msg, get_defined_vars()), "Content-Type: text/plain; charset=UTF-8"); } } } } } } } } } } } } } } } if ($email_configs_were_on) { // Back on? c_ws_plugin__s2member_email_configs::email_config(); } unset($sbj, $msg, $var, $val, $recipient, $email_configs_were_on); // Housekeeping. } if ($url = $GLOBALS["ws_plugin__s2member_registration_return_url"]) { if ($url = preg_replace("/%%cv([0-9]+)%%/ei", 'urlencode(trim($cv[$1]))', $url)) { if ($url = preg_replace("/%%role%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($role)), $url)) { if ($url = preg_replace("/%%level%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($level)), $url)) { if ($url = preg_replace("/%%ccaps%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($ccaps)), $url)) { if ($url = preg_replace("/%%auto_eot_time%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($auto_eot_time)), $url)) { if ($url = preg_replace("/%%user_first_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($fname)), $url)) { if ($url = preg_replace("/%%user_last_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($lname)), $url)) { if ($url = preg_replace("/%%user_full_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($name)), $url)) { if ($url = preg_replace("/%%user_email%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($email)), $url)) { if ($url = preg_replace("/%%user_login%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($login)), $url)) { if ($url = preg_replace("/%%user_pass%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($pass)), $url)) { if ($url = preg_replace("/%%user_ip%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($ip)), $url)) { if ($url = preg_replace("/%%user_id%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode($user_id)), $url)) { foreach ($fields as $var => $val) { // Custom Fields. if (!($url = preg_replace("/%%" . preg_quote($var, "/") . "%%/i", c_ws_plugin__s2member_utils_strings::esc_ds(urlencode(maybe_serialize($val))), $url))) { break; } } if ($url = trim($url)) { // Preserve remaining Replacements; because the parent routine may perform replacements too. $GLOBALS["ws_plugin__s2member_registration_return_url"] = $url; } } } } } } } } } } } } } } } unset($url, $var, $val); // Housekeeping. c_ws_plugin__s2member_list_servers::process_list_servers($role, $level, $login, $pass, $email, $fname, $lname, $ip, $opt_in, true, $user_id); /* Suppress errors here in case this routine is fired in unexpected locations; or with odd output buffering techniques. @todo It may also be impossible to delete cookies when fired inside: `/wp-activate.php`. */ if (!headers_sent()) { @setcookie("s2member_subscr_gateway", "", time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . @setcookie("s2member_subscr_gateway", "", time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN); @setcookie("s2member_subscr_id", "", time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . @setcookie("s2member_subscr_id", "", time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN); @setcookie("s2member_custom", "", time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . @setcookie("s2member_custom", "", time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN); @setcookie("s2member_item_number", "", time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . @setcookie("s2member_item_number", "", time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN); } /* If debugging/logging is enabled; we need to append ``$reg_vars`` to the log file. Logging now supports Multisite Networking as well. */ $reg_vars = get_defined_vars(); // All defined vars. // No need to include these in the logs. Unset before log entry. unset($reg_vars["wpdb"], $reg_vars["current_site"], $reg_vars["current_blog"]); $logt = c_ws_plugin__s2member_utilities::time_details(); $logv = c_ws_plugin__s2member_utilities::ver_details(); $logm = c_ws_plugin__s2member_utilities::mem_details(); $log4 = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nUser-Agent: " . $_SERVER["HTTP_USER_AGENT"]; $log4 = is_multisite() && !is_main_site() ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4; $log2 = is_multisite() && !is_main_site() ? "reg-handler-4-" . trim(preg_replace("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "reg-handler.log"; if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["gateway_debug_logs"]) { if (is_dir($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"])) { if (is_writable($logs_dir) && c_ws_plugin__s2member_utils_logs::archive_oversize_log_files()) { file_put_contents($logs_dir . "/" . $log2, "LOG ENTRY: " . $logt . "\n" . $logv . "\n" . $logm . "\n" . $log4 . "\n" . c_ws_plugin__s2member_utils_logs::conceal_private_info(var_export($reg_vars, true)) . "\n\n", FILE_APPEND); } } } unset($logt, $logv, $logm, $log4, $_log4, $log2, $logs_dir, $reg_vars); // Housekeeping. foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action("ws_plugin__s2member_during_configure_user_registration", get_defined_vars()); unset($__refs, $__v); } } } } } } } } foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action("ws_plugin__s2member_after_configure_user_registration", get_defined_vars()); unset($__refs, $__v); return; }
function lti_parse_request_OLD($wp) { if (!is_basic_lti_request()) { $good_message_type = $_REQUEST[LTI_MESSAGE_TYPE] == LTI_MESSAGE_TYPE_VALUE; $good_lti_version = $_REQUEST[LTI_VERSION] == LTI_VERSION_VALUE; $resource_link_id = $_REQUEST[RESOURCE_LINK_ID]; if ($good_message_type && $good_lti_version && !isset($resource_link_id)) { $launch_presentation_return_url = $_REQUEST[LAUNCH_PRESENTATION_URL]; if (isset($launch_presentation_return_url)) { header('Location: ' . $launch_presentation_return_url); exit; } } return; } // See if we get a context, do not set session, do not redirect $secret = lti_get_secret_from_consumer_key(); $context = new bltiUocWrapper(false, false, null, $secret); if (!$context->valid) { //var_dump($_POST); echo "<hr>OAuthUtil::urldecode_rfc3986('%2B') " . OAuthUtil::urldecode_rfc3986('%2B') . "<br>"; echo "<hr>OAuthUtil::urldecode_rfc3986('%5C') " . OAuthUtil::urldecode_rfc3986('%5C') . "<br>"; wp_die("BASIC LTI Authentication Failed, not valid request (make sure that consumer is authorized and secret is correct) " . $context->message); return; } $error = is_lti_error_data($context); if ($error !== FALSE) { $launch_presentation_return_url = $_REQUEST[LAUNCH_PRESENTATION_URL]; if (isset($launch_presentation_return_url)) { $error = '<p>' . $error . '</p><p>Return to site <a href="' . $launch_presentation_return_url . '">' . $launch_presentation_return_url . '</a></p>'; } wp_die($error, ''); } $blogType = new blogTypeLoader($context); if ($blogType->error < 0) { wp_die("BASIC LTI loading Types Aula Failed " . $blogType->error_miss); return; } // Set up the user... $userkey = getUserkeyLTI($context); $userkey = apply_filters('pre_user_login', $userkey); $userkey = trim($userkey); if (empty($userkey)) { wp_die('<p>Empty username</p><p>Cannot create a user without username</p>'); } $uinfo = get_user_by('login', $userkey); if (isset($uinfo) && $uinfo != false) { // og LTI: set the user_login and user_nicename to the same value, // , because we want the wordpress-login cookie to have the username // otherwise caching won't work properly! $ret_id = wp_insert_user(array('ID' => $uinfo->ID, 'user_login' => $userkey, 'user_nicename' => $userkey, 'first_name' => $context->getUserFirstName(), 'last_name' => $context->getUserLastName(), 'user_email' => $context->getUserEmail(), 'user_url' => 'http://b', 'display_name' => $context->getUserName(), 'role' => get_option('default_role'))); //error_log("og old role is set"); if (is_object($ret_id) && isset($ret_id->errors)) { $msg = ''; foreach ($ret_id->errors as $key => $error) { $msg .= "<p><b>{$key}</b> "; foreach ($error as $erroMsg) { $msg .= "<p> {$erroMsg}</p>"; } $msg .= "</p>"; } wp_die($msg); } } else { // new user!!!! $ret_id = wp_insert_user(array('user_login' => $userkey, 'user_nicename' => $context->getUserName(), 'first_name' => $context->getUserFirstName(), 'last_name' => $context->getUserLastName(), 'user_email' => $context->getUserEmail(), 'user_url' => 'http://c', 'display_name' => $context->getUserName())); if (is_object($ret_id) && isset($ret_id->errors)) { $msg = ''; foreach ($ret_id->errors as $key => $error) { $msg .= "<p><b>{$key}</b> "; foreach ($error as $erroMsg) { $msg .= "<p> {$erroMsg}</p>"; } $msg .= "</p>"; } wp_die($msg); } $uinfo = get_user_by('login', $userkey); } //Eliminem del blog Principal (si no es admin) http://jira.uoc.edu/jira/browse/BLOGA-218 if (!$is_admin) { $user = new WP_User($uinfo->ID); $user->remove_all_caps(); } $_SERVER['REMOTE_USER'] = $userkey; $password = md5($uinfo->user_pass); // User is now authorized; force WordPress to use the generated password //login, set cookies, and set current user wp_authenticate($userkey, $password); wp_set_auth_cookie($user->ID, false); wp_set_current_user($user->ID, $userkey); $siteUrl = substr(get_option("siteurl"), 7); // - "http://" $siteUrlArray = explode("/", $siteUrl); $domain = $siteUrlArray[0]; unset($siteUrlArray[0]); //error_log("og LTI domain: ". $domain); $course = $blogType->getCoursePath($context, $siteUrlArray, $domain); if (isset($context->info[RESOURCE_LINK_ID]) && $context->info[RESOURCE_LINK_ID]) { $course .= '-' . $context->info[RESOURCE_LINK_ID]; } $course = sanitize_user($course, true); //Bug wordpress doesn't get stye sheet if has a dot $course = str_replace('.', '_', $course); $path_base = "/" . implode("/", $siteUrlArray) . "/" . $course; $path_base = str_replace('//', '/', $path_base); $path = $path_base . "/"; $path = str_replace('//', '/', $path); $blog_created = false; $overwrite_plugins_theme = isset($context->info[OVERWRITE_PLUGINS_THEME]) ? $context->info[OVERWRITE_PLUGINS_THEME] == 1 : false; $overwrite_roles = isset($context->info[OVERWRITE_ROLES]) ? $context->info[OVERWRITE_ROLES] == 1 : false; $blog_id = domain_exists($domain, $path); $blog_is_new = false; if (!isset($blog_id)) { $title = __("Blog ") . $blogType->getCourseName($context); $blog_is_new = true; $meta = $blogType->getMetaBlog($context); $old_site_language = get_site_option('WPLANG'); $blogType->setLanguage($context); $blog_id = wpmu_create_blog($domain, $path, $title, $user_id, $meta); update_site_option('WPLANG', $old_site_language); $blogType->checkErrorCreatingBlog($blog_id, $path); $blog_created = true; } // Connect the user to the blog if (isset($blog_id)) { switch_to_blog($blog_id); ob_start(); if ($overwrite_plugins_theme || $blog_created) { $blogType->loadPlugins(); $blogType->changeTheme(); } //Agafem el rol anterior $old_role = null; if (!$blog_created && !$overwrite_roles) { $old_role_array = get_usermeta($user->id, 'wp_' . $blog_id . '_capabilities'); if (count($old_role_array) > 0) { foreach ($old_role_array as $key => $value) { if ($value == true) { $old_role = $key; } } } } remove_user_from_blog($uinfo->ID, $blog_id); $obj = new stdClass(); $obj->blog_id = $blog_id; $obj->userkey = $userkey; $obj->path_base = $path_base; $obj->domain = $domain; $obj->context = $context; $obj->uinfoID = $uinfo->ID; $obj->blog_is_new = $blog_is_new; if ($overwrite_roles || $old_role == null) { $obj->role = $blogType->roleMapping($context->info[FIELD_ROLE_UOC_CAMPUS], $context->info); } else { $obj->role = $old_role; } $blogType->postActions($obj); add_user_to_blog($blog_id, $uinfo->ID, $obj->role); //Si posem el restore_current_blog ens va al principi // restore_current_blog(); ob_end_clean(); } $redirecturl = get_option("siteurl"); //error_log("og LTI redirect URL: ".$redirecturl); $redirecturl = str_replace("http://", "https://", $redirecturl); //error_log("og LTI new redirect URL: ".$redirecturl); wp_redirect($redirecturl); exit; }
function wpmu_delete_user($id) { global $wpdb; $id = (int) $id; $user = get_userdata($id); do_action('wpmu_delete_user', $id); $blogs = get_blogs_of_user($id); if (!empty($blogs)) { foreach ($blogs as $blog) { switch_to_blog($blog->userblog_id); remove_user_from_blog($id, $blog->userblog_id); $post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d", $id)); foreach ((array) $post_ids as $post_id) { wp_delete_post($post_id); } // Clean links $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->links} WHERE link_owner = %d", $id)); restore_current_blog(); } } $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->users} WHERE ID = %d", $id)); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id = %d", $id)); wp_cache_delete($id, 'users'); wp_cache_delete($user->user_login, 'userlogins'); return true; }
/** * Remove a user's role. * * ## OPTIONS * * <user> * : User ID, user email, or user login. * * [<role>] * : A specific role to remove. * * ## EXAMPLES * * $ wp user remove-role 12 author * Success: Removed 'author' role for johndoe (12). * * @subcommand remove-role */ public function remove_role($args, $assoc_args) { $user = $this->fetcher->get_check($args[0]); if (isset($args[1])) { $role = $args[1]; self::validate_role($role); $user->remove_role($role); WP_CLI::success(sprintf("Removed '%s' role for %s (%d).", $role, $user->user_login, $user->ID)); } else { // Multisite if (function_exists('remove_user_from_blog')) { remove_user_from_blog($user->ID, get_current_blog_id()); } else { $user->remove_all_caps(); } WP_CLI::success("Removed {$user->user_login} ({$user->ID}) from " . site_url() . "."); } }
/** * Processed by WP_Cron; this handles Auto-EOTs *(EOT = End Of Term)*. * * If you have a HUGE userbase, increase the max EOTs per process. * But NOTE, this runs ``$per_process`` *(per Blog)* on a Multisite Network. * To increase, use: ``add_filter ('ws_plugin__s2member_auto_eot_system_per_process');``. * * This function makes an important Hook available: `ws_plugin__s2member_after_auto_eot_system`. * This Hook is used by some of s2Member Pro's Gateway integrations; allowing CRON processing * to run for important communications; which poll Payment Gateway APIs for possible EOTs. * * @package s2Member\Auto_EOT_System * @since 3.5 * * @param int $per_process Number of database records to process each time. * Can also be Filtered with `ws_plugin__s2member_auto_eot_system_per_process`. * * @return null */ public static function auto_eot_system($per_process = 6) { global $wpdb; /** @var $wpdb \wpdb */ global $current_site, $current_blog; include_once ABSPATH . 'wp-admin/includes/admin.php'; @set_time_limit(0); // Make time for processing a larger userbase. @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_before_auto_eot_system', get_defined_vars()); unset($__refs, $__v); // Housekeeping. if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['auto_eot_system_enabled']) { $per_process = apply_filters('ws_plugin__s2member_auto_eot_system_per_process', $per_process, get_defined_vars()); if (is_array($eots = $wpdb->get_results("SELECT `user_id` AS `ID` FROM `" . $wpdb->usermeta . "` WHERE `meta_key` = '" . $wpdb->prefix . "s2member_auto_eot_time' AND `meta_value` != '' AND `meta_value` <= '" . esc_sql(strtotime("now")) . "' LIMIT " . $per_process))) { foreach ($eots as $eot) { if (($user_id = $eot->ID) && is_object($user = new WP_User($user_id)) && $user->ID) { $auto_eot_time = get_user_option('s2member_auto_eot_time', $user_id); delete_user_option($user_id, 's2member_last_auto_eot_time'); delete_user_option($user_id, 's2member_auto_eot_time'); if (!$user->has_cap('administrator')) { if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['membership_eot_behavior'] === 'demote') { $eot_del_type = 'auto-eot-cancellation-expiration-demotion'; // Set EOT/Del type. $custom = get_user_option('s2member_custom', $user_id); $subscr_gateway = get_user_option('s2member_subscr_gateway', $user_id); $subscr_id = get_user_option('s2member_subscr_id', $user_id); $subscr_baid = get_user_option('s2member_subscr_baid', $user_id); $subscr_cid = get_user_option('s2member_subscr_cid', $user_id); $fields = get_user_option('s2member_custom_fields', $user_id); $user_reg_ip = get_user_option('s2member_registration_ip', $user_id); $ipn_signup_vars = get_user_option('s2member_ipn_signup_vars', $user_id); $demotion_role = c_ws_plugin__s2member_option_forces::force_demotion_role('subscriber'); $existing_role = c_ws_plugin__s2member_user_access::user_access_role($user); foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_during_auto_eot_system_during_before_demote', get_defined_vars()); do_action('ws_plugin__s2member_during_collective_mods', $user_id, get_defined_vars(), $eot_del_type, 'modification', $demotion_role); do_action('ws_plugin__s2member_during_collective_eots', $user_id, get_defined_vars(), $eot_del_type, 'modification'); unset($__refs, $__v); // Housekeeping. if ($existing_role !== $demotion_role) { $user->set_role($demotion_role); } if (apply_filters('ws_plugin__s2member_remove_ccaps_during_eot_events', (bool) $GLOBALS['WS_PLUGIN__']['s2member']['o']['eots_remove_ccaps'], get_defined_vars())) { foreach ($user->allcaps as $cap => $cap_enabled) { if (preg_match('/^access_s2member_ccap_/', $cap)) { $user->remove_cap($ccap = $cap); } } } delete_user_option($user_id, 's2member_subscr_gateway'); delete_user_option($user_id, 's2member_subscr_id'); delete_user_option($user_id, 's2member_subscr_baid'); delete_user_option($user_id, 's2member_subscr_cid'); delete_user_option($user_id, 's2member_ipn_signup_vars'); if (!apply_filters('ws_plugin__s2member_preserve_paid_registration_times', TRUE)) { delete_user_option($user_id, 's2member_paid_registration_times'); } delete_user_option($user_id, 's2member_last_status_scan'); delete_user_option($user_id, 's2member_first_payment_txn_id'); delete_user_option($user_id, 's2member_last_payment_time'); delete_user_option($user_id, 's2member_last_auto_eot_time'); delete_user_option($user_id, 's2member_auto_eot_time'); delete_user_option($user_id, 's2member_file_download_access_log'); delete_user_option($user_id, 's2member_authnet_payment_failures'); update_user_option($user_id, 's2member_last_auto_eot_time', $auto_eot_time); c_ws_plugin__s2member_user_notes::append_user_notes($user_id, 'Demoted by s2Member: ' . date('D M j, Y g:i a T')); if ($subscr_gateway && $subscr_id) { // Also note the Paid Subscr. Gateway/ID so there is a reference left behind here. c_ws_plugin__s2member_user_notes::append_user_notes($user_id, 'Paid Subscr. ID @ time of demotion: ' . $subscr_gateway . ' → ' . $subscr_id); } if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['eot_del_notification_urls'] && is_array($cv = preg_split('/\\|/', $custom))) { foreach (preg_split('/[' . "\r\n\t" . ']+/', $GLOBALS['WS_PLUGIN__']['s2member']['o']['eot_del_notification_urls']) as $url) { // Handle EOT Notifications. if (($url = preg_replace('/%%cv([0-9]+)%%/ei', 'urlencode(trim(@$cv[$1]))', $url)) && ($url = preg_replace('/%%eot_del_type%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode('auto-eot-cancellation-expiration-demotion')), $url)) && ($url = preg_replace('/%%subscr_id%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($subscr_id)), $url))) { if (($url = preg_replace('/%%user_first_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($user->first_name)), $url)) && ($url = preg_replace('/%%user_last_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($user->last_name)), $url))) { if ($url = preg_replace('/%%user_full_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode(trim($user->first_name . ' ' . $user->last_name))), $url)) { if ($url = preg_replace('/%%user_email%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($user->user_email)), $url)) { if ($url = preg_replace('/%%user_login%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($user->user_login)), $url)) { if ($url = preg_replace('/%%user_ip%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($user_reg_ip)), $url)) { if ($url = preg_replace('/%%user_id%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode($user_id)), $url)) { if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { if (!($url = preg_replace('/%%' . preg_quote($var, '/') . '%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(urlencode(maybe_serialize($val))), $url))) { break; } } } if ($url = trim(preg_replace('/%%(.+?)%%/i', '', $url))) { c_ws_plugin__s2member_utils_urls::remote($url); } } } } } } } } } } if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['eot_del_notification_recipients'] && is_array($cv = preg_split('/\\|/', $custom))) { $email_configs_were_on = c_ws_plugin__s2member_email_configs::email_config_status(); c_ws_plugin__s2member_email_configs::email_config_release(); $msg = $sbj = '(s2Member / API Notification Email) - EOT/Deletion'; $msg .= "\n\n"; // Spacing in the message body. $msg .= 'eot_del_type: %%eot_del_type%%' . "\n"; $msg .= 'subscr_id: %%subscr_id%%' . "\n"; $msg .= 'subscr_baid: %%subscr_baid%%' . "\n"; $msg .= 'subscr_cid: %%subscr_cid%%' . "\n"; $msg .= 'user_first_name: %%user_first_name%%' . "\n"; $msg .= 'user_last_name: %%user_last_name%%' . "\n"; $msg .= 'user_full_name: %%user_full_name%%' . "\n"; $msg .= 'user_email: %%user_email%%' . "\n"; $msg .= 'user_login: %%user_login%%' . "\n"; $msg .= 'user_ip: %%user_ip%%' . "\n"; $msg .= 'user_id: %%user_id%%' . "\n"; if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { $msg .= $var . ': %%' . $var . '%%' . "\n"; } } $msg .= 'cv0: %%cv0%%' . "\n"; $msg .= 'cv1: %%cv1%%' . "\n"; $msg .= 'cv2: %%cv2%%' . "\n"; $msg .= 'cv3: %%cv3%%' . "\n"; $msg .= 'cv4: %%cv4%%' . "\n"; $msg .= 'cv5: %%cv5%%' . "\n"; $msg .= 'cv6: %%cv6%%' . "\n"; $msg .= 'cv7: %%cv7%%' . "\n"; $msg .= 'cv8: %%cv8%%' . "\n"; $msg .= 'cv9: %%cv9%%'; if (($msg = preg_replace('/%%cv([0-9]+)%%/ei', 'trim(@$cv[$1])', $msg)) && ($msg = preg_replace('/%%eot_del_type%%/i', c_ws_plugin__s2member_utils_strings::esc_refs('auto-eot-cancellation-expiration-demotion'), $msg)) && ($msg = preg_replace('/%%subscr_id%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($subscr_id), $msg))) { if (($msg = preg_replace('/%%subscr_baid%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($subscr_baid), $msg)) && ($msg = preg_replace('/%%subscr_cid%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($subscr_cid), $msg))) { if (($msg = preg_replace('/%%user_first_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($user->first_name), $msg)) && ($msg = preg_replace('/%%user_last_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($user->last_name), $msg))) { if ($msg = preg_replace('/%%user_full_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(trim($user->first_name . ' ' . $user->last_name)), $msg)) { if ($msg = preg_replace('/%%user_email%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($user->user_email), $msg)) { if ($msg = preg_replace('/%%user_login%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($user->user_login), $msg)) { if ($msg = preg_replace('/%%user_ip%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($user_reg_ip), $msg)) { if ($msg = preg_replace('/%%user_id%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($user_id), $msg)) { if (is_array($fields) && !empty($fields)) { foreach ($fields as $var => $val) { if (!($msg = preg_replace('/%%' . preg_quote($var, '/') . '%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(maybe_serialize($val)), $msg))) { break; } } } if ($sbj && ($msg = trim(preg_replace('/%%(.+?)%%/i', '', $msg)))) { foreach (c_ws_plugin__s2member_utils_strings::parse_emails($GLOBALS['WS_PLUGIN__']['s2member']['o']['eot_del_notification_recipients']) as $recipient) { wp_mail($recipient, apply_filters('ws_plugin__s2member_eot_del_notification_email_sbj', $sbj, get_defined_vars()), apply_filters('ws_plugin__s2member_eot_del_notification_email_msg', $msg, get_defined_vars()), 'Content-Type: text/plain; charset=UTF-8'); } } } } } } } } } } if ($email_configs_were_on) { c_ws_plugin__s2member_email_configs::email_config(); } } foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_during_auto_eot_system_during_demote', get_defined_vars()); unset($__refs, $__v); // Housekeeping. } else { if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['membership_eot_behavior'] === 'delete') { $eot_del_type = $GLOBALS['ws_plugin__s2member_eot_del_type'] = 'auto-eot-cancellation-expiration-deletion'; foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_during_auto_eot_system_during_before_delete', get_defined_vars()); do_action('ws_plugin__s2member_during_collective_eots', $user_id, get_defined_vars(), $eot_del_type, 'removal-deletion'); unset($__refs, $__v); // Housekeeping. if (is_multisite()) { remove_user_from_blog($user_id, $current_blog->blog_id); // This will automatically trigger `eot_del_notification_urls`. c_ws_plugin__s2member_user_deletions::handle_ms_user_deletions($user_id, $current_blog->blog_id, 's2says'); } else { // Otherwise, we can actually delete them. // This will automatically trigger `eot_del_notification_urls` wp_delete_user($user_id); } foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_during_auto_eot_system_during_delete', get_defined_vars()); unset($__refs, $__v); // Housekeeping. } } foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_during_auto_eot_system', get_defined_vars()); unset($__refs, $__v); // Housekeeping. } } } } } c_ws_plugin__s2member_utils_logs::cleanup_expired_s2m_transients(); foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_after_auto_eot_system', get_defined_vars()); unset($__refs, $__v); // Housekeeping. }
/** * Add a newly created user to the appropriate blog * * @since MU * * @param int $user_id * @param string $email * @param array $meta */ function add_new_user_to_blog($user_id, $email, $meta) { global $current_site; if (!empty($meta['add_to_blog'])) { $blog_id = $meta['add_to_blog']; $role = $meta['new_role']; remove_user_from_blog($user_id, $current_site->blog_id); // remove user from main blog. add_user_to_blog($blog_id, $user_id, $role); update_user_meta($user_id, 'primary_blog', $blog_id); } }
/** * @ticket 37949 * @group multisite */ public function test_admin_bar_contains_correct_about_link_for_users_with_no_role_in_multisite() { if (!is_multisite()) { $this->markTestSkipped('Test only runs in multisite'); } // User is not a member of a site. remove_user_from_blog(self::$no_role_id, get_current_blog_id()); wp_set_current_user(self::$no_role_id); $wp_admin_bar = $this->get_standard_admin_bar(); $wp_logo_node = $wp_admin_bar->get_node('wp-logo'); $about_node = $wp_admin_bar->get_node('about'); $this->assertNotNull($wp_logo_node); $this->assertSame(user_admin_url('about.php'), $wp_logo_node->href); $this->assertArrayNotHasKey('tabindex', $wp_logo_node->meta); $this->assertNotNull($about_node); }