Skip to:
Content

BuddyPress.org

Changeset 13937


Ignore:
Timestamp:
06/24/2024 05:29:42 PM (6 months ago)
Author:
imath
Message:

Manage BP specific WP List Tables pagination from a central function

  • Introduces bp_admin_set_screen_options() to deal with WP List Table pagination

for Activity, Groups, Opt-outs & Site Invitations.

  • Deprecates bp_activity_admin_screen_options() & bp_groups_admin_screen_options().

Props emaralive

Fixes #9195
Closes https://github.com/buddypress/buddypress/pull/320

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-admin.php

    r13871 r13937  
    1515
    1616// Include WP's list table class.
    17 if ( ! class_exists( 'WP_List_Table' ) ) require( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
    18 
    19 // Per_page screen option. Has to be hooked in extremely early.
    20 if ( is_admin() && ! empty( $_REQUEST['page'] ) && 'bp-activity' == $_REQUEST['page'] ) {
    21     add_filter( 'set-screen-option', 'bp_activity_admin_screen_options', 10, 3 );
     17if ( ! class_exists( 'WP_List_Table' ) ) {
     18    require ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
    2219}
    2320
     
    139136}
    140137add_action( 'wp_ajax_bp-activity-admin-reply', 'bp_activity_admin_reply' );
    141 
    142 /**
    143  * Handle save/update of screen options for the Activity component admin screen.
    144  *
    145  * @since 1.6.0
    146  *
    147  * @param string $value     Will always be false unless another plugin filters it first.
    148  * @param string $option    Screen option name.
    149  * @param string $new_value Screen option form value.
    150  * @return string|int Option value. False to abandon update.
    151  */
    152 function bp_activity_admin_screen_options( $value, $option, $new_value ) {
    153     if ( 'toplevel_page_bp_activity_per_page' != $option && 'toplevel_page_bp_activity_network_per_page' != $option )
    154         return $value;
    155 
    156     // Per page.
    157     $new_value = (int) $new_value;
    158     if ( $new_value < 1 || $new_value > 999 )
    159         return $value;
    160 
    161     return $new_value;
    162 }
    163138
    164139/**
  • trunk/src/bp-core/admin/bp-core-admin-functions.php

    r13928 r13937  
    17001700    <?php
    17011701}
     1702
     1703/**
     1704 * Sets the "per page" screen option for BP Items WP Admin lists.
     1705 *
     1706 * @since 14.0.0
     1707 *
     1708 * @param bool   $value     Will always be false unless another plugin filters it first.
     1709 * @param string $option    Screen option name.
     1710 * @param string $new_value Screen option form value.
     1711 * @return string|int Option value. False to abandon update.
     1712 */
     1713function bp_admin_set_screen_options( $value, $option, $new_value ) {
     1714    // Sanitize the new value.
     1715    $new_value = (int) $new_value;
     1716
     1717    // Make sure it's a reasonable value to paginate results.
     1718    if ( $new_value < 1 || $new_value > 999 ) {
     1719        return $value;
     1720    }
     1721
     1722    return $new_value;
     1723}
     1724add_filter( 'set_screen_option_toplevel_page_bp_activity_per_page', 'bp_admin_set_screen_options', 10, 3 );
     1725add_filter( 'set_screen_option_toplevel_page_bp_activity_network_per_page', 'bp_admin_set_screen_options', 10, 3 );
     1726add_filter( 'set_screen_option_toplevel_page_bp_groups_per_page', 'bp_admin_set_screen_options', 10, 3 );
     1727add_filter( 'set_screen_option_toplevel_page_bp_groups_network_per_page', 'bp_admin_set_screen_options', 10, 3 );
     1728add_filter( 'set_screen_option_tools_page_bp_optouts_per_page', 'bp_admin_set_screen_options', 10, 3 );
     1729add_filter( 'set_screen_option_tools_page_bp_optouts_network_per_page', 'bp_admin_set_screen_options', 10, 3 );
     1730add_filter( 'set_screen_option_tools_page_bp_members_invitations_per_page', 'bp_admin_set_screen_options', 10, 3 );
     1731add_filter( 'set_screen_option_tools_page_bp_members_invitations_network_per_page', 'bp_admin_set_screen_options', 10, 3 );
  • trunk/src/bp-core/deprecated/14.0.php

    r13936 r13937  
    9999    return false;
    100100}
     101
     102/**
     103 * Handle save/update of screen options for the Activity component admin screen.
     104 *
     105 * @since 1.6.0
     106 * @deprecated 14.0.0
     107 *
     108 * @param string $value     Will always be false unless another plugin filters it first.
     109 * @param string $option    Screen option name.
     110 * @param string $new_value Screen option form value.
     111 * @return string|int Option value. False to abandon update.
     112 */
     113function bp_activity_admin_screen_options( $value, $option, $new_value ) {
     114    _deprecated_function( __FUNCTION__, '14.0.0', 'bp_admin_set_screen_options' );
     115
     116    return bp_admin_set_screen_options( $value, $option, $new_value );
     117}
     118
     119/**
     120 * Handle save/update of screen options for the Groups component admin screen.
     121 *
     122 * @since 1.7.0
     123 * @deprecated 14.0.0
     124 *
     125 * @param string $value     Will always be false unless another plugin filters it first.
     126 * @param string $option    Screen option name.
     127 * @param string $new_value Screen option form value.
     128 * @return string|int Option value. False to abandon update.
     129 */
     130function bp_groups_admin_screen_options( $value, $option, $new_value ) {
     131    _deprecated_function( __FUNCTION__, '14.0.0', 'bp_admin_set_screen_options' );
     132
     133    return bp_admin_set_screen_options( $value, $option, $new_value );
     134}
  • trunk/src/bp-groups/bp-groups-admin.php

    r13890 r13937  
    1717if ( ! class_exists( 'WP_List_Table' ) ) {
    1818    require ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
    19 }
    20 
    21 // The per_page screen option. Has to be hooked in extremely early.
    22 if ( is_admin() && ! empty( $_REQUEST['page'] ) && 'bp-groups' == $_REQUEST['page'] ) {
    23     add_filter( 'set-screen-option', 'bp_groups_admin_screen_options', 10, 3 );
    2419}
    2520
     
    525520
    526521/**
    527  * Handle save/update of screen options for the Groups component admin screen.
    528  *
    529  * @since 1.7.0
    530  *
    531  * @param string $value     Will always be false unless another plugin filters it first.
    532  * @param string $option    Screen option name.
    533  * @param string $new_value Screen option form value.
    534  * @return string|int Option value. False to abandon update.
    535  */
    536 function bp_groups_admin_screen_options( $value, $option, $new_value ) {
    537     if ( 'toplevel_page_bp_groups_per_page' != $option && 'toplevel_page_bp_groups_network_per_page' != $option ) {
    538         return $value;
    539     }
    540 
    541     // Per page.
    542     $new_value = (int) $new_value;
    543     if ( $new_value < 1 || $new_value > 999 ) {
    544         return $value;
    545     }
    546 
    547     return $new_value;
    548 }
    549 
    550 /**
    551522 * Select the appropriate Groups admin screen, and output it.
    552523 *
Note: See TracChangeset for help on using the changeset viewer.