wpdesk/wp-builder

此包最新版本(2.1.1)没有提供许可证信息。


README

pipeline status coverage report Latest Stable Version Total Downloads Latest Unstable Version License

WP Builder

wp-builder 库定义了创建 WordPress 插件的接口和抽象。

要求

PHP 5.6 或更高版本。

通过 Composer 安装

为了通过 Composer 安装这些绑定,请运行以下命令

composer require wpdesk/wp-builder

示例用法

在 WordPress 插件的主 .php 文件中使用以下代码

<?php

class ContentExtender implements \WPDesk\PluginBuilder\Plugin\Hookable {

	public function hooks() {
		add_filter( 'the_content', [ $this, 'append_sample_text_to_content' ] );
	}
	
	/**
	 * @param string $content
	 * @return string
 	 */
	public function append_sample_text_to_content( $content ) {
		return $content . ' Sample text';
	}
}

class ExamplePlugin extends \WPDesk\PluginBuilder\Plugin\AbstractPlugin implements \WPDesk\PluginBuilder\Plugin\HookableCollection {

	use \WPDesk\PluginBuilder\Plugin\HookableParent;
	
	public function hooks() {
		$this->add_hookable( new ContentExtender() );
		
		$this->hooks_on_hookable_objects();
	}

}

$plugin_info = new WPDesk_Plugin_Info();
$plugin_info->set_plugin_name( 'Example Plugin' );

$example_plugin = new ExamplePlugin( $plugin_info );