getpop / hooks
Contracts to implement hooks (filters and actions) for PoP
Requires
- php: ^8.0
- getpop/translation: ^0.8.9
Requires (Dev)
- phpstan/phpstan: ^1.0
- phpunit/phpunit: >=9.3
- rector/rector: ^0.12
- squizlabs/php_codesniffer: ^3.0
Conflicts
- getpop/access-control: <0.8.9
- getpop/api: <0.8.9
- getpop/api-clients: <0.8.9
- getpop/api-endpoints: <0.8.9
- getpop/api-endpoints-for-wp: <0.8.9
- getpop/api-graphql: <0.8.9
- getpop/api-mirrorquery: <0.8.9
- getpop/api-rest: <0.8.9
- getpop/application: <0.8.9
- getpop/application-wp: <0.8.9
- getpop/cache-control: <0.8.9
- getpop/component-model: <0.8.9
- getpop/component-model-configuration: <0.8.9
- getpop/definitionpersistence: <0.8.9
- getpop/definitions: <0.8.9
- getpop/definitions-base36: <0.8.9
- getpop/definitions-emoji: <0.8.9
- getpop/engine: <0.8.9
- getpop/engine-wp: <0.8.9
- getpop/engine-wp-bootloader: <0.8.9
- getpop/field-query: <0.8.9
- getpop/filestore: <0.8.9
- getpop/function-fields: <0.8.9
- getpop/guzzle-helpers: <0.8.9
- getpop/hooks-wp: <0.8.9
- getpop/loosecontracts: <0.8.9
- getpop/mandatory-directives-by-configuration: <0.8.9
- getpop/modulerouting: <0.8.9
- getpop/multisite: <0.8.9
- getpop/query-parsing: <0.8.9
- getpop/resourceloader: <0.8.9
- getpop/resources: <0.8.9
- getpop/root: <0.8.9
- getpop/routing: <0.8.9
- getpop/routing-wp: <0.8.9
- getpop/site: <0.8.9
- getpop/site-builder-api: <0.8.9
- getpop/site-wp: <0.8.9
- getpop/spa: <0.8.9
- getpop/static-site-generator: <0.8.9
- getpop/translation-wp: <0.8.9
- graphql-api/extension-demo: <0.8.9
- graphql-api/external-dependency-wrappers: <0.8.9
- graphql-api/graphql-api-for-wp: <0.8.9
- graphql-api/markdown-convertor: <0.8.9
- graphql-by-pop/graphiql: <0.8.9
- graphql-by-pop/graphql-clients-for-wp: <0.8.9
- graphql-by-pop/graphql-endpoint-for-wp: <0.8.9
- graphql-by-pop/graphql-parser: <0.8.9
- graphql-by-pop/graphql-query: <0.8.9
- graphql-by-pop/graphql-request: <0.8.9
- graphql-by-pop/graphql-server: <0.8.9
- graphql-by-pop/graphql-voyager: <0.8.9
- pop-schema/block-metadata-for-wp: <0.8.9
- pop-schema/categories: <0.8.9
- pop-schema/categories-wp: <0.8.9
- pop-schema/comment-mutations: <0.8.9
- pop-schema/comment-mutations-wp: <0.8.9
- pop-schema/commentmeta: <0.8.9
- pop-schema/commentmeta-wp: <0.8.9
- pop-schema/comments: <0.8.9
- pop-schema/comments-wp: <0.8.9
- pop-schema/custompost-categories-wp: <0.8.9
- pop-schema/custompost-category-mutations: <0.8.9
- pop-schema/custompost-mutations: <0.8.9
- pop-schema/custompost-mutations-wp: <0.8.9
- pop-schema/custompost-tag-mutations: <0.8.9
- pop-schema/custompost-tags-wp: <0.8.9
- pop-schema/custompostmedia: <0.8.9
- pop-schema/custompostmedia-mutations: <0.8.9
- pop-schema/custompostmedia-mutations-wp: <0.8.9
- pop-schema/custompostmedia-wp: <0.8.9
- pop-schema/custompostmeta: <0.8.9
- pop-schema/custompostmeta-wp: <0.8.9
- pop-schema/customposts: <0.8.9
- pop-schema/customposts-wp: <0.8.9
- pop-schema/generic-customposts: <0.8.9
- pop-schema/media: <0.8.9
- pop-schema/media-wp: <0.8.9
- pop-schema/menus: <0.8.9
- pop-schema/menus-wp: <0.8.9
- pop-schema/meta: <0.8.9
- pop-schema/metaquery-wp: <0.8.9
- pop-schema/pages: <0.8.9
- pop-schema/pages-wp: <0.8.9
- pop-schema/post-categories: <0.8.9
- pop-schema/post-categories-wp: <0.8.9
- pop-schema/post-category-mutations: <0.8.9
- pop-schema/post-category-mutations-wp: <0.8.9
- pop-schema/post-mutations: <0.8.9
- pop-schema/post-tag-mutations: <0.8.9
- pop-schema/post-tag-mutations-wp: <0.8.9
- pop-schema/post-tags: <0.8.9
- pop-schema/post-tags-wp: <0.8.9
- pop-schema/postmedia-mutations: <0.8.9
- pop-schema/posts: <0.8.9
- pop-schema/posts-wp: <0.8.9
- pop-schema/queriedobject: <0.8.9
- pop-schema/queriedobject-wp: <0.8.9
- pop-schema/schema-commons: <0.8.9
- pop-schema/settings: <0.8.9
- pop-schema/settings-wp: <0.8.9
- pop-schema/tags: <0.8.9
- pop-schema/tags-wp: <0.8.9
- pop-schema/taxonomies: <0.8.9
- pop-schema/taxonomies-wp: <0.8.9
- pop-schema/taxonomymeta: <0.8.9
- pop-schema/taxonomymeta-wp: <0.8.9
- pop-schema/taxonomyquery: <0.8.9
- pop-schema/taxonomyquery-wp: <0.8.9
- pop-schema/user-avatars: <0.8.9
- pop-schema/user-avatars-wp: <0.8.9
- pop-schema/user-roles: <0.8.9
- pop-schema/user-roles-access-control: <0.8.9
- pop-schema/user-roles-acl: <0.8.9
- pop-schema/user-roles-wp: <0.8.9
- pop-schema/user-state: <0.8.9
- pop-schema/user-state-access-control: <0.8.9
- pop-schema/user-state-mutations: <0.8.9
- pop-schema/user-state-mutations-wp: <0.8.9
- pop-schema/user-state-wp: <0.8.9
- pop-schema/usermeta: <0.8.9
- pop-schema/usermeta-wp: <0.8.9
- pop-schema/users: <0.8.9
- pop-schema/users-wp: <0.8.9
- pop-sites-wassup/comment-mutations: <0.8.9
- pop-sites-wassup/contactus-mutations: <0.8.9
- pop-sites-wassup/contactuser-mutations: <0.8.9
- pop-sites-wassup/custompost-mutations: <0.8.9
- pop-sites-wassup/custompostlink-mutations: <0.8.9
- pop-sites-wassup/flag-mutations: <0.8.9
- pop-sites-wassup/form-mutations: <0.8.9
- pop-sites-wassup/gravityforms-mutations: <0.8.9
- pop-sites-wassup/highlight-mutations: <0.8.9
- pop-sites-wassup/newsletter-mutations: <0.8.9
- pop-sites-wassup/notification-mutations: <0.8.9
- pop-sites-wassup/post-mutations: <0.8.9
- pop-sites-wassup/postlink-mutations: <0.8.9
- pop-sites-wassup/share-mutations: <0.8.9
- pop-sites-wassup/socialnetwork-mutations: <0.8.9
- pop-sites-wassup/stance-mutations: <0.8.9
- pop-sites-wassup/system-mutations: <0.8.9
- pop-sites-wassup/user-state-mutations: <0.8.9
- pop-sites-wassup/volunteer-mutations: <0.8.9
- pop-wp-schema/comments: <0.8.9
- pop-wp-schema/customposts: <0.8.9
- pop-wp-schema/media: <0.8.9
- pop-wp-schema/menus: <0.8.9
- pop-wp-schema/pages: <0.8.9
- pop-wp-schema/posts: <0.8.9
- pop-wp-schema/schema-commons: <0.8.9
- pop-wp-schema/users: <0.8.9
README
Contracts to implement hooks for PoP. The concept of a “hook” is the same as in WordPress: an “action” allows executing extra functionality, and a “filter” allows to modify a value.
Install
Via Composer
composer require getpop/hooks
Development
The source code is hosted on the PoP monorepo, under Engine/packages/hooks
.
Usage
Initialize the component:
\PoP\Root\App::stockAndInitializeComponentClasses([([ \PoP\Hooks\Component::class, ]);
Use it:
use PoP\Hooks\Facades\HooksAPIFacade; // Get an instance of the service $hooksapi = HooksAPI::getInstance(); // Add a hook for an Action $hooksapi->addAction($actionName, $functionName, $priority, $argNum); // Add a hook for a Filter $hooksapi->addFilter($filterName, $functionName, $priority, $argNum); // Execute an Action $hooksapi->doAction($actionName, $param1, $param2, ...); // Execute a Filter $filterValue = $hooksapi->applyFilters($filterName, $filterValue, $param1, $param2, ...); // Remove an Action $hooksapi->removeAction($actionName, $functionName, $priority, $argNum); // Remove a Filter $hooksapi->removeFilter($filterName, $functionName, $priority, $argNum);
Architecture Design and Implementation
Hooks
PoP uses hooks (as pioneered by WordPress) everywhere, through both functions doAction
and applyFilters
as defined through interface HooksAPI
, allowing any piece of code to be overridable by any 3rd party, or be injected extra functionality. For WordPress, the implementation of the interface is trivial. Other systems can rely on packages to implement this functionality (eg: this one or this one).
PHP versions
Requirements:
- PHP 8.0+ for development
- PHP 7.1+ for production
Supported PHP features
Check the list of Supported PHP features in leoloso/PoP
Preview downgrade to PHP 7.1
Via Rector (dry-run mode):
composer preview-code-downgrade
Standards
To check the coding standards via PHP CodeSniffer, run:
composer check-style
To automatically fix issues, run:
composer fix-style
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
To execute PHPUnit, run:
composer test
Static Analysis
To execute PHPStan, run:
composer analyse
Report issues
To report a bug or request a new feature please do it on the PoP monorepo issue tracker.
Contributing
We welcome contributions for this package on the PoP monorepo (where the source code for this package is hosted).
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email leo@getpop.org instead of using the issue tracker.
Credits
License
GNU General Public License v2 (or later). Please see License File for more information.