Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wordpress/hooks

Package Overview
Dependencies
Maintainers
23
Versions
164
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wordpress/hooks

WordPress hooks library.

  • 4.7.1-next.5368f64a9.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
142K
decreased by-12.06%
Maintainers
23
Weekly downloads
 
Created

What is @wordpress/hooks?

@wordpress/hooks is a library that provides a way to manage and trigger custom actions and filters in JavaScript. It is inspired by the WordPress PHP hooks system and allows developers to add, remove, and execute custom hooks in their JavaScript applications.

What are @wordpress/hooks's main functionalities?

Adding Actions

This feature allows you to add custom actions that can be triggered at specific points in your application. The code sample demonstrates how to add an action named 'myCustomAction' in the 'myNamespace' namespace.

const { addAction } = require('@wordpress/hooks');

addAction('myCustomAction', 'myNamespace', () => {
  console.log('Action triggered!');
});

Doing Actions

This feature allows you to trigger actions that have been added. The code sample demonstrates how to trigger the 'myCustomAction' action, which will execute any functions hooked to it.

const { doAction } = require('@wordpress/hooks');

doAction('myCustomAction');

Adding Filters

This feature allows you to add custom filters that can modify data at specific points in your application. The code sample demonstrates how to add a filter named 'myCustomFilter' in the 'myNamespace' namespace, which appends ' filtered' to the input value.

const { addFilter } = require('@wordpress/hooks');

addFilter('myCustomFilter', 'myNamespace', (value) => {
  return value + ' filtered';
});

Applying Filters

This feature allows you to apply filters to data, modifying it according to the functions hooked to the filter. The code sample demonstrates how to apply the 'myCustomFilter' filter to the string 'original value', resulting in 'original value filtered'.

const { applyFilters } = require('@wordpress/hooks');

const result = applyFilters('myCustomFilter', 'original value');
console.log(result); // Outputs: 'original value filtered'

Other packages similar to @wordpress/hooks

Keywords

FAQs

Package last updated on 12 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc