Making WordPress.org


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

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

Location:
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt
Files:
2 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
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/views/applications/tracker/shortcode-application-tracker.php

    r2869 r2899  
    2424                                <td class="milestone"  ><?php echo esc_html( $milestones[ $post->post_status ] );                  ?></td>
    2525                                <td class="status"     ><?php echo esc_html( $statuses[ $post->post_status ] );                    ?></td>
    26                                 <td class="last-update"><?php echo esc_html( get_last_status_update_time_diff( $post->ID ) );      ?></td>
     26                                <td class="last-update"><?php echo esc_html( human_time_diff( time(), $post->last_update_timestamp ) . ' ago' ); ?></td>
     27                                <!-- todo realign -->
    2728                        </tr>
    2829                <?php endforeach; ?>
Note: See TracChangeset for help on using the changeset viewer.