Hi Team I am new to WordPress, just want to add a new filter option in the multisite WordPress network, in the all-user panel just want to add some filter options.
Asked
Active
Viewed 58 times
1

user3868334
- 57
- 4
1 Answers
0
Here's a bit of a hacky answer for you:
<?php
/**
* Allowing Network Administrators to Export All Users
*/
function __add_export_network_users_button( )
{
if ( !is_network_admin( ) )
return;
$screen = get_current_screen( );
if ( $screen->id != "users-network" )
return;
var_dump( $screen );
?>
<script type="text/javascript">
jQuery(document).ready( function($)
{
$('.tablenav.top .clear, .tablenav.bottom .clear').before('<form action="#" method="POST"><input type="hidden" id="mysite_download_all_users" name="mysite_download_all_users" value="1" /><input class="button button-primary user_export_button" type="submit" value="<?php esc_attr_e( 'Export All Users' );?>" /></form>');
});
</script>
<?php
}
function __export_network_users( )
{
global $wpdb;
if ( !is_network_admin( ) )
return;
if ( !empty( $_POST['mysite_download_all_users'] ) )
{
if ( current_user_can('manage_options') )
{
header("Content-type: application/force-download");
header('Content-Disposition: inline; filename="wp-users-'.date('YmdHis').'.csv"');
$sql = "SELECT
ID,
user_login,
user_email,
CASE
WHEN domain IS NULL THEN 'SUPER ADMIN'
ELSE domain
END AS \"site_domain\",
UPPER( REPLACE( SUBSTR( meta_value, 12 ), '\";b:1;}', '' ) ) AS \"Role\",
last_updated
FROM
wp_usermeta
LEFT JOIN
wp_users
ON user_id = wp_users.ID
LEFT JOIN
wp_blogs
ON wp_blogs.blog_id = REPLACE( REPLACE( meta_key, '_capabilities', '' ), 'wp_', '' )
WHERE
meta_key LIKE '%_capabilities'
ORDER BY
user_id ASC;";
$results = $wpdb->get_results( $sql, 'ARRAY_A' );
if ( is_array( $results ) && 0 < count( $results ) )
{
echo implode( ',', array_keys( $results[0] ) ).PHP_EOL;
foreach ( $results as $result )
echo implode( ',', array_values( $result ) ).PHP_EOL;
exit( 0 );
}
}
}
}
add_action( 'admin_footer', '__add_export_network_users_button' );
add_action( 'admin_init', '__export_network_users' );
Classic Wordpress - there's actions and filters, until there isn't.

Justin
- 1
-
1Hi, while your answer may address the question, it's better to include some [explanation](https://meta.stackoverflow.com/questions/392712/explaining-entirely-code-based-answers) – pierpy May 31 '23 at 18:23