@@ -815,32 +815,18 @@ public function mb_object_type() {
815815 return $ this ->mb_object_type ;
816816 }
817817
818- $ registered_types = $ this ->prop ( 'object_types ' );
819-
820- if ( ! $ registered_types ) {
821- $ this ->mb_object_type = 'post ' ;
822- return $ this ->mb_object_type ;
823- }
818+ $ registered_types = $ this ->box_types ();
824819
825820 $ type = false ;
826821
827- // check if 'object_types' is a string
828- if ( is_string ( $ registered_types ) ) {
829- $ type = $ registered_types ;
830- }
831-
832822 // if it's an array of one, extract it
833- elseif ( is_array ( $ registered_types ) && 1 === count ( $ registered_types ) ) {
823+ if ( 1 === count ( $ registered_types ) ) {
834824 $ last = end ( $ registered_types );
835825 if ( is_string ( $ last ) ) {
836826 $ type = $ last ;
837827 }
838- } elseif ( is_array ( $ registered_types ) ) {
839- $ page_type = $ this ->current_object_type ();
840-
841- if ( in_array ( $ page_type , $ registered_types , true ) ) {
842- $ type = $ page_type ;
843- }
828+ } elseif ( in_array ( $ this ->current_object_type (), $ registered_types , true ) ) {
829+ $ type = $ page_type ;
844830 }
845831
846832 // Get our object type
@@ -860,6 +846,15 @@ public function mb_object_type() {
860846 return $ this ->mb_object_type ;
861847 }
862848
849+ /**
850+ * Gets the box 'object_types' array based on box settings.
851+ * @since 2.2.4
852+ * @return array Object types
853+ */
854+ public function box_types () {
855+ return CMB2_Utils::ensure_array ( $ this ->prop ( 'object_types ' ), array ( 'post ' ) );
856+ }
857+
863858 /**
864859 * Determines if metabox is for an options page
865860 * @since 1.0.1
0 commit comments