承接 stellarwp/installer 相关项目开发

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

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

stellarwp/installer

Composer 安装命令:

composer require stellarwp/installer

包简介

StellarWP plugin install/activation library.

README 文档

README

CI Static Analysis

A library for installing / activating other plugins. Authored by the development team at StellarWP and provided free for the WordPress community.

Installation

It's recommended that you install Schema as a project dependency via Composer:

composer require stellarwp/installer

We actually recommend that this library gets included in your project using Strauss.

Luckily, adding Strauss to your composer.json is only slightly more complicated than adding a typical dependency, so checkout our strauss docs.

Handling text domains

This library has strings that are run through WordPress translation functions. Because of this, there's an extra step that needs to be taken to ensure that the placeholder %TEXTDOMAIN% is replaced with your project's text domain.

If you are using Strauss as a .phar file (recommended)

"scripts": {
	"strauss": [
		"test -f ./bin/strauss.phar || curl -o bin/strauss.phar -L -C - https://github.com/BrianHenryIE/strauss/releases/download/0.13.0/strauss.phar",
		"vendor/stellarwp/installer/bin/set-domain domain=YOUR_PROJECTS_TEXT_DOMAIN",
		"@php bin/strauss.phar"
	]
}

If you are using Strauss from within your vendor/bin directory

"scripts": {
    "strauss": [
      "vendor/stellarwp/installer/bin/set-domain domain=YOUR_PROJECTS_TEXT_DOMAIN",
      "vendor/bin/strauss"
    ]
}

Initialization

During the plugins_loaded action, initialize the installer.

namespace StellarWP\Installer\Config;
namespace StellarWP\Installer\Installer;

add_action( 'plugins_loaded', function () {
	Config::set_hook_prefix( 'boomshakalaka' );
	Installer::init();
} );

Registering a plugin

Registering plugins for installation should be done during (or after) the plugins_loaded action.

$installer->register_plugin( $slug, $plugin_name, $download_link, $did_action );

Parameter Type Description
$slug string Required. A simple slug for referring to your plugin.
$plugin_name string Required. The plugin name. This should not be translated. It must match what is in the plugin header docblock.
$download_link string The plugin download link. If this is omitted, it is assumed that the URL will come from WordPress.org plugin repository.
$did_action string If provided, the action will be checked with did_action() to indicate that the plugin is active.

Simple registration

use StellarWP\Installer\Installer;

add_action( 'plugins_loaded', function () {
	$installer = Installer::get();
	$installer->register_plugin( 'event-tickets', 'Event Tickets' );
} );

Registration with download link

use StellarWP\Installer\Installer;

add_action( 'plugins_loaded', function () {
	$installer = Installer::get();
	$installer->register_plugin( 'event-tickets', 'Event Tickets', 'https://example.com/event-tickets.zip' );
} );

Registration with an action indicating that the plugin is active

use StellarWP\Installer\Installer;

add_action( 'plugins_loaded', function () {
	$installer = Installer::get();
	$installer->register_plugin( 'event-tickets', 'Event Tickets', null, 'event_tickets_plugin_loaded' );
} );

Rendering an install/activate button

Buttons are the main point of this library. You can get or render a button. When you do, the relevant JavaScript will be enqueued to hook the button up with admin-ajax.php.

Render a button

use StellarWP\Installer\Installer;

Installer::get()->render_plugin_button( 'event-tickets', 'install', 'Install Event Tickets' );

Get a button

use StellarWP\Installer\Installer;

Installer::get()->get_plugin_button( 'event-tickets', 'install', 'Install Event Tickets' );

Get or render a button and redirect

use StellarWP\Installer\Installer;

// Get it.
$button = Installer::get()->get_plugin_button( 'event-tickets', 'install', 'Install Event Tickets', $redirect_url );

// Or render it.
Installer::get()->render_plugin_button( 'event-tickets', 'install', 'Install Event Tickets', $redirect_url );

PHP - Actions

stellarwp/installer/{$hook_prefix}/deregister_plugin

Fired when a plugin is deregistgered.

Parameters: string $slug

stellarwp/installer/{$hook_prefix}/register_plugin

Fired after registering a plugin.

Parameters: string $slug, string $plugin_name, string $download_link = null, string $did_action = null

PHP - Filters

stellarwp/installer/{$hook_prefix}/activated_label

Filters the label used for the "activated" button.

Parameters: string $label, string $slug, StellarWP\Installer\Contracts\Handler $handler

Default: Activated!

use StellarWP\Installer;
$hook_prefix = Installer\Config::get_hook_prefix();

add_filter( "stellarwp/installer/{$hook_prefix}/activated_label", function ( $label, $slug, $handler ) {
	return 'Activated, yo.';
}, 10, 3 );

stellarwp/installer/{$hook_prefix}/activating_label

Filters the label used for the "activating" button.

Parameters: string $label, string $slug, StellarWP\Installer\Contracts\Handler $handler

Default: Activating...

use StellarWP\Installer;
$hook_prefix = Installer\Config::get_hook_prefix();

add_filter( "stellarwp/installer/{$hook_prefix}/activating_label", function ( $label, $slug, $handler ) {
	return 'BOOM! Activating...';
}, 10, 3 );

stellarwp/installer/{$hook_prefix}/busy_class

Filters the class used for the "busy" state.

Parameters: string $class

Default: is-busy

use StellarWP\Installer;
$hook_prefix = Installer\Config::get_hook_prefix();

add_filter( "stellarwp/installer/{$hook_prefix}/busy_class", function ( $class ) {
	return 'is-very-busy';
} );

stellarwp/installer/{$hook_prefix}/button_classes

Filters the classes used for the button.

Parameters: array $classes, string $slug, StellarWP\Installer\Contracts\Handler $handler

Default: An array of default namespaced classes.

use StellarWP\Installer;
$hook_prefix = Installer\Config::get_hook_prefix();

add_filter( "stellarwp/installer/{$hook_prefix}/button_classes", function ( $classes, $slug, $handler ) {
	$classes[] = 'is-primary';
	$classes[] = 'some-other-class';
	return $classes;
}, 10, 3 );

stellarwp/installer/{$hook_prefix}/button_id

Filters the button id attribute for the button.

Parameters: string $id, string $slug, StellarWP\Installer\Contracts\Handler $handler

Default: null

stellarwp/installer/{$hook_prefix}/download_url

Filters the download_url used for the installation of the plugin.

stellarwp/installer/{$hook_prefix}/get_permission

Filters the permissions used for the installation of the plugin.

stellarwp/installer/{$hook_prefix}/install_error_message

Filters the install error message.

stellarwp/installer/{$hook_prefix}/installed_label

Filters the label used for the "installed" button.

Parameters: string $label, string $slug, StellarWP\Installer\Contracts\Handler $handler

Default: Installed!

use StellarWP\Installer;
$hook_prefix = Installer\Config::get_hook_prefix();

add_filter( "stellarwp/installer/{$hook_prefix}/installed_label", function ( $label, $slug, $handler ) {
	return 'Installed, yo.';
}, 10, 3 );

stellarwp/installer/{$hook_prefix}/installing_label

Filter the label used for the "installing" button.

Parameters: string $label, string $slug, StellarWP\Installer\Contracts\Handler $handler

Default: Installing...

use StellarWP\Installer;
$hook_prefix = Installer\Config::get_hook_prefix();

add_filter( "stellarwp/installer/{$hook_prefix}/installing_label", function ( $label, $slug, $handler ) {
	return 'YAY! Installing...';
}, 10, 3 );

stellarwp/installer/{$hook_prefix}/nonce_name

The name of the nonce field that is used when interacting with an install/activate button.

stellarwp/installer/{$hook_prefix}/wordpress_org_data

Filters the data returned from the WordPress.org plugin repository.

JS - Actions

stellarwp_installer_{$hook_prefix}_error

Fires when an error occurs during the installation of a plugin.

wp.hooks.addAction( 'stellarwp_installer_HOOK_PREFIX_error', function( selector, slug, action, message, hookPrefix ) {
	alert( message );
} );

Acknowledgements

Props to the folks at The Events Calendar for the efforts on the initial release of this library.

stellarwp/installer 适用场景与选型建议

stellarwp/installer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 595.28k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 01 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 stellarwp/installer 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 595.28k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 17
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2023-01-28