' . esc_html__( 'Users', 'mainwp' ) . '', 'read', 'UserBulkManage', array( static::get_class_name(), 'render', ) ); add_action( 'load-' . $_page, array( static::get_class_name(), 'on_load_page' ) ); add_submenu_page( 'mainwp_tab', __( 'Users', 'mainwp' ), '
' . esc_html__( 'Add New', 'mainwp' ) . '
', 'read', 'UserBulkAdd', array( static::get_class_name(), 'render_bulk_add', ) ); add_submenu_page( 'mainwp_tab', __( 'Import Users', 'mainwp' ), '
' . esc_html__( 'Import Users', 'mainwp' ) . '
', 'read', 'BulkImportUsers', array( static::get_class_name(), 'render_bulk_import_users', ) ); /** * This hook allows you to add extra sub pages to the User page via the 'mainwp-getsubpages-user' filter. * * @link http://codex.mainwp.com/#mainwp-getsubpages-user */ $sub_pages = apply_filters_deprecated( 'mainwp-getsubpages-user', array( array() ), '4.0.7.2', 'mainwp_getsubpages_user' ); // @deprecated Use 'mainwp_getsubpages_user' instead. NOSONAR - not IP. static::$subPages = apply_filters( 'mainwp_getsubpages_user', $sub_pages ); if ( isset( static::$subPages ) && is_array( static::$subPages ) ) { foreach ( static::$subPages as $subPage ) { if ( MainWP_Menu::is_disable_menu_item( 3, 'UserBulk' . $subPage['slug'] ) ) { continue; } add_submenu_page( 'mainwp_tab', $subPage['title'], '
' . esc_html( $subPage['title'] ) . '
', 'read', 'UserBulk' . $subPage['slug'], $subPage['callback'] ); } } static::init_left_menu( static::$subPages ); } /** * Initiates sub pages menu. * * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item() */ public static function init_subpages_menu() { ?> esc_html__( 'Name', 'mainwp' ), 'username' => esc_html__( 'Username', 'mainwp' ), 'email' => esc_html__( 'E-mail', 'mainwp' ), 'role' => esc_html__( 'Role', 'mainwp' ), 'posts' => esc_html__( 'Posts', 'mainwp' ), 'website' => esc_html__( 'Website', 'mainwp' ), ); } /** * Method on_load_page() * * Used during init_menu() to get the class names of, * admin_head and get_hidden_columns. * * @return void */ public static function on_load_page() { add_action( 'mainwp_screen_options_modal_bottom', array( static::get_class_name(), 'hook_screen_options_modal_bottom' ), 10, 2 ); } /** * Method hook_screen_options_modal_bottom() * * Render screen options modal bottom. */ public static function hook_screen_options_modal_bottom() { $page = isset( $_GET['page'] ) ? wp_unslash( $_GET['page'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized if ( 'UserBulkManage' === $page ) { $show_columns = get_user_option( 'mainwp_manageusers_show_columns' ); if ( ! is_array( $show_columns ) ) { $show_columns = array(); } $cols = static::get_manage_columns(); MainWP_UI::render_showhide_columns_settings( $cols, $show_columns, 'user' ); } } /** * Initiates Users menu. * * @param array $subPages Sub pages array. * * @uses \MainWP\Dashboard\MainWP_Menu::add_left_menu() * @uses \MainWP\Dashboard\MainWP_Menu::init_subpages_left_menu() * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item() */ public static function init_left_menu( $subPages = array() ) { MainWP_Menu::add_left_menu( array( 'title' => esc_html__( 'Users', 'mainwp' ), 'parent_key' => 'managesites', 'slug' => 'UserBulkManage', 'href' => 'admin.php?page=UserBulkManage', 'icon' => '', 'desc' => 'Manage users on your child sites', 'leftsub_order' => 7, ), 1 ); $init_sub_subleftmenu = array( array( 'title' => esc_html__( 'Manage Users', 'mainwp' ), 'parent_key' => 'UserBulkManage', 'href' => 'admin.php?page=UserBulkManage', 'slug' => 'UserBulkManage', 'right' => 'manage_users', ), array( 'title' => esc_html__( 'Add New', 'mainwp' ), 'parent_key' => 'UserBulkManage', 'href' => 'admin.php?page=UserBulkAdd', 'slug' => 'UserBulkAdd', 'right' => '', ), array( 'title' => esc_html__( 'Import Users', 'mainwp' ), 'parent_key' => 'UserBulkManage', 'href' => 'admin.php?page=BulkImportUsers', 'slug' => 'BulkImportUsers', 'right' => '', ), array( 'title' => esc_html__( 'Admin Passwords', 'mainwp' ), 'parent_key' => 'UserBulkManage', 'href' => 'admin.php?page=UpdateAdminPasswords', 'slug' => 'UpdateAdminPasswords', 'right' => '', ), ); MainWP_Menu::init_subpages_left_menu( $subPages, $init_sub_subleftmenu, 'UserBulkManage', 'UserBulk' ); foreach ( $init_sub_subleftmenu as $item ) { if ( MainWP_Menu::is_disable_menu_item( 3, $item['slug'] ) ) { continue; } MainWP_Menu::add_left_menu( $item, 2 ); } } /** * Method render_header() * * Render Users page header. * * @param string $shownPage The page slug shown at this moment. * * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item() * @uses \MainWP\Dashboard\MainWP_UI::render_top_header() * @uses \MainWP\Dashboard\MainWP_UI::render_page_navigation() */ public static function render_header( $shownPage = '' ) { //phpcs:ignore -- NOSONAR - complex. $params = array( 'title' => esc_html__( 'Users', 'mainwp' ), ); MainWP_UI::render_top_header( $params ); $renderItems = array(); if ( \mainwp_current_user_can( 'dashboard', 'manage_users' ) ) { $renderItems[] = array( 'title' => esc_html__( 'Manage Users', 'mainwp' ), 'href' => 'admin.php?page=UserBulkManage', 'active' => ( '' === $shownPage ) ? true : false, ); } if ( ! MainWP_Menu::is_disable_menu_item( 3, 'UserBulkAdd' ) ) { $renderItems[] = array( 'title' => esc_html__( 'Add New', 'mainwp' ), 'href' => 'admin.php?page=UserBulkAdd', 'active' => ( 'Add' === $shownPage ) ? true : false, ); } if ( ! MainWP_Menu::is_disable_menu_item( 3, 'BulkImportUsers' ) ) { $renderItems[] = array( 'title' => esc_html__( 'Import Users', 'mainwp' ), 'href' => 'admin.php?page=BulkImportUsers', 'active' => ( 'Import' === $shownPage ) ? true : false, ); } if ( ! MainWP_Menu::is_disable_menu_item( 3, 'UpdateAdminPasswords' ) ) { $renderItems[] = array( 'title' => esc_html__( 'Admin Passwords', 'mainwp' ), 'href' => 'admin.php?page=UpdateAdminPasswords', 'active' => ( 'UpdateAdminPasswords' === $shownPage ) ? true : false, ); } if ( isset( static::$subPages ) && is_array( static::$subPages ) ) { foreach ( static::$subPages as $subPage ) { if ( MainWP_Menu::is_disable_menu_item( 3, 'UserBulk' . $subPage['slug'] ) ) { continue; } $item = array(); $item['title'] = $subPage['title']; $item['href'] = 'admin.php?page=UserBulk' . $subPage['slug']; $item['active'] = ( $subPage['slug'] === $shownPage ) ? true : false; $renderItems[] = $item; } } MainWP_UI::render_page_navigation( $renderItems ); } /** * Method render_footer() * * Render Users page footer. Closes the page container. */ public static function render_footer() { echo ''; } /** * Renders manage users dashboard. * * @return void * * @uses \MainWP\Dashboard\MainWP_Cache::get_cached_context() */ public static function render() { if ( ! \mainwp_current_user_can( 'dashboard', 'manage_users' ) ) { \mainwp_do_not_have_permissions( esc_html__( 'manage users', 'mainwp' ) ); return; } $cachedSearch = MainWP_Cache::get_cached_context( 'Users' ); $selected_sites = array(); $selected_groups = array(); $selected_clients = array(); if ( null !== $cachedSearch ) { if ( is_array( $cachedSearch['sites'] ) ) { $selected_sites = $cachedSearch['sites']; } elseif ( is_array( $cachedSearch['groups'] ) ) { $selected_groups = $cachedSearch['groups']; } elseif ( is_array( $cachedSearch['clients'] ) ) { $selected_clients = $cachedSearch['clients']; } } static::render_header( '' ); ?>
', '' ); ?>
$selected_sites, 'selected_groups' => $selected_groups, 'selected_clients' => $selected_clients, 'class' => 'mainwp_select_sites_box_left', 'show_client' => true, ); MainWP_UI_Select_Sites::select_sites_box( $sel_params ); ?>
esc_html__( 'Subscriber', 'mainwp' ), 'administrator' => esc_html__( 'Administrator', 'mainwp' ), 'editor' => esc_html__( 'Editor', 'mainwp' ), 'author' => esc_html__( 'Author', 'mainwp' ), 'contributor' => esc_html__( 'Contributor', 'mainwp' ), ); $user_roles = apply_filters_deprecated( 'mainwp-users-manage-roles', array( $user_roles ), '4.0.7.2', 'mainwp_users_manage_roles' ); // @deprecated Use 'mainwp_users_manage_roles' instead. NOSONAR - not IP. $user_roles = apply_filters( 'mainwp_users_manage_roles', $user_roles ); ?>
esc_html__( 'Do not update', 'mainwp' ), 'administrator' => esc_html__( 'Administrator', 'mainwp' ), 'subscriber' => esc_html__( 'Subscriber', 'mainwp' ), 'contributor' => esc_html__( 'Contributor', 'mainwp' ), 'author' => esc_html__( 'Author', 'mainwp' ), 'editor' => esc_html__( 'Editor', 'mainwp' ), ); $editable_roles = apply_filters_deprecated( 'mainwp-users-manage-roles', array( $editable_roles ), '4.0.7.2', 'mainwp_users_manage_roles' ); // @deprecated Use 'mainwp_users_manage_roles' instead. NOSONAR - not IP. $editable_roles = apply_filters( 'mainwp_users_manage_roles', $editable_roles ); $editable_roles[''] = esc_html__( '— No role for this site —', 'mainwp' ); ?>
'true', 'paging' => 'true', 'info' => 'true', 'stateSave' => 'true', 'scrollX' => 'true', 'responsive' => 'true', 'colReorder' => '{columns:":not(.check-column):not(:last-child)"}', 'order' => '[]', ); $table_features = apply_filters( 'mainwp_users_table_fatures', $table_features ); ?> errors = array(); $output->users = 0; $data_fields = MainWP_System_Utility::get_default_map_site_fields(); $data_fields[] = 'users'; if ( 1 === (int) get_option( 'mainwp_optimize', 1 ) || MainWP_Demo_Handle::is_demo_mode() ) { $check_users_role = false; if ( ! empty( $role ) ) { $roles = explode( ',', $role ); if ( is_array( $roles ) ) { $check_users_role = true; } } $dbwebsites = array(); if ( ! empty( $sites ) ) { foreach ( $sites as $v ) { if ( MainWP_Utility::ctype_digit( $v ) ) { $website = MainWP_DB::instance()->get_website_by_id( $v ); if ( empty( $website->sync_errors ) && ! MainWP_System_Utility::is_suspended_site( $website ) ) { $dbwebsites[ $website->id ] = $website; } } } } if ( ! empty( $groups ) ) { foreach ( $groups as $v ) { if ( MainWP_Utility::ctype_digit( $v ) ) { $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_by_group_id( $v ) ); while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) { if ( ! empty( $website->sync_errors ) || MainWP_System_Utility::is_suspended_site( $website ) ) { continue; } $dbwebsites[ $website->id ] = $website; } MainWP_DB::free_result( $websites ); } } } if ( ! empty( $clients ) && is_array( $clients ) ) { $websites = MainWP_DB_Client::instance()->get_websites_by_client_ids( $clients, array( 'select_data' => $data_fields, ) ); foreach ( $websites as $website ) { if ( ! empty( $website->sync_errors ) || MainWP_System_Utility::is_suspended_site( $website ) ) { continue; } $dbwebsites[ $website->id ] = $website; } } if ( $dbwebsites ) { foreach ( $dbwebsites as $website ) { $allUsers = json_decode( $website->users, true ); $allUsersCount = count( $allUsers ); $search_user_role = array(); if ( $check_users_role ) { for ( $i = 0; $i < $allUsersCount; $i++ ) { $user = $allUsers[ $i ]; foreach ( $roles as $_role ) { if ( stristr( $user['role'], $_role ) ) { if ( ! in_array( $user['id'], $search_user_role ) ) { $search_user_role[] = $user['id']; } break; } } } } for ( $i = 0; $i < $allUsersCount; $i++ ) { $user = $allUsers[ $i ]; if ( ! empty( $search ) && ! stristr( $user['login'], trim( $search ) ) && ! stristr( $user['display_name'], trim( $search ) ) && ! stristr( $user['email'], trim( $search ) ) ) { continue; } if ( $check_users_role && ! in_array( $user['id'], $search_user_role ) ) { continue; } $tmpUsers = array( $user ); $output->users += static::users_search_handler_renderer( $tmpUsers, $website ); } } } } else { $dbwebsites = array(); if ( '' !== $sites ) { foreach ( $sites as $v ) { if ( MainWP_Utility::ctype_digit( $v ) ) { $website = MainWP_DB::instance()->get_website_by_id( $v ); if ( empty( $website->sync_errors ) && ! MainWP_System_Utility::is_suspended_site( $website ) ) { $dbwebsites[ $website->id ] = MainWP_Utility::map_site( $website, $data_fields ); } } } } if ( '' !== $groups ) { foreach ( $groups as $v ) { if ( MainWP_Utility::ctype_digit( $v ) ) { $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_by_group_id( $v ) ); while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) { if ( '' !== $website->sync_errors || MainWP_System_Utility::is_suspended_site( $website ) ) { continue; } $dbwebsites[ $website->id ] = MainWP_Utility::map_site( $website, $data_fields ); } MainWP_DB::free_result( $websites ); } } } if ( '' !== $clients && is_array( $clients ) ) { $websites = MainWP_DB_Client::instance()->get_websites_by_client_ids( $clients, array( 'select_data' => $data_fields, ) ); if ( $websites ) { foreach ( $websites as $website ) { if ( '' !== $website->sync_errors || MainWP_System_Utility::is_suspended_site( $website ) ) { continue; } $dbwebsites[ $website->id ] = MainWP_Utility::map_site( $website, $data_fields ); } } } $post_data = array( 'role' => $role, 'search' => '*' . trim( $search ) . '*', 'search_columns' => 'user_login,display_name,user_email', ); MainWP_Connect::fetch_urls_authed( $dbwebsites, 'search_users', $post_data, array( static::get_class_name(), 'users_search_handler', ), $output ); } MainWP_Cache::add_context( 'Users', array( 'count' => $output->users, 'keyword' => $search, 'status' => ( isset( $_POST['role'] ) ? sanitize_text_field( wp_unslash( $_POST['role'] ) ) : 'administrator' ), // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized 'sites' => '' !== $sites ? $sites : '', 'groups' => '' !== $groups ? $groups : '', 'clients' => ( '' !== $clients ) ? $clients : '', ) ); // Sort if required. if ( empty( $output->users ) ) { static::render_cache_not_found(); } } /** * Renders when cache is not found. * * @uses \MainWP\Dashboard\MainWP_Cache::add_body() */ public static function render_cache_not_found() { ob_start(); $newOutput = ob_get_clean(); echo $newOutput; // phpcs:ignore WordPress.Security.EscapeOutput MainWP_Cache::add_body( 'Users', $newOutput ); } /** * Gets the selected users current role. * * @param string $role Selected Users Role. */ private static function get_role( $role ) { if ( is_array( $role ) ) { $allowed_roles = array( 'subscriber', 'administrator', 'editor', 'author', 'contributor' ); $ret = ''; foreach ( $role as $ro ) { if ( in_array( $ro, $allowed_roles ) ) { $ret .= ucfirst( $ro ) . ', '; } } $ret = rtrim( $ret, ', ' ); if ( '' === $ret ) { $ret = 'None'; } return $ret; } return ucfirst( $role ); } /** * Renders Search results. * * @param array $users Users array. * @param object $website Object containing the child site info. * * @return mixed Search results table. * * @uses \MainWP\Dashboard\MainWP_Cache::add_body() */ protected static function users_search_handler_renderer( $users, $website ) { $return = 0; $is_demo = MainWP_Demo_Handle::is_demo_mode(); foreach ( $users as $user ) { if ( ! is_array( $user ) ) { continue; } ob_start(); ?> url ); ?> is_demo_website( $website ) ) { return; } if ( 0 < preg_match( '/(.*)<\/mainwp>/', $data, $results ) ) { $result = $results[1]; $users = MainWP_System_Utility::get_child_response( base64_decode( $result ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. unset( $results ); $output->users += static::users_search_handler_renderer( $users, $website ); unset( $users ); } else { $output->errors[ $website->id ] = MainWP_Error_Helper::get_error_message( new MainWP_Exception( 'NOMAINWP', $website->url ) ); } } /** * Deletes user. */ public static function delete() { static::action( 'delete' ); die( wp_json_encode( array( 'result' => esc_html__( 'User has been deleted', 'mainwp' ) ) ) ); } /** * Edits user. */ public static function edit() { $information = static::action( 'edit' ); wp_send_json( $information ); } /** * Updates user. */ public static function update_user() { static::action( 'update_user' ); die( wp_json_encode( array( 'result' => esc_html__( 'User has been updated', 'mainwp' ) ) ) ); } /** * Updates users password. */ public static function update_password() { static::action( 'update_password' ); die( wp_json_encode( array( 'result' => esc_html__( 'User password has been updated', 'mainwp' ) ) ) ); } /** * Users actions. * * @param mixed $pAction Action to perform delete|update_user|update_password. * @param string $extra Additional Roles to add if any. * * @return mixed $information User update info that is returned. * @throws \MainWP_Exception Error message. * * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() * @uses \MainWP\Dashboard\MainWP_DB::update_website_values() * @uses \MainWP\Dashboard\MainWP_Error_Helper::get_error_message() * @uses \MainWP\Dashboard\MainWP_Exception * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed() * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() */ public static function action( $pAction, $extra = '' ) { // phpcs:ignore -- NOSONAR - current complexity required to achieve desired results. Pull request solutions appreciated. // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $userId = isset( $_POST['userId'] ) ? sanitize_text_field( wp_unslash( $_POST['userId'] ) ) : false; $userName = isset( $_POST['userName'] ) ? sanitize_text_field( wp_unslash( $_POST['userName'] ) ) : ''; $websiteId = isset( $_POST['websiteId'] ) ? sanitize_text_field( wp_unslash( $_POST['websiteId'] ) ) : false; $pass = isset( $_POST['update_password'] ) ? rawurldecode( wp_unslash( $_POST['update_password'] ) ) : ''; if ( function_exists( '\mb_convert_encoding' ) ) { $pass = \mb_convert_encoding( $pass, 'ISO-8859-1', 'UTF-8' ); } else { $pass = utf8_decode( $pass ); // to compatible. } if ( empty( $userId ) || empty( $websiteId ) ) { die( wp_json_encode( array( 'error' => esc_html__( 'Site ID or user ID not found. Please reload the page and try again.', 'mainwp' ) ) ) ); } $website = MainWP_DB::instance()->get_website_by_id( $websiteId ); if ( MainWP_System_Utility::is_suspended_site( $website ) ) { die( wp_json_encode( array( 'error' => esc_html__( 'Suspended site.', 'mainwp' ), 'errorCode' => 'SUSPENDED_SITE', ) ) ); } if ( ! MainWP_System_Utility::can_edit_website( $website ) ) { die( wp_json_encode( array( 'error' => esc_html__( 'You can not edit this website!', 'mainwp' ) ) ) ); } if ( ( 'delete' === $pAction ) && ( $website->adminname === $userName ) ) { die( wp_json_encode( array( 'error' => esc_html__( 'This user is used for our secure link, it can not be deleted.', 'mainwp' ) ) ) ); } if ( 'update_user' === $pAction ) { $user_data = isset( $_POST['user_data'] ) ? wp_unslash( $_POST['user_data'] ) : ''; parse_str( $user_data, $extra ); if ( $website->adminname === $userName && is_array( $extra ) && isset( $extra['role'] ) ) { unset( $extra['role'] ); } if ( ! empty( $pass ) ) { $extra['pass1'] = $pass; $extra['pass2'] = $pass; } } // phpcs:enable $optimize = ( 1 === (int) get_option( 'mainwp_optimize', 1 ) ) ? 1 : 0; /** * Action: mainwp_before_user_action * * Fires before user edit/delete/update_user/update_password actions. * * @since 4.1 */ do_action( 'mainwp_before_user_action', $pAction, $userId, $extra, $pass, $optimize, $website ); try { $information = MainWP_Connect::fetch_url_authed( $website, 'user_action', array( 'action' => $pAction, 'id' => $userId, 'extra' => $extra, 'user_pass' => $pass, 'optimize' => $optimize, ) ); if ( is_array( $information ) && isset( $information['status'] ) && ( 'SUCCESS' === $information['status'] ) ) { $data = isset( $information['other_data']['users_data'] ) ? $information['other_data']['users_data'] : array(); // user actions data. /** * Fires immediately after user action. * * @since 4.5.1.1 */ do_action( 'mainwp_user_action', $website, $pAction, $data, $extra, $optimize ); } } catch ( MainWP_Exception $e ) { die( wp_json_encode( array( 'error' => MainWP_Error_Helper::get_error_message( $e ) ) ) ); } /** * Action: mainwp_after_user_action * * Fires after user edit/delete/update_user/update_password actions. * * @since 4.1 */ do_action( 'mainwp_after_user_action', $information, $pAction, $userId, $extra, $pass, $optimize, $website ); if ( is_array( $information ) && isset( $information['error'] ) ) { wp_send_json( array( 'error' => esc_html( $information['error'] ) ) ); } if ( ! isset( $information['status'] ) || ( 'SUCCESS' !== $information['status'] ) ) { die( wp_json_encode( array( 'error' => esc_html__( 'Unexpected error.', 'mainwp' ) ) ) ); } elseif ( 'update_user' === $pAction ) { if ( $optimize && isset( $information['users'] ) ) { $websiteValues['users'] = wp_json_encode( $information['users'] ); MainWP_DB::instance()->update_website_values( $websiteId, $websiteValues ); } } // This user is used for our secure link, you can not change the role. if ( 'edit' === $pAction && $website->adminname === $userName && is_array( $information ) && isset( $information['user_data'] ) ) { $information['is_secure_admin'] = 1; } return $information; } /** * Renders the Add New user form. */ public static function render_bulk_add() { /** * Filter: mainwp_new_user_password_complexity * * Filters the Password lenght for the Add New user, Password field. * * Since 4.1 */ $pass_complexity = apply_filters( 'mainwp_new_user_password_complexity', '24' ); static::render_header( 'Add' ); // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized ?>
', '' ); ?>
>
esc_html__( 'Subscriber', 'mainwp' ), 'administrator' => esc_html__( 'Administrator', 'mainwp' ), 'editor' => esc_html__( 'Editor', 'mainwp' ), 'author' => esc_html__( 'Author', 'mainwp' ), 'contributor' => esc_html__( 'Contributor', 'mainwp' ), ); $user_roles = apply_filters_deprecated( 'mainwp-users-manage-roles', array( $user_roles ), '4.0.7.2', 'mainwp_users_manage_roles' ); // @deprecated Use 'mainwp_users_manage_roles' instead. NOSONAR - not IP. $user_roles = apply_filters( 'mainwp_users_manage_roles', $user_roles ); ?>
true, ); MainWP_UI_Select_Sites::select_sites_box( $sel_params ); ?>
render_demo_disable_button( '' ); } else { ?>
', '' ); ?>
render_demo_disable_button( '' ); } else { ?>
isset( $_POST['pass1'] ) ? wp_unslash( $_POST['pass1'] ) : '', 'user_login' => isset( $_POST['user_login'] ) ? sanitize_text_field( wp_unslash( $_POST['user_login'] ) ) : '', 'user_url' => isset( $_POST['url'] ) ? esc_url_raw( wp_unslash( $_POST['url'] ) ) : '', 'user_email' => isset( $_POST['email'] ) ? sanitize_text_field( wp_unslash( $_POST['email'] ) ) : '', 'first_name' => isset( $_POST['first_name'] ) ? sanitize_text_field( wp_unslash( $_POST['first_name'] ) ) : '', 'last_name' => isset( $_POST['last_name'] ) ? sanitize_text_field( wp_unslash( $_POST['last_name'] ) ) : '', 'role' => isset( $_POST['role'] ) ? sanitize_text_field( wp_unslash( $_POST['role'] ) ) : '', ); $dbwebsites = array(); if ( isset( $_POST['select_by'] ) && 'site' === $_POST['select_by'] ) { foreach ( $selected_sites as $k ) { if ( MainWP_Utility::ctype_digit( $k ) ) { $website = MainWP_DB::instance()->get_website_by_id( $k ); if ( empty( $website->sync_errors ) && ! MainWP_System_Utility::is_suspended_site( $website ) ) { $dbwebsites[ $website->id ] = MainWP_Utility::map_site( $website, $data_fields ); } } } } elseif ( isset( $_POST['select_by'] ) && 'client' === $_POST['select_by'] ) { $websites = MainWP_DB_Client::instance()->get_websites_by_client_ids( $selected_clients, array( 'select_data' => $data_fields, ) ); if ( $websites ) { foreach ( $websites as $website ) { if ( '' !== $website->sync_errors || MainWP_System_Utility::is_suspended_site( $website ) ) { continue; } $dbwebsites[ $website->id ] = MainWP_Utility::map_site( $website, $data_fields ); } } } else { foreach ( $selected_groups as $k ) { if ( MainWP_Utility::ctype_digit( $k ) ) { $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_by_group_id( $k ) ); while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) { if ( '' !== $website->sync_errors || MainWP_System_Utility::is_suspended_site( $website ) ) { continue; } $dbwebsites[ $website->id ] = MainWP_Utility::map_site( $website, $data_fields ); } MainWP_DB::free_result( $websites ); } } } if ( ! empty( $dbwebsites ) ) { $post_data = array( 'new_user' => base64_encode( wp_json_encode( $user_to_add ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. 'send_password' => ( isset( $_POST['send_password'] ) ? intval( $_POST['send_password'] ) : '' ), ); $output = new \stdClass(); $output->ok = array(); $output->errors = array(); /** * Action: mainwp_before_user_create * * Fires before user create. * * @since 4.1 */ do_action( 'mainwp_before_user_create', $post_data, $dbwebsites ); MainWP_Connect::fetch_urls_authed( $dbwebsites, 'newuser', $post_data, array( MainWP_Bulk_Add::get_class_name(), 'posting_bulk_handler', ), $output ); /** * Action: mainwp_after_user_create * * Fires after user create. * * @since 4.1 */ do_action( 'mainwp_after_user_create', $output, $post_data, $dbwebsites ); } $countSites = 0; $countRealItems = 0; foreach ( $dbwebsites as $website ) { if ( isset( $output->ok[ $website->id ] ) && 1 === (int) $output->ok[ $website->id ] ) { ++$countSites; ++$countRealItems; } } static::render_bulk_add_modal( $dbwebsites, $output ); } else { echo wp_json_encode( array( $errorFields, $errors ) ); } // phpcs:enable } /** * Renders Bulk User addition Modal window. * * @param mixed $dbwebsites Child sites list. * @param mixed $output Modal window content. */ public static function render_bulk_add_modal( $dbwebsites, $output ) { // phpcs:disable WordPress.Security.EscapeOutput ?> get_contents( $tmp_path ); $lines = explode( "\r\n", $content ); if ( is_array( $lines ) && ! empty( $lines ) ) { $i = 0; // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized if ( ! empty( $_POST['import_user_chk_header_first'] ) ) { $header_line = trim( $lines[0] ) . "\n"; unset( $lines[0] ); } // phpcs:enable foreach ( $lines as $originalLine ) { $line = trim( $originalLine ); if ( MainWP_Utility::starts_with( $line, '#' ) ) { continue; } $items = str_getcsv( $line, ',' ); if ( 3 > count( $items ) ) { continue; } $import_data = array( 'user_login' => sanitize_text_field( wp_unslash( $items[0] ) ), 'email' => sanitize_text_field( wp_unslash( $items[1] ) ), 'first_name' => sanitize_text_field( wp_unslash( $items[2] ) ), 'last_name' => sanitize_text_field( wp_unslash( $items[3] ) ), 'url' => sanitize_text_field( wp_unslash( $items[4] ) ), 'pass1' => sanitize_text_field( wp_unslash( $items[5] ) ), 'send_password' => intval( $items[6] ), 'role' => sanitize_text_field( wp_unslash( strtolower( $items[7] ) ) ), 'select_sites' => sanitize_text_field( wp_unslash( $items[8] ) ), 'select_groups' => sanitize_text_field( wp_unslash( $items[9] ) ), ); $encoded = wp_json_encode( $import_data ); ?>
isset( $_POST['pass1'] ) ? wp_unslash( $_POST['pass1'] ) : '', 'user_login' => isset( $_POST['user_login'] ) ? sanitize_text_field( wp_unslash( $_POST['user_login'] ) ) : '', 'user_url' => isset( $_POST['url'] ) ? wp_unslash( $_POST['url'] ) : '', 'user_email' => isset( $_POST['email'] ) ? sanitize_text_field( wp_unslash( $_POST['email'] ) ) : '', 'first_name' => isset( $_POST['first_name'] ) ? sanitize_text_field( wp_unslash( $_POST['first_name'] ) ) : '', 'last_name' => isset( $_POST['last_name'] ) ? sanitize_text_field( wp_unslash( $_POST['last_name'] ) ) : '', 'role' => isset( $_POST['role'] ) ? sanitize_text_field( wp_unslash( $_POST['role'] ) ) : '', ); $ret = array(); $dbwebsites = array(); $not_valid = array(); $error_sites = ''; if ( isset( $_POST['select_by'] ) && 'site' === $_POST['select_by'] ) { foreach ( $selected_sites as $url ) { if ( ! empty( $url ) ) { $website = MainWP_DB::instance()->get_websites_by_url( $url ); if ( ! empty( $website ) ) { $website = current( $website ); } if ( $website ) { if ( '' !== $website->sync_errors || MainWP_System_Utility::is_suspended_site( $website ) ) { if ( '' !== $website->sync_errors ) { $err_imp = esc_html__( 'Site disconnected:', 'mainwp' ); } else { $err_imp = esc_html__( 'Site suspended:', 'mainwp' ); } $not_valid[] = $err_imp . ' ' . $website->url; $error_sites .= $website->url . ';'; continue; } $dbwebsites[ $website->id ] = MainWP_Utility::map_site( $website, $data_fields ); } else { $not_valid[] = esc_html__( 'Unexisting website. Please try again.', 'mainwp' ) . ' ' . $url; $error_sites .= $url . ';'; } } } } else { foreach ( $selected_groups as $group ) { if ( MainWP_DB_Common::instance()->get_group_by_name( $group ) ) { $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_by_group_name( $group ) ); if ( $websites ) { while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) { if ( '' !== $website->sync_errors || MainWP_System_Utility::is_suspended_site( $website ) ) { if ( '' !== $website->sync_errors ) { $err_imp = esc_html__( 'Site disconnected:', 'mainwp' ); } else { $err_imp = esc_html__( 'Site suspended:', 'mainwp' ); } $not_valid[] = $err_imp . ' ' . $website->url; $error_sites .= $website->url . ';'; continue; } $dbwebsites[ $website->id ] = MainWP_Utility::map_site( $website, $data_fields ); } MainWP_DB::free_result( $websites ); } else { $not_valid[] = esc_html__( 'No websites assigned to the selected group.', 'mainwp' ) . ' ' . $group; $error_sites .= $group . ';'; } } else { $not_valid[] = esc_html__( 'Unexisting group selected. Please try again.', 'mainwp' ) . ' ' . $group; $error_sites .= $group . ';'; } } } if ( ! empty( $dbwebsites ) ) { $post_data = array( 'new_user' => base64_encode( wp_json_encode( $user_to_add ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. 'send_password' => ( isset( $_POST['send_password'] ) ? intval( $_POST['send_password'] ) : '' ), ); $output = new \stdClass(); $output->ok = array(); $output->errors = array(); /** * Action: mainwp_before_user_create * * Fires before user create. * * @since 4.1 */ do_action( 'mainwp_before_user_create', $post_data, $dbwebsites ); MainWP_Connect::fetch_urls_authed( $dbwebsites, 'newuser', $post_data, array( MainWP_Bulk_Add::get_class_name(), 'posting_bulk_handler', ), $output ); /** * Action: mainwp_after_user_create * * Fires after user create. * * @since 4.1 */ do_action( 'mainwp_after_user_create', $output, $post_data, $dbwebsites ); } $ret['ok_list'] = array(); $ret['error_list'] = array(); foreach ( $dbwebsites as $website ) { if ( isset( $output->ok[ $website->id ] ) && 1 === (int) $output->ok[ $website->id ] ) { $ret['ok_list'][] = 'New user(s) created: ' . esc_html( stripslashes( $website->name ) ); } else { $ret['error_list'][] = esc_html( $output->errors[ $website->id ] . ' ' . stripslashes( $website->name ) ); $error_sites .= $website->url . ';'; } } foreach ( $not_valid as $val ) { $ret['error_list'][] = $val; } $ret['failed_logging'] = ''; if ( ! empty( $error_sites ) ) { $error_sites = rtrim( $error_sites, ';' ); $user_login = isset( $_POST['user_login'] ) ? sanitize_text_field( wp_unslash( $_POST['user_login'] ) ) : ''; $email = isset( $_POST['email'] ) ? sanitize_text_field( wp_unslash( $_POST['email'] ) ) : ''; $first_name = isset( $_POST['first_name'] ) ? sanitize_text_field( wp_unslash( $_POST['first_name'] ) ) : ''; $last_name = isset( $_POST['last_name'] ) ? sanitize_text_field( wp_unslash( $_POST['last_name'] ) ) : ''; $url = isset( $_POST['url'] ) ? sanitize_text_field( wp_unslash( $_POST['url'] ) ) : ''; $pass1 = isset( $_POST['pass1'] ) ? wp_unslash( $_POST['pass1'] ) : ''; $send_password = isset( $_POST['send_password'] ) ? intval( $_POST['send_password'] ) : 0; $role = isset( $_POST['role'] ) ? sanitize_text_field( wp_unslash( $_POST['role'] ) ) : ''; $ret['failed_logging'] = esc_html( $user_login . ',' . $email . ',' . $first_name . ',' . $last_name . ',' . $url . ',' . $pass1 . ',' . $send_password . ',' . $role . ',' . $error_sites . ',' ); } $ret['line_number'] = isset( $_POST['line_number'] ) ? intval( $_POST['line_number'] ) : 0; // phpcs:enable die( wp_json_encode( $ret ) ); } /** * Method mainwp_help_content() * * Creates the MainWP Help Documentation List for the help component in the sidebar. */ public static function mainwp_help_content() { if ( isset( $_GET['page'] ) && ( 'UserBulkManage' === $_GET['page'] || 'UserBulkAdd' === $_GET['page'] || 'UpdateAdminPasswords' === $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized ?>

Your custom text
* * @since 4.1 */ do_action( 'mainwp_users_help_item' ); ?>