/00-interface-asset.php Secret
Created
April 11, 2017 13:43
[WordPress] WordPress Plugin Interfaces: Working With Assets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\Admin\Interfaces; | |
interface Asset { | |
public function init(); | |
public function enqueue(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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