Making WordPress.org


Ignore:
Timestamp:
02/26/2016 12:34:20 AM (11 years ago)
Author:
kovshenin
Message:

WordCamp.org: Allow network admins/deputies to approve payment requests from the network dashboard.

File:
1 edited

Legend:

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

    r2623 r2627  
    2020                add_action( 'network_admin_menu', array( __CLASS__, 'network_admin_menu' ) );
    2121                add_action( 'init', array( __CLASS__, 'upgrade' ) );
     22                add_action( 'init', array( __CLASS__, 'process_approval' ) );
    2223                add_action( 'init', array( __CLASS__, 'process_export_request' ) );
    2324                add_action( 'init', array( __CLASS__, 'process_import_request' ) );
    … …  
    256257                        <h1>Vendor Payments</h1>
    257258
     259                        <?php do_action( 'admin_notices' ); ?>
    258260                        <?php settings_errors(); ?>
    259261
    … …  
    296298
    297299                <?php
     300        }
     301
     302        /**
     303         * Process Approve button in network admin
     304         */
     305        public static function process_approval() {
     306                if ( ! current_user_can( 'network_admin' ) )
     307                        return;
     308
     309                if ( empty( $_GET['wcb-approve'] ) || empty( $_GET['_wpnonce'] ) )
     310                        return;
     311
     312                list( $blog_id, $post_id ) = explode( '-', $_GET['wcb-approve'] );
     313
     314                if ( ! wp_verify_nonce( $_GET['_wpnonce'], sprintf( 'wcb-approve-%d-%d', $blog_id, $post_id ) ) ) {
     315                        add_action( 'admin_notices', function() {
     316                                ?><div class="notice notice-error is-dismissible">
     317                                        <p><?php _e( 'Error! Could not verify nonce.', 'wordcamporg' ); ?></p>
     318                                </div><?php
     319                        });
     320                        return;
     321                }
     322
     323                switch_to_blog( $blog_id );
     324                $post = get_post( $post_id );
     325                if ( $post->post_type == 'wcp_payment_request' ) {
     326                        $post->post_status = 'wcb-approved';
     327                        wp_insert_post( $post );
     328
     329                        WordCamp_Budgets::log( $post->ID, get_current_user_id(), 'Request approved via Network Admin', array(
     330                                'action' => 'approved',
     331                        ) );
     332
     333                        add_action( 'admin_notices', function() {
     334                                ?><div class="notice notice-success is-dismissible">
     335                                        <p><?php _e( 'Success! Request has been marked as approved.', 'wordcamporg' ); ?></p>
     336                                </div><?php
     337                        });
     338                }
     339                restore_current_blog();
    298340        }
    299341
Note: See TracChangeset for help on using the changeset viewer.