I have a small patch that will set $options_page
so the dynamic hook fires at the right time and loads the stylesheet. It sets Maintainn_Tools_Dashboard::options_page
from the hook_suffix returned by add_menu_page()
so it can be added to the right action for the network page.
class Maintainn_Tools_Dashboard {
/**
* The hook suffix for the options page.
*
* @var string
* @since x.x.x
*/
protected $options_page = '';
public function add_network_options_page() {
$this->options_page = add_menu_page(
$this->title,
$this->title,
'manage_options',
$this->key,
array( $this, 'render_page' )
);
// Include CMB CSS in the head to avoid FOUC.
add_action( "admin_print_styles-{$this->options_page}", array( 'CMB2_hookup', 'enqueue_cmb_css' ) );
}
}
-
This reply was modified 6 years, 10 months ago by Jose Castaneda. Reason: fixed code
Sorry for the formatting, here it is again:
class Maintainn_Tools_Dashboard {
/**
* The hook suffix for the options page.
*
* @var string
* @since x.x.x
*/
protected $options_page = '';
public function add_network_options_page() {
$this->options_page = add_menu_page(
$this->title,
$this->title,
'manage_options',
$this->key,
array( $this, 'render_page' )
);
// Include CMB CSS in the head to avoid FOUC.
add_action( "admin_print_styles-{$this->options_page}", array( 'CMB2_hookup', 'enqueue_cmb_css' ) );
}
}
Thanks Morgan, will get this taken care of.
And committed. Thanks again.
I noticed after some more testing that my change only loads the CMB2 stylesheet on the main options page but not any of the tabs. If it needs to load on the tabs pages, that’s a different hook that fires (because if course it is :/).
I’m happy to share another patch to load those styles if they’re needed in the tabs.
As is, it looks like it’s fine. We don’t rely too heavily on CMB2 styles. Mostly the fields themselves and the saving process.