Created
October 19, 2012 20:15
-
-
Save blobaugh/3920430 to your computer and use it in GitHub Desktop.
Data Enterer Metabox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |
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
The issue is in the render() method. The $Post objected passed as a parameter never gets updated with WPE caching is enabled. This leads me to believe that WPE is caching objects inside of wp-admin. No data used by forms should ever be cached. This causes the form to look like it has not been updated after a save, even though the data in the database has in fact changed