doutouman6245 2014-05-10 05:52
浏览 37

Enque_scripts函数不能在wordpress插件中的构造函数中工作

I'm having trouble loading more than 1 javascript file for my plugin, basically they are conflicting with each other and I need to load a specific file for a specific admin page (settings, posts).

Previously I have just been using wp_enque_scripts but now that i have switched to a seperate function to apply some logic to what scripts are loaded nothing works.

public function __construct(){

        $options = get_option($this->option_name);
        add_action( 'init', array($this,'init'));

        add_action('admin_enqueue_scripts', 'cz_load_scripts');


        wp_enqueue_script('jquery-ui-dalog');
        add_action('media_buttons', array($this,'link_add_button_to_editor'));
        add_action('admin_init', array($this, 'admin_init'));
        add_action('admin_menu', array($this, 'add_page'));

        register_activation_hook(CZ_LINK_FILE, array($this, 'activate'));
    }


public function cz_load_scripts($hook) {

    $options = get_option($this->option_name);

    if( $hook == 'post.php' || $hook == 'post-new.php' ) {
        wp_enqueue_style('add-link-css', plugins_url('/add-link.css',  CZ_LINK_FILE));
        wp_enqueue_script('add-link-js', plugins_url('/add-link.js',  CZ_LINK_FILE), array('jquery'));
        wp_localize_script('add-link-js', 'php_data', $options);
    }

    if( $hook == 'options-general.php') {
        //Adds in Custom Javascript for my admin page
        wp_enqueue_script('calzonic-admin', plugins_url('/calzonic-admin.js',  CZ_LINK_FILE), array('jquery'));
        //localizes the script so my admin js can use the php options for auth
        wp_localize_script('calzonic-admin', 'admin_data', $options);
    }


}

Can anyone tell me why my command add_action('admin_enqueue_scripts', 'cz_load_scripts'); doesnt call my function or let me know if there is a better way to structure what I am trying to do?

Additional Information:

Paths set in the high level php file here:

define('CZ_LINK_FILE', __FILE__);
define('CZ_LINK_PATH', plugin_dir_path(__FILE__));

require CZ_LINK_PATH.'includes/czLink.php';

new czLink();
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥40 复杂的限制性的商函数处理
    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码