Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request WebDevStudios#80 from GaryJones/code-standards
Props Gary!
- Loading branch information
Showing
1 changed file
with
116 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,191 +1,209 @@ | ||
<?php | ||
// Include & setup custom metabox and fields | ||
$prefix = '_cmb_'; // start with an underscore to hide fields from custom fields list | ||
/** | ||
* Include and setup custom metaboxes and fields. | ||
* | ||
* @category YourThemeOrPlugin | ||
* @package Metaboxes | ||
* @license http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later) | ||
* @link https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress | ||
*/ | ||
|
||
add_filter( 'cmb_meta_boxes', 'be_sample_metaboxes' ); | ||
function be_sample_metaboxes( $meta_boxes ) { | ||
global $prefix; | ||
/** | ||
* Define the metabox and field configurations. | ||
* | ||
* @param array $meta_boxes | ||
* @return array | ||
*/ | ||
function be_sample_metaboxes( array $meta_boxes ) { | ||
|
||
// Start with an underscore to hide fields from custom fields list | ||
$prefix = '_cmb_'; | ||
|
||
$meta_boxes[] = array( | ||
'id' => 'test_metabox', | ||
'title' => 'Test Metabox', | ||
'pages' => array( 'page' ), // post type | ||
'context' => 'normal', | ||
'priority' => 'high', | ||
'id' => 'test_metabox', | ||
'title' => 'Test Metabox', | ||
'pages' => array( 'page', ), // Post type | ||
'context' => 'normal', | ||
'priority' => 'high', | ||
'show_names' => true, // Show field names on the left | ||
'fields' => array( | ||
'fields' => array( | ||
array( | ||
'name' => 'Test Text', | ||
'desc' => 'field description (optional)', | ||
'id' => $prefix . 'test_text', | ||
'type' => 'text' | ||
'id' => $prefix . 'test_text', | ||
'type' => 'text', | ||
), | ||
array( | ||
'name' => 'Test Text Small', | ||
'desc' => 'field description (optional)', | ||
'id' => $prefix . 'test_textsmall', | ||
'type' => 'text_small' | ||
'id' => $prefix . 'test_textsmall', | ||
'type' => 'text_small', | ||
), | ||
array( | ||
'name' => 'Test Text Medium', | ||
'desc' => 'field description (optional)', | ||
'id' => $prefix . 'test_textmedium', | ||
'type' => 'text_medium' | ||
'id' => $prefix . 'test_textmedium', | ||
'type' => 'text_medium', | ||
), | ||
array( | ||
'name' => 'Test Date Picker', | ||
'desc' => 'field description (optional)', | ||
'id' => $prefix . 'test_textdate', | ||
'type' => 'text_date' | ||
'id' => $prefix . 'test_textdate', | ||
'type' => 'text_date', | ||
), | ||
array( | ||
'name' => 'Test Date Picker (UNIX timestamp)', | ||
'desc' => 'field description (optional)', | ||
'id' => $prefix . 'test_textdate_timestamp', | ||
'type' => 'text_date_timestamp' | ||
), | ||
'id' => $prefix . 'test_textdate_timestamp', | ||
'type' => 'text_date_timestamp', | ||
), | ||
array( | ||
'name' => 'Test Time', | ||
'desc' => 'field description (optional)', | ||
'id' => $prefix . 'test_time', | ||
'type' => 'text_time' | ||
), | ||
'id' => $prefix . 'test_time', | ||
'type' => 'text_time', | ||
), | ||
array( | ||
'name' => 'Test Money', | ||
'desc' => 'field description (optional)', | ||
'id' => $prefix . 'test_textmoney', | ||
'type' => 'text_money' | ||
'id' => $prefix . 'test_textmoney', | ||
'type' => 'text_money', | ||
), | ||
array( | ||
'name' => 'Test Text Area', | ||
'desc' => 'field description (optional)', | ||
'id' => $prefix . 'test_textarea', | ||
'type' => 'textarea' | ||
'id' => $prefix . 'test_textarea', | ||
'type' => 'textarea', | ||
), | ||
array( | ||
'name' => 'Test Text Area Small', | ||
'desc' => 'field description (optional)', | ||
'id' => $prefix . 'test_textareasmall', | ||
'type' => 'textarea_small' | ||
'id' => $prefix . 'test_textareasmall', | ||
'type' => 'textarea_small', | ||
), | ||
array( | ||
'name' => 'Test Text Area Code', | ||
'desc' => 'field description (optional)', | ||
'id' => $prefix . 'test_textarea_code', | ||
'type' => 'textarea_code' | ||
'id' => $prefix . 'test_textarea_code', | ||
'type' => 'textarea_code', | ||
), | ||
array( | ||
'name' => 'Test Title Weeeee', | ||
'desc' => 'This is a title description', | ||
'id' => $prefix . 'test_title', | ||
'type' => 'title', | ||
'id' => $prefix . 'test_title' | ||
), | ||
array( | ||
'name' => 'Test Select', | ||
'desc' => 'field description (optional)', | ||
'id' => $prefix . 'test_select', | ||
'type' => 'select', | ||
'name' => 'Test Select', | ||
'desc' => 'field description (optional)', | ||
'id' => $prefix . 'test_select', | ||
'type' => 'select', | ||
'options' => array( | ||
array('name' => 'Option One', 'value' => 'standard'), | ||
array('name' => 'Option Two', 'value' => 'custom'), | ||
array('name' => 'Option Three', 'value' => 'none') | ||
) | ||
array( 'name' => 'Option One', 'value' => 'standard', ), | ||
array( 'name' => 'Option Two', 'value' => 'custom', ), | ||
array( 'name' => 'Option Three', 'value' => 'none', ), | ||
), | ||
), | ||
array( | ||
'name' => 'Test Radio inline', | ||
'desc' => 'field description (optional)', | ||
'id' => $prefix . 'test_radio', | ||
'type' => 'radio_inline', | ||
'name' => 'Test Radio inline', | ||
'desc' => 'field description (optional)', | ||
'id' => $prefix . 'test_radio', | ||
'type' => 'radio_inline', | ||
'options' => array( | ||
array('name' => 'Option One', 'value' => 'standard'), | ||
array('name' => 'Option Two', 'value' => 'custom'), | ||
array('name' => 'Option Three', 'value' => 'none') | ||
) | ||
array( 'name' => 'Option One', 'value' => 'standard', ), | ||
array( 'name' => 'Option Two', 'value' => 'custom', ), | ||
array( 'name' => 'Option Three', 'value' => 'none', ), | ||
), | ||
), | ||
array( | ||
'name' => 'Test Radio', | ||
'desc' => 'field description (optional)', | ||
'id' => $prefix . 'test_radio', | ||
'type' => 'radio', | ||
'name' => 'Test Radio', | ||
'desc' => 'field description (optional)', | ||
'id' => $prefix . 'test_radio', | ||
'type' => 'radio', | ||
'options' => array( | ||
array('name' => 'Option One', 'value' => 'standard'), | ||
array('name' => 'Option Two', 'value' => 'custom'), | ||
array('name' => 'Option Three', 'value' => 'none') | ||
) | ||
array( 'name' => 'Option One', 'value' => 'standard', ), | ||
array( 'name' => 'Option Two', 'value' => 'custom', ), | ||
array( 'name' => 'Option Three', 'value' => 'none', ), | ||
), | ||
), | ||
array( | ||
'name' => 'Test Taxonomy Radio', | ||
'desc' => 'Description Goes Here', | ||
'id' => $prefix . 'text_taxonomy_radio', | ||
'taxonomy' => '', //Enter Taxonomy Slug | ||
'type' => 'taxonomy_radio', | ||
'name' => 'Test Taxonomy Radio', | ||
'desc' => 'Description Goes Here', | ||
'id' => $prefix . 'text_taxonomy_radio', | ||
'type' => 'taxonomy_radio', | ||
'taxonomy' => '', // Taxonomy Slug | ||
), | ||
array( | ||
'name' => 'Test Taxonomy Select', | ||
'desc' => 'Description Goes Here', | ||
'id' => $prefix . 'text_taxonomy_select', | ||
'taxonomy' => '', //Enter Taxonomy Slug | ||
'type' => 'taxonomy_select', | ||
'name' => 'Test Taxonomy Select', | ||
'desc' => 'Description Goes Here', | ||
'id' => $prefix . 'text_taxonomy_select', | ||
'type' => 'taxonomy_select', | ||
'taxonomy' => '', // Taxonomy Slug | ||
), | ||
array( | ||
'name' => 'Test Checkbox', | ||
'desc' => 'field description (optional)', | ||
'id' => $prefix . 'test_checkbox', | ||
'type' => 'checkbox' | ||
'id' => $prefix . 'test_checkbox', | ||
'type' => 'checkbox', | ||
), | ||
array( | ||
'name' => 'Test Multi Checkbox', | ||
'desc' => 'field description (optional)', | ||
'id' => $prefix . 'test_multicheckbox', | ||
'type' => 'multicheck', | ||
'name' => 'Test Multi Checkbox', | ||
'desc' => 'field description (optional)', | ||
'id' => $prefix . 'test_multicheckbox', | ||
'type' => 'multicheck', | ||
'options' => array( | ||
'check1' => 'Check One', | ||
'check2' => 'Check Two', | ||
'check3' => 'Check Three', | ||
) | ||
), | ||
), | ||
array( | ||
'name' => 'Test wysiwyg', | ||
'desc' => 'field description (optional)', | ||
'id' => $prefix . 'test_wysiwyg', | ||
'type' => 'wysiwyg', | ||
'options' => array( | ||
'textarea_rows' => 5, | ||
) | ||
'name' => 'Test wysiwyg', | ||
'desc' => 'field description (optional)', | ||
'id' => $prefix . 'test_wysiwyg', | ||
'type' => 'wysiwyg', | ||
'options' => array( 'textarea_rows' => 5, ), | ||
), | ||
array( | ||
'name' => 'Test Image', | ||
'desc' => 'Upload an image or enter an URL.', | ||
'id' => $prefix . 'test_image', | ||
'type' => 'file' | ||
'id' => $prefix . 'test_image', | ||
'type' => 'file', | ||
), | ||
) | ||
), | ||
); | ||
|
||
$meta_boxes[] = array( | ||
'id' => 'about_page_metabox', | ||
'title' => 'About Page Metabox', | ||
'pages' => array( 'page' ), // post type | ||
'show_on' => array( 'key' => 'id', 'value' => array( 2 ) ), // specific post ids to display this metabox | ||
'context' => 'normal', | ||
'priority' => 'high', | ||
'id' => 'about_page_metabox', | ||
'title' => 'About Page Metabox', | ||
'pages' => array( 'page', ), // Post type | ||
'context' => 'normal', | ||
'priority' => 'high', | ||
'show_names' => true, // Show field names on the left | ||
'show_on' => array( 'key' => 'id', 'value' => array( 2, ), ), // Specific post IDs to display this metabox | ||
'fields' => array( | ||
array( | ||
'name' => 'Test Text', | ||
'desc' => 'field description (optional)', | ||
'id' => $prefix . 'test_text', | ||
'type' => 'text' | ||
'id' => $prefix . 'test_text', | ||
'type' => 'text', | ||
), | ||
) | ||
); | ||
|
||
|
||
// Add other metaboxes as needed | ||
|
||
return $meta_boxes; | ||
} | ||
|
||
|
||
// Initialize the metabox class | ||
add_action( 'init', 'be_initialize_cmb_meta_boxes', 9999 ); | ||
/** | ||
* Initialize the metabox class. | ||
*/ | ||
function be_initialize_cmb_meta_boxes() { | ||
if ( !class_exists( 'cmb_Meta_Box' ) ) { | ||
require_once( 'init.php' ); | ||
} | ||
|
||
if ( ! class_exists( 'cmb_Meta_Box' ) ) | ||
require_once 'init.php'; | ||
|
||
} |