当前位置: 首页>>代码示例>>PHP>>正文


PHP cmb2_get_metabox函数代码示例

本文整理汇总了PHP中cmb2_get_metabox函数的典型用法代码示例。如果您正苦于以下问题:PHP cmb2_get_metabox函数的具体用法?PHP cmb2_get_metabox怎么用?PHP cmb2_get_metabox使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cmb2_get_metabox函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: yourprefix_add_new_field_to_group

function yourprefix_add_new_field_to_group()
{
    // Try to get a metabox w/ the id of '_yourprefix_group_metabox'
    if ($cmb_group_demo = cmb2_get_metabox('_yourprefix_group_metabox')) {
        $cmb_group_demo->add_field(array('name' => __('Test Text 2', 'your_textdomain'), 'desc' => __('field description (optional)', 'your_textdomain'), 'id' => 'text2', 'type' => 'text', 'attributes' => array('placeholder' => __("I'm some placeholder text", 'your_textdomain'))), '_yourprefix_group_demo', 2);
    }
}
开发者ID:blobaugh,项目名称:CMB2-Snippet-Library,代码行数:7,代码来源:cmb2_init_before_hookup-add-fields.php

示例2: frontend_form_shortcode

function frontend_form_shortcode($atts = array())
{
    // current user
    $user_id = get_current_user_id();
    // user ID of metabox in front_end_metabox
    $metabox_id = '_frontend_form';
    // since post ID will not exist yet, just need to pass it
    $object_id = 'fake_object_id';
    // get cmb2 metabox object
    $cmb = cmb2_get_metabox($metabox_id, $object_id);
    // get $cmb object_type
    $post_types = $cmb->prop('object_types');
    $atts = shortcode_atts(array('post_author' => $user_id ? $user_id : 1, 'post_status' => 'pending', 'post_type' => reset($post_types)), $atts, 'cmb-frontend-form');
    foreach ($atts as $key => $value) {
        $cmb->add_hidden_field(array('field_args' => array('id' => "atts[{$key}]", 'type' => 'hidden', 'default' => $value)));
    }
    // Initiate our output variable
    $output = '';
    // Get any submission errors
    if (($error = $cmb->prop('submission_error')) && is_wp_error($error)) {
        // If there was an error with the submission, add it to our ouput.
        $output .= '<h3>' . sprintf(__('There was an error in the submission: %s', 'sexy'), '<strong>' . $error->get_error_message() . '</strong>') . '</h3>';
    }
    // If the post was submitted successfully, notify the user.
    if (isset($_GET['post_submitted']) && ($post = get_post(absint($_GET['post_submitted'])))) {
        // Get submitter's name
        $name = get_post_meta($post->ID, '_frontend_name', 1);
        $name = $name ? ' ' . $name : '';
        // Add notice of submission to our output
        $output .= '<h3>' . sprintf(__('Thank you%s, your new post has been submitted and is pending review by a site administrator.', 'sexy'), esc_html($name)) . '</h3>';
    }
    // Get our form
    $output .= cmb2_get_metabox_form($cmb, 'fake_object_id', array('save_button' => __('Submit Post', 'sexy')));
    return $output;
}
开发者ID:anam5233,项目名称:wp_isotope,代码行数:35,代码来源:porinite.php

示例3: yourprefix_update_fields_properties

/**
 * This file demonstrates modifying existing registered CMB2 metabox fields
 */
function yourprefix_update_fields_properties()
{
    // Retrieve a CMB2 instance
    $cmb = cmb2_get_metabox('_yourprefix_demo_metabox');
    /**
     * Update a property on the '_yourprefix_demo_text' field.
     * In this case, we'll remove the show_on_cb conditional callback
     * (to instead always display the field)
     *
     * If field exists, and property updated, it will return the field id
     */
    $field_id = $cmb->update_field_property('_yourprefix_demo_text', 'show_on_cb', false);
    /**
     * Always need to compare this value strictly to false, as a field_id COULD be 0 or ''
     */
    if (false !== $field_id) {
        /**
         * Because we don't want to 'stomp' a field's 'attributes' property
         * (It may already have some attributes), we're going to get
         * the field's attributes property and append to it.
         */
        // Get all fields for this metabox
        $fields = $cmb->prop('fields');
        // Get the attributes array if it exists, or else create it
        $attributes = isset($fields['_yourprefix_demo_text']['attributes']) ? $fields['_yourprefix_demo_text']['attributes'] : array();
        // Add placeholder text
        $attributes['placeholder'] = __("I'm some placeholder text", 'your_textdomain');
        // Update the field's 'attributes' property
        $cmb->update_field_property('_yourprefix_demo_text', 'attributes', $attributes);
    }
}
开发者ID:blobaugh,项目名称:CMB2-Snippet-Library,代码行数:34,代码来源:cmb2_init_before_hookup-update-existing-fields.php

示例4: __construct

 public function __construct($meta_box_config)
 {
     $this->setMetaBoxConfig($meta_box_config);
     $this->setCmb2Obj(\cmb2_get_metabox($this->getMetaBoxConfig()));
     //$cmb2Obj = $this->getCmb2Obj();
     //error_log('--- DEBUG: $cmb2Obj ---');
     //error_log(print_r($cmb2Obj, true));
     //add_action("admin_init", array($this, 'adminInit'), 15);
 }
开发者ID:jmarceli,项目名称:CMB2-grid,代码行数:9,代码来源:Cmb2Grid.php

示例5: wds_frontend_cmb2_get

/**
 * Gets the front-end-post-form cmb instance
 *
 * @return CMB2 object
 */
function wds_frontend_cmb2_get()
{
    // Use ID of metabox in wds_frontend_form_register
    $metabox_id = 'front-end-post-form';
    // Post/object ID is not applicable since we're using this form for submission
    $object_id = 'fake-oject-id';
    // Get CMB2 metabox object
    return cmb2_get_metabox($metabox_id, $object_id);
}
开发者ID:ryanduff,项目名称:CMB2-Snippet-Library,代码行数:14,代码来源:cmb2-front-end-submit.php

示例6: tbws_testimonial_cmb2_get

/**
 * Gets the offer-new cmb instance
 *
 * @return CMB2 object
 */
function tbws_testimonial_cmb2_get()
{
    // Use ID of metabox in wds_frontend_form_register
    $metabox_id = 'tbws_testimonial';
    // Post/object ID is not applicable since we're using this form for submission
    $object_id = 'tbws_testimonial_id';
    // Get CMB2 metabox object
    return cmb2_get_metabox($metabox_id, $object_id);
}
开发者ID:JiveDig,项目名称:testimonials-submissions,代码行数:14,代码来源:shortcode.php

示例7: add_rest_api_override_field

 /**
  * Add another field to the $metabox_id CMB box instance
  *
  * @since 0.1.0
  */
 function add_rest_api_override_field()
 {
     // Retrieve the CMB2 instance
     $cmb = cmb2_get_metabox($this->metabox_id);
     if (!$cmb) {
         return;
     }
     foreach ($this->fields() as $field) {
         $cmb->add_field($field);
     }
 }
开发者ID:JPry,项目名称:WDS-Allow-REST-API,代码行数:16,代码来源:admin-base.php

示例8: do_save

 /**
  * Handles saving of the $_POST data
  * @since  0.1.3
  * @param  int $term_id Term's ID
  */
 public function do_save($term_id)
 {
     if (!class_exists('CMB2')) {
         return;
     }
     $object_id = $this->id($term_id);
     $cmb = cmb2_get_metabox($this->metabox, $object_id);
     if (isset($_POST[$cmb->nonce()]) && wp_verify_nonce($_POST[$cmb->nonce()], $cmb->nonce())) {
         $this->do_override_filters($term_id);
         $cmb->save_fields($object_id, 'options-page', $_POST);
     }
 }
开发者ID:cnasikas,项目名称:Taxonomy_MetaData,代码行数:17,代码来源:Taxonomy_MetaData_CMB2.php

示例9: test_cmb2_get_metabox

 public function test_cmb2_get_metabox()
 {
     // Test that successful retrieval by box ID
     $retrieve = cmb2_get_metabox($this->cmb_id);
     $this->assertEquals($this->cmb, $retrieve);
     // Test that successful retrieval by box Array
     $cmb = cmb2_get_metabox($this->metabox_array);
     $this->assertEquals($this->cmb, $cmb);
     // Test successful creation of new MB
     $cmb1 = cmb2_get_metabox($this->metabox_array2);
     $cmb2 = new CMB2($this->metabox_array2);
     $this->assertEquals($cmb1, $cmb2);
 }
开发者ID:Raptor831,项目名称:RFStockalike-Generator,代码行数:13,代码来源:test-cmb-core.php

示例10: __construct

 /**
  * Initiate CMB2 Taxonomy Meta
  *
  * @since 1.0.0
  *
  * @param string  $taxonomy          Taxonomy Slug
  * @param mixed   $meta_box  Metabox config array or Metabox ID
  * @param string  $title             Optional section title
  * @param array   $option_callbacks  Override the option setting/getting
  */
 public function __construct($taxonomy, $metabox, $title = '', $option_callbacks = array())
 {
     $this->cmb = cmb2_get_metabox($metabox);
     // if passing a metabox ID, and that ID was not found
     if (!$this->cmb) {
         return;
     }
     // If a title was passed in
     if ($title) {
         // Then add a title field to the list of fields for CMB
         $this->cmb->add_field(array('name' => $title, 'id' => sanitize_title($title), 'type' => 'title'), 1);
     }
     parent::__construct($taxonomy, array(), '', $option_callbacks);
 }
开发者ID:rhyswynne,项目名称:Taxonomy_MetaData,代码行数:24,代码来源:Taxonomy_MetaData_CMB2.php

示例11: start_customizer

 public function start_customizer($wp_customize)
 {
     $customizer_objects = array();
     $customizer_boxes = CMB2_Boxes::get_all();
     foreach ($customizer_boxes as $type => $instance) {
         $customizer_objects[] = cmb2_get_metabox($type, 0, 'customizer');
     }
     $field_type_mapping = array('title' => 'WP_Customize_Control', 'text' => 'WP_Customize_Control', 'text_small' => 'WP_Customize_Control', 'text_medium' => 'WP_Customize_Control', 'text_email' => 'WP_Customize_Control', 'text_url' => 'WP_Customize_Control', 'text_money' => 'WP_Customize_Control', 'colorpicker' => 'WP_Customize_Color_Control', 'file' => 'WP_Customize_Media_Control');
     foreach ($customizer_objects as $index => $cmb) {
         /* Add Address Info to Customizer */
         $customizer_id = $cmb->prop('id');
         $wp_customize->add_section($customizer_id, array('title' => $cmb->prop('title'), 'priority' => $cmb->prop('priority'), 'capability' => 'edit_theme_options'));
         $fields = $cmb->prop('fields');
         foreach ($fields as $field_type) {
             $type = $field_type['type'];
             $type_class = isset($field_type_mapping[$type]) ? $field_type_mapping[$type] : false;
             /* Street */
             $wp_customize->add_setting($field_type['id'], array('type' => 'option'));
             $wp_customize->add_control(new $type_class($wp_customize, $field_type['id'], array('label' => $field_type['name'], 'section' => $customizer_id, 'settings' => $field_type['id'], 'priority' => 10)));
         }
     }
 }
开发者ID:ronalfy,项目名称:CMB2,代码行数:22,代码来源:CMB2_Customizer.php

示例12: yourprefix_output_custom_mb_location

/**
 * Display checkbox metabox below title field
 * @link https://github.com/WordPress/WordPress/blob/56d6682461be82da1a3bafc454dad2c9da451a38/wp-admin/edit-form-advanced.php#L560-L567
 */
function yourprefix_output_custom_mb_location()
{
    cmb2_get_metabox('_yourprefix_display_title')->show_form();
}
开发者ID:ryanduff,项目名称:CMB2-Snippet-Library,代码行数:8,代码来源:outputting-forms-outside-metaboxes.php

示例13: cmb2_print_metabox_form

/**
 * 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']);
    }
}
开发者ID:jrajalu,项目名称:myxon,代码行数:40,代码来源:helper-functions.php

示例14: save_fields

 /**
  * Save fields earlier in the load order (cmb2_after_init)
  *
  * @since  0.1.0
  *
  * @return null
  */
 public function save_fields()
 {
     // Retrieve the CMB2 instance
     $cmb = cmb2_get_metabox($this->metabox_id);
     // Save the metabox if it's been submitted
     // check permissions
     if ($cmb && isset($_POST['submit-cmb'], $_POST['object_id'], $_POST[$cmb->nonce()]) && wp_verify_nonce($_POST[$cmb->nonce()], $cmb->nonce()) && $_POST['object_id'] == $this->key) {
         $cmb->object_type('options-page');
         $cmb->save_fields($this->key, $cmb->object_type(), $_POST);
     }
 }
开发者ID:WebDevStudios,项目名称:WDS-Network-Require-Login,代码行数:18,代码来源:admin-base.php

示例15: test_multiple_meta_rows

 public function test_multiple_meta_rows()
 {
     $prefix = 'testing';
     $post_id = $this->post_id;
     $array_val = array('check1', 'check2');
     $cmb_demo = cmb2_get_metabox(array('id' => $prefix . 'metabox', 'title' => __('Test Metabox', 'cmb2'), 'object_types' => array('page'), 'show_on_cb' => 'yourprefix_show_if_front_page', 'context' => 'normal', 'priority' => 'high', 'show_names' => true), $post_id);
     $field_id = $cmb_demo->add_field(array('name' => __('Test Multi Checkbox', 'cmb2'), 'desc' => __('field description (optional)', 'cmb2'), 'id' => $prefix . 'multicheckbox', 'type' => 'multicheck', 'multiple' => true, 'options' => array('check1' => __('Check One', 'cmb2'), 'check2' => __('Check Two', 'cmb2'), 'check3' => __('Check Three', 'cmb2'))));
     $field = $cmb_demo->get_field($field_id);
     $saved = $field->save_field($array_val);
     $this->assertEquals(2, $saved);
     $this->assertEquals($array_val, $field->get_data());
     $this->assertEquals($array_val, get_post_meta($post_id, $field_id));
     $val = get_post_meta($post_id, $field_id, 1);
     $this->assertEquals(reset($array_val), $val);
 }
开发者ID:Dovahkiin1991,项目名称:CMB2,代码行数:15,代码来源:test-cmb-field.php


注:本文中的cmb2_get_metabox函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。