WPAlchemy MediaAccess inserting media link in WP Editor instead of custom field in metabox [closed]

I managed to solve it. The problem was in using a custom post-type with Metabox.php / MediaAccess.php (both from WPAlchemy class)

Supposedly you can use custom post-types with WPAlchemy since, when instantiating a WPAlchemy_MetaBox object you can pass some optional parameters to enable that kind of costumization. Like this:

$mb = $my_custom_metabox = new WPAlchemy_MetaBox(array
(
    'id' => '_palestrantes_metabox',
    'title' => 'Palestrantes',
    'types' => array('post','espresso_events'),
    'template' => get_stylesheet_directory() . '/metaboxes/custom-meta.php'
));

But within MetaBox.php, the _init function uses some validation code to proceed:

559   // must be creating or editing a post or page
560   if ( ! WPAlchemy_MetaBox::_is_post() AND ! WPAlchemy_MetaBox::_is_page()) return;

Both functions _is_post() and _is_page(), end up calling the

static function _get_current_post_type()
{
    $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : NULL ;
    if ( isset( $uri ) ) {
        $uri_parts = parse_url($uri);
        $file = basename($uri_parts['path']);

        if ($uri AND in_array($file, array('post.php', 'post-new.php'))) {
            $post_id = WPAlchemy_MetaBox::_get_post_id();

            $post_type = isset($_GET['post_type']) ? $_GET['post_type'] : NULL ;

            $post_type = $post_id ? get_post_type($post_id) : $post_type ;

            if (isset($post_type)) {
                return $post_type;
            }
            else {
                // because of the 'post.php' and 'post-new.php' checks above, we can default to 'post'
                return 'post';
            }
        }
    }
    return NULL;
}

The problem here is validating through the URI, it supposes that every post or page will have the ‘post.php’ or ‘post-new.php’ in its URI. Which in my case turned out being:

/wp-admin/admin.php?page=espresso_events&message=1&action=edit&post=1750&edit_nonce=2de45bf97b&return=editpost

So to fix it (not proud btw). I had to add another validation in both Metabox.php / MediaAccess.php to also allow the execution when ‘page=espresso_events’ and ‘action=edit’

Well that’s it. Hope it helps. Thanks.