您必须打开生成CSS的地方,这可能很复杂,也可能很简单。这完全取决于您决定如何基于业务逻辑生成CSS。
我不知道你是如何加载CSS的,无论如何,我是这样做的-首先,创建你的页面:
public function addAdminMenuPage()
{
    $this->hook_suffix = add_theme_page(
            esc_html__( \'Page Title\', \'my-project\' ),
            esc_html__( \'Page Title\', \'my-project\' ),
            \'manage_options\', \'my-page-handle\',
            [ $this, \'myPageContent\' ]
        );
}
add_action( \'admin_menu\', [$this, \'addAdminMenuPage\' ], 80 );
 然后,
enqueue its CSS completely based on the suffix, making sure that your CSS only loads on that page, in the correct order:public function generatePageCSS( $page )
{
    //Very important, will only load your CSS on the right page, not in all the admin area.
    if( !$page == $this->hook_suffix ) {
        return;
    }
    //This will allow you to keep a lot of the logic in different parts.
    do_action( \'page-\' . $page . \'-css\', $page );
}
add_action( \'admin_enqueue_scripts\', [$this, \'enqueuePageCSS\'] );
 这意味着对于所有CSS逻辑,您将使用
page-my-page-handle-css, 它可以是多个CSS队列、对页面的内联写入等等。但是现在你把所有的CSS都按正确的顺序设置好了,这似乎是你最初的问题。
因此,您正在将页面添加到admin_menu 钩子,然后将脚本排入admin_enqueue_scripts 钩住,检查生成的后缀是否来自add_theme_page 匹配从admin_enqueue_scripts, 您运行此操作的“主要类”是:
class MyAdminPage
{
    public function __construct()
    {
        add_action( \'admin_menu\', [$this, \'addAdminMenuPage\' ], 80 );
        add_action( \'admin_enqueue_scripts\', [$this, \'enqueuePageCSS\'] );
    }
    ..
    ..
    //Here you\'ll put the hooking functions
    ..
    ..
}
 再说一次,只要你能保持
generatePageCSS 用钩子“打开”,也许你可以走了。