',
+ esc_attr( $id ),
+ esc_attr( $name ),
+ esc_attr( $field_id )
+ );
- if ( $this->is_placeholder() ) {
+ if ( $this->is_placeholder() ) {
// For placeholder, output the markup for the editor in a JS var.
ob_start();
$this->args['options']['textarea_name'] = 'cmb-placeholder-name-' . $field_id;
wp_editor( '', 'cmb-placeholder-id-' . $field_id, $this->args['options'] );
$editor = ob_get_clean();
- $editor = str_replace( array( "\n", "\r" ), "", $editor );
+ $editor = str_replace( array( "\n", "\r" ), '', $editor );
$editor = str_replace( array( "'" ), '"', $editor );
?>
@@ -975,7 +1019,7 @@ public function html() {
parent ) && ! is_int( $this->parent->field_index ) )
+ if ( isset( $this->parent ) && ! is_int( $this->parent->field_index ) ) {
return true;
-
- else return ! is_int( $this->field_index );
+ } else {
+ return ! is_int( $this->field_index );
+ }
}
-
}
/**
@@ -1044,17 +1088,19 @@ public function get_default_args() {
);
}
- public function parse_save_values(){
+ public function parse_save_values() {
- if ( isset( $this->parent ) && isset( $this->args['multiple'] ) && $this->args['multiple'] )
+ if ( isset( $this->parent ) && isset( $this->args['multiple'] ) && $this->args['multiple'] ) {
$this->values = array( $this->values );
+ }
}
public function get_options() {
- if ( $this->has_data_delegate() )
+ if ( $this->has_data_delegate() ) {
$this->args['options'] = $this->get_delegate_data();
+ }
return $this->args['options'];
}
@@ -1076,8 +1122,9 @@ public function enqueue_styles() {
public function html() {
- if ( $this->has_data_delegate() )
+ if ( $this->has_data_delegate() ) {
$this->args['options'] = $this->get_delegate_data();
+ }
$this->output_field();
@@ -1107,10 +1154,10 @@ public function output_field() {
>
args['allow_none'] ) : ?>
-
- args['options'] as $value => $name ): ?>
+ args['options'] as $value => $name ) : ?>
@@ -1146,7 +1193,6 @@ public function output_script() {
term_id] = $term->name;
+ foreach ( $terms as $term ) {
+ $term_options[ $term->term_id ] = $term->name;
+ }
return $term_options;
@@ -1199,7 +1246,6 @@ private function get_terms() {
return get_terms( $this->args['taxonomy'], array( 'hide_empty' => $this->args['hide_empty'] ) );
}
-
}
/**
@@ -1225,7 +1271,7 @@ public function __construct() {
}
- }
+ }
/**
* Return the default args for the Post select field.
@@ -1247,8 +1293,9 @@ public function get_delegate_data() {
$data = array();
- foreach ( $this->get_posts() as $post_id )
- $data[$post_id] = get_the_title( $post_id );
+ foreach ( $this->get_posts() as $post_id ) {
+ $data[ $post_id ] = get_the_title( $post_id );
+ }
return $data;
@@ -1310,8 +1357,9 @@ public function output_script() {
(function($) {
- if ( 'undefined' === typeof( window.cmb_select_fields ) )
+ if ( 'undefined' === typeof( window.cmb_select_fields ) ) {
return false;
+ }
// Get options for this field so we can modify it.
var id = get_js_id() ); ?>;
@@ -1381,13 +1429,12 @@ public function output_script() {
-
+
html(); ?>
@@ -1514,7 +1561,6 @@ public function display() {
$i++;
}
-
}
if ( $this->args['repeatable'] ) {
@@ -1550,9 +1596,9 @@ public function html() {
if ( ! empty( $value ) ) {
foreach ( $value as $field_id => $field_value ) {
$field_value = ( ! empty( $field_value ) ) ? $field_value : array();
- if ( ! empty( $fields[$field_id] ) ) {
- $fields[$field_id]->set_values( (array) $field_value );
- }
+ if ( ! empty( $fields[ $field_id ] ) ) {
+ $fields[ $field_id ]->set_values( (array) $field_value );
+ }
}
}
@@ -1577,12 +1623,12 @@ public function parse_save_values() {
foreach ( $values as &$group_value ) {
foreach ( $group_value as $field_id => &$field_value ) {
- if ( ! isset( $fields[$field_id] ) ) {
+ if ( ! isset( $fields[ $field_id ] ) ) {
$field_value = array();
continue;
}
- $field = $fields[$field_id];
+ $field = $fields[ $field_id ];
$field->set_values( $field_value );
$field->parse_save_values();
@@ -1590,8 +1636,9 @@ public function parse_save_values() {
// if the field is a repeatable field, store the whole array of them, if it's not repeatble,
// just store the first (and only) one directly
- if ( ! $field->args['repeatable'] )
+ if ( ! $field->args['repeatable'] ) {
$field_value = reset( $field_value );
+ }
}
}
@@ -1599,7 +1646,7 @@ public function parse_save_values() {
public function add_field( CMB_Field $field ) {
$field->parent = $this;
- $this->fields[$field->id] = $field;
+ $this->fields[ $field->id ] = $field;
}
public function &get_fields() {
@@ -1618,12 +1665,11 @@ public function set_values( array $values ) {
foreach ( $values as $value ) {
foreach ( $value as $field_id => $field_value ) {
- $fields[$field_id]->set_values( (array) $field_value );
+ $fields[ $field_id ]->set_values( (array) $field_value );
}
}
}
-
}
@@ -1666,7 +1712,7 @@ public function enqueue_scripts() {
// Check for our key with either a field argument or constant.
$key = '';
- if ( ! empty( $this->args['google_api_key'] ) ){
+ if ( ! empty( $this->args['google_api_key'] ) ) {
$key = $this->args['google_api_key'];
} elseif ( defined( 'CMB_GAPI_KEY' ) ) {
$key = CMB_GAPI_KEY;
@@ -1682,7 +1728,7 @@ public function enqueue_scripts() {
'strings' => array(
'markerTitle' => $this->args['string-marker-title'],
'googleMapsApiNotLoaded' => $this->args['string-gmaps-api-not-loaded'],
- )
+ ),
) );
}
@@ -1696,7 +1742,7 @@ public function html() {
'lat' => null,
'long' => null,
'elevation' => null,
- 'text' => null
+ 'text' => null,
)
);
@@ -1704,7 +1750,7 @@ public function html() {
sprintf( 'width: %s;', $this->args['field_width'] ),
sprintf( 'height: %s;', $this->args['field_height'] ),
'border: 1px solid #eee;',
- 'margin-top: 8px;'
+ 'margin-top: 8px;',
);
?>
diff --git a/custom-meta-boxes.php b/custom-meta-boxes.php
index 3ab68063..abc0e6ac 100755
--- a/custom-meta-boxes.php
+++ b/custom-meta-boxes.php
@@ -22,14 +22,17 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-if ( ! defined( 'CMB_DEV') )
+if ( ! defined( 'CMB_DEV' ) ) {
define( 'CMB_DEV', false );
+}
-if ( ! defined( 'CMB_PATH') )
+if ( ! defined( 'CMB_PATH' ) ) {
define( 'CMB_PATH', plugin_dir_path( __FILE__ ) );
+}
-if ( ! defined( 'CMB_URL' ) )
+if ( ! defined( 'CMB_URL' ) ) {
define( 'CMB_URL', plugins_url( '', __FILE__ ) );
+}
include_once( CMB_PATH . '/classes.fields.php' );
include_once( CMB_PATH . '/class.cmb-meta-box.php' );
@@ -37,8 +40,6 @@
// Make it possible to add fields in locations other than post edit screen.
include_once( CMB_PATH . '/fields-anywhere.php' );
-// include_once( CMB_PATH . '/example-functions.php' );
-
/**
* Get all the meta boxes on init
*
@@ -46,8 +47,9 @@
*/
function cmb_init() {
- if ( ! is_admin() )
+ if ( ! is_admin() ) {
return;
+ }
// Load translations
$textdomain = 'cmb';
@@ -59,9 +61,11 @@ function cmb_init() {
$meta_boxes = apply_filters( 'cmb_meta_boxes', array() );
- if ( ! empty( $meta_boxes ) )
- foreach ( $meta_boxes as $meta_box )
+ if ( ! empty( $meta_boxes ) ) {
+ foreach ( $meta_boxes as $meta_box ) {
new CMB_Meta_Box( $meta_box );
+ }
+ }
}
add_action( 'init', 'cmb_init', 50 );
@@ -99,7 +103,7 @@ function _cmb_available_fields() {
'title' => 'CMB_Title',
'group' => 'CMB_Group_Field',
'gmap' => 'CMB_Gmap_Field',
- 'number' => 'CMB_Number_Field'
+ 'number' => 'CMB_Number_Field',
) );
}
@@ -114,8 +118,9 @@ function _cmb_field_class_for_type( $type ) {
$map = _cmb_available_fields();
- if ( isset( $map[$type] ) )
- return $map[$type];
+ if ( isset( $map[ $type ] ) ) {
+ return $map[ $type ];
+ }
return false;
@@ -131,30 +136,31 @@ function _cmb_field_class_for_type( $type ) {
* @param string $query
* @return string $query
*/
-function cmb_fix_meta_query_order($query) {
+function cmb_fix_meta_query_order( $query ) {
- $pattern = '/^SELECT (post_id|user_id), meta_key, meta_value FROM \w* WHERE post_id IN \([\d|,]*\)$/';
+ $pattern = '/^SELECT (post_id|user_id), meta_key, meta_value FROM \w* WHERE post_id IN \([\d|,]*\)$/';
- if (
- 0 === strpos( $query, "SELECT post_id, meta_key, meta_value" ) &&
- preg_match( $pattern, $query, $matches )
- ) {
+ if (
+ 0 === strpos( $query, 'SELECT post_id, meta_key, meta_value' ) &&
+ preg_match( $pattern, $query, $matches )
+ ) {
+ if ( isset( $matches[1] ) && 'user_id' == $matches[1] ) {
+ $meta_id_column = 'umeta_id';
+ } else {
+ $meta_id_column = 'meta_id';
+ }
- if ( isset( $matches[1] ) && 'user_id' == $matches[1] )
- $meta_id_column = 'umeta_id';
- else
- $meta_id_column = 'meta_id';
+ $meta_query_orderby = ' ORDER BY ' . $meta_id_column;
- $meta_query_orderby = ' ORDER BY ' . $meta_id_column;
+ if ( false === strpos( $query, $meta_query_orderby ) ) {
+ $query .= $meta_query_orderby;
+ }
+ }
- if ( false === strpos( $query, $meta_query_orderby ) )
- $query .= $meta_query_orderby;
-
- }
-
- return $query;
+ return $query;
}
-if ( version_compare( get_bloginfo( 'version' ), '3.8', '<' ) )
- add_filter( 'query', 'cmb_fix_meta_query_order', 1 );
\ No newline at end of file
+if ( version_compare( get_bloginfo( 'version' ), '3.8', '<' ) ) {
+ add_filter( 'query', 'cmb_fix_meta_query_order', 1 );
+}
diff --git a/example-functions.php b/example-functions.php
index 176b37d2..4ffab4ca 100644
--- a/example-functions.php
+++ b/example-functions.php
@@ -13,7 +13,7 @@ function cmb_sample_metaboxes( array $meta_boxes ) {
array( 'id' => 'field-1', 'name' => 'Text input field', 'type' => 'text' ),
array( 'id' => 'field-2', 'name' => 'Read-only text input field', 'type' => 'text', 'readonly' => true, 'default' => 'READ ONLY' ),
- array( 'id' => 'field-3', 'name' => 'Repeatable text input field', 'type' => 'text', 'desc' => 'Add up to 5 fields.', 'repeatable' => true, 'repeatable_max' => 5, 'sortable' => true ),
+ array( 'id' => 'field-3', 'name' => 'Repeatable text input field', 'type' => 'text', 'desc' => 'Add up to 5 fields.', 'repeatable' => true, 'repeatable_max' => 5, 'sortable' => true ),
array( 'id' => 'field-4', 'name' => 'Small text input field', 'type' => 'text_small' ),
array( 'id' => 'field-5', 'name' => 'URL field', 'type' => 'url' ),
@@ -35,7 +35,7 @@ function cmb_sample_metaboxes( array $meta_boxes ) {
array( 'id' => 'field-15b', 'name' => 'Select taxonomy field', 'type' => 'taxonomy_select', 'taxonomy' => 'category', 'multiple' => true ),
array( 'id' => 'field-16', 'name' => 'Post select field', 'type' => 'post_select', 'use_ajax' => false, 'query' => array( 'cat' => 1 ) ),
array( 'id' => 'field-17', 'name' => 'Post select field (AJAX)', 'type' => 'post_select', 'use_ajax' => true ),
- array( 'id' => 'field-17b', 'name' => 'Post select field (AJAX)', 'type' => 'post_select', 'use_ajax' => true, 'query' => array( 'posts_per_page' => 8 ), 'multiple' => true ),
+ array( 'id' => 'field-17b', 'name' => 'Post select field (AJAX)', 'type' => 'post_select', 'use_ajax' => true, 'query' => array( 'posts_per_page' => 8 ), 'multiple' => true ),
array( 'id' => 'field-18', 'name' => 'Date input field', 'type' => 'date' ),
array( 'id' => 'field-19', 'name' => 'Time input field', 'type' => 'time' ),
@@ -53,7 +53,7 @@ function cmb_sample_metaboxes( array $meta_boxes ) {
$meta_boxes[] = array(
'title' => 'CMB Test - all fields',
'pages' => 'post',
- 'fields' => $fields
+ 'fields' => $fields,
);
// Examples of Groups and Columns
@@ -62,19 +62,31 @@ function cmb_sample_metaboxes( array $meta_boxes ) {
array( 'id' => 'gac-1', 'name' => 'Text input field', 'type' => 'text', 'cols' => 4 ),
array( 'id' => 'gac-2', 'name' => 'Text input field', 'type' => 'text', 'cols' => 4 ),
array( 'id' => 'gac-3', 'name' => 'Text input field', 'type' => 'text', 'cols' => 4 ),
- array( 'id' => 'gac-4', 'name' => 'Group (4 columns)', 'type' => 'group', 'cols' => 4, 'fields' => array(
- array( 'id' => 'gac-4-f-1', 'name' => 'Textarea field', 'type' => 'textarea' )
- ) ),
- array( 'id' => 'gac-5', 'name' => 'Group (8 columns)', 'type' => 'group', 'cols' => 8, 'fields' => array(
- array( 'id' => 'gac-4-f-1', 'name' => 'Text input field', 'type' => 'text' ),
- array( 'id' => 'gac-4-f-2', 'name' => 'Text input field', 'type' => 'text' ),
- ) ),
+ array(
+ 'id' => 'gac-4',
+ 'name' => 'Group (4 columns)',
+ 'type' => 'group',
+ 'cols' => 4,
+ 'fields' => array(
+ array( 'id' => 'gac-4-f-1', 'name' => 'Textarea field', 'type' => 'textarea' ),
+ ),
+ ),
+ array(
+ 'id' => 'gac-5',
+ 'name' => 'Group (8 columns)',
+ 'type' => 'group',
+ 'cols' => 8,
+ 'fields' => array(
+ array( 'id' => 'gac-4-f-1', 'name' => 'Text input field', 'type' => 'text' ),
+ array( 'id' => 'gac-4-f-2', 'name' => 'Text input field', 'type' => 'text' ),
+ ),
+ ),
);
$meta_boxes[] = array(
'title' => 'Groups and Columns',
'pages' => 'post',
- 'fields' => $groups_and_cols
+ 'fields' => $groups_and_cols,
);
// Example of repeatable group. Using all fields.
@@ -95,9 +107,9 @@ function cmb_sample_metaboxes( array $meta_boxes ) {
'repeatable' => true,
'sortable' => true,
'fields' => $group_fields,
- 'desc' => 'This is the group description.'
- )
- )
+ 'desc' => 'This is the group description.',
+ ),
+ ),
);
return $meta_boxes;
diff --git a/fields-anywhere.php b/fields-anywhere.php
index 08bb2c87..4cacf145 100644
--- a/fields-anywhere.php
+++ b/fields-anywhere.php
@@ -1,5 +1,4 @@
-id;
@@ -50,29 +49,35 @@ function cmb_do_meta_boxes( $screen, $context, $object ) {
do {
// Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose
- if ( ! $already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) )
- foreach ( $sorted as $box_context => $ids )
- foreach ( explode(',', $ids ) as $id )
- if ( $id && 'dashboard_browser_nag' !== $id )
+ if ( ! $already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) {
+ foreach ( $sorted as $box_context => $ids ) {
+ foreach ( explode( ',', $ids ) as $id ) {
+ if ( $id && 'dashboard_browser_nag' !== $id ) {
add_meta_box( $id, null, null, $screen, $box_context, 'sorted' );
+ }
+ }
+ }
+ }
$already_sorted = true;
- if ( ! isset( $wp_meta_boxes ) || ! isset( $wp_meta_boxes[$page] ) || ! isset( $wp_meta_boxes[$page][$context] ) )
+ if ( ! isset( $wp_meta_boxes ) || ! isset( $wp_meta_boxes[ $page ] ) || ! isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
break;
+ }
foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) {
- if ( isset( $wp_meta_boxes[$page][$context][$priority] ) ) {
+ if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
- foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) {
+ foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
- if ( false == $box || ! $box['title'] )
+ if ( false == $box || ! $box['title'] ) {
continue;
+ }
$i++;
- $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : ''; ?>
+ $hidden_class = in_array( $box['id'], $hidden ) ? ' hide-if-js' : ''; ?>
@@ -80,13 +85,12 @@ function cmb_do_meta_boxes( $screen, $context, $object ) {
- .field-item > .cmb-delete-field, > .field-item > .group > .cmb-delete-field' ).show();
- if ( typeof( max ) === 'undefined' )
+ if ( typeof( max ) === 'undefined' ) {
return false;
+ }
// Disable the add new field button?
- if ( count >= parseInt( max, 10 ) )
+ if ( count >= parseInt( max, 10 ) ) {
addBtn.attr( 'disabled', 'disabled' );
- else
+ } else {
addBtn.removeAttr( 'disabled' );
+ }
- if ( count > parseInt( max, 10 ) )
+ if ( count > parseInt( max, 10 ) ) {
return true;
+ }
},
@@ -174,9 +179,11 @@ var CMB = {
addCallbackForClonedField: function( fieldName, callback ) {
- if ( jQuery.isArray( fieldName ) )
- for ( var i = 0; i < fieldName.length; i++ )
+ if ( jQuery.isArray( fieldName ) ) {
+ for ( var i = 0; i < fieldName.length; i++ ) {
CMB.addCallbackForClonedField( fieldName[i], callback );
+ }
+ }
this._clonedFieldCallbacks[fieldName] = this._clonedFieldCallbacks[fieldName] ? this._clonedFieldCallbacks[fieldName] : []
this._clonedFieldCallbacks[fieldName].push( callback )
@@ -192,21 +199,25 @@ var CMB = {
// also check child elements
el.add( el.find( 'div[data-class]' ) ).each( function( i, el ) {
- el = jQuery( el )
- var callbacks = CMB._clonedFieldCallbacks[el.attr( 'data-class') ]
+ el = jQuery( el );
+ var callbacks = CMB._clonedFieldCallbacks[ el.attr( 'data-class' ) ];
- if ( callbacks )
- for ( var a = 0; a < callbacks.length; a++ )
+ if ( callbacks ) {
+ for ( var a = 0; a < callbacks.length; a++ ) {
callbacks[a]( el );
+ }
+ }
})
},
addCallbackForDeletedField: function( fieldName, callback ) {
- if ( jQuery.isArray( fieldName ) )
- for ( var i = 0; i < fieldName.length; i++ )
+ if ( jQuery.isArray( fieldName ) ) {
+ for ( var i = 0; i < fieldName.length; i++ ) {
CMB._deletedFieldCallbacks( fieldName[i], callback );
+ }
+ }
this._deletedFieldCallbacks[fieldName] = this._deletedFieldCallbacks[fieldName] ? this._deletedFieldCallbacks[fieldName] : []
this._deletedFieldCallbacks[fieldName].push( callback )
@@ -220,26 +231,28 @@ var CMB = {
deletedField: function( el ) {
// also check child elements
- el.add( el.find( 'div[data-class]' ) ).each( function(i, el) {
+ el.add( el.find( 'div[data-class]' ) ).each( function( i, el ) {
- el = jQuery( el )
- var callbacks = CMB._deletedFieldCallbacks[el.attr( 'data-class') ]
+ el = jQuery( el );
+ var callbacks = CMB._deletedFieldCallbacks[ el.attr( 'data-class' ) ];
- if ( callbacks )
- for ( var a = 0; a < callbacks.length; a++ )
+ if ( callbacks ) {
+ for ( var a = 0; a < callbacks.length; a++ ) {
callbacks[a]( el )
+ }
+ }
})
},
sortableInit : function( field ) {
- var items = field.find(' > .field-item').not('.hidden');
+ var items = field.find( ' > .field-item' ).not( '.hidden' );
field.find( '> .field-item > .cmb-handle' ).remove();
items.each( function() {
- jQuery(this).append( '
' );
+ jQuery( this ).append( '
' );
} );
field.sortable( {
@@ -255,24 +268,28 @@ var CMB = {
sortStart : function ( el ) {
// also check child elements
- el.add( el.find( 'div[data-class]' ) ).each( function(i, el) {
+ el.add( el.find( 'div[data-class]' ) ).each( function( i, el ) {
- el = jQuery( el )
- var callbacks = CMB._sortStartCallbacks[el.attr( 'data-class') ]
+ el = jQuery( el );
+ var callbacks = CMB._sortStartCallbacks[ el.attr( 'data-class' ) ];
- if ( callbacks )
- for ( var a = 0; a < callbacks.length; a++ )
- callbacks[a]( el )
+ if ( callbacks ) {
+ for ( var a = 0; a < callbacks.length; a++ ) {
+ callbacks[a]( el );
+ }
+ }
- })
+ });
},
addCallbackForSortStart: function( fieldName, callback ) {
- if ( jQuery.isArray( fieldName ) )
- for ( var i = 0; i < fieldName.length; i++ )
+ if ( jQuery.isArray( fieldName ) ) {
+ for ( var i = 0; i < fieldName.length; i++ ) {
CMB.addCallbackForSortStart( fieldName[i], callback );
+ }
+ }
this._sortStartCallbacks[fieldName] = this._sortStartCallbacks[fieldName] ? this._sortStartCallbacks[fieldName] : []
this._sortStartCallbacks[fieldName].push( callback )
@@ -284,12 +301,14 @@ var CMB = {
// also check child elements
el.add( el.find( 'div[data-class]' ) ).each( function(i, el) {
- el = jQuery( el )
- var callbacks = CMB._sortEndCallbacks[el.attr( 'data-class') ]
+ el = jQuery( el );
+ var callbacks = CMB._sortEndCallbacks[ el.attr( 'data-class' ) ];
- if ( callbacks )
- for ( var a = 0; a < callbacks.length; a++ )
- callbacks[a]( el )
+ if ( callbacks ) {
+ for ( var a = 0; a < callbacks.length; a++ ) {
+ callbacks[a]( el );
+ }
+ }
})
@@ -297,18 +316,20 @@ var CMB = {
addCallbackForSortEnd: function( fieldName, callback ) {
- if ( jQuery.isArray( fieldName ) )
- for ( var i = 0; i < fieldName.length; i++ )
+ if ( jQuery.isArray( fieldName ) ) {
+ for ( var i = 0; i < fieldName.length; i++ ) {
CMB.addCallbackForSortEnd( fieldName[i], callback );
+ }
+ }
- this._sortEndCallbacks[fieldName] = this._sortEndCallbacks[fieldName] ? this._sortEndCallbacks[fieldName] : []
- this._sortEndCallbacks[fieldName].push( callback )
+ this._sortEndCallbacks[fieldName] = this._sortEndCallbacks[fieldName] ? this._sortEndCallbacks[fieldName] : [];
+ this._sortEndCallbacks[fieldName].push( callback );
}
-}
+};
-jQuery(document).ready( function() {
+jQuery( document ).ready( function() {
CMB.init();
diff --git a/js/field-gmap.js b/js/field-gmap.js
index e4927336..30e8dade 100644
--- a/js/field-gmap.js
+++ b/js/field-gmap.js
@@ -5,16 +5,16 @@
var CMBGmapsInit = function( fieldEl ) {
- var mapCanvas = $( '.map', fieldEl ).get(0);
+ var mapCanvas = $( '.map', fieldEl ).get( 0 );
if ( 'undefined' === typeof google ) {
$( '
' + CMBGmaps.strings.googleMapsApiNotLoaded + '
' )
- .css({ 'padding': '1em', 'textAlign': 'center', 'width': '100%' })
+ .css( { 'padding': '1em', 'textAlign': 'center', 'width': '100%' } )
.appendTo( mapCanvas );
return;
}
- var searchInput = $( '.map-search', fieldEl ).get(0);
+ var searchInput = $( '.map-search', fieldEl ).get( 0 );
var latitude = $( '.latitude', fieldEl );
var longitude = $( '.longitude', fieldEl );
var elevation = $( '.elevation', fieldEl );
@@ -69,21 +69,21 @@
});
// Search
- var autocomplete = new google.maps.places.Autocomplete(searchInput);
- autocomplete.bindTo('bounds', map);
+ var autocomplete = new google.maps.places.Autocomplete( searchInput );
+ autocomplete.bindTo( 'bounds', map );
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
- if (place.geometry.viewport) {
- map.fitBounds(place.geometry.viewport);
+ if ( place.geometry.viewport ) {
+ map.fitBounds( place.geometry.viewport );
}
setPosition( place.geometry.location, 17 );
});
- $(searchInput).keypress(function(e) {
- if (e.keyCode === 13) {
+ $( searchInput ).keypress(function(e) {
+ if ( e.keyCode === 13 ) {
e.preventDefault();
}
});
@@ -102,5 +102,4 @@
$.getScript( '//maps.google.com/maps/api/js?sensor=true&libraries=places&callback=CMB_CMAPS_INIT&key=' + CMBGmaps.key );
-
}(jQuery));
diff --git a/js/field-wysiwyg.js b/js/field-wysiwyg.js
index 1d5c4252..b7640210 100644
--- a/js/field-wysiwyg.js
+++ b/js/field-wysiwyg.js
@@ -2,27 +2,29 @@ CMB.addCallbackForDeletedField( 'CMB_wysiwyg', function( el ) {
// Destroy WYSIWYG editors instances.
el.find( '.cmb-wysiwyg textarea' ).each( function() {
- var instance = tinyMCE.get( jQuery(this).attr('id') );
- if ( instance !== null && typeof( instance ) !== 'undefined' )
+ var instance = tinyMCE.get( jQuery( this ).attr( 'id' ) );
+ if ( instance !== null && typeof( instance ) !== 'undefined' ) {
instance.remove();
+ }
} );
} );
CMB.addCallbackForClonedField( 'CMB_wysiwyg', function( newT ) {
- newT.find( '.cmb-wysiwyg' ).each( function (i) {
+ newT.find( '.cmb-wysiwyg' ).each( function ( i ) {
var el, id, name, ed, dom, i, fieldId, nameRegex, idRegex;
- el = jQuery(this);
+ el = jQuery( this );
id = el.attr( 'data-id' );
name = el.attr( 'data-name' );
- ed = tinyMCE.get(id);
- fieldId = el.attr('data-field-id'); //Field identifier, not including field/group index.,
+ ed = tinyMCE.get( id );
+ fieldId = el.attr( 'data-field-id' ); //Field identifier, not including field/group index.,
- if ( ed )
+ if ( ed ) {
return;
+ }
nameRegex = new RegExp( 'cmb-placeholder-name-' + fieldId, 'g' );
idRegex = new RegExp( 'cmb-placeholder-id-' + fieldId, 'g' );
@@ -34,36 +36,42 @@ CMB.addCallbackForClonedField( 'CMB_wysiwyg', function( newT ) {
// If no settings for this field. Clone from placeholder.
if ( typeof( tinyMCEPreInit.mceInit[ id ] ) === 'undefined' ) {
var newSettings = jQuery.extend( {}, tinyMCEPreInit.mceInit[ 'cmb-placeholder-id-' + fieldId ] );
- for ( var prop in newSettings )
- if ( 'string' === typeof( newSettings[prop] ) )
- newSettings[prop] = newSettings[prop].replace( idRegex, id ).replace( nameRegex, name );
+ for ( var prop in newSettings ) {
+ if ( 'string' === typeof( newSettings[ prop ] ) ) {
+ newSettings[ prop ] = newSettings[ prop ].replace( idRegex, id ).replace( nameRegex, name );
+ }
+ }
tinyMCEPreInit.mceInit[ id ] = newSettings;
}
// If no Quicktag settings for this field. Clone from placeholder.
if ( typeof( tinyMCEPreInit.qtInit[ id ] ) === 'undefined' ) {
var newQTS = jQuery.extend( {}, tinyMCEPreInit.qtInit[ 'cmb-placeholder-id-' + fieldId ] );
- for ( var prop in newQTS )
- if ( 'string' === typeof( newQTS[prop] ) )
- newQTS[prop] = newQTS[prop].replace( idRegex, id ).replace( nameRegex, name );
+ for ( var prop in newQTS ) {
+ if ( 'string' === typeof( newQTS[ prop ] ) ) {
+ newQTS[ prop ] = newQTS[ prop ].replace( idRegex, id ).replace( nameRegex, name );
+ }
+ }
tinyMCEPreInit.qtInit[ id ] = newQTS;
}
- var mode = el.find('.wp-editor-wrap').hasClass('tmce-active') ? 'tmce' : 'html';
+ var mode = el.find( '.wp-editor-wrap' ).hasClass( 'tmce-active' ) ? 'tmce' : 'html';
// If current mode is visual, create the tinyMCE.
if ( 'tmce' === mode ) {
if ( tinyMCE.majorVersion === '4' ) {
var ed = tinymce.init( tinyMCEPreInit.mceInit[id] );
} else if ( tinyMCE.majorVersion === '3' ) {
- var ed = new tinymce.Editor( id, tinyMCEPreInit.mceInit[id] );
+ var ed = new tinymce.Editor( id, tinyMCEPreInit.mceInit[id] );
+ }
ed.render();
}
- }
// Init Quicktags.
QTags.instances[0] = undefined;
- try { quicktags( tinyMCEPreInit.qtInit[id] ); } catch(e){}
+ try {
+ quicktags( tinyMCEPreInit.qtInit[ id ] );
+ } catch ( e ) {}
} );
@@ -73,15 +81,14 @@ CMB.addCallbackForClonedField( 'CMB_wysiwyg', function( newT ) {
CMB.addCallbackForSortStart( 'CMB_wysiwyg', function( el ) {
el.find( '.wp-editor-area' ).each(function(){
- var id = jQuery(this).attr('id');
+ var id = jQuery( this ).attr( 'id' );
if ( tinyMCE.majorVersion === '4' ) {
- tinyMCE.execCommand('mceRemoveEditor', false, id);
+ tinyMCE.execCommand( 'mceRemoveEditor', false, id );
} else if ( tinyMCE.majorVersion === '3' ) {
- tinyMCE.execCommand('mceRemoveControl', false, id);
+ tinyMCE.execCommand( 'mceRemoveControl', false, id );
}
-
});
} );
@@ -90,14 +97,14 @@ CMB.addCallbackForSortEnd( 'CMB_wysiwyg', function( el ) {
el.find( '.wp-editor-area' ).each(function(){
- var id = jQuery(this).attr('id'),
- mode = jQuery(this).closest('.wp-editor-wrap').hasClass('tmce-active') ? 'tmce' : 'html';
+ var id = jQuery( this ).attr( 'id' ),
+ mode = jQuery( this ).closest( '.wp-editor-wrap' ).hasClass( 'tmce-active' ) ? 'tmce' : 'html';
if ( 'tmce' === mode ) {
if ( tinyMCE.majorVersion === '4' ) {
- tinyMCE.execCommand('mceAddEditor', false, id);
+ tinyMCE.execCommand( 'mceAddEditor', false, id );
} else if ( tinyMCE.majorVersion === '3' ) {
- tinyMCE.execCommand('mceAddControl', false, id);
+ tinyMCE.execCommand( 'mceAddControl', false, id );
}
}
diff --git a/js/field.colorpicker.js b/js/field.colorpicker.js
index a064e0db..ed85ea82 100644
--- a/js/field.colorpicker.js
+++ b/js/field.colorpicker.js
@@ -5,14 +5,14 @@
CMB.addCallbackForInit( function() {
// Colorpicker
- jQuery('input:text.cmb_colorpicker').wpColorPicker();
+ jQuery( 'input:text.cmb_colorpicker' ).wpColorPicker();
} );
CMB.addCallbackForClonedField( 'CMB_Color_Picker', function( newT ) {
// Reinitialize colorpickers
- newT.find('.wp-color-result').remove();
- newT.find('input:text.cmb_colorpicker').wpColorPicker();
+ newT.find( '.wp-color-result' ).remove();
+ newT.find( 'input:text.cmb_colorpicker' ).wpColorPicker();
-} );
\ No newline at end of file
+} );
diff --git a/js/field.datetime.js b/js/field.datetime.js
index 76365630..9aa2233f 100644
--- a/js/field.datetime.js
+++ b/js/field.datetime.js
@@ -1,4 +1,3 @@
-
/**
* Date & Time Fields
*/
@@ -7,12 +6,12 @@ CMB.addCallbackForClonedField( ['CMB_Date_Field', 'CMB_Time_Field', 'CMB_Date_Ti
// Reinitialize all the datepickers
newT.find( '.cmb_datepicker' ).each(function () {
- jQuery(this).attr( 'id', '' ).removeClass( 'hasDatepicker' ).removeData( 'datepicker' ).unbind().datepicker();
- });
+ jQuery( this ).attr( 'id', '' ).removeClass( 'hasDatepicker' ).removeData( 'datepicker' ).unbind().datepicker();
+ } );
// Reinitialize all the timepickers.
- newT.find('.cmb_timepicker' ).each(function () {
- jQuery(this).timePicker({
+ newT.find( '.cmb_timepicker' ).each( function () {
+ jQuery( this ).timePicker({
startTime: "00:00",
endTime: "23:30",
show24Hours: false,
@@ -21,21 +20,21 @@ CMB.addCallbackForClonedField( ['CMB_Date_Field', 'CMB_Time_Field', 'CMB_Date_Ti
});
});
-} );
+});
CMB.addCallbackForInit( function() {
// Datepicker
- jQuery('.cmb_datepicker').each(function () {
- jQuery(this).datepicker();
+ jQuery( '.cmb_datepicker' ).each( function () {
+ jQuery( this ).datepicker();
});
-
+
// Wrap date picker in class to narrow the scope of jQuery UI CSS and prevent conflicts
- jQuery("#ui-datepicker-div").wrap('
');
+ jQuery( "#ui-datepicker-div" ).wrap( '
' );
// Timepicker
- jQuery('.cmb_timepicker').each(function () {
- jQuery(this).timePicker({
+ jQuery( '.cmb_timepicker' ).each( function () {
+ jQuery( this ).timePicker({
startTime: "00:00",
endTime: "23:30",
show24Hours: false,
@@ -44,4 +43,4 @@ CMB.addCallbackForInit( function() {
});
} );
-});
\ No newline at end of file
+});
diff --git a/js/field.select.js b/js/field.select.js
index 8a6c7292..d368344b 100644
--- a/js/field.select.js
+++ b/js/field.select.js
@@ -2,8 +2,8 @@ var cmbSelectInit = function() {
jQuery( '.cmb_select' ).each( function() {
- var el = jQuery(this);
- var fieldID = el.attr( 'data-field-id'); // JS Friendly ID
+ var el = jQuery( this );
+ var fieldID = el.attr( 'data-field-id' ); // JS Friendly ID
// If fieldID is set
// If fieldID options exist
diff --git a/js/file-upload.js b/js/file-upload.js
index d03d0a4a..ebd07886 100644
--- a/js/file-upload.js
+++ b/js/file-upload.js
@@ -10,17 +10,18 @@ jQuery( document ).ready( function() {
var frameArgs = {
multiple: false,
title: 'Select File',
- }
+ };
- library = container.attr( 'data-type' ).split(',');
- if ( library.length > 0 )
- frameArgs.library = { type: library }
+ library = container.attr( 'data-type' ).split( ',' );
+ if ( library.length > 0 ) {
+ frameArgs.library = {type: library};
+ }
var CMB_Frame = wp.media( frameArgs );
CMB_Frame.on( 'select', function() {
- var selection = CMB_Frame.state().get('selection'),
+ var selection = CMB_Frame.state().get( 'selection' ),
model = selection.first(),
fileHolder = container.find( '.cmb-file-holder' );
@@ -43,9 +44,9 @@ jQuery( document ).ready( function() {
id: model.attributes.id,
width: container.width(),
height: container.height(),
- crop: fileHolder.attr('data-crop'),
+ crop: fileHolder.attr( 'data-crop' ),
nonce: link.attr( 'data-nonce' )
- }
+ };
fileHolder.addClass( 'cmb-loading' );
@@ -62,7 +63,7 @@ jQuery( document ).ready( function() {
} else {
jQuery( '
', { src: model.attributes.icon } ).prependTo( fileHolder );
- fileHolder.append( jQuery('
').html( '
' + model.attributes.filename + '' ) );
+ fileHolder.append( jQuery( '
' ).html( '
' + model.attributes.filename + '' ) );
}
@@ -96,20 +97,22 @@ jQuery( document ).ready( function() {
jQuery( '.cmb-file-wrap' ).each( function() {
- var el = jQuery(this),
+ var el = jQuery( this ),
container = el.closest( '.postbox' ),
width = container.width() - 12 - 10 - 10,
- ratio = el.height() / el.width();
+ ratio = el.height() / el.width();
- if ( el.attr( 'data-original-width' ) )
+ if ( el.attr( 'data-original-width' ) ) {
el.width( el.attr( 'data-original-width' ) );
- else
+ } else {
el.attr( 'data-original-width', el.width() );
+ }
- if ( el.attr( 'data-original-height' ) )
+ if ( el.attr( 'data-original-height' ) ) {
el.height( el.attr( 'data-original-height' ) );
- else
+ } else {
el.attr( 'data-original-height', el.height() );
+ }
if ( el.width() > width ) {
el.width( width );
@@ -119,11 +122,10 @@ jQuery( document ).ready( function() {
el.find( '.cmb-file-wrap-placeholder' ).height( ( width * ratio ) - 8 );
}
-
} );
- }
+ };
recalculateFileFieldSize();
- jQuery(window).resize( recalculateFileFieldSize );
+ jQuery( window ).resize( recalculateFileFieldSize );
-} );
\ No newline at end of file
+} );
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index be88c32c..9d9bcebf 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -1,7 +1,10 @@
enqueue_scripts();
$field->enqueue_styles();
-
+
$scripts_output = get_echo( 'wp_print_scripts' );
$styles_output = get_echo( 'wp_print_styles' );
@@ -41,64 +41,63 @@ function testDateFieldAssets() {
$this->assertContains( site_url() . '/wp-includes/js/jquery/ui/jquery.ui.core.min.js', $scripts_output );
$this->assertContains( site_url() . '/wp-includes/js/jquery/ui/jquery.ui.datepicker.min.js', $scripts_output );
}
-
+
// Styles
$this->assertContains( 'css/vendor/jquery-ui/jquery-ui.css', $styles_output );
-
+
}
function testTimeFieldAssets() {
- $field = new CMB_Time_Field( 'foo', 'Title', array() );
-
+ $field = new CMB_Time_Field( 'foo', 'Title', array() );
+
// Register CMB-Scripts as this is a dependency.
wp_enqueue_script( 'cmb-scripts', trailingslashit( CMB_URL ) . 'js/cmb.js', array( 'jquery' ) );
-
+
$field->enqueue_scripts();
-
+
$scripts_output = get_echo( 'wp_print_scripts' );
-
+
// Scripts
$this->assertContains( CMB_URL . '/js/cmb.js', $scripts_output );
$this->assertContains( CMB_URL . '/js/jquery.timePicker.min.js', $scripts_output );
$this->assertContains( CMB_URL . '/js/field.datetime.js', $scripts_output );
-
+
}
function testDateTimestampFieldAssets() {
- $field = new CMB_Date_Timestamp_Field( 'foo', 'Title', array() );
-
+ $field = new CMB_Date_Timestamp_Field( 'foo', 'Title', array() );
+
// Register CMB-Scripts as this is a dependency.
wp_enqueue_script( 'cmb-scripts', trailingslashit( CMB_URL ) . 'js/cmb.js', array( 'jquery' ) );
-
+
$field->enqueue_scripts();
-
+
$scripts_output = get_echo( 'wp_print_scripts' );
-
+
// Scripts
$this->assertContains( CMB_URL . '/js/cmb.js', $scripts_output );
$this->assertContains( CMB_URL . '/js/jquery.timePicker.min.js', $scripts_output );
$this->assertContains( CMB_URL . '/js/field.datetime.js', $scripts_output );
-
+
}
function testDatetimeTimestampFieldAssets() {
- $field = new CMB_Datetime_Timestamp_Field( 'foo', 'Title', array() );
-
+ $field = new CMB_Datetime_Timestamp_Field( 'foo', 'Title', array() );
+
// Register CMB-Scripts as this is a dependency.
wp_enqueue_script( 'cmb-scripts', trailingslashit( CMB_URL ) . 'js/cmb.js', array( 'jquery' ) );
-
+
$field->enqueue_scripts();
-
+
$scripts_output = get_echo( 'wp_print_scripts' );
-
+
// Scripts
$this->assertContains( CMB_URL . '/js/cmb.js', $scripts_output );
$this->assertContains( CMB_URL . '/js/jquery.timePicker.min.js', $scripts_output );
$this->assertContains( CMB_URL . '/js/field.datetime.js', $scripts_output );
-
- }
-}
\ No newline at end of file
+ }
+}
diff --git a/tests/testField.php b/tests/testField.php
index d44feb1a..fc5be6a0 100644
--- a/tests/testField.php
+++ b/tests/testField.php
@@ -13,7 +13,7 @@ function setUp() {
'post_status' => 'publish',
'post_content' => rand_str(),
'post_title' => rand_str(),
- 'post_type' => 'post'
+ 'post_type' => 'post',
);
$id = wp_insert_post( $args );
@@ -55,8 +55,9 @@ function testSaveValues() {
$field = new CMB_Text_Field( 'foo', 'Title', array( 1 ) );
$field_value = array( 'one' );
- if ( ! $this->post )
+ if ( ! $this->post ) {
$this->markTestSkipped( 'Post not found' );
+ }
$field->save( $this->post->ID, $field_value );
@@ -70,8 +71,9 @@ function testSaveValuesOnRepeatable() {
$field = new CMB_Text_Field( 'foo', 'Title', array( 1, 2 ), array( 'repeatable' => true ) );
$repeat_value = array( 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'zero' );
- if ( ! $this->post )
+ if ( ! $this->post ) {
$this->markTestSkipped( 'Post not found' );
+ }
$field->save( $this->post->ID, $repeat_value );
@@ -161,4 +163,4 @@ function testSavedFieldOutput() {
$field->html();
}
-}
\ No newline at end of file
+}
diff --git a/tests/testGroupField.php b/tests/testGroupField.php
index f2b3c36a..58cfecb6 100644
--- a/tests/testGroupField.php
+++ b/tests/testGroupField.php
@@ -28,8 +28,8 @@ function testGetValues() {
$group->values = $values = array(
'group' => array(
'foo' => array( 1, 2 ),
- 'bar' => array( 3, 4 )
- )
+ 'bar' => array( 3, 4 ),
+ ),
);
$this->assertEquals( $group->get_values(), $values );
@@ -48,15 +48,15 @@ function testParseSaveValues() {
$group->set_values( array(
'group' => array(
'foo' => array( 1 ),
- 'bar' => array( 2, 3 )
+ 'bar' => array( 2, 3 ),
),
) );
$expected = array(
'group' => array(
'foo' => 1,
- 'bar' => array( 2, 3 )
- )
+ 'bar' => array( 2, 3 ),
+ ),
);
$group->parse_save_values();
@@ -99,8 +99,6 @@ function testFieldNameAttrValue() {
$this->assertEquals( $id_attr, 'group[cmb-group-12][foo][cmb-field-0]' );
$group->field_index = 0; // Unset
-
-
}
function testFieldIdAttrValue() {
@@ -138,5 +136,4 @@ function testFieldIdAttrValue() {
$group->field_index = 0; // Unset
}
-
-}
\ No newline at end of file
+}
diff --git a/tests/testIsMetaBoxDisplayed.php b/tests/testIsMetaBoxDisplayed.php
index 5d0fcd3f..fd8c57e4 100644
--- a/tests/testIsMetaBoxDisplayed.php
+++ b/tests/testIsMetaBoxDisplayed.php
@@ -13,7 +13,7 @@ function setUp() {
'post_status' => 'publish',
'post_content' => rand_str(),
'post_title' => rand_str(),
- 'post_type' => 'post'
+ 'post_type' => 'post',
);
$id = wp_insert_post( $args );
@@ -40,9 +40,9 @@ function testAddForId() {
'id' => 'test',
'name' => 'Test',
'type' => 'text',
- )
+ ),
),
- 'show_on' => array( 'id' => 2 )
+ 'show_on' => array( 'id' => 2 ),
) );
$this->assertFalse( $mb->add_for_id( false ) );
@@ -67,9 +67,9 @@ function testAddForTemplate() {
'id' => 'test',
'name' => 'Test',
'type' => 'text',
- )
+ ),
),
- 'show_on' => array( 'page-template' => 'test.php' )
+ 'show_on' => array( 'page-template' => 'test.php' ),
) );
$this->assertFalse( $mb->add_for_page_template( true ) );
@@ -94,9 +94,9 @@ function testHideForId() {
'id' => 'test',
'name' => 'Test',
'type' => 'text',
- )
+ ),
),
- 'hide_on' => array( 'id' => 2 )
+ 'hide_on' => array( 'id' => 2 ),
) );
// Test is shown when no ID is set.
@@ -127,9 +127,9 @@ function testHideForTemplate() {
'id' => 'test',
'name' => 'Test',
'type' => 'text',
- )
+ ),
),
- 'hide_on' => array( 'page-template' => 'test.php' )
+ 'hide_on' => array( 'page-template' => 'test.php' ),
) );
$this->assertTrue( $mb->hide_for_page_template( true ) );
@@ -143,5 +143,4 @@ function testHideForTemplate() {
unset( $_GET['post'] );
}
-
-}
\ No newline at end of file
+}