Making WordPress.org


Ignore:
Timestamp:
05/12/2016 08:02:37 PM (11 years ago)
Author:
iandunn
Message:

WordCamp Post Type: Set WordCamp posts to Closed after the event is over.

File:
1 edited

Legend:

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

    r3122 r3126  
    5151                add_action( 'admin_notices',                                  array( $this, 'print_admin_notices' ) );
    5252                add_filter( 'redirect_post_location',                         array( $this, 'add_admin_notices_to_redirect_url' ), 10, 2 );
     53
     54                // Cron jobs
     55                add_action( 'plugins_loaded',                                 array( $this, 'schedule_cron_jobs'          ), 11 );
     56                add_action( 'wcpt_close_wordcamps_after_event',               array( $this, 'close_wordcamps_after_event' )     );
    5357        }
    5458
    … …  
    924928                require_once( WCPT_DIR . 'views/wordcamp/metabox-original-application.php' );
    925929        }
     930
     931        /**
     932         * Schedule cron jobs
     933         */
     934        public function schedule_cron_jobs() {
     935                if ( wp_next_scheduled( 'wcpt_close_wordcamps_after_event' ) ) {
     936                        return;
     937                }
     938
     939                wp_schedule_event( current_time( 'timestamp' ), 'hourly', 'wcpt_close_wordcamps_after_event' );
     940        }
     941
     942        /**
     943         * Set WordCamp posts to the Closed status after the event is over
     944         */
     945        public function close_wordcamps_after_event() {
     946                $scheduled_wordcamps = get_posts( array(
     947                        'post_type'      => WCPT_POST_TYPE_ID,
     948                        'post_status'    => 'wcpt-scheduled',
     949                        'posts_per_page' => -1
     950                ) );
     951
     952                foreach ( $scheduled_wordcamps as $wordcamp ) {
     953                        $start_date = get_post_meta( $wordcamp->ID, 'Start Date (YYYY-mm-dd)', true );
     954                        $end_date   = get_post_meta( $wordcamp->ID, 'End Date (YYYY-mm-dd)',   true );
     955
     956                        if ( empty( $start_date ) ) {
     957                                continue;
     958                        }
     959
     960                        if ( empty( $end_date ) ) {
     961                                $end_date = $start_date;
     962                        }
     963
     964                        $end_date_at_midnight = strtotime( '23:59', $end_date );    // $end_date is the date at time 00:00, but the event isn't over until 23:59
     965
     966                        if ( $end_date_at_midnight > time() ) {
     967                                continue;
     968                        }
     969
     970                        wp_update_post( array(
     971                                'ID'          => $wordcamp->ID,
     972                                'post_status' => 'wcpt-closed',
     973                        ) );
     974                }
     975        }
    926976}
    927977endif; // class_exists check
Note: See TracChangeset for help on using the changeset viewer.