/**
  * Displays form markup
  * @since  0.1.3
  * @param  int  $term_id Term ID
  */
 public function display_form($term_id)
 {
     if (!class_exists('CMB2')) {
         return;
     }
     $this->do_override_filters($term_id);
     $object_id = $this->id($term_id);
     $cmb = cmb2_get_metabox($this->metabox, $object_id);
     // if passing a metabox ID, and that ID was not found
     if (!$cmb) {
         return;
     }
     // Hard-code object type
     $cmb->object_type('options-page');
     // Enqueue JS/CSS
     if ($cmb->prop('cmb_styles')) {
         CMB2_hookup::enqueue_cmb_css();
     }
     CMB2_hookup::enqueue_cmb_js();
     // Add object id to the form for easy access
     printf('<input type="hidden" name="term_opt_name" value="%s">', $object_id);
     printf('<input type="hidden" name="object_id" value="%s">', $object_id);
     // Show cmb form
     $cmb->show_form();
 }
Ejemplo n.º 2
0
/**
 * Display a metabox form & save it on submission
 * @since  1.0.0
 * @param  mixed   $meta_box  Metabox config array or Metabox ID
 * @param  int     $object_id Object ID
 * @param  array   $args      Optional arguments array
 */
function cmb2_print_metabox_form($meta_box, $object_id = 0, $args = array())
{
    $object_id = $object_id ? $object_id : get_the_ID();
    $cmb = cmb2_get_metabox($meta_box, $object_id);
    // if passing a metabox ID, and that ID was not found
    if (!$cmb) {
        return;
    }
    $args = wp_parse_args($args, array('form_format' => '<form class="cmb-form" method="post" id="%1$s" enctype="multipart/form-data" encoding="multipart/form-data"><input type="hidden" name="object_id" value="%2$s">%3$s<input type="submit" name="submit-cmb" value="%4$s" class="button-primary"></form>', 'save_button' => __('Save', 'cmb2'), 'object_type' => $cmb->mb_object_type(), 'cmb_styles' => $cmb->prop('cmb_styles'), 'enqueue_js' => $cmb->prop('enqueue_js')));
    // Set object type explicitly (rather than trying to guess from context)
    $cmb->object_type($args['object_type']);
    // Save the metabox if it's been submitted
    // check permissions
    // @todo more hardening?
    if ($cmb->prop('save_fields') && isset($_POST['submit-cmb'], $_POST['object_id'], $_POST[$cmb->nonce()]) && wp_verify_nonce($_POST[$cmb->nonce()], $cmb->nonce()) && $object_id && $_POST['object_id'] == $object_id) {
        $cmb->save_fields($object_id, $cmb->object_type(), $_POST);
    }
    // Enqueue JS/CSS
    if ($args['cmb_styles']) {
        CMB2_hookup::enqueue_cmb_css();
    }
    if ($args['enqueue_js']) {
        CMB2_hookup::enqueue_cmb_js();
    }
    $form_format = apply_filters('cmb2_get_metabox_form_format', $args['form_format'], $object_id, $cmb);
    $format_parts = explode('%3$s', $form_format);
    // Show cmb form
    printf($format_parts[0], $cmb->cmb_id, $object_id);
    $cmb->show_form();
    if (isset($format_parts[1]) && $format_parts[1]) {
        printf(str_ireplace('%4$s', '%1$s', $format_parts[1]), $args['save_button']);
    }
}
Ejemplo n.º 3
0
 /**
  * Render the form of a meta box.
  * @param  string  $metabox     ID of the meta box
  * @param  int $term_id         ID of the term metadata is for
  * @return string               Markup of the form
  */
 function render_form($metabox, $term_id = 0)
 {
     if (!class_exists('CMB2')) {
         return;
     }
     $cmb = cmb2_get_metabox($metabox, $term_id);
     // if passing a metabox ID, and that ID was not found
     if (!$cmb) {
         return;
     }
     // Hard-code object type
     $cmb->object_type('term');
     // Enqueue JS/CSS
     if ($cmb->prop('cmb_styles')) {
         CMB2_hookup::enqueue_cmb_css();
     }
     CMB2_hookup::enqueue_cmb_js();
     // Show cmb form
     $cmb->show_form();
 }
 /**
  * Render the settings page for this plugin.
  *
  * @since    1.0.0
  */
 public function display_plugin_admin_page()
 {
     if (class_exists('CMB2_hookup')) {
         CMB2_hookup::enqueue_cmb_css();
         CMB2_hookup::enqueue_cmb_js();
     }
     include_once 'views/admin.php';
 }
 /**
  * Displays form markup
  * @since  0.1.3
  * @param  int  $term_id Term ID
  */
 public function display_form($term_id)
 {
     if (!class_exists('CMB2')) {
         return;
     }
     $this->do_override_filters($term_id);
     $object_id = $this->id($term_id);
     // Hard-code object ID
     $this->cmb->object_id($object_id);
     // Hard-code object type
     $this->cmb->object_type('options-page');
     // Enqueue JS/CSS
     if ($this->cmb->prop('cmb_styles')) {
         CMB2_hookup::enqueue_cmb_css();
     }
     if ($this->cmb->prop('enqueue_js')) {
         CMB2_hookup::enqueue_cmb_js();
     }
     // Add object id to the form for easy access
     printf('<input type="hidden" name="term_opt_name" value="%s">', $object_id);
     printf('<input type="hidden" name="object_id" value="%s">', $object_id);
     // Show cmb form
     $this->cmb->show_form();
 }