[wp-hackers] Multisite global user setting reset

Drew xoodrew at gmail.com
Mon Sep 30 22:00:58 UTC 2013


You can hook into the 'edit_posts_per_page' filter in
class-wp-posts-list-table.php.
It covers any/all pages (afaik) regardless of whether a post_type is passed.

Something like this should work. It's set to max at 20, but allows fewer:

/**
>  * Force all the things to 20 max X per page.
>  *
>  * @param int    $per_page  The number of items to show per page.
>  * @param string $post_type The post type.
>  *
>  * @return int Filtered number of items to show per page.
>  */
> function force_per_page( $per_page, $post_type ) {
>     return $per_page >= 21 ? 20 : $per_page;
> }
> add_filter( 'edit_posts_per_page', 'force_per_page', 10, 2 );
>


On Mon, Sep 30, 2013 at 2:50 PM, Nikola Nikolov <nikolov.tmw at gmail.com>wrote:

> The quickest thing I can think of is a mu-plugin, which would hook to one
> of the query filters and would simply override the posts_per_page(in case
> of users it would be different) query variable.
>
> Here is an example plugin that you can place straight into *
> /wp-content/mu-plugins/override-counts.php* :
>
>
> <?php
> /*
> Plugin Name: Override WP List Table limit preferences
> */
>
>
> // Override the posts per page variable
> function my_ppp_query_overload( $vars ) {
>     if ( is_admin() ) { // Only affect the admin queries
>         $vars['posts_per_page'] = *20*;
>     }
>     return $vars;
> }
> add_filter( 'request', 'my_ppp_query_overload' );
>
> function my_users_number_query_overload( $query ) {
>         if ( is_admin() ) { // Only affect the admin queries
>                 global $wpdb;
>                 $query->query_vars['number'] = *20*;
>                 // limit
>                 if ( isset( $query->query_vars['number'] ) &&
> $query->query_vars['number'] ) {
>                         if ( $query->query_vars['offset'] ) {
>                                 $query->query_limit =
> $wpdb->prepare("LIMIT %d, %d",
> $query->query_vars['offset'], $query->query_vars['number']);
>                         } else {
>                                 $query->query_limit =
> $wpdb->prepare("LIMIT %d",
> $query->query_vars['number']);
>                         }
>                 }
>         }
> }
> add_action( 'pre_user_query', 'my_users_number_query_overload', 10 );
>
> // The users list needs some extra help by overriding the user's
> preference.
> // Otherwise, the table would list only X users, but the pagination
> would be incorrect.
> function my_override_user_dashboard_settings() {
>         if ( is_admin() && ( $uid = get_current_user_id() ) ) {
>                 $user_settings = array( 'users_per_page',
> 'site_users_network_per_page' );
>                 update_user_option( $uid, 'users_per_page', *20* );
>         }
> }
> add_action( 'init', 'my_override_user_dashboard_settings', 10 );
>
>
> I have only tried this in a normal install, but I see no reason for it not
> to work in a multisite install as well.
>
> You can adjust all "20" numbers to whatever you want your users to be
> limited to. Note that for the post/pages/custom post types they will still
> see their preferred number in the "Screen Options" panel, but for the Users
> lists, they will actually see the number that you enter(and it will be
> over-ridden on every request).
>
> That is because, when hooking to the "request" filter, the posts table
> pagination adjusts automatically just fine, but the users pagination does
> not.
>
> If that doesn't suite you well enough, it will be at least a pretty good
> point to start at :)
>
> Hope that helps,
> Nikola Nikolov
>
>
> On Mon, Sep 30, 2013 at 11:01 PM, Jesse Friedman <me at jes.se.com> wrote:
>
> > We are experiencing a rather large load on our servers because we have
> 500
> > sites on a multisite network with a 100 plus users that are working all
> day
> > long.
> >
> > One thing I would like to do to limit the load on the server is to
> globally
> > control the number of posts, users, cpt's, comments, etc... that someone
> > can display in their admin screen.
> >
> > Right now I'm sure many of my users have changed that number to show 50,
> > 100 or more posts on any given screen.
> >
> > I would like to reset everything to display 20 items per page. Anyone
> have
> > an easy way to do this?
> >
> > --
> > thanks
> >
> > *jesse friedman*
> > jes.se.com *
> > *
> > Book: Web Designers Guide to WordPress -
> > http://wdgwp.com/onamazon<http://wdgwp.com/onamazon>
> > Twitter: @professor <http://twitter.com/professor>
> > Facebook: Like<
> > https://www.facebook.com/pages/Jesse-Friedman/204793299545174>
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>



-- 

— I've kinda got a thing for WordPress >
http://www.werdswords.com<http://www.drewapicture.com>


More information about the wp-hackers mailing list