Giter VIP home page Giter VIP logo

cmb2's Introduction

CMB2

Gitter Travis Scrutinizer Code Quality Scrutinizer Coverage Project Stats

CMB2

Contributors: jtsternberg, webdevstudios, zao, humanmade
Homepage: https://cmb2.io
Tags: metaboxes, forms, fields, options, settings
Requires at least: 3.8.0
Requires PHP: 7.4
Tested up to: 6.4
Stable tag: 2.11.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Wordpress plugin Wordpress Wordpress rating

Complete contributors list found here: github.com/CMB2/CMB2/graphs/contributors

Description

CMB2 is a developer's toolkit for building metaboxes, custom fields, and forms for WordPress that will blow your mind. Easily manage meta for posts, terms, users, comments, or create custom option pages.

Download plugin on wordpress.org

CMB2 is a complete rewrite of Custom Metaboxes and Fields for WordPress. To get started, please follow the examples in the included example-functions.php file and have a look at the basic usage instructions.

You can see a list of available field types here.

If you are coming from the original "Custom Metaboxes and Fields for WordPress" plugin, please read this post for the CMB2 background story.

Contribution

Development occurs on Github, and all contributions welcome. Please read the CONTRIBUTING doc for more details.

A complete list of all our awesome contributors found here: github.com/CMB2/CMB2/graphs/contributors

Features:

Translation

If you are looking to provide language translation files, Please do so via WordPress Plugin Translations.

3rd Party Resources

Custom Field Types

Other Helpful Resources

Links

Installation

If installing the plugin from wordpress.org:

  1. Upload the entire /CMB2 directory to the /wp-content/plugins/ directory.
  2. Activate CMB2 through the 'Plugins' menu in WordPress.
  3. Copy (and rename if desired) example-functions.php into to your theme or plugin's directory.
  4. Edit to only include the fields you need and rename the functions.
  5. Profit.

If including the library in your plugin or theme:

  1. Place the CMB2 directory inside of your theme or plugin.
  2. Copy (and rename if desired) example-functions.php into a folder above the CMB2 directory OR copy the entirety of its contents to your theme's functions.php file.
  3. Edit to only include the fields you need and rename the functions (CMB2 directory should be left unedited in order to easily update the library).
  4. Profit.

View CHANGELOG

Known Issues

  • Not all fields work well in a repeatable group.

cmb2's People

Contributors

anhskohbo avatar billerickson avatar bradp avatar cai333 avatar cluke009 avatar dependabot[bot] avatar dessibelle avatar garyjones avatar gregrickaby avatar gyrus avatar jamesgol avatar jazzsequence avatar jonmasterson avatar jpry avatar jrfnl avatar jtsternberg avatar lipemat avatar manzoorwanijk avatar markjaquith avatar norcross avatar pglewis avatar ramiy avatar rubengc avatar rubenmartins avatar scrutinizer-auto-fixer avatar senicar avatar slaffik avatar tw2113 avatar twoelevenjay avatar yivi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cmb2's Issues

Implement Late Instantiation

  • Store within array of CMB2_Boxes as a basic array
  • Instantiation on get, if $meta_box is not an object already, store new object back in $meta_boxes
  • Store as $meta_boxes[ 'object_type' ][ 'meta_box_id' ] = $meta_box;
  • Add ability to remove meta boxes
  • Ability to add fields to meta boxes
  • Ability to remove fields from meta boxes

CMB2 objects should not be setup for each meta box / field defined in cmb2_meta_boxes filter until called and needed on a page. Avoid processing / cleanup of data prior to storage for performance.

Composer.json

Hi,

Adding a composer.json file would be great for people who use Composer as a dependency manager.

Thanks !

truncated option values in select boxes

When building a select input my values are being truncated. This is happening even with the example form input.

Example

array(
                    'name'    => 'Test Select',
                    'desc'    => 'Select an option',
                    'id'      => $prefix . 'test_select',
                    'type'    => 'select',
                    'options' => array(
                         'standard' => __( 'Option One', 'cmb' ),
                         'custom'   => __( 'Option Two', 'cmb' ),
                         'none'     => __( 'Option Three', 'cmb' ),
                    ),
                    'default' => 'custom',
                ),

output

<select class="cmb2_select" name="_cmb2_characters[0][_cmb2_test_select]" id="_cmb2_characters_0__cmb2_test_select">    <option value="s" >Option One</option>
    <option value="c" >Option Two</option>
    <option value="n" >Option Three</option>
</select>

Enhancements to color picker field

I have a need for rgba color with my usage of this field and I would imagine others may need additional color spaces as well. It would be nice if could choose the format to use for colors in the options as well as alpha level.

So (hex, rgb, hsv) + alpha (are there others people regularly use?)

This field should probably be using the html5 input=[color] as well.
There is a jquery plugin http://bgrins.github.io/spectrum/ it looks pretty robust.

I would be willing to work on this if there is interest. Until then I will be adding this in as a custom field type for my project.

Change 'pages' metabox parameter name

'pages' is unintuitive and ambiguous. 'object_types` is probably most relevant as it accepts CPTs as well as 'user', 'comment', 'options-page' (etc?).

Collapsible groups

Is there any interest making the groups collapsible? I have this working on the master branch, sadly I didn't realize I should have been working against truck until I went to make a pull request.

The new html and/or css really breaks the layout of my code and I wanted to know if there was any interest in merging this feature before I went any further getting things working on trunk.

Add support for custom validation / bail

The sanitization_cb is great, but doesn't let you bail on the saving process or throw an error to the screen. There should be a way to bail or return a WP_Error from sanitization_cb, or add a loop prior to the saving process to handle this which would stop saving entirely.

Package is not in packagist

I am working on making a good base theme that has all dependencies manage by composer.

It would be great if this was in packagist. I would submit it but I believe the package author is supposed to submit it here: https://packagist.org/packages/submit

I could add it to my composer.json file like so ( https://getcomposer.org/doc/05-repositories.md#loading-a-package-from-a-vcs-repository ) but that is typically reserved for forking libraries.

I'm sure a lot of other people would like to see this in packagist too :)

how to create switch feild

I want to create switch feild but i don't know what how to create please check my code below

add_filter( 'cmb_render_at_switch', 'at_switch', 10, 2 ); function at_switch( $field, $meta ) { //Label ON $this->field['on'] = isset( $this->field['on'] ) ? $this->field['on'] : __( 'On', 'mytheme' );

//Label OFF
$this->field['off'] = isset( $this->field['off'] ) ? $this->field['off'] : __( 'Off', 'mytheme' );

echo '<div id="bounds">';
echo '<label class="on"><input type="radio" name="', $field['id'], '" id="', $field['id'], '"><span>'.$this->field['on'].'</span></label>';
echo '<label class="off"><input type="radio" name="', $field['id'], '" id="', $field['id'], '"><span>'.$this->field['off'].'</span></label>';
echo '</div>';

}

html and css can be find here
http://jsfiddle.net/RkvAP/1304/

WYSIWYG autop issues

I'm getting some strange inconsistencies. I have a large metabox that uses a few wysiwyg editors.
One example is:
array(
'name' => __( 'Description', 'rich-recipes' ),
'id' => $prefix . 'description',
'type' => 'wysiwyg',
'options' => array(
'media_buttons' => false,
'textarea_name' => $slug . 'description',
'textarea_rows' => 12,
'teeny' => false,
'tinymce' => array(
'toolbar1' => 'bold,italic,underline,link,unlink,',
),
'quicktags' => false,
),
'before_row' => '

',
),

In the 'options' array i've tried to set 'wpautop' => false as shown the opposite here: https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/wiki/Field-Types#wysiwyg

Here's the strangeness: No matter what I do, the first people never uses wpautop and ALL the other wysiwyg fields DO use it. No matter what I do with the setting or if I remove it altogether.

Any ideas? I've been digging, but no luck.

Helper functions are not accessible

When I try to access the function cmb2_metabox_form from my functions.php or any other theme file I get Call to undefined function cmb2_metabox_form().

I checked using function_exists method as well, it returns false.

I have been trying to access this same at multiple places, but no luck. Only places where it works are the helper-functions.php, CMB2.php and in init.php inside the class definition.

It would be great if you can help in figuring it out.

Feature Request - global and per field description location

It would be great to define whether the description should be before the field (after title) or after field. Example: for wysiwyg having the description below the text editor is awkward because you sometimes don't see it until you scroll down. I'd prefer them above.

The option to declare it globally (per metabox) and/or override it per field would be awesome.

text_money field before attribute not working as expected.

Hi

When I use a text_money field and do not declare the before attribute the $ symbol is printed at the left of the input field. When I declare another symbol like euro the symbol is printed at the top of the field's description.

Code:

$prefix = 'rlp_mb';

$meta_boxes['themed_info_mb'] = array(
    'id'            => 'themed_info_mb',
    'title'         => __( 'Informations', rlp_txtd ),
    'object_types'  => array( 'themed', ), // Post type
    'context'       => 'normal',
    'priority'      => 'high',
    'show_names'    => true, // Show field names on the left
    'fields'        => array(
        array(
            'name'       => __( 'Duration', rlp_txtd ),
            'desc'       => __( 'The duration of the themed.', rlp_txtd ),
            'id'         => $prefix . 'th_duration',
            'type'       => 'text_small',
            //'show_on_cb' => 'cmb2_hide_if_no_cats', // function should return a bool value
            // 'sanitization_cb' => 'my_custom_sanitization', // custom sanitization callback parameter
            // 'escape_cb'       => 'my_custom_escaping',  // custom escaping callback parameter
            // 'on_front'        => false, // Optionally designate a field to wp-admin only
            // 'repeatable'      => true,
        ),
        array(
            'name' => __( 'Meeting time', rlp_txtd ),
            'desc' => __( 'The time of the meeting', rlp_txtd ),
            'id'   => $prefix . 'th_mt',
            'type' => 'text_time',
            'time_format' => 'H:i'
        ),
        array(
            'name'       => __( 'Meeting point description', rlp_txtd ),
            'id'         => $prefix . 'th_meeting_desc',
            'type'       => 'textarea_small'
        ),
        array(
            'name' => __( 'Prices', rlp_txtd ),
            'desc' => __( 'Every row represents the number of persons. First row is the price of the tour for one person, the second row is the price of the tour for two persons etc.<br>'
                .'If the selected number of person, by the client on the front end, is not definied the last row will be used as a price.', rlp_txtd ),
            'id'   => 'th_pp_price',
            'type' => 'text_money',
            'before'     => '&euro;', // override '$' symbol if needed
            'repeatable' => true,
        ),
    )
);

cmb2_price_1
cmb2_price_2

Wordpress version : 4.0
CMB2 version : 2.0.0-beta

Thanks!

Tag a (beta) release

I'd like to include CMB2 via Packagist, but there isn't a version number to lock into, and I'd rather not include the branch under development. Would you mind tagging a beta release? Or is it close to coming out of beta?

Resources do not load with custom WP_CONTENT_DIR & WP_CONTENT_URL

First of all thanks for your time and your effort creating this awesome framework.

I had installed Wordpress with yeoman wordpress generator. The wordpress installtion folder is different from the content folder.

Wordpress version : 4.0
CMB2 version : 2.0.0-beta
Localhost enviroment : Windows 7 SP1, XAMPP 3.2.1

wp-config.php

if (!defined('WP_SITEURL')) {
define('WP_SITEURL', 'http://' . $_SERVER['SERVER_NAME'] . '/ai/cms');
}
if (!defined('WP_HOME')) {
define('WP_HOME', 'http://' . $_SERVER['SERVER_NAME'] . '/ai');
}
if (!defined('WP_CONTENT_DIR')) {
define('WP_CONTENT_DIR', dirname(FILE) . '/content/');
}
if (!defined('WP_CONTENT_URL')) {
define('WP_CONTENT_URL', 'http://' . $_SERVER['SERVER_NAME'] . '/ai/content');
}

I tried to add a metabox and the resources do not load. Specifically the cmb2.min.css, jquery.timePicker.min.js, cmb2.min.js. I get a 404 error.

The problem occurs on the resources path. A trailing slash is missing at the end of the WP_CONTENT_URL.

It is http://localhost/ai/contentthemes/ai/inc/admin/cmb2/css/cmb2.min.css?ver=4.0 and should be http://localhost/ai/content/themes/ai/inc/admin/cmb2/css/cmb2.min.css?ver=4.0

If I add at the end of WP_CONTENT_URL a trailing slash is working but all permalinks have two trailing slashes.

Thanks in advance.

Add support for Required fields

Having the ability to require specific fields (JS tweaks needed too) would be great, stopping submit from happening and highlighting the fields in question. Adding support for a JS trigger / PHP to hook in for custom validation would be great at the same time as part of #62

If empty metadata

Hello,

Thanks for the great plugin. I'm here with a little problem.
If empty metadata how to hide video tag ?

Display the meta data:

http://pastebin.com/yp97aFYh

2014-09-04_105210

Bug with repeating fields and custom field types

There seems to be a bug with the repeating fields using a custom field type. In this case it's a post field type that displays posts from a few different post types. When the post is saved, it ignores the items that were deleted.

Here's a Gist of the mb setup and function:
https://gist.github.com/bearded-avenger/ff479f01bc1bbf24fbf1

Here's a quick screencast of what's going on.
http://cl.ly/151z2Y1y340E

CMB2 in our case is being used as a dedicated plugin that other plugins and theme tap into within our network. The custom filed is in the same php file that loads the init.php from CMB2. Just trying to provide as much context as I can here.

This works with a core field such as textfield_small. however when switched to this custom field type, the odd behavior above is experienced.

Allows required fields

What do you think about putting a parameter to allow required fields, or even the title of the posts and Wordpress itself.

Populate radio and checkbox inputs on repeated groups

Scenario: I have a repeatable group including some radio and checkbox inputs. For those, I have set some default values but when I click on Add Another Item, inside the cloned group those inputs don't contain default values.

Considerations: I see that in cmb2.js file groups are "repeated" through jQuery clone() method, in a few words jQuery clones the last group on the page. What's the best way to get those inputs automatically populated with default values?

Cheers,
P.

How to show contents in front end

Hey,
I have added this plugin as a library of my own plugin. How to show values/contents in front end? For example if I upload an image (repeatable group field), then how to show that image in front end?

Thanks

Change <ul> and <li> to <div>'s and add new fields hooks

I'd like to propose 2 changes that would work together.

I'm looking to add a before and after field hook that would be outside of the cmb-row. Because cmb-row's are currently li's it would make more sense if they were div's so the added content wouldn't screw up the list.

The hooks would most likely require a parameter of $field_id or something similar, so we can specify which field we are targeting.

This would make things much easier for a plugin i'm working on, and more versatile in general.

Are semantics the only reason for using li's? (mostly referring to non-repeater field items)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.