';
?>
ID, '_mts_posttemplate', true );
// Select post template
echo ' ';
}
/**
* When the post is saved, saves our custom data.
*
* @param int $post_id The ID of the post being saved.
*/
function mts_save_posttemplate( $post_id ) {
/*
* We need to verify this came from our screen and with proper authorization,
* because save_post can be triggered at other times.
*/
// Check if our nonce is set.
if ( ! isset( $_POST['mts_inner_posttemplate_metabox_nonce'] ) )
return $post_id;
$nonce = sanitize_text_field(wp_unslash($_POST['mts_inner_posttemplate_metabox_nonce']));
// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $nonce, 'mts_inner_posttemplate_metabox' ) )
return $post_id;
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return $post_id;
// Check the user's permissions.
if ( 'page' == $_get['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) )
return $post_id;
} else {
if ( ! current_user_can( 'edit_post', $post_id ) )
return $post_id;
}
/* OK, its safe for us to save the data now. */
// Sanitize user input.
$posttemplate = sanitize_text_field(wp_unslash($_get['mts_posttemplate'] ) );
// Update the meta field in the database.
update_post_meta( $post_id, '_mts_posttemplate', $posttemplate );
}
add_action( 'save_post', 'mts_save_posttemplate' );
// Related function: mts_get_posttemplate( $single_template ) in functions.php
/*-----------------------------------------------------------------------------------*/
/* Page Header Animation Selection meta box
/*-----------------------------------------------------------------------------------*/
function mts_add_postheader_metabox() {
$screens = array('post', 'page');
foreach ($screens as $screen) {
add_meta_box(
'mts_postheader_metabox', // id
__('Header Animation', 'arbitragex'), // title
'mts_inner_postheader_metabox', // callback
$screen, // post_type
'side', // context (normal, advanced, side)
'high' // priority (high, core, default, low)
// callback args ($post passed by default)
);
}
}
add_action('add_meta_boxes', 'mts_add_postheader_metabox');
/**
* Print the box content.
*
* @param WP_Post $post The object for the current post/page.
*/
function mts_inner_postheader_metabox($post) {
// Add an nonce field so we can check for it later.
wp_nonce_field('mts_inner_postheader_metabox', 'mts_inner_postheader_metabox_nonce');
/*
* Use get_post_meta() to retrieve an existing value
* from the database and use the value for the form.
*/
$postheader = get_post_meta( $post->ID, '_mts_postheader', true );
// Select post header effect
echo ' ';
}
/**
* When the post is saved, saves our custom data.
*
* @param int $post_id The ID of the post being saved.
*/
function mts_save_postheader( $post_id ) {
/*
* We need to verify this came from our screen and with proper authorization,
* because save_post can be triggered at other times.
*/
// Check if our nonce is set.
if ( ! isset( $_POST['mts_inner_postheader_metabox_nonce'] ) )
return $post_id;
$nonce = sanitize_text_field(wp_unslash($_POST['mts_inner_postheader_metabox_nonce']) );
// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $nonce, 'mts_inner_postheader_metabox' ) )
return $post_id;
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return $post_id;
// Check the user's permissions.
if ( 'page' == $_get['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) )
return $post_id;
} else {
if ( ! current_user_can( 'edit_post', $post_id ) )
return $post_id;
}
/* OK, its safe for us to save the data now. */
// Sanitize user input.
$postheader = sanitize_text_field(wp_unslash($_get['mts_postheader'] ) );
// Update the meta field in the database.
update_post_meta( $post_id, '_mts_postheader', $postheader );
}
add_action( 'save_post', 'mts_save_postheader' );
// Related function: mts_get_post_header_effect() in functions.php
?>