Making WordPress.org

Changeset 691


Ignore:
Timestamp:
06/11/2014 08:10:36 PM (12 years ago)
Author:
iandunn
Message:

WordCamp Post Type: Trigger actions when WordCamps are added to schedules.

This refactors the previous code so that custom actions are triggered when a WordCamp is added to the pending
schedule and the final schedule, so that callbacks can hook to those are not having to know the internal details
of the status changes.

File:
1 edited

Legend:

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

    r674 r691  
    4242
    4343                // Post status transitions
    44                 add_action( 'transition_post_status', array( $this, 'add_organizer_to_central' ), 10, 3 );
     44                add_action( 'transition_post_status', array( $this, 'trigger_schedule_actions' ), 10, 3 );
     45                add_action( 'wcpt_added_to_planning_schedule', array( $this, 'add_organizer_to_central' ), 10 );
    4546                add_action( 'wp_insert_post_data',    array( $this, 'require_complete_meta_to_publish_wordcamp' ), 10, 2 );
    4647
    … …  
    416417
    417418        /**
    418          * Add the lead organizer to Central when a WordCamp application is accepted.
    419          *
    420          * When an application is submitted, a `wordcamp` post is created with a `draft` status. When it's accepted,
    421          * the status changes to `pending`. Adding the lead organizer to Central allows them to enter all the `wordcamp`
    422          * meta info themselves, and also post updates to the Central blog.
     419         * Trigger actions related to WordCamps being scheduled.
     420         *
     421         * When an application is submitted, a `wordcamp` post is created with a `draft` status. When it's accepted
     422         * to the planning schedule the status changes to `pending`, and when it's accepted for the final schedule
     423         * the status changes to 'publish'.
    423424         *
    424425         * @param string $new_status
    … …  
    426427         * @param WP_Post $post
    427428         */
    428         public function add_organizer_to_central( $new_status, $old_status, $post ) {
     429        public function trigger_schedule_actions( $new_status, $old_status, $post ) {
    429430                if ( empty( $post->post_type ) || WCPT_POST_TYPE_ID != $post->post_type ) {
    430431                        return;
    431432                }
    432433
    433                 if ( 'draft' != $old_status || 'pending' != $new_status ) {
    434                         return;
    435                 }
    436 
     434                if ( 'draft' == $old_status && 'pending' == $new_status ) {
     435                        do_action( 'wcpt_added_to_planning_schedule', $post );
     436                } elseif ( 'pending' == $old_status && 'publish' == $new_status ) {
     437                        do_action( 'wcpt_added_to_final_schedule', $post );
     438                }
     439        }
     440
     441        /**
     442         * Add the lead organizer to Central when a WordCamp application is accepted.
     443         *
     444         * Adding the lead organizer to Central allows them to enter all the `wordcamp`
     445         * meta info themselves, and also post updates to the Central blog.
     446         *
     447         * @param WP_Post $post
     448         */
     449        public function add_organizer_to_central( $post ) {
    437450                $lead_organizer = get_user_by( 'login', get_post_meta( $post->ID, 'WordPress.org Username', true ) );
    438451
Note: See TracChangeset for help on using the changeset viewer.