* @copyright 2014 Eric Frisino
* @license PL-2.0+
* @version 1.0
* @uses Add custom meta data to the 'post' Post Type
*/
// Fire our meta box setup function on the post editor screen.
add_action( 'load-post.php', 'abh_custom_meta_setup' );
add_action( 'load-post-new.php', 'abh_custom_meta_setup' );
// Meta box setup function.
function abh_custom_meta_setup() {
// Add meta boxes on the 'add_meta_boxes' hook.
add_action( 'add_meta_boxes', 'abh_add_metabox' );
// Save post meta on the 'save_post' hook.
add_action( 'save_post', 'abh_save_meta', 1, 2 );
}
// Create one or more meta boxes to be displayed on the post editor screen.
function abh_add_metabox() {
/**
* Custom Meta Information: 3 Daily Gratitudes
* meta: abh-gratitude-one
* type: Text Input
* use: Lets user input their first daily gratitude.
* values: Holds users first daily gratitude.
*
* meta: abh-gratitude-two
* type: Text Input
* use: Lets user input their second daily gratitude.
* values: Holds users second daily gratitude.
*
* meta: abh-gratitude-three
* type: Text Input
* use: Lets user input their third daily gratitude.
* values: Holds users third daily gratitude.
*/
add_meta_box(
'abh-gratitudes', // Unique ID
__( 'Three Gratitudes', 'abh_trans' ), // Title
'abh_gratitudes', // Callback function
'post', // Post Type for this to appear on
'normal', // Context
'core' // Priority
);
/**
* Custom Meta Information: 3 Daily Gratitudes
* meta: abh-journal
* type: WYSIWYG
* use: Lets user input their first daily gratitude.
* values: Holds users first daily gratitude.
*/
add_meta_box(
'abh-journal', // Unique ID
__( 'One Positive Experience', 'abh_trans' ), // Title
'abh_journal', // Callback function
'post', // Post Type for this to appear on
'normal', // Context
'core' // Priority
);
/**
* Custom Meta Information: Exercise
* meta: abh-exercise-toggle
* type: Checkbox
* use: Lets user check off if they exercised today.
* values: BOOL: 1 True - 0 False.
*
* meta: abh-exercise-info
* type: Textarea
* use: Lets user input any positive information about their workout.
* values: Holds users thoughts on their workout.
*/
add_meta_box(
'abh-exercise', // Unique ID
__( 'Exercise', 'abh_trans' ), // Title
'abh_exercise', // Callback function
'post', // Post Type for this to appear on
'normal', // Context
'core' // Priority
);
/**
* Custom Meta Information: Meditation
* meta: abh-meditation-toggle
* type: Checkbox
* use: Lets user check off if they meditated today.
* values: BOOL: 1 True - 0 False.
*
* meta: abh-meditation-info
* type: Textarea
* use: Lets user input any positive information about their mediation.
* values: Holds users thoughts on their mediation.
*/
add_meta_box(
'abh-meditation', // Unique ID
__( 'Meditation', 'abh_trans' ), // Title
'abh_meditation', // Callback function
'post', // Post Type for this to appear on
'normal', // Context
'core' // Priority
);
/**
* Custom Meta Information: Random Act of Kindness
* meta: abh-meditation-toggle
* type: Checkbox
* use: Lets user check off if they meditated today.
* values: BOOL: 1 True - 0 False.
*
* meta: abh-meditation-info
* type: Textarea
* use: Lets user input any positive information about their mediation.
* values: Holds users thoughts on their mediation.
*/
add_meta_box(
'abh-kindness', // Unique ID
__( 'Conscious Act of Kindness', 'abh_trans' ), // Title
'abh_kindness', // Callback function
'post', // Post Type for this to appear on
'normal', // Context
'core' // Priority
);
}
/* Display the post meta box. */
function abh_gratitudes( $object, $box ) {
global $post;
wp_nonce_field( basename( __FILE__ ), 'abh_gratitudes_nonce' ); ?>
Write three quick sentences about three things that you are great-full for today.
Write any notes about how great your workout was, or any goals or accomplishments you you achieved, or how you felt after.
ID, 'abh-meditation-toggle', true ); ?>
Write any notes about how great your meditation was, or any goals or accomplishments you you achieved, or how you felt after.
Everyday you should commit a conscious act of kindness and make someone else's day better. There are two ways to do this, choose from the following or if you are feeling espically generous today, do both!
ID; }
// bail out if running an autosave, ajax, cron, or revision
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post->ID; }
if( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return $post->ID; }
if( defined( 'DOING_CRON' ) && DOING_CRON ) {
return $post->ID; }
if( wp_is_post_revision( $post_id ) ) {
return $post->ID; }
// make sure the user is authorized
if( ! current_user_can( 'edit_post', $post->ID ) ) {
return $post->ID; }
// this request is validated, proceed to save
if( isset( $_POST[ 'abh-gratitude-one' ] ) ) {
// save the flag for this post
update_post_meta( $post_id, 'abh-gratitude-one', $_POST[ 'abh-gratitude-one' ] );
} else {
// clean up the database record
delete_post_meta( $post->ID, 'abh-gratitude-one' );
}
// this request is validated, proceed to save
if( isset( $_POST[ 'abh-gratitude-two' ] ) ) {
// save the flag for this post
update_post_meta( $post_id, 'abh-gratitude-two', $_POST[ 'abh-gratitude-two' ] );
} else {
// clean up the database record
delete_post_meta( $post->ID, 'abh-gratitude-two' );
}
// this request is validated, proceed to save
if( isset( $_POST[ 'abh-gratitude-three' ] ) ) {
// save the flag for this post
update_post_meta( $post_id, 'abh-gratitude-three', $_POST[ 'abh-gratitude-three' ] );
} else {
// clean up the database record
delete_post_meta( $post->ID, 'abh-gratitude-three' );
}
/*----------------------------------------------------------------------------*
* Save all Content from the journal metabox
*----------------------------------------------------------------------------*/
// validate the request itself using the nonce we set up
if( ! isset( $_POST['abh_journal_nonce'] ) || ! wp_verify_nonce( $_POST['abh_journal_nonce'], basename( __FILE__ ) ) ) {
return $post->ID; }
// bail out if running an autosave, ajax, cron, or revision
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post->ID; }
if( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return $post->ID; }
if( defined( 'DOING_CRON' ) && DOING_CRON ) {
return $post->ID; }
if( wp_is_post_revision( $post_id ) ) {
return $post->ID; }
// make sure the user is authorized
if( ! current_user_can( 'edit_post', $post->ID ) ) {
return $post->ID; }
// this request is validated, proceed to save
if( isset( $_POST[ 'abh_journal' ] ) ) {
// save the flag for this post
update_post_meta( $post_id, 'abh_journal', $_POST[ 'abh_journal' ] );
} else {
// clean up the database record
delete_post_meta( $post->ID, 'abh_journal' );
}
/*----------------------------------------------------------------------------*
* Save all Content from the Exercise Metabox
*----------------------------------------------------------------------------*/
// validate the request itself using the nonce we set up
if( ! isset( $_POST['abh_exercise_nonce'] ) || ! wp_verify_nonce( $_POST['abh_exercise_nonce'], basename( __FILE__ ) ) ) {
return $post->ID; }
// bail out if running an autosave, ajax, cron, or revision
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post->ID; }
if( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return $post->ID; }
if( defined( 'DOING_CRON' ) && DOING_CRON ) {
return $post->ID; }
if( wp_is_post_revision( $post_id ) ) {
return $post->ID; }
// make sure the user is authorized
if( ! current_user_can( 'edit_post', $post->ID ) ) {
return $post->ID; }
// this request is validated, proceed to save
if( isset( $_POST[ 'abh-exercise-toggle' ] ) ) {
// save the flag for this post
update_post_meta( $post_id, 'abh-exercise-toggle', $_POST[ 'abh-exercise-toggle' ] );
} else {
// clean up the database record
delete_post_meta( $post->ID, 'abh-exercise-toggle' );
}
// this request is validated, proceed to save
if( isset( $_POST[ 'abh-exercise-info' ] ) ) {
// save the flag for this post
update_post_meta( $post_id, 'abh-exercise-info', $_POST[ 'abh-exercise-info' ] );
} else {
// clean up the database record
delete_post_meta( $post->ID, 'abh-exercise-info' );
}
/*----------------------------------------------------------------------------*
* Save all Content from the Meditation Metabox
*----------------------------------------------------------------------------*/
// validate the request itself using the nonce we set up
if( ! isset( $_POST['abh_meditation_nonce'] ) || ! wp_verify_nonce( $_POST['abh_meditation_nonce'], basename( __FILE__ ) ) ) {
return $post->ID; }
// bail out if running an autosave, ajax, cron, or revision
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post->ID; }
if( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return $post->ID; }
if( defined( 'DOING_CRON' ) && DOING_CRON ) {
return $post->ID; }
if( wp_is_post_revision( $post_id ) ) {
return $post->ID; }
// make sure the user is authorized
if( ! current_user_can( 'edit_post', $post->ID ) ) {
return $post->ID; }
// this request is validated, proceed to save
if( isset( $_POST[ 'abh-meditation-toggle' ] ) ) {
// save the flag for this post
update_post_meta( $post_id, 'abh-meditation-toggle', $_POST[ 'abh-meditation-toggle' ] );
} else {
// clean up the database record
delete_post_meta( $post->ID, 'abh-meditation-toggle' );
}
// this request is validated, proceed to save
if( isset( $_POST[ 'abh-meditation-info' ] ) ) {
// save the flag for this post
update_post_meta( $post_id, 'abh-meditation-info', $_POST[ 'abh-meditation-info' ] );
} else {
// clean up the database record
delete_post_meta( $post->ID, 'abh-meditation-info' );
}
/*----------------------------------------------------------------------------*
* Save all Content from the Kindness Metabox
*----------------------------------------------------------------------------*/
// validate the request itself using the nonce we set up
if( ! isset( $_POST['abh_kindness_nonce'] ) || ! wp_verify_nonce( $_POST['abh_kindness_nonce'], basename( __FILE__ ) ) ) {
return $post->ID; }
// bail out if running an autosave, ajax, cron, or revision
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post->ID; }
if( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return $post->ID; }
if( defined( 'DOING_CRON' ) && DOING_CRON ) {
return $post->ID; }
if( wp_is_post_revision( $post_id ) ) {
return $post->ID; }
// make sure the user is authorized
if( ! current_user_can( 'edit_post', $post->ID ) ) {
return $post->ID; }
// this request is validated, proceed to save
if( isset( $_POST[ 'abh-kindness-email-toggle' ] ) ) {
// save the flag for this post
update_post_meta( $post_id, 'abh-kindness-email-toggle', $_POST[ 'abh-kindness-email-toggle' ] );
} else {
// clean up the database record
delete_post_meta( $post->ID, 'abh-kindness-email-toggle' );
}
// this request is validated, proceed to save
if( isset( $_POST[ 'abh-kindness-email-name' ] ) ) {
// save the flag for this post
update_post_meta( $post_id, 'abh-kindness-email-name', $_POST[ 'abh-kindness-email-name' ] );
} else {
// clean up the database record
delete_post_meta( $post->ID, 'abh-kindness-email-name' );
}
// this request is validated, proceed to save
if( isset( $_POST[ 'abh-kindness-email-address' ] ) ) {
// save the flag for this post
update_post_meta( $post_id, 'abh-kindness-email-address', $_POST[ 'abh-kindness-email-address' ] );
} else {
// clean up the database record
delete_post_meta( $post->ID, 'abh-kindness-email-address' );
}
// this request is validated, proceed to save
if( isset( $_POST[ 'abh-kindness-email-subject' ] ) ) {
// save the flag for this post
update_post_meta( $post_id, 'abh-kindness-email-subject', $_POST[ 'abh-kindness-email-subject' ] );
} else {
// clean up the database record
delete_post_meta( $post->ID, 'abh-kindness-email-subject' );
}
// this request is validated, proceed to save
if( isset( $_POST[ 'abh-kindness-email-content' ] ) ) {
// save the flag for this post
update_post_meta( $post_id, 'abh-kindness-email-content', $_POST[ 'abh-kindness-email-content' ] );
} else {
// clean up the database record
delete_post_meta( $post->ID, 'abh-kindness-email-content' );
}
// this request is validated, proceed to save
if( isset( $_POST[ 'abh-kindness-email-show-everyone-toggle' ] ) ) {
// save the flag for this post
update_post_meta( $post_id, 'abh-kindness-email-show-everyone-toggle', $_POST[ 'abh-kindness-email-show-everyone-toggle' ] );
} else {
// clean up the database record
delete_post_meta( $post->ID, 'abh-kindness-email-show-everyone-toggle' );
}
// this request is validated, proceed to save
if( isset( $_POST[ 'abh-kindness-physical-toggle' ] ) ) {
// save the flag for this post
update_post_meta( $post_id, 'abh-kindness-physical-toggle', $_POST[ 'abh-kindness-physical-toggle' ] );
} else {
// clean up the database record
delete_post_meta( $post->ID, 'abh-kindness-physical-toggle' );
}
// this request is validated, proceed to save
if( isset( $_POST[ 'abh-kindness-physical-act' ] ) ) {
// save the flag for this post
update_post_meta( $post_id, 'abh-kindness-physical-act', $_POST[ 'abh-kindness-physical-act' ] );
} else {
// clean up the database record
delete_post_meta( $post->ID, 'abh-kindness-physical-act' );
}
return $post;
}