CMB2

Gitter
Travis
Scrutinizer Code Quality
Scrutinizer Coverage
Dockunit Status
Project Stats

CMB2

Contributors: webdevstudios, jtsternberg, gregrickaby, tw2113, patrickgarman, JPry
Donate link: http://webdevstudios.com

Tags: metaboxes, forms, fields, options, settings

Requires at least: 3.8.0

Tested up to: 4.4.2

Stable tag: 2.2.2.1

License: GPLv2 or later

License URI: http://www.gnu.org/licenses/gpl-2.0.html

Wordpress plugin
Wordpress
Wordpress rating

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

Description

CMB2 is a developer’s toolkit for building metaboxes, custom fields, and forms for WordPress that will blow your mind.

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.

Features:

Translation

3rd Party Resources

Custom Field Types

Other Helpful Resources

  • WordPress Shortcode Button: Uses CMB2 fields to generate fields for shortcode input modals.
  • WDS-Simple-Page-Builder: Uses existing template parts in the currently-active theme to build a customized page with rearrangeable elements. Built with CMB2.
  • CMB2 Example Theme: Demonstrate how to include CMB2 in your theme, as well as some cool tips and tricks.
  • facetwp-cmb2: FacetWP integration with CMB2.
  • CMB2-grid from origgami: A grid system for WordPress CMB2 library that allows the creation of columns for a better layout in the admin.
  • CMB2 Metatabs Options from rogerlos: CMO makes it easy to create options pages with multiple metaboxes–and optional WordPress admin tabs.
  • CMB2 Conditionals from jcchavezs: Allows developers to relate fields so the display of one is conditional on the value of another.
  • CMB2 Metabox Code Generator from willthemoor: Skip the boring bits. Use this generator to create fully functional CMB2 metaboxes easily. Now with bulk entry!

Contribution

All contributions welcome. If you would like to submit a pull request, please check out the trunk branch and pull request against it. Please read the CONTRIBUTING doc for more details.

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

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.

Most Recent Changes

2.2.2.1 - 2016-06-27

Bug Fixes

  • Fix issue that kept CMB2 stylesheet from being enqueued when using the options-page snippets.
  • Fix issue which caused the CMB2 column display styles to be enqueued in the wrong pages. Now only enqueues on admin pages with columns.

2.2.2 - 2016-06-27

Enhancements

  • You can now set admin post-listing columns with an extra field parameter, 'column' => true,. If you want to dictate what position the column is, use 'column' => array( 'position' => 2 ),. If you want to dictate the column title (instead of using the field 'name' value), use 'column' => array( 'name' => 'My Column' ),. If you need to specify the column display callback, set the 'display_cb' parameter to a callback function. Columns work for post (all post-types), comment, user, and term object types.
  • Updated Datepicker styles using JJJ’s jQuery UI Datepicker CSS for WordPress, so props Props @stuttter, @johnjamesjacoby. Also cleaned up the timepicker styles (specifically the buttons) to more closely align with the datepicker and WordPress styles.
  • CMB2 is now a lot more intelligent about where it is located in your installation. This update should solve almost all of the reasons to use the 'cmb2_meta_box_url' filter (thought it will continue to work as expected). (#27, #118, #432, related wiki item)
  • Implement CMB2_Ajax as a singleton. Props jrfnl (#602).
  • Add classes and classes_cb CMB2 box params which allows you to add additional classes to the cmb-wrap. The classes parameter can take a string or array, and the classes_cb takes a callback which returns a string or array. The callback will receive $cmb as an argument. These classes are also passed through a new filter, 'cmb2_wrap_classes', which receives the array of classes as the first argument, and the CMB2 object as the second. Reported/requested in #364.
  • Make the 'title' field type accept extra arguments. Props @vladolaru, @pixelgrade (#656).
  • Updated cmb2_get_oembed() function to NOT return the remove link, as it’s intended for outputting the oembed only. This is a backwards-compatibility concern. If you were depending on the remove link, use cmb2_ajax()->get_oembed( $args ) instead.
  • New function, cmb2_do_oembed()‘, which is hooked to 'cmb2_do_oembed', so you can use do_action( 'cmb2_do_oembed', $args ) in your themes without function_exists() checks.
  • New method, CMB2:set_prop( $property, $value ), for setting a CMB2 metabox object property.
  • The CMB2_Field object instances will now have a cmb_id property and a get_cmb method to enable access to the field’s CMB2 parent object’s instance, in places like field callbacks and filters (e.g. $cmb = $field->get_cmb();).
  • Add a data-fieldtype attribute to the field rows for simpler identification in Javascript.
  • Moved each type in CMB2_Types to it’s own class so that each field type can handle it’s own field display, and added the infrastructure to maintainn back-compatibility.
  • New CMB2_Utils methods, notempty() and filter_empty(), both of which consider null, '' and false as empty, but allow 0 (for saving 0 as a field value).
  • New CMB2_Utils public methods, get_url_from_dir(), get_file_ext(), get_file_name_from_path(), and wp_at_least().
  • Add a cmb_pre_init Javascript event to allow overriding CMB2 defaults via JS.

Bug Fixes

  • Fix issue with 'default’ callback not being applied in all instances. Introduced new CMB2_Field::get_default() method, and 'default_cb' field parameter. Using the 'default' field parameter with a callback will be deprecated in the next few releases. (#572).
  • Be sure to call CMB2_Field::row_classes() for group field rows. Also, update CSS to use the cmb-type-group classname instead of cmb-repeat-group-wrap.
  • Introduce new 'text' and 'text_cb' field parameters for overriding CMB2 text strings instead of using the 'options' array. (#630)
  • Fix bug where the value of ‘0’ could not be saved in group fields.
  • Fix bug where a serialized empty array value in the database for a repeatable field would output as Array.
  • Allow for optional/empty money field. Props @jrfnl (#577).
  • The CMB2::$updated parameter (which contains field ids for all fields updated during a save) now also correctly adds group field ids to the array.

Known Issues

  • The CMB2 url (for css/js resources) does not define properly in all WAMP/XAMP (Windows) environments.
  • Metabox containing WYSIWYG editor cannot be moved or used in a repeatable way at this time (this is a TinyMCE issue).
  • Not all fields work well in a repeatable group.