ID, BEYROUTH_META::SIDEBAR_TEMPLATE, true );
$sidebar_location = get_post_meta( $post->ID, BEYROUTH_META::SIDEBAR_LOCATION, true );
// Set default values.
if ( empty( $sidebar_template ) ) { $sidebar_template = 'none'; }
if ( empty( $sidebar_location ) ) { $sidebar_location = 'sidebar-right'; }
// Form fields.
echo '
';
}
public function save_metabox( $post_id, $post ) {
// Add nonce for security and authentication.
$nonce_name = isset( $_POST[ 'left_right_sidebar_meta_box_nonce' ] ) ? $_POST[ 'left_right_sidebar_meta_box_nonce' ] : '';
$nonce_action = 'left_right_sidebar_meta_box_nonce_action';
// Check if a nonce is set and valid
if ( !isset( $nonce_name ) ) { return; }
if ( !wp_verify_nonce( $nonce_name, $nonce_action ) ) { return; }
// Sanitize user input.
$sidebar_template = isset( $_POST[ BEYROUTH_META::SIDEBAR_TEMPLATE ] ) ? sanitize_text_field( $_POST[ BEYROUTH_META::SIDEBAR_TEMPLATE ] ) : '';
$sidebar_location = isset( $_POST[ BEYROUTH_META::SIDEBAR_LOCATION ] ) ? sanitize_text_field( $_POST[ BEYROUTH_META::SIDEBAR_LOCATION ] ) : '';
// Update the meta field in the database.
update_post_meta( $post_id, BEYROUTH_META::SIDEBAR_TEMPLATE, $sidebar_template );
update_post_meta( $post_id, BEYROUTH_META::SIDEBAR_LOCATION, $sidebar_location );
}
}