You should use add_meta_boxes
to add metaboxes.
This hook fires only the appropriate page and also pass as argumument the current post type, so you can use it instead retrieving it with get_post_type()
.
Sample code:
function call_vivid_framework_metaboxClass( $post_type ) {
// if the metabox var is set outside the function, you should
// declare it as global
global $metabox;
if( ! isset( $metabox ) || ! is_array( $metabox ) ) {
return;
}
foreach ( $metabox as $key => $value ) {
if (
isset( $value['screen'] )
&& in_array( $post_type, $value['screen'], true )
) {
new vivid_framework_metaboxClass( $key, $value );
}
}
}
add_action( 'add_meta_boxes', 'call_vivid_framework_metaboxClass' );
Note that I added a check for isset( $value['screen'] )
because you should always check a variable is defined before to use it.