承接 felixarntz/leavesandlove-wp-plugin-util 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

felixarntz/leavesandlove-wp-plugin-util

最新稳定版本:2.0.3

Composer 安装命令:

composer require felixarntz/leavesandlove-wp-plugin-util

包简介

This is a library to initialize WordPress plugins in a proper fashion, making usual processes a lot easier to handle and adding a few useful features, for example plugin dependency management or automatic multisite-compatibility.

关键字:

README 文档

README

Latest Stable Version License

LaL WP Plugin Util

This is a library to initialize WordPress plugins in a proper fashion, making usual processes a lot easier to handle and adding a few useful features, for example plugin dependency management or automatic multisite-compatibility. I originally developed this library to use it in my own plugins, but version 2.0.0 marks its initial public release.

Features

  • use WordPress plugin initialization best practices
  • provide minimum required PHP and WordPress version
  • provide other plugins (including minimum versions) as dependencies (optional)
  • fail gracefully if any of the required dependencies are not met and show a helpful admin notice
  • show plugin installation / activation / update links for plugin dependencies that are not met
  • easily handle plugin installation, uninstallation, activation and deactivation by simply providing one method for each (optional) - it is automatically multisite-compatible
  • allow the plugin to be used as a regular plugin, a must-use plugin or (if you provide an is_library argument with value true) even bundled as a library inside another plugin, must-use plugin or theme
  • automatically handle textdomain loading, whether you use local .po files or wordpress.org language packs
  • show a (permanently dismissible) status message in the admin when the plugin is activated (optional)
  • easily add custom links to the plugin's row in the plugins list table (optional)
  • have useful utility functions of your plugin already available, like getting absolute paths and URLs, the current plugin version or PHP notice generators (in case someone messes with your plugin)

This library uses WordPress best practices to initialize plugins and enhances the default behavior only where necessary - it does not reinvent the wheel or bloat the admin with dozens of internal settings.

Requirements

Your plugin itself must:

  • require at least PHP 5.3 and WordPress 3.5 (don't worry, the plugin loader will fail gracefully if a user with a lower version tries to run the plugin)
  • use namespaces and composer (and preferably use autoloading)
  • have a main initialization class called App which resides in your plugin's root namespace
  • store local translation files (if needed) in an immediate plugin subdirectory /languages/

Getting Started

To use the library, first add it to your project by adding it to your composer.json (composer require felixarntz/leavesandlove-wp-plugin-util:2.0.1). The library uses autoloading to load its classes. It is recommended that you also use autoloading with your plugin's own files.

Your plugin must have a main initialization class which is called App and resides in your plugin's root namespace (do not put this class in the actual plugin main file!). This main class must extend the LaL_WP_Plugin class bundled in this library. For more information on how to extend this class, please check out it's PHPDoc block. See a little bit further below for a basic example of what that class could look like.

Then you initialize the main class from your plugin's main file. The following code snippet gives you an example:

<?php
/*
Plugin Name: My Plugin
Plugin URI: https://wordpress.org/plugins/my-plugin/
Description: This is my plugin's description.
Version: 1.0.0
Author: John Doe
Author URI: http://example.com
License: GNU General Public License v3
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Text Domain: my-plugin
*/

if ( version_compare( phpversion(), '5.3.0' ) >= 0 && ! class_exists( 'MyPluginNamespace\App' ) ) {
  // load the PHP autoloader...
  if ( file_exists( dirname( __FILE__ ) . '/my-plugin/vendor/autoload.php' ) ) {
    require_once dirname( __FILE__ ) . '/my-plugin/vendor/autoload.php';
  } elseif ( file_exists( dirname( __FILE__ ) . '/vendor/autoload.php' ) ) {
    require_once dirname( __FILE__ ) . '/vendor/autoload.php';
  }
} elseif ( ! class_exists( 'LaL_WP_Plugin_Loader' ) ) {
  // ...or load the plugin loader class itself
  if ( file_exists( dirname( __FILE__ ) . '/my-plugin/vendor/felixarntz/leavesandlove-wp-plugin-util/leavesandlove-wp-plugin-loader.php' ) ) {
    require_once dirname( __FILE__ ) . '/my-plugin/vendor/felixarntz/leavesandlove-wp-plugin-util/leavesandlove-wp-plugin-loader.php';
  } elseif ( file_exists( dirname( __FILE__ ) . '/vendor/felixarntz/leavesandlove-wp-plugin-util/leavesandlove-wp-plugin-loader.php' ) ) {
    require_once dirname( __FILE__ ) . '/vendor/felixarntz/leavesandlove-wp-plugin-util/leavesandlove-wp-plugin-loader.php';
  }
}

// the actual plugin loading call
LaL_WP_Plugin_Loader::load_plugin( array(
  'slug'                => 'my-plugin',
  'name'                => 'My Plugin',
  'version'             => '1.0.0',
  'main_file'           => __FILE__,
  'namespace'           => 'MyPluginNamespace',
  'textdomain'          => 'my-plugin',
  'use_language_packs'  => true,
), array(
  'phpversion'          => '5.3.0',
  'wpversion'           => '4.0',
) );

The above code is all that you should include in your plugin's main file. In case you already wondered: You must not wrap any of the code into a plugins_loaded function - the plugin loader handles that for you. For an overview of how to leverage the advanced initialization methods, please check out the plugin loader class' PHPDoc block.

Based on the above example, the following is the absolute minimal code that your main class should have:

<?php
namespace MyPluginNamespace;

use LaL_WP_Plugin as Plugin;

if ( ! class_exists( 'MyPluginNamespace\App' ) ) {

  class App extends Plugin {
    protected static $_args = array();

    protected function __construct( $args ) {
      parent::__construct( $args );
    }

    protected function run() {
      // initialize the plugin here
    }
  }

}

It is recommended to always wrap all your classes and functions into an if clause whether they already exist as this prevents fatal errors that may happen if a plugin is used as a regular plugin and as a bundled library at the same time.

For a detailed guide and reference on how to use this library, please read the Wiki on Github. Detailed guide coming soon - for now please refer to the PHPDoc.

Contributions and Bugs

If you have ideas on how to improve the library or if you discover a bug, please open a new issue or a pull-request.

You can also contribute to the library by translating it. In the library's /languages/ directory, there is a .pot file which you can use as a starting point. When you're done with a translation, you can either create a pull request with the new translation files or you can send them to me manually.

felixarntz/leavesandlove-wp-plugin-util 适用场景与选型建议

felixarntz/leavesandlove-wp-plugin-util 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.08k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 04 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「wordpress」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 felixarntz/leavesandlove-wp-plugin-util 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 felixarntz/leavesandlove-wp-plugin-util 我们能提供哪些服务?
定制开发 / 二次开发

基于 felixarntz/leavesandlove-wp-plugin-util 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.08k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 36
  • 依赖项目数: 9
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2015-04-06