Last active
December 11, 2015 02:29
-
-
Save TravisBallard/4531131 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* add meta box | |
* | |
*/ | |
add_action( 'add_meta_boxes', 'add_testimonial_location_metabox' ); | |
function add_testimonial_location_metabox() | |
{ | |
global $tbtestimonials; | |
if( is_object( $tbtestimonials ) ) | |
add_meta_box( 'tbtlocation', 'Locations', 'tbt_location_metabox', $tbtestimonials->post_type, 'side' ); | |
} | |
/** | |
* display meta box | |
*/ | |
function tbt_location_metabox( $post ) | |
{ | |
?> | |
<p> | |
<label for="tbt_location">Location</label> | |
<input type="text" class="widefat" name="tbt[location]" value="<?php echo get_post_meta( $post->ID, 'tbtestimonials_location', 1 ); ?>" /> | |
<input type="hidden" value="<?php echo wp_create_nonce( 'tbt_location' ); ?>" name="tbt[nonce]" /> | |
</p> | |
<?php | |
} | |
/** | |
* save meta box | |
* | |
* @param mixed $pid | |
*/ | |
add_action( 'save_post', 'save_tbt_location' ); | |
function save_tbt_location($pid) | |
{ | |
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) | |
return; | |
if( isset( $_POST['tbt']['location'] ) && ! empty( $_POST['tbt']['location'] ) && isset( $_POST['tbt']['nonce'] ) && ! empty( $_POST['tbt']['nonce'] ) ) | |
{ | |
extract( $_POST['tbt'] ); | |
if( wp_verify_nonce( $nonce, 'tbt_location' ) ) | |
update_post_meta( $pid, 'tbtestimonials_location', $location ); | |
} | |
} | |
/** | |
* add a 'foobar' variable to tbt | |
* | |
* @param mixed $twig | |
*/ | |
add_action( 'tbt_template_functions', 'add_tags_to_tbtestimonials' ); | |
function add_tags_to_tbtestimonials( $twig ){ | |
$twig->addGlobal( 'location', call_user_func( 'get_tbt_location' ) ); | |
} | |
/** | |
* get location meta data for location template tag | |
* | |
*/ | |
function get_tbt_location(){ | |
return get_post_meta( get_the_ID(), 'tbtestimonials_location', 1 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment