Making WordPress.org


Ignore:
Timestamp:
03/14/2016 06:17:18 PM (10 years ago)
Author:
kovshenin
Message:

WordCamp Budgets: Add handlers for network dashboard actions.

Move "approve" and "set as pending payment" action link handlers
to the main network dashboard file, allow for reimbursement
requests too.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/includes/payment-requests-dashboard.php

    r2694 r2747  
    2020        add_action( 'init', array( __CLASS__, 'upgrade' ) );
    2121        add_action( 'init', array( __CLASS__, 'process_import_request' ) );
    22 
    23         // Dashboard actions.
    24         add_action( 'init', array( __CLASS__, 'process_action_approve' ) );
    25         add_action( 'init', array( __CLASS__, 'process_action_set_pending_payment' ) );
    2622
    2723        // Diff-based updates to the index.
     
    245241            <h1>Vendor Payments</h1>
    246242
    247             <?php do_action( 'admin_notices' ); ?>
    248243            <?php settings_errors(); ?>
    249244
     
    284279
    285280        <?php
    286     }
    287 
    288     /**
    289      * Process Approve button in network admin
    290      */
    291     public static function process_action_approve() {
    292         if ( ! current_user_can( 'manage_network' ) )
    293             return;
    294 
    295         if ( empty( $_GET['wcb-approve'] ) || empty( $_GET['_wpnonce'] ) )
    296             return;
    297 
    298         list( $blog_id, $post_id ) = explode( '-', $_GET['wcb-approve'] );
    299 
    300         if ( ! wp_verify_nonce( $_GET['_wpnonce'], sprintf( 'wcb-approve-%d-%d', $blog_id, $post_id ) ) ) {
    301             add_action( 'admin_notices', function() {
    302                 ?><div class="notice notice-error is-dismissible">
    303                     <p><?php _e( 'Error! Could not verify nonce.', 'wordcamporg' ); ?></p>
    304                 </div><?php
    305             });
    306             return;
    307         }
    308 
    309         switch_to_blog( $blog_id );
    310         $post = get_post( $post_id );
    311         if ( $post->post_type == 'wcp_payment_request' ) {
    312             $post->post_status = 'wcb-approved';
    313             wp_insert_post( $post );
    314 
    315             WordCamp_Budgets::log( $post->ID, get_current_user_id(), 'Request approved via Network Admin', array(
    316                 'action' => 'approved',
    317             ) );
    318 
    319             add_action( 'admin_notices', function() {
    320                 ?><div class="notice notice-success is-dismissible">
    321                     <p><?php _e( 'Success! Request has been marked as approved.', 'wordcamporg' ); ?></p>
    322                 </div><?php
    323             });
    324         }
    325         restore_current_blog();
    326     }
    327 
    328     /**
    329      * Process "Set as Pending Payment" dashboard action.
    330      */
    331     public static function process_action_set_pending_payment() {
    332         if ( ! current_user_can( 'manage_network' ) )
    333             return;
    334 
    335         if ( empty( $_GET['wcb-set-pending-payment'] ) || empty( $_GET['_wpnonce'] ) )
    336             return;
    337 
    338         list( $blog_id, $post_id ) = explode( '-', $_GET['wcb-set-pending-payment'] );
    339 
    340         if ( ! wp_verify_nonce( $_GET['_wpnonce'], sprintf( 'wcb-set-pending-payment-%d-%d', $blog_id, $post_id ) ) ) {
    341             add_action( 'admin_notices', function() {
    342                 ?><div class="notice notice-error is-dismissible">
    343                     <p><?php _e( 'Error! Could not verify nonce.', 'wordcamporg' ); ?></p>
    344                 </div><?php
    345             });
    346             return;
    347         }
    348 
    349         switch_to_blog( $blog_id );
    350         $post = get_post( $post_id );
    351         if ( $post->post_type == 'wcp_payment_request' ) {
    352             $post->post_status = 'wcb-pending-payment';
    353             wp_insert_post( $post );
    354 
    355             WordCamp_Budgets::log( $post->ID, get_current_user_id(), 'Request set as Pending Payment via Network Admin', array(
    356                 'action' => 'set-pending-payment',
    357             ) );
    358 
    359             add_action( 'admin_notices', function() {
    360                 ?><div class="notice notice-success is-dismissible">
    361                     <p><?php _e( 'Success! Request has been marked as Pending Payment.', 'wordcamporg' ); ?></p>
    362                 </div><?php
    363             });
    364         }
    365         restore_current_blog();
    366281    }
    367282
Note: See TracChangeset for help on using the changeset viewer.