hello again
i am using your given examples but i cant get it right.
add_action( ‘cmb2_init’, ‘yourprefix_register_user_profile_metabox’ );
function yourprefix_register_user_profile_metabox() {
// Start with an underscore to hide fields from custom fields list
$prefix = ‘_yourprefix_user_’;
/**
* Metabox for the user profile screen
*/
$cmb_user = new_cmb2_box( array(
‘id’ => $prefix . ‘edit’,
‘title’ => __( ‘User Profile Metabox’, ‘cmb2’ ),
‘object_types’ => array( ‘user’ ), // Tells CMB to use user_meta vs post_meta
‘show_names’ => true,
‘new_user_section’ => ‘add-new-user’, // where form will show on new user page. ‘add-existing-user’ is only other valid option.
) );
$cmb_user->add_field( array(
‘name’ => __( ‘Extra Info’, ‘cmb2’ ),
‘desc’ => __( ‘field description (optional)’, ‘cmb2’ ),
‘id’ => $prefix . ‘extra_info’,
‘type’ => ‘title’,
‘on_front’ => false,
) );
$cmb_user->add_field( array(
‘name’ => __( ‘Something’, ‘cmb2’ ),
‘desc’ => __( ‘field description (optional)’, ‘cmb2’ ),
‘id’ => $prefix . ‘something’,
‘type’ => ‘textarea’,
) );}
function jt_cmb2_do_frontend_form_shortcode( $atts = array() ) {
global $post;
/**
* Make sure a WordPress post ID is set.
* We’ll default to the current post/page
*/
if ( ! isset( $atts[‘user_id’] ) ) {
$atts[‘user_id’] = $post->ID;
}
// If no metabox id is set, yell about it
if ( empty( $atts[‘id’] ) ) {
return ‘Please add an “id” attribute to specify the CMB2 form to display.’;
}
$metabox_id = esc_attr( $atts[‘id’] );
$object_id = absint( $atts[‘user_id’] );
// Get our form
$form = cmb2_get_metabox_form( $metabox_id, $object_id );
return $form;
}
add_shortcode( ‘cmb-form’, ‘jt_cmb2_do_frontend_form_shortcode’ );
/*shortcode [cmb-form id=”edit” user_id=1]*/