@MWP\WordPress\Script( deps={"jquery"}, ver=false, footer=false, always=false )
Using this annotation will register a script from your plugin to be used on WordPress pages. The script will be registered with the core WordPress function wp_enqueue_script()
. The value of the annotated property should be the relative path from your plugin basedir to the script resource.
@Params
deps={"jquery"}
(optional) / {default: {}} – Names of any dependencies that this script has
ver=false
(optional) / {default: false} – Script version number, or false to generate automatically
footer=false
(optional) / {default: false} – Enqueue the script in the footer instead of in the head
always=false
(optional) / {default: false} – If true, script will automatically be enqueued on every page
handle="script-name"
(optional) – Specify a handle for your script to use when it is registered
@Example Code
/**
* The main plugin javascript module
*
* @MWP\WordPress\Script( deps={"jquery"}, ver=false, footer=false, always=false )
*
* @var string
*/
public $mainScript = "assets/js/main.js";
/**
* Enqueue our javascript
*
* @MWP\WordPress\Action( for="wp_enqueue_scripts" )
*
* @return void
*/
public function enqueueScripts()
{
if ( is_page( $this->getSetting( 'plugin_page' ) ) || is_singular( 'custompost' ) )
{
$this->useScript( $this->mainScript );
}
}