wpdesk/wp-builder

There is no license information available for the latest version (2.1.2) of this package.

Maintainers

Package info

github.com/WP-Desk/wp-builder

pkg:composer/wpdesk/wp-builder

Transparency log

Statistics

Installs: 80 253

Dependents: 31

Suggesters: 0

Stars: 0

Open Issues: 0

2.1.2 2024-11-19 09:22 UTC

README

Latest Stable Version Total Downloads Latest Unstable Version License

WP Builder

wpdesk/wp-builder provides small base classes and interfaces for building WordPress plugins.

Requirements

PHP 7.4+.

Installation via Composer

Install with Composer:

composer require wpdesk/wp-builder

Example usage

Basic example for a plugin bootstrap file:

<?php

use WPDesk\PluginBuilder\Plugin\AbstractPlugin;
use WPDesk\PluginBuilder\Plugin\Hookable;
use WPDesk\PluginBuilder\Plugin\HookableCollection;
use WPDesk\PluginBuilder\Plugin\HookableParent;

class ContentExtender implements Hookable {

	public function hooks() {
		add_filter( 'the_content', [ $this, 'append_sample_text_to_content' ] );
	}

	public function append_sample_text_to_content( $content ) {
		return $content . ' Sample text';
	}
}

class ExamplePlugin extends AbstractPlugin implements HookableCollection {

	use HookableParent;

	protected function hooks() {
		parent::hooks();
		$this->add_hookable( new ContentExtender() );
		$this->hooks_on_hookable_objects();
	}
}

$plugin_info = new WPDesk_Plugin_Info();
$plugin_info->set_plugin_file_name( __FILE__ );
$plugin_info->set_plugin_dir( __DIR__ );
$plugin_info->set_plugin_url( plugin_dir_url( __FILE__ ) );
$plugin_info->set_plugin_name( 'Example Plugin' );
$plugin_info->set_text_domain( 'example-plugin' );

$plugin = new ExamplePlugin( $plugin_info );
$plugin->init();