Skip to content

Instantly share code, notes, and snippets.

@soderlind
Created August 28, 2023 08:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soderlind/220a5748b0e64e495bc126b0b7421754 to your computer and use it in GitHub Desktop.
Save soderlind/220a5748b0e64e495bc126b0b7421754 to your computer and use it in GitHub Desktop.
WordPress Admin: Hardcode max number of items per page.
<?php
/**
* name
*
* @package Soderlind\MuPlugins\HardcodeNumberOfItems
* @author Per Soderlind
* @copyright 2021 Per Soderlind
* @license GPL-2.0+
*
* @wordpress-plugin
* Plugin Name: Hardcode number of items per page.
* Description: Will set the number of items per page to max 20.
* Version: 1.0.0
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
declare( strict_types = 1 );
namespace Soderlind\MuPlugins\HardcodeNumberOfItems;
if ( ! defined( 'ABSPATH' ) ) {
wp_die();
}
/**
* Set the number of items per page to max 20.
*
* @param int $val Number of items per page.
* @return int
*/
function __return_max_20( $val ) : int { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
return ( $val > 20 ) ? 20 : $val;
}
add_filter( 'edit_category_per_page', __NAMESPACE__ . '\__return_max_20' );
add_filter( 'edit_comments_per_page', __NAMESPACE__ . '\__return_max_20' );
add_filter( 'edit_page_per_page', __NAMESPACE__ . '\__return_max_20' );
add_filter( 'edit_post_per_page', __NAMESPACE__ . '\__return_max_20' );
add_filter( 'edit_post_tag_per_page', __NAMESPACE__ . '\__return_max_20' );
add_filter( 'plugins_network_per_page', __NAMESPACE__ . '\__return_max_20' );
add_filter( 'plugins_per_page', __NAMESPACE__ . '\__return_max_20' );
add_filter( 'site_themes_network_per_page', __NAMESPACE__ . '\__return_max_20' );
add_filter( 'site_users_network_per_page', __NAMESPACE__ . '\__return_max_20' );
add_filter( 'sites_network_per_page', __NAMESPACE__ . '\__return_max_20' );
add_filter( 'themes_network_per_page', __NAMESPACE__ . '\__return_max_20' );
add_filter( 'upload_per_page', __NAMESPACE__ . '\__return_max_20' );
add_filter( 'users_network_per_page', __NAMESPACE__ . '\__return_max_20' );
add_filter( 'users_per_page', __NAMESPACE__ . '\__return_max_20' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment