Skip to content

Instantly share code, notes, and snippets.

@blobaugh
Created October 19, 2012 20:15
Show Gist options
  • Save blobaugh/3920430 to your computer and use it in GitHub Desktop.
Save blobaugh/3920430 to your computer and use it in GitHub Desktop.
Data Enterer Metabox
<?php
class WotDataEntererListMetabox {
public function __construct() {
add_action( 'add_meta_boxes', array( &$this, 'add' ) );
add_action( 'save_post', array( &$this, 'save' ) );
}
public function add() {
add_meta_box(
'wot_data_enterer',
'Data Enterer assignment',
array( &$this, 'render' ),
'tribe_events'
);
add_meta_box(
'wot_data_enterer',
'Data Enterer assignment',
array( &$this, 'render' ),
'tribe_venue'
);
add_meta_box(
'wot_data_enterer',
'Data Enterer assignment',
array( &$this, 'render' ),
'tribe_organizer'
);
}
public function save( $PostId ) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
if( isset( $_POST['wot_data_enterer'] ) && is_numeric( $_POST['wot_data_enterer'] )) {
//wp_update_post( array( 'ID' => $PostId, 'post_author' ) );
global $wpdb;
$wpdb->update( $wpdb->posts,
array( 'post_author' => $_POST['wot_data_enterer'] ),
array( 'ID' => $PostId )
);
}
}
public function render( $Post ) {
$s = '<select name="wot_data_enterer">';
$s .= '<option style="background-color: #eaeaea">Senior Data Enterer</option>';
foreach( $this->getSrEnterers() AS $e ) {
$s .= '<option value="' . $e->ID . '" ' . selected( $Post->post_author, $e->ID, false) . '>' . $e->display_name . '</option>';
}
$s .= '<option style="background-color: #eaeaea">Data Enterers</option>';
foreach( $this->getEnterers() AS $e ) {
$s .= '<option value="' . $e->ID . '" ' . selected( $Post->post_author, $e->ID, false) . '>' . $e->display_name . '</option>';
}
$s .= '</select>';
echo $s;
}
private function getSrEnterers() {
$sr = get_users( array( 'role' => 'senior_data_enterer' ) );
return $sr;
}
private function getEnterers() {
$d = get_users( array( 'role' => 'data_enterer' ) );
return $d;
}
} // end class
@blobaugh
Copy link
Author

The getSrEnterers() and getEnterers() methods seem to function appropriately, though I did not try changing the user list to determine if they are also being cached. Based off the other caching here though I would assume they are

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment