1. Go to this page and download the library: Download piotrpress/wordpress-hooks 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/ */
piotrpress / wordpress-hooks example snippets
#[ Action( string $name, int $priority = 10 ) ]
#[ Filter( string $name, int $priority = 10 ) ]
use PiotrPress\WordPress\Hooks;
use PiotrPress\WordPress\Hooks\Action;
use PiotrPress\WordPress\Hooks\Filter;
class Example {
public function add_hooks() {
Hooks::add( $this );
}
#[ Action( 'init' ) ]
public function example_init() : void {
// do something
}
#[ Filter( 'the_title', 1 ) ]
public function example_the_title( string $post_title, int $post_id ) : string {
// do something
}
}
$example = new Example();
$example->add_hooks();
Hooks::remove( $example );
use PiotrPress\WordPress\Hooks;
use PiotrPress\WordPress\Hooks\Action;
use PiotrPress\WordPress\Hooks\Filter;
class Example {
public function add_hooks() {
Hooks::add( $this, 'example_init' );
Hooks::add( $this, 'example_the_title' );
}
#[ Action( 'init' ) ]
public function example_init() : void {
// do something
}
#[ Filter( 'the_title', 1 ) ]
public function example_the_title( string $post_title, int $post_id ) : string {
// do something
}
}
$example = new Example();
$example->add_hooks();
Hooks::remove( $example, 'example_init' );
Hooks::remove( $example, 'example_the_title' );
use PiotrPress\Cacher;
use PiotrPress\WordPress\Hooks;
use PiotrPress\WordPress\Hooks\Action;
use PiotrPress\WordPress\Hooks\Filter;
class Example {
#[ Action( 'init' ) ]
public function example_init() : void {
// do something
}
#[ Filter( 'the_title', 1 ) ]
public function example_the_title( string $post_title, int $post_id ) : string {
// do something
}
}
$example = new Example();
$cache = new Cacher( '.hooks' );
Hooks::add( object: $example, cache: $cache );
Hooks::remove( object: $example, cache: $cache );
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.