PHP code example of spenserhale / wp-autohook-library
1. Go to this page and download the library: Download spenserhale/wp-autohook-library 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/ */
spenserhale / wp-autohook-library example snippets
#[Hook('cli_init', priority: 9)]
public static function registerCommand(): void {}
#[Hook('rest_api_init')]
public static function registerController(): void {}
#[Hook('wp_init', 99)]
public static function boot(): void {}
#[Hook(priority: 100, tag: 'pre_update_option')]
public static function filterOption(string $value): string {}
// Stacked attributes
#[Hook('wp_insert_blog_meta')]
#[Hook('wp_insert_post_meta')]
public static function logInsert(array $data, array $postarr): array {}
// Comma-separated (same line)
#[Hook('update_post_meta'), Hook('update_option_meta')]
public static function logChange(mixed $old_value, mixed $new_value): void {}
#[Shortcode('example_shortcode')]
public static function shortcode(): string {}
abstract class AbstractAdminPage
{
public static function registerPage(): void {}
public static function renderPage(): void {}
}
#[Hook('admin_menu', callback: 'registerPage')]
#[Hook('admin_init', callback: 'renderPage')]
class SettingsPage extends AbstractAdminPage
{
// Inherited methods are hooked via class-level attributes
}
namespace ACME;
#[Hook('facade_example_hook', callback: 'facadeMethod', arguments: 3)]
#[Shortcode('other_shortcode', 'otherShortcode')]
class ExamplesClass
{
#[Hook('cli_init', priority: 9)]
public static function registerCommand(): void {}
#[Hook('rest_api_init')]
public static function registerController(): void {}
#[Hook('wp_init', 99)]
public static function boot(): void {}
#[Hook(priority: 100, tag: 'pre_update_option')]
public static function filterOption(string $value): string {}
#[Hook('wp_insert_blog_meta')]
#[Hook('wp_insert_post_meta')]
public static function logInsert(array $data, array $postarr): array {}
#[Hook('update_post_meta'), Hook('update_option_meta')]
public static function logChange(mixed $old_value, mixed $new_value): void {}
#[Shortcode('example_shortcode')]
public static function shortcode(): string {}
public static function facadeMethod($arg1, $arg2, $arg3): mixed {}
public static function otherShortcode(): string {}
}
// Get the list of classes
$classes = \SH\AutoHook\ComposerJsonParser::getClasses($composerJsonPath);
// Process classes to string
[$output] = \SH\AutoHook\AttributeResolver::processClassesToString($classes);
// Write to file
(bool) $written = \SH\AutoHook\FileWriter::write($output, $outputPath);
// Get Classloader object
$loader = s = \SH\AutoHook\ComposerClassLoaderParser::getClasses($loader, ['App\\', 'MyNamespace\\']);
// Process classes to string
[$output] = \SH\AutoHook\AttributeResolver::processClassesToString($classes);
// Write to file
(bool) $written = \SH\AutoHook\FileWriter::write($output, $outputPath);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.