添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Actions and filters are so awesome in WordPress. They provide a very simple and powerful way to customization the WordPress core. So, Plugins and themes can execute code before or after a specified event or change the result of many core functions. On the web, I found a few discussion about the Javascript porting of actions and filters .

In my first experiment, I used the jQuery triggerHandler() featured in order to create something like add_action() as well as add_filter() . In other words, the do_action() becomes $( document ).triggerHandler( 'my_custom_event') and the add_action() becomes $( document ).on( 'my_custom_event', ... ) .

However, this approach has some limitations. First of all, is not possible to handle the priority feature: executing sequence. The function add_action(), in fact, supports the priority param in order to run a hook in a specified order. Also, triggerHandler() can return a result. This is great for “emule” add_filter() function but could make a mess.

Rewrite

This implementation is more beautiful and provides a more like experience of actions and filters in Javascript.

Follow me on Twitter

Categories

  • Development
  • ActionScript
  • Papervision3D
  • Javascript
  • jQuery
  • Laravel
  • MySQL/SQL
  • NextJS
  • Objective-C
  • ReactJS
  • Styled Components
  • TypeScript
  • Very Short Snippet
  • Very Short Trick
  • Graphics & Design
  • Photoshop
  • Personal
  • Retrò
  • Tutorials
  • Videogames
  • WordPress
  • WP Bones

    Privacy Overview

    This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
    Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
  •