Making WordPress.org


Ignore:
Timestamp:
03/23/2016 10:04:20 PM (11 years ago)
Author:
iandunn
Message:

WordCamp Post Type: Log status changes and notes.

File:
1 edited

Legend:

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

    r171 r2784  
    8686}
    8787
    88 ?>
     88/**
     89 * Render the Log metabox
     90 *
     91 * @param WP_Post $post
     92 */
     93function wcpt_log_metabox( $post ) {
     94        $entries = wcpt_get_log_entries( $post->ID );
     95
     96        require_once( __DIR__ . '/views/common/metabox-log.php' );
     97}
     98
     99/**
     100 * Get all the the entries
     101 *
     102 * @param int $wordcamp_id
     103 *
     104 * @return array
     105 */
     106function wcpt_get_log_entries( $wordcamp_id ) {
     107        $entries        = array();
     108        $notes          = get_post_meta( $wordcamp_id, '_note'          );  // todo better key name?
     109        $status_changes = get_post_meta( $wordcamp_id, '_status_change' );  // todo better key name? if yes, update get_last_status_update_time_diff too
     110
     111        foreach ( array( 'note' => $notes, 'status_change' => $status_changes ) as $entry_type => $raw_entries ) {
     112                foreach ( $raw_entries as $entry ) {
     113                        $user = get_user_by( 'id', $entry['user_id'] );
     114
     115                        $entry['type']              = $entry_type;
     116                        $entry['user_display_name'] = $user->display_name;
     117
     118                        $entries[] = $entry;
     119                }
     120        }
     121
     122        usort( $entries, 'wcpt_sort_log_entries' );
     123
     124        return $entries;
     125}
     126
     127/**
     128 * Sort the log entries in reverse-chronological order
     129 *
     130 * @param array $a
     131 * @param array $b
     132 *
     133 * @return int
     134 */
     135function wcpt_sort_log_entries( $a, $b ) {
     136        // If a status change and a note occur at the same time, show the change before the note
     137        if ( $a['timestamp'] == $b['timestamp'] ) {
     138                return ( '_status_change' == $a['type'] ) ? -1 : 1; // todo not consistent
     139        }
     140
     141        return ( $a['timestamp'] > $b['timestamp'] ) ? -1 : 1;
     142}
     143
     144/**
     145 * Render the Notes metabox
     146 *
     147 * @param WP_Post $post
     148 */
     149function wcpt_add_note_metabox( $post ) {
     150        wp_nonce_field( 'wcpt_notes', 'wcpt_notes_nonce' );
     151
     152        require_once( __DIR__ . '/views/common/metabox-notes.php' );
     153}
Note: See TracChangeset for help on using the changeset viewer.