mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-25 18:48:57 +01:00
cc5ed3a485
The exceptions to this are update_post_meta() and add_post_meta() which are often used by plugins in POST handlers and will continue accepting slashed data for now. Introduce wp_upate_post_meta() and wp_add_post_meta() as unslashed alternatives to update_post_meta() and add_post_meta(). These functions could become methods in WP_Post so don't use them too heavily yet. Remove all escape() calls from wp_xmlrpc_server. Now that core expects unslashed data this is no longer needed. Remove addslashes(), addslashes_gpc(), add_magic_quotes() calls on data being prepared for handoff to core functions that until now expected slashed data. Adding slashes in no longer necessary. Introduce wp_unslash() and use to it remove slashes from GPCS data before using it in core API. Almost every instance of stripslashes() in core should now be wp_unslash(). In the future (a release or three) when GPCS is no longer slashed, wp_unslash() will stop stripping slashes and simply return what is passed. At this point wp_unslash() calls can be removed from core. Introduce wp_slash() for slashing GPCS data. This will also turn into a noop once GPCS is no longer slashed. wp_slash() should almost never be used. It is mainly of use in unit tests. Plugins should use wp_unslash() on data being passed to core API. Plugins should no longer slash data being passed to core. So when you get_post() and then wp_insert_post() the post data from get_post() no longer needs addslashes(). Most plugins were not bothering with this. They will magically start doing the right thing. Unfortunately, those few souls who did it properly will now have to avoid calling addslashes() for 3.6 and newer. Use wp_kses_post() and wp_kses_data(), which expect unslashed data, instead of wp_filter_post_kses() and wp_filter_kses(), which expect slashed data. Filters are no longer passed slashed data. Remove many no longer necessary calls to $wpdb->escape() and esc_sql(). In wp_get_referer() and wp_get_original_referer(), return unslashed data. Remove old stripslashes() calls from WP_Widget::update() handlers. These haven't been necessary since WP_Widget. Switch several queries over to prepare(). Expect something to break. Props alexkingorg see #21767 git-svn-id: http://core.svn.wordpress.org/trunk@23416 1a063a9b-81f0-0310-95a4-ce76da25c4cd
273 lines
8.6 KiB
PHP
273 lines
8.6 KiB
PHP
<?php
|
|
/**
|
|
* Multisite Users List Table class.
|
|
*
|
|
* @package WordPress
|
|
* @subpackage List_Table
|
|
* @since 3.1.0
|
|
* @access private
|
|
*/
|
|
class WP_MS_Users_List_Table extends WP_List_Table {
|
|
|
|
function ajax_user_can() {
|
|
return current_user_can( 'manage_network_users' );
|
|
}
|
|
|
|
function prepare_items() {
|
|
global $usersearch, $role, $wpdb, $mode;
|
|
|
|
$usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
|
|
|
|
$users_per_page = $this->get_items_per_page( 'users_network_per_page' );
|
|
|
|
$role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
|
|
|
|
$paged = $this->get_pagenum();
|
|
|
|
$args = array(
|
|
'number' => $users_per_page,
|
|
'offset' => ( $paged-1 ) * $users_per_page,
|
|
'search' => $usersearch,
|
|
'blog_id' => 0,
|
|
'fields' => 'all_with_meta'
|
|
);
|
|
|
|
if ( wp_is_large_network( 'users' ) )
|
|
$args['search'] = ltrim( $args['search'], '*' );
|
|
|
|
if ( $role == 'super' ) {
|
|
$logins = implode( "', '", get_super_admins() );
|
|
$args['include'] = $wpdb->get_col( "SELECT ID FROM $wpdb->users WHERE user_login IN ('$logins')" );
|
|
}
|
|
|
|
// If the network is large and a search is not being performed, show only the latest users with no paging in order
|
|
// to avoid expensive count queries.
|
|
if ( !$usersearch && wp_is_large_network( 'users' ) ) {
|
|
if ( !isset($_REQUEST['orderby']) )
|
|
$_GET['orderby'] = $_REQUEST['orderby'] = 'id';
|
|
if ( !isset($_REQUEST['order']) )
|
|
$_GET['order'] = $_REQUEST['order'] = 'DESC';
|
|
$args['count_total'] = false;
|
|
}
|
|
|
|
if ( isset( $_REQUEST['orderby'] ) )
|
|
$args['orderby'] = $_REQUEST['orderby'];
|
|
|
|
if ( isset( $_REQUEST['order'] ) )
|
|
$args['order'] = $_REQUEST['order'];
|
|
|
|
$mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
|
|
|
|
// Query the user IDs for this page
|
|
$wp_user_search = new WP_User_Query( $args );
|
|
|
|
$this->items = $wp_user_search->get_results();
|
|
|
|
$this->set_pagination_args( array(
|
|
'total_items' => $wp_user_search->get_total(),
|
|
'per_page' => $users_per_page,
|
|
) );
|
|
}
|
|
|
|
function get_bulk_actions() {
|
|
$actions = array();
|
|
if ( current_user_can( 'delete_users' ) )
|
|
$actions['delete'] = __( 'Delete' );
|
|
$actions['spam'] = _x( 'Mark as Spam', 'user' );
|
|
$actions['notspam'] = _x( 'Not Spam', 'user' );
|
|
|
|
return $actions;
|
|
}
|
|
|
|
function no_items() {
|
|
_e( 'No users found.' );
|
|
}
|
|
|
|
function get_views() {
|
|
global $wp_roles, $role;
|
|
|
|
$total_users = get_user_count();
|
|
$super_admins = get_super_admins();
|
|
$total_admins = count( $super_admins );
|
|
|
|
$current_role = false;
|
|
$class = $role != 'super' ? ' class="current"' : '';
|
|
$role_links = array();
|
|
$role_links['all'] = "<a href='" . network_admin_url('users.php') . "'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>';
|
|
$class = $role == 'super' ? ' class="current"' : '';
|
|
$role_links['super'] = "<a href='" . network_admin_url('users.php?role=super') . "'$class>" . sprintf( _n( 'Super Admin <span class="count">(%s)</span>', 'Super Admins <span class="count">(%s)</span>', $total_admins ), number_format_i18n( $total_admins ) ) . '</a>';
|
|
|
|
return $role_links;
|
|
}
|
|
|
|
function pagination( $which ) {
|
|
global $mode;
|
|
|
|
parent::pagination ( $which );
|
|
|
|
if ( 'top' == $which )
|
|
$this->view_switcher( $mode );
|
|
}
|
|
|
|
function get_columns() {
|
|
$users_columns = array(
|
|
'cb' => '<input type="checkbox" />',
|
|
'username' => __( 'Username' ),
|
|
'name' => __( 'Name' ),
|
|
'email' => __( 'E-mail' ),
|
|
'registered' => _x( 'Registered', 'user' ),
|
|
'blogs' => __( 'Sites' )
|
|
);
|
|
$users_columns = apply_filters( 'wpmu_users_columns', $users_columns );
|
|
|
|
return $users_columns;
|
|
}
|
|
|
|
function get_sortable_columns() {
|
|
return array(
|
|
'username' => 'login',
|
|
'name' => 'name',
|
|
'email' => 'email',
|
|
'registered' => 'id',
|
|
);
|
|
}
|
|
|
|
function display_rows() {
|
|
global $current_site, $mode;
|
|
|
|
$alt = '';
|
|
$super_admins = get_super_admins();
|
|
foreach ( $this->items as $user ) {
|
|
$alt = ( 'alternate' == $alt ) ? '' : 'alternate';
|
|
|
|
$status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' );
|
|
|
|
foreach ( $status_list as $status => $col ) {
|
|
if ( $user->$status )
|
|
$alt .= " $col";
|
|
}
|
|
|
|
?>
|
|
<tr class="<?php echo $alt; ?>">
|
|
<?php
|
|
|
|
list( $columns, $hidden ) = $this->get_column_info();
|
|
|
|
foreach ( $columns as $column_name => $column_display_name ) :
|
|
$class = "class='$column_name column-$column_name'";
|
|
|
|
$style = '';
|
|
if ( in_array( $column_name, $hidden ) )
|
|
$style = ' style="display:none;"';
|
|
|
|
$attributes = "$class$style";
|
|
|
|
switch ( $column_name ) {
|
|
case 'cb': ?>
|
|
<th scope="row" class="check-column">
|
|
<label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>"><?php echo sprintf( __( 'Select %s' ), $user->user_login ); ?></label>
|
|
<input type="checkbox" id="blog_<?php echo $user->ID ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ) ?>" />
|
|
</th>
|
|
<?php
|
|
break;
|
|
|
|
case 'username':
|
|
$avatar = get_avatar( $user->user_email, 32 );
|
|
$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
|
|
|
|
echo "<td $attributes>"; ?>
|
|
<?php echo $avatar; ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo $user->user_login; ?></a><?php
|
|
if ( in_array( $user->user_login, $super_admins ) )
|
|
echo ' - ' . __( 'Super Admin' );
|
|
?></strong>
|
|
<br/>
|
|
<?php
|
|
$actions = array();
|
|
$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
|
|
|
|
if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) {
|
|
$actions['delete'] = '<a href="' . $delete = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&action=deleteuser&id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>';
|
|
}
|
|
|
|
$actions = apply_filters( 'ms_user_row_actions', $actions, $user );
|
|
echo $this->row_actions( $actions );
|
|
?>
|
|
</td>
|
|
<?php
|
|
break;
|
|
|
|
case 'name':
|
|
echo "<td $attributes>$user->first_name $user->last_name</td>";
|
|
break;
|
|
|
|
case 'email':
|
|
echo "<td $attributes><a href='mailto:$user->user_email'>$user->user_email</a></td>";
|
|
break;
|
|
|
|
case 'registered':
|
|
if ( 'list' == $mode )
|
|
$date = 'Y/m/d';
|
|
else
|
|
$date = 'Y/m/d \<\b\r \/\> g:i:s a';
|
|
|
|
echo "<td $attributes>" . mysql2date( $date, $user->user_registered ) . "</td>";
|
|
break;
|
|
|
|
case 'blogs':
|
|
$blogs = get_blogs_of_user( $user->ID, true );
|
|
echo "<td $attributes>";
|
|
if ( is_array( $blogs ) ) {
|
|
foreach ( (array) $blogs as $key => $val ) {
|
|
if ( !can_edit_network( $val->site_id ) )
|
|
continue;
|
|
|
|
$path = ( $val->path == '/' ) ? '' : $val->path;
|
|
echo '<span class="site-' . $val->site_id . '" >';
|
|
echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . $current_site->domain, '', $val->domain . $path ) . '</a>';
|
|
echo ' <small class="row-actions">';
|
|
$actions = array();
|
|
$actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>';
|
|
|
|
$class = '';
|
|
if ( get_blog_status( $val->userblog_id, 'spam' ) == 1 )
|
|
$class .= 'site-spammed ';
|
|
if ( get_blog_status( $val->userblog_id, 'mature' ) == 1 )
|
|
$class .= 'site-mature ';
|
|
if ( get_blog_status( $val->userblog_id, 'deleted' ) == 1 )
|
|
$class .= 'site-deleted ';
|
|
if ( get_blog_status( $val->userblog_id, 'archived' ) == 1 )
|
|
$class .= 'site-archived ';
|
|
|
|
$actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>';
|
|
|
|
$actions = apply_filters('ms_user_list_site_actions', $actions, $val->userblog_id);
|
|
|
|
$i=0;
|
|
$action_count = count( $actions );
|
|
foreach ( $actions as $action => $link ) {
|
|
++$i;
|
|
( $i == $action_count ) ? $sep = '' : $sep = ' | ';
|
|
echo "<span class='$action'>$link$sep</span>";
|
|
}
|
|
echo '</small></span><br/>';
|
|
}
|
|
}
|
|
?>
|
|
</td>
|
|
<?php
|
|
break;
|
|
|
|
default:
|
|
echo "<td $attributes>";
|
|
echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );
|
|
echo "</td>";
|
|
break;
|
|
}
|
|
endforeach
|
|
?>
|
|
</tr>
|
|
<?php
|
|
}
|
|
}
|
|
}
|