Skip to content

Commit

Permalink
added brackets and set spacing to tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
gregrickaby committed Aug 18, 2014
1 parent 55b05c5 commit d4ec161
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 38 deletions.
3 changes: 2 additions & 1 deletion example-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ function cmb2_sample_metaboxes( array $meta_boxes ) {
*/
function cmb2_initialize_meta_boxes() {

if ( ! class_exists( 'CMB2' ) )
if ( ! class_exists( 'CMB2' ) ) {
require_once 'cmb/init.php';
}

}
12 changes: 8 additions & 4 deletions includes/CMB2_Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ class CMB2_Ajax {
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' ) ) )
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'] );
Expand Down Expand Up @@ -116,8 +117,9 @@ public function get_oembed( $args ) {
$fallback = $wp_embed->maybe_make_link( $oembed_url );

// Send back our embed
if ( $check_embed && $check_embed != $fallback )
if ( $check_embed && $check_embed != $fallback ) {
return '<div class="embed_status">'. $check_embed .'<p class="cmb2_remove_wrapper"><a href="#" class="cmb2_remove_file_button" rel="'. $args['field_id'] .'">'. __( 'Remove Embed', 'cmb2' ) .'</a></p></div>';
}

// Otherwise, send back error info that no oEmbeds were found
return '<p class="ui-state-error-text">'. sprintf( __( 'No oEmbed Results Found for %s. View more info at', 'cmb2' ), $fallback ) .' <a href="http://codex.wordpress.org/Embeds" target="_blank">codex.wordpress.org/Embeds</a>.</p>';
Expand All @@ -136,8 +138,9 @@ public function get_oembed( $args ) {
*/
public function hijack_oembed_cache_get( $check, $object_id, $meta_key ) {

if ( ! $this->hijack || ( $this->object_id != $object_id && 1987645321 !== $object_id ) )
if ( ! $this->hijack || ( $this->object_id != $object_id && 1987645321 !== $object_id ) ) {
return $check;
}

if ( $this->ajax_update ) {
return false;
Expand All @@ -163,8 +166,9 @@ public function hijack_oembed_cache_get( $check, $object_id, $meta_key ) {
* @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 ) )
if ( ! $this->hijack || ( $this->object_id != $object_id && 1987645321 !== $object_id ) ){
return $check;
}

$this->oembed_cache_set( $meta_key, $meta_value );

Expand Down
6 changes: 4 additions & 2 deletions includes/CMB2_Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,14 @@ public function field_timezone() {
public function render_field() {

// If field is requesting to not be shown on the front-end
if ( ! is_admin() && ! $this->args( 'on_front' ) )
if ( ! is_admin() && ! $this->args( 'on_front' ) ) {
return;
}

// If field is requesting to be conditionally shown
if ( is_callable( $this->args( 'show_on_cb' ) ) && ! call_user_func( $this->args( 'show_on_cb' ), $this ) )
if ( is_callable( $this->args( 'show_on_cb' ) ) && ! call_user_func( $this->args( 'show_on_cb' ), $this ) ) {
return;
}

$classes = 'cmb-type-'. sanitize_html_class( $this->type() );
$classes .= ' cmb2_id_'. sanitize_html_class( $this->id() );
Expand Down
27 changes: 18 additions & 9 deletions includes/CMB2_Sanitize.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,19 @@ public function text_date_timestamp( $value ) {
public function text_datetime_timestamp( $value, $repeat = false ) {

$test = is_array( $value ) ? array_filter( $value ) : '';
if ( empty( $test ) )
if ( empty( $test ) ) {
return '';
}

if ( $repeat_value = $this->_check_repeat( $value, __FUNCTION__, $repeat ) )
if ( $repeat_value = $this->_check_repeat( $value, __FUNCTION__, $repeat ) ) {
return $repeat_value;
}

$value = strtotime( $value['date'] .' '. $value['time'] );

if ( $tz_offset = $this->field->field_timezone_offset() )
if ( $tz_offset = $this->field->field_timezone_offset() ) {
$value += $tz_offset;
}

return $value;
}
Expand All @@ -226,24 +229,29 @@ public function text_datetime_timestamp( $value, $repeat = false ) {
public function text_datetime_timestamp_timezone( $value, $repeat = false ) {

$test = is_array( $value ) ? array_filter( $value ) : '';
if ( empty( $test ) )
if ( empty( $test ) ) {
return '';
}

if ( $repeat_value = $this->_check_repeat( $value, __FUNCTION__, $repeat ) )
if ( $repeat_value = $this->_check_repeat( $value, __FUNCTION__, $repeat ) ) {
return $repeat_value;
}

$tzstring = null;

if ( is_array( $value ) && array_key_exists( 'timezone', $value ) )
if ( is_array( $value ) && array_key_exists( 'timezone', $value ) ) {
$tzstring = $value['timezone'];
}

if ( empty( $tzstring ) )
if ( empty( $tzstring ) ) {
$tzstring = cmb2_utils()->timezone_string();
}

$offset = cmb2_utils()->timezone_offset( $tzstring, true );

if ( substr( $tzstring, 0, 3 ) === 'UTC' )
if ( substr( $tzstring, 0, 3 ) === 'UTC' ) {
$tzstring = timezone_name_from_abbr( '', $offset, 0 );
}

$value = new DateTime( $value['date'] .' '. $value['time'], new DateTimeZone( $tzstring ) );
$value = serialize( $value );
Expand Down Expand Up @@ -352,8 +360,9 @@ public function file( $value ) {
* @return mixed Sanitized value
*/
public function _check_repeat( $value, $method, $repeat ) {
if ( $repeat || ! $this->field->args( 'repeatable' ) )
if ( $repeat || ! $this->field->args( 'repeatable' ) ) {
return;
}
$new_value = array();
foreach ( $value as $iterator => $val ) {
$new_value[] = $this->$method( $val, true );
Expand Down
18 changes: 12 additions & 6 deletions includes/CMB2_Show_Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,23 @@ public static function check_id( $display, $meta_box_args, $cmb ) {
*/
public static function check_page_template( $display, $meta_box_args, $cmb ) {

if ( ! isset( $meta_box_args['show_on']['key'] ) || 'page-template' !== $meta_box_args['show_on']['key'] )
if ( ! isset( $meta_box_args['show_on']['key'] ) || 'page-template' !== $meta_box_args['show_on']['key'] ) {
return $display;
}

$object_id = $cmb->object_id();

if ( ! $object_id || $cmb->object_type() !== 'post' )
if ( ! $object_id || $cmb->object_type() !== 'post' ) {
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) $meta_box_args['show_on']['value'] ) )
if ( $current_template && in_array( $current_template, (array) $meta_box_args['show_on']['value'] ) ) {
return true;
}

return false;
}
Expand All @@ -70,18 +73,21 @@ public static function check_page_template( $display, $meta_box_args, $cmb ) {
public static function check_admin_page( $display, $meta_box_args ) {

// check if this is a 'options-page' metabox
if ( ! isset( $meta_box_args['show_on']['key'] ) || 'options-page' !== $meta_box_args['show_on']['key'] )
if ( ! isset( $meta_box_args['show_on']['key'] ) || 'options-page' !== $meta_box_args['show_on']['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'] ) )
if ( ! isset( $_GET['page'] ) ) {
return $display;
}

if ( ! isset( $meta_box_args['show_on']['value'] ) )
if ( ! isset( $meta_box_args['show_on']['value'] ) ) {
return false;
}

$pages = $meta_box_args['show_on']['value'];

Expand Down
13 changes: 8 additions & 5 deletions includes/CMB2_Types.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ public function get_object_terms() {

// Check cache
$cached = $test = get_transient( $cache_key );
if ( $cached )
if ( $cached ) {
return $cached;
}

$cached = wp_get_object_terms( $object_id, $taxonomy );
// Do our own (minimal) caching. Long enough for a page-load.
Expand Down Expand Up @@ -199,8 +200,9 @@ public function concat_options( $args = array(), $method = 'list_input' ) {
$this_args = $args;
$this_args['value'] = $opt_value;
$this_args['label'] = $opt_label;
if ( $is_current )
if ( $is_current ) {
$this_args['checked'] = 'checked';
}

$_options .= $this->$method( $this_args, $i );
} else {
Expand Down Expand Up @@ -535,11 +537,12 @@ public function select_timezone() {
public function colorpicker() {
$meta_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 #.
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 #.
}
elseif ( ! preg_match( '/^#' . $hex_color . '/i', $meta_value ) ) { // Value doesn't match #123abc, so sanitize to just #.
$meta_value = "#";

}
return $this->input( array( 'class' => 'cmb2_colorpicker cmb2_text_small', 'value' => $meta_value ) );
}

Expand Down
10 changes: 6 additions & 4 deletions includes/CMB2_Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ public function image_id_from_url( $img_url ) {
$attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid LIKE '%%%s%%' LIMIT 1;", $img_url ) );

// If we found an attachement ID, return it
if ( !empty( $attachment ) && is_array( $attachment ) )
if ( !empty( $attachment ) && is_array( $attachment ) ) {
return $attachment[0];
}

// No luck
return false;
Expand Down Expand Up @@ -78,12 +79,13 @@ public function timezone_string() {
$tzstring = get_option( 'timezone_string' );

if ( empty( $tzstring ) ) { // Create a UTC+- zone if no timezone string exists
if ( 0 == $current_offset )
if ( 0 == $current_offset ) {
$tzstring = 'UTC+0';
elseif ( $current_offset < 0 )
} elseif ( $current_offset < 0 ) {
$tzstring = 'UTC' . $current_offset;
else
} else {
$tzstring = 'UTC+' . $current_offset;
}
}

return $tzstring;
Expand Down
6 changes: 3 additions & 3 deletions includes/CMB2_hookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ public static function register_scripts() {

if ( ! is_admin() ) {
// we need to register colorpicker on the front-end
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_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' => __( 'Clear', 'cmb2' ),
'defaultString' => __( 'Default', 'cmb2' ),
Expand Down Expand Up @@ -208,7 +208,7 @@ public function add_post_enctype() {
echo '
<script type="text/javascript">
jQuery(document).ready(function(){
$form = jQuery("#'. $this->form_id .'");
$form = jQuery("#' . $this->form_id . '");
if ( $form.length ) {
$form.attr( {
"enctype" : "multipart/form-data",
Expand Down
10 changes: 6 additions & 4 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
*/

/************************************************************************
You should not edit the code below
(or any code in the included files)
or things might explode!
You should not edit the code below
(or any code in the included files)
or things might explode!
*************************************************************************/

/**
Expand All @@ -63,7 +63,9 @@ class cmb2_bootstrap_200 {
public static $single = null;

public static function go() {
if ( null === self::$single ) { self::$single = new self(); }
if ( null === self::$single ) {
self::$single = new self();
}
return self::$single;
}

Expand Down

0 comments on commit d4ec161

Please sign in to comment.