/* ========================================================= * EXPORT PLUGINS + USERS CSV * ========================================================= */ /* --------------------------------------------------------- * PLUGINS PAGE - EXPORT BUTTON * --------------------------------------------------------- */ add_action( 'manage_plugins_extra_tablenav', 'rk_export_plugins_button' ); function rk_export_plugins_button( $which ) { if ( $which !== 'top' ) { return; } if ( ! current_user_can( 'activate_plugins' ) ) { return; } $url = wp_nonce_url( admin_url( 'admin-post.php?action=rk_export_plugins' ), 'rk_export_plugins' ); echo 'Export Plugins'; } /* --------------------------------------------------------- * USERS PAGE - EXPORT BUTTON * --------------------------------------------------------- */ add_action( 'restrict_manage_users', 'rk_export_users_button' ); function rk_export_users_button( $which ) { if ( $which !== 'top' ) { return; } if ( ! current_user_can( 'list_users' ) ) { return; } $url = wp_nonce_url( admin_url( 'admin-post.php?action=rk_export_users' ), 'rk_export_users' ); echo 'Export Users'; } /* ========================================================= * EXPORT PLUGINS * ========================================================= */ add_action( 'admin_post_rk_export_plugins', 'rk_do_export_plugins' ); function rk_do_export_plugins() { if ( ! current_user_can( 'activate_plugins' ) ) { wp_die( 'You do not have permission to export plugins.' ); } check_admin_referer( 'rk_export_plugins' ); if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $plugins = get_plugins(); $active_plugins = (array) get_option( 'active_plugins', array() ); // Clean output buffer while ( ob_get_level() ) { ob_end_clean(); } $filename = 'plugins-export-' . date( 'Y-m-d-H-i-s' ) . '.csv'; header( 'Content-Type: text/csv; charset=utf-8' ); header( 'Content-Disposition: attachment; filename="' . $filename . '"' ); header( 'Pragma: no-cache' ); header( 'Expires: 0' ); $output = fopen( 'php://output', 'w' ); // Excel UTF-8 BOM fprintf( $output, chr(0xEF) . chr(0xBB) . chr(0xBF) ); // Headers fputcsv( $output, array( 'Plugin Name', 'Active / Deactivate Plugin' ) ); foreach ( $plugins as $plugin_file => $plugin_data ) { $plugin_name = isset( $plugin_data['Name'] ) ? $plugin_data['Name'] : ''; $status = in_array( $plugin_file, $active_plugins, true ) ? 'Active' : 'Deactivate'; fputcsv( $output, array( $plugin_name, $status ) ); } fclose( $output ); exit; } /* ========================================================= * EXPORT USERS * ========================================================= */ add_action( 'admin_post_rk_export_users', 'rk_do_export_users' ); function rk_do_export_users() { if ( ! current_user_can( 'list_users' ) ) { wp_die( 'You do not have permission to export users.' ); } check_admin_referer( 'rk_export_users' ); $users = get_users( array( 'orderby' => 'user_login', 'order' => 'ASC' ) ); // Clean output buffer while ( ob_get_level() ) { ob_end_clean(); } $filename = 'users-export-' . date( 'Y-m-d-H-i-s' ) . '.csv'; header( 'Content-Type: text/csv; charset=utf-8' ); header( 'Content-Disposition: attachment; filename="' . $filename . '"' ); header( 'Pragma: no-cache' ); header( 'Expires: 0' ); $output = fopen( 'php://output', 'w' ); // Excel UTF-8 BOM fprintf( $output, chr(0xEF) . chr(0xBB) . chr(0xBF) ); // Headers fputcsv( $output, array( 'Username', 'User Role' ) ); foreach ( $users as $user ) { $roles = array(); if ( ! empty( $user->roles ) ) { foreach ( $user->roles as $role ) { $wp_roles = wp_roles(); if ( isset( $wp_roles->roles[ $role ]['name'] ) ) { $roles[] = translate_user_role( $wp_roles->roles[ $role ]['name'] ); } else { $roles[] = $role; } } } $role_name = ! empty( $roles ) ? implode( ', ', $roles ) : 'No role'; fputcsv( $output, array( $user->user_login, $role_name ) ); } fclose( $output ); exit; }
Please confirm you want to block this member.
You will no longer be able to:
Please note: This action will also remove this member from your connections and send a report to the site admin. Please allow a few minutes for this process to complete.