1. Go to this page and download the library: Download cloakwp/hook-modifiers library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cloakwp / hook-modifiers example snippets
use CloakWP\HookModifiers;
// Apply desired modifiers to an existing hook
HookModifiers::make(['post_type']) // note it accepts an array of multiple modifiers
->forFilter('wp_insert_post_data')
->register();
// Now you can use the modifier when calling the hook to target a specific post type
add_filter('wp_insert_post_data/post_type=page', function ($data, $postarr, $unsanitized_postarr) {
$data['post_title'] = 'Page: ' . $data['post_title'];
return $data;
}, 10, 2);
// The post_type example above is equivalent to:
add_filter('wp_insert_post_data', function ($data, $postarr, $unsanitized_postarr) {
if ($data['post_type'] === 'page') {
$data['post_title'] = 'Page: ' . $data['post_title'];
}
return $data;
}, 10, 2);
HookModifiers::make(['type'])
->forFilter('some_filter_with_many_args')
->modifiersArgPosition(2) // 0 indexed, so the third arg is `2`
->register();
add_filter('some_filter_with_many_args/type=image', function ($one, $two, $three) {
// This filter will only run if the arg $three is an associative array with a property 'type' equal to 'image'
}, 10, 3);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.