Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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
You can’t perform that action at this time.