Making WordPress.org


Ignore:
Timestamp:
04/05/2016 06:40:48 PM (8 years ago)
Author:
iandunn
Message:

WordCamp Post Type: Remove inactive camps from [application-tracker].

File:
1 edited

Legend:

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

    r2894 r2899  
    1515    $statuses   = \WordCamp_Loader::get_post_statuses();
    1616    $milestones = \WordCamp_Loader::map_statuses_to_milestones();
     17    $posts      = get_active_wordcamps( $statuses );
     18
     19    require_once( dirname( __DIR__ ) . '/wcpt-wordcamp/wordcamp-admin.php'                             );
     20    require(      dirname( __DIR__ ) . '/views/applications/tracker/shortcode-application-tracker.php' );
     21}
     22
     23/**
     24 * Get camps that are active enough to be shown on the tracker
     25 *
     26 * @param array $statuses
     27 *
     28 * @return array
     29 */
     30function get_active_wordcamps( $statuses ) {
     31    $inactive_timestamp = strtotime( '60 days ago' );
    1732
    1833    $shown_statuses = $statuses;
     
    2035    $shown_statuses = array_keys( $shown_statuses );
    2136
    22     $posts = get_posts( array(
     37    $wordcamps = get_posts( array(
    2338        'post_type'      => WCPT_POST_TYPE_ID,
    2439        'post_status'    => $shown_statuses,
     
    2843    ) );
    2944
    30     require_once( dirname( __DIR__ ) . '/wcpt-wordcamp/wordcamp-admin.php'                             );
    31     require(      dirname( __DIR__ ) . '/views/applications/tracker/shortcode-application-tracker.php' );
     45    foreach ( $wordcamps as $key => $wordcamp ) {
     46        $wordcamp->last_update_timestamp = get_last_update_timestamp( $wordcamp->ID );
     47
     48        if ( $wordcamp->last_update_timestamp <= $inactive_timestamp ) {
     49            unset( $wordcamps[ $key ] );
     50        }
     51    }
     52
     53    return $wordcamps;
    3254}
    3355
    3456/**
    35  * Get the time difference between now and the last status update.
     57 * Get the timestamp of the last time the post status changed
    3658 *
    37  * @param $post_id
     59 * @param int $post_id
    3860 *
    39  * @return string
     61 * @return int
    4062 */
    41 function get_last_status_update_time_diff( $post_id ) {
    42     $time_diff      = '';
    43     $status_changes = get_post_meta( $post_id, '_status_change' );
     63function get_last_update_timestamp( $post_id ) {
     64    $last_update_timestamp = 0;
     65    $status_changes        = get_post_meta( $post_id, '_status_change' );
    4466
    4567    if ( $status_changes ) {
    4668        usort( $status_changes, 'wcpt_sort_log_entries' );
    47         $time_diff = human_time_diff( time(), $status_changes[0]['timestamp'] ) . ' ago';
     69        $last_update_timestamp = $status_changes[0]['timestamp'];
    4870    }
    4971
    50     return $time_diff;
     72    return $last_update_timestamp;
    5173}
    5274
Note: See TracChangeset for help on using the changeset viewer.