Skip to content
This repository has been archived by the owner on Apr 16, 2020. It is now read-only.

Commit

Permalink
scrutinizer-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsternberg committed Feb 15, 2015
1 parent 30aa4e8 commit bc48c1b
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 76 deletions.
2 changes: 2 additions & 0 deletions includes/CMB2.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
/**
* Create meta boxes
*
* @property-read string $cmb_id
*/
class CMB2 {

Expand Down
2 changes: 2 additions & 0 deletions includes/CMB2_Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

/**
* CMB field class
* @since 1.1.0
*
* @method string _id()
* @method string type()
* @method mixed fields()
Expand Down
17 changes: 12 additions & 5 deletions includes/CMB2_Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class CMB2_Option {
*/
protected $options = array();

/**
* Current option key
* @var string
*/
protected $key = '';

/**
* Initiate option object
* @since 2.0.0
Expand Down Expand Up @@ -124,14 +130,15 @@ function update( $field_id, $value = '', $resave = false, $single = 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.
* @uses apply_filters() Calls 'cmb2_override_option_save_{$this->key}' hook
* to allow overwriting the option value to be stored.
*
* @since 1.0.1
* @return boolean Success/Failure
* @param array $options Optional options to override
* @return bool Success/Failure
*/
function set( $options = false ) {
$this->options = $options ? $options : $this->options;
function set( $options = array() ) {
$this->options = ! empty( $options ) ? $options : $this->options;

$test_save = apply_filters( "cmb2_override_option_save_{$this->key}", 'cmb2_no_override_option_save', $this->options, $this );

Expand Down
2 changes: 1 addition & 1 deletion includes/CMB2_Sanitize.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public function text_datetime_timestamp_timezone( $value, $repeat = false ) {
$tzstring = cmb2_utils()->timezone_string();
}

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

if ( 'UTC' === substr( $tzstring, 0, 3 ) ) {
$tzstring = timezone_name_from_abbr( '', $offset, 0 );
Expand Down
2 changes: 1 addition & 1 deletion includes/CMB2_Show_Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CMB2_Show_Filters {
*
* @param array $meta_box_args Metabox config array
*
* @return string|false show_on key or false
* @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;
Expand Down
28 changes: 12 additions & 16 deletions includes/CMB2_Types.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ public function get_object_terms() {
$cache_key = "cmb-cache-{$taxonomy}-{$object_id}";

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

$cached = wp_get_object_terms( $object_id, $taxonomy );
// Do our own (minimal) caching. Long enough for a page-load.
$set = set_transient( $cache_key, $cached, 60 );
set_transient( $cache_key, $cached, 60 );
return $cached;
}

Expand Down Expand Up @@ -136,13 +136,9 @@ public function get_file_ext( $file ) {
* @param string $value File url or path
* @return string File name
*/
public function get_file_name_from_path( $value ) {
$parts = explode( '/', $value );
for ( $i = 0; $i < count( $parts ); ++$i ) {
$file_name = $parts[$i];
}

return $file_name;
public function get_file_name_from_path( $url ) {
$parts = explode( '/', $url );
return is_array( $parts ) ? end( $parts ) : $url;
}

/**
Expand Down Expand Up @@ -254,7 +250,7 @@ public function list_input( $args = array(), $i ) {
'label' => '',
) );

return sprintf( "\t".'<li><input%s/> <label for="%s">%s</label></li>'."\n", $this->concat_attrs( $a, 'label' ), $a['id'], $a['label'] );
return sprintf( "\t".'<li><input%s/> <label for="%s">%s</label></li>'."\n", $this->concat_attrs( $a, array( 'label' ) ), $a['id'], $a['label'] );
}

/**
Expand Down Expand Up @@ -335,9 +331,9 @@ public function repeatable_rows() {

/**
* Generates a repeatable row's markup
* @since 1.1.0
* @param string $disable_remover Whether remove button should be disabled
* @param string $class Repeatable table row's class
* @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' : '';
Expand Down Expand Up @@ -419,7 +415,7 @@ public function input( $args = array() ) {
'desc' => $this->_desc( true ),
) );

return sprintf( '<input%s/>%s', $this->concat_attrs( $a, 'desc' ), $a['desc'] );
return sprintf( '<input%s/>%s', $this->concat_attrs( $a, array( 'desc' ) ), $a['desc'] );
}

/**
Expand Down Expand Up @@ -511,7 +507,7 @@ public function text_date_timestamp() {
return $this->input( array( 'class' => 'cmb2-text-small cmb2-datepicker', 'value' => $formatted_value ) );
}

public function text_datetime_timestamp( $meta_value = '' ) {
public function text_datetime_timestamp( $meta_value = null ) {
$desc = '';
if ( ! $meta_value ) {
$meta_value = $this->field->escaped_value();
Expand Down Expand Up @@ -549,7 +545,7 @@ public function text_datetime_timestamp_timezone() {
$meta_value = '';
}
$datetime = unserialize( $meta_value );
$meta_value = $tzstring = false;
$meta_value = $tzstring = '';

if ( $datetime && $datetime instanceof DateTime ) {
$tz = $datetime->getTimezone();
Expand Down
25 changes: 12 additions & 13 deletions includes/CMB2_hookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@ class CMB2_hookup {

/**
* Only allow JS registration once
* @var array
* @var bool
* @since 2.0.0
*/
protected static $registration_done = false;

public function __construct( $cmb ) {
/**
* Metabox Form ID
* @var CMB2 object
* @since 2.0.2
*/
protected $cmb;

public function __construct( CMB2 $cmb ) {
$this->cmb = $cmb;

$this->hooks();
Expand Down Expand Up @@ -51,7 +58,7 @@ public function admin_hooks() {
global $pagenow;

// register our scripts and styles for cmb
$this->once( 'admin_enqueue_scripts', array( $this, '_register_scripts' ), 8 );
$this->once( 'admin_enqueue_scripts', array( __CLASS__, 'register_scripts' ), 8 );

$type = $this->cmb->mb_object_type();
if ( 'post' == $type ) {
Expand Down Expand Up @@ -101,14 +108,6 @@ public function admin_hooks() {
}
}

/**
* Registers scripts and styles for CMB
* @since 1.0.0
*/
public function _register_scripts() {
self::register_scripts( $this->cmb->object_type() );
}

/**
* Registers scripts and styles for CMB
* @since 1.0.0
Expand Down Expand Up @@ -374,7 +373,7 @@ public static function enqueue_cmb_css() {
return false;
}

CMB2_hookup::register_scripts();
self::register_scripts();
return wp_enqueue_style( 'cmb2-styles' );
}

Expand All @@ -387,7 +386,7 @@ public static function enqueue_cmb_js() {
return false;
}

CMB2_hookup::register_scripts();
self::register_scripts();
wp_enqueue_media();
return wp_enqueue_script( 'cmb2-scripts' );
}
Expand Down
12 changes: 6 additions & 6 deletions includes/helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function cmb2_autoload_classes( $class_name ) {

$file = cmb2_dir( "includes/{$class_name}.php" );
if ( file_exists( $file ) ) {
@include_once( $file );
include_once( $file );
}
}
spl_autoload_register( 'cmb2_autoload_classes' );
Expand All @@ -33,7 +33,7 @@ function cmb2_utils() {
* @since 2.0.0
* @return CMB2_Ajax object CMB utilities class
*/
function cmb2_ajax( $args = array() ) {
function cmb2_ajax() {
static $cmb2_ajax;
$cmb2_ajax = $cmb2_ajax ? $cmb2_ajax : new CMB2_Ajax();
return $cmb2_ajax;
Expand Down Expand Up @@ -164,7 +164,7 @@ function new_cmb2_box( array $meta_box_config ) {
/**
* Retrieve a CMB instance by the metabox ID
* @since 2.0.0
* @param array $meta_box Metabox ID or Metabox config array
* @param mixed $meta_box Metabox ID or Metabox config array
* @return CMB2 object
*/
function cmb2_get_metabox( $meta_box, $object_id = 0 ) {
Expand All @@ -191,7 +191,7 @@ function cmb2_get_metabox( $meta_box, $object_id = 0 ) {
/**
* Retrieve a metabox form
* @since 2.0.0
* @param array $meta_box Metabox config array or Metabox ID
* @param mixed $meta_box Metabox config array or Metabox ID
* @param int $object_id Object ID
* @param array $args Optional arguments array
* @return string CMB html form markup
Expand All @@ -213,7 +213,7 @@ function cmb2_get_metabox_form( $meta_box, $object_id = 0, $args = array() ) {
/**
* Display a metabox form & save it on submission
* @since 1.0.0
* @param array $meta_box Metabox config array or Metabox ID
* @param mixed $meta_box Metabox config array or Metabox ID
* @param int $object_id Object ID
* @param array $args Optional arguments array
*/
Expand Down Expand Up @@ -270,7 +270,7 @@ function cmb2_print_metabox_form( $meta_box, $object_id = 0, $args = array() ) {
/**
* Display a metabox form (or optionally return it) & save it on submission
* @since 1.0.0
* @param array $meta_box Metabox config array or Metabox ID
* @param mixed $meta_box Metabox config array or Metabox ID
* @param int $object_id Object ID
* @param array $args Optional arguments array
*/
Expand Down
Loading

0 comments on commit bc48c1b

Please sign in to comment.