<?php
/**
 * Add meta box
 *
 */
function effectpage_add_meta_boxes( $post ){
	add_meta_box( 'food_meta_box', __( '<span class="dashicons dashicons-layout"></span> Page Layout Select [Pro Only]', 'effect' ), 'effectpage_build_meta_box', 'page', 'side', 'high' );
}
add_action( 'add_meta_boxes', 'effectpage_add_meta_boxes' );
/**
 * Build custom field meta box
 *
 * @param post $post The post object
 */
function effectpage_build_meta_box( $post ){
	// make sure the form request comes from WordPress
	wp_nonce_field( basename( __FILE__ ), 'effectpagemeta_meta_box_nonce' );
	// retrieve the _food_effectpagemeta current value
	$current_effectpagemeta = get_post_meta( $post->ID, '_food_effectpagemeta', true );
	
	$upgradetopro = 'Layout Select for current Page only - for website layout please choose from theme options <a href="' . esc_url('http://www.insertcart.com/product/effect-wp-theme/','effect') . '" target="_blank">' . esc_attr__( 'Get Effect Pro', 'effect' ) . '</a>';

	?>
	<div class='inside'>

		<h4><?php echo $upgradetopro; ?></h4>
		<p>
			<input type="radio" name="effectpagemeta" value="rsd" <?php checked( $current_effectpagemeta, 'rsd' ); ?> /> <?php _e('Right Sidebar - Default','effect'); ?><br />
			<input type="radio" name="effectpagemeta" value="ls" <?php checked( $current_effectpagemeta, 'ls' ); ?> /> <?php _e('Left Sidebar','effect'); ?><br/>
			<input type="radio" name="effectpagemeta" value="lr" <?php checked( $current_effectpagemeta, 'lr' ); ?> />     <?php _e('Left - Right Sidebars','effect'); ?> <br/>
			<input type="radio" name="effectpagemeta" value="fc" <?php checked( $current_effectpagemeta, 'fc' ); ?> /> <?php _e('Full Content - No Sidebar','effect'); ?>
		</p>

		

	</div>
	<?php
}
/**
 * Store custom field meta box data
 *
 * @param int $post_id The post ID.
 * @link https://codex.wordpress.org/Plugin_API/Action_Reference/save_post
 */
function effectpage_save_meta_box_data( $post_id ){
	// verify meta box nonce
	if ( !isset( $_POST['effectpagemeta_meta_box_nonce'] ) || !wp_verify_nonce( $_POST['effectpagemeta_meta_box_nonce'], basename( __FILE__ ) ) ){
		return;
	}
	// return if autosave
	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ){
		return;
	}
  // Check the user's permissions.
	if ( ! current_user_can( 'edit_post', $post_id ) ){
		return;
	}
	// store custom fields values
	// effectpagemeta string
	if ( isset( $_REQUEST['effectpagemeta'] ) ) {
		update_post_meta( $post_id, '_food_effectpagemeta', sanitize_text_field( $_POST['effectpagemeta'] ) );
	}

}
add_action( 'save_post', 'effectpage_save_meta_box_data' );