• Resolved Cole Slaw

    (@nthorin)


    I want to share a object instance between different php files used when creating meta boxes for a custom post type.

    The reason is that I dont want to to load the same information from every included file.

    From register_post_type i call the following function to create the meta boxes:

    function my_new_meta_box( $post ) {
    
    $video = new MyClass( $post->ID );
    
    # Example meta box
    add_meta_box( 'mbtest1', __( 'XXX', 'abc' ), function() { include( MY_DIR . 'metabox/metabox1.php' ); }, 'mycpt', 'normal', 'default' );
    
    # Example meta box
    add_meta_box( 'mbtest2', __( 'XXX', 'abc' ), function() { include( MY_DIR . 'metabox/metabox2.php' ); }, 'mycpt', 'normal', 'default' );
    }

    Is there any ‘good’ way to do this, without the use of a global variable?

    Thanks in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Sharing object instance between files’ is closed to new replies.