Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created April 11, 2017 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tommcfarlin/30521dcf0c493283327bf9162c7b9a35 to your computer and use it in GitHub Desktop.
Save tommcfarlin/30521dcf0c493283327bf9162c7b9a35 to your computer and use it in GitHub Desktop.
[WordPress] WordPress Plugin Interfaces: Working With Assets
<?php
namespace Acme\Admin\Interfaces;
interface Asset {
public function init();
public function enqueue();
}
<?php
namespace Acme\Admin;
use Acme\Admin\Interfaces;
class JavaScript_Assets implements Interfaces\Asset {
private $assets_dir;
private $js_dir;
public function __construct() {
$this->assets_dir = trailingslashit(
plugin_dir_url( __FILE__ ) . 'assets'
);
$this->js_dir = trailingslashit( $this->assets_dir . 'js' );
}
public function init() {
add_action(
'admin_enqueue_scripts',
array( $this, 'enqueue' )
);
}
public function enqueue() {
wp_enqueue_script(
'toggle-admin-notices',
$this->js_dir . 'admin.js',
array( 'jquery' ),
false
);
}
}
<?php
$assets = new Admin\JavaScript_Assets();
$assets->init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment