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

Commit

Permalink
Do not throw a doing_it_wrong notice when we guess the `CMB2_Types:…
Browse files Browse the repository at this point in the history
…:$type` object.

We broke back-compat.. let's fix it, but not yell about it.
  • Loading branch information
jtsternberg committed Oct 19, 2016
1 parent 9942b9c commit 4a91731
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ All notable changes to this project will be documented in this file.

### Bug Fixes

* If custom field types use a method and the Type object has not been instantiated, Try to guess the Type object and instantiate, then throw a `_doing_it_wrong` notice.
* If custom field types use a method and the Type object has not been instantiated, Try to guess the Type object and instantiate.
* Normalize WordPress root path (`ABSPATH`) and theme rooth path (`get_theme_root()`). Props [@rianbotha](https://github.com/rianbotha) ([#677](https://github.com/WebDevStudios/CMB2/pull/677), [#676](https://github.com/WebDevStudios/CMB2/pull/676)).
* Fix issue with `'cmb2_remove_row'` Javascript callback for non-group row removal. Fixes [#729](https://github.com/WebDevStudios/CMB2/pull/729)).

Expand Down
17 changes: 4 additions & 13 deletions includes/CMB2_Types.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CMB2_Types {
* @var CMB2_Type_Base object
* @since 2.2.2
*/
public $type;
public $type = null;

public function __construct( CMB2_Field $field ) {
$this->field = $field;
Expand Down Expand Up @@ -130,13 +130,14 @@ protected function proxy_method( $method, $default, $args = array() ) {
/**
* If no CMB2_Types::$type object is initiated when a proxy method is called, it means
* it's a custom field type (which SHOULD be instantiating a Type), but let's try and
* guess the type object for them, instantiate it, and throw a _doing_it_wrong notice.
* guess the type object for them and instantiate it.
*
* @since 2.2.3
*
* @param string $method Method attempting to be called on the CMB2_Type_Base object.
*/
protected function guess_type_object( $method ) {

// Try to "guess" the Type object based on the method requested.
switch ( $method ) {
case 'select_option':
Expand Down Expand Up @@ -166,17 +167,7 @@ protected function guess_type_object( $method ) {
break;
}

// Then, let's throw a debug _doing_it_wrong notice.

$message = array( sprintf( esc_html__( 'Custom field types require a Type object instantiation to use this method. This method was called by the \'%s\' field type.' ), $this->field->type() ) );

$message[] = is_object( $this->type )
? esc_html__( 'That field type may not work as expected.', 'cmb2' )
: esc_html__( 'That field type will not work as expected.', 'cmb2' );

$message[] = esc_html__( 'For more information about this change see: https://github.com/mustardBees/cmb-field-select2/pull/34w', 'cmb2' );

_doing_it_wrong( __CLASS__ . '::' . $method, implode( ' ', $message ), '2.2.2' );
return null !== $this->type;
}

/**
Expand Down

0 comments on commit 4a91731

Please sign in to comment.