Skip to content

Instantly share code, notes, and snippets.

@ejntaylor
Created December 1, 2016 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejntaylor/6e47208763a877cf7a3b6f3360a5c9de to your computer and use it in GitHub Desktop.
Save ejntaylor/6e47208763a877cf7a3b6f3360a5c9de to your computer and use it in GitHub Desktop.
<?php
function ss_settings_form( $atts = array() ) {
global $post;
// var_dump($atts);
/**
* Depending on your setup, check if the user has permissions to edit_posts
*/
if ( ! current_user_can( 'edit_posts' ) ) {
return _e( 'You do not have permissions to edit this post.', 'lang_domain' );
}
/**
* Make sure a WordPress post ID is set.
* We'll default to the current post/page
*/
if ( ! isset( $atts['post_id'] ) ) {
$atts['post_id'] = $post->ID;
}
// If no metabox id is set, yell about it
if ( empty( $atts['id'] ) ) {
return "Please add a 'id' attribute to specify the CMB2 form to display.";
}
$metabox_id = esc_attr( $atts['id'] );
$object_id = absint( $atts['post_id'] );
// Initiate our output variable
$form = '';
// Get our form
$form .= cmb2_get_metabox_form( $metabox_id, $object_id, array( 'save_button' => __( 'Save Site Data', 'wds-post-submit' ) ) );
return $form;
}
// output for test
$atts2 = array (
'id' => 'site_meta',
'post_id' => 584
);
echo ss_settings_form( $atts2 );
$atts3 = array (
'id' => 'site_meta',
'post_id' => 585
);
echo ss_settings_form( $atts3 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment