Active class not working on custom menu link using add_menu_page

Well, it is quite a hack I propose, but I would suggest the following:

add_action( 'admin_head', 'chg_menu_on_special_pages_page' );
function chg_menu_on_special_pages_page(){
    global $parent_file;
    $gallery_page_id = 2;
    if( $parent_file != 'edit.php?post_type=page' )
        return;

    if( ! isset( $_GET['post'] ) || $_GET['post'] != $gallery_page_id )
        return;

    $parent_file="post.php?post=". $gallery_page_id .'&action=edit';
    return;
}

By the global $parent_file it is decided, which menu gets highlighted. We hook into the admin_head-action, the last action hook before the menu gets displayed. WordPress already decided, which is the $parent_file, in the case of your gallery it would be the “edit.php?post_type=page”.

So, what do we do? We check if we are on our “Gallery”-Edit page and if so, we switch $parent_file to the URL, we’ve registered earlier using add_menu_page(). In my code, I was setting $gallery_page_id = 2; to test it.

Files in the admin, you might be interested in are wp-admin/menu-header.php. Variables, which you might be interested in are $menu, $submenu, $parent_file.

I hope, this helps you.