add_action( 'add_meta_boxes', 'global_banner_setting_meta_box' );
function global_banner_setting_meta_box() {
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
add_meta_box(
'banner_setting_data',
__( 'Banner Setting', 'launchpm' ),
'render_metabox',
'page',
'advanced',
'default'
);
}
function render_metabox( $post ) {
field_generator( $post );
}
function field_generator( $post ) {
wp_nonce_field( 'banner_nonce_action', 'banner_nonce' );
$banner_title_data = get_post_meta($post->ID,'banner_title_data_',true);
$banner_description_data = get_post_meta($post->ID,'banner_description_data_',true);
if(empty($banner_title_data)){$banner_title_data = '';}
if(empty($banner_description_data)){$banner_description_data = '';}
$banner_html_code = '<div id="postcustomstuff">';
$banner_html_code .='<table class="form-table">';
$banner_html_code .='<tr>';
$banner_html_code .='<td><label style="display:block; font-weight:600; margin:0 8px;" for="banner_title_data" class="banner_title_label">' . __( 'Banner Title', 'launchpm' ) . '</label><input type="text" id="banner_title_data" name="banner_title_data" class="banner_title_data_field" placeholder="' . esc_attr__( '', 'launchpm' ) . '" value="' . esc_attr__( $banner_title_data ) . '"></td>';
$banner_html_code .='</tr>';
$banner_html_code .='<tr>';
$banner_html_code .='<td><label style="display:block; font-weight:600; margin:0 8px;" for="banner_description_data" class=banner_description_data_label">' . __( 'Banner Description', 'launchpm' ) . '</label>
<textarea id="banner_description_data" class="textarea banner_description_data_field" name="banner_description_data" placeholder="' . esc_attr__( '', 'launchpm' ) . '" rows="8">' . esc_attr__( $banner_description_data ) . '</textarea></td>
';
$banner_html_code .='</tr>';
$banner_html_code .='</table>';
$banner_html_code .='</div>';
echo $banner_html_code;
}
add_action( 'save_post','save_metabox_banner_data', 10, 2);
function save_metabox_banner_data($post_id, $post)
{
$nonce_name = $_POST['banner_nonce'];
$nonce_action = 'banner_nonce_action';
if ( ! isset( $nonce_name ) )
return;
if ( ! wp_verify_nonce( $nonce_name, $nonce_action ) )
return;
if ( ! current_user_can( 'edit_post', $post_id ) )
return;
if ( wp_is_post_autosave( $post_id ) )
return;
if ( wp_is_post_revision( $post_id ) )
return;
$banner_title_data = isset( $_POST[ 'banner_title_data' ] ) ? $_POST[ 'banner_title_data' ] : '';
$banner_description_data = isset( $_POST[ 'banner_description_data' ] ) ? $_POST[ 'banner_description_data' ] : '';
// Update the meta field in the database.
update_post_meta( $post_id, 'banner_title_data_', $banner_title_data );
update_post_meta( $post_id, 'banner_description_data_', $banner_description_data );
}