Download the PHP package syntatis/wp-hook without Composer

On this page you can find all versions of the php package syntatis/wp-hook. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package wp-hook

🪝 wp-hook

Packagist Dependency Version wp codecov

[!CAUTION] This package is now part of Codex.

A class wrapper designed to use WordPress hooks with object-oriented programming (OOP), inspired by the WordPress Plugin Boilerplate. This class helps you stay organized and maintain structure when managing hooks in your WordPress plugin or theme.

Installation

Install the package via Composer:

Usage

Create a new instance of the Registry class and register your hooks:

Using PHP Attributes

If your theme or plugin runs on PHP 8.0 or later, you can leverage PHP Attributes to define hooks directly within your classes:

[!NOTE] Attributes will only be applied to non-abstract public methods that are not PHP native methods or any methods that begin with __ like __constructor, __clone, and __callStatic. If you add the Attributes at the class level, the class should implement the __invoke method, as shown in the above example.

Removing Hook

You can also remove a hook similarly to how you would with the native WordPress functions:

It is also possible to remove all hooks at once:

It is possible to attach hook with method from an object instance, a static method, or a closure:

However, this makes it rather tricky to remove the hook later on the code since you need to pass the same object instance or the same reference to the anonymous function to the removeAction and removeFilter methods, which is not always possible.

To circumvent this, you can pass id to the addAction and addFilter methods, and refer the id using @ symbol when removing the hook. For example:

[!IMPORTANT] The ID must be all lowercase and use words separated by -, ., or _. It should not have any uppercase letters, spaces, or special characters. You can use a slash (/) to define the namespace, like acme/hello-world, to avoid conflicts with other plugins or themes. Please note that the ID added within the registry must be unique. If you're trying to add the same ID twice, it will throw an exception.

References


All versions of wp-hook with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package syntatis/wp-hook contains the following files

Loading the files please wait ...