WordPress.org

Make WordPress Core

Changeset 41375


Ignore:
Timestamp:
09/12/17 12:53:21 (10 days ago)
Author:
adamsilverstein
Message:

Add wp.hooks - JavaScript actions and filters.

Add a JavaScript hooks library with an API that mirrors the WordPress Plugin API; provides similar functionality and API to PHP hooks.

Called via the global wp.hooks, eg: wp.hooks.addAction(), etc. Adds:

  • addAction( 'hook', 'vendor/plugin/function', callback, priority )
  • addFilter( 'hook', 'vendor/plugin/function', callback, priority )
  • removeAction( 'hook', 'vendor/plugin/function' )
  • removeFilter( 'hook', 'vendor/plugin/function' )
  • removeAllActions( 'hook' )
  • removeAllFilters( 'hook' )
  • doAction( 'hook', arg1, arg2, moreArgs, finalArg )
  • applyFilters( 'hook', content, arg1, arg2, moreArgs, finalArg )
  • doingAction( 'hook' )
  • doingFilter( 'hook' )
  • didAction( 'hook' )
  • didFilter( 'hook' )
  • hasAction( 'hook' )
  • hasFilter( 'hook' )

Props adamsilverstein, jnylen0, aduth, kadamwhite, youknowriad, schlessera, mikeschinkel, azaozz, vhauri, CaptainN, scribu, carldanley, chetanchauhan, mgibbs189, stephenharris, justnorris, koopersmith, gcorne, TV productions, atimmer.

Fixes #21170.

Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Gruntfile.js

    r41351 r41375  
    370370                    '!wp-includes/js/tw-sack.js', 
    371371                    '!wp-includes/js/twemoji.js', 
    372                     '!**/*.min.js' 
     372                    '!**/*.min.js', 
     373                    '!wp-includes/js/wp-hooks.js' 
    373374                ], 
    374375                // Remove once other JSHint errors are resolved 
  • trunk/src/wp-includes/plugin.php

    r41308 r41375  
    364364 
    365365/** 
    366  * Retrieve the name of an action currently being processed. 
     366 * Retrieve whether action currently being processed. 
    367367 * 
    368368 * @since 3.9.0 
  • trunk/src/wp-includes/script-loader.php

    r41374 r41375  
    8585 
    8686    $scripts->add( 'wp-a11y', "/wp-includes/js/wp-a11y$suffix.js", array( 'jquery' ), false, 1 ); 
     87 
     88    $scripts->add( 'wp-hooks', "/wp-includes/js/wp-hooks$suffix.js", array(), false, 1 ); 
    8789 
    8890    $scripts->add( 'sack', "/wp-includes/js/tw-sack$suffix.js", array(), '1.6.1', 1 ); 
  • trunk/tests/qunit/index.html

    r41374 r41375  
    7878        <script src="../../src/wp-includes/js/customize-models.js"></script> 
    7979        <script src="../../src/wp-includes/js/shortcode.js"></script> 
     80        <script src="../../src/wp-includes/js/wp-hooks.js"></script> 
    8081        <script src="../../src/wp-admin/js/customize-controls.js"></script> 
    8182        <script src="../../src/wp-includes/js/api-request.js"></script> 
     
    126127        <script src="wp-includes/js/shortcode.js"></script> 
    127128        <script src="wp-includes/js/api-request.js"></script> 
     129        <script src="wp-includes/js/wp-hooks.js"></script> 
    128130        <script src="wp-includes/js/wp-api.js"></script> 
    129131        <script src="wp-admin/js/customize-controls.js"></script> 
Note: See TracChangeset for help on using the changeset viewer.