Skip to content

Commit

Permalink
Add CMB2::is_supported_core_object_type helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsternberg committed Mar 29, 2024
1 parent 462c0ca commit ae1c740
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions includes/CMB2.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
*/
class CMB2 extends CMB2_Base {

/**
* Supported CMB2 object types
*
* @var array
* @since 2.11.0
*/
protected $core_object_types = array( 'post', 'user', 'comment', 'term', 'options-page' );

/**
* The object properties name.
*
Expand Down Expand Up @@ -1098,8 +1106,7 @@ public function mb_object_type() {
}

// Get our object type.
$supported_types = array( 'post', 'user', 'comment', 'term', 'options-page' );
$mb_object_type = in_array( $found_type, $supported_types, true )
$mb_object_type = $this->is_supported_core_object_type( $found_type )
? $found_type
: 'post';

Expand Down Expand Up @@ -1809,6 +1816,16 @@ public function is_alternate_context_box() {
return $this->prop( 'context' ) && in_array( $this->prop( 'context' ), array( 'form_top', 'before_permalink', 'after_title', 'after_editor' ), true );
}

/**
* Whether given object type is one of the core supported object types.
*
* @since 2.11.0
* @return bool
*/
public function is_supported_core_object_type( $object_type ) {
return in_array( $object_type, $this->core_object_types, true );
}

/**
* Magic getter for our object.
*
Expand All @@ -1821,6 +1838,7 @@ public function __get( $property ) {
case 'updated':
case 'has_columns':
case 'tax_metaboxes_to_remove':
case 'core_object_types':
return $this->{$property};
default:
return parent::__get( $property );
Expand Down

0 comments on commit ae1c740

Please sign in to comment.