定制 abuyoyo/plugincore 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

abuyoyo/plugincore

Composer 安装命令:

composer require abuyoyo/plugincore

包简介

WordPress plugin core helper class

README 文档

README

Helper class for registering WordPress plugins.

Plugin Boilerplates and boilerplate generator are a hassle. The file structure they impose is way too cumbersome (and redundant) to push into every single plugin. WPHelper\PluginCore replaces boilerplates with one simple class (usually hidden away somewhere in your vendor/ dir).

WPHelper\AdminMenuPage can be used to register and generate admin menus if your plugin requires that.

Requirements

Installation

Install with Composer or just drop PluginCore.php into your plugin folder and require it.

// Require the Composer autoloader anywhere in your code.
require __DIR__ . '/vendor/autoload.php';

OR

// Require the class file directly from your plugin.
require_once __DIR__ . 'PluginCore.php';

WPHelper\PluginCore uses PSR-4 to autoload.

Basic Usage

WpHelper/PluginCore replaces the many plugin core skeleton generators out there. Just add these lines of code at the top of your plugin file and you're good to go.

WpHelper/PluginCore will define %PLUGIN%_BASENAME, %PLUGIN%_PATH, %PLUGIN%_URL, %PLUGIN%_FILE constants available to your code.

/*
 * Plugin Name: My Awesome Plugin
 * Description: Plugin's description.
 * Version:  1.0.0
 */

// Import PluginCore.
use WPHelper\PluginCore;

// Register the plugin
$args = [
    'title' => 'My Awesome Plugin', // Optional - will fallback to plugin header Plugin Name.
    'slug' => 'my-awesome-plugin', // Optional - will generate slug based on plugin header Plugin Name
    'const' => 'MYPLUGIN' // Optional - slug used to define constants: MYPLUGIN_DIR, MYPLUGIN_URL etc. (if not provided will use 'slug' in ALLCAPS)
    'activate_cb' => 'activate_callback' // Optional - Provide a callable function to run on activation
    'deactivate_cb' => 'deactivate_callback' // Optional - Provide a callable function to run on deactivation
    'uninstall_cb' => 'uninstall_callback' // Optional - (@todo) Consider using uninstall.php and not this plugin. This plugin can run in the global scope and cause problems
];

// Setup plugin constants and activation/deactivation hooks
new PluginCore( __FILE__, $args );

// Start writing your code here..
include '/foo.php';
add_action( 'plugins_loaded' function() {
    // whatever..
});

Constants

WPHelper\PluginCore defines constants for use in your code. Where __FILE__ is the filename provided to the class and %PLUGIN% is the 'const' option. Like so:

define( '%PLUGIN%_URL', plugin_dir_url( __FILE__ ) );
define( '%PLUGIN%_FILE', __FILE__ );

These are the constants defined by WPHelper\PluginCore. There are some redundancies to account for different conventions.

  • %PLUGIN%_PATH: plugin_dir_path( __FILE__ ) )
  • %PLUGIN%_DIR: plugin_dir_path( __FILE__ ) )
  • %PLUGIN%_URL: plugin_dir_url( __FILE__ ) )
  • %PLUGIN%_BASENAME: plugin_basename( __FILE__ ) )
  • %PLUGIN%_FILE: __FILE__
  • %PLUGIN%_PLUGIN_FILE: __FILE__

Get Instance

All PluginCore instances can be referenced anywhere in your code using static method get() and the plugin slug. Available on plugins_loaded hook or later.

PluginCore::get('my-awesome-plugin'); // returns PluginCore instance constructed with slug 'my-awesome-plugin'

统计信息

  • 总下载量: 213
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2019-09-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固