未使用wp_enQueue_style应用css

时间:2012-06-27 作者:Todd

我试图在插件中加载我的样式表,但它们没有被调用,但是javascript文件正在加载。

<?php
/**
Plugin Name: 
Plugin URI: 
Description: 
Version:
Author: 
Author URI: 
**/

define("MPF_PATH", ABSPATH . \'wp-content/plugins/\' . basename(dirname(__FILE__)).\'/\' );
define("MPF_URL", trailingslashit(get_option(\'siteurl\')) . \'wp-content/plugins/\' . basename(dirname(__FILE__)) . \'/\' ); 


class mpf_plugin{

function crf_user_registration(){
    add_action(\'plugins_loaded\', array(&$this, "load_my_scripts"));
    add_action(\'admin_menu\', array(&$this,\'add_crf_menu_items\'));

    if(!is_admin()){
        add_shortcode(\'crf_registration\', array(&$this, "do_shortcode"));
    } else {
        //do something else here

    }
}

function load_my_scripts(){
    if(is_admin()){
        wp_register_script(\'crf_script\', MPF_URL . \'includes/js/crf_script.js\');
        wp_register_style(\'crf_style\', MPF_URL . \'includes/css/crf_style.css\');
        wp_enqueue_style(\'crf-style\');

        wp_enqueue_script(\'jquery\');
        wp_enqueue_script(\'crf_script\');

        wp_localize_script( \'crf_script\', \'MyAjax\', array( \'MPF_PATH\' => MPF_PATH, \'MPF_URL\' => MPF_URL,\'ajaxurl\' => MPF_URL . \'includes/save-layout.php\', \'loadPageLayoutURL\' => MPF_URL . \'includes/get-layout.php\', \'optionsPageURL\' => MPF_URL . \'includes/options.php\' ));
    }
}


function do_shortcode(){

    include(\'crf_form.php\');
}


function options_page() {
    // HTML code goes here, left out for brevity
}

function custom_dropdown_page(){
    // HTML code goes here, left out for brevity
}

function add_crf_menu_items() {
    add_menu_page(
            \'My Plugin Form\', 
            \'MPF\', 
            \'manage_options\', 
            \'mpf-options\', 
            array(&$this,\'options_page\')
        );

    add_submenu_page(
            \'mpf-options\', 
            \'MPF Options\', 
            \'MPF Options\', 
            \'manage_options\', 
            \'custom-mpf-options\', 
            array(&$this,\'custom_dropdown_page\')
        );
}

}

new mpf_plugin();
路径都是正确的。有什么想法吗?

1 个回复
SO网友:Milo

我猜是因为plugins_loaded 为时尚早,无法将样式排队。这个wp_enqueue_scripts 操作是将脚本和样式排入队列的适当操作。

结束

相关推荐

如何将WordPress的CSS样式应用到jQueryUi对话框中?

我正在开发一个wordpress插件,并成功地使用jQuery显示了一个模式对话框。问题是,我还将列表和按钮显示到该对话框中,我希望这些按钮和列表看起来像wordpress中的按钮和列表。换句话说,我希望我的对话框“继承”WP样式,以便按钮和列表看起来很好。我会非常感谢你的帮助,因为(如果你想叫我傻瓜的话)我已经花了三天时间在这上面了。谢谢