Pink-Crab / Perique-Registerables

The Registerables module for the PinkCrab framework.
MIT License
3 stars 0 forks source link

Metabox Actions Not Firing #44

Closed gin0115 closed 2 years ago

gin0115 commented 2 years ago

There is 2 parts to this issue.

Race Condition solution

Meta_Box_Registrar::register( Meta_Box $meta_box ) image

$this->loader->action(
    'current_screen',
    function() use ( $meta_box ) {
        // If we have any hook calls, add them to the loader.
        if ( $this->is_active( $meta_box ) && ! empty( $meta_box->actions ) ) {
            foreach ( $meta_box->actions as $handle => $hook ) {
                add_action( (string) $handle, $hook['callback'], $hook['priority'], $hook['params'] );
            }
        }
    }
);

Auto populate the meta box with cpt used on.

Registerable_Middleware::process_post_type() image

// Register meta boxes.
$meta_boxes = $post_type_registerable->meta_boxes( array() );

if ( ! empty( $meta_boxes ) ) {

    // Create the registrar
    $meta_box_registrar = $this->get_meta_box_registrar();

    // Register each meta box.
    foreach ( $meta_boxes as $meta_box ) {
        $meta_box->screen( $post_type_registerable->key );
        $meta_box_registrar->register( $meta_box );
    }
}