Skip to content

Instantly share code, notes, and snippets.

@richardsweeney
Created March 22, 2016 07:55
Show Gist options
  • Save richardsweeney/757bff6d11780302b321 to your computer and use it in GitHub Desktop.
Save richardsweeney/757bff6d11780302b321 to your computer and use it in GitHub Desktop.
<?php
// in javascript, object properties are accessed as ajax_object.ajax_url, ajax_object.we_value
function pacsoft_enqueue(){
wp_enqueue_script('jquery');
// You can't hardcode the path to a plugin directory. WordPress may rename it.
// Below is incorrect.
// wp_register_script( 'pacsoft-script', plugins_url( '/woocommerce-pacsoft-unifaun/js/pacsoft.js' ) );
// This is correct.
wp_register_script( 'pacsoft-script', plugin_dir_url( __FILE__ ) . 'js/pacsoft.js' );
wp_enqueue_script( 'pacsoft-script' );
}
add_action( 'admin_enqueue_scripts', 'pacsoft_enqueue' );
add_action( 'admin_enqueue_scripts', 'load_pacsoft_admin_style' );
function load_pacsoft_admin_style() {
// The fortnox plugin also enqueues 'admin_css' - this is an ID and must be unique.
// The path to the plugin directory is also hardcoded.
// The stylehsheet below will therefore never be loaded, if it was it would give a 404.
// wp_register_style( 'admin_css', plugins_url( '/woocommerce-pacsoft-unifaun/css/admin-style.css'), false, '1.0.0' );
// wp_enqueue_style( 'admin_css', plugins_url( '/woocommerce-pacsoft-unifaun/css/admin-style.css'), false, '1.0.0' );
// This is correct (it's not necessary to call wp_register_style)
wp_enqueue_style( 'pacsoft_admin_css', plugin_dir_url( __FILE__ ) . 'css/admin-style.css', false, '1.0.0' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment