Loading your own scripts and styles in Addofy
Queue your own scripts and stylesheets through Addofy instead of wp_enqueue_script(). They then follow Addofy's loading rules: never on the frontend, never in safe mode (?adba_safe=1 or the ADBA_SAFE_MODE constant) and never on an excluded screen.
Queue a script and a stylesheet
add_action( 'adba_screen', static function ( $screen ) {
adba( 'assets' )->enqueue_external(
'myplugin-admin', // Unique handle, prefixed with your slug.
plugins_url( 'build/admin.js', __FILE__ ),
array( 'adba-core' ), // Needed for window.adba.
'1.2.0'
);
adba( 'assets' )->enqueue_external( 'myplugin-admin-css', plugins_url( 'build/admin.css', __FILE__ ) );
} );
Rules
- The type follows the URL (a
.cssfile is a stylesheet) or the fifth argument (scriptorstyle). - Addofy's own handles cannot be replaced.
- Depend on
adba-corewhen your script useswindow.adba. - For a stylesheet that must load after the dark mode colors, depend on
adba-module-darkmode-css. - The handles
adba-module-design,adba-module-shell,adba-module-notices,adba-module-searchandadba-module-helpstay registered as aliases ofadba-core, so an older dependency on them keeps working.
When to call it
Call enqueue_external() from the adba_screen action or from a module's on_screen(). Both run only when Addofy is active on the current screen, so you do not need to check the screen yourself.