Making WordPress.org

Changeset 2893


Ignore:
Timestamp:
04/04/2016 08:50:21 PM (11 years ago)
Author:
iandunn
Message:

WordCamp Post Type: Update required fields logic for new statuses.

File:
1 edited

Legend:

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

    r2892 r2893  
    4646                add_action( 'wcpt_added_to_planning_schedule',                array( $this, 'mark_date_added_to_planning_schedule' ), 10 );
    4747                add_filter( 'wp_insert_post_data',                            array( $this, 'enforce_post_status' ), 10, 2 );
    48                 add_filter( 'wp_insert_post_data',                            array( $this, 'require_complete_meta_to_publish_wordcamp' ), 10, 2 );
     48                add_filter( 'wp_insert_post_data',                            array( $this, 'require_complete_meta_to_publish_wordcamp' ), 11, 2 ); // after enforce_post_status
    4949
    5050                // Admin notices
    … …  
    617617         * Trigger actions related to WordCamps being scheduled.
    618618         *
    619          * When an application is submitted, a `wordcamp` post is created with a `draft` status. When it's accepted
    620          * to the planning schedule the status changes to `pending`, and when it's accepted for the final schedule
    621          * the status changes to 'publish'.
    622          *
    623619         * @param string $new_status
    624620         * @param string $old_status
    … …  
    751747                }
    752748
    753                 // todo update for new statuses
    754 
    755749                // The ID of the last site that was created before this rule went into effect, so that we don't apply the rule retroactively.
    756750                $min_site_id = apply_filters( 'wcpt_require_complete_meta_min_site_id', '2416297' );
    757751
    758                 $required_pending_fields = $this->get_required_fields( 'pending' );
    759                 $required_publish_fields = $this->get_required_fields( 'publish' );
     752                $required_pre_planning_fields = $this->get_required_fields( 'pre-planning' );
     753                $required_scheduled_fields    = $this->get_required_fields( 'scheduled' );
    760754
    761755                // Check pending posts
    762                 if ( 'pending' == $post_data['post_status'] && absint( $_POST['post_ID'] ) > $min_site_id ) {
    763                         foreach( $required_pending_fields as $field ) {
     756                if ( 'wcpt-approved-pre-pl' == $post_data['post_status'] && absint( $_POST['post_ID'] ) > $min_site_id ) {
     757                        foreach( $required_pre_planning_fields as $field ) {
    764758                                $value = $_POST[ wcpt_key_to_str( $field, 'wcpt_' ) ];
    765759
    766760                                if ( empty( $value ) || 'null' == $value ) {
    767                                         $post_data['post_status']     = 'draft';
     761                                        $post_data['post_status']     = 'wcpt-interview-sched';
     762                                        $this->active_admin_notices[] = 1;
     763                                        break;
     764                                }
     765                        }
     766                }
     767
     768                // Check published posts
     769                if ( 'wcpt-scheduled' == $post_data['post_status'] && isset( $_POST['post_ID'] ) && absint( $_POST['post_ID'] ) > $min_site_id ) {
     770                        foreach( $required_scheduled_fields as $field ) {
     771                                $value = $_POST[ wcpt_key_to_str( $field, 'wcpt_' ) ];
     772
     773                                if ( empty( $value ) || 'null' == $value ) {
     774                                        $post_data['post_status']     = 'wcpt-needs-schedule';
    768775                                        $this->active_admin_notices[] = 3;
    769776                                        break;
    … …  
    772779                }
    773780
    774                 // Check published posts
    775                 if ( 'publish' == $post_data['post_status'] && isset( $_POST['post_ID'] ) && absint( $_POST['post_ID'] ) > $min_site_id ) {
    776                         foreach( $required_publish_fields as $field ) {
    777                                 $value = $_POST[ wcpt_key_to_str( $field, 'wcpt_' ) ];
    778 
    779                                 if ( empty( $value ) || 'null' == $value ) {
    780                                         $post_data['post_status']     = 'pending';
    781                                         $this->active_admin_notices[] = 1;
    782                                         break;
    783                                 }
    784                         }
    785                 }
    786 
    787781                return $post_data;
    788782        }
    … …  
    791785         * Get a list of fields required to move to a certain post status
    792786         *
    793          * @param string $status 'pending' | 'publish' | 'any'
     787         * @param string $status 'pre-planning' | 'scheduled' | 'any'
    794788         *
    795789         * @return array
    796790         */
    797791        public static function get_required_fields( $status ) {
    798                 $pending = array( 'E-mail Address' );
    799 
    800                 $publish = array(
     792                $pre_planning = array( 'E-mail Address' );
     793
     794                $scheduled = array(
    801795                        // WordCamp
    802796                        'Start Date (YYYY-mm-dd)',
    … …  
    820814
    821815                switch ( $status ) {
    822                         case 'pending':
    823                                 $required_fields = $pending;
     816                        case 'pre-planning':
     817                                $required_fields = $pre_planning;
    824818                                break;
    825819
    826                         case 'publish':
    827                                 $required_fields = $publish;
     820                        case 'scheduled':
     821                                $required_fields = $scheduled;
    828822                                break;
    829823
    830824                        case 'any':
    831825                        default:
    832                                 $required_fields = array_merge( $pending, $publish );
     826                                $required_fields = array_merge( $pre_planning, $scheduled );
    833827                                break;
    834828                }
    … …  
    877871                }
    878872
    879                 // todo update for new statuses
    880 
    881873                $notices = array(
    882874                        1 => array(
    883875                                'type'   => 'error',
    884                                 'notice' => __( 'This WordCamp cannot be published until all of its required metadata is filled in.', 'wordcamporg' ),
     876                                'notice' => __( 'This WordCamp cannot be approved for pre-planning until all of its required metadata is filled in.', 'wordcamporg' ),
    885877                        ),
    886878
    887879                        3 => array(
    888880                                'type'   => 'error',
    889                                 'notice' => __( 'This WordCamp cannot be set to pending until all of its required metadata is filled in.', 'wordcamporg' ),
     881                                'notice' => __( 'This WordCamp cannot be added to the schedule until all of its required metadata is filled in.', 'wordcamporg' ),
    890882                        ),
    891883                );
Note: See TracChangeset for help on using the changeset viewer.