Changeset 2784
- Timestamp:
- 03/23/2016 10:04:20 PM (11 years ago)
- Location:
- sites/branches/application-tracking/wordcamp.org/public_html/wp-content/plugins/wcpt
- Files:
-
- 2 edited
-
wcpt-functions.php (modified) (1 diff)
-
wcpt-wordcamp/wordcamp-admin.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sites/branches/application-tracking/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-functions.php
r171 r2784 86 86 } 87 87 88 ?> 88 /** 89 * Render the Log metabox 90 * 91 * @param WP_Post $post 92 */ 93 function 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 */ 106 function 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 */ 135 function 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 */ 149 function 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 } -
sites/branches/application-tracking/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-admin.php
r2517 r2784 43 43 // Post status transitions 44 44 add_action( 'transition_post_status', array( $this, 'trigger_schedule_actions' ), 10, 3 ); 45 add_action( 'transition_post_status', array( $this, 'log_status_changes' ), 10, 3 ); 45 46 add_action( 'wcpt_added_to_planning_schedule', array( $this, 'add_organizer_to_central' ), 10 ); 46 47 add_action( 'wcpt_added_to_planning_schedule', array( $this, 'mark_date_added_to_planning_schedule' ), 10 ); … … 51 52 add_action( 'admin_notices', array( $this, 'print_admin_notices' ) ); 52 53 add_filter( 'redirect_post_location', array( $this, 'add_admin_notices_to_redirect_url' ), 10, 2 ); 54 } 55 56 // todo phpdoc 57 public static function get_status_name( $status_slug ) { 58 // todo call get_custom_statuses and map ? 59 60 return '{status name}'; 61 } 62 63 //todo phpdoc 64 public static function get_milestone_from_status( $status_slug ) { 65 // todo just have an array that maps them together? 66 67 return '{milestone name}'; 53 68 } 54 69 … … 87 102 'high' 88 103 ); 104 105 add_meta_box( 106 'wcpt_notes', 107 __( 'Add a Note', 'wordcamporg' ), 108 'wcpt_add_note_metabox', 109 WCPT_POST_TYPE_ID, 110 'side', 111 'low' 112 ); 113 114 add_meta_box( 115 'wcpt_log', 116 'Log', 117 'wcpt_log_metabox', 118 WCPT_POST_TYPE_ID, 119 'advanced', 120 'low' 121 ); 89 122 } 90 123 … … 159 192 } 160 193 } 161 } 194 195 $this->validate_and_add_note( $post_id ); 196 } 197 198 /** 199 * Validate and add a new note 200 * 201 * @param int $post_id 202 */ 203 protected function validate_and_add_note( $post_id ) { 204 // todo make sure edit is actionable - done in caller, but test 205 206 check_admin_referer( 'wcpt_notes', 'wcpt_notes_nonce' ); // todo test working 207 208 $new_note_message = sanitize_text_field( wp_unslash( $_POST['wcpt_new_note'] ) ); 209 210 if ( empty( $new_note_message ) ) { 211 return; 212 } 213 214 add_post_meta( $post_id, '_note', array( 215 'timestamp' => current_time( 'timestamp' ), 216 'user_id' => get_current_user_id(), 217 'message' => $new_note_message, 218 ) ); 219 } 220 162 221 163 222 /** … … 553 612 554 613 /** 614 * Log when the post status changes 615 * 616 * @param string $new_status 617 * @param string $old_status 618 * @param WP_Post $post 619 */ 620 public function log_status_changes( $new_status, $old_status, $post ) { 621 if ( $new_status === $old_status ) { 622 return; 623 } 624 625 add_post_meta( $post->ID, '_status_change', array( 626 'timestamp' => current_time( 'timestamp' ), 627 'user_id' => get_current_user_id(), 628 'message' => sprintf( '%s -> %s', $old_status, $new_status ), /// todo use get_status_name() when it's ready 629 ) ); 630 } 631 632 /** 555 633 * Add the lead organizer to Central when a WordCamp application is accepted. 556 634 *
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)