/**
  * Displays form markup
  * @since  0.1.3
  * @param  int  $term_id Term ID
  */
 public function display_form($term_id)
 {
     if (!class_exists('cmb_Meta_Box')) {
         return;
     }
     $this->do_override_filters($term_id);
     // Fill in the mb defaults
     $meta_box = cmb_Meta_Box::set_mb_defaults($this->fields());
     // Make sure that our object type is explicitly set by the metabox config
     cmb_Meta_Box::set_object_type(cmb_Meta_Box::set_mb_type($meta_box));
     // Add object id to the form for easy access
     printf('<input type="hidden" name="term_opt_name" value="%s">', $this->id($term_id));
     // Show cmb form
     cmb_print_metabox($meta_box, $this->id($term_id));
 }
Exemplo n.º 2
0
/**
 * Display a metabox form & save it on submission
 * @since  1.0.0
 * @param  array   $meta_box  Metabox config array
 * @param  int     $object_id Object ID
 * @param  boolean $return    Whether to return or echo form
 * @return string             CMB html form markup
 */
function cmb_metabox_form($meta_box, $object_id, $echo = true)
{
    $meta_box = cmb_Meta_Box::set_mb_defaults($meta_box);
    // Make sure form should be shown
    if (!apply_filters('cmb_show_on', true, $meta_box)) {
        return '';
    }
    // Make sure that our object type is explicitly set by the metabox config
    cmb_Meta_Box::set_object_type(cmb_Meta_Box::set_mb_type($meta_box));
    // Save the metabox if it's been submitted
    // check permissions
    // @todo more hardening?
    if (isset($_POST['submit-cmb'], $_POST['object_id'], $_POST['wp_meta_box_nonce']) && wp_verify_nonce($_POST['wp_meta_box_nonce'], cmb_Meta_Box::nonce()) && $_POST['object_id'] == $object_id) {
        cmb_save_metabox_fields($meta_box, $object_id);
    }
    // Show specific metabox form
    // Get cmb form
    ob_start();
    cmb_print_metabox($meta_box, $object_id);
    $form = ob_get_contents();
    ob_end_clean();
    $form_format = apply_filters('cmb_frontend_form_format', '<form class="cmb-form" method="post" id="%s" enctype="multipart/form-data" encoding="multipart/form-data"><input type="hidden" name="object_id" value="%s">%s<input type="submit" name="submit-cmb" value="%s" class="button-primary"></form>', $object_id, $meta_box, $form);
    $form = sprintf($form_format, $meta_box['id'], $object_id, $form, __('Save'));
    if ($echo) {
        echo $form;
    }
    return $form;
}