cmb2 as a framework, SCSS + Autoprefixer

This commit is contained in:
Alexander Yakovlev 2017-06-15 18:30:23 +07:00
parent 1e4374736e
commit 6ea1324e1f
335 changed files with 86882 additions and 196 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.sass-cache
style.css
style.css.map
node_modules

27
Gulpfile.js Normal file
View File

@ -0,0 +1,27 @@
var gulp = require('gulp');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var input = './stylesheets/**/*.scss';
var output = './public/css';
var sassOptions = {
errLogToConsole: true,
outputStyle: 'expanded'
};
var autoprefixerOptions = {
browsers: ['last 2 versions', '> 5%', 'Firefox ESR']
};
gulp.task('sass', function () {
return gulp
// Find all `.scss` files from the `stylesheets/` folder
.src(input)
.pipe(sourcemaps.init())
// Run Sass on those files
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(sourcemaps.write())
.pipe(autoprefixer())
// Write the resulting CSS in the output folder
.pipe(gulp.dest(output));
});

565
cmb2/CHANGELOG.md Normal file
View File

@ -0,0 +1,565 @@
# Changelog
All notable changes to this project will be documented in this file.
## [Unreleased][unreleased]
## 2.2.4 - 2017-02-27
### Enhancements
* Modify `'taxonomy_*'` fields to return stored terms for non-post objects.
* Modify `CMB2::get_sanitized_values()` to return the sanitized `'taxonomy_*'` field values. Also added `"cmb2_return_taxonomy_values_{$cmb_id}"` filter to modify if `'taxonomy_*'` field values are returned. Fixes [#538](https://github.com/WebDevStudios/CMB2/issues/538).
* Allow outputting CMB2 boxes/fields in additional locations in the post-editor.
**The new locations are:** [`form_top`](https://developer.wordpress.org/reference/hooks/edit_form_top/), [`before_permalink`](https://developer.wordpress.org/reference/hooks/edit_form_before_permalink/), [`after_title`](https://developer.wordpress.org/reference/hooks/edit_form_after_title/), and [`after_editor`](https://developer.wordpress.org/reference/hooks/edit_form_after_editor/)
These would be defined by setting the `context` property for your box:
```php
$cmb_demo = new_cmb2_box( array(
...
'context' => 'before_permalink',
) );
```
If it is preferred that the fields are output without the metabox, then omit the `'title'` property from the metabox registration array, and instead add ` 'remove_box_wrap' => true,`.
Props [@norcross](https://github.com/norcross) ([#836](https://github.com/WebDevStudios/CMB2/pull/836)).
* New field parameter, `'render_class'`, allowing you to override the default `'CMB2_Type_Base'` class that is used when rendering the field. This provides interesting object-oriented ways to override default CMB2 behavior by subclassing the default class and overriding methods. The render class can also be overridden with the `"cmb2_render_class_{$fieldtype}"` filter, which is passed the default render class name as well as the `CMB2_Types` object, but this should be used sparingly, and within the context of your project's boxes/fields or you could break other plugins'/themes' CMB2 fields.
* Improvements to the `file`/`file_list` fields javascript APIs, including using undersore templates.
* Small improvements to the styling for the `file_list` field type.
* New action hook, `cmb2_footer_enqueue`, which occurs after CMB2 enqueues its assets.
* Example functions clean up. Props [@PavelK27](https://github.com/PavelK27) ([#866](https://github.com/WebDevStudios/CMB2/pull/866)).
* New `CMB2_Utils` methods, `get_available_image_sizes()` and `get_named_size()`. Props [@Cai333](https://github.com/Cai333).
### Bug Fixes
* Fix datepicker month/year dropdown text color. On windows, the option text was showing as white (invisible). Fixes [#770](https://github.com/WebDevStudios/CMB2/issues/770).
* Repeatable WYSIWYG no longer breaks if `'quicktags'` param is set to false. Props [@timburden](https://github.com/timburden) ([#797](https://github.com/WebDevStudios/CMB2/pull/797), [#796](https://github.com/WebDevStudios/CMB2/issues/796)).
* Do not process title fields during group field save process.
* Fix issue where term-meta values were not being displayed for some users. Props [@sbussetti](https://github.com/sbussetti) ([#763](https://github.com/WebDevStudios/CMB2/pull/763), [#700](https://github.com/WebDevStudios/CMB2/issues/700)).
* Fix issue where term meta would not be applied when using the new term form if multiple object types were specified. Props [@ADC07](https://github.com/ADC07) ([#842](https://github.com/WebDevStudios/CMB2/pull/842), [#841](https://github.com/WebDevStudios/CMB2/issues/841)).
* Fix WordPress spinner styling when boxes/fields used on the frontend.
* Fix issue where clicking to remove a `file_list` item could occasionally remove the field row. ([#828](https://github.com/WebDevStudios/CMB2/pull/828)).
* Fix issue where empty file field in group would still cause non-empty values to store to database. ([#721](https://github.com/WebDevStudios/CMB2/issues/721)).
* Make `file`/`file_list` field preview images work with named sizes. Props [@Cai333](https://github.com/Cai333) ([#848](https://github.com/WebDevStudios/CMB2/pull/848), [#844](https://github.com/WebDevStudios/CMB2/issues/844)).
* Fix incorrect text-domain. ([#798](https://github.com/WebDevStudios/CMB2/issues/798))
* Do not silence notices/errors in `CMB2_Utils::get_file_ext()`.
* If `title` field type has no name value, then only output a span element (instead of a header element).
## 2.2.3.1 - 2016-11-08
### Enhancements
* Better styling for disabled group "X" buttons, and add title attr. Fixes [#773](https://github.com/WebDevStudios/CMB2/issues/773).
### Bug Fixes
* Use quotes for `label[for=""]` selector. Fixed `Syntax error, unrecognized expression`. Props [@anhskohbo](https://github.com/anhskohbo) ([#789](https://github.com/WebDevStudios/CMB2/pull/789)).
* Fix `ReferenceError: tinyMCE is not defined` javascript errors (happening when trying to remove a repeatable field/group). Fixes [#790](https://github.com/WebDevStudios/CMB2/issues/790), and [#730](https://github.com/WebDevStudios/CMB2/issues/730).
* Fix REST API `'show_in_rest'` examples in `example-functions.php`. Any REST API boxes/fields must use the `'cmb2_init'` hook (as opposed to the `'cmb2_admin_init'` hook).
## 2.2.3 - 2016-10-25
### Enhancements
* CMB2 REST API! CMB2 now has WP REST API endpoints for displaying your boxes and fields data, as well as registers rest fields in the existing post, user, term, and comment endpoints (in the cmb2 namespace). Enabling the REST API for your boxes/fields is opt-in, meaning it will not be automatically enabled. For more info, [check out the wiki](https://github.com/WebDevStudios/CMB2/wiki/REST-API).
* Small string improvement, move a period inside the translatable string. Props [@pedro-mendonca](https://github.com/pedro-mendonca) ([#672](https://github.com/WebDevStudios/CMB2/pull/672)).
* Introduce the `'save_field'` boolean field parameter for disabling the saving of a field. Useful if you want to display the value of another field, or use a disabled/read-only field. Props [@jamesgol](https://github.com/jamesgol) ([#674](https://github.com/WebDevStudios/CMB2/pull/674), [#346](https://github.com/WebDevStudios/CMB2/issues/346), [#500](https://github.com/WebDevStudios/CMB2/issues/500)).
* Update docblocks for `CMB2_Field::save_field_from_data()` and `CMB2_Field::save_field()`. Props [@jamesgol](https://github.com/jamesgol) ([#675](https://github.com/WebDevStudios/CMB2/pull/675)).
* More javascript events tied to the media modal actions (related to the `'file'` and '`file_list'` fields). `'cmb_media_modal_init'`, `'cmb_media_modal_open'`, and `'cmb_media_modal_select'`.
* All CMB2 JS events now also get the CMB2 JS object passed in the list of arguments.
* CMB2 JS object is now instantiated without stomping existing object, to enable extending.
* New field parameter for taxonomy fields, `'remove_default'` which allows disabling the default taxonomy metabox. Props [@c3mdigital](https://github.com/c3mdigital) ([#593](https://github.com/WebDevStudios/CMB2/pull/593)).
* Change `'row_classes'` to just `'classes'`, to mirror the metabox `'classes'` property. Also now accepts a `'classes_cb'` parameter for specifying a callback which returns a string or array. The callback will receive `$field_args` as the first argument, and the CMB2_Field `$field` object as the second argument. (`'row_classes'` will continue to work, but is deprecated)
* Make wysiwyg editors work in the repeatable groups context. A standard repeatable (non-group) wysiwyg field is not supported (but will possibly be included in a future update). Props [@johnsonpaul1014](https://github.com/johnsonpaul1014) ([#26](https://github.com/WebDevStudios/CMB2/pull/26), [#99](https://github.com/WebDevStudios/CMB2/pull/99), [#260](https://github.com/WebDevStudios/CMB2/pull/260), [#264](https://github.com/WebDevStudios/CMB2/pull/264), [#356](https://github.com/WebDevStudios/CMB2/pull/356), [#431](https://github.com/WebDevStudios/CMB2/pull/431), [#462](https://github.com/WebDevStudios/CMB2/pull/462), [#657](https://github.com/WebDevStudios/CMB2/pull/657), [#693](https://github.com/WebDevStudios/CMB2/pull/693)).
* Add an id to the heading tag in the title field. This allows linking to a particular title using the id.
* Internationalization improvements. Props [ramiy](https://github.com/ramiy) ([#696](https://github.com/WebDevStudios/CMB2/pull/696)).
* Ensure that saving does not happen during a switch-to-blog session, as data would be saved to the wrong object. [See more](https://wordpress.org/support/topic/bug-in-lastest-version?replies=2).
* Add `'cmb2_group_wrap_attributes'` filter to modifying the group wrap div's attributes. Filter gets passed an array of attributes and expects the return to be an array. Props [jrfnl](https://github.com/jrfnl) ([#582](https://github.com/WebDevStudios/CMB2/pull/582)).
* Update the unit-tests README and inline docs. Props [bobbingwide](https://github.com/bobbingwide) ([#714](https://github.com/WebDevStudios/CMB2/pull/714), [#715](https://github.com/WebDevStudios/CMB2/pull/715)).
* Minor update to make naming-conventions consistent. Props [ramiy](https://github.com/ramiy) ([#718](https://github.com/WebDevStudios/CMB2/pull/718)).
* Update files to be compatible with PHP7 CodeSniffer standards. Props [ryanshoover](https://github.com/ryanshoover) ([#719](https://github.com/WebDevStudios/CMB2/pull/719), [#720](https://github.com/WebDevStudios/CMB2/pull/720)).
* Make exception message translatable. Props [ramiy](https://github.com/ramiy) ([#724](https://github.com/WebDevStudios/CMB2/pull/724)).
* Portuguese translation provided by [@alvarogois](https://github.com/alvarogois) and [@pedro-mendonca](https://github.com/pedro-mendonca) - [#709](https://github.com/WebDevStudios/CMB2/pull/709), [#727](https://github.com/WebDevStudios/CMB2/pull/727).
* Stop using `$wp_version` global. Props [ramiy](https://github.com/ramiy) ([#731](https://github.com/WebDevStudios/CMB2/pull/731)).
* Closures (anonymous functions) are now supported for any box/field `'*_cb'` parameters. E.g.
```php
...
'show_on_cb' => function( $cmb ) { return has_tag( 'cats', $cmb->object_id ); },
...
```
### Bug Fixes
* If custom field types use a method and the Type object has not been instantiated, Try to guess the Type object and instantiate.
* Normalize WordPress root path (`ABSPATH`) and theme rooth path (`get_theme_root()`). Props [@rianbotha](https://github.com/rianbotha) ([#677](https://github.com/WebDevStudios/CMB2/pull/677), [#676](https://github.com/WebDevStudios/CMB2/pull/676)).
* Fix issue with `'cmb2_remove_row'` Javascript callback for non-group row removal. Fixes [#729](https://github.com/WebDevStudios/CMB2/pull/729)).
* Fix issue with missing assignment of variable (undefined variable). Props [@anhskohbo](https://github.com/anhskohbo) ([#779](https://github.com/WebDevStudios/CMB2/pull/779)).
## 2.2.2.1 - 2016-06-27
### Bug Fixes
* Fix issue that kept CMB2 stylesheet from being enqueued when using the [options-page snippets](https://github.com/WebDevStudios/CMB2-Snippet-Library/tree/master/options-and-settings-pages).
* 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](https://github.com/WebDevStudios/CMB2/wiki/Field-Parameters#render_row_cb). 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](https://github.com/stuttter), [@johnjamesjacoby](https://github.com/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](https://github.com/WebDevStudios/CMB2/issues/27), [#118](https://github.com/WebDevStudios/CMB2/issues/118), [#432](https://github.com/WebDevStudios/CMB2/issues/432), [related wiki item](https://github.com/WebDevStudios/CMB2/wiki/Troubleshooting#cmb2-urls-issues))
* Implement CMB2_Ajax as a singleton. Props [jrfnl](https://github.com/jrfnl) ([#602](https://github.com/WebDevStudios/CMB2/pull/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](https://github.com/WebDevStudios/CMB2/issues/364#issuecomment-213223692).
* Make the `'title'` field type accept extra arguments. Props [@vladolaru](https://github.com/vladolaru), [@pixelgrade](https://github.com/pixelgrade) ([#656](https://github.com/WebDevStudios/CMB2/pull/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](https://github.com/WebDevStudios/CMB2/issues/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](https://github.com/WebDevStudios/CMB2/pull/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](https://github.com/jrfnl) ([#577](https://github.com/WebDevStudios/CMB2/pull/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.
## 2.2.1 - 2016-02-29
### Bug Fixes
* Fixes back-compatibility issue which could allow multiple CMB2 instances to load (causing fatal errors). ([#520](https://github.com/WebDevStudios/CMB2/pull/520))
## 2.2.0 - 2016-02-27
### Enhancements
* Term Meta! As of WordPress 4.4, [WordPress will have the ability to use term metadata](https://make.wordpress.org/core/2015/10/23/4-4-taxonomy-roundup/). CMB2 will work with term meta out of the box. To do so, see the example cmb registration in the `yourprefix_register_taxonomy_metabox` function in [example-functions.php](https://github.com/WebDevStudios/CMB2/blob/master/example-functions.php).
* New hooks which hook in after save field action: `'cmb2_save_field'` and `"cmb2_save_field_{$field_id}"`. Props [wpsmith](https://github.com/wpsmith) ([#475](https://github.com/WebDevStudios/CMB2/pull/475)).
* The "cmb2_sanitize_{$field_type}" hook now runs for every field type (not just custom types) so you can override the sanitization for all field types via a filter.
* `CMB2::show_form()` is now composed of 3 smaller methods, `CMB2::render_form_open()`, `CMB2::render_field()`, `CMB2::render_form_close()` ([#506](https://github.com/WebDevStudios/CMB2/pull/506)).
* RTL Style generated. Props [@devinsays](https://github.com/devinsays) ([#510](https://github.com/WebDevStudios/CMB2/pull/510)).
* Properly scope date/time-pickers styling by adding a class to only cmb2 picker instances. ([#527](https://github.com/WebDevStudios/CMB2/pull/527))
* Allow per-field overrides for the date/time/color picker options (wiki documentation: [Modify Field Date, Time, or Color Picker options](https://github.com/WebDevStudios/CMB2/wiki/Tips-&-Tricks#modify-field-date-time-or-color-picker-options))
* Fix some inline documentation issues. Props [@jrfnl](https://github.com/jrfnl) ([#579](https://github.com/WebDevStudios/CMB2/pull/579)).
* Include `.gitattributes` file for excluding development resources when using Composer. Props [@benoitchantre](https://github.com/benoitchantre) ([#575](https://github.com/WebDevStudios/CMB2/pull/575), [#53](https://github.com/WebDevStudios/CMB2/pull/53)).
### Bug Fixes
* Fixed issue with `'taxonomy_select'` field type where a term which evaluated falsey would not be displayed properly. Props [adamcapriola](https://github.com/adamcapriola) ([#477](https://github.com/WebDevStudios/CMB2/pull/477)).
* Fix issue with colorpickers not changing when sorting groups.
* `'show_option_none'` field parameter now works on taxonomy fields when explicitly setting to false.
* Fix so the date/time-picker javascript respects the `'date_format'` and `'time_format'` field parameters. Props [@yivi](https://github.com/yivi) ([#39](https://github.com/WebDevStudios/CMB2/pull/39), [#282](https://github.com/WebDevStudios/CMB2/pull/282), [#300](https://github.com/WebDevStudios/CMB2/pull/300), [#318](https://github.com/WebDevStudios/CMB2/pull/318), [#330](https://github.com/WebDevStudios/CMB2/pull/330), [#446](https://github.com/WebDevStudios/CMB2/pull/446), [#498](https://github.com/WebDevStudios/CMB2/pull/498)).
* Fix a sometimes-broken unit test. Props [JPry](https://github.com/JPry) ([#539](https://github.com/WebDevStudios/CMB2/pull/539)).
* Fix issue with oembed fields not working correctly on options pages. ([#542](https://github.com/WebDevStudios/CMB2/pull/542)).
* Fix issue with repeatable field <button> elements stealing focus from "submit" button.
## 2.1.2 - 2015-10-01
### Bug Fixes
* Fixes back-compatibility issue when adding fields array to the metabox registration. ([#472](https://github.com/WebDevStudios/CMB2/pull/472))
## 2.1.1 - 2015-09-30
### Enhancements
* Make all CMB2::save_fields arguments optional to fall-back to `$_POST` data. Props [JPry](https://github.com/JPry).
* New filter, `cmb2_non_repeatable_fields` for adding additional fields to the blacklist of repeatable field-types. Props [JPry](https://github.com/JPry) ([#430](https://github.com/WebDevStudios/CMB2/pull/430)).
* New recommended hook for adding metaboxes, `cmb2_admin_init`. Most metabox registration only needs to happen if in wp-admin, so there is no reason to register them when loading the front-end (and increase the memory usage). `cmb2_init` still exists to register metaboxes that will be used on the front-end or used on both the front and back-end. Instances of `cmb2_init` in example-functions.php have been switched to `cmb2_admin_init`.
* Add `'render_row_cb'` field parameter for overriding the field render method.
* Add `'label_cb'` field parameter for overriding the field label render method.
* Allow `CMB2_Types::checkbox()` method to be more flexible for extending by taking an args array and an `$is_checked` second argument.
* More thorough unit tests. Props [pglewis](https://github.com/pglewis), ([#447](https://github.com/WebDevStudios/CMB2/pull/447),[#448](https://github.com/WebDevStudios/CMB2/pull/448)).
* Update `CMB2_Utils::image_id_from_url` to be more reliable. Props [wpscholar](https://github.com/wpscholar), ([#453](https://github.com/WebDevStudios/CMB2/pull/453)).
* `cmb2_get_option` now takes a default fallback value as a third parameter.
### Bug Fixes
* Address issue where `'file'` and `'file_list'` field results were getting mixed. Props [augustuswm](https://github.com/augustuswm) ([#382](https://github.com/WebDevStudios/CMB2/pull/382), [#250](https://github.com/WebDevStudios/CMB2/pull/250), [#296](https://github.com/WebDevStudios/CMB2/pull/296)).
* Fix long-standing issues with radio and multicheck fields in repeatable groups losing their values when new rows are added. ([#341](https://github.com/WebDevStudios/CMB2/pull/341), [#304](https://github.com/WebDevStudios/CMB2/pull/304), [#263](https://github.com/WebDevStudios/CMB2/pull/263), [#246](https://github.com/WebDevStudios/CMB2/pull/246), [#150](https://github.com/WebDevStudios/CMB2/pull/150))
* Fixes issue where currently logged-in user's profile data would display in the "Add New User" screen fields. ([#427](https://github.com/WebDevStudios/CMB2/pull/427))
* Fixes issue where radio values/selections would not always properly transfer when shifting rows (up/down). Props [jamiechong](https://github.com/jamiechong) ([#429](https://github.com/WebDevStudios/CMB2/pull/429), [#152](https://github.com/WebDevStudios/CMB2/pull/152)).
* Fixes issue where repeatable groups display "Array" as the field values if group is left completely empty. ([#332](https://github.com/WebDevStudios/CMB2/pull/332),[#390](https://github.com/WebDevStudios/CMB2/pull/390)).
* Fixes issue with `'file_list'` fields not saving properly when in repeatable groups display. Props [jamiechong](https://github.com/jamiechong) ([#433](https://github.com/WebDevStudios/CMB2/pull/433),[#187](https://github.com/WebDevStudios/CMB2/pull/187)).
* Update `'taxonomy_radio_inline'` and `'taxonomy_multicheck_inline'` fields sanitization method to use the same method as the non-inline versions. Props [superfreund](https://github.com/superfreund) ([#454](https://github.com/WebDevStudios/CMB2/pull/454)).
## 2.1.0 - 2015-08-05
### Bug Fixes
* Fix user fields not saving. Props [achavez](https://github.com/achavez), ([#417](https://github.com/WebDevStudios/CMB2/pull/417)).
## 2.0.9 - 2015-07-28
### Enhancements
* Updated/Added many translations. Props [fxbenard](https://github.com/fxbenard), ([#203](https://github.com/WebDevStudios/CMB2/pull/344)) and [Mte90](https://github.com/Mte90) for the Italian translation.
* Updated `'file_list'` field type to have a more intuitive selection in the media library, and updated the 'Use file' text in the button. Props [SteveHoneyNZ](https://github.com/SteveHoneyNZ) ([#357](https://github.com/WebDevStudios/CMB2/pull/357), [#358](https://github.com/WebDevStudios/CMB2/pull/358)).
* `'closed'` group field option parameter introduced in order to set the groups as collapsed by default. Requested in [#391](https://github.com/WebDevStudios/CMB2/issues/391).
* Added `"cmb2_{$object_type}_process_fields_{$cmb_id}"` hook for hooking in and modifying the metabox or fields before the fields are processed/sanitized for saving.
* Added Comment Metabox support. Props [GregLancaster71](https://github.com/GregLancaster71) ([#238](https://github.com/WebDevStudios/CMB2/pull/238), [#244](https://github.com/WebDevStudios/CMB2/pull/244)).
* New `"cmb2_{$field_id}_is_valid_img_ext"`` filter for determining if a field value has a valid image file-type extension.
### Bug Fixes
* `'multicheck_inline'`, `'taxonomy_radio_inline'`, and `'taxonomy_multicheck_inline'` field types were not outputting anything since it's value was not being returned. Props [ediamin](https://github.com/ediamin), ([#367](https://github.com/WebDevStudios/CMB2/pull/367), ([#405](https://github.com/WebDevStudios/CMB2/pull/405)).
* `'hidden'` type fields were not honoring the `'show_on_cb'` callback. Props [JPry](https://github.com/JPry), ([commits](https://github.com/WebDevStudios/CMB2/compare/5a4146eec546089fbe1a1c859d680dfda3a86ee2...1ef5ef1e3b2260ab381090c4abe9dc7234cfa0a6)).
* Fixed: There was no minified cmb2-front.min.css file.
* Fallback for fatal error with invalid timezone. Props [ryanduff](https://github.com/ryanduff) ([#385](https://github.com/WebDevStudios/CMB2/pull/385)).
* Fix issues with deleting a row from repeatable group. Props [yuks](https://github.com/yuks) ([#387](https://github.com/WebDevStudios/CMB2/pull/387)).
* Ensure value passed to `strtotime` in `make_valid_time_stamp` is cast to a string. Props [vajrasar](https://github.com/vajrasar) ([#389](https://github.com/WebDevStudios/CMB2/pull/389)).
* Fixed issue with Windows IIS and bundling CMB2 in the theme. Props [DevinWalker](https://github.com/DevinWalker), ([#400](https://github.com/WebDevStudios/CMB2/pull/400), [#401](https://github.com/WebDevStudios/CMB2/pull/401))
## 2.0.8 - 2015-06-01
### Bug Fixes
* Fix color-picker field not enqueueing the colorpicker script. ([#333](https://github.com/WebDevStudios/CMB2/issues/333))
## 2.0.7 - 2015-05-28
### Enhancements
* Ability to use non-repeatable group fields by setting the `'repeatable'` field param to `false` when registering a group field type. Props [marcusbattle](https://github.com/marcusbattle), ([#159](https://github.com/WebDevStudios/CMB2/pull/159)).
* Add and enqeueue a front-end specific CSS file which adds additional styles which are typically covered by wp-admin css. ([#311](https://github.com/WebDevStudios/CMB2/issues/311))
* Better handling of the CMB2 javascript (and CSS) required dependencies array. Dependencies are now only added conditionally based on the field types that are actually visible. ([#136](https://github.com/WebDevStudios/CMB2/issues/136))
* **THIS IS A BREAKING CHANGE:** The `group` field type's `'show_on_cb'` parameter now receives the `CMB2_Field` object instance as an argument instead of the `CMB2` instance. If you're using the `'show_on_cb'` parameter for a `group` field, please adjust accordingly. _note: you can still retrieve the `CMB2` instance via the `cmb2_get_metabox` helper function._
* New dynamic hook, `"cmb2_save_{$object_type}_fields_{$this->cmb_id}"`, to complement the existing `"cmb2_save_{$object_type}_fields"` hook.
* New CMB2 parameter, `enqueue_js`, to disable the enqueueing of the CMB2 Javascript.
* German translation provided by Friedhelm Jost.
### Bug Fixes
* Fix incorrect repeatable group title number. ([#310](https://github.com/WebDevStudios/CMB2/pull/310))
* Fix obscure bug which prevented group field arguments from being passed to the sub-fields (like `show_names` and `context`).
* Fixed occasional issue when adding a group row, the previous row's content would be cloned. ([#257](https://github.com/WebDevStudios/CMB2/pull/257))
## 2.0.6 - 2015-04-30
### Enhancements
* New metabox/form parameter, `show_on_cb`, allows you to conditionally display a cmb metabox/form via a callback. The `$cmb` object gets passed as a parameter to the callback. This complements the `'show_on_cb'` parameter that already exists for individual fields. Using this callback is similar to using the `'cmb2_show_on'` filter, but only applies to that specific metabox and it is recommended to use this callback instead as it minimizes th risk that your filter will affect other metaboxes.
* Taxonomy types no longer save a value. The value getting saved was causing confusion and is not meant to be used. To use the saved taxonomy data, you need to use the WordPress term api, `get_the_terms `, `get_the_term_list`, etc.
* Add `'multiple'` field parameter to store values in individual rows instead of serialized array. Will only work if field is not repeatable or a repeatable group. Props [JohnyGoerend](https://github.com/JohnyGoerend). ([#262](https://github.com/WebDevStudios/CMB2/pull/262), [#206](https://github.com/WebDevStudios/CMB2/issues/206), [#45](https://github.com/WebDevStudios/CMB2/issues/45)).
* Portuguese (Brazil) translation provided by [@lucascdsilva](https://github.com/lucascdsilva) - [#293](https://github.com/WebDevStudios/CMB2/pull/293).
* Spanish (Spain) translation updated by [@yivi](https://github.com/yivi) - [#272](https://github.com/WebDevStudios/CMB2/pull/272).
* Added group field callback parameters, `'before_group'`, `'before_group_row'`, `'after_group_row'`, `'after_group'` to complement the `'before_row'`, `'before'`, `'after'`, `'after_row'` field parameters.
* Better styling for `title` fields and `title` descriptions on options pages.
* Add a `sanitization_cb` field parameter check for the `group` field type.
* Better function/file doc-blocks to provide better documentation for automated documentation tools. See: [cmb2.io/api](http://cmb2.io/api/).
* `cmb2_print_metabox_form`, `cmb2_metabox_form`, and `cmb2_get_metabox_form` helper functions now accept two new parameters:
* an `'object_type'` parameter to explictly set that in the `$cmb` object.
* an `'enqueue_js'` parameter to explicitly disable the CMB JS enqueue. This is handy if you're not planning on using any of the fields which require JS (like color/date pickers, wysiwyg, file, etc).
### Bug Fixes
* Fix issue with oembed fields in repeatable groups where changing video changed it for all fields in a group.
* Fix empty arrays (like in the group field) saving as a value.
* Move `'cmb2_override_meta_value'` and `"cmb2_override_{$field_id}_meta_value"` filters to the `CMB2_Field::get_data()` method so that the filters are applied every time the data is requested. **THIS IS A BREAKING CHANGE:** The parameters for those filters have changed a bit. Previously, the filters accepted 5 arguments, `$value`, `$object_id`, `$field_args`, `$object_type`, `$field`. They have changed to accept 4 arguments instead, `$value`, `$object_id`, `$args`, `$field`, where `$args` is an array that contains the following:
* @type string $type The current object type
* @type int $id The current object ID
* @type string $field_id The ID of the field being requested
* @type bool $repeat Whether current field is repeatable
* @type bool $single Whether current field is a single database row
## 2.0.5 - 2015-03-17
### Bug Fixes
* Fix grouped fields display (first field was being repeated), broken in 2.0.3.
## 2.0.4 - 2015-03-16
### Enhancements
* `select`, `radio`, `radio_inline` field types now all accept the `'show_option_none'` field parameter. This parameter allows you to set the text to display for showing a 'no selection' option. Default will be `false`, which means a 'none' option will not be added. Set to `true` to use the default text, 'None', or specify another value, i.e. 'No selection'.
### Bug Fixes
* Fix back-compatibility when adding group field sub-fields via old array method (vs using the `CMB2:add_group_field()` method). Thanks to [norcross](https://github.com/norcross) for reporting.
* Fix occasional jQuery issues with group-field indexes.
## 2.0.3 - 2015-03-15
### Enhancements
* New constant, `CMB2_DIR`, which stores the file-path to the CMB2 directory.
* `text_date`, `text_time`, `text_date_timestamp`, `text_datetime_timestamp`, and ` text_datetime_timestamp_timezone` field types now take an arguments array so they can be extended by custom field types.
* Removed auto-scroll when adding groups. To re-add the feature, use the [snippet/plugin here](https://github.com/WebDevStudios/CMB2-Snippet-Library/blob/master/javascript/cmb2-auto-scroll-to-new-group.php). ([#205](https://github.com/WebDevStudios/CMB2/issues/205))
* Updated Timepicker utilizing the [@trentrichardson](https://github.com/trentrichardson) jQuery Timepicker add-on (https://github.com/trentrichardson/jQuery-Timepicker-Addon), and updated Datepicker styles. Props [JonMasterson](https://github.com/JonMasterson). ([#204](https://github.com/WebDevStudios/CMB2/issues/204), [#206](https://github.com/WebDevStudios/CMB2/issues/206), [#45](https://github.com/WebDevStudios/CMB2/issues/45)).
* Added a callback option for the field default value. The callback gets passed an array of all the field parameters as the first argument, and the field object as the second argument. (which means you can get the post id using `$field->object_id`). ([#233](https://github.com/WebDevStudios/CMB2/issues/233)).
* New `CMB2::get_field()` method and `cmb2_get_field` helper function for retrieving a `CMB2_Field` object from the array of registered fields for a metabox.
* New `CMB2::get_sanitized_values()` method and `cmb2_get_metabox_sanitized_values` helper function for retrieving sanitized values from an array of values (usually `$_POST` data).
* New `'save_fields'` metabox parameter that can be used to disable (by setting `'save_fields' => false`) the automatic saving of the fields when the form is submitted. These can be useful when you want to handle the saving of the fields yourself, or want to use submitted data for other purposes like generating new posts, or sending emails, etc.
### Bug Fixes
* Fix commented out text_datetime_timestamp_timezone field registration example in `example-functions.php`. Props [cliffordp](https://github.com/cliffordp), ([#203](https://github.com/WebDevStudios/CMB2/pull/203)).
* Fix sidebar styling for money fields and fields with textareas. ([#234](https://github.com/WebDevStudios/CMB2/issues/234))
* Fix `CMB2_Sanitize` class to properly use the stripslashed value (which was added in [#162](https://github.com/WebDevStudios/CMB2/pull/162) but never used). Props [dustyf](https://github.com/dustyf), ([#241](https://github.com/WebDevStudios/CMB2/pull/241)).
## 2.0.2 - 2015-02-15
### Enhancements
* Use the more appropriate `add_meta_boxes` hook for hooking in metaboxes to post-edit screen. Thanks [@inspiraaz](https://github.com/inspiraaz) for reporting. ([#161](https://github.com/WebDevStudios/CMB2/issues/161))
* Add a `row_classes` field param which allows you to add additional classes to the cmb-row wrap. This parameter can take a string, or array, or can take a callback that returns a string or array. The callback will receive `$field_args` as the first argument, and the CMB2_Field `$field` object as the second argument. Reported/requested in [#68](https://github.com/WebDevStudios/CMB2/issues/68).
* New constant, `CMB2_LOADED`, which you can use to check if CMB2 is loaded for your plugins/themes with CMB2 dependency.
* New hooks, [`cmb2_init_before_hookup` and `cmb2_after_init`](https://github.com/WebDevStudios/CMB2-Snippet-Library/blob/master/filters-and-actions).
* New API for adding metaboxes and fields, demonstrated in [`example-functions.php`](https://github.com/WebDevStudios/CMB2/blob/master/example-functions.php). In keeping with backwards-compatibility, the `cmb2_meta_boxes` filter method will still work, but is not recommended. New API includes `new_cmb2_box` helper function to generate a new metabox, and returns a `$cmb` object to add new fields (via the `CMB2::add_field()` and `CMB2::add_group_field()` methods).
* New CMB2 method, [`CMB2::remove_field()`](https://github.com/WebDevStudios/CMB2-Snippet-Library/blob/master/filters-and-actions/cmb2_init_%24cmb_id-remove-field.php).
* New CMB2_Boxes method, [`CMB2_Boxes::remove()`](https://github.com/WebDevStudios/CMB2-Snippet-Library/blob/master/filters-and-actions/cmb2_init_before_hookup-remove-cmb2-metabox.php).
* When clicking on a file/image in the `file`, or `file_list` type, the media modal will open with that image selected. Props [johnsonpaul1014](https://github.com/johnsonpaul1014), ([#120](https://github.com/WebDevStudios/CMB2/pull/120)).
## 2.0.1 - 2015-02-02
2.0.1 is the official version after beta, and includes all the changes from 2.0.0 (beta).
## 2.0.0(beta) - 2014-08-16
2.0.0 is the official version number for the transition to CMB2, and 2.0.1 is the official version after beta. It is a complete rewrite. Improvements and fixes are listed below. __Note: This release requires WordPress 3.8+__
### Enhancements
* Converted `<table>` markup to more generic `<div>` markup to be more extensible and allow easier styling.
* Much better handling and display of repeatable groups.
* Entirely translation-ready [with full translations](http://wp-translations.org/project/cmb2/) in Spanish, French (Props [@fredserva](https://github.com/fredserva) - [#127](https://github.com/WebDevStudios/CMB2/pull/127)), Finnish (Props [@onnimonni](https://github.com/onnimonni) - [#108](https://github.com/WebDevStudios/CMB2/pull/108)), Swedish (Props [@EyesX](https://github.com/EyesX) - [#141](https://github.com/WebDevStudios/CMB2/pull/141)), and English.
* Add cmb fields to new user page. Props [GioSensation](https://github.com/GioSensation), ([#645](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/pull/645)).
* Improved and additional [helper-functions](https://github.com/WebDevStudios/CMB2/blob/master/includes/helper-functions.php).
* Added new features and translation for datepicker. Props [kalicki](https://github.com/kalicki), ([#657](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/pull/657)).
* General code standards cleanup. Props [gregrickaby](https://github.com/gregrickaby), ([#17](https://github.com/WebDevStudios/CMB2/pull/17) & others).
* Use SASS for development. Props [gregrickaby](https://github.com/gregrickaby), ([#18](https://github.com/WebDevStudios/CMB2/pull/18)).
* New `hidden` field type.
* [Ability to override text strings in fields via field options parameter](https://github.com/WebDevStudios/CMB2/wiki/Tips-&-Tricks#override-text-strings-in-field).
* Added composer.json. Props [nlemoine](https://github.com/nlemoine), ([#19](https://github.com/WebDevStudios/CMB2/pull/19)).
* New field 'hooks' can take [static text/html](https://github.com/WebDevStudios/CMB2/wiki/Tips-&-Tricks#inject-static-content-in-a-field) or a [callback](https://github.com/WebDevStudios/CMB2/wiki/Tips-&-Tricks#inject-dynamic-content-in-a-field-via-a-callback).
* New `preview_size` parameter for `file` field type. Takes an array or named image size.
* Empty index.php file to all folders (for more security). Props [brunoramalho](https://github.com/brunoramalho), ([#41](https://github.com/WebDevStudios/CMB2/pull/41)).
* Clean up styling. Props [brunoramalho](https://github.com/brunoramalho), ([#43](https://github.com/WebDevStudios/CMB2/pull/43)) and [senicar](https://github.com/senicar).
* Collapsible field groups. Props [cluke009](https://github.com/cluke009), ([#59](https://github.com/WebDevStudios/CMB2/pull/59)).
* Allow for override of update/remove for CMB2_Field. Props [sc0ttkclark](https://github.com/sc0ttkclark), ([#65](https://github.com/WebDevStudios/CMB2/pull/65)).
* Use class button-disabled instead of disabled="disabled" for <a> buttons. Props [sc0ttkclark](https://github.com/sc0ttkclark), ([#66](https://github.com/WebDevStudios/CMB2/pull/66)).
* [New before/after dynamic form hooks](https://github.com/WebDevStudios/CMB2/wiki/Tips-&-Tricks#using-the-dynamic-beforeafter-form-hooks).
* Larger unit test coverage. Props to [@pmgarman](https://github.com/pmgarman) for assistance. ([#90](https://github.com/WebDevStudios/CMB2/pull/90) and [#91](https://github.com/WebDevStudios/CMB2/pull/91))
* Added helper function to update an option. Props [mAAdhaTTah](https://github.com/mAAdhaTTah), ([#110](https://github.com/WebDevStudios/CMB2/pull/110)).
* More JS hooks during repeat group shifting. Props [AlchemyUnited](https://github.com/AlchemyUnited), ([#125](https://github.com/WebDevStudios/CMB2/pull/125)).
* [New metabox config option for defaulting to closed](https://github.com/WebDevStudios/CMB2/wiki/Tips-&-Tricks#setting-a-metabox-to-closed-by-default).
* New hooks, [`cmb2_init`](https://github.com/WebDevStudios/CMB2/wiki/Tips-&-Tricks#using-cmb2-helper-functions-and-cmb2_init) and `cmb2_init_{$cmb_id}`.
### Bug Fixes
* New mechanism to ensure CMB2 only loads the most recent version of CMB2 in your system. This fixes the issue where another bundled version could conflict or take precendent over your up-to-date version.
* Fix issue with field labels being hidden. Props [mustardBees](https://github.com/mustardBees), ([#48](https://github.com/WebDevStudios/CMB2/pull/48)).
* Address issues with autoloading before autoloader is setup. Props [JPry](https://github.com/JPry), ([#56](https://github.com/WebDevStudios/CMB2/pull/56)).
* Fixed 'show_on_cb' for field groups. Props [marcusbattle](https://github.com/marcusbattle), ([#98](https://github.com/WebDevStudios/CMB2/pull/98)).
* Make get_object_terms work with and without object caching. Props [joshlevinson](https://github.com/joshlevinson), ([#105](https://github.com/WebDevStudios/CMB2/pull/105)).
* Don't use `__DIR__` in example-functions.php to ensure PHP 5.2 compatibility. Props [bryceadams](https://github.com/bryceadams), ([#129](https://github.com/WebDevStudios/CMB2/pull/129)).
* Added support for radio input swapping in repeatable fields. Props [DevinWalker](https://github.com/DevinWalker), ([#138](https://github.com/WebDevStudios/CMB2/pull/138), [#149](https://github.com/WebDevStudios/CMB2/pull/149)).
* Fix metabox form not being returned to caller. Props [akshayagarwal](https://github.com/akshayagarwal), ([#145](https://github.com/WebDevStudios/CMB2/pull/145)).
* Run stripslashes before saving data, since WordPress forces magic quotes. Props [clifgriffin](https://github.com/clifgriffin), ([#162](https://github.com/WebDevStudios/CMB2/pull/162)).
## 1.3.0 - (never released, merged into CMB2)
### Enhancements
* Localize Date, Time, and Color picker defaults so that they can be overridden via the `cmb_localized_data` filter. ([#528](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/issues/528))
* Change third parameter for 'cmb_metabox_form' to be an args array. Optional arguments include `echo`, `form_format`, and `save_button`.
* Add support for `show_option_none` argument for `taxonomy_select` and `taxonomy_radio` field types. Also adds the following filters: `cmb_all_or_nothing_types`, `cmb_taxonomy_select_default_value`, `cmb_taxonomy_select_{$this->_id()}_default_value`, `cmb_taxonomy_radio_{$this->_id()}_default_value`, `cmb_taxonomy_radio_default_value`. Props [@pmgarman](https://github.com/pmgarman), ([#569](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/pull/569)).
* Make the list items in the `file_list` field type drag & drop sortable. Props [twoelevenjay](https://github.com/twoelevenjay), ([#603](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/pull/603)).
### Bug Fixes
* Fixed typo in closing `</th>` tag. Props [@CivicImages](https://github.com/CivicImages). ([#616](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/issues/616))
## 1.2.0 - 2014-05-03
### Enhancements
* Add support for custom date/time formats. Props [@Scrent](https://github.com/Scrent). ([#506](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/pull/506))
* Simplify `wysiwyg` escaping and allow it to be overridden via the `escape_cb` parameter. ([#491](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/pull/491))
* Add a 'Select/Deselect all' button for the `multicheck` field type.
* Add title option for [repeatable groups](https://github.com/WebDevStudios/CMB2/wiki/Field-Types#group). Title field takes an optional replacement hash, "{#}" that will be replaced by the row number.
* New field parameter, `show_on_cb`, allows you to conditionally display a field via a callback. ([#47](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/issues/47))
* Unit testing (the beginning). Props [@brichards](https://github.com/brichards) and [@camdensegal](https://github.com/camdensegal).
### Bug Fixes
* Fixed issue where remove file button wouldn't clear the url field. ([#514](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/issues/514))
* `wysiwyg` fields now allow underscores. Fixes some wysiwyg display issues in WordPress 3.8. Props [@lswilson](https://github.com/lswilson). ([#491](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/issues/491))
* Nonce field should only be added once per page. ([#521](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/issues/521))
* Fix `in_array` issue when a post does not have any saved terms for a taxonomy multicheck. ([#527](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/issues/527))
* Fixed error: 'Uninitialized string offset: 0 in cmb_Meta_Box_field.php...`. Props [@DevinWalker](https://github.com/DevinWalker). ([#539](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/issues/539), [#549](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/issues/549)))
* Fix missing `file` field description. ([#543](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/issues/543), [#547](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/issues/547))
## 1.1.3 - 2014-04-07
### Bug Fixes
* Update `cmb_get_field_value` function as it was passing the parameters to `cmb_get_field` in the wrong order.
* Fix repeating fields not working correctly if meta key or prefix contained an integer. ([#503](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/issues/503))
## 1.1.2 - 2014-04-05
### Bug Fixes
* Fix issue with `cmb_Meta_Box_types.php` calling a missing method, `image_id_from_url`. ([#502](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/pull/502))
## 1.1.1 - 2014-04-03
### Bug Fixes
* Radio button values were not showing saved value. ([#500](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/issues/500))
## 1.1.0 - 2014-04-02
### Enhancements
* [Repeatable groups](https://github.com/WebDevStudios/CMB2/wiki/Field-Types#group)
* Support for more fields to be repeatable, including oEmbed field, and date, time, and color picker fields, etc.
* Codebase has been revamped to be more modular and object-oriented.
* New filter, `"cmb_{$element}_attributes" ` for modifying an element's attributes.
* Every field now supports an `attributes` parameter that takes an array of attributes. [Read more](https://github.com/WebDevStudios/CMB2/wiki/Field-Types#attributes).
* Removed `cmb_std_filter` in favor of `cmb_default_filter`. **THIS IS A BREAKING CHANGE**
* Better handling of labels in sidebar. They are now placed on top of the input rather than adjacent.
* Added i18n compatibility to text_money. props [@ArchCarrier](https://github.com/ArchCarrier), ([#485](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/pull/485))
* New helper functions: `cmb_get_field` and `cmb_get_field_value` for getting access to CMB's field object and/or value.
* New JavaScript events, `cmb_add_row` and `cmb_remove_row` for hooking in and manipulating the new row's data.
* New filter, `cmb_localized_data`, for modifiying localized data passed to the CMB JS.
### Bug Fixes
* Resolved occasional issue where only the first character of the label/value was diplayed. props [@mustardBees](https://github.com/mustardBees), ([#486](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/pull/486))
## 1.0.2 - 2014-03-03
### Enhancements
* Change the way the `'cmb_validate_{$field['type']}'` filter works.
It is now passed a null value vs saved value. If null is returned, default sanitization will follow. **THIS IS A BREAKING CHANGE**. If you're already using this filter, take note.
* All field types that take an option array have been simplified to take `key => value` pairs (vs `array( 'name' => 'value', 'value' => 'key', )`). This effects the 'select', 'radio', 'radio_inline' field types. The 'multicheck' field type was already using the `key => value` format. Backwards compatibility has been maintained for those using the older style.
* Added default value option for `taxonomy_select` field type. props [@darlantc](https://github.com/darlantc), ([#473](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/pull/473))
* Added `preview_size` parameter for `file_list` field type. props [@IgorCode](https://github.com/IgorCode), ([#471](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/pull/471))
* Updated `file_list` images to be displayed horizontally instead of vertically. props [@IgorCode](https://github.com/IgorCode), ([#467](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/pull/467))
* Use `get_the_terms` where possible since the data is cached.
### Bug Fixes
* Fixed wysiwyg escaping slashes. props [@gregrickaby](https://github.com/gregrickaby), ([#465](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/pull/465))
* Replaced `__DIR__`, as `dirname( __FILE__ )` is easier to maintain back-compatibility.
* Fixed missing table styling on new posts. props [@mustardBees](https://github.com/mustardBees), ([#438](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/pull/438))
* Fix undeclared JS variable. [@veelen](https://github.com/veelen), ([#451](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/pull/451))
* Fix `file_list` errors when removing all files and saving.
* Set correct `object_id` to be used later in `cmb_show_on` filter. [@lauravaq](https://github.com/lauravaq), ([#445](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/pull/445))
* Fix sanitization recursion memeory issues.
## 1.0.1 - 2014-01-24
### Enhancements
* Now works with option pages and site settings. ([view example in wiki](https://github.com/WebDevStudios/CMB2/wiki/Using-CMB-to-create-an-Admin-Theme-Options-Page))
* two filters to override the setting and getting of options, `cmb_override_option_get_$option_key` and `cmb_override_option_save_$option_key` respectively. Handy for using plugins like [WP Large Options](https://github.com/voceconnect/wp-large-options/) ([also here](http://vip.wordpress.com/plugins/wp-large-options/)).
* Improved styling on taxonomy (\*tease\*) and options pages and for new 3.8 admin UI.
* New sanitization class to sanitize data when saved.
* New callback field parameter, `sanitization_cb`, for performing your own sanitization.
* new `cmb_Meta_Box_types::esc()` method that handles escaping data for display.
* New callback field parameter, `escape_cb`, for performing your own data escaping, as well as a new filter, `'cmb_types_esc_'. $field['type']`.
### Bug Fixes
* Fixed wysiwyg editor button padding. props [@corvannoorloos](https://github.com/corvannoorloos), ([#391](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/pull/391))
* A few php < 5.3 errors were addressed.
* Fields with quotation marks no longer break the input/textarea fields.
* metaboxes for Attachment pages now save correctly. Thanks [@nciske](https://github.com/nciske) for reporting. ([#412](https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/issues/412))
* Occasionally fields wouldn't save because of the admin show_on filter.
* Smaller images loaded to the file field type will no longer be blown up larger than their dimensions.
## 1.0.0 - 2013-11-30
* Added `text_datetime_timestamp_timezone` type, a datetime combo field with an additional timezone drop down, props [@dessibelle](https://github.com/dessibelle)
* Added `select_timezone` type, a standalone time zone select dropdown. The time zone select can be used with standalone `text_datetime_timestamp` if desired. Props [@dessibelle](https://github.com/dessibelle)
* Added `text_url` type, a basic url field. Props [@dessibelle](https://github.com/dessibelle)
* Added `text_email` type, a basic email field. Props [@dessibelle](https://github.com/dessibelle)
* Added ability to display metabox fields in frontend. Default is true, but can be overriden using the `cmb_allow_frontend filter`. If set to true, an entire metabox form can be output with the `cmb_metabox_form( $meta_box, $object_id, $echo )` function. Props [@dessibelle](https://github.com/dessibelle), [@messenlehner](https://github.com/messenlehner) & [@jtsternberg](https://github.com/jtsternberg).
* Added hook `cmb_after_table` after all metabox output. Props [@wpsmith](https://github.com/wpsmith)
* `file_list` now works like a repeatable field. Add as many files as you want. Props [@coreymcollins](https://github.com/coreymcollins)
* `text`, `text_small`, `text_medium`, `text_url`, `text_email`, & `text_money` fields now all have the option to be repeatable. Props [@jtsternberg](https://github.com/jtsternberg)
* Custom metaboxes can now be added for user meta. Add them on the user add/edit screen, or in a custom user profile edit page on the front-end. Props [@tw2113](https://github.com/tw2113), [@jtsternberg](https://github.com/jtsternberg)
## 0.9.4
* Added field "before" and "after" options for each field. Solves issue with '$' not being the desired text_money monetary symbol, props [@GaryJones](https://github.com/GaryJones)
* Added filter for 'std' default fallback value, props [@messenlehner](https://github.com/messenlehner)
* Ensure oEmbed videos fit in their respective metaboxes, props [@jtsternberg](https://github.com/jtsternberg)
* Fixed issue where an upload field with 'show_names' disabled wouldn't have the correct button label, props [@jtsternberg](https://github.com/jtsternberg)
* Better file-extension check for images, props [@GhostToast](https://github.com/GhostToast)
* New filter, `cmb_valid_img_types`, for whitelisted image file-extensions, props [@jtsternberg](https://github.com/jtsternberg)
## 0.9.3
* Added field type and field id classes to each cmb table row, props [@jtsternberg](https://github.com/jtsternberg)
## 0.9.2
* Added post type comparison to prevent storing null values for taxonomy selectors, props [@norcross](https://github.com/norcross)
## 0.9.1
* Added `oEmbed` field type with ajax display, props [@jtsternberg](https://github.com/jtsternberg)
## 0.9
* __Note: This release requires WordPress 3.3+__
* Cleaned up scripts being queued, props [@jaredatch](https://github.com/jaredatch)
* Cleaned up and reorganized jQuery, props [@GaryJones](https://github.com/GaryJones)
* Use $pagenow instead of custom $current_page, props [@jaredatch](https://github.com/jaredatch)
* Fixed CSS, removed inline styles, now all in style.css, props [@jaredatch](https://github.com/jaredatch)
* Fixed multicheck issues (issue #48), props [@jaredatch](https://github.com/jaredatch)
* Fixed jQuery UI datepicker CSS conflicting with WordPress UI elements, props [@jaredatch](https://github.com/jaredatch)
* Fixed zeros not saving in fields, props [@GaryJones](https://github.com/GaryJones)
* Fixed improper labels on radio and multicheck fields, props [@jaredatch](https://github.com/jaredatch)
* Fixed fields not rendering properly when in sidebar, props [@jaredatch](https://github.com/jaredatch)
* Fixed bug where datepicker triggers extra space after footer in Firefox (issue #14), props [@jaredatch](https://github.com/jaredatch)
* Added jQuery UI datepicker packaged with 3.3 core, props [@jaredatch](https://github.com/jaredatch)
* Added date time combo picker, props [@jaredatch](https://github.com/jaredatch)
* Added color picker, props [@jaredatch](https://github.com/jaredatch)
* Added readme.md markdown file, props [@jaredatch](https://github.com/jaredatch)
## 0.8 - 2012-01-19
* Added jQuery timepicker, props [@norcross](https://github.com/norcross)
* Added 'raw' textarea to convert special HTML entities back to characters, props [@norcross](https://github.com/norcross)
* Added missing examples on example-functions.php, props [@norcross](https://github.com/norcross)
## 0.7
* Added the new wp_editor() function for the WYSIWYG dialog box, props [@jcpry](https://github.com/jcpry)
* Created 'cmb_show_on' filter to define your own Show On Filters, props [@billerickson](https://github.com/billerickson)
* Added page template show_on filter, props [@billerickson](https://github.com/billerickson)
* Improvements to the 'file' field type, props [@randyhoyt](https://github.com/randyhoyt)
* Allow for default values on 'radio' and 'radio_inline' field types, props [@billerickson](https://github.com/billerickson)
## 0.6.1
* Enabled the ability to define your own custom field types (issue #28). props [@randyhoyt](https://github.com/randyhoyt)
## 0.6
* Added the ability to limit metaboxes to certain posts by id. props [@billerickson](https://github.com/billerickson)
## 0.5
* Fixed define to prevent notices. props [@destos](https://github.com/destos)
* Added text_date_timestap option. props [@andrewyno](https://github.com/andrewyno)
* Fixed WYSIWYG paragraph breaking/spacing bug. props [@wpsmith](https://github.com/wpsmith)
* Added taxonomy_radio and taxonomies_select options. props [@c3mdigital](https://github.com/c3mdigital)
* Fixed script causing the dashboard widgets to not be collapsible.
* Fixed various spacing and whitespace inconsistencies
## 0.4
* Think we have a release that is mostly working. We'll say the initial release :)

51
cmb2/CONTRIBUTING.md Normal file
View File

@ -0,0 +1,51 @@
# Contributing to CMB2
Thank you for your interest in contributing back to CMB2. Please help us review your issues and/or merge your pull requests by following the below guidelines.
#### NOTE: The issues section is for bug reports and feature requests only.
_Support is not offered for this library, and the likelihood that the maintainers will respond is very low. If you need help, please use [stackoverflow](http://stackoverflow.com/search?q=cmb), or the [wordpress.org plugin forums](http://wordpress.org/support/plugin/cmb2)._
Before reporting a bug
---
1. Search [issues](https://github.com/WebDevStudios/CMB2/issues) to see if the issue has been previously reported.
2. Install the trunk version of CMB2 and test there.
How to report a bug
---
1. Specify the version number for both WordPress and CMB2.
3. Describe the problem in detail. Explain what happened, and what you expected would happen.
4. Provide a small test-case and a link to a [gist](https://gist.github.com/) containing your entire metabox registration code.
5. If helpful, include a screenshot. Annotate the screenshot for clarity.
How to contribute to CMB2
---
All contributions welcome. If you would like to submit a pull request, please follow the steps below.
1. Make sure you have a GitHub account.
2. Fork the repository on GitHub.
3. **Check out the trunk version of CMB2.** If you submit to the master branch, the PR will be closed with a link back to this document.
4. **Verify your issue still exists in the trunk branch.**
5. Make changes to your clone of the repository.
1. Please follow the [WordPress code standards](https://make.wordpress.org/core/handbook/coding-standards).
2. If possible, and if applicable, please also add/update unit tests for your changes.
3. Please add documentation to any new functions, methods, actions and filters.
4. When committing, reference your issue (if present) and include a note about the fix.
6. [Submit a pull request](https://help.github.com/articles/creating-a-pull-request/).
**Note:** You may gain more ground and avoid unecessary effort if you first open an issue with the proposed changes, but this step is not necessary.
Translations
---
If you are looking to provide language translation files, Please do so via [WP-Translations](http://wp-translations.org/project/cmb2/).
Additional Resources
---
* [CMB2 Documentation Wiki](https://github.com/WebDevStudios/CMB2/wiki)
* [CMB2 Snippet Library](https://github.com/WebDevStudios/CMB2-Snippet-Library)
* [CMB2 API Documentation](http://cmb2.io/api/)
* [General GitHub Documentation](http://help.github.com/)
* [GitHub Pull Request documentation](http://help.github.com/send-pull-requests/)
* [PHPUnit Tests Guide](http://phpunit.de/manual/current/en/writing-tests-for-phpunit.html)

75
cmb2/bootstrap.php Normal file
View File

@ -0,0 +1,75 @@
<?php
/**
* Bootstraps the CMB2 process
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
/**
* Function to encapsulate the CMB2 bootstrap process.
* @since 2.2.0
* @return void
*/
function cmb2_bootstrap() {
if ( is_admin() ) {
/**
* Fires on the admin side when CMB2 is included/loaded.
*
* In most cases, this should be used to add metaboxes. See example-functions.php
*/
do_action( 'cmb2_admin_init' );
}
/**
* Fires when CMB2 is included/loaded
*
* Can be used to add metaboxes if needed on the front-end or WP-API (or the front and backend).
*/
do_action( 'cmb2_init' );
/**
* For back-compat. Does the dirty-work of instantiating all the
* CMB2 instances for the cmb2_meta_boxes filter
* @since 2.0.2
*/
$cmb_config_arrays = apply_filters( 'cmb2_meta_boxes', array() );
foreach ( (array) $cmb_config_arrays as $cmb_config ) {
new CMB2( $cmb_config );
}
/**
* Fires after all CMB2 instances are created
*/
do_action( 'cmb2_init_before_hookup' );
/**
* Get all created metaboxes, and instantiate CMB2_hookup
* on metaboxes which require it.
* @since 2.0.2
*/
foreach ( CMB2_Boxes::get_all() as $cmb ) {
if ( $cmb->prop( 'hookup' ) ) {
$hookup = new CMB2_hookup( $cmb );
$hookup->universal_hooks();
}
if ( $cmb->prop( 'show_in_rest' ) && function_exists( 'rest_get_server' ) ) {
$rest = new CMB2_REST( $cmb );
$rest->universal_hooks();
}
}
/**
* Fires after CMB2 initiation process has been completed
*/
do_action( 'cmb2_after_init' );
}
// End. That's it, folks! //

View File

@ -0,0 +1,41 @@
/**
* CMB2 Styling
*/
/**
* CMB2 Styling
*/
/* line 6, sass/partials/_display.scss */
.cmb2-colorpicker-swatch span {
display: inline-block;
width: 1em;
height: 1em;
border-radius: 1em;
float: right;
margin-top: 3px;
margin-left: 2px;
}
/* line 17, sass/partials/_display.scss */
.cmb2-code {
overflow: scroll;
}
/* line 21, sass/partials/_display.scss */
.cmb-image-display {
max-width: 100%;
height: auto;
}
/* line 26, sass/partials/_display.scss */
.cmb2-display-file-list li {
display: inline;
margin: 0 0 .5em .5em;
}
/* line 31, sass/partials/_display.scss */
.cmb2-oembed * {
max-width: 100%;
height: auto;
}
/*# sourceMappingURL=cmb2-display.css.map */

1
cmb2/css/cmb2-display-rtl.min.css vendored Normal file
View File

@ -0,0 +1 @@
.cmb2-colorpicker-swatch span{display:inline-block;width:1em;height:1em;border-radius:1em;float:right;margin-top:3px;margin-left:2px}.cmb2-code{overflow:scroll}.cmb-image-display{max-width:100%;height:auto}.cmb2-display-file-list li{display:inline;margin:0 0 .5em .5em}.cmb2-oembed *{max-width:100%;height:auto}

41
cmb2/css/cmb2-display.css Normal file
View File

@ -0,0 +1,41 @@
/**
* CMB2 Styling
*/
/**
* CMB2 Styling
*/
/* line 6, sass/partials/_display.scss */
.cmb2-colorpicker-swatch span {
display: inline-block;
width: 1em;
height: 1em;
border-radius: 1em;
float: left;
margin-top: 3px;
margin-right: 2px;
}
/* line 17, sass/partials/_display.scss */
.cmb2-code {
overflow: scroll;
}
/* line 21, sass/partials/_display.scss */
.cmb-image-display {
max-width: 100%;
height: auto;
}
/* line 26, sass/partials/_display.scss */
.cmb2-display-file-list li {
display: inline;
margin: 0 .5em .5em 0;
}
/* line 31, sass/partials/_display.scss */
.cmb2-oembed * {
max-width: 100%;
height: auto;
}
/*# sourceMappingURL=cmb2-display.css.map */

View File

@ -0,0 +1,7 @@
{
"version": 3,
"mappings": "AAAA;;GAEG;ACFH;;GAEG;;AAGF,6BAAK;EACJ,OAAO,EAAE,YAAY;EACrB,KAAK,EAAE,GAAG;EACV,MAAM,EAAE,GAAG;EACX,aAAa,EAAE,GAAG;EAClB,KAAK,EAAE,IAAI;EACX,UAAU,EAAE,GAAG;EACf,YAAY,EAAE,GAAG;;;;AAInB,UAAW;EACV,QAAQ,EAAE,MAAM;;;;AAGjB,kBAAmB;EAClB,SAAS,EAAE,IAAI;EACf,MAAM,EAAE,IAAI;;;;AAGb,0BAA2B;EAC1B,OAAO,EAAE,MAAM;EACf,MAAM,EAAE,aAAa;;;;AAGtB,cAAe;EACd,SAAS,EAAE,IAAI;EACf,MAAM,EAAE,IAAI",
"sources": ["sass/cmb2-display.scss","sass/partials/_display.scss"],
"names": [],
"file": "cmb2-display.css"
}

1
cmb2/css/cmb2-display.min.css vendored Normal file
View File

@ -0,0 +1 @@
.cmb2-colorpicker-swatch span{display:inline-block;width:1em;height:1em;border-radius:1em;float:left;margin-top:3px;margin-right:2px}.cmb2-code{overflow:scroll}.cmb-image-display{max-width:100%;height:auto}.cmb2-display-file-list li{display:inline;margin:0 .5em .5em 0}.cmb2-oembed *{max-width:100%;height:auto}

1481
cmb2/css/cmb2-front-rtl.css Normal file

File diff suppressed because it is too large Load Diff

1
cmb2/css/cmb2-front-rtl.min.css vendored Normal file

File diff suppressed because one or more lines are too long

1481
cmb2/css/cmb2-front.css Normal file

File diff suppressed because it is too large Load Diff

1
cmb2/css/cmb2-front.min.css vendored Normal file

File diff suppressed because one or more lines are too long

1980
cmb2/css/cmb2-rtl.css Normal file

File diff suppressed because it is too large Load Diff

1
cmb2/css/cmb2-rtl.min.css vendored Normal file

File diff suppressed because one or more lines are too long

1980
cmb2/css/cmb2.css Normal file

File diff suppressed because it is too large Load Diff

1
cmb2/css/cmb2.min.css vendored Normal file

File diff suppressed because one or more lines are too long

2
cmb2/css/index.php Normal file
View File

@ -0,0 +1,2 @@
<?php
// Silence is golden

723
cmb2/example-functions.php Normal file
View File

@ -0,0 +1,723 @@
<?php
/**
* Include and setup custom metaboxes and fields. (make sure you copy this file to outside the CMB2 directory)
*
* Be sure to replace all instances of 'yourprefix_' with your project's prefix.
* http://nacin.com/2010/05/11/in-wordpress-prefix-everything/
*
* @category YourThemeOrPlugin
* @package Demo_CMB2
* @license http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
* @link https://github.com/WebDevStudios/CMB2
*/
/**
* Get the bootstrap! If using the plugin from wordpress.org, REMOVE THIS!
*/
if ( file_exists( dirname( __FILE__ ) . '/cmb2/init.php' ) ) {
require_once dirname( __FILE__ ) . '/cmb2/init.php';
} elseif ( file_exists( dirname( __FILE__ ) . '/CMB2/init.php' ) ) {
require_once dirname( __FILE__ ) . '/CMB2/init.php';
}
/**
* Conditionally displays a metabox when used as a callback in the 'show_on_cb' cmb2_box parameter
*
* @param CMB2 object $cmb CMB2 object.
*
* @return bool True if metabox should show
*/
function yourprefix_show_if_front_page( $cmb ) {
// Don't show this metabox if it's not the front page template.
if ( get_option( 'page_on_front' ) !== $cmb->object_id ) {
return false;
}
return true;
}
/**
* Conditionally displays a field when used as a callback in the 'show_on_cb' field parameter
*
* @param CMB2_Field object $field Field object.
*
* @return bool True if metabox should show
*/
function yourprefix_hide_if_no_cats( $field ) {
// Don't show this field if not in the cats category.
if ( ! has_tag( 'cats', $field->object_id ) ) {
return false;
}
return true;
}
/**
* Manually render a field.
*
* @param array $field_args Array of field arguments.
* @param CMB2_Field $field The field object.
*/
function yourprefix_render_row_cb( $field_args, $field ) {
$classes = $field->row_classes();
$id = $field->args( 'id' );
$label = $field->args( 'name' );
$name = $field->args( '_name' );
$value = $field->escaped_value();
$description = $field->args( 'description' );
?>
<div class="custom-field-row <?php echo esc_attr( $classes ); ?>">
<p><label for="<?php echo esc_attr( $id ); ?>"><?php echo esc_html( $label ); ?></label></p>
<p><input id="<?php echo esc_attr( $id ); ?>" type="text" name="<?php echo esc_attr( $name ); ?>" value="<?php echo $value; ?>"/></p>
<p class="description"><?php echo esc_html( $description ); ?></p>
</div>
<?php
}
/**
* Manually render a field column display.
*
* @param array $field_args Array of field arguments.
* @param CMB2_Field $field The field object.
*/
function yourprefix_display_text_small_column( $field_args, $field ) {
?>
<div class="custom-column-display <?php echo esc_attr( $field->row_classes() ); ?>">
<p><?php echo $field->escaped_value(); ?></p>
<p class="description"><?php echo esc_html( $field->args( 'description' ) ); ?></p>
</div>
<?php
}
/**
* Conditionally displays a message if the $post_id is 2
*
* @param array $field_args Array of field parameters.
* @param CMB2_Field object $field Field object.
*/
function yourprefix_before_row_if_2( $field_args, $field ) {
if ( 2 == $field->object_id ) {
echo '<p>Testing <b>"before_row"</b> parameter (on $post_id 2)</p>';
} else {
echo '<p>Testing <b>"before_row"</b> parameter (<b>NOT</b> on $post_id 2)</p>';
}
}
add_action( 'cmb2_admin_init', 'yourprefix_register_demo_metabox' );
/**
* Hook in and add a demo metabox. Can only happen on the 'cmb2_admin_init' or 'cmb2_init' hook.
*/
function yourprefix_register_demo_metabox() {
$prefix = 'yourprefix_demo_';
/**
* Sample metabox to demonstrate each field type included
*/
$cmb_demo = new_cmb2_box( array(
'id' => $prefix . 'metabox',
'title' => esc_html__( 'Test Metabox', 'cmb2' ),
'object_types' => array( 'page', ), // Post type
// 'show_on_cb' => 'yourprefix_show_if_front_page', // function should return a bool value
// 'context' => 'normal',
// 'priority' => 'high',
// 'show_names' => true, // Show field names on the left
// 'cmb_styles' => false, // false to disable the CMB stylesheet
// 'closed' => true, // true to keep the metabox closed by default
// 'classes' => 'extra-class', // Extra cmb2-wrap classes
// 'classes_cb' => 'yourprefix_add_some_classes', // Add classes through a callback.
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Text', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'text',
'type' => 'text',
'show_on_cb' => 'yourprefix_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,
// 'column' => true, // Display field value in the admin post-listing columns
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Text Small', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'textsmall',
'type' => 'text_small',
// 'repeatable' => true,
// 'column' => array(
// 'name' => esc_html__( 'Column Title', 'cmb2' ), // Set the admin column title
// 'position' => 2, // Set as the second column.
// );
// 'display_cb' => 'yourprefix_display_text_small_column', // Output the display of the column values through a callback.
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Text Medium', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'textmedium',
'type' => 'text_medium',
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Read-only Disabled Field', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'readonly',
'type' => 'text_medium',
'default' => esc_attr__( 'Hey there, I\'m a read-only field', 'cmb2' ),
'save_field' => false, // Disables the saving of this field.
'attributes' => array(
'disabled' => 'disabled',
'readonly' => 'readonly',
),
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Custom Rendered Field', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'render_row_cb',
'type' => 'text',
'render_row_cb' => 'yourprefix_render_row_cb',
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Website URL', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'url',
'type' => 'text_url',
// 'protocols' => array('http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet'), // Array of allowed protocols
// 'repeatable' => true,
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Text Email', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'email',
'type' => 'text_email',
// 'repeatable' => true,
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Time', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'time',
'type' => 'text_time',
// 'time_format' => 'H:i', // Set to 24hr format
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Time zone', 'cmb2' ),
'desc' => esc_html__( 'Time zone', 'cmb2' ),
'id' => $prefix . 'timezone',
'type' => 'select_timezone',
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Date Picker', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'textdate',
'type' => 'text_date',
// 'date_format' => 'Y-m-d',
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Date Picker (UNIX timestamp)', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'textdate_timestamp',
'type' => 'text_date_timestamp',
// 'timezone_meta_key' => $prefix . 'timezone', // Optionally make this field honor the timezone selected in the select_timezone specified above
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Date/Time Picker Combo (UNIX timestamp)', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'datetime_timestamp',
'type' => 'text_datetime_timestamp',
) );
// This text_datetime_timestamp_timezone field type
// is only compatible with PHP versions 5.3 or above.
// Feel free to uncomment and use if your server meets the requirement
// $cmb_demo->add_field( array(
// 'name' => esc_html__( 'Test Date/Time Picker/Time zone Combo (serialized DateTime object)', 'cmb2' ),
// 'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
// 'id' => $prefix . 'datetime_timestamp_timezone',
// 'type' => 'text_datetime_timestamp_timezone',
// ) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Money', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'textmoney',
'type' => 'text_money',
// 'before_field' => '£', // override '$' symbol if needed
// 'repeatable' => true,
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Color Picker', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'colorpicker',
'type' => 'colorpicker',
'default' => '#ffffff',
// 'attributes' => array(
// 'data-colorpicker' => json_encode( array(
// 'palettes' => array( '#3dd0cc', '#ff834c', '#4fa2c0', '#0bc991', ),
// ) ),
// ),
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Text Area', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'textarea',
'type' => 'textarea',
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Text Area Small', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'textareasmall',
'type' => 'textarea_small',
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Text Area for Code', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'textarea_code',
'type' => 'textarea_code',
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Title Weeeee', 'cmb2' ),
'desc' => esc_html__( 'This is a title description', 'cmb2' ),
'id' => $prefix . 'title',
'type' => 'title',
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Select', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'select',
'type' => 'select',
'show_option_none' => true,
'options' => array(
'standard' => esc_html__( 'Option One', 'cmb2' ),
'custom' => esc_html__( 'Option Two', 'cmb2' ),
'none' => esc_html__( 'Option Three', 'cmb2' ),
),
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Radio inline', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'radio_inline',
'type' => 'radio_inline',
'show_option_none' => 'No Selection',
'options' => array(
'standard' => esc_html__( 'Option One', 'cmb2' ),
'custom' => esc_html__( 'Option Two', 'cmb2' ),
'none' => esc_html__( 'Option Three', 'cmb2' ),
),
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Radio', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'radio',
'type' => 'radio',
'options' => array(
'option1' => esc_html__( 'Option One', 'cmb2' ),
'option2' => esc_html__( 'Option Two', 'cmb2' ),
'option3' => esc_html__( 'Option Three', 'cmb2' ),
),
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Taxonomy Radio', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'text_taxonomy_radio',
'type' => 'taxonomy_radio',
'taxonomy' => 'category', // Taxonomy Slug
// 'inline' => true, // Toggles display to inline
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Taxonomy Select', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'taxonomy_select',
'type' => 'taxonomy_select',
'taxonomy' => 'category', // Taxonomy Slug
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Taxonomy Multi Checkbox', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'multitaxonomy',
'type' => 'taxonomy_multicheck',
'taxonomy' => 'post_tag', // Taxonomy Slug
// 'inline' => true, // Toggles display to inline
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Checkbox', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'checkbox',
'type' => 'checkbox',
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Multi Checkbox', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'multicheckbox',
'type' => 'multicheck',
// 'multiple' => true, // Store values in individual rows
'options' => array(
'check1' => esc_html__( 'Check One', 'cmb2' ),
'check2' => esc_html__( 'Check Two', 'cmb2' ),
'check3' => esc_html__( 'Check Three', 'cmb2' ),
),
// 'inline' => true, // Toggles display to inline
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test wysiwyg', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'wysiwyg',
'type' => 'wysiwyg',
'options' => array( 'textarea_rows' => 5, ),
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Test Image', 'cmb2' ),
'desc' => esc_html__( 'Upload an image or enter a URL.', 'cmb2' ),
'id' => $prefix . 'image',
'type' => 'file',
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'Multiple Files', 'cmb2' ),
'desc' => esc_html__( 'Upload or add multiple images/attachments.', 'cmb2' ),
'id' => $prefix . 'file_list',
'type' => 'file_list',
'preview_size' => array( 100, 100 ), // Default: array( 50, 50 )
) );
$cmb_demo->add_field( array(
'name' => esc_html__( 'oEmbed', 'cmb2' ),
'desc' => sprintf(
/* translators: %s: link to codex.wordpress.org/Embeds */
esc_html__( 'Enter a youtube, twitter, or instagram URL. Supports services listed at %s.', 'cmb2' ),
'<a href="https://codex.wordpress.org/Embeds">codex.wordpress.org/Embeds</a>'
),
'id' => $prefix . 'embed',
'type' => 'oembed',
) );
$cmb_demo->add_field( array(
'name' => 'Testing Field Parameters',
'id' => $prefix . 'parameters',
'type' => 'text',
'before_row' => 'yourprefix_before_row_if_2', // callback.
'before' => '<p>Testing <b>"before"</b> parameter</p>',
'before_field' => '<p>Testing <b>"before_field"</b> parameter</p>',
'after_field' => '<p>Testing <b>"after_field"</b> parameter</p>',
'after' => '<p>Testing <b>"after"</b> parameter</p>',
'after_row' => '<p>Testing <b>"after_row"</b> parameter</p>',
) );
}
add_action( 'cmb2_admin_init', 'yourprefix_register_about_page_metabox' );
/**
* Hook in and add a metabox that only appears on the 'About' page
*/
function yourprefix_register_about_page_metabox() {
$prefix = 'yourprefix_about_';
/**
* Metabox to be displayed on a single page ID
*/
$cmb_about_page = new_cmb2_box( array(
'id' => $prefix . 'metabox',
'title' => esc_html__( 'About Page Metabox', 'cmb2' ),
'object_types' => array( 'page', ), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
'show_on' => array( 'id' => array( 2, ) ), // Specific post IDs to display this metabox
) );
$cmb_about_page->add_field( array(
'name' => esc_html__( 'Test Text', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'text',
'type' => 'text',
) );
}
add_action( 'cmb2_admin_init', 'yourprefix_register_repeatable_group_field_metabox' );
/**
* Hook in and add a metabox to demonstrate repeatable grouped fields
*/
function yourprefix_register_repeatable_group_field_metabox() {
$prefix = 'yourprefix_group_';
/**
* Repeatable Field Groups
*/
$cmb_group = new_cmb2_box( array(
'id' => $prefix . 'metabox',
'title' => esc_html__( 'Repeating Field Group', 'cmb2' ),
'object_types' => array( 'page', ),
) );
// $group_field_id is the field id string, so in this case: $prefix . 'demo'
$group_field_id = $cmb_group->add_field( array(
'id' => $prefix . 'demo',
'type' => 'group',
'description' => esc_html__( 'Generates reusable form entries', 'cmb2' ),
'options' => array(
'group_title' => esc_html__( 'Entry {#}', 'cmb2' ), // {#} gets replaced by row number
'add_button' => esc_html__( 'Add Another Entry', 'cmb2' ),
'remove_button' => esc_html__( 'Remove Entry', 'cmb2' ),
'sortable' => true, // beta
// 'closed' => true, // true to have the groups closed by default
),
) );
/**
* Group fields works the same, except ids only need
* to be unique to the group. Prefix is not needed.
*
* The parent field's id needs to be passed as the first argument.
*/
$cmb_group->add_group_field( $group_field_id, array(
'name' => esc_html__( 'Entry Title', 'cmb2' ),
'id' => 'title',
'type' => 'text',
// 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types)
) );
$cmb_group->add_group_field( $group_field_id, array(
'name' => esc_html__( 'Description', 'cmb2' ),
'description' => esc_html__( 'Write a short description for this entry', 'cmb2' ),
'id' => 'description',
'type' => 'textarea_small',
) );
$cmb_group->add_group_field( $group_field_id, array(
'name' => esc_html__( 'Entry Image', 'cmb2' ),
'id' => 'image',
'type' => 'file',
) );
$cmb_group->add_group_field( $group_field_id, array(
'name' => esc_html__( 'Image Caption', 'cmb2' ),
'id' => 'image_caption',
'type' => 'text',
) );
}
add_action( 'cmb2_admin_init', 'yourprefix_register_user_profile_metabox' );
/**
* Hook in and add a metabox to add fields to the user profile pages
*/
function yourprefix_register_user_profile_metabox() {
$prefix = 'yourprefix_user_';
/**
* Metabox for the user profile screen
*/
$cmb_user = new_cmb2_box( array(
'id' => $prefix . 'edit',
'title' => esc_html__( 'User Profile Metabox', 'cmb2' ), // Doesn't output for user boxes
'object_types' => array( 'user' ), // Tells CMB2 to use user_meta vs post_meta
'show_names' => true,
'new_user_section' => 'add-new-user', // where form will show on new user page. 'add-existing-user' is only other valid option.
) );
$cmb_user->add_field( array(
'name' => esc_html__( 'Extra Info', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'extra_info',
'type' => 'title',
'on_front' => false,
) );
$cmb_user->add_field( array(
'name' => esc_html__( 'Avatar', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'avatar',
'type' => 'file',
) );
$cmb_user->add_field( array(
'name' => esc_html__( 'Facebook URL', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'facebookurl',
'type' => 'text_url',
) );
$cmb_user->add_field( array(
'name' => esc_html__( 'Twitter URL', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'twitterurl',
'type' => 'text_url',
) );
$cmb_user->add_field( array(
'name' => esc_html__( 'Google+ URL', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'googleplusurl',
'type' => 'text_url',
) );
$cmb_user->add_field( array(
'name' => esc_html__( 'Linkedin URL', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'linkedinurl',
'type' => 'text_url',
) );
$cmb_user->add_field( array(
'name' => esc_html__( 'User Field', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'user_text_field',
'type' => 'text',
) );
}
add_action( 'cmb2_admin_init', 'yourprefix_register_taxonomy_metabox' );
/**
* Hook in and add a metabox to add fields to taxonomy terms
*/
function yourprefix_register_taxonomy_metabox() {
$prefix = 'yourprefix_term_';
/**
* Metabox to add fields to categories and tags
*/
$cmb_term = new_cmb2_box( array(
'id' => $prefix . 'edit',
'title' => esc_html__( 'Category Metabox', 'cmb2' ), // Doesn't output for term boxes
'object_types' => array( 'term' ), // Tells CMB2 to use term_meta vs post_meta
'taxonomies' => array( 'category', 'post_tag' ), // Tells CMB2 which taxonomies should have these fields
// 'new_term_section' => true, // Will display in the "Add New Category" section
) );
$cmb_term->add_field( array(
'name' => esc_html__( 'Extra Info', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'extra_info',
'type' => 'title',
'on_front' => false,
) );
$cmb_term->add_field( array(
'name' => esc_html__( 'Term Image', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'avatar',
'type' => 'file',
) );
$cmb_term->add_field( array(
'name' => esc_html__( 'Arbitrary Term Field', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'term_text_field',
'type' => 'text',
) );
}
add_action( 'cmb2_admin_init', 'yourprefix_register_theme_options_metabox' );
/**
* Hook in and register a metabox to handle a theme options page
*/
function yourprefix_register_theme_options_metabox() {
$option_key = 'yourprefix_theme_options';
/**
* Metabox for an options page. Will not be added automatically, but needs to be called with
* the `cmb2_metabox_form` helper function. See https://github.com/WebDevStudios/CMB2/wiki for more info.
*/
$cmb_options = new_cmb2_box( array(
'id' => $option_key . 'page',
'title' => esc_html__( 'Theme Options Metabox', 'cmb2' ),
'hookup' => false, // Do not need the normal user/post hookup.
'show_on' => array(
// These are important, don't remove.
'key' => 'options-page',
'value' => array( $option_key )
),
) );
/**
* Options fields ids only need
* to be unique within this option group.
* Prefix is not needed.
*/
$cmb_options->add_field( array(
'name' => esc_html__( 'Site Background Color', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => 'bg_color',
'type' => 'colorpicker',
'default' => '#ffffff',
) );
}
/**
* Only show this box in the CMB2 REST API if the user is logged in.
*
* @param bool $is_allowed Whether this box and its fields are allowed to be viewed.
* @param CMB2_REST_Controller $cmb_controller The controller object.
* CMB2 object available via `$cmb_controller->rest_box->cmb`.
*
* @return bool Whether this box and its fields are allowed to be viewed.
*/
function yourprefix_limit_rest_view_to_logged_in_users( $is_allowed, $cmb_controller ) {
if ( ! is_user_logged_in() ) {
$is_allowed = false;
}
return $is_allowed;
}
add_action( 'cmb2_init', 'yourprefix_register_rest_api_box' );
/**
* Hook in and add a box to be available in the CMB2 REST API. Can only happen on the 'cmb2_init' hook.
* More info: https://github.com/WebDevStudios/CMB2/wiki/REST-API
*/
function yourprefix_register_rest_api_box() {
$prefix = 'yourprefix_rest_';
$cmb_rest = new_cmb2_box( array(
'id' => $prefix . 'metabox',
'title' => esc_html__( 'REST Test Box', 'cmb2' ),
'object_types' => array( 'page', ), // Post type
'show_in_rest' => WP_REST_Server::ALLMETHODS, // WP_REST_Server::READABLE|WP_REST_Server::EDITABLE, // Determines which HTTP methods the box is visible in.
// Optional callback to limit box visibility.
// See: https://github.com/WebDevStudios/CMB2/wiki/REST-API#permissions
// 'get_box_permissions_check_cb' => 'yourprefix_limit_rest_view_to_logged_in_users',
) );
$cmb_rest->add_field( array(
'name' => esc_html__( 'REST Test Text', 'cmb2' ),
'desc' => esc_html__( 'Will show in the REST API for this box and for pages.', 'cmb2' ),
'id' => $prefix . 'text',
'type' => 'text',
) );
$cmb_rest->add_field( array(
'name' => esc_html__( 'REST Editable Test Text', 'cmb2' ),
'desc' => esc_html__( 'Will show in REST API "editable" contexts only (`POST` requests).', 'cmb2' ),
'id' => $prefix . 'editable_text',
'type' => 'text',
'show_in_rest' => WP_REST_Server::EDITABLE// WP_REST_Server::ALLMETHODS|WP_REST_Server::READABLE, // Determines which HTTP methods the field is visible in. Will override the cmb2_box 'show_in_rest' param.
) );
}

BIN
cmb2/images/ico-delete.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 715 B

2
cmb2/images/index.php Normal file
View File

@ -0,0 +1,2 @@
<?php
// Silence is golden

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

1390
cmb2/includes/CMB2.php Normal file

File diff suppressed because it is too large Load Diff

312
cmb2/includes/CMB2_Ajax.php Normal file
View File

@ -0,0 +1,312 @@
<?php
/**
* CMB2 ajax methods
* (i.e. a lot of work to get oEmbeds to work with non-post objects)
*
* @since 0.9.5
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
*/
class CMB2_Ajax {
// Whether to hijack the oembed cache system
protected $hijack = false;
protected $object_id = 0;
protected $embed_args = array();
protected $object_type = 'post';
protected $ajax_update = false;
/**
* Instance of this class
* @since 2.2.2
* @var object
*/
protected static $instance;
/**
* Get the singleton instance of this class
* @since 2.2.2
* @return CMB2_Ajax
*/
public static function get_instance() {
if ( ! ( self::$instance instanceof self ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
* @since 2.2.0
*/
protected function __construct() {
add_action( 'wp_ajax_cmb2_oembed_handler', array( $this, 'oembed_handler' ) );
add_action( 'wp_ajax_nopriv_cmb2_oembed_handler', array( $this, 'oembed_handler' ) );
// Need to occasionally clean stale oembed cache data from the option value.
add_action( 'cmb2_save_options-page_fields', array( __CLASS__, 'clean_stale_options_page_oembeds' ) );
}
/**
* Handles our oEmbed ajax request
* @since 0.9.5
* @return object oEmbed embed code | fallback | error message
*/
public function oembed_handler() {
// Verify our nonce
if ( ! ( isset( $_REQUEST['cmb2_ajax_nonce'], $_REQUEST['oembed_url'] ) && wp_verify_nonce( $_REQUEST['cmb2_ajax_nonce'], 'ajax_nonce' ) ) ) {
die();
}
// Sanitize our search string
$oembed_string = sanitize_text_field( $_REQUEST['oembed_url'] );
// Send back error if empty
if ( empty( $oembed_string ) ) {
wp_send_json_error( '<p class="ui-state-error-text">' . esc_html__( 'Please Try Again', 'cmb2' ) . '</p>' );
}
// Set width of embed
$embed_width = isset( $_REQUEST['oembed_width'] ) && intval( $_REQUEST['oembed_width'] ) < 640 ? intval( $_REQUEST['oembed_width'] ) : '640';
// Set url
$oembed_url = esc_url( $oembed_string );
// Set args
$embed_args = array( 'width' => $embed_width );
$this->ajax_update = true;
// Get embed code (or fallback link)
$html = $this->get_oembed( array(
'url' => $oembed_url,
'object_id' => $_REQUEST['object_id'],
'object_type' => isset( $_REQUEST['object_type'] ) ? $_REQUEST['object_type'] : 'post',
'oembed_args' => $embed_args,
'field_id' => $_REQUEST['field_id'],
) );
wp_send_json_success( $html );
}
/**
* Retrieves oEmbed from url/object ID
* @since 0.9.5
* @param array $args Arguments for method
* @return string html markup with embed or fallback
*/
public function get_oembed_no_edit( $args ) {
global $wp_embed;
$oembed_url = esc_url( $args['url'] );
// Sanitize object_id
$this->object_id = is_numeric( $args['object_id'] ) ? absint( $args['object_id'] ) : sanitize_text_field( $args['object_id'] );
$args = wp_parse_args( $args, array(
'object_type' => 'post',
'oembed_args' => $this->embed_args,
'field_id' => false,
'wp_error' => false,
) );
$this->embed_args =& $args;
/**
* Set the post_ID so oEmbed won't fail
* wp-includes/class-wp-embed.php, WP_Embed::shortcode()
*/
$wp_embed->post_ID = $this->object_id;
// Special scenario if NOT a post object
if ( isset( $args['object_type'] ) && 'post' != $args['object_type'] ) {
if ( 'options-page' == $args['object_type'] ) {
// Bogus id to pass some numeric checks. Issue with a VERY large WP install?
$wp_embed->post_ID = 1987645321;
}
// Ok, we need to hijack the oembed cache system
$this->hijack = true;
$this->object_type = $args['object_type'];
// Gets ombed cache from our object's meta (vs postmeta)
add_filter( 'get_post_metadata', array( $this, 'hijack_oembed_cache_get' ), 10, 3 );
// Sets ombed cache in our object's meta (vs postmeta)
add_filter( 'update_post_metadata', array( $this, 'hijack_oembed_cache_set' ), 10, 4 );
}
$embed_args = '';
foreach ( $args['oembed_args'] as $key => $val ) {
$embed_args .= " $key=\"$val\"";
}
// Ping WordPress for an embed
$embed = $wp_embed->run_shortcode( '[embed' . $embed_args . ']' . $oembed_url . '[/embed]' );
// Fallback that WordPress creates when no oEmbed was found
$fallback = $wp_embed->maybe_make_link( $oembed_url );
return compact( 'embed', 'fallback', 'args' );
}
/**
* Retrieves oEmbed from url/object ID
* @since 0.9.5
* @param array $args Arguments for method
* @return string html markup with embed or fallback
*/
public function get_oembed( $args ) {
$oembed = $this->get_oembed_no_edit( $args );
// Send back our embed
if ( $oembed['embed'] && $oembed['embed'] != $oembed['fallback'] ) {
return '<div class="cmb2-oembed embed-status">' . $oembed['embed'] . '<p class="cmb2-remove-wrapper"><a href="#" class="cmb2-remove-file-button" rel="' . $oembed['args']['field_id'] . '">' . esc_html__( 'Remove Embed', 'cmb2' ) . '</a></p></div>';
}
// Otherwise, send back error info that no oEmbeds were found
return sprintf(
'<p class="ui-state-error-text">%s</p>',
sprintf(
/* translators: 1: results for. 2: link to codex.wordpress.org/Embeds */
esc_html__( 'No oEmbed Results Found for %1$s. View more info at %2$s.', 'cmb2' ),
$oembed['fallback'],
'<a href="https://codex.wordpress.org/Embeds" target="_blank">codex.wordpress.org/Embeds</a>'
)
);
}
/**
* Hijacks retrieving of cached oEmbed.
* Returns cached data from relevant object metadata (vs postmeta)
*
* @since 0.9.5
* @param boolean $check Whether to retrieve postmeta or override
* @param int $object_id Object ID
* @param string $meta_key Object metakey
* @return mixed Object's oEmbed cached data
*/
public function hijack_oembed_cache_get( $check, $object_id, $meta_key ) {
if ( ! $this->hijack || ( $this->object_id != $object_id && 1987645321 !== $object_id ) ) {
return $check;
}
if ( $this->ajax_update ) {
return false;
}
return $this->cache_action( $meta_key );
}
/**
* Hijacks saving of cached oEmbed.
* Saves cached data to relevant object metadata (vs postmeta)
*
* @since 0.9.5
* @param boolean $check Whether to continue setting postmeta
* @param int $object_id Object ID to get postmeta from
* @param string $meta_key Postmeta's key
* @param mixed $meta_value Value of the postmeta to be saved
* @return boolean Whether to continue setting
*/
public function hijack_oembed_cache_set( $check, $object_id, $meta_key, $meta_value ) {
if (
! $this->hijack
|| ( $this->object_id != $object_id && 1987645321 !== $object_id )
// only want to hijack oembed meta values
|| 0 !== strpos( $meta_key, '_oembed_' )
) {
return $check;
}
$this->cache_action( $meta_key, $meta_value );
// Anything other than `null` to cancel saving to postmeta
return true;
}
/**
* Gets/updates the cached oEmbed value from/to relevant object metadata (vs postmeta)
*
* @since 1.3.0
* @param string $meta_key Postmeta's key
*/
protected function cache_action( $meta_key ) {
$func_args = func_get_args();
$action = isset( $func_args[1] ) ? 'update' : 'get';
if ( 'options-page' === $this->object_type ) {
$args = array( $meta_key );
if ( 'update' === $action ) {
$args[] = $func_args[1];
$args[] = true;
}
// Cache the result to our options
$status = call_user_func_array( array( cmb2_options( $this->object_id ), $action ), $args );
} else {
$args = array( $this->object_type, $this->object_id, $meta_key );
$args[] = 'update' === $action ? $func_args : true;
// Cache the result to our metadata
$status = call_user_func_array( $action . '_metadata', $args );
}
return $status;
}
/**
* Hooks in when options-page data is saved to clean stale
* oembed cache data from the option value.
* @since 2.2.0
* @param string $option_key The options-page option key
* @return void
*/
public static function clean_stale_options_page_oembeds( $option_key ) {
$options = cmb2_options( $option_key )->get_options();
$modified = false;
if ( is_array( $options ) ) {
$ttl = apply_filters( 'oembed_ttl', DAY_IN_SECONDS, '', array(), 0 );
$now = time();
foreach ( $options as $key => $value ) {
// Check for cached oembed data
if ( 0 === strpos( $key, '_oembed_time_' ) ) {
$cached_recently = ( $now - $value ) < $ttl;
if ( ! $cached_recently ) {
$modified = true;
// Remove the the cached ttl expiration, and the cached oembed value.
unset( $options[ $key ] );
unset( $options[ str_replace( '_oembed_time_', '_oembed_', $key ) ] );
}
}
// Remove the cached unknown values
elseif ( '{{unknown}}' === $value ) {
$modified = true;
unset( $options[ $key ] );
}
}
}
// Update the option and remove stale cache data
if ( $modified ) {
$updated = cmb2_options( $option_key )->set( $options );
}
}
}

497
cmb2/includes/CMB2_Base.php Normal file
View File

@ -0,0 +1,497 @@
<?php
/**
* CMB2 Base - Base object functionality.
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*
* @property-read $args The objects array of properties/arguments.
* @property-read $meta_box The objects array of properties/arguments.
* @property-read $properties The objects array of properties/arguments.
* @property-read $cmb_id Current CMB2 instance ID
* @property-read $object_id Object ID
* @property-read $object_type Type of object being handled. (e.g., post, user, comment, or term)
*/
abstract class CMB2_Base {
/**
* Current CMB2 instance ID
* @var string
* @since 2.2.3
*/
protected $cmb_id = '';
/**
* The object properties name.
* @var string
* @since 2.2.3
*/
protected $properties_name = 'meta_box';
/**
* Object ID
* @var mixed
* @since 2.2.3
*/
protected $object_id = 0;
/**
* Type of object being handled. (e.g., post, user, comment, or term)
* @var string
* @since 2.2.3
*/
protected $object_type = '';
/**
* Array of key => value data for saving. Likely $_POST data.
* @var array
* @since 2.2.3
*/
public $data_to_save = array();
/**
* Array of field param callback results
* @var array
* @since 2.0.0
*/
protected $callback_results = array();
/**
* The deprecated_param method deprecated param message signature.
*/
const DEPRECATED_PARAM = 1;
/**
* The deprecated_param method deprecated callback param message signature.
*/
const DEPRECATED_CB_PARAM = 2;
/**
* Get started
* @since 2.2.3
* @param array $args Object properties array
*/
public function __construct( $args = array() ) {
if ( ! empty( $args ) ) {
foreach ( array(
'cmb_id',
'properties_name',
'object_id',
'object_type',
'data_to_save',
) as $object_prop ) {
if ( isset( $args[ $object_prop ] ) ) {
$this->{$object_prop} = $args[ $object_prop ];
}
}
}
}
/**
* Returns the object ID
* @since 2.2.3
* @param integer $object_id Object ID
* @return integer Object ID
*/
public function object_id( $object_id = 0 ) {
if ( $object_id ) {
$this->object_id = $object_id;
}
return $this->object_id;
}
/**
* Returns the object type
* @since 2.2.3
* @param string $object_type Object Type
* @return string Object type
*/
public function object_type( $object_type = '' ) {
if ( $object_type ) {
$this->object_type = $object_type;
}
return $this->object_type;
}
/**
* Get the object type for the current page, based on the $pagenow global.
* @since 2.2.2
* @return string Page object type name.
*/
public function current_object_type() {
global $pagenow;
$type = 'post';
if ( in_array( $pagenow, array( 'user-edit.php', 'profile.php', 'user-new.php' ), true ) ) {
$type = 'user';
}
if ( in_array( $pagenow, array( 'edit-comments.php', 'comment.php' ), true ) ) {
$type = 'comment';
}
if ( in_array( $pagenow, array( 'edit-tags.php', 'term.php' ), true ) ) {
$type = 'term';
}
return $type;
}
/**
* Set object property.
* @since 2.2.2
* @param string $property Metabox config property to retrieve
* @param mixed $value Value to set if no value found
* @return mixed Metabox config property value or false
*/
public function set_prop( $property, $value ) {
$this->{$this->properties_name}[ $property ] = $value;
return $this->prop( $property );
}
/**
* Get object property and optionally set a fallback
* @since 2.0.0
* @param string $property Metabox config property to retrieve
* @param mixed $fallback Fallback value to set if no value found
* @return mixed Metabox config property value or false
*/
public function prop( $property, $fallback = null ) {
if ( array_key_exists( $property, $this->{$this->properties_name} ) ) {
return $this->{$this->properties_name}[ $property ];
} elseif ( $fallback ) {
return $this->{$this->properties_name}[ $property ] = $fallback;
}
}
/**
* Get default field arguments specific to this CMB2 object.
* @since 2.2.0
* @param array $field_args Metabox field config array.
* @param CMB2_Field $field_group (optional) CMB2_Field object (group parent)
* @return array Array of field arguments.
*/
protected function get_default_args( $field_args, $field_group = null ) {
if ( $field_group ) {
$args = array(
'field_args' => $field_args,
'group_field' => $field_group,
);
} else {
$args = array(
'field_args' => $field_args,
'object_type' => $this->object_type(),
'object_id' => $this->object_id(),
'cmb_id' => $this->cmb_id,
);
}
return $args;
}
/**
* Get a new field object specific to this CMB2 object.
* @since 2.2.0
* @param array $field_args Metabox field config array.
* @param CMB2_Field $field_group (optional) CMB2_Field object (group parent)
* @return CMB2_Field CMB2_Field object
*/
protected function get_new_field( $field_args, $field_group = null ) {
return new CMB2_Field( $this->get_default_args( $field_args, $field_group ) );
}
/**
* Determine whether this cmb object should show, based on the 'show_on_cb' callback.
*
* @since 2.0.9
*
* @return bool Whether this cmb should be shown.
*/
public function should_show() {
// Default to showing this cmb
$show = true;
// Use the callback to determine showing the cmb, if it exists
if ( is_callable( $this->prop( 'show_on_cb' ) ) ) {
$show = (bool) call_user_func( $this->prop( 'show_on_cb' ), $this );
}
return $show;
}
/**
* Displays the results of the param callbacks.
*
* @since 2.0.0
* @param string $param Field parameter
*/
public function peform_param_callback( $param ) {
echo $this->get_param_callback_result( $param );
}
/**
* Store results of the param callbacks for continual access
* @since 2.0.0
* @param string $param Field parameter
* @return mixed Results of param/param callback
*/
public function get_param_callback_result( $param ) {
// If we've already retrieved this param's value,
if ( array_key_exists( $param, $this->callback_results ) ) {
// send it back
return $this->callback_results[ $param ];
}
// Check if parameter has registered a callback.
if ( $cb = $this->maybe_callback( $param ) ) {
// Ok, callback is good, let's run it and store the result.
ob_start();
$returned = $this->do_callback( $cb );
// Grab the result from the output buffer and store it.
$echoed = ob_get_clean();
// This checks if the user returned or echoed their callback.
// Defaults to using the echoed value.
$this->callback_results[ $param ] = $echoed ? $echoed : $returned;
} else {
// Otherwise just get whatever is there.
$this->callback_results[ $param ] = isset( $this->{$this->properties_name}[ $param ] ) ? $this->{$this->properties_name}[ $param ] : false;
}
return $this->callback_results[ $param ];
}
/**
* Handles the parameter callbacks, and passes this object as parameter.
* @since 2.2.3
* @param callable $cb The callback method/function/closure
* @return mixed Return of the callback function.
*/
protected function do_callback( $cb ) {
return call_user_func( $cb, $this->{$this->properties_name}, $this );
}
/**
* Checks if field has a callback value
* @since 1.0.1
* @param string $cb Callback string
* @return mixed NULL, false for NO validation, or $cb string if it exists.
*/
public function maybe_callback( $cb ) {
$args = $this->{$this->properties_name};
if ( ! isset( $args[ $cb ] ) ) {
return null;
}
// Check if requesting explicitly false
$cb = false !== $args[ $cb ] && 'false' !== $args[ $cb ] ? $args[ $cb ] : false;
// If requesting NO validation, return false
if ( ! $cb ) {
return false;
}
if ( is_callable( $cb ) ) {
return $cb;
}
return null;
}
/**
* Checks if this object has parameter corresponding to the given filter
* which is callable. If so, it registers the callback, and if not,
* converts the maybe-modified $val to a boolean for return.
*
* The registered handlers will have a parameter name which matches the filter, except:
* - The 'cmb2_api' prefix will be removed
* - A '_cb' suffix will be added (to stay inline with other '*_cb' parameters).
*
* @since 2.2.3
*
* @param string $hook_name The hook name.
* @param bool $val The default value.
* @param string $hook_function The hook function. Default: 'add_filter'
*
* @return null|bool Null if hook is registered, or bool for value.
*/
public function maybe_hook_parameter( $hook_name, $val = null, $hook_function = 'add_filter' ) {
// Remove filter prefix, add param suffix.
$parameter = substr( $hook_name, strlen( 'cmb2_api_' ) ) . '_cb';
return self::maybe_hook(
$this->prop( $parameter, $val ),
$hook_name,
$hook_function
);
}
/**
* Checks if given value is callable, and registers the callback.
* If is non-callable, converts the $val to a boolean for return.
*
* @since 2.2.3
*
* @param bool $val The default value.
* @param string $hook_name The hook name.
* @param string $hook_function The hook function.
*
* @return null|bool Null if hook is registered, or bool for value.
*/
public static function maybe_hook( $val, $hook_name, $hook_function ) {
if ( is_callable( $val ) ) {
$hook_function( $hook_name, $val, 10, 2 );
return null;
}
// Cast to bool.
return !! $val;
}
/**
* Mark a param as deprecated and inform when it has been used.
*
* There is a default WordPress hook deprecated_argument_run that will be called
* that can be used to get the backtrace up to what file and function used the
* deprecated argument.
*
* The current behavior is to trigger a user error if WP_DEBUG is true.
*
* @since 2.2.3
*
* @param string $function The function that was called.
* @param string $version The version of CMB2 that deprecated the argument used.
* @param string $message Optional. A message regarding the change, or numeric
* key to generate message from additional arguments.
* Default null.
*/
protected function deprecated_param( $function, $version, $message = null ) {
if ( is_numeric( $message ) ) {
$args = func_get_args();
switch ( $message ) {
case self::DEPRECATED_PARAM:
$message = sprintf( __( 'The "%s" field parameter has been deprecated in favor of the "%s" parameter.', 'cmb2' ), $args[3], $args[4] );
break;
case self::DEPRECATED_CB_PARAM:
$message = sprintf( __( 'Using the "%s" field parameter as a callback has been deprecated in favor of the "%s" parameter.', 'cmb2' ), $args[3], $args[4] );
break;
default:
$message = null;
break;
}
}
/**
* Fires when a deprecated argument is called. This is a WP core action.
*
* @since 2.2.3
*
* @param string $function The function that was called.
* @param string $message A message regarding the change.
* @param string $version The version of CMB2 that deprecated the argument used.
*/
do_action( 'deprecated_argument_run', $function, $message, $version );
/**
* Filters whether to trigger an error for deprecated arguments. This is a WP core filter.
*
* @since 2.2.3
*
* @param bool $trigger Whether to trigger the error for deprecated arguments. Default true.
*/
if ( defined( 'WP_DEBUG' ) && WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) {
if ( function_exists( '__' ) ) {
if ( ! is_null( $message ) ) {
trigger_error( sprintf( __( '%1$s was called with a parameter that is <strong>deprecated</strong> since version %2$s! %3$s', 'cmb2' ), $function, $version, $message ) );
}
else {
trigger_error( sprintf( __( '%1$s was called with a parameter that is <strong>deprecated</strong> since version %2$s with no alternative available.', 'cmb2' ), $function, $version ) );
}
} else {
if ( ! is_null( $message ) ) {
trigger_error( sprintf( '%1$s was called with a parameter that is <strong>deprecated</strong> since version %2$s! %3$s', $function, $version, $message ) );
}
else {
trigger_error( sprintf( '%1$s was called with a parameter that is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );
}
}
}
}
/**
* Magic getter for our object.
* @param string $field
* @throws Exception Throws an exception if the field is invalid.
* @return mixed
*/
public function __get( $field ) {
switch ( $field ) {
case 'args':
case 'meta_box':
if ( $field === $this->properties_name ) {
return $this->{$this->properties_name};
}
case 'properties':
return $this->{$this->properties_name};
case 'cmb_id':
case 'object_id':
case 'object_type':
return $this->{$field};
default:
throw new Exception( sprintf( esc_html__( 'Invalid %1$s property: %2$s', 'cmb2' ), __CLASS__, $field ) );
}
}
/**
* Allows overloading the object with methods... Whooaaa oooh it's magic, y'knoooow.
* @since 1.0.0
* @param string $method Non-existent method.
* @param array $args All arguments passed to the method
*/
public function __call( $method, $args ) {
$object_class = strtolower( get_class( $this ) );
if ( ! has_filter( "{$object_class}_inherit_{$method}" ) ) {
throw new Exception( sprintf( esc_html__( 'Invalid %1$s method: %2$s', 'cmb2' ), get_class( $this ), $method ) );
}
array_unshift( $args, $this );
/**
* Allows overloading the object (CMB2 or CMB2_Field) with additional capabilities
* by registering hook callbacks.
*
* The first dynamic portion of the hook name, $object_class, refers to the object class,
* either cmb2 or cmb2_field.
*
* The second dynamic portion of the hook name, $method, is the non-existent method being
* called on the object. To avoid possible future methods encroaching on your hooks,
* use a unique method (aka, $cmb->prefix_my_method()).
*
* When registering your callback, you will need to ensure that you register the correct
* number of `$accepted_args`, accounting for this object instance being the first argument.
*
* @param array $args The arguments to be passed to the hook.
* The first argument will always be this object instance.
*/
return apply_filters_ref_array( "{$object_class}_inherit_{$method}", $args );
}
}

View File

@ -0,0 +1,95 @@
<?php
/**
* A CMB2 object instance registry for storing every CMB2 instance.
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Boxes {
/**
* Array of all metabox objects.
*
* @since 2.0.0
* @var array
*/
protected static $cmb2_instances = array();
/**
* Add a CMB2 instance object to the registry.
*
* @since 1.X.X
*
* @param CMB2 $cmb_instance CMB2 instance.
*/
public static function add( CMB2 $cmb_instance ) {
self::$cmb2_instances[ $cmb_instance->cmb_id ] = $cmb_instance;
}
/**
* Remove a CMB2 instance object from the registry.
*
* @since 1.X.X
*
* @param string $cmb_id A CMB2 instance id.
*/
public static function remove( $cmb_id ) {
if ( array_key_exists( $cmb_id, self::$cmb2_instances ) ) {
unset( self::$cmb2_instances[ $cmb_id ] );
}
}
/**
* Retrieve a CMB2 instance by cmb id.
*
* @since 1.X.X
*
* @param string $cmb_id A CMB2 instance id.
*
* @return CMB2|bool False or CMB2 object instance.
*/
public static function get( $cmb_id ) {
if ( empty( self::$cmb2_instances ) || empty( self::$cmb2_instances[ $cmb_id ] ) ) {
return false;
}
return self::$cmb2_instances[ $cmb_id ];
}
/**
* Retrieve all CMB2 instances registered.
*
* @since 1.X.X
* @return CMB2[] Array of all registered cmb2 instances.
*/
public static function get_all() {
return self::$cmb2_instances;
}
/**
* Retrieve all CMB2 instances that have the specified property set.
* @since 2.2.3
* @param string $property Property name.
* @param mixed $ignore The value to ignore.
* @return CMB2[] Array of matching cmb2 instances.
*/
public static function get_by_property( $property, $ignore = null ) {
$by_property[ $property ] = array();
foreach ( self::$cmb2_instances as $cmb_id => $cmb ) {
if ( $ignore === $cmb->prop( $property ) ) {
continue;
}
$by_property[ $property ][ $cmb_id ] = $cmb;
}
return $by_property[ $property ];
}
}

1262
cmb2/includes/CMB2_Field.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,457 @@
<?php
/**
* CMB2 field display base.
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Field_Display {
/**
* A CMB field object
* @var CMB2_Field object
* @since 2.2.2
*/
public $field;
/**
* The CMB field object's value.
* @var mixed
* @since 2.2.2
*/
public $value;
/**
* Get the corresponding display class for the field type.
* @since 2.2.2
* @param CMB2_Field $field
* @return CMB2_Field_Display
*/
public static function get( CMB2_Field $field ) {
switch ( $field->type() ) {
case 'text_url':
$type = new CMB2_Display_Text_Url( $field );
break;
case 'text_money':
$type = new CMB2_Display_Text_Money( $field );
break;
case 'colorpicker':
$type = new CMB2_Display_Colorpicker( $field );
break;
case 'checkbox':
$type = new CMB2_Display_Checkbox( $field );
break;
case 'wysiwyg':
case 'textarea_small':
$type = new CMB2_Display_Textarea( $field );
break;
case 'textarea_code':
$type = new CMB2_Display_Textarea_Code( $field );
break;
case 'text_time':
$type = new CMB2_Display_Text_Time( $field );
break;
case 'text_date':
case 'text_date_timestamp':
case 'text_datetime_timestamp':
$type = new CMB2_Display_Text_Date( $field );
break;
case 'text_datetime_timestamp_timezone':
$type = new CMB2_Display_Text_Date_Timezone( $field );
break;
case 'select':
case 'radio':
case 'radio_inline':
$type = new CMB2_Display_Select( $field );
break;
case 'multicheck':
case 'multicheck_inline':
$type = new CMB2_Display_Multicheck( $field );
break;
case 'taxonomy_radio':
case 'taxonomy_radio_inline':
case 'taxonomy_select':
$type = new CMB2_Display_Taxonomy_Radio( $field );
break;
case 'taxonomy_multicheck':
case 'taxonomy_multicheck_inline':
$type = new CMB2_Display_Taxonomy_Multicheck( $field );
break;
case 'file':
$type = new CMB2_Display_File( $field );
break;
case 'file_list':
$type = new CMB2_Display_File_List( $field );
break;
case 'oembed':
$type = new CMB2_Display_oEmbed( $field );
break;
default:
$type = new self( $field );
break;
}
return $type;
}
/**
* Setup our class vars
* @since 2.2.2
* @param CMB2_Field $field A CMB2 field object
*/
public function __construct( CMB2_Field $field ) {
$this->field = $field;
$this->value = $this->field->value;
}
/**
* Catchall method if field's 'display_cb' is NOT defined, or field type does
* not have a corresponding display method
* @since 2.2.2
*/
public function display() {
// If repeatable
if ( $this->field->args( 'repeatable' ) ) {
// And has a repeatable value
if ( is_array( $this->field->value ) ) {
// Then loop and output.
echo '<ul class="cmb2-'. str_replace( '_', '-', $this->field->type() ) .'">';
foreach ( $this->field->value as $val ) {
$this->value = $val;
echo '<li>', $this->_display(), '</li>';
;
}
echo '</ul>';
}
} else {
$this->_display();
}
}
/**
* Default fallback display method.
* @since 2.2.2
*/
protected function _display() {
print_r( $this->value );
}
}
class CMB2_Display_Text_Url extends CMB2_Field_Display {
/**
* Display url value.
* @since 2.2.2
*/
protected function _display() {
echo make_clickable( esc_url( $this->value ) );
}
}
class CMB2_Display_Text_Money extends CMB2_Field_Display {
/**
* Display text_money value.
* @since 2.2.2
*/
protected function _display() {
$this->value = $this->value ? $this->value : '0';
echo ( ! $this->field->get_param_callback_result( 'before_field' ) ? '$' : ' ' ), $this->value;
}
}
class CMB2_Display_Colorpicker extends CMB2_Field_Display {
/**
* Display color picker value.
* @since 2.2.2
*/
protected function _display() {
echo '<span class="cmb2-colorpicker-swatch"><span style="background-color:', esc_attr( $this->value ), '"></span> ', esc_html( $this->value ), '</span>';
}
}
class CMB2_Display_Checkbox extends CMB2_Field_Display {
/**
* Display multicheck value.
* @since 2.2.2
*/
protected function _display() {
echo $this->value === 'on' ? 'on' : 'off';
}
}
class CMB2_Display_Select extends CMB2_Field_Display {
/**
* Display select value.
* @since 2.2.2
*/
protected function _display() {
$options = $this->field->options();
$fallback = $this->field->args( 'show_option_none' );
if ( ! $fallback && isset( $options[''] ) ) {
$fallback = $options[''];
}
if ( ! $this->value && $fallback ) {
echo $fallback;
} elseif ( isset( $options[ $this->value ] ) ) {
echo $options[ $this->value ];
} else {
echo esc_attr( $this->value );
}
}
}
class CMB2_Display_Multicheck extends CMB2_Field_Display {
/**
* Display multicheck value.
* @since 2.2.2
*/
protected function _display() {
if ( empty( $this->value ) || ! is_array( $this->value ) ) {
return;
}
$options = $this->field->options();
$output = array();
foreach ( $this->value as $val ) {
if ( isset( $options[ $val ] ) ) {
$output[] = $options[ $val ];
} else {
$output[] = esc_attr( $val );
}
}
echo implode( ', ', $output );
}
}
class CMB2_Display_Textarea extends CMB2_Field_Display {
/**
* Display textarea value.
* @since 2.2.2
*/
protected function _display() {
echo wpautop( wp_kses_post( $this->value ) );
}
}
class CMB2_Display_Textarea_Code extends CMB2_Field_Display {
/**
* Display textarea_code value.
* @since 2.2.2
*/
protected function _display() {
echo '<xmp class="cmb2-code">'. print_r( $this->value, true ) .'</xmp>';
}
}
class CMB2_Display_Text_Time extends CMB2_Field_Display {
/**
* Display text_time value.
* @since 2.2.2
*/
protected function _display() {
echo $this->field->get_timestamp_format( 'time_format', $this->value );
}
}
class CMB2_Display_Text_Date extends CMB2_Field_Display {
/**
* Display text_date value.
* @since 2.2.2
*/
protected function _display() {
echo $this->field->get_timestamp_format( 'date_format', $this->value );
}
}
class CMB2_Display_Text_Date_Timezone extends CMB2_Field_Display {
/**
* Display text_datetime_timestamp_timezone value.
* @since 2.2.2
*/
protected function _display() {
$field = $this->field;
if ( empty( $this->value ) ) {
return;
}
$datetime = maybe_unserialize( $this->value );
$this->value = $tzstring = '';
if ( $datetime && $datetime instanceof DateTime ) {
$tz = $datetime->getTimezone();
$tzstring = $tz->getName();
$this->value = $datetime->getTimestamp();
}
$date = $this->field->get_timestamp_format( 'date_format', $this->value );
$time = $this->field->get_timestamp_format( 'time_format', $this->value );
echo $date, ( $time ? ' ' . $time : '' ), ( $tzstring ? ', ' . $tzstring : '' );
}
}
class CMB2_Display_Taxonomy_Radio extends CMB2_Field_Display {
/**
* Display single taxonomy value.
* @since 2.2.2
*/
protected function _display() {
$taxonomy = $this->field->args( 'taxonomy' );
$types = new CMB2_Types( $this->field );
$type = $types->get_new_render_type( $this->field->type(), 'CMB2_Type_Taxonomy_Radio' );
$terms = $type->get_object_terms();
$term = false;
if ( is_wp_error( $terms ) || empty( $terms ) && ( $default = $this->field->get_default() ) ) {
$term = get_term_by( 'slug', $default, $taxonomy );
} elseif ( ! empty( $terms ) ) {
$term = $terms[key( $terms )];
}
if ( $term ) {
$link = get_edit_term_link( $term->term_id, $taxonomy );
echo '<a href="', esc_url( $link ), '">', esc_html( $term->name ), '</a>';
}
}
}
class CMB2_Display_Taxonomy_Multicheck extends CMB2_Field_Display {
/**
* Display taxonomy values.
* @since 2.2.2
*/
protected function _display() {
$taxonomy = $this->field->args( 'taxonomy' );
$types = new CMB2_Types( $this->field );
$type = $types->get_new_render_type( $this->field->type(), 'CMB2_Type_Taxonomy_Multicheck' );
$terms = $type->get_object_terms();
if ( is_wp_error( $terms ) || empty( $terms ) && ( $default = $this->field->get_default() ) ) {
$terms = array();
if ( is_array( $default ) ) {
foreach ( $default as $slug ) {
$terms[] = get_term_by( 'slug', $slug, $taxonomy );
}
} else {
$terms[] = get_term_by( 'slug', $default, $taxonomy );
}
}
if ( is_array( $terms ) ) {
$links = array();
foreach ( $terms as $term ) {
$link = get_edit_term_link( $term->term_id, $taxonomy );
$links[] = '<a href="'. esc_url( $link ) .'">'. esc_html( $term->name ) .'</a>';
}
// Then loop and output.
echo '<div class="cmb2-taxonomy-terms-', esc_attr( $taxonomy ), '">';
echo implode( ', ', $links );
echo '</div>';
}
}
}
class CMB2_Display_File extends CMB2_Field_Display {
/**
* Display file value.
* @since 2.2.2
*/
protected function _display() {
if ( empty( $this->value ) ) {
return;
}
$this->value = esc_url_raw( $this->value );
$types = new CMB2_Types( $this->field );
$type = $types->get_new_render_type( $this->field->type(), 'CMB2_Type_File_Base' );
$id = $this->field->get_field_clone( array(
'id' => $this->field->_id() . '_id',
) )->escaped_value( 'absint' );
$this->file_output( $this->value, $id, $type );
}
protected function file_output( $url_value, $id, CMB2_Type_File_Base $field_type ) {
// If there is no ID saved yet, try to get it from the url
if ( $url_value && ! $id ) {
$id = CMB2_Utils::image_id_from_url( esc_url_raw( $url_value ) );
}
if ( $field_type->is_valid_img_ext( $url_value ) ) {
$img_size = $this->field->args( 'preview_size' );
if ( $id ) {
$image = wp_get_attachment_image( $id, $img_size, null, array( 'class' => 'cmb-image-display' ) );
} else {
$size = is_array( $img_size ) ? $img_size[0] : 200;
$image = '<img class="cmb-image-display" style="max-width: ' . absint( $size ) . 'px; width: 100%; height: auto;" src="' . $url_value . '" alt="" />';
}
echo $image;
} else {
printf( '<div class="file-status"><span>%1$s <strong><a href="%2$s">%3$s</a></strong></span></div>',
esc_html( $field_type->_text( 'file_text', esc_html__( 'File:', 'cmb2' ) ) ),
$url_value,
CMB2_Utils::get_file_name_from_path( $url_value )
);
}
}
}
class CMB2_Display_File_List extends CMB2_Display_File {
/**
* Display file_list value.
* @since 2.2.2
*/
protected function _display() {
if ( empty( $this->value ) || ! is_array( $this->value ) ) {
return;
}
$types = new CMB2_Types( $this->field );
$type = $types->get_new_render_type( $this->field->type(), 'CMB2_Type_File_Base' );
echo '<ul class="cmb2-display-file-list">';
foreach ( $this->value as $id => $fullurl ) {
echo '<li>', $this->file_output( esc_url_raw( $fullurl ), $id, $type ), '</li>';
}
echo '</ul>';
}
}
class CMB2_Display_oEmbed extends CMB2_Field_Display {
/**
* Display oembed value.
* @since 2.2.2
*/
protected function _display() {
if ( ! $this->value ) {
return;
}
cmb2_do_oembed( array(
'url' => $this->value,
'object_id' => $this->field->object_id,
'object_type' => $this->field->object_type,
'oembed_args' => array( 'width' => '300' ),
'field_id' => $this->field->id(),
) );
}
}

View File

@ -0,0 +1,68 @@
<?php
/**
* Base class for hooking CMB2 into WordPress.
*
* @since 2.2.0
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
abstract class CMB2_Hookup_Base {
/**
* @var CMB2 object
* @since 2.0.2
*/
protected $cmb;
/**
* The object type we are performing the hookup for
* @var string
* @since 2.0.9
*/
protected $object_type = 'post';
/**
* Constructor
* @since 2.0.0
* @param CMB2 $cmb The CMB2 object to hookup
*/
public function __construct( CMB2 $cmb ) {
$this->cmb = $cmb;
$this->object_type = $this->cmb->mb_object_type();
}
abstract public function universal_hooks();
/**
* Ensures WordPress hook only gets fired once per object.
* @since 2.0.0
* @param string $action The name of the filter to hook the $hook callback to.
* @param callback $hook The callback to be run when the filter is applied.
* @param integer $priority Order the functions are executed
* @param int $accepted_args The number of arguments the function accepts.
*/
public function once( $action, $hook, $priority = 10, $accepted_args = 1 ) {
static $hooks_completed = array();
$args = func_get_args();
// Get object hash.. This bypasses issues with serializing closures.
if ( is_object( $hook ) ) {
$args[1] = spl_object_hash( $args[1] );
} elseif ( is_array( $hook ) && is_object( $hook[0] ) ) {
$args[1][0] = spl_object_hash( $hook[0] );
}
$key = md5( serialize( $args ) );
if ( ! isset( $hooks_completed[ $key ] ) ) {
$hooks_completed[ $key ] = 1;
add_filter( $action, $hook, $priority, $accepted_args );
}
}
}

167
cmb2/includes/CMB2_JS.php Normal file
View File

@ -0,0 +1,167 @@
<?php
/**
* Handles the dependencies and enqueueing of the CMB2 JS scripts
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_JS {
/**
* The CMB2 JS handle
* @var string
* @since 2.0.7
*/
protected static $handle = 'cmb2-scripts';
/**
* The CMB2 JS variable name
* @var string
* @since 2.0.7
*/
protected static $js_variable = 'cmb2_l10';
/**
* Array of CMB2 JS dependencies
* @var array
* @since 2.0.7
*/
protected static $dependencies = array( 'jquery' => 'jquery' );
/**
* Add a dependency to the array of CMB2 JS dependencies
* @since 2.0.7
* @param array|string $dependencies Array (or string) of dependencies to add
*/
public static function add_dependencies( $dependencies ) {
foreach ( (array) $dependencies as $dependency ) {
self::$dependencies[ $dependency ] = $dependency;
}
}
/**
* Enqueue the CMB2 JS
* @since 2.0.7
*/
public static function enqueue() {
// Filter required script dependencies
$dependencies = apply_filters( 'cmb2_script_dependencies', self::$dependencies );
// Only use minified files if SCRIPT_DEBUG is off
$debug = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
$min = $debug ? '' : '.min';
// if colorpicker
if ( ! is_admin() && isset( $dependencies['wp-color-picker'] ) ) {
self::colorpicker_frontend();
}
// if file/file_list
if ( isset( $dependencies['media-editor'] ) ) {
wp_enqueue_media();
CMB2_Type_File_Base::output_js_underscore_templates();
}
// if timepicker
if ( isset( $dependencies['jquery-ui-datetimepicker'] ) ) {
wp_register_script( 'jquery-ui-datetimepicker', CMB2_Utils::url( 'js/jquery-ui-timepicker-addon.min.js' ), array( 'jquery-ui-slider' ), CMB2_VERSION );
}
// if cmb2-wysiwyg
$enqueue_wysiwyg = isset( $dependencies['cmb2-wysiwyg'] ) && $debug;
unset( $dependencies['cmb2-wysiwyg'] );
// Enqueue cmb JS
wp_enqueue_script( self::$handle, CMB2_Utils::url( "js/cmb2{$min}.js" ), $dependencies, CMB2_VERSION, true );
// if SCRIPT_DEBUG, we need to enqueue separately.
if ( $enqueue_wysiwyg ) {
wp_enqueue_script( 'cmb2-wysiwyg', CMB2_Utils::url( 'js/cmb2-wysiwyg.js' ), array( 'jquery', 'wp-util' ), CMB2_VERSION );
}
self::localize( $debug );
do_action( 'cmb2_footer_enqueue' );
}
/**
* We need to register colorpicker on the front-end
* @since 2.0.7
*/
protected static function colorpicker_frontend() {
wp_register_script( 'iris', admin_url( 'js/iris.min.js' ), array( 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch' ), CMB2_VERSION );
wp_register_script( 'wp-color-picker', admin_url( 'js/color-picker.min.js' ), array( 'iris' ), CMB2_VERSION );
wp_localize_script( 'wp-color-picker', 'wpColorPickerL10n', array(
'clear' => esc_html__( 'Clear', 'cmb2' ),
'defaultString' => esc_html__( 'Default', 'cmb2' ),
'pick' => esc_html__( 'Select Color', 'cmb2' ),
'current' => esc_html__( 'Current Color', 'cmb2' ),
) );
}
/**
* Localize the php variables for CMB2 JS
* @since 2.0.7
*/
protected static function localize( $debug ) {
static $localized = false;
if ( $localized ) {
return;
}
$localized = true;
$l10n = array(
'ajax_nonce' => wp_create_nonce( 'ajax_nonce' ),
'ajaxurl' => admin_url( '/admin-ajax.php' ),
'script_debug' => $debug,
'up_arrow_class' => 'dashicons dashicons-arrow-up-alt2',
'down_arrow_class' => 'dashicons dashicons-arrow-down-alt2',
'defaults' => array(
'color_picker' => false,
'date_picker' => array(
'changeMonth' => true,
'changeYear' => true,
'dateFormat' => _x( 'mm/dd/yy', 'Valid formatDate string for jquery-ui datepicker', 'cmb2' ),
'dayNames' => explode( ',', esc_html__( 'Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday', 'cmb2' ) ),
'dayNamesMin' => explode( ',', esc_html__( 'Su, Mo, Tu, We, Th, Fr, Sa', 'cmb2' ) ),
'dayNamesShort' => explode( ',', esc_html__( 'Sun, Mon, Tue, Wed, Thu, Fri, Sat', 'cmb2' ) ),
'monthNames' => explode( ',', esc_html__( 'January, February, March, April, May, June, July, August, September, October, November, December', 'cmb2' ) ),
'monthNamesShort' => explode( ',', esc_html__( 'Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec', 'cmb2' ) ),
'nextText' => esc_html__( 'Next', 'cmb2' ),
'prevText' => esc_html__( 'Prev', 'cmb2' ),
'currentText' => esc_html__( 'Today', 'cmb2' ),
'closeText' => esc_html__( 'Done', 'cmb2' ),
'clearText' => esc_html__( 'Clear', 'cmb2' ),
),
'time_picker' => array(
'timeOnlyTitle' => esc_html__( 'Choose Time', 'cmb2' ),
'timeText' => esc_html__( 'Time', 'cmb2' ),
'hourText' => esc_html__( 'Hour', 'cmb2' ),
'minuteText' => esc_html__( 'Minute', 'cmb2' ),
'secondText' => esc_html__( 'Second', 'cmb2' ),
'currentText' => esc_html__( 'Now', 'cmb2' ),
'closeText' => esc_html__( 'Done', 'cmb2' ),
'timeFormat' => _x( 'hh:mm TT', 'Valid formatting string, as per http://trentrichardson.com/examples/timepicker/', 'cmb2' ),
'controlType' => 'select',
'stepMinute' => 5,
),
),
'strings' => array(
'upload_file' => esc_html__( 'Use this file', 'cmb2' ),
'upload_files' => esc_html__( 'Use these files', 'cmb2' ),
'remove_image' => esc_html__( 'Remove Image', 'cmb2' ),
'remove_file' => esc_html__( 'Remove', 'cmb2' ),
'file' => esc_html__( 'File:', 'cmb2' ),
'download' => esc_html__( 'Download', 'cmb2' ),
'check_toggle' => esc_html__( 'Select / Deselect All', 'cmb2' ),
),
);
wp_localize_script( self::$handle, self::$js_variable, apply_filters( 'cmb2_localized_data', $l10n ) );
}
}

View File

@ -0,0 +1,202 @@
<?php
/**
* CMB2 Utility classes for handling multi-dimensional array data for options
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
/**
* Retrieves an instance of CMB2_Option based on the option key
*
* @package CMB2
* @author WebDevStudios
*/
class CMB2_Options {
/**
* Array of all CMB2_Option instances
* @var array
* @since 1.0.0
*/
protected static $option_sets = array();
public static function get( $option_key ) {
if ( empty( self::$option_sets ) || empty( self::$option_sets[ $option_key ] ) ) {
self::$option_sets[ $option_key ] = new CMB2_Option( $option_key );
}
return self::$option_sets[ $option_key ];
}
}
/**
* Handles getting/setting of values to an option array
* for a specific option key
*
* @package CMB2
* @author WebDevStudios
*/
class CMB2_Option {
/**
* Options array
* @var array
*/
protected $options = array();
/**
* Current option key
* @var string
*/
protected $key = '';
/**
* Initiate option object
* @param string $option_key Option key where data will be saved.
* Leave empty for temporary data store.
* @since 2.0.0
*/
public function __construct( $option_key = '' ) {
$this->key = ! empty( $option_key ) ? $option_key : '';
}
/**
* Delete the option from the db
* @since 2.0.0
* @return bool Delete success or failure
*/
public function delete_option() {
$deleted = $this->key ? delete_option( $this->key ) : true;
$this->options = $deleted ? array() : $this->options;
return $this->options;
}
/**
* Removes an option from an option array
* @since 1.0.1
* @param string $field_id Option array field key
* @return array Modified options
*/
public function remove( $field_id, $resave = false ) {
$this->get_options();
if ( isset( $this->options[ $field_id ] ) ) {
unset( $this->options[ $field_id ] );
}
if ( $resave ) {
$this->set();
}
return $this->options;
}
/**
* Retrieves an option from an option array
* @since 1.0.1
* @param string $field_id Option array field key
* @param mixed $default Fallback value for the option
* @return array Requested field or default
*/
public function get( $field_id, $default = false ) {
$opts = $this->get_options();
if ( 'all' == $field_id ) {
return $opts;
} elseif ( array_key_exists( $field_id, $opts ) ) {
return false !== $opts[ $field_id ] ? $opts[ $field_id ] : $default;
}
return $default;
}
/**
* Updates Option data
* @since 1.0.1
* @param string $field_id Option array field key
* @param mixed $value Value to update data with
* @param bool $resave Whether to re-save the data
* @param bool $single Whether data should not be an array
* @return boolean Return status of update
*/
public function update( $field_id, $value = '', $resave = false, $single = true ) {
$this->get_options();
if ( true !== $field_id ) {
if ( ! $single ) {
// If multiple, add to array
$this->options[ $field_id ][] = $value;
} else {
$this->options[ $field_id ] = $value;
}
}
if ( $resave || true === $field_id ) {
return $this->set();
}
return true;
}
/**
* Saves the option array
* Needs to be run after finished using remove/update_option
* @uses apply_filters() Calls 'cmb2_override_option_save_{$this->key}' hook
* to allow overwriting the option value to be stored.
*
* @since 1.0.1
* @param array $options Optional options to override
* @return bool Success/Failure
*/
public function set( $options = array() ) {
$this->options = ! empty( $options ) || empty( $options ) && empty( $this->key )
? $options
: $this->options;
if ( empty( $this->key ) ) {
return false;
}
$test_save = apply_filters( "cmb2_override_option_save_{$this->key}", 'cmb2_no_override_option_save', $this->options, $this );
if ( 'cmb2_no_override_option_save' !== $test_save ) {
return $test_save;
}
// If no override, update the option
return update_option( $this->key, $this->options );
}
/**
* Retrieve option value based on name of option.
* @uses apply_filters() Calls 'cmb2_override_option_get_{$this->key}' hook to allow
* overwriting the option value to be retrieved.
*
* @since 1.0.1
* @param mixed $default Optional. Default value to return if the option does not exist.
* @return mixed Value set for the option.
*/
public function get_options( $default = null ) {
if ( empty( $this->options ) && ! empty( $this->key ) ) {
$test_get = apply_filters( "cmb2_override_option_get_{$this->key}", 'cmb2_no_override_option_get', $default, $this );
if ( 'cmb2_no_override_option_get' !== $test_get ) {
$this->options = $test_get;
} else {
// If no override, get the option
$this->options = get_option( $this->key, $default );
}
}
return (array) $this->options;
}
}

View File

@ -0,0 +1,523 @@
<?php
/**
* CMB2 field sanitization
*
* @since 0.0.4
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*
* @method string _id()
*/
class CMB2_Sanitize {
/**
* A CMB field object
* @var CMB2_Field object
*/
public $field;
/**
* Field's value
* @var mixed
*/
public $value;
/**
* Setup our class vars
* @since 1.1.0
* @param CMB2_Field $field A CMB2 field object
* @param mixed $value Field value
*/
public function __construct( CMB2_Field $field, $value ) {
$this->field = $field;
$this->value = stripslashes_deep( $value ); // get rid of those evil magic quotes
}
/**
* Catchall method if field's 'sanitization_cb' is NOT defined, or field type does not have a corresponding validation method
* @since 1.0.0
* @param string $name Non-existent method name
* @param array $arguments All arguments passed to the method
*/
public function __call( $name, $arguments ) {
return $this->default_sanitization();
}
/**
* Default fallback sanitization method. Applies filters.
* @since 1.0.2
*/
public function default_sanitization() {
/**
* This exists for back-compatibility, but validation
* is not what happens here.
* @deprecated See documentation for "cmb2_sanitize_{$this->type()}".
*/
if ( function_exists( 'apply_filters_deprecated' ) ) {
$override_value = apply_filters_deprecated( "cmb2_validate_{$this->field->type()}", array( null, $this->value, $this->field->object_id, $this->field->args(), $this ), '2.0.0', "cmb2_sanitize_{$this->field->type()}" );
} else {
$override_value = apply_filters( "cmb2_validate_{$this->field->type()}", null, $this->value, $this->field->object_id, $this->field->args(), $this );
}
if ( null !== $override_value ) {
return $override_value;
}
$sanitized_value = '';
switch ( $this->field->type() ) {
case 'wysiwyg':
case 'textarea_small':
case 'oembed':
$sanitized_value = $this->textarea();
break;
case 'taxonomy_select':
case 'taxonomy_radio':
case 'taxonomy_radio_inline':
case 'taxonomy_multicheck':
case 'taxonomy_multicheck_inline':
$sanitized_value = $this->_taxonomy();
break;
case 'multicheck':
case 'multicheck_inline':
case 'file_list':
case 'group':
// no filtering
$sanitized_value = $this->value;
break;
default:
// Handle repeatable fields array
// We'll fallback to 'sanitize_text_field'
$sanitized_value = $this->_default_sanitization();
break;
}
return $this->_is_empty_array( $sanitized_value ) ? '' : $sanitized_value;
}
/**
* Default sanitization method, sanitize_text_field. Checks if value is array.
* @since 2.2.4
* @return mixed Sanitized value.
*/
protected function _default_sanitization() {
// Handle repeatable fields array
return is_array( $this->value ) ? array_map( 'sanitize_text_field', $this->value ) : sanitize_text_field( $this->value );
}
/**
* Sets the object terms to the object (if not options-page) and optionally returns the sanitized term values.
* @since 2.2.4
* @return mixed Blank value, or sanitized term values if "cmb2_return_taxonomy_values_{$cmb_id}" is true.
*/
protected function _taxonomy() {
$sanitized_value = '';
if ( ! $this->field->args( 'taxonomy' ) ) {
CMB2_Utils::log_if_debug( __METHOD__, __LINE__, "{$this->field->type()} {$this->field->_id()} is missing the 'taxonomy' parameter." );
} else {
if ( 'options-page' === $this->field->object_type ) {
$return_values = true;
} else {
wp_set_object_terms( $this->field->object_id, $this->value, $this->field->args( 'taxonomy' ) );
$return_values = false;
}
$cmb_id = $this->field->cmb_id;
/**
* Filter whether 'taxonomy_*' fields should return their value when being sanitized.
*
* By default, these fields do not return a value as we do not want them stored to meta
* (as they are stored as terms). This allows overriding that and is used by CMB2::get_sanitized_values().
*
* The dynamic portion of the hook, $cmb_id, refers to the this field's CMB2 box id.
*
* @since 2.2.4
*
* @param bool $return_values By default, this is only true for 'options-page' boxes. To enable:
* `add_filter( "cmb2_return_taxonomy_values_{$cmb_id}", '__return_true' );`
* @param CMB2_Sanitize $sanitizer This object.
*/
if ( apply_filters( "cmb2_return_taxonomy_values_{$cmb_id}", $return_values, $this ) ) {
$sanitized_value = $this->_default_sanitization();
}
}
return $sanitized_value;
}
/**
* Simple checkbox validation
* @since 1.0.1
* @return string|false 'on' or false
*/
public function checkbox() {
return $this->value === 'on' ? 'on' : false;
}
/**
* Validate url in a meta value
* @since 1.0.1
* @return string Empty string or escaped url
*/
public function text_url() {
$protocols = $this->field->args( 'protocols' );
// for repeatable
if ( is_array( $this->value ) ) {
foreach ( $this->value as $key => $val ) {
$this->value[ $key ] = $val ? esc_url_raw( $val, $protocols ) : $this->field->get_default();
}
} else {
$this->value = $this->value ? esc_url_raw( $this->value, $protocols ) : $this->field->get_default();
}
return $this->value;
}
public function colorpicker() {
// for repeatable
if ( is_array( $this->value ) ) {
$check = $this->value;
$this->value = array();
foreach ( $check as $key => $val ) {
if ( $val && '#' != $val ) {
$this->value[ $key ] = esc_attr( $val );
}
}
} else {
$this->value = ! $this->value || '#' == $this->value ? '' : esc_attr( $this->value );
}
return $this->value;
}
/**
* Validate email in a meta value
* @since 1.0.1
* @return string Empty string or sanitized email
*/
public function text_email() {
// for repeatable
if ( is_array( $this->value ) ) {
foreach ( $this->value as $key => $val ) {
$val = trim( $val );
$this->value[ $key ] = is_email( $val ) ? $val : '';
}
} else {
$this->value = trim( $this->value );
$this->value = is_email( $this->value ) ? $this->value : '';
}
return $this->value;
}
/**
* Validate money in a meta value
* @since 1.0.1
* @return string Empty string or sanitized money value
*/
public function text_money() {
if ( ! $this->value ) {
return '';
}
global $wp_locale;
$search = array( $wp_locale->number_format['thousands_sep'], $wp_locale->number_format['decimal_point'] );
$replace = array( '', '.' );
// for repeatable
if ( is_array( $this->value ) ) {
foreach ( $this->value as $key => $val ) {
if ( $val ) {
$this->value[ $key ] = number_format_i18n( (float) str_ireplace( $search, $replace, $val ), 2 );
}
}
} else {
$this->value = number_format_i18n( (float) str_ireplace( $search, $replace, $this->value ), 2 );
}
return $this->value;
}
/**
* Converts text date to timestamp
* @since 1.0.2
* @return string Timestring
*/
public function text_date_timestamp() {
return is_array( $this->value )
? array_map( array( $this->field, 'get_timestamp_from_value' ), $this->value )
: $this->field->get_timestamp_from_value( $this->value );
}
/**
* Datetime to timestamp
* @since 1.0.1
* @return string|array Timestring
*/
public function text_datetime_timestamp( $repeat = false ) {
$test = is_array( $this->value ) ? array_filter( $this->value ) : '';
if ( empty( $test ) ) {
return '';
}
$repeat_value = $this->_check_repeat( __FUNCTION__, $repeat );
if ( false !== $repeat_value ) {
return $repeat_value;
}
if ( isset( $this->value['date'], $this->value['time'] ) ) {
$this->value = $this->field->get_timestamp_from_value( $this->value['date'] . ' ' . $this->value['time'] );
}
if ( $tz_offset = $this->field->field_timezone_offset() ) {
$this->value += (int) $tz_offset;
}
return $this->value;
}
/**
* Datetime to timestamp with timezone
* @since 1.0.1
* @return string Timestring
*/
public function text_datetime_timestamp_timezone( $repeat = false ) {
static $utc_values = array();
$test = is_array( $this->value ) ? array_filter( $this->value ) : '';
if ( empty( $test ) ) {
return '';
}
$utc_key = $this->field->_id() . '_utc';
$repeat_value = $this->_check_repeat( __FUNCTION__, $repeat );
if ( false !== $repeat_value ) {
if ( ! empty( $utc_values[ $utc_key ] ) ) {
$this->_save_utc_value( $utc_key, $utc_values[ $utc_key ] );
unset( $utc_values[ $utc_key ] );
}
return $repeat_value;
}
$tzstring = null;
if ( is_array( $this->value ) && array_key_exists( 'timezone', $this->value ) ) {
$tzstring = $this->value['timezone'];
}
if ( empty( $tzstring ) ) {
$tzstring = CMB2_Utils::timezone_string();
}
$offset = CMB2_Utils::timezone_offset( $tzstring );
if ( 'UTC' === substr( $tzstring, 0, 3 ) ) {
$tzstring = timezone_name_from_abbr( '', $offset, 0 );
/*
* timezone_name_from_abbr() returns false if not found based on offset.
* Since there are currently some invalid timezones in wp_timezone_dropdown(),
* fallback to an offset of 0 (UTC+0)
* https://core.trac.wordpress.org/ticket/29205
*/
$tzstring = false !== $tzstring ? $tzstring : timezone_name_from_abbr( '', 0, 0 );
}
$full_format = $this->field->args['date_format'] . ' ' . $this->field->args['time_format'];
$full_date = $this->value['date'] . ' ' . $this->value['time'];
try {
$datetime = date_create_from_format( $full_format, $full_date );
if ( ! is_object( $datetime ) ) {
$this->value = $utc_stamp = '';
} else {
$timestamp = $datetime->setTimezone( new DateTimeZone( $tzstring ) )->getTimestamp();
$utc_stamp = $timestamp - $offset;
$this->value = serialize( $datetime );
}
if ( $this->field->group ) {
$this->value = array(
'supporting_field_value' => $utc_stamp,
'supporting_field_id' => $utc_key,
'value' => $this->value,
);
} else {
// Save the utc timestamp supporting field
if ( $repeat ) {
$utc_values[ $utc_key ][] = $utc_stamp;
} else {
$this->_save_utc_value( $utc_key, $utc_stamp );
}
}
} catch ( Exception $e ) {
$this->value = '';
CMB2_Utils::log_if_debug( __METHOD__, __LINE__, $e->getMessage() );
}
return $this->value;
}
/**
* Sanitize textareas and wysiwyg fields
* @since 1.0.1
* @return string Sanitized data
*/
public function textarea() {
return is_array( $this->value ) ? array_map( 'wp_kses_post', $this->value ) : wp_kses_post( $this->value );
}
/**
* Sanitize code textareas
* @since 1.0.2
* @return string Sanitized data
*/
public function textarea_code( $repeat = false ) {
$repeat_value = $this->_check_repeat( __FUNCTION__, $repeat );
if ( false !== $repeat_value ) {
return $repeat_value;
}
return htmlspecialchars_decode( stripslashes( $this->value ) );
}
/**
* Handles saving of attachment post ID and sanitizing file url
* @since 1.1.0
* @return string Sanitized url
*/
public function file() {
$file_id_key = $this->field->_id() . '_id';
if ( $this->field->group ) {
// Return an array with url/id if saving a group field
$this->value = $this->_get_group_file_value_array( $file_id_key );
} else {
$this->_save_file_id_value( $file_id_key );
$this->text_url();
}
return $this->value;
}
/**
* Gets the values for the `file` field type from the data being saved.
* @since 2.2.0
*/
public function _get_group_file_value_array( $id_key ) {
$alldata = $this->field->group->data_to_save;
$base_id = $this->field->group->_id();
$i = $this->field->group->index;
// Check group $alldata data
$id_val = isset( $alldata[ $base_id ][ $i ][ $id_key ] )
? absint( $alldata[ $base_id ][ $i ][ $id_key ] )
: '';
// We don't want to save 0 to the DB for file fields.
if ( 0 === $id_val ) {
$id_val = '';
}
return array(
'value' => $this->text_url(),
'supporting_field_value' => $id_val,
'supporting_field_id' => $id_key,
);
}
/**
* Peforms saving of `file` attachement's ID
* @since 1.1.0
*/
public function _save_file_id_value( $file_id_key ) {
$id_field = $this->_new_supporting_field( $file_id_key );
// Check standard data_to_save data
$id_val = isset( $this->field->data_to_save[ $file_id_key ] )
? $this->field->data_to_save[ $file_id_key ]
: null;
// If there is no ID saved yet, try to get it from the url
if ( $this->value && ! $id_val ) {
$id_val = CMB2_Utils::image_id_from_url( $this->value );
}
return $id_field->save_field( $id_val );
}
/**
* Peforms saving of `text_datetime_timestamp_timezone` utc timestamp
* @since 2.2.0
*/
public function _save_utc_value( $utc_key, $utc_stamp ) {
return $this->_new_supporting_field( $utc_key )->save_field( $utc_stamp );
}
/**
* Returns a new, supporting, CMB2_Field object based on a new field id.
* @since 2.2.0
*/
public function _new_supporting_field( $new_field_id ) {
return $this->field->get_field_clone( array(
'id' => $new_field_id,
'sanitization_cb' => false,
) );
}
/**
* If repeating, loop through and re-apply sanitization method
* @since 1.1.0
* @param string $method Class method
* @param bool $repeat Whether repeating or not
* @return mixed Sanitized value
*/
public function _check_repeat( $method, $repeat ) {
if ( $repeat || ! $this->field->args( 'repeatable' ) ) {
return false;
}
$values_array = $this->value;
$new_value = array();
foreach ( $values_array as $iterator => $this->value ) {
if ( $this->value ) {
$val = $this->$method( true );
if ( ! empty( $val ) ) {
$new_value[] = $val;
}
}
}
$this->value = $new_value;
return empty( $this->value ) ? null : $this->value;
}
/**
* Determine if passed value is an empty array
* @since 2.0.6
* @param mixed $to_check Value to check
* @return boolean Whether value is an array that's empty
*/
public function _is_empty_array( $to_check ) {
if ( is_array( $to_check ) ) {
$cleaned_up = array_filter( $to_check );
return empty( $cleaned_up );
}
return false;
}
}

View File

@ -0,0 +1,175 @@
<?php
/**
* Show On Filters
* Use the 'cmb2_show_on' filter to further refine the conditions
* under which a metabox is displayed.
* Below you can limit it by ID and page template
*
* All methods in this class are automatically filtered
*
* @since 1.0.0
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Show_Filters {
/**
* Get Show_on key. backwards compatible w/ 'key' indexes
*
* @since 2.0.0
*
* @param array $meta_box_args Metabox config array
*
* @return mixed show_on key or false
*/
private static function get_show_on_key( $meta_box_args ) {
$show_on = isset( $meta_box_args['show_on'] ) ? (array) $meta_box_args['show_on'] : false;
if ( $show_on && is_array( $show_on ) ) {
if ( array_key_exists( 'key', $show_on ) ) {
return $show_on['key'];
}
$keys = array_keys( $show_on );
return $keys[0];
}
return false;
}
/**
* Get Show_on value. backwards compatible w/ 'value' indexes
*
* @since 2.0.0
*
* @param array $meta_box_args Metabox config array
*
* @return mixed show_on value or false
*/
private static function get_show_on_value( $meta_box_args ) {
$show_on = isset( $meta_box_args['show_on'] ) ? (array) $meta_box_args['show_on'] : false;
if ( $show_on && is_array( $show_on ) ) {
if ( array_key_exists( 'value', $show_on ) ) {
return $show_on['value'];
}
$keys = array_keys( $show_on );
return $show_on[ $keys[0] ];
}
return array();
}
/**
* Add metaboxes for an specific ID
* @since 1.0.0
* @param bool $display To display or not
* @param array $meta_box_args Metabox config array
* @param CMB2 $cmb The CMB2 instance.
* @return bool Whether to display this metabox on the current page.
*/
public static function check_id( $display, $meta_box_args, $cmb ) {
$key = self::get_show_on_key( $meta_box_args );
if ( ! $key || 'id' !== $key ) {
return $display;
}
$object_id = is_admin() ? $cmb->object_id() : get_the_ID();
if ( ! $object_id ) {
return false;
}
// If current page id is in the included array, display the metabox
return in_array( $object_id, (array) self::get_show_on_value( $meta_box_args ) );
}
/**
* Add metaboxes for an specific Page Template
* @since 1.0.0
* @param bool $display To display or not
* @param array $meta_box_args Metabox config array
* @return bool Whether to display this metabox on the current page.
*/
public static function check_page_template( $display, $meta_box_args, $cmb ) {
$key = self::get_show_on_key( $meta_box_args );
if ( ! $key || 'page-template' !== $key ) {
return $display;
}
$object_id = $cmb->object_id();
if ( ! $object_id || 'post' !== $cmb->object_type() ) {
return false;
}
// Get current template
$current_template = get_post_meta( $object_id, '_wp_page_template', true );
// See if there's a match
if ( $current_template && in_array( $current_template, (array) self::get_show_on_value( $meta_box_args ) ) ) {
return true;
}
return false;
}
/**
* Only show options-page metaboxes on their options page (but only enforce on the admin side)
* @since 1.0.0
* @param bool $display To display or not
* @param array $meta_box_args Metabox config array
* @return bool Whether to display this metabox on the current page.
*/
public static function check_admin_page( $display, $meta_box_args ) {
$key = self::get_show_on_key( $meta_box_args );
// check if this is a 'options-page' metabox
if ( ! $key || 'options-page' !== $key ) {
return $display;
}
// Enforce 'show_on' filter in the admin
if ( is_admin() ) {
// If there is no 'page' query var, our filter isn't applicable
if ( ! isset( $_GET['page'] ) ) {
return $display;
}
$show_on = self::get_show_on_value( $meta_box_args );
if ( empty( $show_on ) ) {
return false;
}
if ( is_array( $show_on ) ) {
foreach ( $show_on as $page ) {
if ( $_GET['page'] == $page ) {
return true;
}
}
} else {
if ( $_GET['page'] == $show_on ) {
return true;
}
}
return false;
}
// Allow options-page metaboxes to be displayed anywhere on the front-end
return true;
}
}

View File

@ -0,0 +1,634 @@
<?php
/**
* CMB field type objects
*
* @since 1.0.0
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*
* @method string _id()
* @method string _name()
* @method string _desc()
* @method string _text()
* @method string concat_attrs()
*/
class CMB2_Types {
/**
* An iterator value for repeatable fields
* @var integer
* @since 1.0.0
*/
public $iterator = 0;
/**
* Current CMB2_Field field object
* @var CMB2_Field object
* @since 1.0.0
*/
public $field;
/**
* Current CMB2_Type_Base object
* @var CMB2_Type_Base object
* @since 2.2.2
*/
public $type = null;
public function __construct( CMB2_Field $field ) {
$this->field = $field;
}
/**
* Default fallback. Allows rendering fields via "cmb2_render_$fieldtype" hook
* @since 1.0.0
* @param string $fieldtype Non-existent field type name
* @param array $arguments All arguments passed to the method
*/
public function __call( $fieldtype, $arguments ) {
// Check for methods to be proxied to the CMB2_Type_Base object.
if ( $exists = $this->maybe_proxy_method( $fieldtype, $arguments ) ) {
return $exists['value'];
}
// Check for custom field type class.
if ( $object = $this->maybe_custom_field_object( $fieldtype, $arguments ) ) {
return $object->render();
}
/**
* Pass non-existent field types through an action.
*
* The dynamic portion of the hook name, $fieldtype, refers to the field type.
*
* @param array $field The passed in `CMB2_Field` object
* @param mixed $escaped_value The value of this field escaped.
* It defaults to `sanitize_text_field`.
* If you need the unescaped value, you can access it
* via `$field->value()`
* @param int $object_id The ID of the current object
* @param string $object_type The type of object you are working with.
* Most commonly, `post` (this applies to all post-types),
* but could also be `comment`, `user` or `options-page`.
* @param object $field_type_object This `CMB2_Types` object
*/
do_action( "cmb2_render_{$fieldtype}", $this->field, $this->field->escaped_value(), $this->field->object_id, $this->field->object_type, $this );
}
/**
* Render a field (and handle repeatable)
* @since 1.1.0
*/
public function render() {
if ( $this->field->args( 'repeatable' ) ) {
$this->render_repeatable_field();
} else {
$this->_render();
}
}
/**
* Render a field type
* @since 1.1.0
*/
protected function _render() {
$this->field->peform_param_callback( 'before_field' );
echo $this->{$this->field->type()}();
$this->field->peform_param_callback( 'after_field' );
}
/**
* Proxies the method call to the CMB2_Type_Base object, if it exists, otherwise returns a default fallback value.
*
* @since 2.2.2
*
* @param string $method Method to call on the CMB2_Type_Base object.
* @param mixed $default Default fallback value if method is not found.
* @param array $args Optional arguments to pass to proxy method.
*
* @return mixed Results from called method.
*/
protected function proxy_method( $method, $default, $args = array() ) {
if ( ! is_object( $this->type ) ) {
$this->guess_type_object( $method );
}
if ( is_object( $this->type ) && method_exists( $this->type, $method ) ) {
return empty( $args )
? $this->type->$method()
: call_user_func_array( array( $this->type, $method ), $args );
}
return $default;
}
/**
* If no CMB2_Types::$type object is initiated when a proxy method is called, it means
* it's a custom field type (which SHOULD be instantiating a Type), but let's try and
* guess the type object for them and instantiate it.
*
* @since 2.2.3
*
* @param string $method Method attempting to be called on the CMB2_Type_Base object.
*/
protected function guess_type_object( $method ) {
$fieldtype = $this->field->type();
// Try to "guess" the Type object based on the method requested.
switch ( $method ) {
case 'select_option':
case 'list_input':
case 'list_input_checkbox':
case 'concat_items':
$this->get_new_render_type( $fieldtype, 'CMB2_Type_Select' );
break;
case 'is_valid_img_ext':
case 'img_status_output':
case 'file_status_output':
$this->get_new_render_type( $fieldtype, 'CMB2_Type_File_Base' );
break;
case 'parse_picker_options':
$this->get_new_render_type( $fieldtype, 'CMB2_Type_Text_Date' );
break;
case 'get_object_terms':
case 'get_terms':
$this->get_new_render_type( $fieldtype, 'CMB2_Type_Taxonomy_Multicheck' );
break;
case 'date_args':
case 'time_args':
$this->get_new_render_type( $fieldtype, 'CMB2_Type_Text_Datetime_Timestamp' );
break;
case 'parse_args':
$this->get_new_render_type( $fieldtype, 'CMB2_Type_Text' );
break;
}
return null !== $this->type;
}
/**
* Check for methods to be proxied to the CMB2_Type_Base object.
* @since 2.2.4
* @param string $method The possible method to proxy.
* @param array $arguments All arguments passed to the method.
* @return bool|array False if not proxied, else array with 'value' key being the return of the method.
*/
public function maybe_proxy_method( $method, $arguments ) {
$exists = false;
$proxied = array(
'get_object_terms' => array(),
'is_valid_img_ext' => false,
'parse_args' => array(),
'concat_items' => '',
'select_option' => '',
'list_input' => '',
'list_input_checkbox' => '',
'img_status_output' => '',
'file_status_output' => '',
'parse_picker_options' => array(),
);
if ( isset( $proxied[ $method ] ) ) {
$exists = array(
// Ok, proxy the method call to the CMB2_Type_Base object.
'value' => $this->proxy_method( $method, $proxied[ $method ], $arguments ),
);
}
return $exists;
}
/**
* Checks for a custom field CMB2_Type_Base class to use for rendering.
* @since 2.2.4
* @param string $fieldtype Non-existent field type name
* @param array $args Optional field arguments.
* @return CMB2_Type_Base Type object.
*/
public function maybe_custom_field_object( $fieldtype, $args = array() ) {
if ( $render_class_name = $this->get_render_type_class( $fieldtype ) ) {
$this->type = new $render_class_name( $this, $args );
if ( ! ( $this->type instanceof CMB2_Type_Base ) ) {
throw new Exception( __( 'Custom CMB2 field type classes must extend CMB2_Type_Base.', 'cmb2' ) );
}
}
return $this->type;
}
/**
* Gets the render type CMB2_Type_Base object to use for rendering the field.
* @since 2.2.4
* @param string $fieldtype The type of field being rendered.
* @param string $render_class_name The default field type class to use. Defaults to null.
* @param array $args Optional arguments to pass to type class.
* @param mixed $additional Optional additional argument to pass to type class.
* @return CMB2_Type_Base Type object.
*/
public function get_new_render_type( $fieldtype, $render_class_name = null, $args = array(), $additional = '' ) {
$render_class_name = $this->get_render_type_class( $fieldtype, $render_class_name );
$this->type = new $render_class_name( $this, $args, $additional );
return $this->type;
}
/**
* Checks for the render type class to use for rendering the field.
* @since 2.2.4
* @param string $fieldtype The type of field being rendered.
* @param string $render_class_name The default field type class to use. Defaults to null.
* @return string The field type class to use.
*/
public function get_render_type_class( $fieldtype, $render_class_name = null ) {
$render_class_name = $this->field->args( 'render_class' ) ? $this->field->args( 'render_class' ) : $render_class_name;
if ( has_action( "cmb2_render_class_{$fieldtype}" ) ) {
/**
* Filters the custom field type class used for rendering the field. Class is required to extend CMB2_Type_Base.
*
* The dynamic portion of the hook name, $fieldtype, refers to the (custom) field type.
*
* @since 2.2.4
*
* @param string $render_class_name The custom field type class to use. Default null.
* @param object $field_type_object This `CMB2_Types` object.
*/
$render_class_name = apply_filters( "cmb2_render_class_{$fieldtype}", $render_class_name, $this );
}
return $render_class_name && class_exists( $render_class_name ) ? $render_class_name : false;
}
/**
* Retrieve text parameter from field's options array (if it has one), or use fallback text
* @since 2.0.0
* @param string $text_key Key in field's options array
* @param string $fallback Fallback text
* @return string Text
*/
public function _text( $text_key, $fallback = '' ) {
return $this->field->get_string( $text_key, $fallback );
}
/**
* Determine a file's extension
* @since 1.0.0
* @param string $file File url
* @return string|false File extension or false
*/
public function get_file_ext( $file ) {
return CMB2_Utils::get_file_ext( $file );
}
/**
* Get the file name from a url
* @since 2.0.0
* @param string $value File url or path
* @return string File name
*/
public function get_file_name_from_path( $value ) {
return CMB2_Utils::get_file_name_from_path( $value );
}
/**
* Combines attributes into a string for a form element
* @since 1.1.0
* @param array $attrs Attributes to concatenate
* @param array $attr_exclude Attributes that should NOT be concatenated
* @return string String of attributes for form element
*/
public function concat_attrs( $attrs, $attr_exclude = array() ) {
return CMB2_Utils::concat_attrs( $attrs, $attr_exclude );
}
/**
* Generates repeatable field table markup
* @since 1.0.0
*/
public function render_repeatable_field() {
$table_id = $this->field->id() . '_repeat';
$this->_desc( true, true, true );
?>
<div id="<?php echo $table_id; ?>" class="cmb-repeat-table cmb-nested">
<div class="cmb-tbody cmb-field-list">
<?php $this->repeatable_rows(); ?>
</div>
</div>
<p class="cmb-add-row">
<button type="button" data-selector="<?php echo $table_id; ?>" class="cmb-add-row-button button"><?php echo esc_html( $this->_text( 'add_row_text', esc_html__( 'Add Row', 'cmb2' ) ) ); ?></button>
</p>
<?php
// reset iterator
$this->iterator = 0;
}
/**
* Generates repeatable field rows
* @since 1.1.0
*/
public function repeatable_rows() {
$meta_value = array_filter( (array) $this->field->escaped_value() );
// check for default content
$default = $this->field->get_default();
// check for saved data
if ( ! empty( $meta_value ) ) {
$meta_value = is_array( $meta_value ) ? array_filter( $meta_value ) : $meta_value;
$meta_value = ! empty( $meta_value ) ? $meta_value : $default;
} else {
$meta_value = $default;
}
// Loop value array and add a row
if ( ! empty( $meta_value ) ) {
$count = count( $meta_value );
foreach ( (array) $meta_value as $val ) {
$this->field->escaped_value = $val;
$this->repeat_row( $count < 2 );
$this->iterator++;
}
} else {
// If value is empty (including empty array), then clear the value.
$this->field->escaped_value = $this->field->value = null;
// Otherwise add one row
$this->repeat_row( true );
}
// Then add an empty row
$this->field->escaped_value = '';
$this->iterator = $this->iterator ? $this->iterator : 1;
$this->repeat_row( false, 'empty-row hidden' );
}
/**
* Generates a repeatable row's markup
* @since 1.1.0
* @param bool $disable_remover Whether remove button should be disabled
* @param string $class Repeatable table row's class
*/
protected function repeat_row( $disable_remover = false, $class = 'cmb-repeat-row' ) {
$disabled = $disable_remover ? ' button-disabled' : '';
?>
<div class="cmb-row <?php echo $class; ?>">
<div class="cmb-td">
<?php $this->_render(); ?>
</div>
<div class="cmb-td cmb-remove-row">
<button type="button" class="button cmb-remove-row-button<?php echo $disabled; ?>"><?php echo esc_html( $this->_text( 'remove_row_text', esc_html__( 'Remove', 'cmb2' ) ) ); ?></button>
</div>
</div>
<?php
}
/**
* Generates description markup
* @since 1.0.0
* @param boolean $paragraph Paragraph tag or span
* @param boolean $echo Whether to echo description or only return it
* @return string Field's description markup
*/
public function _desc( $paragraph = false, $echo = false, $repeat_group = false ) {
// Prevent description from printing multiple times for repeatable fields
if ( ! $repeat_group && ( $this->field->args( 'repeatable' ) || $this->iterator > 0 ) ) {
return '';
}
$desc = $this->field->args( 'description' );
if ( ! $desc ) {
return;
}
$tag = $paragraph ? 'p' : 'span';
$desc = sprintf( "\n" . '<%1$s class="cmb2-metabox-description">%2$s</%1$s>' . "\n", $tag, $desc );
if ( $echo ) {
echo $desc;
}
return $desc;
}
/**
* Generate field name attribute
* @since 1.1.0
* @param string $suffix For multi-part fields
* @return string Name attribute
*/
public function _name( $suffix = '' ) {
return $this->field->args( '_name' ) . ( $this->field->args( 'repeatable' ) ? '[' . $this->iterator . ']' : '' ) . $suffix;
}
/**
* Generate field id attribute
* @since 1.1.0
* @param string $suffix For multi-part fields
* @return string Id attribute
*/
public function _id( $suffix = '' ) {
return $this->field->id() . $suffix . ( $this->field->args( 'repeatable' ) ? '_' . $this->iterator . '" data-iterator="' . $this->iterator : '' );
}
/**
* Handles outputting an 'input' element
* @since 1.1.0
* @param array $args Override arguments
* @param string $type Field type
* @return string Form input element
*/
public function input( $args = array(), $type = __FUNCTION__ ) {
return $this->get_new_render_type( 'text', 'CMB2_Type_Text', $args, $type )->render();
}
/**
* Handles outputting an 'textarea' element
* @since 1.1.0
* @param array $args Override arguments
* @return string Form textarea element
*/
public function textarea( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Textarea', $args )->render();
}
/**
* Begin Field Types
*/
public function text() {
return $this->input();
}
public function hidden() {
$args = array(
'type' => 'hidden',
'desc' => '',
'class' => 'cmb2-hidden',
);
if ( $this->field->group ) {
$args['data-groupid'] = $this->field->group->id();
$args['data-iterator'] = $this->iterator;
}
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text', $args, 'input' )->render();
}
public function text_small() {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text', array(
'class' => 'cmb2-text-small',
'desc' => $this->_desc(),
), 'input' )->render();
}
public function text_medium() {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text', array(
'class' => 'cmb2-text-medium',
'desc' => $this->_desc(),
), 'input' )->render();
}
public function text_email() {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text', array(
'class' => 'cmb2-text-email cmb2-text-medium',
'type' => 'email',
), 'input' )->render();
}
public function text_url() {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text', array(
'class' => 'cmb2-text-url cmb2-text-medium regular-text',
'value' => $this->field->escaped_value( 'esc_url' ),
), 'input' )->render();
}
public function text_money() {
$input = $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text', array(
'class' => 'cmb2-text-money',
'desc' => $this->_desc(),
), 'input' )->render();
return ( ! $this->field->get_param_callback_result( 'before_field' ) ? '$ ' : ' ' ) . $input;
}
public function textarea_small() {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Textarea', array(
'class' => 'cmb2-textarea-small',
'rows' => 4,
) )->render();
}
public function textarea_code( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Textarea_Code', $args )->render();
}
public function wysiwyg( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Wysiwyg', $args )->render();
}
public function text_date( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text_Date', $args )->render();
}
// Alias for text_date
public function text_date_timestamp( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text_Date', $args )->render();
}
public function text_time( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text_Time', $args )->render();
}
public function text_datetime_timestamp( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text_Datetime_Timestamp', $args )->render();
}
public function text_datetime_timestamp_timezone( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text_Datetime_Timestamp_Timezone', $args )->render();
}
public function select_timezone( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Select_Timezone', $args )->render();
}
public function colorpicker( $args = array(), $meta_value = '' ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Colorpicker', $args, $meta_value )->render();
}
public function title( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Title', $args )->render();
}
public function select( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Select', $args )->render();
}
public function taxonomy_select( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Taxonomy_Select', $args )->render();
}
public function radio( $args = array(), $type = __FUNCTION__ ) {
return $this->get_new_render_type( $type, 'CMB2_Type_Radio', $args, $type )->render();
}
public function radio_inline( $args = array() ) {
return $this->radio( $args, __FUNCTION__ );
}
public function multicheck( $type = 'checkbox' ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Multicheck', array(), $type )->render();
}
public function multicheck_inline() {
return $this->multicheck( 'multicheck_inline' );
}
public function checkbox( $args = array(), $is_checked = null ) {
// Avoid get_new_render_type since we need a different default for the 3rd argument than ''.
$render_class_name = $this->get_render_type_class( __FUNCTION__, 'CMB2_Type_Checkbox' );
$this->type = new $render_class_name( $this, $args, $is_checked );
return $this->type->render();
}
public function taxonomy_radio( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Taxonomy_Radio', $args )->render();
}
public function taxonomy_radio_inline( $args = array() ) {
return $this->taxonomy_radio( $args );
}
public function taxonomy_multicheck( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Taxonomy_Multicheck', $args )->render();
}
public function taxonomy_multicheck_inline( $args = array() ) {
return $this->taxonomy_multicheck( $args );
}
public function oembed( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Oembed', $args )->render();
}
public function file_list( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_File_List', $args )->render();
}
public function file( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_File', $args )->render();
}
}

View File

@ -0,0 +1,588 @@
<?php
/**
* CMB2 Utilities
*
* @since 1.1.0
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Utils {
/**
* The WordPress ABSPATH constant.
* @var string
* @since 2.2.3
*/
protected static $ABSPATH = ABSPATH;
/**
* The url which is used to load local resources.
* @var string
* @since 2.0.0
*/
protected static $url = '';
/**
* Utility method that attempts to get an attachment's ID by it's url
* @since 1.0.0
* @param string $img_url Attachment url
* @return int|false Attachment ID or false
*/
public static function image_id_from_url( $img_url ) {
$attachment_id = 0;
$dir = wp_upload_dir();
// Is URL in uploads directory?
if ( false === strpos( $img_url, $dir['baseurl'] . '/' ) ) {
return false;
}
$file = basename( $img_url );
$query_args = array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'fields' => 'ids',
'meta_query' => array(
array(
'value' => $file,
'compare' => 'LIKE',
'key' => '_wp_attachment_metadata',
),
)
);
$query = new WP_Query( $query_args );
if ( $query->have_posts() ) {
foreach ( $query->posts as $post_id ) {
$meta = wp_get_attachment_metadata( $post_id );
$original_file = basename( $meta['file'] );
$cropped_image_files = isset( $meta['sizes'] ) ? wp_list_pluck( $meta['sizes'], 'file' ) : array();
if ( $original_file === $file || in_array( $file, $cropped_image_files ) ) {
$attachment_id = $post_id;
break;
}
}
}
return 0 === $attachment_id ? false : $attachment_id;
}
/**
* Utility method to get a combined list of default and custom registered image sizes
* @since 2.2.4
* @link http://core.trac.wordpress.org/ticket/18947
* @global array $_wp_additional_image_sizes
* @return array The image sizes
*/
static function get_available_image_sizes() {
global $_wp_additional_image_sizes;
$default_image_sizes = array( 'thumbnail', 'medium', 'large' );
foreach ( $default_image_sizes as $size ) {
$image_sizes[ $size ] = array(
'height' => intval( get_option( "{$size}_size_h" ) ),
'width' => intval( get_option( "{$size}_size_w" ) ),
'crop' => get_option( "{$size}_crop" ) ? get_option( "{$size}_crop" ) : false,
);
}
if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) ) {
$image_sizes = array_merge( $image_sizes, $_wp_additional_image_sizes );
}
return $image_sizes;
}
/**
* Utility method to return the closest named size from an array of values
*
* Based off of WordPress's image_get_intermediate_size()
* If the size matches an existing size then it will be used. If there is no
* direct match, then the nearest image size larger than the specified size
* will be used. If nothing is found, then the function will return false.
* Uses get_available_image_sizes() to get all available sizes.
*
* @since 2.2.4
* @param array|string $size Image size. Accepts an array of width and height (in that order)
* @return false|string Named image size e.g. 'thumbnail'
*/
public static function get_named_size( $size ) {
$data = array();
// Find the best match when '$size' is an array.
if ( is_array( $size ) ) {
$image_sizes = self::get_available_image_sizes();
$candidates = array();
foreach ( $image_sizes as $_size => $data ) {
// If there's an exact match to an existing image size, short circuit.
if ( $data['width'] == $size[0] && $data['height'] == $size[1] ) {
$candidates[ $data['width'] * $data['height'] ] = array( $_size, $data );
break;
}
// If it's not an exact match, consider larger sizes with the same aspect ratio.
if ( $data['width'] >= $size[0] && $data['height'] >= $size[1] ) {
/*
* To test for varying crops, we constrain the dimensions of the larger image
* to the dimensions of the smaller image and see if they match.
*/
if ( $data['width'] > $size[0] ) {
$constrained_size = wp_constrain_dimensions( $data['width'], $data['height'], $size[0] );
$expected_size = array( $size[0], $size[1] );
} else {
$constrained_size = wp_constrain_dimensions( $size[0], $size[1], $data['width'] );
$expected_size = array( $data['width'], $data['height'] );
}
// If the image dimensions are within 1px of the expected size, we consider it a match.
$matched = ( abs( $constrained_size[0] - $expected_size[0] ) <= 1 && abs( $constrained_size[1] - $expected_size[1] ) <= 1 );
if ( $matched ) {
$candidates[ $data['width'] * $data['height'] ] = array( $_size, $data );
}
}
}
if ( ! empty( $candidates ) ) {
// Sort the array by size if we have more than one candidate.
if ( 1 < count( $candidates ) ) {
ksort( $candidates );
}
$data = array_shift( $candidates );
$data = $data[0];
}
/*
* When the size requested is smaller than the thumbnail dimensions, we
* fall back to the thumbnail size.
*/
elseif ( ! empty( $image_sizes['thumbnail'] ) && $image_sizes['thumbnail']['width'] >= $size[0] && $image_sizes['thumbnail']['width'] >= $size[1] ) {
$data = 'thumbnail';
} else {
return false;
}
} elseif ( ! empty( $image_sizes[ $size ] ) ) {
$data = $size;
}
// If we still don't have a match at this point, return false.
if ( empty( $data ) ) {
return false;
}
return $data;
}
/**
* Utility method that returns time string offset by timezone
* @since 1.0.0
* @param string $tzstring Time string
* @return string Offset time string
*/
public static function timezone_offset( $tzstring ) {
$tz_offset = 0;
if ( ! empty( $tzstring ) && is_string( $tzstring ) ) {
if ( 'UTC' === substr( $tzstring, 0, 3 ) ) {
$tzstring = str_replace( array( ':15', ':30', ':45' ), array( '.25', '.5', '.75' ), $tzstring );
return intval( floatval( substr( $tzstring, 3 ) ) * HOUR_IN_SECONDS );
}
try {
$date_time_zone_selected = new DateTimeZone( $tzstring );
$tz_offset = timezone_offset_get( $date_time_zone_selected, date_create() );
} catch ( Exception $e ) {
self::log_if_debug( __METHOD__, __LINE__, $e->getMessage() );
}
}
return $tz_offset;
}
/**
* Utility method that returns a timezone string representing the default timezone for the site.
*
* Roughly copied from WordPress, as get_option('timezone_string') will return
* an empty string if no value has been set on the options page.
* A timezone string is required by the wp_timezone_choice() used by the
* select_timezone field.
*
* @since 1.0.0
* @return string Timezone string
*/
public static function timezone_string() {
$current_offset = get_option( 'gmt_offset' );
$tzstring = get_option( 'timezone_string' );
// Remove old Etc mappings. Fallback to gmt_offset.
if ( false !== strpos( $tzstring, 'Etc/GMT' ) ) {
$tzstring = '';
}
if ( empty( $tzstring ) ) { // Create a UTC+- zone if no timezone string exists
if ( 0 == $current_offset ) {
$tzstring = 'UTC+0';
} elseif ( $current_offset < 0 ) {
$tzstring = 'UTC' . $current_offset;
} else {
$tzstring = 'UTC+' . $current_offset;
}
}
return $tzstring;
}
/**
* Returns a timestamp, first checking if value already is a timestamp.
* @since 2.0.0
* @param string|int $string Possible timestamp string
* @return int Time stamp
*/
public static function make_valid_time_stamp( $string ) {
if ( ! $string ) {
return 0;
}
return self::is_valid_time_stamp( $string )
? (int) $string :
strtotime( (string) $string );
}
/**
* Determine if a value is a valid timestamp
* @since 2.0.0
* @param mixed $timestamp Value to check
* @return boolean Whether value is a valid timestamp
*/
public static function is_valid_time_stamp( $timestamp ) {
return (string) (int) $timestamp === (string) $timestamp
&& $timestamp <= PHP_INT_MAX
&& $timestamp >= ~PHP_INT_MAX;
}
/**
* Checks if a value is 'empty'. Still accepts 0.
* @since 2.0.0
* @param mixed $value Value to check
* @return bool True or false
*/
public static function isempty( $value ) {
return null === $value || '' === $value || false === $value || array() === $value;
}
/**
* Checks if a value is not 'empty'. 0 doesn't count as empty.
* @since 2.2.2
* @param mixed $value Value to check
* @return bool True or false
*/
public static function notempty( $value ){
return null !== $value && '' !== $value && false !== $value && array() !== $value;
}
/**
* Filters out empty values (not including 0).
* @since 2.2.2
* @param mixed $value Value to check
* @return bool True or false
*/
public static function filter_empty( $value ) {
return array_filter( $value, array( __CLASS__, 'notempty' ) );
}
/**
* Insert a single array item inside another array at a set position
* @since 2.0.2
* @param array &$array Array to modify. Is passed by reference, and no return is needed.
* @param array $new New array to insert
* @param int $position Position in the main array to insert the new array
*/
public static function array_insert( &$array, $new, $position ) {
$before = array_slice( $array, 0, $position - 1 );
$after = array_diff_key( $array, $before );
$array = array_merge( $before, $new, $after );
}
/**
* Defines the url which is used to load local resources.
* This may need to be filtered for local Window installations.
* If resources do not load, please check the wiki for details.
* @since 1.0.1
* @return string URL to CMB2 resources
*/
public static function url( $path = '' ) {
if ( self::$url ) {
return self::$url . $path;
}
$cmb2_url = self::get_url_from_dir( cmb2_dir() );
/**
* Filter the CMB location url
*
* @param string $cmb2_url Currently registered url
*/
self::$url = trailingslashit( apply_filters( 'cmb2_meta_box_url', $cmb2_url, CMB2_VERSION ) );
return self::$url . $path;
}
/**
* Converts a system path to a URL
* @since 2.2.2
* @param string $dir Directory path to convert.
* @return string Converted URL.
*/
public static function get_url_from_dir( $dir ) {
$dir = self::normalize_path( $dir );
// Let's test if We are in the plugins or mu-plugins dir.
$test_dir = trailingslashit( $dir ) . 'unneeded.php';
if (
0 === strpos( $test_dir, self::normalize_path( WPMU_PLUGIN_DIR ) )
|| 0 === strpos( $test_dir, self::normalize_path( WP_PLUGIN_DIR ) )
) {
// Ok, then use plugins_url, as it is more reliable.
return trailingslashit( plugins_url( '', $test_dir ) );
}
// Ok, now let's test if we are in the theme dir.
$theme_root = self::normalize_path( get_theme_root() );
if ( 0 === strpos( $dir, $theme_root ) ) {
// Ok, then use get_theme_root_uri.
return set_url_scheme(
trailingslashit(
str_replace(
untrailingslashit( $theme_root ),
untrailingslashit( get_theme_root_uri() ),
$dir
)
)
);
}
// Check to see if it's anywhere in the root directory
$site_dir = self::normalize_path( self::$ABSPATH );
$site_url = trailingslashit( is_multisite() ? network_site_url() : site_url() );
$url = str_replace(
array( $site_dir, WP_PLUGIN_DIR ),
array( $site_url, WP_PLUGIN_URL ),
$dir
);
return set_url_scheme( $url );
}
/**
* `wp_normalize_path` wrapper for back-compat. Normalize a filesystem path.
*
* On windows systems, replaces backslashes with forward slashes
* and forces upper-case drive letters.
* Allows for two leading slashes for Windows network shares, but
* ensures that all other duplicate slashes are reduced to a single.
*
* @since 2.2.0
*
* @param string $path Path to normalize.
* @return string Normalized path.
*/
protected static function normalize_path( $path ) {
if ( function_exists( 'wp_normalize_path' ) ) {
return wp_normalize_path( $path );
}
// Replace newer WP's version of wp_normalize_path.
$path = str_replace( '\\', '/', $path );
$path = preg_replace( '|(?<=.)/+|', '/', $path );
if ( ':' === substr( $path, 1, 1 ) ) {
$path = ucfirst( $path );
}
return $path;
}
/**
* Get timestamp from text date
* @since 2.2.0
* @param string $value Date value
* @param string $date_format Expected date format
* @return mixed Unix timestamp representing the date.
*/
public static function get_timestamp_from_value( $value, $date_format ) {
$date_object = date_create_from_format( $date_format, $value );
return $date_object ? $date_object->setTime( 0, 0, 0 )->getTimeStamp() : strtotime( $value );
}
/**
* Takes a php date() format string and returns a string formatted to suit for the date/time pickers
* It will work with only with the following subset ot date() options:
*
* d, j, z, m, n, y, and Y.
*
* A slight effort is made to deal with escaped characters.
*
* Other options are ignored, because they would either bring compatibility problems between PHP and JS, or
* bring even more translation troubles.
*
* @since 2.2.0
* @param string $format php date format
* @return string reformatted string
*/
public static function php_to_js_dateformat( $format ) {
// order is relevant here, since the replacement will be done sequentially.
$supported_options = array(
'd' => 'dd', // Day, leading 0
'j' => 'd', // Day, no 0
'z' => 'o', // Day of the year, no leading zeroes,
// 'D' => 'D', // Day name short, not sure how it'll work with translations
// 'l' => 'DD', // Day name full, idem before
'm' => 'mm', // Month of the year, leading 0
'n' => 'm', // Month of the year, no leading 0
// 'M' => 'M', // Month, Short name
// 'F' => 'MM', // Month, full name,
'y' => 'y', // Year, two digit
'Y' => 'yy', // Year, full
'H' => 'HH', // Hour with leading 0 (24 hour)
'G' => 'H', // Hour with no leading 0 (24 hour)
'h' => 'hh', // Hour with leading 0 (12 hour)
'g' => 'h', // Hour with no leading 0 (12 hour),
'i' => 'mm', // Minute with leading 0,
's' => 'ss', // Second with leading 0,
'a' => 'tt', // am/pm
'A' => 'TT' // AM/PM
);
foreach ( $supported_options as $php => $js ) {
// replaces every instance of a supported option, but skips escaped characters
$format = preg_replace( "~(?<!\\\\)$php~", $js, $format );
}
$format = preg_replace_callback( '~(?:\\\.)+~', array( __CLASS__, 'wrap_escaped_chars' ), $format );
return $format;
}
/**
* Helper function for CMB_Utils->php_to_js_dateformat, because php 5.2 was retarded.
* @since 2.2.0
* @param $value Value to wrap/escape
* @return string Modified value
*/
public static function wrap_escaped_chars( $value ) {
return "&#39;" . str_replace( '\\', '', $value[0] ) . "&#39;";
}
/**
* Send to debug.log if WP_DEBUG is defined and true
*
* @since 2.2.0
*
* @param string $function Function name
* @param int $line Line number
* @param mixed $msg Message to output
* @param mixed $debug Variable to print_r
*/
public static function log_if_debug( $function, $line, $msg, $debug = null ) {
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
error_log( "In $function, $line:" . print_r( $msg, true ) . ( $debug ? print_r( $debug, true ) : '' ) );
}
}
/**
* Determine a file's extension
* @since 1.0.0
* @param string $file File url
* @return string|false File extension or false
*/
public static function get_file_ext( $file ) {
$parsed = parse_url( $file, PHP_URL_PATH );
return $parsed ? strtolower( pathinfo( $parsed, PATHINFO_EXTENSION ) ) : false;
}
/**
* Get the file name from a url
* @since 2.0.0
* @param string $value File url or path
* @return string File name
*/
public static function get_file_name_from_path( $value ) {
$parts = explode( '/', $value );
return is_array( $parts ) ? end( $parts ) : $value;
}
/**
* Check if WP version is at least $version.
* @since 2.2.2
* @param string $version WP version string to compare.
* @return bool Result of comparison check.
*/
public static function wp_at_least( $version ) {
return version_compare( get_bloginfo( 'version' ), $version, '>=' );
}
/**
* Combines attributes into a string for a form element.
* @since 1.1.0
* @param array $attrs Attributes to concatenate.
* @param array $attr_exclude Attributes that should NOT be concatenated.
* @return string String of attributes for form element.
*/
public static function concat_attrs( $attrs, $attr_exclude = array() ) {
$attr_exclude[] = 'rendered';
$attributes = '';
foreach ( $attrs as $attr => $val ) {
$excluded = in_array( $attr, (array) $attr_exclude, true );
$empty = false === $val && 'value' !== $attr;
if ( ! $excluded && ! $empty ) {
// if data attribute, use single quote wraps, else double
$quotes = false !== stripos( $attr, 'data-' ) ? "'" : '"';
$attributes .= sprintf( ' %1$s=%3$s%2$s%3$s', $attr, $val, $quotes );
}
}
return $attributes;
}
/**
* Ensures value is an array.
*
* @since 2.2.3
*
* @param mixed $value Value to ensure is array.
* @param array $default Default array. Defaults to empty array.
*
* @return array The array.
*/
public static function ensure_array( $value, $default = array() ) {
if ( empty( $value ) ) {
return $default;
}
if ( is_array( $value ) || is_object( $value ) ) {
return (array) $value;
}
// Not sure anything would be non-scalar that is not an array or object?
if ( ! is_scalar( $value ) ) {
return $default;
}
return (array) $value;
}
}

View File

@ -0,0 +1,801 @@
<?php
/**
* Handles hooking CMB2 forms/metaboxes into the post/attachement/user screens
* and handles hooking in and saving those fields.
*
* @since 2.0.0
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_hookup extends CMB2_Hookup_Base {
/**
* Only allow JS registration once
* @var bool
* @since 2.0.7
*/
protected static $js_registration_done = false;
/**
* Only allow CSS registration once
* @var bool
* @since 2.0.7
*/
protected static $css_registration_done = false;
/**
* CMB taxonomies array for term meta
* @var array
* @since 2.2.0
*/
protected $taxonomies = array();
/**
* Custom field columns.
* @var array
* @since 2.2.2
*/
protected $columns = array();
/**
* Constructor
* @since 2.0.0
* @param CMB2 $cmb The CMB2 object to hookup
*/
public function __construct( CMB2 $cmb ) {
$this->cmb = $cmb;
$this->object_type = $this->cmb->mb_object_type();
}
public function universal_hooks() {
foreach ( get_class_methods( 'CMB2_Show_Filters' ) as $filter ) {
add_filter( 'cmb2_show_on', array( 'CMB2_Show_Filters', $filter ), 10, 3 );
}
if ( is_admin() ) {
// register our scripts and styles for cmb
$this->once( 'admin_enqueue_scripts', array( __CLASS__, 'register_scripts' ), 8 );
$this->once( 'admin_enqueue_scripts', array( $this, 'do_scripts' ) );
$this->maybe_enqueue_column_display_styles();
switch ( $this->object_type ) {
case 'post':
return $this->post_hooks();
case 'comment':
return $this->comment_hooks();
case 'user':
return $this->user_hooks();
case 'term':
return $this->term_hooks();
}
}
}
public function post_hooks() {
// Fetch the context we set in our call.
$context = $this->cmb->prop( 'context' ) ? $this->cmb->prop( 'context' ) : 'normal';
// Call the proper hook based on the context provided.
switch ( $context ) {
case 'form_top':
add_action( 'edit_form_top', array( $this, 'add_context_metaboxes' ) );
break;
case 'before_permalink':
add_action( 'edit_form_before_permalink', array( $this, 'add_context_metaboxes' ) );
break;
case 'after_title':
add_action( 'edit_form_after_title', array( $this, 'add_context_metaboxes' ) );
break;
case 'after_editor':
add_action( 'edit_form_after_editor', array( $this, 'add_context_metaboxes' ) );
break;
default:
add_action( 'add_meta_boxes', array( $this, 'add_metaboxes' ) );
}
add_action( 'add_attachment', array( $this, 'save_post' ) );
add_action( 'edit_attachment', array( $this, 'save_post' ) );
add_action( 'save_post', array( $this, 'save_post' ), 10, 2 );
if ( $this->cmb->has_columns ) {
foreach ( $this->cmb->prop( 'object_types' ) as $post_type ) {
add_filter( "manage_{$post_type}_posts_columns", array( $this, 'register_column_headers' ) );
add_action( "manage_{$post_type}_posts_custom_column", array( $this, 'column_display' ), 10, 2 );
}
}
}
public function comment_hooks() {
add_action( 'add_meta_boxes_comment', array( $this, 'add_metaboxes' ) );
add_action( 'edit_comment', array( $this, 'save_comment' ) );
if ( $this->cmb->has_columns ) {
add_filter( 'manage_edit-comments_columns', array( $this, 'register_column_headers' ) );
add_action( 'manage_comments_custom_column', array( $this, 'column_display' ), 10, 3 );
}
}
public function user_hooks() {
$priority = $this->get_priority();
add_action( 'show_user_profile', array( $this, 'user_metabox' ), $priority );
add_action( 'edit_user_profile', array( $this, 'user_metabox' ), $priority );
add_action( 'user_new_form', array( $this, 'user_new_metabox' ), $priority );
add_action( 'personal_options_update', array( $this, 'save_user' ) );
add_action( 'edit_user_profile_update', array( $this, 'save_user' ) );
add_action( 'user_register', array( $this, 'save_user' ) );
if ( $this->cmb->has_columns ) {
add_filter( 'manage_users_columns', array( $this, 'register_column_headers' ) );
add_filter( 'manage_users_custom_column', array( $this, 'return_column_display' ), 10, 3 );
}
}
public function term_hooks() {
if ( ! function_exists( 'get_term_meta' ) ) {
wp_die( esc_html__( 'Term Metadata is a WordPress 4.4+ feature. Please upgrade your WordPress install.', 'cmb2' ) );
}
if ( ! $this->cmb->prop( 'taxonomies' ) ) {
wp_die( esc_html__( 'Term metaboxes configuration requires a "taxonomies" parameter.', 'cmb2' ) );
}
$this->taxonomies = (array) $this->cmb->prop( 'taxonomies' );
$show_on_term_add = $this->cmb->prop( 'new_term_section' );
$priority = $this->get_priority( 8 );
foreach ( $this->taxonomies as $taxonomy ) {
// Display our form data
add_action( "{$taxonomy}_edit_form", array( $this, 'term_metabox' ), $priority, 2 );
$show_on_add = is_array( $show_on_term_add )
? in_array( $taxonomy, $show_on_term_add )
: (bool) $show_on_term_add;
$show_on_add = apply_filters( "cmb2_show_on_term_add_form_{$this->cmb->cmb_id}", $show_on_add, $this->cmb );
// Display form in add-new section (unless specified not to)
if ( $show_on_add ) {
add_action( "{$taxonomy}_add_form_fields", array( $this, 'term_metabox' ), $priority, 2 );
}
if ( $this->cmb->has_columns ) {
add_filter( "manage_edit-{$taxonomy}_columns", array( $this, 'register_column_headers' ) );
add_filter( "manage_{$taxonomy}_custom_column", array( $this, 'return_column_display' ), 10, 3 );
}
}
add_action( 'created_term', array( $this, 'save_term' ), 10, 3 );
add_action( 'edited_terms', array( $this, 'save_term' ), 10, 2 );
add_action( 'delete_term', array( $this, 'delete_term' ), 10, 3 );
}
/**
* Registers styles for CMB2
* @since 2.0.7
*/
protected static function register_styles() {
if ( self::$css_registration_done ) {
return;
}
// Only use minified files if SCRIPT_DEBUG is off
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
$front = is_admin() ? '' : '-front';
$rtl = is_rtl() ? '-rtl' : '';
// Filter required styles and register stylesheet
$dependencies = apply_filters( 'cmb2_style_dependencies', array() );
wp_register_style( 'cmb2-styles', CMB2_Utils::url( "css/cmb2{$front}{$rtl}{$min}.css" ), $dependencies );
wp_register_style( 'cmb2-display-styles', CMB2_Utils::url( "css/cmb2-display{$rtl}{$min}.css" ), $dependencies );
self::$css_registration_done = true;
}
/**
* Registers scripts for CMB2
* @since 2.0.7
*/
protected static function register_js() {
if ( self::$js_registration_done ) {
return;
}
$hook = is_admin() ? 'admin_footer' : 'wp_footer';
add_action( $hook, array( 'CMB2_JS', 'enqueue' ), 8 );
self::$js_registration_done = true;
}
/**
* Registers scripts and styles for CMB2
* @since 1.0.0
*/
public static function register_scripts() {
self::register_styles();
self::register_js();
}
/**
* Enqueues scripts and styles for CMB2 in admin_head.
* @since 1.0.0
*/
public function do_scripts( $hook ) {
$hooks = array(
'post.php',
'post-new.php',
'page-new.php',
'page.php',
'comment.php',
'edit-tags.php',
'term.php',
'user-new.php',
'profile.php',
'user-edit.php',
);
// only pre-enqueue our scripts/styles on the proper pages
// show_form_for_type will have us covered if we miss something here.
if ( in_array( $hook, $hooks, true ) ) {
if ( $this->cmb->prop( 'cmb_styles' ) ) {
self::enqueue_cmb_css();
}
if ( $this->cmb->prop( 'enqueue_js' ) ) {
self::enqueue_cmb_js();
}
}
}
/**
* Register the CMB2 field column headers.
* @since 2.2.2
*/
public function register_column_headers( $columns ) {
$fields = $this->cmb->prop( 'fields' );
foreach ( $fields as $key => $field ) {
if ( ! isset( $field['column'] ) ) {
continue;
}
$column = $field['column'];
if ( false === $column['position'] ) {
$columns[ $field['id'] ] = $column['name'];
} else {
$before = array_slice( $columns, 0, absint( $column['position'] ) );
$before[ $field['id'] ] = $column['name'];
$columns = $before + $columns;
}
$column['field'] = $field;
$this->columns[ $field['id'] ] = $column;
}
return $columns;
}
/**
* The CMB2 field column display output.
* @since 2.2.2
*/
public function column_display( $column_name, $object_id ) {
if ( isset( $this->columns[ $column_name ] ) ) {
$field = new CMB2_Field( array(
'field_args' => $this->columns[ $column_name ]['field'],
'object_type' => $this->object_type,
'object_id' => $this->cmb->object_id( $object_id ),
'cmb_id' => $this->cmb->cmb_id,
) );
$this->cmb->get_field( $field )->render_column();
}
}
/**
* Returns the column display.
* @since 2.2.2
*/
public function return_column_display( $empty, $custom_column, $object_id ) {
ob_start();
$this->column_display( $custom_column, $object_id );
$column = ob_get_clean();
return $column ? $column : $empty;
}
/**
* Output the CMB2 box/fields in an alternate context (not in a standard metabox area).
* @since 2.2.4
*/
public function add_context_metaboxes() {
if ( ! $this->show_on() ) {
return;
}
$page = get_current_screen()->id;
foreach ( $this->cmb->prop( 'object_types' ) as $object_type ) {
$screen = convert_to_screen( $object_type );
// If we're on the right post-type/object...
if ( isset( $screen->id ) && $screen->id === $page ) {
// Show the box.
$this->output_context_metabox();
}
}
}
/**
* Output the CMB2 box/fields in an alternate context (not in a standard metabox area).
* @since 2.2.4
*/
public function output_context_metabox() {
$title = $this->cmb->prop( 'title' );
/*
* To keep from outputting the open/close markup, do not include
* a 'title' property in your metabox registration array.
*
* To output the fields 'naked' (without a postbox wrapper/style), then
* add a `'remove_box_wrap' => true` to your metabox registration array.
*/
$add_wrap = ! empty( $title ) || ! $this->cmb->prop( 'remove_box_wrap' );
$add_handle = $add_wrap && ! empty( $title );
// Open the context-box wrap.
$add_handle = $this->context_box_title_markup_open( $add_handle );
// Show the form fields.
$this->cmb->show_form();
// Close the context-box wrap.
$this->context_box_title_markup_close( $add_handle );
}
/**
* Output the opening markup for a context box.
* @since 2.2.4
* @param $add_handle Whether to add the metabox handle and opening div for .inside
*/
public function context_box_title_markup_open( $add_handle = true ) {
$title = $this->cmb->prop( 'title' );
$page = get_current_screen()->id;
add_filter( "postbox_classes_{$page}_{$this->cmb->cmb_id}", array( $this, 'postbox_classes' ) );
echo '<div id="' . $this->cmb->cmb_id . '" class="' . postbox_classes( $this->cmb->cmb_id, $page ) . '">' . "\n";
if ( $add_handle ) {
echo '<button type="button" class="handlediv button-link" aria-expanded="true">';
echo '<span class="screen-reader-text">' . sprintf( __( 'Toggle panel: %s' ), $title ) . '</span>';
echo '<span class="toggle-indicator" aria-hidden="true"></span>';
echo '</button>';
echo '<h2 class="hndle"><span>' . esc_attr( $title ) . '</span></h2>' . "\n";
echo '<div class="inside">' . "\n";
}
}
/**
* Output the closing markup for a context box.
* @since 2.2.4
* @param $add_inside_close Whether to add closing div for .inside.
*/
public function context_box_title_markup_close( $add_inside_close = true ) {
// Load the closing divs for a title box.
if ( $add_inside_close ) {
echo '</div>' . "\n"; // .inside
}
echo '</div>' . "\n"; // .context-box
}
/**
* Add metaboxes (to 'post' or 'comment' object types)
* @since 1.0.0
*/
public function add_metaboxes() {
if ( ! $this->show_on() ) {
return;
}
/*
* To keep from registering an actual post-screen metabox,
* omit the 'title' property from the metabox registration array.
*
* (WordPress will not display metaboxes without titles anyway)
*
* This is a good solution if you want to handle outputting your
* metaboxes/fields elsewhere in the post-screen.
*/
if ( ! $this->cmb->prop( 'title' ) ) {
return;
}
$page = get_current_screen()->id;
add_filter( "postbox_classes_{$page}_{$this->cmb->cmb_id}", array( $this, 'postbox_classes' ) );
foreach ( $this->cmb->prop( 'object_types' ) as $object_type ) {
if ( count( $this->cmb->tax_metaboxes_to_remove ) ) {
$this->remove_default_tax_metaboxes( $object_type );
}
add_meta_box( $this->cmb->cmb_id, $this->cmb->prop( 'title' ), array( $this, 'metabox_callback' ), $object_type, $this->cmb->prop( 'context' ), $this->cmb->prop( 'priority' ) );
}
}
/**
* Remove the specified default taxonomy metaboxes for a post-type.
* @since 2.2.3
* @param string $post_type Post type to remove the metabox for.
*/
protected function remove_default_tax_metaboxes( $post_type ) {
foreach ( $this->cmb->tax_metaboxes_to_remove as $taxonomy ) {
if ( ! taxonomy_exists( $taxonomy ) ) {
continue;
}
$mb_id = is_taxonomy_hierarchical( $taxonomy ) ? "{$taxonomy}div" : "tagsdiv-{$taxonomy}";
remove_meta_box( $mb_id, $post_type, 'side' );
}
}
/**
* Modify metabox postbox classes.
* @since 2.2.4
* @param array $classes Array of classes
* @return array Modified array of classes
*/
public function postbox_classes( $classes ) {
if ( $this->cmb->prop( 'closed' ) && ! in_array( 'closed', $classes ) ) {
$classes[] = 'closed';
}
if ( $this->cmb->is_alternate_context_box() ) {
$classes = $this->alternate_context_postbox_classes( $classes );
} else {
$classes[] = 'cmb2-postbox';
}
return $classes;
}
/**
* Modify metabox altnernate context postbox classes.
* @since 2.2.4
* @param array $classes Array of classes
* @return array Modified array of classes
*/
protected function alternate_context_postbox_classes( $classes ) {
$classes[] = 'context-box';
$classes[] = 'context-' . $this->cmb->prop( 'context' ) . '-box';
if ( in_array( $this->cmb->cmb_id, get_hidden_meta_boxes( get_current_screen() ) ) ) {
$classes[] = 'hide-if-js';
}
$add_wrap = $this->cmb->prop( 'title' ) || ! $this->cmb->prop( 'remove_box_wrap' );
if ( $add_wrap ) {
$classes[] = 'cmb2-postbox postbox';
} else {
$classes[] = 'cmb2-no-box-wrap';
}
return $classes;
}
/**
* Display metaboxes for a post or comment object
* @since 1.0.0
*/
public function metabox_callback() {
$object_id = 'comment' == $this->object_type ? get_comment_ID() : get_the_ID();
$this->cmb->show_form( $object_id, $this->object_type );
}
/**
* Display metaboxes for new user page
* @since 1.0.0
*/
public function user_new_metabox( $section ) {
if ( $section == $this->cmb->prop( 'new_user_section' ) ) {
$object_id = $this->cmb->object_id();
$this->cmb->object_id( isset( $_REQUEST['user_id'] ) ? $_REQUEST['user_id'] : $object_id );
$this->user_metabox();
}
}
/**
* Display metaboxes for a user object
* @since 1.0.0
*/
public function user_metabox() {
$this->show_form_for_type( 'user' );
}
/**
* Display metaboxes for a taxonomy term object
* @since 2.2.0
*/
public function term_metabox() {
$this->show_form_for_type( 'term' );
}
/**
* Display metaboxes for an object type
* @since 2.2.0
* @param string $type Object type
* @return void
*/
public function show_form_for_type( $type ) {
if ( $type != $this->cmb->mb_object_type() ) {
return;
}
if ( ! $this->show_on() ) {
return;
}
if ( $this->cmb->prop( 'cmb_styles' ) ) {
self::enqueue_cmb_css();
}
if ( $this->cmb->prop( 'enqueue_js' ) ) {
self::enqueue_cmb_js();
}
$this->cmb->show_form( 0, $type );
}
/**
* Determines if metabox should be shown in current context
* @since 2.0.0
* @return bool Whether metabox should be added/shown
*/
public function show_on() {
// If metabox is requesting to be conditionally shown
$show = $this->cmb->should_show();
/**
* Filter to determine if metabox should show. Default is true
*
* @param array $show Default is true, show the metabox
* @param mixed $meta_box_args Array of the metabox arguments
* @param mixed $cmb The CMB2 instance
*/
$show = (bool) apply_filters( 'cmb2_show_on', $show, $this->cmb->meta_box, $this->cmb );
return $show;
}
/**
* Get the CMB priority property set to numeric hook priority.
* @since 2.2.0
* @param integer $default Default display hook priority.
* @return integer Hook priority.
*/
public function get_priority( $default = 10 ) {
$priority = $this->cmb->prop( 'priority' );
if ( ! is_numeric( $priority ) ) {
switch ( $priority ) {
case 'high':
$priority = 5;
break;
case 'low':
$priority = 20;
break;
default:
$priority = $default;
break;
}
}
return $priority;
}
/**
* Save data from post metabox
* @since 1.0.0
* @param int $post_id Post ID
* @param mixed $post Post object
* @return null
*/
public function save_post( $post_id, $post = false ) {
$post_type = $post ? $post->post_type : get_post_type( $post_id );
$do_not_pass_go = (
! $this->can_save( $post_type )
// check user editing permissions
|| ( 'page' == $post_type && ! current_user_can( 'edit_page', $post_id ) )
|| ! current_user_can( 'edit_post', $post_id )
);
if ( $do_not_pass_go ) {
// do not collect $200
return;
}
// take a trip to reading railroad if you pass go collect $200
$this->cmb->save_fields( $post_id, 'post', $_POST );
}
/**
* Save data from comment metabox
* @since 2.0.9
* @param int $comment_id Comment ID
* @return null
*/
public function save_comment( $comment_id ) {
$can_edit = current_user_can( 'moderate_comments', $comment_id );
if ( $this->can_save( get_comment_type( $comment_id ) ) && $can_edit ) {
$this->cmb->save_fields( $comment_id, 'comment', $_POST );
}
}
/**
* Save data from user fields
* @since 1.0.x
* @param int $user_id User ID
* @return null
*/
public function save_user( $user_id ) {
// check permissions
if ( $this->can_save( 'user' ) ) {
$this->cmb->save_fields( $user_id, 'user', $_POST );
}
}
/**
* Save data from term fields
* @since 2.2.0
* @param int $term_id Term ID
* @param int $tt_id Term Taxonomy ID
* @param string $taxonomy Taxonomy
* @return null
*/
public function save_term( $term_id, $tt_id, $taxonomy = '' ) {
$taxonomy = $taxonomy ? $taxonomy : $tt_id;
// check permissions
if ( $this->taxonomy_can_save( $taxonomy ) && $this->can_save( 'term' ) ) {
$this->cmb->save_fields( $term_id, 'term', $_POST );
}
}
/**
* Delete term meta when a term is deleted.
* @since 2.2.0
* @param int $term_id Term ID
* @param int $tt_id Term Taxonomy ID
* @param string $taxonomy Taxonomy
* @return null
*/
public function delete_term( $term_id, $tt_id, $taxonomy = '' ) {
if ( $this->taxonomy_can_save( $taxonomy ) ) {
$data_to_delete = array();
foreach ( $this->cmb->prop( 'fields' ) as $field ) {
$data_to_delete[ $field['id'] ] = '';
}
$this->cmb->save_fields( $term_id, 'term', $data_to_delete );
}
}
/**
* Determines if the current object is able to be saved
* @since 2.0.9
* @param string $type Current post_type or comment_type
* @return bool Whether object can be saved
*/
public function can_save( $type = '' ) {
return apply_filters( 'cmb2_can_save', (
$this->cmb->prop( 'save_fields' )
// check nonce
&& isset( $_POST[ $this->cmb->nonce() ] )
&& wp_verify_nonce( $_POST[ $this->cmb->nonce() ], $this->cmb->nonce() )
// check if autosave
&& ! ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
// get the metabox types & compare it to this type
&& ( $type && in_array( $type, $this->cmb->prop( 'object_types' ) ) )
// Don't do updates during a switch-to-blog instance.
&& ! ( is_multisite() && ms_is_switched() )
) );
}
/**
* Determine if taxonomy of term being modified is cmb2-editable.
* @since 2.2.0
* @param string $taxonomy Taxonomy of term being modified.
* @return bool Whether taxonomy is editable.
*/
public function taxonomy_can_save( $taxonomy ) {
if ( empty( $this->taxonomies ) || ! in_array( $taxonomy, $this->taxonomies ) ) {
return false;
}
$taxonomy_object = get_taxonomy( $taxonomy );
// Can the user edit this term?
if ( ! isset( $taxonomy_object->cap ) || ! current_user_can( $taxonomy_object->cap->edit_terms ) ) {
return false;
}
return true;
}
/**
* Enqueues the 'cmb2-display-styles' if the conditions match (has columns, on the right page, etc).
* @since 2.2.2.1
*/
protected function maybe_enqueue_column_display_styles() {
global $pagenow;
if (
$pagenow
&& $this->cmb->has_columns
&& $this->cmb->prop( 'cmb_styles' )
&& in_array( $pagenow, array( 'edit.php', 'users.php', 'edit-comments.php', 'edit-tags.php' ), 1 )
) {
self::enqueue_cmb_css( 'cmb2-display-styles' );
}
}
/**
* Includes CMB2 styles
* @since 2.0.0
*/
public static function enqueue_cmb_css( $handle = 'cmb2-styles' ) {
if ( ! apply_filters( 'cmb2_enqueue_css', true ) ) {
return false;
}
self::register_styles();
/*
* White list the options as this method can be used as a hook callback
* and have a different argument passed.
*/
return wp_enqueue_style( 'cmb2-display-styles' === $handle ? $handle : 'cmb2-styles' );
}
/**
* Includes CMB2 JS
* @since 2.0.0
*/
public static function enqueue_cmb_js() {
if ( ! apply_filters( 'cmb2_enqueue_js', true ) ) {
return false;
}
self::register_js();
return true;
}
}

View File

@ -0,0 +1,389 @@
<?php
/**
* CMB2 Helper Functions
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
/**
* Helper function to provide directory path to CMB2
* @since 2.0.0
* @param string $path Path to append
* @return string Directory with optional path appended
*/
function cmb2_dir( $path = '' ) {
return CMB2_DIR . $path;
}
/**
* Autoloads files with CMB2 classes when needed
* @since 1.0.0
* @param string $class_name Name of the class being requested
*/
function cmb2_autoload_classes( $class_name ) {
if ( 0 !== strpos( $class_name, 'CMB2' ) ) {
return;
}
$path = 'includes';
if ( 'CMB2_Type' === $class_name || 0 === strpos( $class_name, 'CMB2_Type_' ) ) {
$path .= '/types';
}
if ( 'CMB2_REST' === $class_name || 0 === strpos( $class_name, 'CMB2_REST_' ) ) {
$path .= '/rest-api';
}
include_once( cmb2_dir( "$path/{$class_name}.php" ) );
}
/**
* Get instance of the CMB2_Utils class
* @since 2.0.0
* @return CMB2_Utils object CMB2 utilities class
*/
function cmb2_utils() {
static $cmb2_utils;
$cmb2_utils = $cmb2_utils ? $cmb2_utils : new CMB2_Utils();
return $cmb2_utils;
}
/**
* Get instance of the CMB2_Ajax class
* @since 2.0.0
* @return CMB2_Ajax object CMB2 ajax class
*/
function cmb2_ajax() {
return CMB2_Ajax::get_instance();
}
/**
* Get instance of the CMB2_Option class for the passed metabox ID
* @since 2.0.0
* @return CMB2_Option object Options class for setting/getting options for metabox
*/
function cmb2_options( $key ) {
return CMB2_Options::get( $key );
}
/**
* Get a cmb oEmbed. Handles oEmbed getting for non-post objects
* @since 2.0.0
* @param array $args Arguments. Accepts:
*
* 'url' - URL to retrieve the oEmbed from,
* 'object_id' - $post_id,
* 'object_type' - 'post',
* 'oembed_args' - $embed_args, // array containing 'width', etc
* 'field_id' - false,
* 'cache_key' - false,
* 'wp_error' - true/false, // To return a wp_error object if no embed found.
*
* @return string oEmbed string
*/
function cmb2_get_oembed( $args = array() ) {
$oembed = cmb2_ajax()->get_oembed_no_edit( $args );
// Send back our embed
if ( $oembed['embed'] && $oembed['embed'] != $oembed['fallback'] ) {
return '<div class="cmb2-oembed">' . $oembed['embed'] . '</div>';
}
$error = sprintf(
/* translators: 1: results for. 2: link to codex.wordpress.org/Embeds */
esc_html__( 'No oEmbed Results Found for %1$s. View more info at %2$s.', 'cmb2' ),
$oembed['fallback'],
'<a href="https://codex.wordpress.org/Embeds" target="_blank">codex.wordpress.org/Embeds</a>'
);
if ( isset( $args['wp_error'] ) && $args['wp_error'] ) {
return new WP_Error( 'cmb2_get_oembed_result', $error, compact( 'oembed', 'args' ) );
}
// Otherwise, send back error info that no oEmbeds were found
return '<p class="ui-state-error-text">' . $error . '</p>';
}
/**
* Outputs the return of cmb2_get_oembed.
* @since 2.2.2
* @see cmb2_get_oembed
*/
function cmb2_do_oembed( $args = array() ) {
echo cmb2_get_oembed( $args );
}
add_action( 'cmb2_do_oembed', 'cmb2_do_oembed' );
/**
* A helper function to get an option from a CMB2 options array
* @since 1.0.1
* @param string $option_key Option key
* @param string $field_id Option array field key
* @param mixed $default Optional default fallback value
* @return array Options array or specific field
*/
function cmb2_get_option( $option_key, $field_id = '', $default = false ) {
return cmb2_options( $option_key )->get( $field_id, $default );
}
/**
* A helper function to update an option in a CMB2 options array
* @since 2.0.0
* @param string $option_key Option key
* @param string $field_id Option array field key
* @param mixed $value Value to update data with
* @param boolean $single Whether data should not be an array
* @return boolean Success/Failure
*/
function cmb2_update_option( $option_key, $field_id, $value, $single = true ) {
if ( cmb2_options( $option_key )->update( $field_id, $value, false, $single ) ) {
return cmb2_options( $option_key )->set();
}
return false;
}
/**
* Get a CMB2 field object.
* @since 1.1.0
* @param array $meta_box Metabox ID or Metabox config array
* @param array $field_id Field ID or all field arguments
* @param int $object_id Object ID
* @param string $object_type Type of object being saved. (e.g., post, user, comment, or options-page).
* Defaults to metabox object type.
* @return CMB2_Field|null CMB2_Field object unless metabox config cannot be found
*/
function cmb2_get_field( $meta_box, $field_id, $object_id = 0, $object_type = '' ) {
$object_id = $object_id ? $object_id : get_the_ID();
$cmb = $meta_box instanceof CMB2 ? $meta_box : cmb2_get_metabox( $meta_box, $object_id );
if ( ! $cmb ) {
return;
}
$cmb->object_type( $object_type ? $object_type : $cmb->mb_object_type() );
return $cmb->get_field( $field_id );
}
/**
* Get a field's value.
* @since 1.1.0
* @param array $meta_box Metabox ID or Metabox config array
* @param array $field_id Field ID or all field arguments
* @param int $object_id Object ID
* @param string $object_type Type of object being saved. (e.g., post, user, comment, or options-page).
* Defaults to metabox object type.
* @return mixed Maybe escaped value
*/
function cmb2_get_field_value( $meta_box, $field_id, $object_id = 0, $object_type = '' ) {
$field = cmb2_get_field( $meta_box, $field_id, $object_id, $object_type );
return $field->escaped_value();
}
/**
* Because OOP can be scary
* @since 2.0.2
* @param array $meta_box_config Metabox Config array
* @return CMB2 object Instantiated CMB2 object
*/
function new_cmb2_box( array $meta_box_config ) {
return cmb2_get_metabox( $meta_box_config );
}
/**
* Retrieve a CMB2 instance by the metabox ID
* @since 2.0.0
* @param mixed $meta_box Metabox ID or Metabox config array
* @param int $object_id Object ID
* @param string $object_type Type of object being saved. (e.g., post, user, comment, or options-page).
* Defaults to metabox object type.
* @return CMB2 object
*/
function cmb2_get_metabox( $meta_box, $object_id = 0, $object_type = '' ) {
if ( $meta_box instanceof CMB2 ) {
return $meta_box;
}
if ( is_string( $meta_box ) ) {
$cmb = CMB2_Boxes::get( $meta_box );
} else {
// See if we already have an instance of this metabox
$cmb = CMB2_Boxes::get( $meta_box['id'] );
// If not, we'll initate a new metabox
$cmb = $cmb ? $cmb : new CMB2( $meta_box, $object_id );
}
if ( $cmb && $object_id ) {
$cmb->object_id( $object_id );
}
if ( $cmb && $object_type ) {
$cmb->object_type( $object_type );
}
return $cmb;
}
/**
* Returns array of sanitized field values from a metabox (without saving them)
* @since 2.0.3
* @param mixed $meta_box Metabox ID or Metabox config array
* @param array $data_to_sanitize Array of field_id => value data for sanitizing (likely $_POST data).
* @return mixed Array of sanitized values or false if no CMB2 object found
*/
function cmb2_get_metabox_sanitized_values( $meta_box, array $data_to_sanitize ) {
$cmb = cmb2_get_metabox( $meta_box );
return $cmb ? $cmb->get_sanitized_values( $data_to_sanitize ) : false;
}
/**
* Retrieve a metabox form
* @since 2.0.0
* @param mixed $meta_box Metabox config array or Metabox ID
* @param int $object_id Object ID
* @param array $args Optional arguments array
* @return string CMB2 html form markup
*/
function cmb2_get_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 );
ob_start();
// Get cmb form
cmb2_print_metabox_form( $cmb, $object_id, $args );
$form = ob_get_clean();
return apply_filters( 'cmb2_get_metabox_form', $form, $object_id, $cmb );
}
/**
* 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' => esc_html__( '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' )
// check nonce
&& 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'] );
}
}
/**
* Display a metabox form (or optionally return it) & 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_metabox_form( $meta_box, $object_id = 0, $args = array() ) {
if ( ! isset( $args['echo'] ) || $args['echo'] ) {
cmb2_print_metabox_form( $meta_box, $object_id, $args );
} else {
return cmb2_get_metabox_form( $meta_box, $object_id, $args );
}
}
if ( ! function_exists( 'date_create_from_format' ) ) {
/**
* Reimplementation of DateTime::createFromFormat for PHP < 5.3. :(
* Borrowed from http://stackoverflow.com/questions/5399075/php-datetimecreatefromformat-in-5-2
*
* @param $date_format
* @param $date_value
*
* @return DateTime
*/
function date_create_from_format( $date_format, $date_value ) {
$schedule_format = str_replace(
array( 'M', 'Y', 'm', 'd', 'H', 'i', 'a' ),
array('%b', '%Y', '%m', '%d', '%H', '%M', '%p' ),
$date_format
);
/*
* %Y, %m and %d correspond to date()'s Y m and d.
* %I corresponds to H, %M to i and %p to a
*/
$parsed_time = strptime( $date_value, $schedule_format );
$ymd = sprintf(
/*
* This is a format string that takes six total decimal
* arguments, then left-pads them with zeros to either
* 4 or 2 characters, as needed
*/
'%04d-%02d-%02d %02d:%02d:%02d',
$parsed_time['tm_year'] + 1900, // This will be "111", so we need to add 1900.
$parsed_time['tm_mon'] + 1, // This will be the month minus one, so we add one.
$parsed_time['tm_mday'],
$parsed_time['tm_hour'],
$parsed_time['tm_min'],
$parsed_time['tm_sec']
);
return new DateTime($ymd);
}
}

2
cmb2/includes/index.php Normal file
View File

@ -0,0 +1,2 @@
<?php
// Silence is golden

View File

@ -0,0 +1,767 @@
<?php
/**
* Handles hooking CMB2 objects/fields into the WordPres REST API
* which can allow fields to be read and/or updated.
*
* @since 2.2.3
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*
* @property-read read_fields Array of readable field objects.
* @property-read edit_fields Array of editable field objects.
* @property-read rest_read Whether CMB2 object is readable via the rest api.
* @property-read rest_edit Whether CMB2 object is editable via the rest api.
*/
class CMB2_REST extends CMB2_Hookup_Base {
/**
* The current CMB2 REST endpoint version
* @var string
* @since 2.2.3
*/
const VERSION = '1';
/**
* The CMB2 REST base namespace (v should always be followed by $version)
* @var string
* @since 2.2.3
*/
const NAME_SPACE = 'cmb2/v1';
/**
* @var CMB2 object
* @since 2.2.3
*/
public $cmb;
/**
* @var CMB2_REST[] objects
* @since 2.2.3
*/
protected static $boxes = array();
/**
* @var array Array of cmb ids for each type.
* @since 2.2.3
*/
protected static $type_boxes = array(
'post' => array(),
'user' => array(),
'comment' => array(),
'term' => array(),
);
/**
* Array of readable field objects.
* @var CMB2_Field[]
* @since 2.2.3
*/
protected $read_fields = array();
/**
* Array of editable field objects.
* @var CMB2_Field[]
* @since 2.2.3
*/
protected $edit_fields = array();
/**
* Whether CMB2 object is readable via the rest api.
* @var boolean
*/
protected $rest_read = false;
/**
* Whether CMB2 object is editable via the rest api.
* @var boolean
*/
protected $rest_edit = false;
/**
* Constructor
*
* @since 2.2.3
*
* @param CMB2 $cmb The CMB2 object to be registered for the API.
*/
public function __construct( CMB2 $cmb ) {
$this->cmb = $cmb;
self::$boxes[ $cmb->cmb_id ] = $this;
$show_value = $this->cmb->prop( 'show_in_rest' );
$this->rest_read = self::is_readable( $show_value );
$this->rest_edit = self::is_editable( $show_value );
}
/**
* Hooks to register on frontend and backend.
*
* @since 2.2.3
*
* @return void
*/
public function universal_hooks() {
// hook up the CMB rest endpoint classes
$this->once( 'rest_api_init', array( __CLASS__, 'init_routes' ), 0 );
if ( function_exists( 'register_rest_field' ) ) {
$this->once( 'rest_api_init', array( __CLASS__, 'register_cmb2_fields' ), 50 );
}
$this->declare_read_edit_fields();
add_filter( 'is_protected_meta', array( $this, 'is_protected_meta' ), 10, 3 );
}
/**
* Initiate the CMB2 Boxes and Fields routes
*
* @since 2.2.3
*
* @return void
*/
public static function init_routes() {
$wp_rest_server = rest_get_server();
$boxes_controller = new CMB2_REST_Controller_Boxes( $wp_rest_server );
$boxes_controller->register_routes();
$fields_controller = new CMB2_REST_Controller_Fields( $wp_rest_server );
$fields_controller->register_routes();
}
/**
* Loop through REST boxes and call register_rest_field for each object type.
*
* @since 2.2.3
*
* @return void
*/
public static function register_cmb2_fields() {
$alltypes = $taxonomies = array();
foreach ( self::$boxes as $cmb_id => $rest_box ) {
$types = array_flip( $rest_box->cmb->box_types() );
if ( isset( $types['user'] ) ) {
unset( $types['user'] );
self::$type_boxes['user'][ $cmb_id ] = $cmb_id;
}
if ( isset( $types['comment'] ) ) {
unset( $types['comment'] );
self::$type_boxes['comment'][ $cmb_id ] = $cmb_id;
}
if ( isset( $types['term'] ) ) {
unset( $types['term'] );
$taxonomies = array_merge(
$taxonomies,
CMB2_Utils::ensure_array( $rest_box->cmb->prop( 'taxonomies' ) )
);
self::$type_boxes['term'][ $cmb_id ] = $cmb_id;
}
if ( ! empty( $types ) ) {
$alltypes = array_merge( $alltypes, array_flip( $types ) );
self::$type_boxes['post'][ $cmb_id ] = $cmb_id;
}
}
$alltypes = array_unique( $alltypes );
if ( ! empty( $alltypes ) ) {
self::register_rest_field( $alltypes, 'post' );
}
if ( ! empty( self::$type_boxes['user'] ) ) {
self::register_rest_field( 'user', 'user' );
}
if ( ! empty( self::$type_boxes['comment'] ) ) {
self::register_rest_field( 'comment', 'comment' );
}
if ( ! empty( self::$type_boxes['term'] ) ) {
self::register_rest_field( $taxonomies, 'term' );
}
}
/**
* Wrapper for register_rest_field.
*
* @since 2.2.3
*
* @param string|array $object_types Object(s) the field is being registered
* to, "post"|"term"|"comment" etc.
* @param string $object_types Canonical object type for callbacks.
*
* @return void
*/
protected static function register_rest_field( $object_types, $object_type ) {
register_rest_field( $object_types, 'cmb2', array(
'get_callback' => array( __CLASS__, "get_{$object_type}_rest_values" ),
'update_callback' => array( __CLASS__, "update_{$object_type}_rest_values" ),
'schema' => null, // @todo add schema
) );
}
/**
* Setup readable and editable fields.
*
* @since 2.2.3
*
* @return void
*/
protected function declare_read_edit_fields() {
foreach ( $this->cmb->prop( 'fields' ) as $field ) {
$show_in_rest = isset( $field['show_in_rest'] ) ? $field['show_in_rest'] : null;
if ( false === $show_in_rest ) {
continue;
}
if ( $this->can_read( $show_in_rest ) ) {
$this->read_fields[] = $field['id'];
}
if ( $this->can_edit( $show_in_rest ) ) {
$this->edit_fields[] = $field['id'];
}
}
}
/**
* Determines if a field is readable based on it's show_in_rest value
* and the box's show_in_rest value.
*
* @since 2.2.3
*
* @param bool $show_in_rest Field's show_in_rest value. Default null.
*
* @return bool Whether field is readable.
*/
protected function can_read( $show_in_rest ) {
// if 'null', then use default box value.
if ( null === $show_in_rest ) {
return $this->rest_read;
}
// Else check if the value represents readable.
return self::is_readable( $show_in_rest );
}
/**
* Determines if a field is editable based on it's show_in_rest value
* and the box's show_in_rest value.
*
* @since 2.2.3
*
* @param bool $show_in_rest Field's show_in_rest value. Default null.
*
* @return bool Whether field is editable.
*/
protected function can_edit( $show_in_rest ) {
// if 'null', then use default box value.
if ( null === $show_in_rest ) {
return $this->rest_edit;
}
// Else check if the value represents editable.
return self::is_editable( $show_in_rest );
}
/**
* Handler for getting post custom field data.
*
* @since 2.2.3
*
* @param array $object The object data from the response
* @param string $field_name Name of field
* @param WP_REST_Request $request Current request
* @param string $object_type The request object type
*
* @return mixed
*/
public static function get_post_rest_values( $object, $field_name, $request, $object_type ) {
if ( 'cmb2' === $field_name ) {
return self::get_rest_values( $object, $request, $object_type, 'post' );
}
}
/**
* Handler for getting user custom field data.
*
* @since 2.2.3
*
* @param array $object The object data from the response
* @param string $field_name Name of field
* @param WP_REST_Request $request Current request
* @param string $object_type The request object type
*
* @return mixed
*/
public static function get_user_rest_values( $object, $field_name, $request, $object_type ) {
if ( 'cmb2' === $field_name ) {
return self::get_rest_values( $object, $request, $object_type, 'user' );
}
}
/**
* Handler for getting comment custom field data.
*
* @since 2.2.3
*
* @param array $object The object data from the response
* @param string $field_name Name of field
* @param WP_REST_Request $request Current request
* @param string $object_type The request object type
*
* @return mixed
*/
public static function get_comment_rest_values( $object, $field_name, $request, $object_type ) {
if ( 'cmb2' === $field_name ) {
return self::get_rest_values( $object, $request, $object_type, 'comment' );
}
}
/**
* Handler for getting term custom field data.
*
* @since 2.2.3
*
* @param array $object The object data from the response
* @param string $field_name Name of field
* @param WP_REST_Request $request Current request
* @param string $object_type The request object type
*
* @return mixed
*/
public static function get_term_rest_values( $object, $field_name, $request, $object_type ) {
if ( 'cmb2' === $field_name ) {
return self::get_rest_values( $object, $request, $object_type, 'term' );
}
}
/**
* Handler for getting custom field data.
*
* @since 2.2.3
*
* @param array $object The object data from the response
* @param WP_REST_Request $request Current request
* @param string $object_type The request object type
* @param string $main_object_type The cmb main object type
*
* @return mixed
*/
protected static function get_rest_values( $object, $request, $object_type, $main_object_type = 'post' ) {
if ( ! isset( $object['id'] ) ) {
return;
}
$values = array();
if ( ! empty( self::$type_boxes[ $main_object_type ] ) ) {
foreach ( self::$type_boxes[ $main_object_type ] as $cmb_id ) {
$rest_box = self::$boxes[ $cmb_id ];
foreach ( $rest_box->read_fields as $field_id ) {
$rest_box->cmb->object_id( $object['id'] );
$rest_box->cmb->object_type( $main_object_type );
$field = $rest_box->cmb->get_field( $field_id );
$field->object_id( $object['id'] );
$field->object_type( $main_object_type );
$values[ $cmb_id ][ $field->id( true ) ] = $field->get_data();
}
}
}
return $values;
}
/**
* Handler for updating post custom field data.
*
* @since 2.2.3
*
* @param mixed $values The value of the field
* @param object $object The object from the response
* @param string $field_name Name of field
* @param WP_REST_Request $request Current request
* @param string $object_type The request object type
*
* @return bool|int
*/
public static function update_post_rest_values( $values, $object, $field_name, $request, $object_type ) {
if ( 'cmb2' === $field_name ) {
return self::update_rest_values( $values, $object, $request, $object_type, 'post' );
}
}
/**
* Handler for updating user custom field data.
*
* @since 2.2.3
*
* @param mixed $values The value of the field
* @param object $object The object from the response
* @param string $field_name Name of field
* @param WP_REST_Request $request Current request
* @param string $object_type The request object type
*
* @return bool|int
*/
public static function update_user_rest_values( $values, $object, $field_name, $request, $object_type ) {
if ( 'cmb2' === $field_name ) {
return self::update_rest_values( $values, $object, $request, $object_type, 'user' );
}
}
/**
* Handler for updating comment custom field data.
*
* @since 2.2.3
*
* @param mixed $values The value of the field
* @param object $object The object from the response
* @param string $field_name Name of field
* @param WP_REST_Request $request Current request
* @param string $object_type The request object type
*
* @return bool|int
*/
public static function update_comment_rest_values( $values, $object, $field_name, $request, $object_type ) {
if ( 'cmb2' === $field_name ) {
return self::update_rest_values( $values, $object, $request, $object_type, 'comment' );
}
}
/**
* Handler for updating term custom field data.
*
* @since 2.2.3
*
* @param mixed $values The value of the field
* @param object $object The object from the response
* @param string $field_name Name of field
* @param WP_REST_Request $request Current request
* @param string $object_type The request object type
*
* @return bool|int
*/
public static function update_term_rest_values( $values, $object, $field_name, $request, $object_type ) {
if ( 'cmb2' === $field_name ) {
return self::update_rest_values( $values, $object, $request, $object_type, 'term' );
}
}
/**
* Handler for updating custom field data.
*
* @since 2.2.3
*
* @param mixed $values The value of the field
* @param object $object The object from the response
* @param WP_REST_Request $request Current request
* @param string $object_type The request object type
* @param string $main_object_type The cmb main object type
*
* @return bool|int
*/
protected static function update_rest_values( $values, $object, $request, $object_type, $main_object_type = 'post' ) {
if ( empty( $values ) || ! is_array( $values ) ) {
return;
}
$object_id = self::get_object_id( $object, $main_object_type );
if ( ! $object_id ) {
return;
}
$updated = array();
if ( ! empty( self::$type_boxes[ $main_object_type ] ) ) {
foreach ( self::$type_boxes[ $main_object_type ] as $cmb_id ) {
$rest_box = self::$boxes[ $cmb_id ];
if ( ! array_key_exists( $cmb_id, $values ) ) {
continue;
}
$rest_box->cmb->object_id( $object_id );
$rest_box->cmb->object_type( $main_object_type );
$updated[ $cmb_id ] = $rest_box->sanitize_box_values( $values );
}
}
return $updated;
}
/**
* Loop through box fields and sanitize the values.
*
* @since 2.2.o
*
* @param array $values Array of values being provided.
* @return array Array of updated/sanitized values.
*/
public function sanitize_box_values( array $values ) {
$updated = array();
$this->cmb->pre_process();
foreach ( $this->edit_fields as $field_id ) {
$updated[ $field_id ] = $this->sanitize_field_value( $values, $field_id );
}
$this->cmb->after_save();
return $updated;
}
/**
* Handles returning a sanitized field value.
*
* @since 2.2.3
*
* @param array $values Array of values being provided.
* @param string $field_id The id of the field to update.
*
* @return mixed The results of saving/sanitizing a field value.
*/
protected function sanitize_field_value( array $values, $field_id ) {
if ( ! array_key_exists( $field_id, $values[ $this->cmb->cmb_id ] ) ) {
return;
}
$field = $this->cmb->get_field( $field_id );
if ( 'title' == $field->type() ) {
return;
}
$field->object_id( $this->cmb->object_id() );
$field->object_type( $this->cmb->object_type() );
if ( 'group' == $field->type() ) {
return $this->sanitize_group_value( $values, $field );
}
return $field->save_field( $values[ $this->cmb->cmb_id ][ $field_id ] );
}
/**
* Handles returning a sanitized group field value.
*
* @since 2.2.3
*
* @param array $values Array of values being provided.
* @param CMB2_Field $field CMB2_Field object.
*
* @return mixed The results of saving/sanitizing the group field value.
*/
protected function sanitize_group_value( array $values, CMB2_Field $field ) {
$fields = $field->fields();
if ( empty( $fields ) ) {
return;
}
$this->cmb->data_to_save[ $field->_id() ] = $values[ $this->cmb->cmb_id ][ $field->_id() ];
return $this->cmb->save_group_field( $field );
}
/**
* Filter whether a meta key is protected.
*
* @since 2.2.3
*
* @param bool $protected Whether the key is protected. Default false.
* @param string $meta_key Meta key.
* @param string $meta_type Meta type.
*/
public function is_protected_meta( $protected, $meta_key, $meta_type ) {
if ( $this->field_can_edit( $meta_key ) ) {
return false;
}
return $protected;
}
protected static function get_object_id( $object, $object_type = 'post' ) {
switch ( $object_type ) {
case 'user':
case 'post':
if ( isset( $object->ID ) ) {
return intval( $object->ID );
}
case 'comment':
if ( isset( $object->comment_ID ) ) {
return intval( $object->comment_ID );
}
case 'term':
if ( is_array( $object ) && isset( $object['term_id'] ) ) {
return intval( $object['term_id'] );
} elseif ( isset( $object->term_id ) ) {
return intval( $object->term_id );
}
}
return 0;
}
/**
* Checks if a given field can be read.
*
* @since 2.2.3
*
* @param string|CMB2_Field $field_id Field ID or CMB2_Field object.
* @param boolean $return_object Whether to return the Field object.
*
* @return mixed False if field can't be read or true|CMB2_Field object.
*/
public function field_can_read( $field_id, $return_object = false ) {
return $this->field_can( 'read_fields', $field_id, $return_object );
}
/**
* Checks if a given field can be edited.
*
* @since 2.2.3
*
* @param string|CMB2_Field $field_id Field ID or CMB2_Field object.
* @param boolean $return_object Whether to return the Field object.
*
* @return mixed False if field can't be edited or true|CMB2_Field object.
*/
public function field_can_edit( $field_id, $return_object = false ) {
return $this->field_can( 'edit_fields', $field_id, $return_object );
}
/**
* Checks if a given field can be read or edited.
*
* @since 2.2.3
*
* @param string $type Whether we are checking for read or edit fields.
* @param string|CMB2_Field $field_id Field ID or CMB2_Field object.
* @param boolean $return_object Whether to return the Field object.
*
* @return mixed False if field can't be read or edited or true|CMB2_Field object.
*/
protected function field_can( $type = 'read_fields', $field_id, $return_object = false ) {
if ( ! in_array( $field_id instanceof CMB2_Field ? $field_id->id() : $field_id, $this->{$type}, true ) ) {
return false;
}
return $return_object ? $this->cmb->get_field( $field_id ) : true;
}
/**
* Get a CMB2_REST instance object from the registry by a CMB2 id.
*
* @since 2.2.3
*
* @param string $cmb_id CMB2 config id
*
* @return CMB2_REST|false The CMB2_REST object or false.
*/
public static function get_rest_box( $cmb_id ) {
return isset( self::$boxes[ $cmb_id ] ) ? self::$boxes[ $cmb_id ] : false;
}
/**
* Remove a CMB2_REST instance object from the registry.
*
* @since 2.2.3
*
* @param string $cmb_id A CMB2 instance id.
*/
public static function remove( $cmb_id ) {
if ( array_key_exists( $cmb_id, self::$boxes ) ) {
unset( self::$boxes[ $cmb_id ] );
}
}
/**
* Retrieve all CMB2_REST instances from the registry.
*
* @since 2.2.3
* @return CMB2[] Array of all registered CMB2_REST instances.
*/
public static function get_all() {
return self::$boxes;
}
/**
* Checks if given value is readable.
*
* Value is considered readable if it is not empty and if it does not match the editable blacklist.
*
* @since 2.2.3
*
* @param mixed $value Value to check.
*
* @return boolean Whether value is considered readable.
*/
public static function is_readable( $value ) {
return ! empty( $value ) && ! in_array( $value, array(
WP_REST_Server::CREATABLE,
WP_REST_Server::EDITABLE,
WP_REST_Server::DELETABLE,
), true );
}
/**
* Checks if given value is editable.
*
* Value is considered editable if matches the editable whitelist.
*
* @since 2.2.3
*
* @param mixed $value Value to check.
*
* @return boolean Whether value is considered editable.
*/
public static function is_editable( $value ) {
return in_array( $value, array(
WP_REST_Server::EDITABLE,
WP_REST_Server::ALLMETHODS,
), true );
}
/**
* Magic getter for our object.
*
* @param string $field
* @throws Exception Throws an exception if the field is invalid.
*
* @return mixed
*/
public function __get( $field ) {
switch ( $field ) {
case 'read_fields':
case 'edit_fields':
case 'rest_read':
case 'rest_edit':
return $this->{$field};
default:
throw new Exception( 'Invalid ' . __CLASS__ . ' property: ' . $field );
}
}
}

View File

@ -0,0 +1,428 @@
<?php
if ( ! class_exists( 'WP_REST_Controller' ) ) {
// Shim the WP_REST_Controller class if wp-api plugin not installed, & not in core.
require_once cmb2_dir( 'includes/shim/WP_REST_Controller.php' );
}
/**
* Creates CMB2 objects/fields endpoint for WordPres REST API.
* Allows access to fields registered to a specific post type and more.
*
* @todo Add better documentation.
* @todo Research proper schema.
*
* @since 2.2.3
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
abstract class CMB2_REST_Controller extends WP_REST_Controller {
/**
* The namespace of this controller's route.
*
* @var string
*/
protected $namespace = CMB2_REST::NAME_SPACE;
/**
* The base of this controller's route.
*
* @var string
*/
protected $rest_base;
/**
* The current request object
* @var WP_REST_Request $request
* @since 2.2.3
*/
public $request;
/**
* The current server object
* @var WP_REST_Server $server
* @since 2.2.3
*/
public $server;
/**
* Box object id
* @var mixed
* @since 2.2.3
*/
public $object_id = null;
/**
* Box object type
* @var string
* @since 2.2.3
*/
public $object_type = '';
/**
* CMB2 Instance
*
* @var CMB2_REST
*/
protected $rest_box;
/**
* CMB2_Field Instance
*
* @var CMB2_Field
*/
protected $field;
/**
* The initial route
* @var string
* @since 2.2.3
*/
protected static $route = '';
/**
* Defines which endpoint the initial request is.
* @var string $request_type
* @since 2.2.3
*/
protected static $request_type = '';
/**
* Constructor
* @since 2.2.3
*/
public function __construct( WP_REST_Server $wp_rest_server ) {
$this->server = $wp_rest_server;
}
/**
* A wrapper for `apply_filters` which checks for box/field properties to hook to the filter.
*
* Checks if a CMB object callback property exists, and if it does,
* hook it to the permissions filter.
*
* @since 2.2.3
*
* @param string $filter The name of the filter to apply.
* @param bool $default_access The default access for this request.
*
* @return void
*/
public function maybe_hook_callback_and_apply_filters( $filter, $default_access ) {
if ( ! $this->rest_box && $this->request->get_param( 'cmb_id' ) ) {
$this->rest_box = CMB2_REST::get_rest_box( $this->request->get_param( 'cmb_id' ) );
}
$default_access = $this->maybe_hook_registered_callback( $filter, $default_access );
/**
* Apply the permissions check filter.
*
* @since 2.2.3
*
* @param bool $default_access Whether this CMB2 endpoint can be accessed.
* @param object $controller This CMB2_REST_Controller object.
*/
$default_access = apply_filters( $filter, $default_access, $this );
$this->maybe_unhook_registered_callback( $filter );
return $default_access;
}
/**
* Checks if the CMB2 box has any registered callback parameters for the given filter.
*
* The registered handlers will have a property name which matches the filter, except:
* - The 'cmb2_api' prefix will be removed
* - A '_cb' suffix will be added (to stay inline with other '*_cb' parameters).
*
* @since 2.2.3
*
* @param string $filter The filter name.
* @param bool $default_val The default filter value.
*
* @return bool The possibly-modified filter value (if the '*_cb' param is non-callable).
*/
public function maybe_hook_registered_callback( $filter, $default_val ) {
if ( ! $this->rest_box || is_wp_error( $this->rest_box ) ) {
return $default_val;
}
// Hook box specific filter callbacks.
$val = $this->rest_box->cmb->maybe_hook_parameter( $filter, $default_val );
if ( null !== $val ) {
$default_val = $val;
}
return $default_val;
}
/**
* Unhooks any CMB2 box registered callback parameters for the given filter.
*
* @since 2.2.3
*
* @param string $filter The filter name.
*
* @return void
*/
public function maybe_unhook_registered_callback( $filter ) {
if ( ! $this->rest_box || is_wp_error( $this->rest_box ) ) {
return;
}
// Unhook box specific filter callbacks.
$this->rest_box->cmb->maybe_hook_parameter( $filter, null, 'remove_filter' );
}
/**
* Prepare a CMB2 object for serialization
*
* @since 2.2.3
*
* @param mixed $data
* @return array $data
*/
public function prepare_item( $data ) {
return $this->prepare_item_for_response( $data, $this->request );
}
/**
* Output buffers a callback and returns the results.
*
* @since 2.2.3
*
* @param mixed $cb Callable function/method.
* @return mixed Results of output buffer after calling function/method.
*/
public function get_cb_results( $cb ) {
$args = func_get_args();
array_shift( $args ); // ignore $cb
ob_start();
call_user_func_array( $cb, $args );
return ob_get_clean();
}
/**
* Prepare the CMB2 item for the REST response.
*
* @since 2.2.3
*
* @param mixed $item WordPress representation of the item.
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response $response
*/
public function prepare_item_for_response( $data, $request = null ) {
$data = $this->filter_response_by_context( $data, $this->request['context'] );
/**
* Filter the prepared CMB2 item response.
*
* @since 2.2.3
*
* @param mixed $data Prepared data
* @param object $request The WP_REST_Request object
* @param object $cmb2_endpoints This endpoints object
*/
return apply_filters( 'cmb2_rest_prepare', rest_ensure_response( $data ), $this->request, $this );
}
/**
* Initiates the request property and the rest_box property if box is readable.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Request object.
* @param string $request_type A description of the type of request being made.
*
* @return void
*/
protected function initiate_rest_read_box( $request, $request_type ) {
$this->initiate_rest_box( $request, $request_type );
if ( ! is_wp_error( $this->rest_box ) && ! $this->rest_box->rest_read ) {
$this->rest_box = new WP_Error( 'cmb2_rest_no_read_error', __( 'This box does not have read permissions.', 'cmb2' ), array( 'status' => 403 ) );
}
}
/**
* Initiates the request property and the rest_box property if box is writeable.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Request object.
* @param string $request_type A description of the type of request being made.
*
* @return void
*/
protected function initiate_rest_edit_box( $request, $request_type ) {
$this->initiate_rest_box( $request, $request_type );
if ( ! is_wp_error( $this->rest_box ) && ! $this->rest_box->rest_edit ) {
$this->rest_box = new WP_Error( 'cmb2_rest_no_write_error', __( 'This box does not have write permissions.', 'cmb2' ), array( 'status' => 403 ) );
}
}
/**
* Initiates the request property and the rest_box property.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Request object.
* @param string $request_type A description of the type of request being made.
*
* @return void
*/
protected function initiate_rest_box( $request, $request_type ) {
$this->initiate_request( $request, $request_type );
$this->rest_box = CMB2_REST::get_rest_box( $this->request->get_param( 'cmb_id' ) );
if ( ! $this->rest_box ) {
$this->rest_box = new WP_Error( 'cmb2_rest_box_not_found_error', __( 'No box found by that id. A box needs to be registered with the "show_in_rest" parameter configured.', 'cmb2' ), array( 'status' => 403 ) );
} else {
if ( isset( $this->request['object_id'] ) ) {
$this->rest_box->cmb->object_id( sanitize_text_field( $this->request['object_id'] ) );
}
if ( isset( $this->request['object_type'] ) ) {
$this->rest_box->cmb->object_type( sanitize_text_field( $this->request['object_type'] ) );
}
}
}
/**
* Initiates the request property and sets up the initial static properties.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Request object.
* @param string $request_type A description of the type of request being made.
*
* @return void
*/
public function initiate_request( $request, $request_type ) {
$this->request = $request;
if ( ! isset( $this->request['context'] ) || empty( $this->request['context'] ) ) {
$this->request['context'] = 'view';
}
if ( ! self::$request_type ) {
self::$request_type = $request_type;
}
if ( ! self::$route ) {
self::$route = $this->request->get_route();
}
}
/**
* Useful when getting `_embed`-ed items
*
* @since 2.2.3
*
* @return string Initial requested type.
*/
public static function get_intial_request_type() {
return self::$request_type;
}
/**
* Useful when getting `_embed`-ed items
*
* @since 2.2.3
*
* @return string Initial requested route.
*/
public static function get_intial_route() {
return self::$route;
}
/**
* Get CMB2 fields schema, conforming to JSON Schema
*
* @since 2.2.3
*
* @return array
*/
public function get_item_schema() {
$schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'CMB2',
'type' => 'object',
'properties' => array(
'description' => array(
'description' => __( 'A human-readable description of the object.', 'cmb2' ),
'type' => 'string',
'context' => array( 'view' ),
),
'name' => array(
'description' => __( 'The id for the object.', 'cmb2' ),
'type' => 'integer',
'context' => array( 'view' ),
),
'name' => array(
'description' => __( 'The title for the object.', 'cmb2' ),
'type' => 'string',
'context' => array( 'view' ),
),
),
);
return $this->add_additional_fields_schema( $schema );
}
/**
* Return an array of contextual links for endpoint/object
* @link http://v2.wp-api.org/extending/linking/
* @link http://www.iana.org/assignments/link-relations/link-relations.xhtml
*
* @since 2.2.3
*
* @param mixed $object Object to build links from.
*
* @return array Array of links
*/
abstract protected function prepare_links( $object );
/**
* Get whitelisted query strings from URL for appending to link URLS.
*
* @since 2.2.3
*
* @return string URL query stringl
*/
public function get_query_string() {
$defaults = array(
'object_id' => 0,
'object_type' => '',
'_rendered' => '',
// '_embed' => '',
);
$query_string = '';
foreach ( $defaults as $key => $value ) {
if ( isset( $this->request[ $key ] ) ) {
$query_string .= $query_string ? '&' : '?';
$query_string .= $key;
if ( $value = sanitize_text_field( $this->request[ $key ] ) ) {
$query_string .= '=' . $value;
}
}
}
return $query_string;
}
}

View File

@ -0,0 +1,268 @@
<?php
/**
* CMB2 objects/boxes endpoint for WordPres REST API.
* Allows access to boxes configuration data.
*
* @todo Add better documentation.
* @todo Research proper schema.
*
* @since 2.2.3
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_REST_Controller_Boxes extends CMB2_REST_Controller {
/**
* The base of this controller's route.
*
* @var string
*/
protected $rest_base = 'boxes';
/**
* The combined $namespace and $rest_base for these routes.
*
* @var string
*/
protected $namespace_base = '';
/**
* Constructor
* @since 2.2.3
*/
public function __construct( WP_REST_Server $wp_rest_server ) {
$this->namespace_base = $this->namespace . '/' . $this->rest_base;
parent::__construct( $wp_rest_server );
}
/**
* Register the routes for the objects of the controller.
*
* @since 2.2.3
*/
public function register_routes() {
$args = array(
'_embed' => array(
'description' => __( 'Includes the registered fields for the box in the response.', 'cmb2' ),
),
);
// @todo determine what belongs in the context param.
// $args['context'] = $this->get_context_param();
// $args['context']['required'] = false;
// $args['context']['default'] = 'view';
// $args['context']['enum'] = array( 'view', 'embed' );
// Returns all boxes data.
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
array(
'methods' => WP_REST_Server::READABLE,
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'callback' => array( $this, 'get_items' ),
'args' => $args,
),
'schema' => array( $this, 'get_item_schema' ),
) );
$args['_rendered'] = array(
'description' => __( 'Includes the fully rendered attributes, \'form_open\', \'form_close\', as well as the enqueued \'js_dependencies\' script handles, and \'css_dependencies\' stylesheet handles.', 'cmb2' ),
);
// Returns specific box's data.
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<cmb_id>[\w-]+)', array(
array(
'methods' => WP_REST_Server::READABLE,
'permission_callback' => array( $this, 'get_item_permissions_check' ),
'callback' => array( $this, 'get_item' ),
'args' => $args,
),
'schema' => array( $this, 'get_item_schema' ),
) );
}
/**
* Check if a given request has access to get boxes.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|boolean
*/
public function get_items_permissions_check( $request ) {
$this->initiate_request( $request, __FUNCTION__ );
/**
* By default, no special permissions needed.
*
* @since 2.2.3
*
* @param bool $can_access Whether this CMB2 endpoint can be accessed.
* @param object $controller This CMB2_REST_Controller object.
*/
return apply_filters( 'cmb2_api_get_boxes_permissions_check', true, $this );
}
/**
* Get all public CMB2 boxes.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function get_items( $request ) {
$this->initiate_request( $request, 'boxes_read' );
$boxes = CMB2_REST::get_all();
if ( empty( $boxes ) ) {
return new WP_Error( 'cmb2_rest_no_boxes', __( 'No boxes found.', 'cmb2' ), array( 'status' => 403 ) );
}
$boxes_data = array();
// Loop and prepare boxes data.
foreach ( $boxes as $this->rest_box ) {
if (
// Make sure this box can be read
$this->rest_box->rest_read
// And make sure current user can view this box.
&& $this->get_item_permissions_check_filter( $this->request )
) {
$boxes_data[] = $this->server->response_to_data(
$this->get_rest_box(),
isset( $this->request['_embed'] )
);
}
}
return $this->prepare_item( $boxes_data );
}
/**
* Check if a given request has access to a box.
* By default, no special permissions needed, but filtering return value.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|boolean
*/
public function get_item_permissions_check( $request ) {
$this->initiate_rest_read_box( $request, 'box_read' );
return $this->get_item_permissions_check_filter();
}
/**
* Check by filter if a given request has access to a box.
* By default, no special permissions needed, but filtering return value.
*
* @since 2.2.3
*
* @param bool $can_access Whether the current request has access to view the box by default.
* @return WP_Error|boolean
*/
public function get_item_permissions_check_filter( $can_access = true ) {
/**
* By default, no special permissions needed.
*
* @since 2.2.3
*
* @param bool $can_access Whether this CMB2 endpoint can be accessed.
* @param object $controller This CMB2_REST_Controller object.
*/
return $this->maybe_hook_callback_and_apply_filters( 'cmb2_api_get_box_permissions_check', $can_access );
}
/**
* Get one CMB2 box from the collection.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function get_item( $request ) {
$this->initiate_rest_read_box( $request, 'box_read' );
if ( is_wp_error( $this->rest_box ) ) {
return $this->rest_box;
}
return $this->prepare_item( $this->get_rest_box() );
}
/**
* Get a CMB2 box prepared for REST
*
* @since 2.2.3
*
* @return array
*/
public function get_rest_box() {
$cmb = $this->rest_box->cmb;
$boxes_data = $cmb->meta_box;
if ( isset( $this->request['_rendered'] ) && $this->namespace_base !== ltrim( CMB2_REST_Controller::get_intial_route(), '/' ) ) {
$boxes_data['form_open'] = $this->get_cb_results( array( $cmb, 'render_form_open' ) );
$boxes_data['form_close'] = $this->get_cb_results( array( $cmb, 'render_form_close' ) );
global $wp_scripts, $wp_styles;
$before_css = $wp_styles->queue;
$before_js = $wp_scripts->queue;
CMB2_JS::enqueue();
$boxes_data['js_dependencies'] = array_values( array_diff( $wp_scripts->queue, $before_js ) );
$boxes_data['css_dependencies'] = array_values( array_diff( $wp_styles->queue, $before_css ) );
}
// TODO: look into 'embed' parameter.
// http://demo.wp-api.org/wp-json/wp/v2/posts?_embed
unset( $boxes_data['fields'] );
// Handle callable properties.
unset( $boxes_data['show_on_cb'] );
$response = rest_ensure_response( $boxes_data );
$response->add_links( $this->prepare_links( $cmb ) );
return $response;
}
/**
* Return an array of contextual links for box/boxes.
*
* @since 2.2.3
*
* @param CMB2_REST $cmb CMB2_REST object to build links from.
*
* @return array Array of links
*/
protected function prepare_links( $cmb ) {
$boxbase = $this->namespace_base . '/' . $cmb->cmb_id;
$query_string = $this->get_query_string();
return array(
// Standard Link Relations -- http://v2.wp-api.org/extending/linking/
'self' => array(
'href' => rest_url( $boxbase . $query_string ),
),
'collection' => array(
'href' => rest_url( $this->namespace_base . $query_string ),
),
// Custom Link Relations -- http://v2.wp-api.org/extending/linking/
// TODO URL should document relationship.
'https://cmb2.io/fields' => array(
'href' => rest_url( trailingslashit( $boxbase ) . 'fields' . $query_string ),
'embeddable' => true,
),
);
}
}

View File

@ -0,0 +1,494 @@
<?php
/**
* CMB2 objects/fields endpoint for WordPres REST API.
* Allows access to fields registered to a specific box.
*
* @todo Add better documentation.
* @todo Research proper schema.
*
* @since 2.2.3
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_REST_Controller_Fields extends CMB2_REST_Controller_Boxes {
/**
* Register the routes for the objects of the controller.
*
* @since 2.2.3
*/
public function register_routes() {
$args = array(
'_embed' => array(
'description' => __( 'Includes the box object which the fields are registered to in the response.', 'cmb2' ),
),
'_rendered' => array(
'description' => __( 'When the \'_rendered\' argument is passed, the renderable field attributes will be returned fully rendered. By default, the names of the callback handers for the renderable attributes will be returned.', 'cmb2' ),
),
'object_id' => array(
'description' => __( 'To view or modify the field\'s value, the \'object_id\' and \'object_type\' arguments are required.', 'cmb2' ),
),
'object_type' => array(
'description' => __( 'To view or modify the field\'s value, the \'object_id\' and \'object_type\' arguments are required.', 'cmb2' ),
),
);
// Returns specific box's fields.
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<cmb_id>[\w-]+)/fields/', array(
array(
'methods' => WP_REST_Server::READABLE,
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'callback' => array( $this, 'get_items' ),
'args' => $args,
),
'schema' => array( $this, 'get_item_schema' ),
) );
$delete_args = $args;
$delete_args['object_id']['required'] = true;
$delete_args['object_type']['required'] = true;
// Returns specific field data.
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<cmb_id>[\w-]+)/fields/(?P<field_id>[\w-]+)', array(
array(
'methods' => WP_REST_Server::READABLE,
'permission_callback' => array( $this, 'get_item_permissions_check' ),
'callback' => array( $this, 'get_item' ),
'args' => $args,
),
array(
'methods' => WP_REST_Server::EDITABLE,
'permission_callback' => array( $this, 'update_item_permissions_check' ),
'callback' => array( $this, 'update_item' ),
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
'args' => $args,
),
array(
'methods' => WP_REST_Server::DELETABLE,
'permission_callback' => array( $this, 'delete_item_permissions_check' ),
'callback' => array( $this, 'delete_item' ),
'args' => $delete_args,
),
'schema' => array( $this, 'get_item_schema' ),
) );
}
/**
* Check if a given request has access to get fields.
* By default, no special permissions needed, but filtering return value.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|boolean
*/
public function get_items_permissions_check( $request ) {
$this->initiate_rest_read_box( $request, 'fields_read' );
$can_access = true;
/**
* By default, no special permissions needed.
*
* @since 2.2.3
*
* @param bool $can_access Whether this CMB2 endpoint can be accessed.
* @param object $controller This CMB2_REST_Controller object.
*/
return $this->maybe_hook_callback_and_apply_filters( 'cmb2_api_get_fields_permissions_check', $can_access );
}
/**
* Get all public CMB2 box fields.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function get_items( $request ) {
if ( ! $this->rest_box ) {
$this->initiate_rest_read_box( $request, 'fields_read' );
}
if ( is_wp_error( $this->rest_box ) ) {
return $this->rest_box;
}
$fields = array();
foreach ( $this->rest_box->cmb->prop( 'fields', array() ) as $field ) {
// Make sure this field can be read.
$this->field = $this->rest_box->field_can_read( $field['id'], true );
// And make sure current user can view this box.
if ( $this->field && $this->get_item_permissions_check_filter() ) {
$fields[ $field['id'] ] = $this->server->response_to_data(
$this->prepare_field_response(),
isset( $this->request['_embed'] )
);
}
}
return $this->prepare_item( $fields );
}
/**
* Check if a given request has access to a field.
* By default, no special permissions needed, but filtering return value.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|boolean
*/
public function get_item_permissions_check( $request ) {
$this->initiate_rest_read_box( $request, 'field_read' );
if ( ! is_wp_error( $this->rest_box ) ) {
$this->field = $this->rest_box->field_can_read( $this->request->get_param( 'field_id' ), true );
}
return $this->get_item_permissions_check_filter();
}
/**
* Check by filter if a given request has access to a field.
* By default, no special permissions needed, but filtering return value.
*
* @since 2.2.3
*
* @param bool $can_access Whether the current request has access to view the field by default.
* @return WP_Error|boolean
*/
public function get_item_permissions_check_filter( $can_access = true ) {
/**
* By default, no special permissions needed.
*
* @since 2.2.3
*
* @param bool $can_access Whether this CMB2 endpoint can be accessed.
* @param object $controller This CMB2_REST_Controller object.
*/
return $this->maybe_hook_callback_and_apply_filters( 'cmb2_api_get_field_permissions_check', $can_access );
}
/**
* Get one CMB2 field from the collection.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function get_item( $request ) {
$this->initiate_rest_read_box( $request, 'field_read' );
if ( is_wp_error( $this->rest_box ) ) {
return $this->rest_box;
}
return $this->prepare_read_field( $this->request->get_param( 'field_id' ) );
}
/**
* Check if a given request has access to update a field value.
* By default, requires 'edit_others_posts' capability, but filtering return value.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|boolean
*/
public function update_item_permissions_check( $request ) {
$this->initiate_rest_read_box( $request, 'field_value_update' );
if ( ! is_wp_error( $this->rest_box ) ) {
$this->field = $this->rest_box->field_can_edit( $this->request->get_param( 'field_id' ), true );
}
$can_update = current_user_can( 'edit_others_posts' );
/**
* By default, 'edit_others_posts' is required capability.
*
* @since 2.2.3
*
* @param bool $can_update Whether this CMB2 endpoint can be accessed.
* @param object $controller This CMB2_REST_Controller object.
*/
return $this->maybe_hook_callback_and_apply_filters( 'cmb2_api_update_field_value_permissions_check', $can_update );
}
/**
* Update CMB2 field value.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function update_item( $request ) {
$this->initiate_rest_read_box( $request, 'field_value_update' );
if ( ! $this->request['value'] ) {
return new WP_Error( 'cmb2_rest_update_field_error', __( 'CMB2 Field value cannot be updated without the value parameter specified.', 'cmb2' ), array( 'status' => 400 ) );
}
return $this->modify_field_value( 'updated' );
}
/**
* Check if a given request has access to delete a field value.
* By default, requires 'delete_others_posts' capability, but filtering return value.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|boolean
*/
public function delete_item_permissions_check( $request ) {
$this->initiate_rest_read_box( $request, 'field_value_delete' );
if ( ! is_wp_error( $this->rest_box ) ) {
$this->field = $this->rest_box->field_can_edit( $this->request->get_param( 'field_id' ), true );
}
$can_delete = current_user_can( 'delete_others_posts' );
/**
* By default, 'delete_others_posts' is required capability.
*
* @since 2.2.3
*
* @param bool $can_delete Whether this CMB2 endpoint can be accessed.
* @param object $controller This CMB2_REST_Controller object.
*/
return $this->maybe_hook_callback_and_apply_filters( 'cmb2_api_delete_field_value_permissions_check', $can_delete );
}
/**
* Delete CMB2 field value.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function delete_item( $request ) {
$this->initiate_rest_read_box( $request, 'field_value_delete' );
return $this->modify_field_value( 'deleted' );
}
/**
* Modify CMB2 field value.
*
* @since 2.2.3
*
* @param string $activity The modification activity (updated or deleted).
* @return WP_Error|WP_REST_Response
*/
public function modify_field_value( $activity) {
if ( ! $this->request['object_id'] || ! $this->request['object_type'] ) {
return new WP_Error( 'cmb2_rest_modify_field_value_error', __( 'CMB2 Field value cannot be modified without the object_id and object_type parameters specified.', 'cmb2' ), array( 'status' => 400 ) );
}
if ( is_wp_error( $this->rest_box ) ) {
return $this->rest_box;
}
$this->field = $this->rest_box->field_can_edit(
$this->field ? $this->field : $this->request->get_param( 'field_id' ),
true
);
if ( ! $this->field ) {
return new WP_Error( 'cmb2_rest_no_field_by_id_error', __( 'No field found by that id.', 'cmb2' ), array( 'status' => 403 ) );
}
$this->field->args["value_{$activity}"] = (bool) 'deleted' === $activity
? $this->field->remove_data()
: $this->field->save_field( $this->request['value'] );
// If options page, save the $activity options
if ( 'options-page' == $this->request['object_type'] ) {
$this->field->args["value_{$activity}"] = cmb2_options( $this->request['object_id'] )->set();
}
return $this->prepare_read_field( $this->field );
}
/**
* Get a response object for a specific field ID.
*
* @since 2.2.3
*
* @param string\CMB2_Field Field id or Field object.
* @return WP_Error|WP_REST_Response
*/
public function prepare_read_field( $field ) {
$this->field = $this->rest_box->field_can_read( $field, true );
if ( ! $this->field ) {
return new WP_Error( 'cmb2_rest_no_field_by_id_error', __( 'No field found by that id.', 'cmb2' ), array( 'status' => 403 ) );
}
return $this->prepare_item( $this->prepare_field_response() );
}
/**
* Get a specific field response.
*
* @since 2.2.3
*
* @param CMB2_Field Field object.
* @return array Response array.
*/
public function prepare_field_response() {
$field_data = $this->prepare_field_data( $this->field );
$response = rest_ensure_response( $field_data );
$response->add_links( $this->prepare_links( $this->field ) );
return $response;
}
/**
* Prepare the field data array for JSON.
*
* @since 2.2.3
*
* @param CMB2_Field $field field object.
*
* @return array Array of field data.
*/
protected function prepare_field_data( CMB2_Field $field ) {
$field_data = array();
$params_to_ignore = array( 'show_in_rest', 'options' );
$params_to_rename = array(
'label_cb' => 'label',
'options_cb' => 'options',
);
// Run this first so the js_dependencies arg is populated.
$rendered = ( $cb = $field->maybe_callback( 'render_row_cb' ) )
// Ok, callback is good, let's run it.
? $this->get_cb_results( $cb, $field->args(), $field )
: false;
$field_args = $field->args();
foreach ( $field_args as $key => $value ) {
if ( in_array( $key, $params_to_ignore, true ) ) {
continue;
}
if ( 'options_cb' === $key ) {
$value = $field->options();
} elseif ( in_array( $key, CMB2_Field::$callable_fields, true ) ) {
if ( isset( $this->request['_rendered'] ) ) {
$value = $key === 'render_row_cb' ? $rendered : $field->get_param_callback_result( $key );
} elseif ( is_array( $value ) ) {
// We need to rewrite callbacks as string as they will cause
// JSON recursion errors.
$class = is_string( $value[0] ) ? $value[0] : get_class( $value[0] );
$value = $class . '::' . $value[1];
}
}
$key = isset( $params_to_rename[ $key ] ) ? $params_to_rename[ $key ] : $key;
if ( empty( $value ) || is_scalar( $value ) || is_array( $value ) ) {
$field_data[ $key ] = $value;
} else {
$field_data[ $key ] = sprintf( __( 'Value Error for %s', 'cmb2' ), $key );
}
}
if ( $this->request['object_id'] && $this->request['object_type'] ) {
$field_data['value'] = $field->get_data();
}
return $field_data;
}
/**
* Return an array of contextual links for field/fields.
*
* @since 2.2.3
*
* @param CMB2_Field $field Field object to build links from.
*
* @return array Array of links
*/
protected function prepare_links( $field ) {
$boxbase = $this->namespace_base . '/' . $this->rest_box->cmb->cmb_id;
$query_string = $this->get_query_string();
$links = array(
'self' => array(
'href' => rest_url( trailingslashit( $boxbase ) . 'fields/' . $field->_id() . $query_string ),
),
'collection' => array(
'href' => rest_url( trailingslashit( $boxbase ) . 'fields' . $query_string ),
),
'up' => array(
'embeddable' => true,
'href' => rest_url( $boxbase . $query_string ),
),
);
return $links;
}
/**
* Checks if the CMB2 box or field has any registered callback parameters for the given filter.
*
* The registered handlers will have a property name which matches the filter, except:
* - The 'cmb2_api' prefix will be removed
* - A '_cb' suffix will be added (to stay inline with other '*_cb' parameters).
*
* @since 2.2.3
*
* @param string $filter The filter name.
* @param bool $default_val The default filter value.
*
* @return bool The possibly-modified filter value (if the _cb param is a non-callable).
*/
public function maybe_hook_registered_callback( $filter, $default_val ) {
$default_val = parent::maybe_hook_registered_callback( $filter, $default_val );
if ( $this->field ) {
// Hook field specific filter callbacks.
$val = $this->field->maybe_hook_parameter( $filter, $default_val );
if ( null !== $val ) {
$default_val = $val;
}
}
return $default_val;
}
/**
* Unhooks any CMB2 box or field registered callback parameters for the given filter.
*
* @since 2.2.3
*
* @param string $filter The filter name.
*
* @return void
*/
public function maybe_unhook_registered_callback( $filter ) {
parent::maybe_unhook_registered_callback( $filter );
if ( $this->field ) {
// Unhook field specific filter callbacks.
$this->field->maybe_hook_parameter( $filter, null, 'remove_filter' );
}
}
}

View File

@ -0,0 +1,513 @@
<?php
abstract class WP_REST_Controller {
/**
* The namespace of this controller's route.
*
* @var string
*/
protected $namespace;
/**
* The base of this controller's route.
*
* @var string
*/
protected $rest_base;
/**
* Register the routes for the objects of the controller.
*/
public function register_routes() {
_doing_it_wrong( 'WP_REST_Controller::register_routes', __( 'The register_routes() method must be overriden' ), 'WPAPI-2.0' );
}
/**
* Check if a given request has access to get items.
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|boolean
*/
public function get_items_permissions_check( $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
}
/**
* Get a collection of items.
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function get_items( $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
}
/**
* Check if a given request has access to get a specific item.
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|boolean
*/
public function get_item_permissions_check( $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
}
/**
* Get one item from the collection.
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function get_item( $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
}
/**
* Check if a given request has access to create items.
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|boolean
*/
public function create_item_permissions_check( $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
}
/**
* Create one item from the collection.
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function create_item( $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
}
/**
* Check if a given request has access to update a specific item.
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|boolean
*/
public function update_item_permissions_check( $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
}
/**
* Update one item from the collection.
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function update_item( $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
}
/**
* Check if a given request has access to delete a specific item.
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|boolean
*/
public function delete_item_permissions_check( $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
}
/**
* Delete one item from the collection.
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function delete_item( $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
}
/**
* Prepare the item for create or update operation.
*
* @param WP_REST_Request $request Request object.
* @return WP_Error|object $prepared_item
*/
protected function prepare_item_for_database( $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
}
/**
* Prepare the item for the REST response.
*
* @param mixed $item WordPress representation of the item.
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response $response
*/
public function prepare_item_for_response( $item, $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) );
}
/**
* Prepare a response for inserting into a collection.
*
* @param WP_REST_Response $response Response object.
* @return array Response data, ready for insertion into collection data.
*/
public function prepare_response_for_collection( $response ) {
if ( ! ( $response instanceof WP_REST_Response ) ) {
return $response;
}
$data = (array) $response->get_data();
$server = rest_get_server();
if ( method_exists( $server, 'get_compact_response_links' ) ) {
$links = call_user_func( array( $server, 'get_compact_response_links' ), $response );
} else {
$links = call_user_func( array( $server, 'get_response_links' ), $response );
}
if ( ! empty( $links ) ) {
$data['_links'] = $links;
}
return $data;
}
/**
* Filter a response based on the context defined in the schema.
*
* @param array $data
* @param string $context
* @return array
*/
public function filter_response_by_context( $data, $context ) {
$schema = $this->get_item_schema();
foreach ( $data as $key => $value ) {
if ( empty( $schema['properties'][ $key ] ) || empty( $schema['properties'][ $key ]['context'] ) ) {
continue;
}
if ( ! in_array( $context, $schema['properties'][ $key ]['context'] ) ) {
unset( $data[ $key ] );
continue;
}
if ( 'object' === $schema['properties'][ $key ]['type'] && ! empty( $schema['properties'][ $key ]['properties'] ) ) {
foreach ( $schema['properties'][ $key ]['properties'] as $attribute => $details ) {
if ( empty( $details['context'] ) ) {
continue;
}
if ( ! in_array( $context, $details['context'] ) ) {
if ( isset( $data[ $key ][ $attribute ] ) ) {
unset( $data[ $key ][ $attribute ] );
}
}
}
}
}
return $data;
}
/**
* Get the item's schema, conforming to JSON Schema.
*
* @return array
*/
public function get_item_schema() {
return $this->add_additional_fields_schema( array() );
}
/**
* Get the item's schema for display / public consumption purposes.
*
* @return array
*/
public function get_public_item_schema() {
$schema = $this->get_item_schema();
foreach ( $schema['properties'] as &$property ) {
if ( isset( $property['arg_options'] ) ) {
unset( $property['arg_options'] );
}
}
return $schema;
}
/**
* Get the query params for collections.
*
* @return array
*/
public function get_collection_params() {
return array(
'context' => $this->get_context_param(),
'page' => array(
'description' => __( 'Current page of the collection.' ),
'type' => 'integer',
'default' => 1,
'sanitize_callback' => 'absint',
'validate_callback' => 'rest_validate_request_arg',
'minimum' => 1,
),
'per_page' => array(
'description' => __( 'Maximum number of items to be returned in result set.' ),
'type' => 'integer',
'default' => 10,
'minimum' => 1,
'maximum' => 100,
'sanitize_callback' => 'absint',
'validate_callback' => 'rest_validate_request_arg',
),
'search' => array(
'description' => __( 'Limit results to those matching a string.' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => 'rest_validate_request_arg',
),
);
}
/**
* Get the magical context param.
*
* Ensures consistent description between endpoints, and populates enum from schema.
*
* @param array $args
* @return array
*/
public function get_context_param( $args = array() ) {
$param_details = array(
'description' => __( 'Scope under which the request is made; determines fields present in response.' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_key',
'validate_callback' => 'rest_validate_request_arg',
);
$schema = $this->get_item_schema();
if ( empty( $schema['properties'] ) ) {
return array_merge( $param_details, $args );
}
$contexts = array();
foreach ( $schema['properties'] as $attributes ) {
if ( ! empty( $attributes['context'] ) ) {
$contexts = array_merge( $contexts, $attributes['context'] );
}
}
if ( ! empty( $contexts ) ) {
$param_details['enum'] = array_unique( $contexts );
rsort( $param_details['enum'] );
}
return array_merge( $param_details, $args );
}
/**
* Add the values from additional fields to a data object.
*
* @param array $object
* @param WP_REST_Request $request
* @return array modified object with additional fields.
*/
protected function add_additional_fields_to_object( $object, $request ) {
$additional_fields = $this->get_additional_fields();
foreach ( $additional_fields as $field_name => $field_options ) {
if ( ! $field_options['get_callback'] ) {
continue;
}
$object[ $field_name ] = call_user_func( $field_options['get_callback'], $object, $field_name, $request, $this->get_object_type() );
}
return $object;
}
/**
* Update the values of additional fields added to a data object.
*
* @param array $object
* @param WP_REST_Request $request
*/
protected function update_additional_fields_for_object( $object, $request ) {
$additional_fields = $this->get_additional_fields();
foreach ( $additional_fields as $field_name => $field_options ) {
if ( ! $field_options['update_callback'] ) {
continue;
}
// Don't run the update callbacks if the data wasn't passed in the request.
if ( ! isset( $request[ $field_name ] ) ) {
continue;
}
call_user_func( $field_options['update_callback'], $request[ $field_name ], $object, $field_name, $request, $this->get_object_type() );
}
}
/**
* Add the schema from additional fields to an schema array.
*
* The type of object is inferred from the passed schema.
*
* @param array $schema Schema array.
*/
protected function add_additional_fields_schema( $schema ) {
if ( empty( $schema['title'] ) ) {
return $schema;
}
/**
* Can't use $this->get_object_type otherwise we cause an inf loop.
*/
$object_type = $schema['title'];
$additional_fields = $this->get_additional_fields( $object_type );
foreach ( $additional_fields as $field_name => $field_options ) {
if ( ! $field_options['schema'] ) {
continue;
}
$schema['properties'][ $field_name ] = $field_options['schema'];
}
return $schema;
}
/**
* Get all the registered additional fields for a given object-type.
*
* @param string $object_type
* @return array
*/
protected function get_additional_fields( $object_type = null ) {
if ( ! $object_type ) {
$object_type = $this->get_object_type();
}
if ( ! $object_type ) {
return array();
}
global $wp_rest_additional_fields;
if ( ! $wp_rest_additional_fields || ! isset( $wp_rest_additional_fields[ $object_type ] ) ) {
return array();
}
return $wp_rest_additional_fields[ $object_type ];
}
/**
* Get the object type this controller is responsible for managing.
*
* @return string
*/
protected function get_object_type() {
$schema = $this->get_item_schema();
if ( ! $schema || ! isset( $schema['title'] ) ) {
return null;
}
return $schema['title'];
}
/**
* Get an array of endpoint arguments from the item schema for the controller.
*
* @param string $method HTTP method of the request. The arguments
* for `CREATABLE` requests are checked for required
* values and may fall-back to a given default, this
* is not done on `EDITABLE` requests. Default is
* WP_REST_Server::CREATABLE.
* @return array $endpoint_args
*/
public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ) {
$schema = $this->get_item_schema();
$schema_properties = ! empty( $schema['properties'] ) ? $schema['properties'] : array();
$endpoint_args = array();
foreach ( $schema_properties as $field_id => $params ) {
// Arguments specified as `readonly` are not allowed to be set.
if ( ! empty( $params['readonly'] ) ) {
continue;
}
$endpoint_args[ $field_id ] = array(
'validate_callback' => 'rest_validate_request_arg',
'sanitize_callback' => 'rest_sanitize_request_arg',
);
if ( isset( $params['description'] ) ) {
$endpoint_args[ $field_id ]['description'] = $params['description'];
}
if ( WP_REST_Server::CREATABLE === $method && isset( $params['default'] ) ) {
$endpoint_args[ $field_id ]['default'] = $params['default'];
}
if ( WP_REST_Server::CREATABLE === $method && ! empty( $params['required'] ) ) {
$endpoint_args[ $field_id ]['required'] = true;
}
foreach ( array( 'type', 'format', 'enum' ) as $schema_prop ) {
if ( isset( $params[ $schema_prop ] ) ) {
$endpoint_args[ $field_id ][ $schema_prop ] = $params[ $schema_prop ];
}
}
// Merge in any options provided by the schema property.
if ( isset( $params['arg_options'] ) ) {
// Only use required / default from arg_options on CREATABLE endpoints.
if ( WP_REST_Server::CREATABLE !== $method ) {
$params['arg_options'] = array_diff_key( $params['arg_options'], array( 'required' => '', 'default' => '' ) );
}
$endpoint_args[ $field_id ] = array_merge( $endpoint_args[ $field_id ], $params['arg_options'] );
}
}
return $endpoint_args;
}
/**
* Retrieves post data given a post ID or post object.
*
* This is a subset of the functionality of the `get_post()` function, with
* the additional functionality of having `the_post` action done on the
* resultant post object. This is done so that plugins may manipulate the
* post that is used in the REST API.
*
* @see get_post()
* @global WP_Query $wp_query
*
* @param int|WP_Post $post Post ID or post object. Defaults to global $post.
* @return WP_Post|null A `WP_Post` object when successful.
*/
public function get_post( $post ) {
$post_obj = get_post( $post );
/**
* Filter the post.
*
* Allows plugins to filter the post object as returned by `\WP_REST_Controller::get_post()`.
*
* @param WP_Post|null $post_obj The post object as returned by `get_post()`.
* @param int|WP_Post $post The original value used to obtain the post object.
*/
$post = apply_filters( 'rest_the_post', $post_obj, $post );
return $post;
}
}

View File

@ -0,0 +1,142 @@
<?php
/**
* CMB base field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
abstract class CMB2_Type_Base {
/**
* The CMB2_Types object
* @var CMB2_Types
*/
public $types;
/**
* Arguments for use in the render method
* @var array
*/
public $args;
/**
* Rendered output (if 'rendered' argument is set to false)
* @var string
*/
protected $rendered = '';
/**
* Constructor
* @since 2.2.2
* @param CMB2_Types $types
* @param array $args
*/
public function __construct( CMB2_Types $types, $args = array() ) {
$this->types = $types;
$args['rendered'] = isset( $args['rendered'] ) ? (bool) $args['rendered'] : true;
$this->args = $args;
}
/**
* Handles rendering this field type.
* @since 2.2.2
* @return string Rendered field type.
*/
abstract public function render();
/**
* Stores the rendered field output.
* @since 2.2.2
* @param string|CMB2_Type_Base $rendered Rendered output.
* @return string|CMB2_Type_Base Rendered output or this object.
*/
public function rendered( $rendered ) {
if ( $this->args['rendered'] ) {
return is_a( $rendered, __CLASS__ ) ? $rendered->rendered : $rendered;
}
$this->rendered = is_a( $rendered, __CLASS__ ) ? $rendered->rendered : $rendered;
return $this;
}
/**
* Returns the stored rendered field output.
* @since 2.2.2
* @return string Stored rendered output (if 'rendered' argument is set to false).
*/
public function get_rendered() {
return $this->rendered;
}
/**
* Handles parsing and filtering attributes while preserving any passed in via field config.
* @since 1.1.0
* @param string $element Element for filter
* @param array $type_defaults Type default arguments
* @param array $type_args Type override arguments
* @return array Parsed and filtered arguments
*/
public function parse_args( $element, $type_defaults, $type_args = array() ) {
$type_args = empty( $type_args ) ? $this->args : $type_args;
$field_overrides = $this->field->args( 'attributes' );
$args = ! empty( $field_overrides )
? wp_parse_args( $field_overrides, $type_args )
: $type_args;
/**
* Filter attributes for a field type.
* The dynamic portion of the hook name, $element, refers to the field type.
* @since 1.1.0
* @param array $args The array of attribute arguments.
* @param array $type_defaults The array of default values.
* @param array $field The `CMB2_Field` object.
* @param object $field_type_object This `CMB2_Types` object.
*/
$args = apply_filters( "cmb2_{$element}_attributes", $args, $type_defaults, $this->field, $this->types );
return wp_parse_args( $args, $type_defaults );
}
/**
* Fall back to CMB2_Types methods
* @param string $field
* @throws Exception Throws an exception if the field is invalid.
* @return mixed
*/
public function __call( $name, $arguments ) {
switch ( $name ) {
case '_id':
case '_name':
case '_desc':
case '_text':
case 'concat_attrs':
return call_user_func_array( array( $this->types, $name ), $arguments );
default:
throw new Exception( sprintf( esc_html__( 'Invalid %1$s method: %2$s', 'cmb2' ), __CLASS__, $name ) );
}
}
/**
* Magic getter for our object.
* @param string $field
* @throws Exception Throws an exception if the field is invalid.
* @return mixed
*/
public function __get( $field ) {
switch ( $field ) {
case 'field':
return $this->types->field;
default:
throw new Exception( sprintf( esc_html__( 'Invalid %1$s property: %2$s', 'cmb2' ), __CLASS__, $field ) );
}
}
}

View File

@ -0,0 +1,65 @@
<?php
/**
* CMB checkbox field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Type_Checkbox extends CMB2_Type_Text {
/**
* If checkbox is checked
*
* @var mixed
*/
public $is_checked = null;
/**
* Constructor
*
* @since 2.2.2
*
* @param CMB2_Types $types
* @param array $args
*/
public function __construct( CMB2_Types $types, $args = array(), $is_checked = null ) {
parent::__construct( $types, $args );
$this->is_checked = $is_checked;
}
public function render() {
$defaults = array(
'type' => 'checkbox',
'class' => 'cmb2-option cmb2-list',
'value' => 'on',
'desc' => '',
);
$meta_value = $this->field->escaped_value();
$is_checked = null === $this->is_checked
? ! empty( $meta_value )
: $this->is_checked;
if ( $is_checked ) {
$defaults['checked'] = 'checked';
}
$args = $this->parse_args( 'checkbox', $defaults );
return $this->rendered(
sprintf(
'%s <label for="%s">%s</label>',
parent::render( $args ),
$this->_id(),
$this->_desc()
)
);
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* CMB colorpicker field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Type_Colorpicker extends CMB2_Type_Text {
/**
* The optional value for the colorpicker field
*
* @var string
*/
public $value = '';
/**
* Constructor
*
* @since 2.2.2
*
* @param CMB2_Types $types
* @param array $args
*/
public function __construct( CMB2_Types $types, $args = array(), $value = '' ) {
parent::__construct( $types, $args );
$this->value = $value ? $value : $this->value;
}
public function render() {
$meta_value = $this->value ? $this->value : $this->field->escaped_value();
$hex_color = '(([a-fA-F0-9]){3}){1,2}$';
if ( preg_match( '/^' . $hex_color . '/i', $meta_value ) ) {
// Value is just 123abc, so prepend #
$meta_value = '#' . $meta_value;
} elseif ( ! preg_match( '/^#' . $hex_color . '/i', $meta_value ) ) {
// Value doesn't match #123abc, so sanitize to just #
$meta_value = '#';
}
wp_enqueue_style( 'wp-color-picker' );
$args = wp_parse_args( $this->args, array(
'class' => 'cmb2-colorpicker cmb2-text-small',
'value' => $meta_value,
'js_dependencies' => 'wp-color-picker',
) );
return parent::render( $args );
}
}

View File

@ -0,0 +1,107 @@
<?php
/**
* CMB file field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Type_File extends CMB2_Type_File_Base {
public function render() {
$field = $this->field;
$meta_value = $field->escaped_value();
$options = (array) $field->options();
$img_size = $field->args( 'preview_size' );
$query_args = $field->args( 'query_args' );
$output = '';
// get an array of image size meta data, fallback to 'large'
$img_size_data = parent::get_image_size_data( $img_size, 'large' );
// if options array and 'url' => false, then hide the url field
$input_type = array_key_exists( 'url', $options ) && false === $options['url'] ? 'hidden' : 'text';
$output .= parent::render( array(
'type' => $input_type,
'class' => 'cmb2-upload-file regular-text',
'size' => 45,
'desc' => '',
'data-previewsize' => sprintf( '[%d,%d]', $img_size_data['width'], $img_size_data['height'] ),
'data-sizename' => $img_size_data['name'],
'data-queryargs' => ! empty( $query_args ) ? json_encode( $query_args ) : '',
'js_dependencies' => 'media-editor',
) );
$output .= sprintf( '<input class="cmb2-upload-button button" type="button" value="%s" />', esc_attr( $this->_text( 'add_upload_file_text', esc_html__( 'Add or Upload File', 'cmb2' ) ) ) );
$output .= $this->_desc( true );
$cached_id = $this->_id();
// Reset field args for attachment ID
$args = array(
// If we're looking at a file in a group, we need to get the non-prefixed id
'id' => ( $field->group ? $field->args( '_id' ) : $cached_id ) . '_id',
);
// And get new field object
// (Need to set it to the types field property)
$this->types->field = $field = $field->get_field_clone( $args );
// Get ID value
$_id_value = $field->escaped_value( 'absint' );
// We don't want to output "0" as a value.
if ( ! $_id_value ) {
$_id_value = '';
}
// If there is no ID saved yet, try to get it from the url
if ( $meta_value && ! $_id_value ) {
$_id_value = CMB2_Utils::image_id_from_url( esc_url_raw( $meta_value ) );
}
$output .= parent::render( array(
'type' => 'hidden',
'class' => 'cmb2-upload-file-id',
'value' => $_id_value,
'desc' => '',
) );
$output .= '<div id="' . $this->_id( '-status' ) . '" class="cmb2-media-status">';
if ( ! empty( $meta_value ) ) {
if ( $this->is_valid_img_ext( $meta_value ) ) {
if ( $_id_value ) {
$image = wp_get_attachment_image( $_id_value, $img_size, null, array( 'class' => 'cmb-file-field-image' ) );
} else {
$image = '<img style="max-width: ' . absint( $img_size_data['width'] ) . 'px; width: 100%;" src="' . $meta_value . '" class="cmb-file-field-image" alt="" />';
}
$output .= $this->img_status_output( array(
'image' => $image,
'tag' => 'div',
'cached_id' => $cached_id,
) );
} else {
$output .= $this->file_status_output( array(
'value' => $meta_value,
'tag' => 'div',
'cached_id' => $cached_id,
) );
}
}
$output .= '</div>';
return $this->rendered( $output );
}
}

View File

@ -0,0 +1,205 @@
<?php
/**
* CMB File base field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Type_File_Base extends CMB2_Type_Text {
/**
* Determines if a file has a valid image extension
* @since 1.0.0
* @param string $file File url
* @return bool Whether file has a valid image extension
*/
public function is_valid_img_ext( $file, $blah = false ) {
$file_ext = CMB2_Utils::get_file_ext( $file );
$valid_types = array( 'jpg', 'jpeg', 'png', 'gif', 'ico', 'icon' );
/**
* Which image types are considered valid image file extensions.
*
* @since 2.0.9
*
* @param array $valid_types The valid image file extensions.
*/
$is_valid_types = apply_filters( 'cmb2_valid_img_types', $valid_types );
$is_valid = $file_ext && in_array( $file_ext, (array) $is_valid_types );
/**
* Filter for determining if a field value has a valid image file-type extension.
*
* The dynamic portion of the hook name, $this->field->id(), refers to the field id attribute.
*
* @since 2.0.9
*
* @param bool $is_valid Whether field value has a valid image file-type extension.
* @param string $file File url.
* @param string $file_ext File extension.
*/
return (bool) apply_filters( "cmb2_{$this->field->id()}_is_valid_img_ext", $is_valid, $file, $file_ext );
}
/**
* file/file_list image wrap
* @since 2.0.2
* @param array $args Array of arguments for output
* @return string Image wrap output
*/
public function img_status_output( $args ) {
return sprintf( '<%1$s class="img-status cmb2-media-item">%2$s<p class="cmb2-remove-wrapper"><a href="#" class="cmb2-remove-file-button"%3$s>%4$s</a></p>%5$s</%1$s>',
$args['tag'],
$args['image'],
isset( $args['cached_id'] ) ? ' rel="' . $args['cached_id'] . '"' : '',
esc_html( $this->_text( 'remove_image_text', esc_html__( 'Remove Image', 'cmb2' ) ) ),
isset( $args['id_input'] ) ? $args['id_input'] : ''
);
}
/**
* file/file_list file wrap
* @since 2.0.2
* @param array $args Array of arguments for output
* @return string File wrap output
*/
public function file_status_output( $args ) {
return sprintf( '<%1$s class="file-status cmb2-media-item"><span>%2$s <strong>%3$s</strong></span>&nbsp;&nbsp; (<a href="%4$s" target="_blank" rel="external">%5$s</a> / <a href="#" class="cmb2-remove-file-button"%6$s>%7$s</a>)%8$s</%1$s>',
$args['tag'],
esc_html( $this->_text( 'file_text', esc_html__( 'File:', 'cmb2' ) ) ),
CMB2_Utils::get_file_name_from_path( $args['value'] ),
$args['value'],
esc_html( $this->_text( 'file_download_text', esc_html__( 'Download', 'cmb2' ) ) ),
isset( $args['cached_id'] ) ? ' rel="' . $args['cached_id'] . '"' : '',
esc_html( $this->_text( 'remove_text', esc_html__( 'Remove', 'cmb2' ) ) ),
isset( $args['id_input'] ) ? $args['id_input'] : ''
);
}
/**
* Outputs the file/file_list underscore Javascript templates in the footer.
* @since 2.2.4
* @return void
*/
public static function output_js_underscore_templates() {
?>
<script type="text/html" id="tmpl-cmb2-single-image">
<div class="img-status cmb2-media-item">
<img width="{{ data.sizeWidth }}" height="{{ data.sizeHeight }}" src="{{ data.sizeUrl }}" class="cmb-file-field-image" alt="{{ data.filename }}" title="{{ data.filename }}" />
<p><a href="#" class="cmb2-remove-file-button" rel="{{ data.mediaField }}">{{ data.stringRemoveImage }}</a></p>
</div>
</script>
<script type="text/html" id="tmpl-cmb2-single-file">
<div class="file-status cmb2-media-item">
<span>{{ data.stringFile }} <strong>{{ data.filename }}</strong></span>&nbsp;&nbsp; (<a href="{{ data.url }}" target="_blank" rel="external">{{ data.stringDownload }}</a> / <a href="#" class="cmb2-remove-file-button" rel="{{ data.mediaField }}">{{ data.stringRemoveFile }}</a>)
</div>
</script>
<script type="text/html" id="tmpl-cmb2-list-image">
<li class="img-status cmb2-media-item">
<img width="{{ data.sizeWidth }}" height="{{ data.sizeHeight }}" src="{{ data.sizeUrl }}" class="cmb-file_list-field-image" alt="{{ data.filename }}">
<p><a href="#" class="cmb2-remove-file-button" rel="{{ data.mediaField }}[{{ data.id }}]">{{ data.stringRemoveImage }}</a></p>
<input type="hidden" id="filelist-{{ data.id }}" data-id="{{ data.id }}" name="{{ data.mediaFieldName }}[{{ data.id }}]" value="{{ data.url }}">
</li>
</script>
<script type="text/html" id="tmpl-cmb2-list-file">
<li class="file-status cmb2-media-item">
<span>{{ data.stringFile }} <strong>{{ data.filename }}</strong></span>&nbsp;&nbsp; (<a href="{{ data.url }}" target="_blank" rel="external">{{ data.stringDownload }}</a> / <a href="#" class="cmb2-remove-file-button" rel="{{ data.mediaField }}[{{ data.id }}]">{{ data.stringRemoveFile }}</a>)
<input type="hidden" id="filelist-{{ data.id }}" data-id="{{ data.id }}" name="{{ data.mediaFieldName }}[{{ data.id }}]" value="{{ data.url }}">
</li>
</script>
<?php
}
/**
* Utility method to return an array of meta data for a registered image size
*
* Uses CMB2_Utils::get_named_size() to get the closest available named size
* from an array of width and height values and CMB2_Utils::get_available_image_sizes()
* to get the meta data associated with a named size.
*
* @since 2.2.4
* @param array|string $img_size Image size. Accepts an array of width and height (in that order)
* @param string $fallback Size to use if the supplied named size doesn't exist
* @return array Array containing the image size meta data
* $size = (
* 'width' => (int) image size width
* 'height' => (int) image size height
* 'name' => (string) e.g. 'thumbnail'
* )
*/
static function get_image_size_data( $img_size = '', $fallback = 'thumbnail' ) {
$data = array();
if ( is_array( $img_size ) ) {
$data['width'] = intval( $img_size[0] );
$data['height'] = intval( $img_size[1] );
$data['name'] = '';
// Try and get the closest named size from our array of dimensions
if ( $named_size = CMB2_Utils::get_named_size( $img_size ) ) {
$data['name'] = $named_size;
}
} else {
$image_sizes = CMB2_Utils::get_available_image_sizes();
// The 'thumb' alias, which works elsewhere, doesn't work in the wp.media uploader
if ( 'thumb' == $img_size ) {
$img_size = 'thumbnail';
}
// Named size doesn't exist, use $fallback
if ( ! array_key_exists( $img_size, $image_sizes ) ) {
$img_size = $fallback;
}
// Get image dimensions from named sizes
$data['width'] = intval( $image_sizes[ $img_size ]['width'] );
$data['height'] = intval( $image_sizes[ $img_size ]['height'] );
$data['name'] = $img_size;
}
return $data;
}
/**
* Filters attachment data prepared for JavaScript.
*
* Adds the url, width, height, and orientation for custom sizes to the JavaScript
* object returned by the wp.media uploader. Hooked to 'wp_prepare_attachment_for_js'.
*
* @since 2.2.4
* @param array $response Array of prepared attachment data
* @param int|object $attachment Attachment ID or object
* @param array $meta Array of attachment meta data ( from wp_get_attachment_metadata() )
* @return array filtered $response array
*/
public static function prepare_image_sizes_for_js( $response, $attachment, $meta ) {
foreach ( CMB2_Utils::get_available_image_sizes() as $size => $info ) {
// registered image size exists for this attachment
if ( isset( $meta['sizes'][ $size ] ) ) {
$attachment_url = wp_get_attachment_url( $attachment->ID );
$base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url );
$size_meta = $meta['sizes'][ $size ];
$response['sizes'][ $size ] = array(
'url' => $base_url . $size_meta['file'],
'height' => $size_meta['height'],
'width' => $size_meta['width'],
'orientation' => $size_meta['height'] > $size_meta['width'] ? 'portrait' : 'landscape',
);
}
}
return $response;
}
}

View File

@ -0,0 +1,83 @@
<?php
/**
* CMB file_list field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Type_File_List extends CMB2_Type_File_Base {
public function render() {
$field = $this->field;
$meta_value = $field->escaped_value();
$name = $this->_name();
$img_size = $field->args( 'preview_size' );
$query_args = $field->args( 'query_args' );
$output = '';
// get an array of image size meta data, fallback to 'thumbnail'
$img_size_data = parent::get_image_size_data( $img_size, 'thumbnail' );
$output .= parent::render( array(
'type' => 'hidden',
'class' => 'cmb2-upload-file cmb2-upload-list',
'size' => 45, 'desc' => '', 'value' => '',
'data-previewsize' => sprintf( '[%d,%d]', $img_size_data['width'], $img_size_data['height'] ),
'data-sizename' => $img_size_data['name'],
'data-queryargs' => ! empty( $query_args ) ? json_encode( $query_args ) : '',
'js_dependencies' => 'media-editor',
) );
$output .= parent::render( array(
'type' => 'button',
'class' => 'cmb2-upload-button button cmb2-upload-list',
'value' => esc_attr( $this->_text( 'add_upload_files_text', esc_html__( 'Add or Upload Files', 'cmb2' ) ) ),
'name' => '', 'id' => '',
) );
$output .= '<ul id="' . $this->_id( '-status' ) . '" class="cmb2-media-status cmb-attach-list">';
if ( $meta_value && is_array( $meta_value ) ) {
foreach ( $meta_value as $id => $fullurl ) {
$id_input = parent::render( array(
'type' => 'hidden',
'value' => $fullurl,
'name' => $name . '[' . $id . ']',
'id' => 'filelist-' . $id,
'data-id' => $id,
'desc' => '',
'class' => false,
) );
if ( $this->is_valid_img_ext( $fullurl ) ) {
$output .= $this->img_status_output( array(
'image' => wp_get_attachment_image( $id, $img_size ),
'tag' => 'li',
'id_input' => $id_input,
) );
} else {
$output .= $this->file_status_output( array(
'value' => $fullurl,
'tag' => 'li',
'id_input' => $id_input,
) );
}
}
}
$output .= '</ul>';
return $this->rendered( $output );
}
}

View File

@ -0,0 +1,107 @@
<?php
/**
* CMB Multi base field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
abstract class CMB2_Type_Multi_Base extends CMB2_Type_Base {
/**
* Generates html for an option element
* @since 1.1.0
* @param array $args Arguments array containing value, label, and checked boolean
* @return string Generated option element html
*/
public function select_option( $args = array() ) {
return sprintf( "\t" . '<option value="%s" %s>%s</option>', $args['value'], selected( isset( $args['checked'] ) && $args['checked'], true, false ), $args['label'] ) . "\n";
}
/**
* Generates html for list item with input
* @since 1.1.0
* @param array $args Override arguments
* @param int $i Iterator value
* @return string Gnerated list item html
*/
public function list_input( $args = array(), $i ) {
$a = $this->parse_args( 'list_input', array(
'type' => 'radio',
'class' => 'cmb2-option',
'name' => $this->_name(),
'id' => $this->_id( $i ),
'value' => $this->field->escaped_value(),
'label' => '',
), $args );
return sprintf( "\t" . '<li><input%s/> <label for="%s">%s</label></li>' . "\n", $this->concat_attrs( $a, array( 'label' ) ), $a['id'], $a['label'] );
}
/**
* Generates html for list item with checkbox input
* @since 1.1.0
* @param array $args Override arguments
* @param int $i Iterator value
* @return string Gnerated list item html
*/
public function list_input_checkbox( $args, $i ) {
$saved_value = $this->field->escaped_value();
if ( is_array( $saved_value ) && in_array( $args['value'], $saved_value ) ) {
$args['checked'] = 'checked';
}
$args['type'] = 'checkbox';
return $this->list_input( $args, $i );
}
/**
* Generates html for concatenated items
* @since 1.1.0
* @param array $args Optional arguments
* @return string Concatenated html items
*/
public function concat_items( $args = array() ) {
$field = $this->field;
$method = isset( $args['method'] ) ? $args['method'] : 'select_option';
unset( $args['method'] );
$value = null !== $field->escaped_value()
? $field->escaped_value()
: $field->get_default();
if ( is_numeric( $value ) ) {
$value = intval( $value );
}
$concatenated_items = ''; $i = 1;
$options = array();
if ( $option_none = $field->args( 'show_option_none' ) ) {
$options[ '' ] = $option_none;
}
$options = $options + (array) $field->options();
foreach ( $options as $opt_value => $opt_label ) {
// Clone args & modify for just this item
$a = $args;
$a['value'] = $opt_value;
$a['label'] = $opt_label;
// Check if this option is the value of the input
if ( $value === $opt_value ) {
$a['checked'] = 'checked';
}
$concatenated_items .= $this->$method( $a, $i++ );
}
return $concatenated_items;
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* CMB multicheck field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Type_Multicheck extends CMB2_Type_Radio {
/**
* The type of radio field
*
* @var string
*/
public $type = 'checkbox';
public function render() {
$classes = false === $this->field->args( 'select_all_button' )
? 'cmb2-checkbox-list no-select-all cmb2-list'
: 'cmb2-checkbox-list cmb2-list';
$args = $this->parse_args( $this->type, array(
'class' => $classes,
'options' => $this->concat_items( array(
'name' => $this->_name() . '[]',
'method' => 'list_input_checkbox',
) ),
'desc' => $this->_desc( true ),
) );
return $this->rendered( $this->ul( $args ) );
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* CMB oembed field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Type_Oembed extends CMB2_Type_Text {
public function render() {
$field = $this->field;
$meta_value = trim( $field->escaped_value() );
$oembed = ! empty( $meta_value )
? cmb2_ajax()->get_oembed( array(
'url' => $field->escaped_value(),
'object_id' => $field->object_id,
'object_type' => $field->object_type,
'oembed_args' => array( 'width' => '640' ),
'field_id' => $this->_id(),
) )
: '';
return parent::render( array(
'class' => 'cmb2-oembed regular-text',
'data-objectid' => $field->object_id,
'data-objecttype' => $field->object_type,
) )
. '<p class="cmb-spinner spinner"></p>'
. '<div id="'. $this->_id( '-status' ). '" class="cmb2-media-status ui-helper-clearfix embed_wrap">' . $oembed . '</div>';
}
}

View File

@ -0,0 +1,55 @@
<?php
/**
* CMB Picker base field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
abstract class CMB2_Type_Picker_Base extends CMB2_Type_Text {
/**
* Parse the picker attributes.
* @since 2.2.0
* @param string $arg 'date' or 'time'
* @param array $args Optional arguments to modify (else use $this->field->args['attributes'])
* @return array Array of field attributes
*/
public function parse_picker_options( $arg = 'date', $args = array() ) {
$att = 'data-' . $arg . 'picker';
$update = empty( $args );
$atts = array();
$format = $this->field->args( $arg . '_format' );
if ( $js_format = CMB2_Utils::php_to_js_dateformat( $format ) ) {
if ( $update ) {
$atts = $this->field->args( 'attributes' );
} else {
$atts = isset( $args['attributes'] )
? $args['attributes']
: $atts;
}
// Don't override user-provided datepicker values
$data = isset( $atts[ $att ] )
? json_decode( $atts[ $att ], true )
: array();
$data[ $arg . 'Format' ] = $js_format;
$atts[ $att ] = function_exists( 'wp_json_encode' )
? wp_json_encode( $data )
: json_encode( $data );
}
if ( $update ) {
$this->field->args['attributes'] = $atts;
}
return array_merge( $args, $atts );
}
}

View File

@ -0,0 +1,52 @@
<?php
/**
* CMB radio field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Type_Radio extends CMB2_Type_Multi_Base {
/**
* The type of radio field
*
* @var string
*/
public $type = 'radio';
/**
* Constructor
*
* @since 2.2.2
*
* @param CMB2_Types $types
* @param array $args
*/
public function __construct( CMB2_Types $types, $args = array(), $type = '' ) {
parent::__construct( $types, $args );
$this->type = $type ? $type : $this->type;
}
public function render() {
$args = $this->parse_args( $this->type, array(
'class' => 'cmb2-radio-list cmb2-list',
'options' => $this->concat_items( array(
'label' => 'test',
'method' => 'list_input'
) ),
'desc' => $this->_desc( true ),
) );
return $this->rendered( $this->ul( $args ) );
}
protected function ul( $a ) {
return sprintf( '<ul class="%s">%s</ul>%s', $a['class'], $a['options'], $a['desc'] );
}
}

View File

@ -0,0 +1,30 @@
<?php
/**
* CMB select field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Type_Select extends CMB2_Type_Multi_Base {
public function render() {
$a = $this->parse_args( 'select', array(
'class' => 'cmb2_select',
'name' => $this->_name(),
'id' => $this->_id(),
'desc' => $this->_desc( true ),
'options' => $this->concat_items(),
) );
$attrs = $this->concat_attrs( $a, array( 'desc', 'options' ) );
return $this->rendered(
sprintf( '<select%s>%s</select>%s', $attrs, $a['options'], $a['desc'] )
);
}
}

View File

@ -0,0 +1,29 @@
<?php
/**
* CMB select_timezone field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Type_Select_Timezone extends CMB2_Type_Select {
public function render() {
$this->field->args['default'] = $this->field->get_default()
? $this->field->get_default()
: CMB2_Utils::timezone_string();
$this->args = wp_parse_args( $this->args, array(
'class' => 'cmb2_select cmb2-select-timezone',
'options' => wp_timezone_choice( $this->field->escaped_value() ),
'desc' => $this->_desc(),
) );
return parent::render();
}
}

View File

@ -0,0 +1,87 @@
<?php
/**
* CMB Taxonomy base field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
abstract class CMB2_Type_Taxonomy_Base extends CMB2_Type_Multi_Base {
/**
* Checks if we can get a post object, and if so, uses `get_the_terms` which utilizes caching.
* @since 1.0.2
* @return mixed Array of terms on success
*/
public function get_object_terms() {
if ( 'options-page' === $this->field->object_type ) {
return $this->options_terms();
}
if ( 'post' !== $this->field->object_type ) {
return $this->non_post_object_terms();
}
// WP caches internally so it's better to use
return get_the_terms( $this->field->object_id, $this->field->args( 'taxonomy' ) );
}
/**
* Gets the term objects for the terms stored via options boxes.
* @since 2.2.4
* @return mixed Array of terms on success
*/
public function options_terms() {
if ( empty( $this->field->value ) ) {
return array();
}
$terms = (array) $this->field->value;
foreach ( $terms as $index => $term ) {
$terms[ $index ] = get_term_by( 'slug', $term, $this->field->args( 'taxonomy' ) );
}
return $terms;
}
/**
* For non-post objects, wraps the call to wp_get_object_terms with transient caching.
* @since 2.2.4
* @return mixed Array of terms on success
*/
public function non_post_object_terms() {
$object_id = $this->field->object_id;
$taxonomy = $this->field->args( 'taxonomy' );
$cache_key = "cmb-cache-{$taxonomy}-{$object_id}";
// Check cache
$cached = get_transient( $cache_key );
if ( ! $cached ) {
$cached = wp_get_object_terms( $object_id, $taxonomy );
// Do our own (minimal) caching. Long enough for a page-load.
set_transient( $cache_key, $cached, 60 );
}
return $cached;
}
/**
* Wrapper for `get_terms` to account for changes in WP 4.6 where taxonomy is expected
* as part of the arguments.
* @since 2.2.2
* @return mixed Array of terms on success
*/
public function get_terms() {
return CMB2_Utils::wp_at_least( '4.5.0' )
? get_terms( array( 'taxonomy' => $this->field->args( 'taxonomy' ), 'hide_empty' => false ) )
: get_terms( $this->field->args( 'taxonomy' ), 'hide_empty=0' );
}
}

View File

@ -0,0 +1,54 @@
<?php
/**
* CMB taxonomy_multicheck field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Type_Taxonomy_Multicheck extends CMB2_Type_Taxonomy_Base {
public function render() {
$field = $this->field;
$names = $this->get_object_terms();
$saved_terms = is_wp_error( $names ) || empty( $names )
? $field->get_default()
: wp_list_pluck( $names, 'slug' );
$terms = $this->get_terms();
$name = $this->_name() . '[]';
$options = ''; $i = 1;
if ( ! $terms ) {
$options .= sprintf( '<li><label>%s</label></li>', esc_html( $this->_text( 'no_terms_text', esc_html__( 'No terms', 'cmb2' ) ) ) );
} else {
foreach ( $terms as $term ) {
$args = array(
'value' => $term->slug,
'label' => $term->name,
'type' => 'checkbox',
'name' => $name,
);
if ( is_array( $saved_terms ) && in_array( $term->slug, $saved_terms ) ) {
$args['checked'] = 'checked';
}
$options .= $this->list_input( $args, $i );
$i++;
}
}
$classes = false === $field->args( 'select_all_button' )
? 'cmb2-checkbox-list no-select-all cmb2-list'
: 'cmb2-checkbox-list cmb2-list';
return $this->rendered(
$this->types->radio( array( 'class' => $classes, 'options' => $options ), 'taxonomy_multicheck' )
);
}
}

View File

@ -0,0 +1,81 @@
<?php
/**
* CMB taxonomy_radio field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Type_Taxonomy_Radio extends CMB2_Type_Taxonomy_Base {
public function render() {
$field = $this->field;
$names = $this->get_object_terms();
$saved_term = is_wp_error( $names ) || empty( $names ) ? $this->field->get_default() : array_shift( $names )->slug;
$terms = $this->get_terms();
$options = '';
$i = 1;
if ( ! $terms ) {
$options .= sprintf( '<li><label>%s</label></li>', esc_html( $this->_text( 'no_terms_text', esc_html__( 'No terms', 'cmb2' ) ) ) );
} else {
$option_none = $field->args( 'show_option_none' );
if ( ! empty( $option_none ) ) {
$field_id = $this->_id();
/**
* Default (option-none) taxonomy-radio value.
*
* @since 1.3.0
*
* @param string $option_none_value Default (option-none) taxonomy-radio value.
*/
$option_none_value = apply_filters( 'cmb2_taxonomy_radio_default_value', '' );
/**
* Default (option-none) taxonomy-radio value.
*
* The dynamic portion of the hook name, $field_id, refers to the field id attribute.
*
* @since 1.3.0
*
* @param string $option_none_value Default (option-none) taxonomy-radio value.
*/
$option_none_value = apply_filters( "cmb2_taxonomy_radio_{$field_id}_default_value", $option_none_value );
$args = array(
'value' => $option_none_value,
'label' => $option_none,
);
if ( $saved_term == $option_none_value ) {
$args['checked'] = 'checked';
}
$options .= $this->list_input( $args, $i );
$i++;
}
foreach ( $terms as $term ) {
$args = array(
'value' => $term->slug,
'label' => $term->name,
);
if ( $saved_term == $term->slug ) {
$args['checked'] = 'checked';
}
$options .= $this->list_input( $args, $i );
$i++;
}
}
return $this->rendered(
$this->types->radio( array( 'options' => $options ), 'taxonomy_radio' )
);
}
}

View File

@ -0,0 +1,68 @@
<?php
/**
* CMB taxonomy_select field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Type_Taxonomy_Select extends CMB2_Type_Taxonomy_Base {
public function render() {
$names = $this->get_object_terms();
$saved_term = is_wp_error( $names ) || empty( $names ) ? $this->field->get_default() : array_shift( $names )->slug;
$terms = $this->get_terms();
$options = '';
$option_none = $this->field->args( 'show_option_none' );
if ( ! empty( $option_none ) ) {
$field_id = $this->_id();
/**
* Default (option-none) taxonomy-select value.
*
* @since 1.3.0
*
* @param string $option_none_value Default (option-none) taxonomy-select value.
*/
$option_none_value = apply_filters( 'cmb2_taxonomy_select_default_value', '' );
/**
* Default (option-none) taxonomy-select value.
*
* The dynamic portion of the hook name, $field_id, refers to the field id attribute.
*
* @since 1.3.0
*
* @param string $option_none_value Default (option-none) taxonomy-select value.
*/
$option_none_value = apply_filters( "cmb2_taxonomy_select_{$field_id}_default_value", $option_none_value );
$options .= $this->select_option( array(
'label' => $option_none,
'value' => $option_none_value,
'checked' => $saved_term == $option_none_value,
) );
}
if ( ! empty( $terms ) ) {
foreach ( $terms as $term ) {
$options .= $this->select_option( array(
'label' => $term->name,
'value' => $term->slug,
'checked' => $saved_term === $term->slug,
) );
}
}
return $this->rendered(
$this->types->select( array( 'options' => $options ) )
);
}
}

View File

@ -0,0 +1,61 @@
<?php
/**
* CMB text field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Type_Text extends CMB2_Type_Base {
/**
* The type of field
*
* @var string
*/
public $type = 'input';
/**
* Constructor
*
* @since 2.2.2
*
* @param CMB2_Types $types
* @param array $args
*/
public function __construct( CMB2_Types $types, $args = array(), $type = '' ) {
parent::__construct( $types, $args );
$this->type = $type ? $type : $this->type;
}
/**
* Handles outputting an 'input' element
* @since 1.1.0
* @param array $args Override arguments
* @return string Form input element
*/
public function render( $args = array() ) {
$args = empty( $args ) ? $this->args : $args;
$a = $this->parse_args( $this->type, array(
'type' => 'text',
'class' => 'regular-text',
'name' => $this->_name(),
'id' => $this->_id(),
'value' => $this->field->escaped_value(),
'desc' => $this->_desc( true ),
'js_dependencies' => array(),
), $args );
if ( ! empty( $a['js_dependencies'] ) ) {
$this->field->add_js_dependencies( $a['js_dependencies'] );
}
return $this->rendered(
sprintf( '<input%s/>%s', $this->concat_attrs( $a, array( 'desc', 'js_dependencies' ) ), $a['desc'] )
);
}
}

View File

@ -0,0 +1,30 @@
<?php
/**
* CMB text_date field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Type_Text_Date extends CMB2_Type_Picker_Base {
public function render() {
$args = $this->parse_args( 'text_date', array(
'class' => 'cmb2-text-small cmb2-datepicker',
'value' => $this->field->get_timestamp_format(),
'desc' => $this->_desc(),
'js_dependencies' => array( 'jquery-ui-core', 'jquery-ui-datepicker' ),
) );
if ( false === strpos( $args['class'], 'timepicker' ) ) {
$this->parse_picker_options( 'date' );
}
return parent::render( $args );
}
}

View File

@ -0,0 +1,73 @@
<?php
/**
* CMB text_datetime_timestamp field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Type_Text_Datetime_Timestamp extends CMB2_Type_Picker_Base {
public function render() {
$field = $this->field;
$args = wp_parse_args( $this->args, array(
'value' => $field->escaped_value(),
'desc' => $this->_desc(),
'datepicker' => array(),
'timepicker' => array(),
) );
if ( empty( $args['value'] ) ) {
$args['value'] = $field->escaped_value();
// This will be used if there is a select_timezone set for this field
$tz_offset = $field->field_timezone_offset();
if ( ! empty( $tz_offset ) ) {
$args['value'] -= $tz_offset;
}
}
$has_good_value = ! empty( $args['value'] ) && ! is_array( $args['value'] );
$date_input = parent::render( $this->date_args( $args, $has_good_value ) );
$time_input = parent::render( $this->time_args( $args, $has_good_value ) );
return $this->rendered( $date_input . "\n" . $time_input );
}
public function date_args( $args, $has_good_value ) {
$date_args = wp_parse_args( $args['datepicker'], array(
'class' => 'cmb2-text-small cmb2-datepicker',
'name' => $this->_name( '[date]' ),
'id' => $this->_id( '_date' ),
'value' => $has_good_value ? $this->field->get_timestamp_format( 'date_format', $args['value'] ) : '',
'desc' => '',
) );
$date_args['rendered'] = true;
// Let's get the date-format, and set it up as a data attr for the field.
return $this->parse_picker_options( 'date', $date_args );
}
public function time_args( $args, $has_good_value ) {
$time_args = wp_parse_args( $args['timepicker'], array(
'class' => 'cmb2-timepicker text-time',
'name' => $this->_name( '[time]' ),
'id' => $this->_id( '_time' ),
'value' => $has_good_value ? $this->field->get_timestamp_format( 'time_format', $args['value'] ) : '',
'desc' => $args['desc'],
'js_dependencies' => array( 'jquery-ui-core', 'jquery-ui-datepicker', 'jquery-ui-datetimepicker' ),
) );
$time_args['rendered'] = true;
// Let's get the time-format, and set it up as a data attr for the field.
return $this->parse_picker_options( 'time', $time_args );
}
}

View File

@ -0,0 +1,61 @@
<?php
/**
* CMB text_datetime_timestamp_timezone field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Type_Text_Datetime_Timestamp_Timezone extends CMB2_Type_Base {
public function render() {
$field = $this->field;
$args = wp_parse_args( $this->args, array(
'value' => $field->escaped_value(),
'desc' => $this->_desc( true ),
'text_datetime_timestamp' => array(),
'select_timezone' => array(),
) );
$args['value'] = $field->escaped_value();
if ( is_array( $args['value'] ) ) {
$args['value'] = '';
}
$datetime = maybe_unserialize( $args['value'] );
$value = $tzstring = '';
if ( $datetime && $datetime instanceof DateTime ) {
$tz = $datetime->getTimezone();
$tzstring = $tz->getName();
$value = $datetime->getTimestamp();
}
$timestamp_args = wp_parse_args( $args['text_datetime_timestamp'], array(
'desc' => '',
'value' => $value,
'rendered' => true,
) );
$datetime_timestamp = $this->types->text_datetime_timestamp( $timestamp_args );
$timezone_select_args = wp_parse_args( $args['select_timezone'], array(
'class' => 'cmb2_select cmb2-select-timezone',
'name' => $this->_name( '[timezone]' ),
'id' => $this->_id( '_timezone' ),
'options' => wp_timezone_choice( $tzstring ),
'desc' => $args['desc'],
'rendered' => true,
) );
$select = $this->types->select( $timezone_select_args );
return $this->rendered(
$datetime_timestamp . "\n" . $select
);
}
}

View File

@ -0,0 +1,25 @@
<?php
/**
* CMB text_time field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Type_Text_Time extends CMB2_Type_Text_Date {
public function render() {
$this->args = $this->parse_picker_options( 'time', wp_parse_args( $this->args, array(
'class' => 'cmb2-timepicker text-time',
'value' => $this->field->get_timestamp_format( 'time_format' ),
'js_dependencies' => array( 'jquery-ui-core', 'jquery-ui-datepicker', 'jquery-ui-datetimepicker' ),
) ) );
return parent::render();
}
}

View File

@ -0,0 +1,37 @@
<?php
/**
* CMB textarea field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Type_Textarea extends CMB2_Type_Base {
/**
* Handles outputting an 'textarea' element
* @since 1.1.0
* @param array $args Override arguments
* @return string Form textarea element
*/
public function render( $args = array() ) {
$args = empty( $args ) ? $this->args : $args;
$a = $this->parse_args( 'textarea', array(
'class' => 'cmb2_textarea',
'name' => $this->_name(),
'id' => $this->_id(),
'cols' => 60,
'rows' => 10,
'value' => $this->field->escaped_value( 'esc_textarea' ),
'desc' => $this->_desc( true ),
), $args );
return $this->rendered(
sprintf( '<textarea%s>%s</textarea>%s', $this->concat_attrs( $a, array( 'desc', 'value' ) ), $a['value'], $a['desc'] )
);
}
}

View File

@ -0,0 +1,29 @@
<?php
/**
* CMB textarea_code field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Type_Textarea_Code extends CMB2_Type_Textarea {
/**
* Handles outputting an 'textarea' element
* @since 1.1.0
* @param array $args Override arguments
* @return string Form textarea element
*/
public function render() {
return $this->rendered(
sprintf( '<pre>%s', parent::render( array(
'class' => 'cmb2-textarea-code',
'desc' => '</pre>' . $this->_desc( true ),
) ) )
);
}
}

View File

@ -0,0 +1,46 @@
<?php
/**
* CMB title field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Type_Title extends CMB2_Type_Base {
/**
* Handles outputting an 'title' element
* @return string Heading element
*/
public function render() {
$name = $this->field->args( 'name' );
$tag = 'span';
if ( ! empty( $name ) ) {
$tag = $this->field->object_type == 'post' ? 'h5' : 'h3';
}
$a = $this->parse_args( 'title', array(
'tag' => $tag,
'class' => empty( $name ) ? 'cmb2-metabox-title-anchor' : 'cmb2-metabox-title',
'name' => $name,
'desc' => $this->_desc( true ),
'id' => str_replace( '_', '-', sanitize_html_class( $this->field->id() ) ),
) );
return $this->rendered(
sprintf(
'<%1$s %2$s>%3$s</%1$s>%4$s',
$a['tag'],
$this->concat_attrs( $a, array( 'tag', 'name', 'desc' ) ),
$a['name'],
$a['desc']
)
);
}
}

View File

@ -0,0 +1,92 @@
<?php
/**
* CMB wysiwyg field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*
* @method string _id()
* @method string _desc()
*/
class CMB2_Type_Wysiwyg extends CMB2_Type_Textarea {
/**
* Handles outputting a 'wysiwyg' element
* @since 1.1.0
* @return string Form wysiwyg element
*/
public function render() {
$field = $this->field;
$a = $this->parse_args( 'wysiwyg', array(
'id' => $this->_id(),
'value' => $field->escaped_value( 'stripslashes' ),
'desc' => $this->_desc( true ),
'options' => $field->options(),
) );
if ( ! $field->group ) {
return $this->rendered( $this->get_wp_editor( $a ) . $a['desc'] );
}
// wysiwyg fields in a group need some special handling.
$field->add_js_dependencies( 'wp-util' );
$field->add_js_dependencies( 'cmb2-wysiwyg' );
// Hook in our template-output to the footer.
add_action( is_admin() ? 'admin_footer' : 'wp_footer', array( $this, 'add_wysiwyg_template_for_group' ) );
return $this->rendered(
sprintf( '<div class="cmb2-wysiwyg-wrap">%s', parent::render( array(
'class' => 'cmb2_textarea cmb2-wysiwyg-placeholder',
'data-groupid' => $field->group->id(),
'data-iterator' => $field->group->index,
'data-fieldid' => $field->id( true ),
'desc' => '</div>' . $this->_desc( true ),
) ) )
);
}
protected function get_wp_editor( $args ) {
ob_start();
wp_editor( $args['value'], $args['id'], $args['options'] );
return ob_get_clean();
}
public function add_wysiwyg_template_for_group() {
$group_id = $this->field->group->id();
$field_id = $this->field->id( true );
$options = $this->field->options();
$options['textarea_name'] = 'cmb2_n_' . $group_id . $field_id;
// Initate the editor with special id/value/name so we can retrieve the options in JS.
$editor = $this->get_wp_editor( array(
'value' => 'cmb2_v_' . $group_id . $field_id,
'id' => 'cmb2_i_' . $group_id . $field_id,
'options' => $options,
) );
// Then replace the special id/value/name with underscore placeholders.
$editor = str_replace( array(
'cmb2_n_' . $group_id . $field_id,
'cmb2_v_' . $group_id . $field_id,
'cmb2_i_' . $group_id . $field_id,
), array(
'{{ data.name }}',
'{{{ data.value }}}',
'{{ data.id }}',
), $editor );
// And put the editor instance in a JS template wrapper.
echo '<script type="text/template" id="tmpl-cmb2-wysiwyg-' . $group_id . '-' . $field_id . '">';
// Need to wrap the template in a wrapper div w/ specific data attributes which will be used when adding/removing rows.
echo '<div class="cmb2-wysiwyg-inner-wrap" data-iterator="{{ data.iterator }}" data-groupid="'. $group_id .'" data-id="'. $field_id .'">'. $editor .'</div>';
echo '</script>';
}
}

2
cmb2/index.php Normal file
View File

@ -0,0 +1,2 @@
<?php
// Silence is golden

186
cmb2/init.php Normal file
View File

@ -0,0 +1,186 @@
<?php
/**
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*
* Plugin Name: CMB2
* Plugin URI: https://github.com/WebDevStudios/CMB2
* Description: CMB2 will create metaboxes and forms with custom fields that will blow your mind.
* Author: WebDevStudios
* Author URI: http://webdevstudios.com
* Contributors: WebDevStudios (@webdevstudios / webdevstudios.com)
* Justin Sternberg (@jtsternberg / dsgnwrks.pro)
* Jared Atchison (@jaredatch / jaredatchison.com)
* Bill Erickson (@billerickson / billerickson.net)
* Andrew Norcross (@norcross / andrewnorcross.com)
*
* Version: 2.2.4
*
* Text Domain: cmb2
* Domain Path: languages
*
*
* Released under the GPL license
* http://www.opensource.org/licenses/gpl-license.php
*
* This is an add-on for WordPress
* http://wordpress.org/
*
* **********************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* **********************************************************************
*/
/************************************************************************
You should not edit the code below
(or any code in the included files)
or things might explode!
*************************************************************************/
if ( ! class_exists( 'CMB2_Bootstrap_224', false ) ) {
/**
* Handles checking for and loading the newest version of CMB2
*
* @since 2.0.0
*
* @category WordPress_Plugin
* @package CMB2
* @author WebDevStudios
* @license GPL-2.0+
* @link http://webdevstudios.com
*/
class CMB2_Bootstrap_224 {
/**
* Current version number
* @var string
* @since 1.0.0
*/
const VERSION = '2.2.4';
/**
* Current version hook priority.
* Will decrement with each release
*
* @var int
* @since 2.0.0
*/
const PRIORITY = 9977;
/**
* Single instance of the CMB2_Bootstrap_224 object
*
* @var CMB2_Bootstrap_224
*/
public static $single_instance = null;
/**
* Creates/returns the single instance CMB2_Bootstrap_224 object
*
* @since 2.0.0
* @return CMB2_Bootstrap_224 Single instance object
*/
public static function initiate() {
if ( null === self::$single_instance ) {
self::$single_instance = new self();
}
return self::$single_instance;
}
/**
* Starts the version checking process.
* Creates CMB2_LOADED definition for early detection by other scripts
*
* Hooks CMB2 inclusion to the init hook on a high priority which decrements
* (increasing the priority) with each version release.
*
* @since 2.0.0
*/
private function __construct() {
/**
* A constant you can use to check if CMB2 is loaded
* for your plugins/themes with CMB2 dependency
*/
if ( ! defined( 'CMB2_LOADED' ) ) {
define( 'CMB2_LOADED', self::PRIORITY );
}
add_action( 'init', array( $this, 'include_cmb' ), self::PRIORITY );
}
/**
* A final check if CMB2 exists before kicking off our CMB2 loading.
* CMB2_VERSION and CMB2_DIR constants are set at this point.
*
* @since 2.0.0
*/
public function include_cmb() {
if ( class_exists( 'CMB2', false ) ) {
return;
}
if ( ! defined( 'CMB2_VERSION' ) ) {
define( 'CMB2_VERSION', self::VERSION );
}
if ( ! defined( 'CMB2_DIR' ) ) {
define( 'CMB2_DIR', trailingslashit( dirname( __FILE__ ) ) );
}
$this->l10ni18n();
// Include helper functions
require_once 'includes/CMB2_Base.php';
require_once 'includes/CMB2.php';
require_once 'includes/helper-functions.php';
// Now kick off the class autoloader
spl_autoload_register( 'cmb2_autoload_classes' );
// Kick the whole thing off
require_once 'bootstrap.php';
cmb2_bootstrap();
}
/**
* Registers CMB2 text domain path
* @since 2.0.0
*/
public function l10ni18n() {
$loaded = load_plugin_textdomain( 'cmb2', false, '/languages/' );
if ( ! $loaded ) {
$loaded = load_muplugin_textdomain( 'cmb2', '/languages/' );
}
if ( ! $loaded ) {
$loaded = load_theme_textdomain( 'cmb2', get_stylesheet_directory() . '/languages/' );
}
if ( ! $loaded ) {
$locale = apply_filters( 'plugin_locale', get_locale(), 'cmb2' );
$mofile = dirname( __FILE__ ) . '/languages/cmb2-' . $locale . '.mo';
load_textdomain( 'cmb2', $mofile );
}
}
}
// Make it so...
CMB2_Bootstrap_224::initiate();
}

331
cmb2/js/cmb2-wysiwyg.js Normal file
View File

@ -0,0 +1,331 @@
/**
* Used for WYSIWYG logic
*/
window.CMB2 = window.CMB2 || {};
window.CMB2.wysiwyg = window.CMB2.wysiwyg || {};
( function(window, document, $, wysiwyg, undefined ) {
'use strict';
// Private variables
var toBeDestroyed = [];
var toBeInitialized = [];
var all = wysiwyg.all = {};
// Private functions
/**
* Initializes any editors that weren't initialized because they didn't exist yet.
*
* @since 2.2.3
*
* @return {void}
*/
function delayedInit() {
// Don't initialize until they've all been destroyed.
if ( 0 === toBeDestroyed.length ) {
toBeInitialized.forEach( function ( toInit ) {
toBeInitialized.splice( toBeInitialized.indexOf( toInit ), 1 );
wysiwyg.init.apply( wysiwyg, toInit );
} );
} else {
window.setTimeout( delayedInit, 100 );
}
}
/**
* Destroys any editors that weren't destroyed because they didn't exist yet.
*
* @since 2.2.3
*
* @return {void}
*/
function delayedDestroy() {
toBeDestroyed.forEach( function( id ) {
toBeDestroyed.splice( toBeDestroyed.indexOf( id ), 1 );
wysiwyg.destroy( id );
} );
}
/**
* Gets the option data for a group (and initializes that data if it doesn't exist).
*
* @since 2.2.3
*
* @param {object} data The group/field data.
*
* @return {object} Options data object for a group.
*/
function getGroupData( data ) {
var groupid = data.groupid;
var fieldid = data.fieldid;
if ( ! all[ groupid ] || ! all[ groupid ][ fieldid ] ) {
all[ groupid ] = all[ groupid ] || {};
all[ groupid ][ fieldid ] = {
template : wp.template( 'cmb2-wysiwyg-' + groupid + '-' + fieldid ),
defaults : {
// Get the data from the template-wysiwyg initiation.
mce : $.extend( {}, tinyMCEPreInit.mceInit[ 'cmb2_i_' + groupid + fieldid ] ),
qt : $.extend( {}, tinyMCEPreInit.qtInit[ 'cmb2_i_' + groupid + fieldid ] )
}
};
// This is the template-wysiwyg data, and we do not want that to be initiated.
delete tinyMCEPreInit.mceInit[ 'cmb2_i_' + groupid + fieldid ];
delete tinyMCEPreInit.qtInit[ 'cmb2_i_' + groupid + fieldid ];
}
return all[ groupid ][ fieldid ];
}
/**
* Initiates the tinyMCEPreInit options for a wysiwyg editor instance.
*
* @since 2.2.3
*
* @param {object} options Options data object for the wysiwyg editor instance.
*
* @return {void}
*/
function initOptions( options ) {
var nameRegex = new RegExp( 'cmb2_n_' + options.groupid + options.fieldid, 'g' );
var idRegex = new RegExp( 'cmb2_i_' + options.groupid + options.fieldid, 'g' );
var prop, newSettings, newQTS;
// If no settings for this field. Clone from placeholder.
if ( 'undefined' === typeof( tinyMCEPreInit.mceInit[ options.id ] ) ) {
newSettings = $.extend( {}, options.defaults.mce );
for ( prop in newSettings ) {
if ( 'string' === typeof( newSettings[ prop ] ) ) {
newSettings[ prop ] = newSettings[ prop ]
.replace( idRegex, options.id )
.replace( nameRegex, options.name );
}
}
tinyMCEPreInit.mceInit[ options.id ] = newSettings;
}
// If no Quicktag settings for this field. Clone from placeholder.
if ( 'undefined' === typeof( tinyMCEPreInit.qtInit[ options.id ] ) ) {
newQTS = $.extend( {}, options.defaults.qt );
for ( prop in newQTS ) {
if ( 'string' === typeof( newQTS[ prop ] ) ) {
newQTS[ prop ] = newQTS[ prop ]
.replace( idRegex, options.id )
.replace( nameRegex, options.name );
}
}
tinyMCEPreInit.qtInit[ options.id ] = newQTS;
}
}
/**
* Initializes all group wysiwyg editors. Hooked to cmb_init.
*
* @since 2.2.3
*
* @return {void}
*/
wysiwyg.initAll = function() {
var $this,data,initiated;
$( '.cmb2-wysiwyg-placeholder' ).each( function() {
$this = $( this );
data = $this.data();
if ( data.groupid ) {
data.id = $this.attr( 'id' );
data.name = $this.attr( 'name' );
data.value = $this.val();
wysiwyg.init( $this, data, false );
initiated = true;
}
} );
if ( true === initiated ) {
if ( 'undefined' !== typeof window.QTags ) {
window.QTags._buttonsInit();
}
// Hook in our event callbacks.
$( document )
.on( 'cmb2_add_row', wysiwyg.addRow )
.on( 'cmb2_remove_group_row_start', wysiwyg.destroyRowEditors )
.on( 'cmb2_shift_rows_start', wysiwyg.shiftStart )
.on( 'cmb2_shift_rows_complete', wysiwyg.shiftComplete );
}
};
/**
* Initiates wysiwyg editors in a new group row. Hooked to cmb2_add_row.
*
* @since 2.2.3
*
* @param {object} evt A jQuery-normalized event object.
* @param {object} $row A jQuery dom element object for the group row.
*
* @return {void}
*/
wysiwyg.addRow = function( evt, $row ) {
wysiwyg.initRow( $row );
};
/**
* Destroys wysiwyg editors in a group row when that row is removed. Hooked to cmb2_remove_group_row_start.
*
* @since 2.2.3
*
* @param {object} evt A jQuery-normalized event object.
* @param {object} $btn A jQuery dom element object for the remove-row button.
*
* @return {void}
*/
wysiwyg.destroyRowEditors = function( evt, $btn ) {
wysiwyg.destroy( $btn.parents( '.cmb-repeatable-grouping' ).find( '.wp-editor-area' ).attr( 'id' ) );
};
/**
* When a row-shift starts, we need to destroy the wysiwyg editors for the group-rows being shuffled.
*
* @since 2.2.3
*
* @param {object} evt A jQuery-normalized event object.
* @param {object} $btn A jQuery dom element object for the remove-row button.
* @param {object} $from A jQuery dom element object for the row being shifted from.
* @param {object} $to A jQuery dom element object for the row being shifted to.
*
* @return {void}
*/
wysiwyg.shiftStart = function( evt, $btn, $from, $to ) {
$from.add( $to ).find( '.wp-editor-wrap textarea' ).each( function() {
wysiwyg.destroy( $( this ).attr( 'id' ) );
} );
};
/**
* When a row-shift completes, we need to re-init the wysiwyg editors for the group-rows being shuffled.
*
* @since 2.2.3
*
* @param {object} evt A jQuery-normalized event object.
* @param {object} $btn A jQuery dom element object for the remove-row button.
* @param {object} $from A jQuery dom element object for the row being shifted from.
* @param {object} $to A jQuery dom element object for the row being shifted to.
*
* @return {void}
*/
wysiwyg.shiftComplete = function( evt, $btn, $from, $to ) {
$from.add( $to ).each( function() {
wysiwyg.initRow( $( this ) );
} );
};
/**
* Initializes editors for a new CMB row.
*
* @since 2.2.3
*
* @param {object} $row A jQuery dom element object for the group row.
*
* @return {void}
*/
wysiwyg.initRow = function( $row ) {
var $toReplace, data;
$row.find( '.cmb2-wysiwyg-inner-wrap' ).each( function() {
$toReplace = $( this );
data = $toReplace.data();
data.iterator = $row.data( 'iterator' );
data.fieldid = data.id;
data.id = data.groupid + '_' + data.iterator + '_' + data.fieldid;
data.name = data.groupid + '[' + data.iterator + '][' + data.fieldid + ']';
data.value = $toReplace.find( '.wp-editor-area' ).length ? $toReplace.find( '.wp-editor-area' ).val() : '';
// The destroys might not have happened yet. Don't init until they have.
if ( 0 === toBeDestroyed.length ) {
wysiwyg.init( $toReplace, data );
} else {
toBeInitialized.push( [$toReplace, data] );
window.setTimeout( delayedInit, 100 );
}
} );
};
/**
* Initiates a wysiwyg editor instance and replaces the passed dom element w/ the editor html.
*
* @since 2.2.3
*
* @param {object} $toReplace A jQuery dom element which will be replaced with the wysiwyg editor.
* @param {object} data Data used to initate the editor.
* @param {bool} buttonsInit Whether to run QTags._buttonsInit()
*
* @return {void}
*/
wysiwyg.init = function( $toReplace, data, buttonsInit ) {
if ( ! data.groupid ) {
return false;
}
$.extend( data, getGroupData( data ) );
initOptions( data );
$toReplace.replaceWith( data.template( data ) );
window.tinyMCE.init( tinyMCEPreInit.mceInit[ data.id ] );
if ( 'function' === typeof window.quicktags ) {
window.quicktags( tinyMCEPreInit.qtInit[ data.id ] );
}
$( document.getElementById( data.id ) ).parents( '.wp-editor-wrap' ).removeClass( 'html-active' ).addClass( 'tmce-active' );
if ( false !== buttonsInit && 'undefined' !== typeof window.QTags ) {
window.QTags._buttonsInit();
}
};
/**
* Destroys a wysiwyg editor instance.
*
* @since 2.2.3
*
* @param {string} id Editor id.
*
* @return {void}
*/
wysiwyg.destroy = function( id ) {
// The editor might not be initialized yet. But we need to destroy it once it is.
var editor = tinyMCE.get( id );
if ( editor !== null && typeof( editor ) !== 'undefined' ) {
editor.destroy();
if ( 'undefined' === typeof( tinyMCEPreInit.mceInit[ id ] ) ) {
delete tinyMCEPreInit.mceInit[ id ];
}
if ( 'undefined' === typeof( tinyMCEPreInit.qtInit[ id ] ) ) {
delete tinyMCEPreInit.qtInit[ id ];
}
} else if ( -1 === toBeDestroyed.indexOf( id ) ) {
toBeDestroyed.push( id );
window.setTimeout( delayedDestroy, 100 );
}
};
// Hook in our event callbacks.
$( document ).on( 'cmb_init', wysiwyg.initAll );
} )( window, document, jQuery, window.CMB2.wysiwyg );

1024
cmb2/js/cmb2.js Normal file

File diff suppressed because it is too large Load Diff

1
cmb2/js/cmb2.min.js vendored Normal file

File diff suppressed because one or more lines are too long

2
cmb2/js/index.php Normal file
View File

@ -0,0 +1,2 @@
<?php
// Silence is golden

File diff suppressed because one or more lines are too long

BIN
cmb2/languages/cmb2-ach.mo Normal file

Binary file not shown.

527
cmb2/languages/cmb2-ach.po Normal file
View File

@ -0,0 +1,527 @@
# Copyright (C) 2016 WebDevStudios
# This file is distributed under the same license as the CMB2 package.
# Translators:
msgid ""
msgstr ""
"Project-Id-Version: CMB2\n"
"Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/cmb2\n"
"POT-Creation-Date: 2016-06-27 17:01:22+00:00\n"
"PO-Revision-Date: 2016-06-27 17:01+0000\n"
"Last-Translator: Justin Sternberg <me@jtsternberg.com>\n"
"Language-Team: Acoli (http://www.transifex.com/wp-translations/cmb2/language/ach/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: ach\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Generator: grunt-wp-i18n 0.4.9\n"
"X-Poedit-Basepath: ../\n"
"X-Poedit-Bookmarks: \n"
"X-Poedit-Country: United States\n"
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;_nx_noop:1,2,3c;esc_attr__;esc_html__;esc_attr_e;esc_html_e;esc_attr_x:1,2c;esc_html_x:1,2c;\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Textdomain-Support: yes\n"
#: example-functions.php:117 tests/test-cmb-field.php:255
msgid "Test Metabox"
msgstr ""
#: example-functions.php:130 example-functions.php:436
msgid "Test Text"
msgstr ""
#: example-functions.php:131 example-functions.php:144
#: example-functions.php:157 example-functions.php:165
#: example-functions.php:173 example-functions.php:182
#: example-functions.php:190 example-functions.php:205
#: example-functions.php:213 example-functions.php:221
#: example-functions.php:238 example-functions.php:247
#: example-functions.php:260 example-functions.php:267
#: example-functions.php:274 example-functions.php:288
#: example-functions.php:301 example-functions.php:314
#: example-functions.php:326 example-functions.php:335
#: example-functions.php:343 example-functions.php:352
#: example-functions.php:359 example-functions.php:373
#: example-functions.php:437 example-functions.php:528
#: example-functions.php:536 example-functions.php:543
#: example-functions.php:550 example-functions.php:557
#: example-functions.php:564 example-functions.php:571
#: example-functions.php:598 example-functions.php:606
#: example-functions.php:613 example-functions.php:650
#: tests/test-cmb-field.php:267
msgid "field description (optional)"
msgstr ""
#: example-functions.php:143
msgid "Test Text Small"
msgstr ""
#: example-functions.php:156
msgid "Test Text Medium"
msgstr ""
#: example-functions.php:164
msgid "Custom Rendered Field"
msgstr ""
#: example-functions.php:172
msgid "Website URL"
msgstr ""
#: example-functions.php:181
msgid "Test Text Email"
msgstr ""
#: example-functions.php:189
msgid "Test Time"
msgstr ""
#: example-functions.php:197 example-functions.php:198
msgid "Time zone"
msgstr ""
#: example-functions.php:204
msgid "Test Date Picker"
msgstr ""
#: example-functions.php:212
msgid "Test Date Picker (UNIX timestamp)"
msgstr ""
#: example-functions.php:220
msgid "Test Date/Time Picker Combo (UNIX timestamp)"
msgstr ""
#: example-functions.php:237
msgid "Test Money"
msgstr ""
#: example-functions.php:246
msgid "Test Color Picker"
msgstr ""
#: example-functions.php:259
msgid "Test Text Area"
msgstr ""
#: example-functions.php:266
msgid "Test Text Area Small"
msgstr ""
#: example-functions.php:273
msgid "Test Text Area for Code"
msgstr ""
#: example-functions.php:280
msgid "Test Title Weeeee"
msgstr ""
#: example-functions.php:281
msgid "This is a title description"
msgstr ""
#: example-functions.php:287
msgid "Test Select"
msgstr ""
#: example-functions.php:293 example-functions.php:306
#: example-functions.php:318
msgid "Option One"
msgstr ""
#: example-functions.php:294 example-functions.php:307
#: example-functions.php:319
msgid "Option Two"
msgstr ""
#: example-functions.php:295 example-functions.php:308
#: example-functions.php:320
msgid "Option Three"
msgstr ""
#: example-functions.php:300
msgid "Test Radio inline"
msgstr ""
#: example-functions.php:313
msgid "Test Radio"
msgstr ""
#: example-functions.php:325
msgid "Test Taxonomy Radio"
msgstr ""
#: example-functions.php:334
msgid "Test Taxonomy Select"
msgstr ""
#: example-functions.php:342
msgid "Test Taxonomy Multi Checkbox"
msgstr ""
#: example-functions.php:351
msgid "Test Checkbox"
msgstr ""
#: example-functions.php:358 tests/test-cmb-field.php:266
msgid "Test Multi Checkbox"
msgstr ""
#: example-functions.php:364 tests/test-cmb-field.php:272
msgid "Check One"
msgstr ""
#: example-functions.php:365 tests/test-cmb-field.php:273
msgid "Check Two"
msgstr ""
#: example-functions.php:366 tests/test-cmb-field.php:274
msgid "Check Three"
msgstr ""
#: example-functions.php:372
msgid "Test wysiwyg"
msgstr ""
#: example-functions.php:380
msgid "Test Image"
msgstr ""
#: example-functions.php:381
msgid "Upload an image or enter a URL."
msgstr ""
#: example-functions.php:387
msgid "Multiple Files"
msgstr ""
#: example-functions.php:388
msgid "Upload or add multiple images/attachments."
msgstr ""
#: example-functions.php:395
msgid "oEmbed"
msgstr ""
#: example-functions.php:396
msgid ""
"Enter a youtube, twitter, or instagram URL. Supports services listed at <a "
"href=\"http://codex.wordpress.org/Embeds\">http://codex.wordpress.org/Embeds</a>."
msgstr ""
#: example-functions.php:427
msgid "About Page Metabox"
msgstr ""
#: example-functions.php:456
msgid "Repeating Field Group"
msgstr ""
#: example-functions.php:464
msgid "Generates reusable form entries"
msgstr ""
#: example-functions.php:466
msgid "Entry {#}"
msgstr ""
#: example-functions.php:467
msgid "Add Another Entry"
msgstr ""
#: example-functions.php:468
msgid "Remove Entry"
msgstr ""
#: example-functions.php:481
msgid "Entry Title"
msgstr ""
#: example-functions.php:488
msgid "Description"
msgstr ""
#: example-functions.php:489
msgid "Write a short description for this entry"
msgstr ""
#: example-functions.php:495
msgid "Entry Image"
msgstr ""
#: example-functions.php:501
msgid "Image Caption"
msgstr ""
#: example-functions.php:520
msgid "User Profile Metabox"
msgstr ""
#: example-functions.php:527 example-functions.php:597
msgid "Extra Info"
msgstr ""
#: example-functions.php:535
msgid "Avatar"
msgstr ""
#: example-functions.php:542
msgid "Facebook URL"
msgstr ""
#: example-functions.php:549
msgid "Twitter URL"
msgstr ""
#: example-functions.php:556
msgid "Google+ URL"
msgstr ""
#: example-functions.php:563
msgid "Linkedin URL"
msgstr ""
#: example-functions.php:570
msgid "User Field"
msgstr ""
#: example-functions.php:590
msgid "Category Metabox"
msgstr ""
#: example-functions.php:605
msgid "Term Image"
msgstr ""
#: example-functions.php:612
msgid "Arbitrary Term Field"
msgstr ""
#: example-functions.php:634
msgid "Theme Options Metabox"
msgstr ""
#: example-functions.php:649
msgid "Site Background Color"
msgstr ""
#: includes/CMB2.php:129
msgid "Metabox configuration is required to have an ID parameter"
msgstr ""
#: includes/CMB2.php:418
msgid "Click to toggle"
msgstr ""
#: includes/CMB2_Ajax.php:71
msgid "Please Try Again"
msgstr ""
#: includes/CMB2_Ajax.php:173 tests/cmb-tests-base.php:59
msgid "Remove Embed"
msgstr ""
#: includes/CMB2_Ajax.php:177 tests/cmb-tests-base.php:64
msgid "No oEmbed Results Found for %s. View more info at"
msgstr ""
#: includes/CMB2_Field.php:1186
msgid "Add Group"
msgstr ""
#: includes/CMB2_Field.php:1187
msgid "Remove Group"
msgstr ""
#: includes/CMB2_Field.php:1209 includes/CMB2_Field.php:1213
#: tests/test-cmb-field.php:229
msgid "None"
msgstr ""
#: includes/CMB2_Field.php:1269
msgid "Sorry, this field does not have a cmb_id specified."
msgstr ""
#: includes/CMB2_Field_Display.php:408 includes/CMB2_JS.php:139
#: includes/types/CMB2_Type_File_Base.php:75 tests/test-cmb-types-base.php:143
#: tests/test-cmb-types.php:701
msgid "File:"
msgstr ""
#: includes/CMB2_JS.php:86 includes/CMB2_JS.php:119
msgid "Clear"
msgstr ""
#: includes/CMB2_JS.php:87
msgid "Default"
msgstr ""
#: includes/CMB2_JS.php:88
msgid "Select Color"
msgstr ""
#: includes/CMB2_JS.php:89
msgid "Current Color"
msgstr ""
#: includes/CMB2_JS.php:110
msgid "Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday"
msgstr ""
#: includes/CMB2_JS.php:111
msgid "Su, Mo, Tu, We, Th, Fr, Sa"
msgstr ""
#: includes/CMB2_JS.php:112
msgid "Sun, Mon, Tue, Wed, Thu, Fri, Sat"
msgstr ""
#: includes/CMB2_JS.php:113
msgid ""
"January, February, March, April, May, June, July, August, September, "
"October, November, December"
msgstr ""
#: includes/CMB2_JS.php:114
msgid "Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec"
msgstr ""
#: includes/CMB2_JS.php:115
msgid "Next"
msgstr ""
#: includes/CMB2_JS.php:116
msgid "Prev"
msgstr ""
#: includes/CMB2_JS.php:117
msgid "Today"
msgstr ""
#: includes/CMB2_JS.php:118 includes/CMB2_JS.php:128
msgid "Done"
msgstr ""
#: includes/CMB2_JS.php:122
msgid "Choose Time"
msgstr ""
#: includes/CMB2_JS.php:123
msgid "Time"
msgstr ""
#: includes/CMB2_JS.php:124
msgid "Hour"
msgstr ""
#: includes/CMB2_JS.php:125
msgid "Minute"
msgstr ""
#: includes/CMB2_JS.php:126
msgid "Second"
msgstr ""
#: includes/CMB2_JS.php:127
msgid "Now"
msgstr ""
#: includes/CMB2_JS.php:135
msgid "Use this file"
msgstr ""
#: includes/CMB2_JS.php:136
msgid "Use these files"
msgstr ""
#: includes/CMB2_JS.php:137 includes/types/CMB2_Type_File_Base.php:61
msgid "Remove Image"
msgstr ""
#: includes/CMB2_JS.php:138 includes/CMB2_Types.php:257
#: includes/types/CMB2_Type_File_Base.php:80 tests/test-cmb-types-base.php:143
#: tests/test-cmb-types.php:47 tests/test-cmb-types.php:55
#: tests/test-cmb-types.php:701
msgid "Remove"
msgstr ""
#: includes/CMB2_JS.php:140 includes/types/CMB2_Type_File_Base.php:78
#: tests/test-cmb-types-base.php:143 tests/test-cmb-types.php:701
msgid "Download"
msgstr ""
#: includes/CMB2_JS.php:141
msgid "Select / Deselect All"
msgstr ""
#: includes/CMB2_Types.php:194
msgid "Add Row"
msgstr ""
#: includes/CMB2_hookup.php:145
msgid ""
"Term Metadata is a WordPress > 4.4 feature. Please upgrade your WordPress "
"install."
msgstr ""
#: includes/CMB2_hookup.php:149
msgid "Term metaboxes configuration requires a 'taxonomies' parameter"
msgstr ""
#: includes/helper-functions.php:93
msgid "No oEmbed Results Found for %s. View more info at %s"
msgstr ""
#: includes/helper-functions.php:279
msgid "Save"
msgstr ""
#: includes/types/CMB2_Type_File.php:36 tests/test-cmb-types.php:683
#: tests/test-cmb-types.php:701
msgid "Add or Upload File"
msgstr ""
#: includes/types/CMB2_Type_File_List.php:36 tests/test-cmb-types.php:639
#: tests/test-cmb-types.php:663
msgid "Add or Upload Files"
msgstr ""
#: includes/types/CMB2_Type_Taxonomy_Multicheck.php:27
#: includes/types/CMB2_Type_Taxonomy_Radio.php:25
msgid "No terms"
msgstr ""
#. Plugin Name of the plugin/theme
msgid "CMB2"
msgstr ""
#. Plugin URI of the plugin/theme
msgid "https://github.com/WebDevStudios/CMB2"
msgstr ""
#. Description of the plugin/theme
msgid ""
"CMB2 will create metaboxes and forms with custom fields that will blow your "
"mind."
msgstr ""
#. Author of the plugin/theme
msgid "WebDevStudios"
msgstr ""
#. Author URI of the plugin/theme
msgid "http://webdevstudios.com"
msgstr ""
#: includes/CMB2_JS.php:109
msgctxt "Valid formatDate string for jquery-ui datepicker"
msgid "mm/dd/yy"
msgstr ""
#: includes/CMB2_JS.php:129
msgctxt ""
"Valid formatting string, as per "
"http://trentrichardson.com/examples/timepicker/"
msgid "hh:mm TT"
msgstr ""

BIN
cmb2/languages/cmb2-af.mo Normal file

Binary file not shown.

527
cmb2/languages/cmb2-af.po Normal file
View File

@ -0,0 +1,527 @@
# Copyright (C) 2016 WebDevStudios
# This file is distributed under the same license as the CMB2 package.
# Translators:
msgid ""
msgstr ""
"Project-Id-Version: CMB2\n"
"Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/cmb2\n"
"POT-Creation-Date: 2016-06-27 17:01:22+00:00\n"
"PO-Revision-Date: 2016-06-27 17:01+0000\n"
"Last-Translator: Justin Sternberg <me@jtsternberg.com>\n"
"Language-Team: Afrikaans (http://www.transifex.com/wp-translations/cmb2/language/af/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: af\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: grunt-wp-i18n 0.4.9\n"
"X-Poedit-Basepath: ../\n"
"X-Poedit-Bookmarks: \n"
"X-Poedit-Country: United States\n"
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;_nx_noop:1,2,3c;esc_attr__;esc_html__;esc_attr_e;esc_html_e;esc_attr_x:1,2c;esc_html_x:1,2c;\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Textdomain-Support: yes\n"
#: example-functions.php:117 tests/test-cmb-field.php:255
msgid "Test Metabox"
msgstr ""
#: example-functions.php:130 example-functions.php:436
msgid "Test Text"
msgstr ""
#: example-functions.php:131 example-functions.php:144
#: example-functions.php:157 example-functions.php:165
#: example-functions.php:173 example-functions.php:182
#: example-functions.php:190 example-functions.php:205
#: example-functions.php:213 example-functions.php:221
#: example-functions.php:238 example-functions.php:247
#: example-functions.php:260 example-functions.php:267
#: example-functions.php:274 example-functions.php:288
#: example-functions.php:301 example-functions.php:314
#: example-functions.php:326 example-functions.php:335
#: example-functions.php:343 example-functions.php:352
#: example-functions.php:359 example-functions.php:373
#: example-functions.php:437 example-functions.php:528
#: example-functions.php:536 example-functions.php:543
#: example-functions.php:550 example-functions.php:557
#: example-functions.php:564 example-functions.php:571
#: example-functions.php:598 example-functions.php:606
#: example-functions.php:613 example-functions.php:650
#: tests/test-cmb-field.php:267
msgid "field description (optional)"
msgstr ""
#: example-functions.php:143
msgid "Test Text Small"
msgstr ""
#: example-functions.php:156
msgid "Test Text Medium"
msgstr ""
#: example-functions.php:164
msgid "Custom Rendered Field"
msgstr ""
#: example-functions.php:172
msgid "Website URL"
msgstr ""
#: example-functions.php:181
msgid "Test Text Email"
msgstr ""
#: example-functions.php:189
msgid "Test Time"
msgstr ""
#: example-functions.php:197 example-functions.php:198
msgid "Time zone"
msgstr ""
#: example-functions.php:204
msgid "Test Date Picker"
msgstr ""
#: example-functions.php:212
msgid "Test Date Picker (UNIX timestamp)"
msgstr ""
#: example-functions.php:220
msgid "Test Date/Time Picker Combo (UNIX timestamp)"
msgstr ""
#: example-functions.php:237
msgid "Test Money"
msgstr ""
#: example-functions.php:246
msgid "Test Color Picker"
msgstr ""
#: example-functions.php:259
msgid "Test Text Area"
msgstr ""
#: example-functions.php:266
msgid "Test Text Area Small"
msgstr ""
#: example-functions.php:273
msgid "Test Text Area for Code"
msgstr ""
#: example-functions.php:280
msgid "Test Title Weeeee"
msgstr ""
#: example-functions.php:281
msgid "This is a title description"
msgstr ""
#: example-functions.php:287
msgid "Test Select"
msgstr ""
#: example-functions.php:293 example-functions.php:306
#: example-functions.php:318
msgid "Option One"
msgstr ""
#: example-functions.php:294 example-functions.php:307
#: example-functions.php:319
msgid "Option Two"
msgstr ""
#: example-functions.php:295 example-functions.php:308
#: example-functions.php:320
msgid "Option Three"
msgstr ""
#: example-functions.php:300
msgid "Test Radio inline"
msgstr ""
#: example-functions.php:313
msgid "Test Radio"
msgstr ""
#: example-functions.php:325
msgid "Test Taxonomy Radio"
msgstr ""
#: example-functions.php:334
msgid "Test Taxonomy Select"
msgstr ""
#: example-functions.php:342
msgid "Test Taxonomy Multi Checkbox"
msgstr ""
#: example-functions.php:351
msgid "Test Checkbox"
msgstr ""
#: example-functions.php:358 tests/test-cmb-field.php:266
msgid "Test Multi Checkbox"
msgstr ""
#: example-functions.php:364 tests/test-cmb-field.php:272
msgid "Check One"
msgstr ""
#: example-functions.php:365 tests/test-cmb-field.php:273
msgid "Check Two"
msgstr ""
#: example-functions.php:366 tests/test-cmb-field.php:274
msgid "Check Three"
msgstr ""
#: example-functions.php:372
msgid "Test wysiwyg"
msgstr ""
#: example-functions.php:380
msgid "Test Image"
msgstr ""
#: example-functions.php:381
msgid "Upload an image or enter a URL."
msgstr ""
#: example-functions.php:387
msgid "Multiple Files"
msgstr ""
#: example-functions.php:388
msgid "Upload or add multiple images/attachments."
msgstr ""
#: example-functions.php:395
msgid "oEmbed"
msgstr ""
#: example-functions.php:396
msgid ""
"Enter a youtube, twitter, or instagram URL. Supports services listed at <a "
"href=\"http://codex.wordpress.org/Embeds\">http://codex.wordpress.org/Embeds</a>."
msgstr ""
#: example-functions.php:427
msgid "About Page Metabox"
msgstr ""
#: example-functions.php:456
msgid "Repeating Field Group"
msgstr ""
#: example-functions.php:464
msgid "Generates reusable form entries"
msgstr ""
#: example-functions.php:466
msgid "Entry {#}"
msgstr ""
#: example-functions.php:467
msgid "Add Another Entry"
msgstr ""
#: example-functions.php:468
msgid "Remove Entry"
msgstr ""
#: example-functions.php:481
msgid "Entry Title"
msgstr ""
#: example-functions.php:488
msgid "Description"
msgstr "Beskrywing"
#: example-functions.php:489
msgid "Write a short description for this entry"
msgstr ""
#: example-functions.php:495
msgid "Entry Image"
msgstr ""
#: example-functions.php:501
msgid "Image Caption"
msgstr ""
#: example-functions.php:520
msgid "User Profile Metabox"
msgstr ""
#: example-functions.php:527 example-functions.php:597
msgid "Extra Info"
msgstr ""
#: example-functions.php:535
msgid "Avatar"
msgstr ""
#: example-functions.php:542
msgid "Facebook URL"
msgstr ""
#: example-functions.php:549
msgid "Twitter URL"
msgstr ""
#: example-functions.php:556
msgid "Google+ URL"
msgstr ""
#: example-functions.php:563
msgid "Linkedin URL"
msgstr ""
#: example-functions.php:570
msgid "User Field"
msgstr ""
#: example-functions.php:590
msgid "Category Metabox"
msgstr ""
#: example-functions.php:605
msgid "Term Image"
msgstr ""
#: example-functions.php:612
msgid "Arbitrary Term Field"
msgstr ""
#: example-functions.php:634
msgid "Theme Options Metabox"
msgstr ""
#: example-functions.php:649
msgid "Site Background Color"
msgstr ""
#: includes/CMB2.php:129
msgid "Metabox configuration is required to have an ID parameter"
msgstr ""
#: includes/CMB2.php:418
msgid "Click to toggle"
msgstr ""
#: includes/CMB2_Ajax.php:71
msgid "Please Try Again"
msgstr ""
#: includes/CMB2_Ajax.php:173 tests/cmb-tests-base.php:59
msgid "Remove Embed"
msgstr ""
#: includes/CMB2_Ajax.php:177 tests/cmb-tests-base.php:64
msgid "No oEmbed Results Found for %s. View more info at"
msgstr ""
#: includes/CMB2_Field.php:1186
msgid "Add Group"
msgstr ""
#: includes/CMB2_Field.php:1187
msgid "Remove Group"
msgstr ""
#: includes/CMB2_Field.php:1209 includes/CMB2_Field.php:1213
#: tests/test-cmb-field.php:229
msgid "None"
msgstr "Geen"
#: includes/CMB2_Field.php:1269
msgid "Sorry, this field does not have a cmb_id specified."
msgstr ""
#: includes/CMB2_Field_Display.php:408 includes/CMB2_JS.php:139
#: includes/types/CMB2_Type_File_Base.php:75 tests/test-cmb-types-base.php:143
#: tests/test-cmb-types.php:701
msgid "File:"
msgstr ""
#: includes/CMB2_JS.php:86 includes/CMB2_JS.php:119
msgid "Clear"
msgstr "Maak Leeg"
#: includes/CMB2_JS.php:87
msgid "Default"
msgstr "Verstek"
#: includes/CMB2_JS.php:88
msgid "Select Color"
msgstr "Selekteer kleur"
#: includes/CMB2_JS.php:89
msgid "Current Color"
msgstr "Huidige kleur"
#: includes/CMB2_JS.php:110
msgid "Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday"
msgstr ""
#: includes/CMB2_JS.php:111
msgid "Su, Mo, Tu, We, Th, Fr, Sa"
msgstr ""
#: includes/CMB2_JS.php:112
msgid "Sun, Mon, Tue, Wed, Thu, Fri, Sat"
msgstr ""
#: includes/CMB2_JS.php:113
msgid ""
"January, February, March, April, May, June, July, August, September, "
"October, November, December"
msgstr ""
#: includes/CMB2_JS.php:114
msgid "Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec"
msgstr ""
#: includes/CMB2_JS.php:115
msgid "Next"
msgstr "Volgende"
#: includes/CMB2_JS.php:116
msgid "Prev"
msgstr "Vorige"
#: includes/CMB2_JS.php:117
msgid "Today"
msgstr ""
#: includes/CMB2_JS.php:118 includes/CMB2_JS.php:128
msgid "Done"
msgstr "Klaar"
#: includes/CMB2_JS.php:122
msgid "Choose Time"
msgstr ""
#: includes/CMB2_JS.php:123
msgid "Time"
msgstr ""
#: includes/CMB2_JS.php:124
msgid "Hour"
msgstr ""
#: includes/CMB2_JS.php:125
msgid "Minute"
msgstr ""
#: includes/CMB2_JS.php:126
msgid "Second"
msgstr ""
#: includes/CMB2_JS.php:127
msgid "Now"
msgstr ""
#: includes/CMB2_JS.php:135
msgid "Use this file"
msgstr ""
#: includes/CMB2_JS.php:136
msgid "Use these files"
msgstr ""
#: includes/CMB2_JS.php:137 includes/types/CMB2_Type_File_Base.php:61
msgid "Remove Image"
msgstr ""
#: includes/CMB2_JS.php:138 includes/CMB2_Types.php:257
#: includes/types/CMB2_Type_File_Base.php:80 tests/test-cmb-types-base.php:143
#: tests/test-cmb-types.php:47 tests/test-cmb-types.php:55
#: tests/test-cmb-types.php:701
msgid "Remove"
msgstr "Verwyder"
#: includes/CMB2_JS.php:140 includes/types/CMB2_Type_File_Base.php:78
#: tests/test-cmb-types-base.php:143 tests/test-cmb-types.php:701
msgid "Download"
msgstr ""
#: includes/CMB2_JS.php:141
msgid "Select / Deselect All"
msgstr ""
#: includes/CMB2_Types.php:194
msgid "Add Row"
msgstr ""
#: includes/CMB2_hookup.php:145
msgid ""
"Term Metadata is a WordPress > 4.4 feature. Please upgrade your WordPress "
"install."
msgstr ""
#: includes/CMB2_hookup.php:149
msgid "Term metaboxes configuration requires a 'taxonomies' parameter"
msgstr ""
#: includes/helper-functions.php:93
msgid "No oEmbed Results Found for %s. View more info at %s"
msgstr ""
#: includes/helper-functions.php:279
msgid "Save"
msgstr "Stoor"
#: includes/types/CMB2_Type_File.php:36 tests/test-cmb-types.php:683
#: tests/test-cmb-types.php:701
msgid "Add or Upload File"
msgstr ""
#: includes/types/CMB2_Type_File_List.php:36 tests/test-cmb-types.php:639
#: tests/test-cmb-types.php:663
msgid "Add or Upload Files"
msgstr ""
#: includes/types/CMB2_Type_Taxonomy_Multicheck.php:27
#: includes/types/CMB2_Type_Taxonomy_Radio.php:25
msgid "No terms"
msgstr ""
#. Plugin Name of the plugin/theme
msgid "CMB2"
msgstr ""
#. Plugin URI of the plugin/theme
msgid "https://github.com/WebDevStudios/CMB2"
msgstr ""
#. Description of the plugin/theme
msgid ""
"CMB2 will create metaboxes and forms with custom fields that will blow your "
"mind."
msgstr ""
#. Author of the plugin/theme
msgid "WebDevStudios"
msgstr ""
#. Author URI of the plugin/theme
msgid "http://webdevstudios.com"
msgstr ""
#: includes/CMB2_JS.php:109
msgctxt "Valid formatDate string for jquery-ui datepicker"
msgid "mm/dd/yy"
msgstr ""
#: includes/CMB2_JS.php:129
msgctxt ""
"Valid formatting string, as per "
"http://trentrichardson.com/examples/timepicker/"
msgid "hh:mm TT"
msgstr ""

BIN
cmb2/languages/cmb2-an.mo Normal file

Binary file not shown.

527
cmb2/languages/cmb2-an.po Normal file
View File

@ -0,0 +1,527 @@
# Copyright (C) 2016 WebDevStudios
# This file is distributed under the same license as the CMB2 package.
# Translators:
msgid ""
msgstr ""
"Project-Id-Version: CMB2\n"
"Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/cmb2\n"
"POT-Creation-Date: 2016-06-27 17:01:22+00:00\n"
"PO-Revision-Date: 2016-06-27 17:01+0000\n"
"Last-Translator: Justin Sternberg <me@jtsternberg.com>\n"
"Language-Team: Aragonese (http://www.transifex.com/wp-translations/cmb2/language/an/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: an\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: grunt-wp-i18n 0.4.9\n"
"X-Poedit-Basepath: ../\n"
"X-Poedit-Bookmarks: \n"
"X-Poedit-Country: United States\n"
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;_nx_noop:1,2,3c;esc_attr__;esc_html__;esc_attr_e;esc_html_e;esc_attr_x:1,2c;esc_html_x:1,2c;\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Textdomain-Support: yes\n"
#: example-functions.php:117 tests/test-cmb-field.php:255
msgid "Test Metabox"
msgstr ""
#: example-functions.php:130 example-functions.php:436
msgid "Test Text"
msgstr ""
#: example-functions.php:131 example-functions.php:144
#: example-functions.php:157 example-functions.php:165
#: example-functions.php:173 example-functions.php:182
#: example-functions.php:190 example-functions.php:205
#: example-functions.php:213 example-functions.php:221
#: example-functions.php:238 example-functions.php:247
#: example-functions.php:260 example-functions.php:267
#: example-functions.php:274 example-functions.php:288
#: example-functions.php:301 example-functions.php:314
#: example-functions.php:326 example-functions.php:335
#: example-functions.php:343 example-functions.php:352
#: example-functions.php:359 example-functions.php:373
#: example-functions.php:437 example-functions.php:528
#: example-functions.php:536 example-functions.php:543
#: example-functions.php:550 example-functions.php:557
#: example-functions.php:564 example-functions.php:571
#: example-functions.php:598 example-functions.php:606
#: example-functions.php:613 example-functions.php:650
#: tests/test-cmb-field.php:267
msgid "field description (optional)"
msgstr ""
#: example-functions.php:143
msgid "Test Text Small"
msgstr ""
#: example-functions.php:156
msgid "Test Text Medium"
msgstr ""
#: example-functions.php:164
msgid "Custom Rendered Field"
msgstr ""
#: example-functions.php:172
msgid "Website URL"
msgstr ""
#: example-functions.php:181
msgid "Test Text Email"
msgstr ""
#: example-functions.php:189
msgid "Test Time"
msgstr ""
#: example-functions.php:197 example-functions.php:198
msgid "Time zone"
msgstr ""
#: example-functions.php:204
msgid "Test Date Picker"
msgstr ""
#: example-functions.php:212
msgid "Test Date Picker (UNIX timestamp)"
msgstr ""
#: example-functions.php:220
msgid "Test Date/Time Picker Combo (UNIX timestamp)"
msgstr ""
#: example-functions.php:237
msgid "Test Money"
msgstr ""
#: example-functions.php:246
msgid "Test Color Picker"
msgstr ""
#: example-functions.php:259
msgid "Test Text Area"
msgstr ""
#: example-functions.php:266
msgid "Test Text Area Small"
msgstr ""
#: example-functions.php:273
msgid "Test Text Area for Code"
msgstr ""
#: example-functions.php:280
msgid "Test Title Weeeee"
msgstr ""
#: example-functions.php:281
msgid "This is a title description"
msgstr ""
#: example-functions.php:287
msgid "Test Select"
msgstr ""
#: example-functions.php:293 example-functions.php:306
#: example-functions.php:318
msgid "Option One"
msgstr ""
#: example-functions.php:294 example-functions.php:307
#: example-functions.php:319
msgid "Option Two"
msgstr ""
#: example-functions.php:295 example-functions.php:308
#: example-functions.php:320
msgid "Option Three"
msgstr ""
#: example-functions.php:300
msgid "Test Radio inline"
msgstr ""
#: example-functions.php:313
msgid "Test Radio"
msgstr ""
#: example-functions.php:325
msgid "Test Taxonomy Radio"
msgstr ""
#: example-functions.php:334
msgid "Test Taxonomy Select"
msgstr ""
#: example-functions.php:342
msgid "Test Taxonomy Multi Checkbox"
msgstr ""
#: example-functions.php:351
msgid "Test Checkbox"
msgstr ""
#: example-functions.php:358 tests/test-cmb-field.php:266
msgid "Test Multi Checkbox"
msgstr ""
#: example-functions.php:364 tests/test-cmb-field.php:272
msgid "Check One"
msgstr ""
#: example-functions.php:365 tests/test-cmb-field.php:273
msgid "Check Two"
msgstr ""
#: example-functions.php:366 tests/test-cmb-field.php:274
msgid "Check Three"
msgstr ""
#: example-functions.php:372
msgid "Test wysiwyg"
msgstr ""
#: example-functions.php:380
msgid "Test Image"
msgstr ""
#: example-functions.php:381
msgid "Upload an image or enter a URL."
msgstr ""
#: example-functions.php:387
msgid "Multiple Files"
msgstr ""
#: example-functions.php:388
msgid "Upload or add multiple images/attachments."
msgstr ""
#: example-functions.php:395
msgid "oEmbed"
msgstr ""
#: example-functions.php:396
msgid ""
"Enter a youtube, twitter, or instagram URL. Supports services listed at <a "
"href=\"http://codex.wordpress.org/Embeds\">http://codex.wordpress.org/Embeds</a>."
msgstr ""
#: example-functions.php:427
msgid "About Page Metabox"
msgstr ""
#: example-functions.php:456
msgid "Repeating Field Group"
msgstr ""
#: example-functions.php:464
msgid "Generates reusable form entries"
msgstr ""
#: example-functions.php:466
msgid "Entry {#}"
msgstr ""
#: example-functions.php:467
msgid "Add Another Entry"
msgstr ""
#: example-functions.php:468
msgid "Remove Entry"
msgstr ""
#: example-functions.php:481
msgid "Entry Title"
msgstr ""
#: example-functions.php:488
msgid "Description"
msgstr ""
#: example-functions.php:489
msgid "Write a short description for this entry"
msgstr ""
#: example-functions.php:495
msgid "Entry Image"
msgstr ""
#: example-functions.php:501
msgid "Image Caption"
msgstr "Leyenda d'a imachen"
#: example-functions.php:520
msgid "User Profile Metabox"
msgstr ""
#: example-functions.php:527 example-functions.php:597
msgid "Extra Info"
msgstr ""
#: example-functions.php:535
msgid "Avatar"
msgstr ""
#: example-functions.php:542
msgid "Facebook URL"
msgstr ""
#: example-functions.php:549
msgid "Twitter URL"
msgstr ""
#: example-functions.php:556
msgid "Google+ URL"
msgstr ""
#: example-functions.php:563
msgid "Linkedin URL"
msgstr ""
#: example-functions.php:570
msgid "User Field"
msgstr ""
#: example-functions.php:590
msgid "Category Metabox"
msgstr ""
#: example-functions.php:605
msgid "Term Image"
msgstr ""
#: example-functions.php:612
msgid "Arbitrary Term Field"
msgstr ""
#: example-functions.php:634
msgid "Theme Options Metabox"
msgstr ""
#: example-functions.php:649
msgid "Site Background Color"
msgstr ""
#: includes/CMB2.php:129
msgid "Metabox configuration is required to have an ID parameter"
msgstr ""
#: includes/CMB2.php:418
msgid "Click to toggle"
msgstr "Fe clic ta cambiar"
#: includes/CMB2_Ajax.php:71
msgid "Please Try Again"
msgstr ""
#: includes/CMB2_Ajax.php:173 tests/cmb-tests-base.php:59
msgid "Remove Embed"
msgstr ""
#: includes/CMB2_Ajax.php:177 tests/cmb-tests-base.php:64
msgid "No oEmbed Results Found for %s. View more info at"
msgstr ""
#: includes/CMB2_Field.php:1186
msgid "Add Group"
msgstr ""
#: includes/CMB2_Field.php:1187
msgid "Remove Group"
msgstr ""
#: includes/CMB2_Field.php:1209 includes/CMB2_Field.php:1213
#: tests/test-cmb-field.php:229
msgid "None"
msgstr "Garra"
#: includes/CMB2_Field.php:1269
msgid "Sorry, this field does not have a cmb_id specified."
msgstr ""
#: includes/CMB2_Field_Display.php:408 includes/CMB2_JS.php:139
#: includes/types/CMB2_Type_File_Base.php:75 tests/test-cmb-types-base.php:143
#: tests/test-cmb-types.php:701
msgid "File:"
msgstr ""
#: includes/CMB2_JS.php:86 includes/CMB2_JS.php:119
msgid "Clear"
msgstr "Limpiar"
#: includes/CMB2_JS.php:87
msgid "Default"
msgstr "Predeterminau"
#: includes/CMB2_JS.php:88
msgid "Select Color"
msgstr ""
#: includes/CMB2_JS.php:89
msgid "Current Color"
msgstr ""
#: includes/CMB2_JS.php:110
msgid "Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday"
msgstr ""
#: includes/CMB2_JS.php:111
msgid "Su, Mo, Tu, We, Th, Fr, Sa"
msgstr ""
#: includes/CMB2_JS.php:112
msgid "Sun, Mon, Tue, Wed, Thu, Fri, Sat"
msgstr ""
#: includes/CMB2_JS.php:113
msgid ""
"January, February, March, April, May, June, July, August, September, "
"October, November, December"
msgstr ""
#: includes/CMB2_JS.php:114
msgid "Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec"
msgstr ""
#: includes/CMB2_JS.php:115
msgid "Next"
msgstr "Siguient"
#: includes/CMB2_JS.php:116
msgid "Prev"
msgstr ""
#: includes/CMB2_JS.php:117
msgid "Today"
msgstr ""
#: includes/CMB2_JS.php:118 includes/CMB2_JS.php:128
msgid "Done"
msgstr "Feito"
#: includes/CMB2_JS.php:122
msgid "Choose Time"
msgstr ""
#: includes/CMB2_JS.php:123
msgid "Time"
msgstr ""
#: includes/CMB2_JS.php:124
msgid "Hour"
msgstr ""
#: includes/CMB2_JS.php:125
msgid "Minute"
msgstr ""
#: includes/CMB2_JS.php:126
msgid "Second"
msgstr ""
#: includes/CMB2_JS.php:127
msgid "Now"
msgstr ""
#: includes/CMB2_JS.php:135
msgid "Use this file"
msgstr ""
#: includes/CMB2_JS.php:136
msgid "Use these files"
msgstr ""
#: includes/CMB2_JS.php:137 includes/types/CMB2_Type_File_Base.php:61
msgid "Remove Image"
msgstr "Eliminar Imachen"
#: includes/CMB2_JS.php:138 includes/CMB2_Types.php:257
#: includes/types/CMB2_Type_File_Base.php:80 tests/test-cmb-types-base.php:143
#: tests/test-cmb-types.php:47 tests/test-cmb-types.php:55
#: tests/test-cmb-types.php:701
msgid "Remove"
msgstr ""
#: includes/CMB2_JS.php:140 includes/types/CMB2_Type_File_Base.php:78
#: tests/test-cmb-types-base.php:143 tests/test-cmb-types.php:701
msgid "Download"
msgstr ""
#: includes/CMB2_JS.php:141
msgid "Select / Deselect All"
msgstr ""
#: includes/CMB2_Types.php:194
msgid "Add Row"
msgstr ""
#: includes/CMB2_hookup.php:145
msgid ""
"Term Metadata is a WordPress > 4.4 feature. Please upgrade your WordPress "
"install."
msgstr ""
#: includes/CMB2_hookup.php:149
msgid "Term metaboxes configuration requires a 'taxonomies' parameter"
msgstr ""
#: includes/helper-functions.php:93
msgid "No oEmbed Results Found for %s. View more info at %s"
msgstr ""
#: includes/helper-functions.php:279
msgid "Save"
msgstr "Alzar"
#: includes/types/CMB2_Type_File.php:36 tests/test-cmb-types.php:683
#: tests/test-cmb-types.php:701
msgid "Add or Upload File"
msgstr ""
#: includes/types/CMB2_Type_File_List.php:36 tests/test-cmb-types.php:639
#: tests/test-cmb-types.php:663
msgid "Add or Upload Files"
msgstr ""
#: includes/types/CMB2_Type_Taxonomy_Multicheck.php:27
#: includes/types/CMB2_Type_Taxonomy_Radio.php:25
msgid "No terms"
msgstr ""
#. Plugin Name of the plugin/theme
msgid "CMB2"
msgstr ""
#. Plugin URI of the plugin/theme
msgid "https://github.com/WebDevStudios/CMB2"
msgstr ""
#. Description of the plugin/theme
msgid ""
"CMB2 will create metaboxes and forms with custom fields that will blow your "
"mind."
msgstr ""
#. Author of the plugin/theme
msgid "WebDevStudios"
msgstr ""
#. Author URI of the plugin/theme
msgid "http://webdevstudios.com"
msgstr ""
#: includes/CMB2_JS.php:109
msgctxt "Valid formatDate string for jquery-ui datepicker"
msgid "mm/dd/yy"
msgstr ""
#: includes/CMB2_JS.php:129
msgctxt ""
"Valid formatting string, as per "
"http://trentrichardson.com/examples/timepicker/"
msgid "hh:mm TT"
msgstr ""

BIN
cmb2/languages/cmb2-ar.mo Normal file

Binary file not shown.

529
cmb2/languages/cmb2-ar.po Normal file
View File

@ -0,0 +1,529 @@
# Copyright (C) 2016 WebDevStudios
# This file is distributed under the same license as the CMB2 package.
# Translators:
# Adil Elsaeed <adil.elsaeed@hotmail.com>, 2015
# nabil eisa <nabilstudios@gmail.com>, 2015
msgid ""
msgstr ""
"Project-Id-Version: CMB2\n"
"Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/cmb2\n"
"POT-Creation-Date: 2016-06-27 17:01:22+00:00\n"
"PO-Revision-Date: 2016-06-27 17:01+0000\n"
"Last-Translator: Justin Sternberg <me@jtsternberg.com>\n"
"Language-Team: Arabic (http://www.transifex.com/wp-translations/cmb2/language/ar/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: ar\n"
"Plural-Forms: nplurals=6; plural=n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5;\n"
"X-Generator: grunt-wp-i18n 0.4.9\n"
"X-Poedit-Basepath: ../\n"
"X-Poedit-Bookmarks: \n"
"X-Poedit-Country: United States\n"
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;_nx_noop:1,2,3c;esc_attr__;esc_html__;esc_attr_e;esc_html_e;esc_attr_x:1,2c;esc_html_x:1,2c;\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Textdomain-Support: yes\n"
#: example-functions.php:117 tests/test-cmb-field.php:255
msgid "Test Metabox"
msgstr "صندوق ميتا اختباري"
#: example-functions.php:130 example-functions.php:436
msgid "Test Text"
msgstr "نص اختباري"
#: example-functions.php:131 example-functions.php:144
#: example-functions.php:157 example-functions.php:165
#: example-functions.php:173 example-functions.php:182
#: example-functions.php:190 example-functions.php:205
#: example-functions.php:213 example-functions.php:221
#: example-functions.php:238 example-functions.php:247
#: example-functions.php:260 example-functions.php:267
#: example-functions.php:274 example-functions.php:288
#: example-functions.php:301 example-functions.php:314
#: example-functions.php:326 example-functions.php:335
#: example-functions.php:343 example-functions.php:352
#: example-functions.php:359 example-functions.php:373
#: example-functions.php:437 example-functions.php:528
#: example-functions.php:536 example-functions.php:543
#: example-functions.php:550 example-functions.php:557
#: example-functions.php:564 example-functions.php:571
#: example-functions.php:598 example-functions.php:606
#: example-functions.php:613 example-functions.php:650
#: tests/test-cmb-field.php:267
msgid "field description (optional)"
msgstr "وصف الحقل (اختياري)"
#: example-functions.php:143
msgid "Test Text Small"
msgstr "نص اختباري صغير"
#: example-functions.php:156
msgid "Test Text Medium"
msgstr "نص اختباري متوسط"
#: example-functions.php:164
msgid "Custom Rendered Field"
msgstr ""
#: example-functions.php:172
msgid "Website URL"
msgstr "رابط موقع"
#: example-functions.php:181
msgid "Test Text Email"
msgstr "نص بريد إلكتروني اختباري"
#: example-functions.php:189
msgid "Test Time"
msgstr "وقت اختباري"
#: example-functions.php:197 example-functions.php:198
msgid "Time zone"
msgstr "منطقة زمنية"
#: example-functions.php:204
msgid "Test Date Picker"
msgstr "مربع اختيار التاريخ اختباري"
#: example-functions.php:212
msgid "Test Date Picker (UNIX timestamp)"
msgstr "مربع اختيار التاريخ اختباري بنظام (UNIX timestamp)"
#: example-functions.php:220
msgid "Test Date/Time Picker Combo (UNIX timestamp)"
msgstr "مربع اختباري لاختيار الوقت و التاريخ معا بنظام (UNIX timestamp)"
#: example-functions.php:237
msgid "Test Money"
msgstr "حقل نقود اختباري"
#: example-functions.php:246
msgid "Test Color Picker"
msgstr "حقل اختيار اللون اختباري"
#: example-functions.php:259
msgid "Test Text Area"
msgstr "مربع نصي متعدد السطور اختباري"
#: example-functions.php:266
msgid "Test Text Area Small"
msgstr "مربع نصي متعدد السطور اختباري صغير"
#: example-functions.php:273
msgid "Test Text Area for Code"
msgstr "مربع نصي متعدد السطور اختباري خاص بالكود"
#: example-functions.php:280
msgid "Test Title Weeeee"
msgstr "عنوان اختباري"
#: example-functions.php:281
msgid "This is a title description"
msgstr "هذا هو وصف للعنوان"
#: example-functions.php:287
msgid "Test Select"
msgstr "اختيار من قائمة منسدلة اختباري"
#: example-functions.php:293 example-functions.php:306
#: example-functions.php:318
msgid "Option One"
msgstr "الخيار الأول"
#: example-functions.php:294 example-functions.php:307
#: example-functions.php:319
msgid "Option Two"
msgstr "الخيار الثاني"
#: example-functions.php:295 example-functions.php:308
#: example-functions.php:320
msgid "Option Three"
msgstr "الخيار الثالث"
#: example-functions.php:300
msgid "Test Radio inline"
msgstr "زر راديو اختاري مُضمن"
#: example-functions.php:313
msgid "Test Radio"
msgstr "زر راديو اختباري"
#: example-functions.php:325
msgid "Test Taxonomy Radio"
msgstr "زر راديو للاختيار من التصنيفات اختباري"
#: example-functions.php:334
msgid "Test Taxonomy Select"
msgstr "قائمة منسدلة للاختيار من التصنيفات اختبارية"
#: example-functions.php:342
msgid "Test Taxonomy Multi Checkbox"
msgstr "مربع اختباري متعدد الاختيارات للتصنيفات"
#: example-functions.php:351
msgid "Test Checkbox"
msgstr "مربع اختيار اختباري"
#: example-functions.php:358 tests/test-cmb-field.php:266
msgid "Test Multi Checkbox"
msgstr "مربع اختيار متعدد اختباري"
#: example-functions.php:364 tests/test-cmb-field.php:272
msgid "Check One"
msgstr "الاختيار الأول"
#: example-functions.php:365 tests/test-cmb-field.php:273
msgid "Check Two"
msgstr "الاختيار الثاني"
#: example-functions.php:366 tests/test-cmb-field.php:274
msgid "Check Three"
msgstr "الاختيار الثالث"
#: example-functions.php:372
msgid "Test wysiwyg"
msgstr "محرر اختباري"
#: example-functions.php:380
msgid "Test Image"
msgstr "صورة اختبارية"
#: example-functions.php:381
msgid "Upload an image or enter a URL."
msgstr "قم برفع صورة او قم بادخال رابط"
#: example-functions.php:387
msgid "Multiple Files"
msgstr "ملفات متعددة"
#: example-functions.php:388
msgid "Upload or add multiple images/attachments."
msgstr "قم برفع او اضافة صور/مرفقات متعددة"
#: example-functions.php:395
msgid "oEmbed"
msgstr "مدرج oEmbed"
#: example-functions.php:396
msgid ""
"Enter a youtube, twitter, or instagram URL. Supports services listed at <a "
"href=\"http://codex.wordpress.org/Embeds\">http://codex.wordpress.org/Embeds</a>."
msgstr "أدخل رابط يوتيوب أو تويتر أو إنستجرام. يمكنك الإطلاع على قائمة المواقع المدعومة في <a href=\"http://codex.wordpress.org/Embeds\">http://codex.wordpress.org/Embeds</a>."
#: example-functions.php:427
msgid "About Page Metabox"
msgstr "صندوق ميتا خاص بصفحة \" about\""
#: example-functions.php:456
msgid "Repeating Field Group"
msgstr "مجموعة حقول متكررة"
#: example-functions.php:464
msgid "Generates reusable form entries"
msgstr "تنتج مدخلات استمارات - form - قابلة لاعادة الاستخدام"
#: example-functions.php:466
msgid "Entry {#}"
msgstr "مدخلة {#}"
#: example-functions.php:467
msgid "Add Another Entry"
msgstr "اضف مدخلة أخرى"
#: example-functions.php:468
msgid "Remove Entry"
msgstr "حذف مدخلة"
#: example-functions.php:481
msgid "Entry Title"
msgstr "عنوان المدخلة"
#: example-functions.php:488
msgid "Description"
msgstr "الوصف"
#: example-functions.php:489
msgid "Write a short description for this entry"
msgstr "اكتب وصف قصير لهذه المدخلة"
#: example-functions.php:495
msgid "Entry Image"
msgstr "صورة المدخلة"
#: example-functions.php:501
msgid "Image Caption"
msgstr "وصف الصورة"
#: example-functions.php:520
msgid "User Profile Metabox"
msgstr "صندوق ميتا خاص بالملف الشخصي للعضو"
#: example-functions.php:527 example-functions.php:597
msgid "Extra Info"
msgstr "معلومات اضافية"
#: example-functions.php:535
msgid "Avatar"
msgstr "الصورة الرمزية"
#: example-functions.php:542
msgid "Facebook URL"
msgstr "رابط فيسبوك"
#: example-functions.php:549
msgid "Twitter URL"
msgstr "رابط تويتر"
#: example-functions.php:556
msgid "Google+ URL"
msgstr "رابط جوجل بلس"
#: example-functions.php:563
msgid "Linkedin URL"
msgstr "لابط لينكد ان"
#: example-functions.php:570
msgid "User Field"
msgstr "حقل المستخدم"
#: example-functions.php:590
msgid "Category Metabox"
msgstr ""
#: example-functions.php:605
msgid "Term Image"
msgstr ""
#: example-functions.php:612
msgid "Arbitrary Term Field"
msgstr ""
#: example-functions.php:634
msgid "Theme Options Metabox"
msgstr "حقل ميتا خاص بخيارات القالب"
#: example-functions.php:649
msgid "Site Background Color"
msgstr "لون خلفية الموقع"
#: includes/CMB2.php:129
msgid "Metabox configuration is required to have an ID parameter"
msgstr "ضبط صندوق الميتا يتطلب وجود متغير خاص ب ID"
#: includes/CMB2.php:418
msgid "Click to toggle"
msgstr "أنقر للفتح والإغلاق"
#: includes/CMB2_Ajax.php:71
msgid "Please Try Again"
msgstr "برجاء المحاولة مرة أخرى"
#: includes/CMB2_Ajax.php:173 tests/cmb-tests-base.php:59
msgid "Remove Embed"
msgstr "حذف المدرج"
#: includes/CMB2_Ajax.php:177 tests/cmb-tests-base.php:64
msgid "No oEmbed Results Found for %s. View more info at"
msgstr "لم يتم العثور على مدرج oEmbed في %s. شاهد المزيد من المعلومات في "
#: includes/CMB2_Field.php:1186
msgid "Add Group"
msgstr "اضافة مجموعة"
#: includes/CMB2_Field.php:1187
msgid "Remove Group"
msgstr "حذف مجموعة"
#: includes/CMB2_Field.php:1209 includes/CMB2_Field.php:1213
#: tests/test-cmb-field.php:229
msgid "None"
msgstr "لا شيء"
#: includes/CMB2_Field.php:1269
msgid "Sorry, this field does not have a cmb_id specified."
msgstr ""
#: includes/CMB2_Field_Display.php:408 includes/CMB2_JS.php:139
#: includes/types/CMB2_Type_File_Base.php:75 tests/test-cmb-types-base.php:143
#: tests/test-cmb-types.php:701
msgid "File:"
msgstr "ملف :"
#: includes/CMB2_JS.php:86 includes/CMB2_JS.php:119
msgid "Clear"
msgstr "مسح"
#: includes/CMB2_JS.php:87
msgid "Default"
msgstr "افتراضي"
#: includes/CMB2_JS.php:88
msgid "Select Color"
msgstr "إختر لونا"
#: includes/CMB2_JS.php:89
msgid "Current Color"
msgstr "اللون الحالي"
#: includes/CMB2_JS.php:110
msgid "Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday"
msgstr "الأحد, الاثنين, الثلاثاء, الأربعاء, الخميس, الجمعة, السبت"
#: includes/CMB2_JS.php:111
msgid "Su, Mo, Tu, We, Th, Fr, Sa"
msgstr "الأحد, الاثنين, الثلاثاء, الأربعاء, الخميس, الجمعة, السبت"
#: includes/CMB2_JS.php:112
msgid "Sun, Mon, Tue, Wed, Thu, Fri, Sat"
msgstr "الأحد, الاثنين, الثلاثاء, الأربعاء, الخميس, الجمعة, السبت"
#: includes/CMB2_JS.php:113
msgid ""
"January, February, March, April, May, June, July, August, September, "
"October, November, December"
msgstr "يناير, فبراير, مارس, ابريل, مايو, يونيو, يوليو, اغسطس, سبتمبر, اكتوبر, نوفمبر, ديسمبر"
#: includes/CMB2_JS.php:114
msgid "Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec"
msgstr "يناير, فبراير, مارس, ابريل, مايو, يونيو, يوليو, اغسطس, سبتمبر, اكتوبر, نوفمبر, ديسمبر"
#: includes/CMB2_JS.php:115
msgid "Next"
msgstr "التالي"
#: includes/CMB2_JS.php:116
msgid "Prev"
msgstr "السابق"
#: includes/CMB2_JS.php:117
msgid "Today"
msgstr "اليوم"
#: includes/CMB2_JS.php:118 includes/CMB2_JS.php:128
msgid "Done"
msgstr "انتهى"
#: includes/CMB2_JS.php:122
msgid "Choose Time"
msgstr "اختر الوقت"
#: includes/CMB2_JS.php:123
msgid "Time"
msgstr "الوقت"
#: includes/CMB2_JS.php:124
msgid "Hour"
msgstr "ساعة"
#: includes/CMB2_JS.php:125
msgid "Minute"
msgstr "دقيقة"
#: includes/CMB2_JS.php:126
msgid "Second"
msgstr "ثانية"
#: includes/CMB2_JS.php:127
msgid "Now"
msgstr "الآن"
#: includes/CMB2_JS.php:135
msgid "Use this file"
msgstr "استخدم هذا الملف"
#: includes/CMB2_JS.php:136
msgid "Use these files"
msgstr "إستخدم هذه الملفات"
#: includes/CMB2_JS.php:137 includes/types/CMB2_Type_File_Base.php:61
msgid "Remove Image"
msgstr "إزالة الصورة"
#: includes/CMB2_JS.php:138 includes/CMB2_Types.php:257
#: includes/types/CMB2_Type_File_Base.php:80 tests/test-cmb-types-base.php:143
#: tests/test-cmb-types.php:47 tests/test-cmb-types.php:55
#: tests/test-cmb-types.php:701
msgid "Remove"
msgstr "إزالة"
#: includes/CMB2_JS.php:140 includes/types/CMB2_Type_File_Base.php:78
#: tests/test-cmb-types-base.php:143 tests/test-cmb-types.php:701
msgid "Download"
msgstr "التحميل"
#: includes/CMB2_JS.php:141
msgid "Select / Deselect All"
msgstr "اختيار/ عدم اختيار الكل"
#: includes/CMB2_Types.php:194
msgid "Add Row"
msgstr "اضافة صف"
#: includes/CMB2_hookup.php:145
msgid ""
"Term Metadata is a WordPress > 4.4 feature. Please upgrade your WordPress "
"install."
msgstr ""
#: includes/CMB2_hookup.php:149
msgid "Term metaboxes configuration requires a 'taxonomies' parameter"
msgstr ""
#: includes/helper-functions.php:93
msgid "No oEmbed Results Found for %s. View more info at %s"
msgstr ""
#: includes/helper-functions.php:279
msgid "Save"
msgstr "حفظ"
#: includes/types/CMB2_Type_File.php:36 tests/test-cmb-types.php:683
#: tests/test-cmb-types.php:701
msgid "Add or Upload File"
msgstr "اضف او قم برفع ملف"
#: includes/types/CMB2_Type_File_List.php:36 tests/test-cmb-types.php:639
#: tests/test-cmb-types.php:663
msgid "Add or Upload Files"
msgstr "اضف او قم برفع ملفات"
#: includes/types/CMB2_Type_Taxonomy_Multicheck.php:27
#: includes/types/CMB2_Type_Taxonomy_Radio.php:25
msgid "No terms"
msgstr "لا يوجد مصطلحات"
#. Plugin Name of the plugin/theme
msgid "CMB2"
msgstr "CMB2"
#. Plugin URI of the plugin/theme
msgid "https://github.com/WebDevStudios/CMB2"
msgstr "https://github.com/WebDevStudios/CMB2"
#. Description of the plugin/theme
msgid ""
"CMB2 will create metaboxes and forms with custom fields that will blow your "
"mind."
msgstr "يمكنك من خلال CMB2 إنشاء حقول مخصصة ونماذج بحقول مختلفة."
#. Author of the plugin/theme
msgid "WebDevStudios"
msgstr "WebDevStudios"
#. Author URI of the plugin/theme
msgid "http://webdevstudios.com"
msgstr "http://webdevstudios.com"
#: includes/CMB2_JS.php:109
msgctxt "Valid formatDate string for jquery-ui datepicker"
msgid "mm/dd/yy"
msgstr "mm/dd/yy"
#: includes/CMB2_JS.php:129
msgctxt ""
"Valid formatting string, as per "
"http://trentrichardson.com/examples/timepicker/"
msgid "hh:mm TT"
msgstr "hh:mm TT"

BIN
cmb2/languages/cmb2-ary.mo Normal file

Binary file not shown.

448
cmb2/languages/cmb2-ary.po Normal file
View File

@ -0,0 +1,448 @@
# Translation of Development (trunk) in Moroccan Arabic
# This file is distributed under the same license as the Development (trunk) package.
msgid ""
msgstr ""
"PO-Revision-Date: 2015-10-21 21:13:01+0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=6; plural=n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5;\n"
"X-Generator: GlotPress/1.0-alpha-1100\n"
"Project-Id-Version: Development (trunk)\n"
#: includes/CMB2_JS.php:140 includes/CMB2_Types.php:1021
msgid "Download"
msgstr "التحميل"
#: includes/CMB2_JS.php:115
msgid "Next"
msgstr "التالي"
#: includes/helper-functions.php:250
msgid "Save"
msgstr "حفظ"
#: includes/CMB2_JS.php:138 includes/CMB2_Types.php:357
#: includes/CMB2_Types.php:1023
msgid "Remove"
msgstr "إزالة"
#: includes/CMB2_Field.php:978 includes/CMB2_Field.php:982
msgid "None"
msgstr "لا شيء"
#: includes/CMB2_JS.php:87
msgid "Default"
msgstr "افتراضي"
#: includes/CMB2_JS.php:117
msgid "Today"
msgstr "اليوم"
#: includes/CMB2_JS.php:127
msgid "Now"
msgstr "الآن"
#: includes/CMB2_JS.php:123
msgid "Time"
msgstr "الوقت"
#: example-functions.php:434
msgid "Description"
msgstr "الوصف"
#: example-functions.php:267
msgid "Test Taxonomy Radio"
msgstr "زر راديو للاختيار من التصنيفات اختباري"
#: example-functions.php:276
msgid "Test Taxonomy Select"
msgstr "قائمة منسدلة للاختيار من التصنيفات اختبارية"
#: example-functions.php:284
msgid "Test Taxonomy Multi Checkbox"
msgstr "مربع اختباري متعدد الاختيارات للتصنيفات"
#: example-functions.php:293
msgid "Test Checkbox"
msgstr "مربع اختيار اختباري"
#: example-functions.php:300
msgid "Test Multi Checkbox"
msgstr "مربع اختيار متعدد اختباري"
#: example-functions.php:306
msgid "Check One"
msgstr "الاختيار الأول"
#: example-functions.php:307
msgid "Check Two"
msgstr "الاختيار الثاني"
#: example-functions.php:308
msgid "Check Three"
msgstr "الاختيار الثالث"
#: example-functions.php:314
msgid "Test wysiwyg"
msgstr "محرر اختباري"
#: example-functions.php:322
msgid "Test Image"
msgstr "صورة اختبارية"
#: example-functions.php:323
msgid "Upload an image or enter a URL."
msgstr "قم برفع صورة او قم بادخال رابط"
#: example-functions.php:329
msgid "Multiple Files"
msgstr "ملفات متعددة"
#: example-functions.php:330
msgid "Upload or add multiple images/attachments."
msgstr "قم برفع او اضافة صور/مرفقات متعددة"
#: example-functions.php:337
msgid "oEmbed"
msgstr "مدرج oEmbed"
#: example-functions.php:371
msgid "About Page Metabox"
msgstr "صندوق ميتا خاص بصفحة \" about\""
#: example-functions.php:402
msgid "Repeating Field Group"
msgstr "مجموعة حقول متكررة"
#: example-functions.php:410
msgid "Generates reusable form entries"
msgstr "تنتج مدخلات استمارات - form - قابلة لاعادة الاستخدام"
#: example-functions.php:412
msgid "Entry {#}"
msgstr "مدخلة {#}"
#: example-functions.php:413
msgid "Add Another Entry"
msgstr "اضف مدخلة أخرى"
#: example-functions.php:414
msgid "Remove Entry"
msgstr "حذف مدخلة"
#: example-functions.php:427
msgid "Entry Title"
msgstr "عنوان المدخلة"
#: example-functions.php:435
msgid "Write a short description for this entry"
msgstr "اكتب وصف قصير لهذه المدخلة"
#: example-functions.php:441
msgid "Entry Image"
msgstr "صورة المدخلة"
#: example-functions.php:447
msgid "Image Caption"
msgstr "وصف الصورة"
#: example-functions.php:468
msgid "User Profile Metabox"
msgstr "صندوق ميتا خاص بالملف الشخصي للعضو"
#: example-functions.php:475
msgid "Extra Info"
msgstr "معلومات اضافية"
#: example-functions.php:483
msgid "Avatar"
msgstr "الصورة الرمزية"
#: example-functions.php:490
msgid "Facebook URL"
msgstr "رابط فيسبوك"
#: example-functions.php:497
msgid "Twitter URL"
msgstr "رابط تويتر"
#: example-functions.php:504
msgid "Google+ URL"
msgstr "رابط جوجل بلس"
#: example-functions.php:511
msgid "Linkedin URL"
msgstr "لابط لينكد ان"
#: example-functions.php:518
msgid "User Field"
msgstr "حقل المستخدم"
#: example-functions.php:541
msgid "Theme Options Metabox"
msgstr "حقل ميتا خاص بخيارات القالب"
#: example-functions.php:556
msgid "Site Background Color"
msgstr "لون خلفية الموقع"
#: includes/CMB2.php:120
msgid "Metabox configuration is required to have an ID parameter"
msgstr "ضبط صندوق الميتا يتطلب وجود متغير خاص ب ID"
#: includes/CMB2.php:332
msgid "Click to toggle"
msgstr "أنقر للفتح والإغلاق"
#: includes/CMB2_Ajax.php:40
msgid "Please Try Again"
msgstr "برجاء المحاولة مرة أخرى"
#: includes/CMB2_Ajax.php:135
msgid "Remove Embed"
msgstr "حذف المدرج"
#: includes/CMB2_Ajax.php:139
msgid "No oEmbed Results Found for %s. View more info at"
msgstr "لم يتم العثور على مدرج oEmbed في %s. شاهد المزيد من المعلومات في "
#: includes/CMB2_Field.php:955
msgid "Add Group"
msgstr "اضافة مجموعة"
#: includes/CMB2_Field.php:956
msgid "Remove Group"
msgstr "حذف مجموعة"
#: includes/CMB2_JS.php:86 includes/CMB2_JS.php:119
msgid "Clear"
msgstr "مسح"
#: includes/CMB2_JS.php:88
msgid "Select Color"
msgstr "إختر لونا"
#: includes/CMB2_JS.php:89
msgid "Current Color"
msgstr "اللون الحالي"
#: includes/CMB2_JS.php:109
msgctxt "Valid formatDate string for jquery-ui datepicker"
msgid "mm/dd/yy"
msgstr "mm/dd/yy"
#: includes/CMB2_JS.php:110
msgid "Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday"
msgstr "الأحد, الاثنين, الثلاثاء, الأربعاء, الخميس, الجمعة, السبت"
#: includes/CMB2_JS.php:111
msgid "Su, Mo, Tu, We, Th, Fr, Sa"
msgstr "الأحد, الاثنين, الثلاثاء, الأربعاء, الخميس, الجمعة, السبت"
#: includes/CMB2_JS.php:112
msgid "Sun, Mon, Tue, Wed, Thu, Fri, Sat"
msgstr "الأحد, الاثنين, الثلاثاء, الأربعاء, الخميس, الجمعة, السبت"
#: includes/CMB2_JS.php:113
msgid "January, February, March, April, May, June, July, August, September, October, November, December"
msgstr "يناير, فبراير, مارس, ابريل, مايو, يونيو, يوليو, اغسطس, سبتمبر, اكتوبر, نوفمبر, ديسمبر"
#: includes/CMB2_JS.php:114
msgid "Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec"
msgstr "يناير, فبراير, مارس, ابريل, مايو, يونيو, يوليو, اغسطس, سبتمبر, اكتوبر, نوفمبر, ديسمبر"
#: includes/CMB2_JS.php:116
msgid "Prev"
msgstr "السابق"
#: includes/CMB2_JS.php:118 includes/CMB2_JS.php:128
msgid "Done"
msgstr "انتهى"
#: includes/CMB2_JS.php:122
msgid "Choose Time"
msgstr "اختر الوقت"
#: includes/CMB2_JS.php:124
msgid "Hour"
msgstr "ساعة"
#: includes/CMB2_JS.php:125
msgid "Minute"
msgstr "دقيقة"
#: includes/CMB2_JS.php:126
msgid "Second"
msgstr "ثانية"
#: includes/CMB2_JS.php:129
msgctxt "Valid formatting string, as per http://trentrichardson.com/examples/timepicker/"
msgid "hh:mm TT"
msgstr "hh:mm TT"
#: includes/CMB2_JS.php:135
msgid "Use this file"
msgstr "استخدم هذا الملف"
#: includes/CMB2_JS.php:137 includes/CMB2_Types.php:1004
msgid "Remove Image"
msgstr "إزالة الصورة"
#: includes/CMB2_JS.php:139 includes/CMB2_Types.php:1018
msgid "File:"
msgstr "ملف :"
#: includes/CMB2_JS.php:141
msgid "Select / Deselect All"
msgstr "اختيار/ عدم اختيار الكل"
#: includes/CMB2_Types.php:298
msgid "Add Row"
msgstr "اضافة صف"
#: includes/CMB2_Types.php:749 includes/CMB2_Types.php:797
msgid "No terms"
msgstr "لا يوجد مصطلحات"
#: includes/CMB2_Types.php:864
msgid "Add or Upload Files"
msgstr "اضف او قم برفع ملفات"
#: includes/CMB2_Types.php:926
msgid "Add or Upload File"
msgstr "اضف او قم برفع ملف"
#. Author URI of the plugin/theme
msgid "http://webdevstudios.com"
msgstr "http://webdevstudios.com"
#. Plugin Name of the plugin/theme
msgid "CMB2"
msgstr "CMB2"
#. Plugin URI of the plugin/theme
msgid "https://github.com/WebDevStudios/CMB2"
msgstr "https://github.com/WebDevStudios/CMB2"
#. Author of the plugin/theme
msgid "WebDevStudios"
msgstr "WebDevStudios"
#: example-functions.php:82
msgid "Test Metabox"
msgstr "صندوق ميتا اختباري"
#: example-functions.php:93 example-functions.php:380
msgid "Test Text"
msgstr "نص اختباري"
#: example-functions.php:94 example-functions.php:106 example-functions.php:114
#: example-functions.php:122 example-functions.php:131
#: example-functions.php:139 example-functions.php:153
#: example-functions.php:160 example-functions.php:168
#: example-functions.php:185 example-functions.php:194
#: example-functions.php:202 example-functions.php:209
#: example-functions.php:216 example-functions.php:230
#: example-functions.php:243 example-functions.php:256
#: example-functions.php:268 example-functions.php:277
#: example-functions.php:285 example-functions.php:294
#: example-functions.php:301 example-functions.php:315
#: example-functions.php:381 example-functions.php:476
#: example-functions.php:484 example-functions.php:491
#: example-functions.php:498 example-functions.php:505
#: example-functions.php:512 example-functions.php:519
#: example-functions.php:557
msgid "field description (optional)"
msgstr "وصف الحقل (اختياري)"
#: example-functions.php:105
msgid "Test Text Small"
msgstr "نص اختباري صغير"
#: example-functions.php:113
msgid "Test Text Medium"
msgstr "نص اختباري متوسط"
#: example-functions.php:121
msgid "Website URL"
msgstr "رابط موقع"
#: example-functions.php:130
msgid "Test Text Email"
msgstr "نص بريد إلكتروني اختباري"
#: example-functions.php:138
msgid "Test Time"
msgstr "وقت اختباري"
#: example-functions.php:145 example-functions.php:146
msgid "Time zone"
msgstr "منطقة زمنية"
#: example-functions.php:152
msgid "Test Date Picker"
msgstr "مربع اختيار التاريخ اختباري"
#: example-functions.php:159
msgid "Test Date Picker (UNIX timestamp)"
msgstr "مربع اختيار التاريخ اختباري بنظام (UNIX timestamp)"
#: example-functions.php:167
msgid "Test Date/Time Picker Combo (UNIX timestamp)"
msgstr "مربع اختباري لاختيار الوقت و التاريخ معا بنظام (UNIX timestamp)"
#: example-functions.php:184
msgid "Test Money"
msgstr "حقل نقود اختباري"
#: example-functions.php:193
msgid "Test Color Picker"
msgstr "حقل اختيار اللون اختباري"
#: example-functions.php:201
msgid "Test Text Area"
msgstr "مربع نصي متعدد السطور اختباري"
#: example-functions.php:208
msgid "Test Text Area Small"
msgstr "مربع نصي متعدد السطور اختباري صغير"
#: example-functions.php:215
msgid "Test Text Area for Code"
msgstr "مربع نصي متعدد السطور اختباري خاص بالكود"
#: example-functions.php:222
msgid "Test Title Weeeee"
msgstr "عنوان اختباري"
#: example-functions.php:223
msgid "This is a title description"
msgstr "هذا هو وصف للعنوان"
#: example-functions.php:229
msgid "Test Select"
msgstr "اختيار من قائمة منسدلة اختباري"
#: example-functions.php:235 example-functions.php:248
#: example-functions.php:260
msgid "Option One"
msgstr "الخيار الأول"
#: example-functions.php:236 example-functions.php:249
#: example-functions.php:261
msgid "Option Two"
msgstr "الخيار الثاني"
#: example-functions.php:237 example-functions.php:250
#: example-functions.php:262
msgid "Option Three"
msgstr "الخيار الثالث"
#: example-functions.php:242
msgid "Test Radio inline"
msgstr "زر راديو اختاري مُضمن"
#: example-functions.php:255
msgid "Test Radio"
msgstr "زر راديو اختباري"

BIN
cmb2/languages/cmb2-as.mo Normal file

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More