Making WordPress.org

Changeset 2824


Ignore:
Timestamp:
03/28/2016 05:11:35 PM (11 years ago)
Author:
kovshenin
Message:

WordCamp Post Type: Soft-enforce a post status progression for WordCamps via the UI.

Location:
sites/branches/application-tracking/wordcamp.org/public_html/wp-content/plugins/wcpt
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sites/branches/application-tracking/wordcamp.org/public_html/wp-content/plugins/wcpt/views/wordcamp/metabox-status.php

    r2823 r2824  
    1212                                                <span id="post-status-display">
    1313                                                        <select name="post_status">
     14                                                                <?php $transitions = WordCamp_Loader::get_valid_status_transitions( $post->post_status ); ?>
    1415                                                                <?php foreach ( WordCamp_Loader::get_post_statuses() as $key => $label ) : ?>
    1516                                                                        <?php $status = get_post_status_object( $key ); ?>
    16                                                                         <option value="<?php echo esc_attr( $status->name ); ?>" <?php selected( $post->post_status, $status->name ); ?> >
     17                                                                        <option value="<?php echo esc_attr( $status->name ); ?>" <?php
     18                                                                                if ( $post->post_status == $status->name ) {
     19                                                                                        selected( true );
     20                                                                                } elseif ( ! in_array( $status->name, $transitions ) ) {
     21                                                                                        echo ' disabled ';
     22                                                                                }
     23                                                                        ?>>
    1724                                                                                <?php echo esc_html( $status->label ); ?>
    1825                                                                        </option>
  • sites/branches/application-tracking/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-admin.php

    r2823 r2824  
    4545                add_action( 'wcpt_added_to_planning_schedule',                array( $this, 'add_organizer_to_central' ), 10 );
    4646                add_action( 'wcpt_added_to_planning_schedule',                array( $this, 'mark_date_added_to_planning_schedule' ), 10 );
    47                 add_filter( 'wp_insert_post_data',                            array( $this, 'enforce_post_status_progression' ), 10, 2 );
     47                add_filter( 'wp_insert_post_data',                            array( $this, 'enforce_post_status' ), 10, 2 );
    4848                add_filter( 'wp_insert_post_data',                            array( $this, 'require_complete_meta_to_publish_wordcamp' ), 10, 2 );
    4949
    … …  
    695695
    696696        /**
    697          * Force WordCamp posts to go through the expected status progression.
     697         * Enforce a valid post status for WordCamps.
    698698         *
    699699         * @param array $post_data
    … …  
    701701         * @return array
    702702         */
    703         public function enforce_post_status_progression( $post_data, $post_data_raw ) {
     703        public function enforce_post_status( $post_data, $post_data_raw ) {
    704704                if ( $post_data['post_type'] != WCPT_POST_TYPE_ID || empty( $_POST['post_ID'] ) ) {
    705705                        return $post_data;
    … …  
    709709                if ( ! $post ) {
    710710                        return $post_data;
    711                 }
    712 
    713                 // @todo: Rewrite all of this according to the new flow.
    714                 if ( ! empty( $_POST ) ) {
    715                         $previous_post_status = get_post( absint( $_POST['post_ID'] ) );
    716                         $previous_post_status = $previous_post_status->post_status;
    717 
    718                         if ( 'pending' == $post_data['post_status'] && ! in_array( $previous_post_status, array( 'draft', 'pending', 'publish' ) ) ) {
    719                                 $this->active_admin_notices[] = 2;
    720                                 $post_data['post_status'] = $previous_post_status;
    721                         }
    722 
    723                         if ( 'publish' == $post_data['post_status'] && ! in_array( $previous_post_status, array( 'pending', 'publish' ) ) ) {
    724                                 $this->active_admin_notices[] = 2;
    725                                 $post_data['post_status'] = $previous_post_status;
    726                         }
    727711                }
    728712
  • sites/branches/application-tracking/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-loader.php

    r2805 r2824  
    117117        }
    118118
     119        /**
     120         * Get WordCamp post statuses.
     121         *
     122         * @return array
     123         */
    119124        public static function get_post_statuses() {
    120125                return array(
    … …  
    137142                );
    138143        }
     144
     145        /**
     146         * Return valid transitions given a post status.
     147         *
     148         * @param string $status Current status.
     149         *
     150         * @return array Valid transitions.
     151         */
     152        public static function get_valid_status_transitions( $status ) {
     153                $transitions = array(
     154                        'wcpt-formal-review'   => array( 'wcpt-inactive', 'wcpt-application-rev' ),
     155                        'wcpt-inactive'        => array( 'wcpt-formal-review', 'wcpt-application-rev' ),
     156                        'wcpt-application-rev' => array( 'wcpt-inactive', 'wcpt-scheduling' ),
     157                        'wcpt-scheduling'      => array( 'wcpt-inactive', 'wcpt-interview-sched', 'wcpt-application-rev' ),
     158                        'wcpt-interview-sched' => array( 'wcpt-inactive', 'wcpt-needs-site', 'wcpt-scheduling', 'wcpt-rejected' ),
     159                        'wcpt-needs-site'      => array( 'wcpt-inactive', 'wcpt-agreement-sig', 'wcpt-interview-sched' ),
     160                        'wcpt-rejected'        => array( 'wcpt-inactive' ),
     161                        'wcpt-agreement-sig'   => array( 'wcpt-inactive', 'wcpt-site-created', 'wcpt-needs-site' ),
     162                        'wcpt-site-created'    => array( 'wcpt-inactive', 'wcpt-listing-added', 'wcpt-agreement-sig' ),
     163                        'wcpt-listing-added'   => array( 'wcpt-inactive', 'wcpt-needs-budget-re', 'wcpt-site-created' ),
     164                        'wcpt-needs-budget-re' => array( 'wcpt-inactive', 'wcpt-budget-approved', 'wcpt-listing-added' ),
     165                        'wcpt-budget-approved' => array( 'wcpt-inactive', 'wcpt-venue-signed', 'wcpt-needs-budget-re' ),
     166                        'wcpt-venue-signed'    => array( 'wcpt-inactive', 'wcpt-scheduled', 'wcpt-budget-approved' ),
     167                        'wcpt-scheduled'       => array( 'wcpt-inactive', 'wcpt-debrief', 'wcpt-venue-signed' ),
     168                        'wcpt-debrief'         => array( 'wcpt-inactive', 'wcpt-budget-closed', 'wcpt-scheduled' ),
     169                        'wcpt-budget-closed'   => array( 'wcpt-inactive', 'wcpt-debrief' ),
     170                );
     171
     172                if ( empty( $transitions[ $status ] ) )
     173                        return array( 'wcpt-inactive', 'wcpt-formal-review' );
     174
     175                return $transitions[ $status ];
     176        }
    139177}
    140178
Note: See TracChangeset for help on using the changeset viewer.