' . esc_html__( 'Admin Passwords', 'mainwp' ) . '', 'read', 'UpdateAdminPasswords', array( static::get_class_name(), 'render', ) ); } /** * Renders the Admin Passwords page footer. */ public static function render_footer() { echo ''; } /** * Renders the Admin Passwords page. * * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed() * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() * @uses \MainWP\Dashboard\MainWP_DB::query() * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_by_group_id() * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user() * @uses \MainWP\Dashboard\MainWP_DB::fetch_object() * @uses \MainWP\Dashboard\MainWP_DB::free_result() * @uses \MainWP\Dashboard\MainWP_Bulk_Add::get_class_name() * @uses \MainWP\Dashboard\MainWP_User::render_header() * @uses \MainWP\Dashboard\MainWP_User::render_footer() * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() * @uses \MainWP\Dashboard\MainWP_Utility::map_site() */ public static function render() { // phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated. $show_form = true; $errors = array(); if ( isset( $_POST['bulk_updateadminpassword'] ) ) { check_admin_referer( 'mainwp_updateadminpassword', 'security' ); if ( isset( $_POST['select_by'] ) ) { $selected_sites = ( isset( $_POST['selected_sites'] ) && is_array( $_POST['selected_sites'] ) ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['selected_sites'] ) ) : array(); $selected_groups = ( isset( $_POST['selected_groups'] ) && is_array( $_POST['selected_groups'] ) ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['selected_groups'] ) ) : array(); $selected_clients = ( isset( $_POST['selected_clients'] ) && is_array( $_POST['selected_clients'] ) ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['selected_clients'] ) ) : array(); if ( ( 'group' === $_POST['select_by'] && empty( $selected_groups ) ) || ( 'site' === $_POST['select_by'] && empty( $selected_sites ) ) || ( 'client' === $_POST['select_by'] && empty( $selected_clients ) ) ) { $errors[] = esc_html__( 'Please select the sites or groups or clients where you want to change the administrator password.', 'mainwp' ); } } else { $errors[] = esc_html__( 'Please select whether you want to change the administrator password for specific sites or groups or clients.', 'mainwp' ); } if ( ! isset( $_POST['password'] ) || '' === trim( wp_unslash( $_POST['password'] ) ) ) { //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- ok. $errors[] = esc_html__( 'Please enter the password.', 'mainwp' ); } $data_fields = MainWP_System_Utility::get_default_map_site_fields(); if ( empty( $errors ) ) { $show_form = false; $new_password = wp_unslash( $_POST['password'] ); //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- ok. $dbwebsites = array(); if ( 'site' === $_POST['select_by'] ) { // Get all selected websites. foreach ( $selected_sites as $k ) { if ( MainWP_Utility::ctype_digit( $k ) ) { $website = MainWP_DB::instance()->get_website_by_id( $k ); if ( '' !== $website->sync_errors || MainWP_System_Utility::is_suspended_site( $website ) ) { continue; } $dbwebsites[ $website->id ] = MainWP_Utility::map_site( $website, $data_fields ); } } } elseif ( 'client' === $_POST['select_by'] ) { // Get all selected websites. $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 { // Get all websites from the selected groups. 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_password' => base64_encode( $new_password ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. $output = new \stdClass(); $output->ok = array(); $output->errors = array(); MainWP_Connect::fetch_urls_authed( $dbwebsites, 'newadminpassword', $post_data, array( MainWP_Bulk_Add::get_class_name(), 'posting_bulk_handler', ), $output ); } } } $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, false, array( 'admin_nicename', 'admin_useremail' ) ) ); MainWP_User::render_header( 'UpdateAdminPasswords' ); if ( ! $show_form ) { static::render_modal( $dbwebsites, $output ); } static::render_bulk_form( $websites ); MainWP_User::render_footer( 'UpdateAdminPasswords' ); } /** * Renders update password results. * * @param object $dbwebsites The websites object. * @param object $output Result of update password. */ public static function render_modal( $dbwebsites, $output ) { ?>
', ' ' ); // NOSONAR - noopener - open safe. ?>
adminname; ?>
name ) ); ?> admin_nicename ); ?> admin_useremail ); ?>
'true', 'paging' => 'true', 'info' => 'true', 'colReorder' => 'true', 'stateSave' => 'true', 'responsive' => 'true', ); /** * Filter: mainwp_admin_users_table_fatures * * Filters Admin Users table features. * * @since 4.1 */ $table_features = apply_filters( 'mainwp_admin_users_table_fatures', $table_features ); ?>
true, ); MainWP_UI_Select_Sites::select_sites_box( $sel_params ); ?>

render_demo_disable_button( '' ); } else { ?>