PHP code example of crtl / wp-plugin-base

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

    

crtl / wp-plugin-base example snippets




use Crtl\WpPluginBase\PluginBase;
use Crtl\WpPluginBase\Attribute\WPAction;
use Crtl\WpPluginBase\Attribute\WPFilter;

class MyPlugin extends PluginBase {

    /**
     * Registers an action by creating method in format action_{action_name}
    * @return void
     */
    public function action_wp_enqueue_scripts() {
        wp_enqueue_script(...)
    }
    
    /**
     * Registers a filter by creating method in format action_{action_name} 
     * @return false
     */
    public function filter_admin_bar() {
        return false;
    }
    
    /**
     * Register action using {@link WPAction} attribute
     * @return void
     */
    #[WPAction("action_name", 10, 0)]
    public function usingAttributes() {
    
    }

    /**
     * Register filter using {@link WPFilter} attribute
     * @return void
     */
    #[WPFilter("filter_name", 10, 0)]
    public function usingAttributes() {
    
    }

}


> #[WPAction(priority: 10)]
> public function action_my_action() {}
>