Skip to:
Content

bbPress.org


Ignore:
Timestamp:
03/19/2012 06:12:21 PM (9 years ago)
Author:
johnjamesjacoby
Message:

Split admin tools Recount into two functions to handle form submission without duplicate admin notices. Fixes #1788.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-admin/bbp-tools.php

    r3790 r3811  
    2323 * @uses wp_nonce_field() To add a hidden nonce field
    2424 */
    25 function bbp_admin_tools() {
    26 
    27     $recount_list = bbp_recount_list();
    28 
    29     if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) ) {
    30         check_admin_referer( 'do-counts' );
    31 
    32         // Stores messages
    33         $messages = array();
    34 
    35         wp_cache_flush();
    36 
    37         foreach ( (array) $recount_list as $item )
    38             if ( isset( $item[2] ) && isset( $_POST[$item[0]] ) && 1 == $_POST[$item[0]] && is_callable( $item[2] ) )
    39                 $messages[] = call_user_func( $item[2] );
    40 
    41 
    42         if ( count( $messages ) ) {
    43             foreach ( $messages as $message ) {
    44                 bbp_tools_feedback( $message[1] );
    45             }
    46         }
    47     } ?>
     25function bbp_admin_tools_screen() {
     26
     27    $recount_list = bbp_recount_list(); ?>
    4828
    4929    <div class="wrap">
     
    5232
    5333        <h2><?php _e( 'bbPress Recount', 'bbpress' ) ?></h2>
    54 
    55         <?php do_action( 'admin_notices' ); ?>
    5634
    5735        <p><?php _e( 'bbPress keeps a running count of things like replies to each topic and topics in each forum. In rare occasions these counts can fall out of sync. Using this form you can have bbPress manually recount these items.', 'bbpress' ); ?></p>
     
    8866            <fieldset class="submit">
    8967                <input class="button-primary" type="submit" name="submit" value="<?php _e( 'Recount Items', 'bbpress' ); ?>" />
    90                 <?php wp_nonce_field( 'do-counts' ); ?>
     68                <?php wp_nonce_field( 'bbpress-do-counts' ); ?>
    9169            </fieldset>
    9270        </form>
     
    9472
    9573<?php
     74}
     75
     76/**
     77 * Handle the processing and feedback of the admin tools page
     78 *
     79 * @since bbPress (r2613)
     80 *
     81 * @uses bbp_recount_list() To get the recount list
     82 * @uses check_admin_referer() To verify the nonce and the referer
     83 * @uses wp_cache_flush() To flush the cache
     84 * @uses do_action() Calls 'admin_notices' to display the notices
     85 */
     86function bbp_admin_tools_handler() {
     87
     88    if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) ) {
     89        check_admin_referer( 'bbpress-do-counts' );
     90
     91        // Stores messages
     92        $messages     = array();
     93        $recount_list = bbp_recount_list();
     94
     95        wp_cache_flush();
     96
     97        foreach ( (array) $recount_list as $item ) {
     98            if ( isset( $item[2] ) && isset( $_POST[$item[0]] ) && 1 == $_POST[$item[0]] && is_callable( $item[2] ) ) {
     99                $messages[] = call_user_func( $item[2] );
     100            }
     101        }
     102
     103        if ( count( $messages ) ) {
     104            foreach ( $messages as $message ) {
     105                bbp_tools_feedback( $message[1] );
     106            }
     107        }
     108    }
    96109}
    97110
Note: See TracChangeset for help on using the changeset viewer.