Making WordPress.org

Changeset 2747


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.

Location:
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/includes
Files:
4 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
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/includes/reimbursement-requests-dashboard.php

    r2706 r2747  
    1010    add_action( 'network_admin_menu',    __NAMESPACE__ . '\register_submenu_page' );
    1111    add_action( 'init',                  __NAMESPACE__ . '\upgrade_database'      );
    12 
    13 } elseif ( is_admin() ) {
    14     add_action( 'save_post',    __NAMESPACE__ . '\update_index_row', 11, 2 );   // See note in callback about priority
    15     add_action( 'trashed_post', __NAMESPACE__ . '\delete_index_row'        );
    16     add_action( 'delete_post',  __NAMESPACE__ . '\delete_index_row'        );
    17     add_action( 'draft_wcb_reimbursement', __NAMESPACE__ . '\delete_index_row' );
    18 }
     12}
     13
     14add_action( 'save_post',    __NAMESPACE__ . '\update_index_row', 11, 2 );   // See note in callback about priority
     15add_action( 'trashed_post', __NAMESPACE__ . '\delete_index_row'        );
     16add_action( 'delete_post',  __NAMESPACE__ . '\delete_index_row'        );
     17add_action( 'draft_wcb_reimbursement', __NAMESPACE__ . '\delete_index_row' );
    1918
    2019/**
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/includes/reimbursement-requests-list-table.php

    r2647 r2747  
    8080     */
    8181    protected function column_request_title( $index_row ) {
    82         $title = empty( $index_row->request_title ) ? '(no title)' : $index_row->request_title;
     82        $blog_id = $index_row->blog_id;
     83        switch_to_blog( $blog_id );
     84        $post = get_post( $index_row->request_id );
     85        $title = get_the_title( $post );
     86        $title = empty( $title ) ? '(no title)' : $title;
     87        $edit_post_link = add_query_arg( array( 'post' => $post->ID, 'action' => 'edit' ), admin_url( 'post.php' ) );
     88        $actions = array(
     89            'view-all' => sprintf( '<a href="%s" target="_blank">View All</a>', esc_url( admin_url( 'edit.php?post_type=wcb_reimbursement' ) ) ),
     90        );
    8391
    84         $edit_url = get_admin_url(
    85             $index_row->blog_id,
    86             sprintf( 'post.php?post=%s&action=edit', $index_row->request_id )
    87         );
     92        if ( $post->post_status == 'wcb-pending-approval' ) {
     93            $action_url = wp_nonce_url( add_query_arg( array(
     94                'wcb-approve' => sprintf( '%d-%d', $blog_id, $post->ID ),
     95            ) ), sprintf( 'wcb-approve-%d-%d', $blog_id, $post->ID ) );
     96
     97            $actions['wcb-approve'] = sprintf( '<a style="color: green;" onclick="return confirm(\'Approve this reimbursement request?\');" href="%s">Approve</a>', esc_url( $action_url ) );
     98
     99        } elseif ( $post->post_status == 'wcb-approved' ) {
     100            $action_url = wp_nonce_url( add_query_arg( array(
     101                'wcb-set-pending-payment' => sprintf( '%d-%d', $blog_id, $post->ID ),
     102            ) ), sprintf( 'wcb-set-pending-payment-%d-%d', $blog_id, $post->ID ) );
     103
     104            $actions['wcb-set-pending-payment'] = sprintf( '<a style="color: green;" onclick="return confirm(\'Set this request as pending payment?\');" href="%s">Set as Pending Payment</a>', esc_url( $action_url ) );
     105        }
    88106
    89107        ob_start();
    90108        ?>
    91109
    92         <a href="<?php echo esc_url( $edit_url ); ?>">
     110        <a href="<?php echo esc_url( $edit_post_link ); ?>" class="row-title" target="_blank">
    93111            <?php echo esc_html( $title ); ?>
     112            <?php echo $this->row_actions( $actions ); ?>
    94113        </a>
    95114
    96115        <?php
    97116
    98         return ob_get_clean();
     117        $output = ob_get_clean();
     118        restore_current_blog();
     119        return $output;
    99120    }
    100121
  • 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.