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();