Created
November 23, 2016 17:11
-
-
Save ejntaylor/bf0c45ce0e1a80695f0b4f23d2e2d0fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_shortcode( 'ss-site-form', 'ss_frontend_form_shortcode' ); | |
/** | |
* Shortcode to display a CMB2 form for a post ID. | |
* @param array $atts Shortcode attributes | |
* @return string Form HTML markup | |
*/ | |
function ss_frontend_form_shortcode( $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'] ); | |
// Get our form | |
$form = cmb2_get_metabox_form( $metabox_id, $object_id ); | |
return $form; | |
} | |
function site_title() { | |
$user_array = ss_list_array(); | |
foreach ($user_array['sites'] as $site) { | |
$title = $site['post_title'];; | |
echo '<li><a href="">'.$title.'</a></li>'; | |
} | |
} | |
function site_tab() { | |
$user_array = ss_list_array(); | |
foreach ($user_array['sites'] as $site) { | |
// vars | |
$post_id = $site['post_id']; | |
$meta_id = 'site_meta'; | |
$atts = array ( | |
'id' => $meta_id, | |
'post_id' => (string)$post_id | |
); | |
//var_dump($atts); | |
echo '<li>'.do_shortcode('[ss-site-form post_id='. $post_id .' id='. $meta_id .' ]').'</li>'; | |
//ss_frontend_form_shortcode($atts); | |
} | |
} | |
?> | |
<h1>Site Settings</h1> | |
<div class="uk-alert uk-alert-warning">Your sites will be displayed below.</div> | |
<div class="uk-grid"> | |
<!-- This is the vertical tabbed navigation containing the toggling elements --> | |
<ul class="uk-tab uk-tab-left col-md-4" data-uk-tab="{connect:'#my-id'}"> | |
<?php site_title(); ?> | |
</ul> | |
<!-- This is the container of the content items --> | |
<ul id="my-id" class="uk-switcher col-med-8 container"> | |
<?php site_tab(); ?> | |
</ul> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment