Making WordPress.org


Ignore:
Timestamp:
02/26/2016 06:17:34 PM (10 years ago)
Author:
kovshenin
Message:

WordCamp Budgets: Allow network admins to mark requests as pending payment via the dashboard.

Location:
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/includes
Files:
2 edited

Legend:

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

    r2632 r2641  
    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' ) );
    2322        add_action( 'init', array( __CLASS__, 'process_export_request' ) );
    2423        add_action( 'init', array( __CLASS__, 'process_import_request' ) );
     24
     25        // Dashboard actions.
     26        add_action( 'init', array( __CLASS__, 'process_action_approve' ) );
     27        add_action( 'init', array( __CLASS__, 'process_action_set_pending_payment' ) );
    2528
    2629        // Diff-based updates to the index.
     
    303306     * Process Approve button in network admin
    304307     */
    305     public static function process_approval() {
    306         if ( ! current_user_can( 'network_admin' ) )
     308    public static function process_action_approve() {
     309        if ( ! current_user_can( 'manage_network' ) )
    307310            return;
    308311
     
    334337                ?><div class="notice notice-success is-dismissible">
    335338                    <p><?php _e( 'Success! Request has been marked as approved.', 'wordcamporg' ); ?></p>
     339                </div><?php
     340            });
     341        }
     342        restore_current_blog();
     343    }
     344
     345    /**
     346     * Process "Set as Pending Payment" dashboard action.
     347     */
     348    public static function process_action_set_pending_payment() {
     349        if ( ! current_user_can( 'manage_network' ) )
     350            return;
     351
     352        if ( empty( $_GET['wcb-set-pending-payment'] ) || empty( $_GET['_wpnonce'] ) )
     353            return;
     354
     355        list( $blog_id, $post_id ) = explode( '-', $_GET['wcb-set-pending-payment'] );
     356
     357        if ( ! wp_verify_nonce( $_GET['_wpnonce'], sprintf( 'wcb-set-pending-payment-%d-%d', $blog_id, $post_id ) ) ) {
     358            add_action( 'admin_notices', function() {
     359                ?><div class="notice notice-error is-dismissible">
     360                    <p><?php _e( 'Error! Could not verify nonce.', 'wordcamporg' ); ?></p>
     361                </div><?php
     362            });
     363            return;
     364        }
     365
     366        switch_to_blog( $blog_id );
     367        $post = get_post( $post_id );
     368        if ( $post->post_type == 'wcp_payment_request' ) {
     369            $post->post_status = 'wcb-pending-payment';
     370            wp_insert_post( $post );
     371
     372            WordCamp_Budgets::log( $post->ID, get_current_user_id(), 'Request set as Pending Payment via Network Admin', array(
     373                'action' => 'set-pending-payment',
     374            ) );
     375
     376            add_action( 'admin_notices', function() {
     377                ?><div class="notice notice-success is-dismissible">
     378                    <p><?php _e( 'Success! Request has been marked as Pending Payment.', 'wordcamporg' ); ?></p>
    336379                </div><?php
    337380            });
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/includes/payment-requests-list-table.php

    r2632 r2641  
    150150
    151151        if ( $request->post_status == 'wcb-pending-approval' ) {
    152             $approve_url = wp_nonce_url( add_query_arg( array(
     152            $action_url = wp_nonce_url( add_query_arg( array(
    153153                'wcb-approve' => sprintf( '%d-%d', $blog_id, $request->ID ),
    154154            ) ), sprintf( 'wcb-approve-%d-%d', $blog_id, $request->ID ) );
    155155
    156             $actions['wcb-approve'] = sprintf( '<a style="color: green;" onclick="return confirm(\'Approve this payment request?\');" href="%s">Approve</a>', esc_url( $approve_url ) );
     156            $actions['wcb-approve'] = sprintf( '<a style="color: green;" onclick="return confirm(\'Approve this payment request?\');" href="%s">Approve</a>', esc_url( $action_url ) );
     157
     158        } elseif ( $request->post_status == 'wcb-approved' ) {
     159            $action_url = wp_nonce_url( add_query_arg( array(
     160                'wcb-set-pending-payment' => sprintf( '%d-%d', $blog_id, $request->ID ),
     161            ) ), sprintf( 'wcb-set-pending-payment-%d-%d', $blog_id, $request->ID ) );
     162
     163            $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 ) );
    157164        }
    158165
Note: See TracChangeset for help on using the changeset viewer.