PHP code example of simplemediacode / hooks

1. Go to this page and download the library: Download simplemediacode/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/ */

    

simplemediacode / hooks example snippets


use Simplemediacode\Hooks\Hooks;

// Add a filter
Hooks::addFilter('content', function($content) {
    return strtoupper($content);
});

// Apply a filter
$content = Hooks::applyFilters('content', 'Hello World'); // Returns "HELLO WORLD"

// Add an action
Hooks::addAction('save_post', function($postId) {
    // Do something when a post is saved
    echo "Post {$postId} was saved!";
});

// Execute an action
Hooks::doAction('save_post', 123);

use Simplemediacode\Hooks\HooksInterface;

class MyClass
{
    private ?HooksInterface $hooks;

    public function __construct(
        ?HooksInterface $hooks = null
    ) {
        $this->hooks = $hooks;
    }
    
    public function processContent(string $content): string
    {
        // If hooks are available, filter the content
        if ($this->hooks) {
            $content = $this->hooks->executeHook('content', $content);
        }
        
        return $content;
    }
}

$customHooks = new MyCustomHooksImplementation();
Hooks::setInstance($customHooks);