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/wordcamp-budgets-dashboard.php

    r2713 r2747  
    1414
    1515add_action( 'admin_init', __NAMESPACE__ . '\process_export_request' );
     16add_action( 'admin_init', __NAMESPACE__ . '\process_action_approve', 11 );
     17add_action( 'admin_init', __NAMESPACE__ . '\process_action_set_pending_payment', 11 );
    1618
    1719/**
     
    536538    return $amount * $rate;
    537539}
     540
     541
     542/**
     543 * Approve a payment or reimbursement request.
     544 */
     545function process_action_approve() {
     546    if ( ! current_user_can( 'manage_network' ) )
     547        return;
     548
     549    if ( empty( $_GET['wcb-approve'] ) || empty( $_GET['_wpnonce'] ) )
     550        return;
     551
     552    list( $blog_id, $post_id ) = explode( '-', $_GET['wcb-approve'] );
     553
     554    if ( ! wp_verify_nonce( $_GET['_wpnonce'], sprintf( 'wcb-approve-%d-%d', $blog_id, $post_id ) ) ) {
     555        add_settings_error( 'wcb-dashboard', 'nonce_error', 'Could not verify nonce.', 'error' );
     556        return;
     557    }
     558
     559    switch_to_blog( $blog_id );
     560    $post = get_post( $post_id );
     561
     562    if ( ! in_array( $post->post_type, array( 'wcp_payment_request', 'wcb_reimbursement' ) ) ) {
     563        add_settings_error( 'wcb-dashboard', 'type_error', 'Invalid post type.', 'error' );
     564        restore_current_blog();
     565        return;
     566    }
     567
     568    $post->post_status = 'wcb-approved';
     569    wp_insert_post( $post );
     570
     571    \WordCamp_Budgets::log( $post->ID, get_current_user_id(), 'Request approved via Network Admin', array(
     572        'action' => 'approved',
     573    ) );
     574
     575    restore_current_blog();
     576    add_settings_error( 'wcb-dashboard', 'success', 'Success! Request has been marked as Approved.', 'updated' );
     577}
     578
     579/**
     580 * Process "Set as Pending Payment" dashboard action.
     581 */
     582function process_action_set_pending_payment() {
     583    if ( ! current_user_can( 'manage_network' ) )
     584        return;
     585
     586    if ( empty( $_GET['wcb-set-pending-payment'] ) || empty( $_GET['_wpnonce'] ) )
     587        return;
     588
     589    list( $blog_id, $post_id ) = explode( '-', $_GET['wcb-set-pending-payment'] );
     590
     591    if ( ! wp_verify_nonce( $_GET['_wpnonce'], sprintf( 'wcb-set-pending-payment-%d-%d', $blog_id, $post_id ) ) ) {
     592        add_settings_error( 'wcb-dashboard', 'nonce_error', 'Could not verify nonce.', 'error' );
     593        return;
     594    }
     595
     596    switch_to_blog( $blog_id );
     597    $post = get_post( $post_id );
     598
     599    if ( ! in_array( $post->post_type, array( 'wcp_payment_request', 'wcb_reimbursement' ) ) ) {
     600        add_settings_error( 'wcb-dashboard', 'type_error', 'Invalid post type.', 'error' );
     601        restore_current_blog();
     602        return;
     603    }
     604
     605    $post->post_status = 'wcb-pending-payment';
     606    wp_insert_post( $post );
     607
     608    \WordCamp_Budgets::log( $post->ID, get_current_user_id(), 'Request set as Pending Payment via Network Admin', array(
     609        'action' => 'set-pending-payment',
     610    ) );
     611
     612    restore_current_blog();
     613    add_settings_error( 'wcb-dashboard', 'success', 'Success! Request has been marked as Pending Payment.', 'updated' );
     614}
Note: See TracChangeset for help on using the changeset viewer.