diff --git a/class.cmb-meta-box.php b/class.cmb-meta-box.php
index ae441bc3..0c111bd5 100644
--- a/class.cmb-meta-box.php
+++ b/class.cmb-meta-box.php
@@ -56,12 +56,13 @@ public function init_fields( $post_id = 0 ) {
public function init_fields_for_post() {
global $post;
+ $post_id = null;
// Get the current ID
if ( isset( $_GET['post'] ) ) {
- $post_id = $_GET['post'];
+ $post_id = wp_unslash( $_GET['post'] );
} elseif ( isset( $_POST['post_ID'] ) ) {
- $post_id = $_POST['post_ID'];
+ $post_id = wp_unslash( $_POST['post_ID'] );
} elseif ( ! empty( $post->ID ) ) {
$post_id = $post->ID;
}
@@ -70,6 +71,10 @@ public function init_fields_for_post() {
return false;
}
+ if ( ! is_numeric( $post_id ) || $post_id != floor( $post_id ) ) {
+ return false;
+ }
+
$this->init_fields( (int) $post_id );
}
@@ -392,13 +397,13 @@ function save_for_post( $post_id ) {
function get_post_id() {
- $post_id = isset( $_GET['post'] ) ? $_GET['post'] : null;
+ $post_id = isset( $_GET['post'] ) ? absint( $_GET['post'] ) : null;
if ( ! $post_id && isset( $_POST['post_id'] ) ) {
- $post_id = $_POST['post_id'];
+ $post_id = absint( $_POST['post_id'] );
}
- return $post_id;
+ return (int) $post_id;
}
}
diff --git a/classes.fields.php b/classes.fields.php
index 6601d6f9..3bfa2307 100644
--- a/classes.fields.php
+++ b/classes.fields.php
@@ -643,7 +643,7 @@ static function request_image_ajax_callback() {
return;
}
- $id = intval( $_POST['id'] );
+ $id = absint( $_POST['id'] );
$size = array(
intval( $_POST['width'] ),
@@ -652,7 +652,7 @@ static function request_image_ajax_callback() {
);
$image = wp_get_attachment_image_src( $id, $size );
- echo reset( $image );
+ echo esc_url( reset( $image ) );
die(); // this is required to return a proper result
}
@@ -1019,7 +1019,7 @@ public function html() {
.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
+} );