add( $meta_box ); return $meta_box; } public function add( RW_Meta_Box $meta_box ) { $this->data[ $meta_box->id ] = $meta_box; } public function get( $id ) { return $this->data[ $id ] ?? false; } /** * Get meta boxes under some conditions. * * @param array $args Custom argument to get meta boxes by. */ public function get_by( array $args ) : array { $meta_boxes = $this->data; foreach ( $meta_boxes as $index => $meta_box ) { foreach ( $args as $key => $value ) { $meta_box_key = 'object_type' === $key ? $meta_box->get_object_type() : $meta_box->$key; if ( $meta_box_key !== $value ) { unset( $meta_boxes[ $index ] ); continue 2; // Skip the meta box loop. } } } return $meta_boxes; } public function all() { return $this->data; } }