1. Go to this page and download the library: Download morningtrain/wp-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/ */
morningtrain / wp-hooks example snippets
// Load all .php files in ./Hooks and add all found Hooks
\Morningtrain\WP\Hooks\Hook::loadDir(__DIR__ . "/App/Hooks");
// Load all .php files in ./Hooks and add all found Hooks
\Morningtrain\WP\Hooks\Hook::loadDir([__DIR__ . "/App/Hooks",__DIR__ . "/EvenMoreHooks"]);
\Morningtrain\WP\Hooks\Hook::action('init',[Some::class, 'someMethod']);
// is the same as
\Morningtrain\WP\Hooks\Hook::action('init')
->handle([Some::class, 'someMethod']);
// With a priority
\Morningtrain\WP\Hooks\Hook::action('init')
->priority(20)
->handle([Some::class, 'someMethod']);
// Rendering a view
\Morningtrain\WP\Hooks\Hook::action('init')
->view('some_view');
\Morningtrain\WP\Hooks\Hook::filter('mime_types',[Some::class, 'addSvgMimeType']);
// is the same as
\Morningtrain\WP\Hooks\Hook::filter('mime_types')
->filter([Some::class, 'addSvgMimeType']);
// With a priority
\Morningtrain\WP\Hooks\Hook::filter('mime_types')
->priority(20)
->filter([Some::class, 'addSvgMimeType']);
// For simple filters that return true or false
\Morningtrain\WP\Hooks\Hook::filter('use_some_feature')
->returnTrue();
\Morningtrain\WP\Hooks\Hook::filter('use_some_feature')
->returnFalse();
// This will render the footer/copyright view in the footer
\Morningtrain\WP\Hooks\Hook::view('footer','footer/copyright');
// An action that looks something like this: do_action('some_post_action',$postId);
\Morningtrain\WP\Hooks\Hook::view('some_post_action','someView');
\Morningtrain\WP\View\View::composer('some_post_action',function($view){
[$postId] = $view;
$view->with('postId',$postId);
});
class FilterMimeTypes{
public function __invoke(array $mimeTypes)
{
$mimeTypes['webp'] = 'image/webp';
return $mimeTypes;
}
}
\Morningtrain\WP\Hooks\Hook::filter('mime_types',FilterMimeTypes::class);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.