PHP code example of jascha030 / wp-plugin-lib

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

    

jascha030 / wp-plugin-lib example snippets



/**
 * Plugin jascha030/wp-plugin-lib
 *
 * @package   Jascha030
 * @author    Jascha van Aalst
 * @copyright 2021
 * @license   GPL-2.0+
 *
 * @wordpress-plugin
 *
 * Plugin Name: Package Tester
 * Plugin URI: https://github.com/jascha030/wp-plugin-lib
 * Description: Test plugin for package jascha030/wp-plugin-lib
 * Version: 1.0.0
 * Author: Jascha030
 * Author URI: https://github.com/jascha030.
 */

namespace Jascha030;

use Exception;
use Jascha030\PackageTest\Hookable\TestingAfterInitHookable;
use Jascha030\PackageTest\Hookable\TestingHookable;
use Jascha030\PackageTest\PackageTestPlugin;
use Jascha030\PluginLib\Container\Config\ConfigInterface;

use function Jascha030\PluginLib\Functions\buildPlugin;

/**
 * Check if WordPress' ABSPATH const is loaded
 */
if (! defined('ABSPATH')) {
    die('Forbidden');
}

/**
 * Get autoloader
 */
$autoloaderPath = __DIR__.'/vendor/autoload.php';

if (! is_readable($autoloaderPath)) {
    throw new \RuntimeException(sprintf('Could not find file \'%s\'. It is generated by Composer. Use \'install --prefer-source\' or \'update --prefer-source\' Composer commands to move forward.',
        $autoloaderPath));
}




namespace Jascha030\PackageTest\Hookable;

use Jascha030\PluginLib\Service\Hookable\LazyHookableInterface;

class TestingHookable implements LazyHookableInterface
{
    public static array $actions = [
        // 'hook' => ['method', priority, numberOfArguments]
        // If the prio and number are default you hook a method with call as `'hook' => 'method',`
        'init' => ['initMethod', 10, 1]
    ];

    public static array $filters = [];

    public static function getActions(): array
    {
        return static::$actions;
    }

    public static function getFilters(): array
    {
        return static::$filters;
    }

    final public function initMethod(): void
    {
        echo 'What\'s up, twitter world?';
        die();
    }
}