Making WordPress.org

Changeset 3126


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

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

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

Legend:

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

    r2898 r3126  
    112112            $user = get_user_by( 'id', $entry['user_id'] );
    113113
     114            if ( $user ) {
     115                $entry['user_display_name'] = $user->display_name;
     116            } else {
     117                // Assume that the action was performed during a cron job
     118                $entry['user_display_name'] = 'WordCamp Bot';
     119            }
     120
    114121            $entry['type']              = $entry_type;
    115             $entry['user_display_name'] = $user->display_name;
     122            // todo realign
    116123
    117124            $entries[] = $entry;
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-loader.php

    r2898 r3126  
    5151
    5252        // Require admin files.
    53         if ( is_admin() ) {
     53        if ( is_admin() || DOING_CRON ) {
    5454            require_once ( WCPT_DIR . 'wcpt-admin.php' );
    5555            require_once ( WCPT_DIR . 'wcpt-wordcamp/wordcamp-admin.php' );
     
    5959    function core_admin() {
    6060        // Quick admin check
    61         if ( !is_admin() )
     61        if ( ! is_admin() && ! DOING_CRON ) {
    6262            return;
     63        }
    6364
    6465        // Create admin
  • 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.