Skip to content

wpbones/actions-and-filters-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WordPress actions and filters implementation for Javascript

Latest Stable Version Latest Unstable Version Total Downloads License Monthly Downloads

A Javascript version of the actions and filters used in PHP in WordPress for WP Bones.

Requirements

This package works with a WordPress plugin written with WP Bones framework library.

Installation

You can install third party packages by using:

php bones require wpbones/actions-and-filters-js

I advise to use this command instead of composer require because doing this an automatic renaming will done.

You can use composer to install this package:

composer require wpbones/actions-and-filters-js

You may also to add "wpbones/actions-and-filters-js": "^1.0" in the composer.json file of your plugin:

  "require": {
    "php": ">=7.4",
    "wpbones/wpbones": "~0.8",
    "wpbones/actions-and-filters-js": "~1.0"
  },

and run

composer install

Alternatively, you can get the single files src/resources/assets/js/actions-and-filters.js in your WP Bones plugin and compile it with gulp. Also, you can get pre-compiled minified version src/public/js/actions-and-filters.min.js.

Enqueue for Controller

You can use the provider to enqueue the styles.

public function index()
{
  // enqueue the minified version
  ActionsAndFiltersJSProvider::enqueueScripts();

  // ...

}

ActionsAndFiltersJSProvider

This is a static class autoloaded by composer. You can use it to enqueue or get the styles path:

// enqueue the minified version
ActionsAndFiltersJSProvider::enqueueScripts();

// enqueue the flat version
ActionsAndFiltersJSProvider::enqueueScripts( false );

// return the absolute path of the minified css
ActionsAndFiltersJSProvider::js();

// return the absolute path of the flat css
ActionsAndFiltersJSProvider::js();

Usage

Let's an example:

wpbones_add_action( 'my-action', function() { alert( "Hello" ) } );

...

wpbones_do_action( 'my-action' );

This Javascript version works in the same way than PHP version in WordPress.