WordPress.org

Making WordPress.org

Changeset 6610


Ignore:
Timestamp:
02/12/2018 10:23:23 PM (4 years ago)
Author:
iandunn
Message:

WordCamp Organizer Reminders: Replace code with get_wordcamp_dropdown().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-organizer-reminders/wcor-reminder.php

    r5356 r6610  
    326326     */
    327327    public function markup_manually_send( $post ) {
    328         $wordcamps = $this->get_all_wordcamps();
    329328        ?>
    330329
     
    334333
    335334        <p>
    336             <select name="wcor_manually_send_wordcamp">
    337                 <option value="instructions"><?php _e( 'Select a WordCamp', 'wordcamporg' ); ?></option>
    338                 <?php /* translators: label for a spacer <option> at the beginning of a <select> */ ?>
    339                 <option value="spacer"><?php _e( '- - -', 'wordcamporg' ); ?></option>
    340 
    341                 <?php foreach ( $wordcamps as $wordcamp ) : ?>
    342                     <option value="<?php echo esc_attr( $wordcamp->ID ); ?>">
    343                         [<?php echo esc_html( $wordcamp->meta['sort_column'] ); ?>]
    344                         <?php echo esc_html( $wordcamp->post_title ); ?>
    345                     </option>
    346                 <?php endforeach; ?>
    347             </select>
     335            <?php echo get_wordcamp_dropdown( 'wcor_manually_send_wordcamp' ); ?>
    348336        </p>
    349337
     
    354342
    355343        <?php
    356     }
    357 
    358     /**
    359      * Retrieve all WordCamps and their metadata, sorted by status and year.
    360      *
    361      * @return array
    362      */
    363     protected function get_all_wordcamps() {
    364         if ( $wordcamps = get_transient( 'wcor_get_all_wordcamps' ) ) {
    365             return $wordcamps;
    366         }
    367 
    368         $statuses = WordCamp_Loader::get_post_statuses();
    369         $statuses = array_merge( array_keys( $statuses ), array( 'draft', 'pending', 'publish' ) );
    370 
    371         $wordcamps = get_posts( array(
    372             'post_type'   => WCPT_POST_TYPE_ID,
    373             'post_status' => $statuses,
    374             'numberposts' => -1,
    375         ) );
    376 
    377         foreach ( $wordcamps as &$wordcamp ) {
    378             $wordcamp->meta                = get_post_custom( $wordcamp->ID );
    379             $wordcamp->meta['sort_column'] = empty( $wordcamp->meta['Start Date (YYYY-mm-dd)'][0] ) ? $wordcamp->post_status : date( 'Y', $wordcamp->meta['Start Date (YYYY-mm-dd)'][0] );
    380         }
    381 
    382         usort( $wordcamps, array( $this, 'usort_wordcamps_by_year_and_status' ) );
    383 
    384         set_transient( 'wcor_get_all_wordcamps', $wordcamps, HOUR_IN_SECONDS );
    385 
    386         return $wordcamps;
    387     }
    388 
    389     /**
    390      * Sort WordCamps by year and post status.
    391      *
    392      * This is a usort() callback.
    393      *
    394      * WordCamps without a start date should be listed first, followed by WordCamps with a start date.
    395      *
    396      * Within the set that does not have a start date, they should be sorted by status; first drafts, then pending,
    397      * then published. Those with the same status should be sorted alphabetically.
    398      *
    399      * Within the set that does have a start date, they should be sorted by year, descending. Those within the same
    400      * year should be sorted alphabetically.
    401      *
    402      * Example:
    403      *
    404      * 1) draft   missing start date, titled "WordCamp Atlanta"
    405      * 2) draft   missing start date, titled "WordCamp Chicago"
    406      * 3) pending missing start date, titled "WordCamp Seattle"
    407      * 4) publish missing start date, titled "WordCamp Portland"
    408      * 5) publish in year 2014,       titled "WordCamp Dayton"
    409      * 6) publish in year 2014,       titled "WordCamp San Francisco"
    410      * 7) publish in year 2013,       titled "WordCamp Boston"
    411      * 8) publish in year 2013,       titled "WordCamp Columbus"
    412      *
    413      * @param WP_Post $a
    414      * @param WP_Post $b
    415      *
    416      * @return int
    417      */
    418     protected function usort_wordcamps_by_year_and_status( $a, $b ) {
    419         $a_year = empty( $a->meta['Start Date (YYYY-mm-dd)'][0] ) ? false : date( 'Y', $a->meta['Start Date (YYYY-mm-dd)'][0] );
    420         $b_year = empty( $b->meta['Start Date (YYYY-mm-dd)'][0] ) ? false : date( 'Y', $b->meta['Start Date (YYYY-mm-dd)'][0] );
    421 
    422         $status_weights = array(
    423             // @todo - this needs to be updated with new wordcamp post statuses
    424             'draft'   => 3,
    425             'pending' => 2,
    426             'publish' => 1,
    427         );
    428 
    429         if ( empty( $a_year ) || empty( $b_year ) ) {
    430             if ( $a->post_status == $b->post_status ) {
    431                 return $a->post_title > $b->post_title;
    432             } else {
    433                 return $status_weights[ $a->post_status ] < $status_weights[ $b->post_status ];
    434             }
    435         } else {
    436             if ( date( 'Y', $a->meta['Start Date (YYYY-mm-dd)'][0] ) == date( 'Y', $b->meta['Start Date (YYYY-mm-dd)'][0] ) ) {
    437                 return $a->post_title > $b->post_title;
    438             } else {
    439                 return $a_year < $b_year;
    440             }
    441         }
    442344    }
    443345
Note: See TracChangeset for help on using the changeset viewer.