Making WordPress.org

Changeset 1816


Ignore:
Timestamp:
08/06/2015 11:05:20 PM (9 years ago)
Author:
iandunn
Message:

WordCamp Payments: Allow requests to be marked as incomplete.

Location:
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/classes/payment-request.php

    r1732 r1816  
    8888            )
    8989        );
    90     }
    91 
     90
     91        register_post_status(
     92            'incomplete',
     93            array(
     94                'label'              => _x( 'Incomplete', 'post', 'wordcamporg' ),
     95                'label_count'        => _nx_noop( 'Incomplete<span class="count">(%s)</span>', 'Incomplete <span class="count">(%s)</span>', 'wordcamporg' ),
     96                'public'             => true,
     97                'publicly_queryable' => false,
     98            )
     99        );
     100    }
     101
     102    /**
     103     * Register meta boxes
     104     */
    92105    public function init_meta_boxes() {
     106        /** @var $post WP_Post */
     107        global $post;
     108
    93109        // We're build our own Publish box, thankyouverymuch
    94110        remove_meta_box( 'submitdiv', self::POST_TYPE, 'side' );
     
    103119        );
    104120
     121        if ( 'incomplete' != $post->post_status && current_user_can( 'manage_network' ) ) {
     122            add_meta_box(
     123                'wcp_mark_incomplete',
     124                __( 'Mark as Incomplete', 'wordcamporg' ),
     125                array( $this, 'render_mark_incomplete_metabox' ),
     126                self::POST_TYPE,
     127                'side',
     128                'high'
     129            );
     130        }
     131
    105132        add_meta_box(
    106133            'wcp_general_info',
     
    153180
    154181        require_once( dirname( __DIR__ ) . '/views/payment-request/metabox-status.php' );
     182    }
     183
     184    /**
     185     * Render the Mark as Incomplete metabox
     186     *
     187     * @param WP_Post $post
     188     */
     189    public function render_mark_incomplete_metabox( $post ) {
     190        wp_nonce_field( 'mark_incomplete', 'mark_incomplete_nonce' );
     191
     192        require_once( dirname( __DIR__ ) . '/views/payment-request/metabox-mark-incomplete.php' );
    155193    }
    156194
     
    539577        }
    540578
     579        if ( 'incomplete' == $post->post_status && 'incomplete' != get_query_var( 'post_status' ) ) {
     580            $states['incomplete'] = __( 'Incomplete', 'wordcamporg' );
     581        }
     582
    541583        return $states;
    542584    }
     
    595637    public function update_request_status( $post_data, $post_data_raw ) {
    596638        if ( $this->post_edit_is_actionable( $post_data ) ) {
    597             $previous_status          = $post_data['post_status'];
    598             $post_data['post_status'] = strtotime( sanitize_text_field( $_POST['date_vendor_paid'] ) ) ? 'paid' : 'unpaid';
    599 
    600             if ( 'paid' != $previous_status && 'paid' == $post_data['post_status'] ) {
    601                 $this->notify_requester_payment_made( $post_data_raw['ID'], $post_data );
     639
     640            if ( 'on' == $_POST['wcp_mark_incomplete_checkbox'] && ! empty( $_POST['wcp_mark_incomplete_notes'] ) ) {
     641                $post_data['post_status'] = 'incomplete';
     642                $this->notify_requester_request_incomplete( $post_data_raw['ID'], $post_data, $post_data_raw );
     643            } else {
     644                $previous_status          = $post_data['post_status'];
     645                $post_data['post_status'] = strtotime( sanitize_text_field( $_POST['date_vendor_paid'] ) ) ? 'paid' : 'unpaid';
     646
     647                if ( 'paid' != $previous_status && 'paid' == $post_data['post_status'] ) {
     648                    $this->notify_requester_payment_made( $post_data_raw['ID'], $post_data );
     649                }
    602650            }
    603651        }
     
    637685
    638686    /**
     687     * Notify the payment requester that it has been marked as paid.
     688     *
     689     * @param int   $request_id
     690     * @param array $post_data
     691     * @param array $post_data_raw
     692     */
     693    protected function notify_requester_request_incomplete( $request_id, $post_data, $post_data_raw ) {
     694        if ( ! $to = $this->get_requester_formatted_email( $post_data['post_author'] ) ) {
     695            return;
     696        }
     697
     698        $subject = sprintf( '`%s` is incomplete', $post_data['post_title'] );
     699        $headers = array( 'Reply-To: support@wordcamp.org' );
     700
     701        $message = sprintf(
     702            "The request for `%s` has been marked as incomplete by WordCamp Central.
     703
     704            The reason for this is: %s
     705
     706            You can complete the request at:
     707
     708            %s
     709
     710            If you have any questions, please reply to let us know.",
     711            $post_data['post_title'],
     712            sanitize_text_field( $post_data_raw['wcp_mark_incomplete_notes'] ),
     713            admin_url( sprintf( 'post.php?post=%s&action=edit', $request_id ) )
     714        );
     715        $message = str_replace( "\t", '', $message );
     716
     717        wp_mail( $to, $subject, $message, $headers );
     718    }
     719
     720    /**
    639721     * Save the post's data
    640722     *
     
    648730
    649731        // Verify nonces
    650         $nonces = array( 'status_nonce', 'general_info_nonce', 'payment_details_nonce', 'vendor_details_nonce' );    // todo add prefix to all of these
     732        $nonces = array( 'status_nonce', 'mark_incomplete_nonce', 'general_info_nonce', 'payment_details_nonce', 'vendor_details_nonce' );    // todo add prefix to all of these
    651733
    652734        foreach ( $nonces as $nonce ) {
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/javascript/wordcamp-payments.js

    r995 r1816  
    1818            $( '#payment_category' ).change( $.wordcampPayments.toggleOtherCategoryDescription );
    1919            $( '#wcp_files' ).find( 'a.wcp-insert-media' ).click( $.wordcampPayments.showUploadModal );
     20            $( '#wcp_mark_incomplete_checkbox' ).click( $.wordcampPayments.requireNotes );
    2021        },
    2122
     
    109110                } );
    110111            }
     112        },
     113
     114        /**
     115         * Require notes when the request is being marked as incomplete
     116         */
     117        requireNotes : function() {
     118            var notes = $( '#wcp_mark_incomplete_notes' );
     119
     120            if ( 'checked' === $( '#wcp_mark_incomplete_checkbox' ).attr( 'checked' ) ) {
     121                notes.attr( 'required', true );
     122            } else {
     123                notes.attr( 'required', false );
     124            }
    111125        }
    112126    };
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/payment-request/metabox-status.php

    r995 r1816  
    66
    77                <span id="post-status-display">
    8                     <?php if ( 'paid' == $post->post_status ) : ?>
     8                    <?php if ( 'incomplete' == $post->post_status ) : ?>
     9                        <?php _e( 'Incomplete', 'wordcamporg' ); ?>
     10                    <?php elseif ( 'paid' == $post->post_status ) : ?>
    911                        <?php _e( 'Paid' ); ?>
    1012                    <?php else : ?>
Note: See TracChangeset for help on using the changeset viewer.