stellarwp / installer
StellarWP 插件安装/激活库。
Requires
- php: >=7.2
- ext-json: *
Requires (Dev)
- automattic/vipwpcs: ^2.3
- codeception/module-asserts: ^1.0
- codeception/module-cli: ^1.0
- codeception/module-db: ^1.0
- codeception/module-filesystem: ^1.0
- codeception/module-phpbrowser: ^1.0
- codeception/module-webdriver: ^1.0
- codeception/util-universalframework: ^1.0
- dealerdirect/phpcodesniffer-composer-installer: ^0.7.2
- lucatume/wp-browser: ^3.1
- phpcompatibility/phpcompatibility-wp: *
- szepeviktor/phpstan-wordpress: ^1.1
- the-events-calendar/coding-standards: dev-master
- wp-coding-standards/wpcs: ^2.3
This package is auto-updated.
Last update: 2024-08-27 20:17:41 UTC
README
这是一个用于安装/激活其他插件的库。由 StellarWP 开发团队编写,免费提供给 WordPress 社区。
安装
建议您通过 Composer 将 Schema 安装为项目依赖项。
composer require stellarwp/installer
实际上,我们建议您使用 Strauss 将此库包含到您的项目中。
幸运的是,将 Strauss 添加到您的
composer.json
的过程仅比添加典型依赖项稍微复杂一些,请参阅我们的 strauss 文档。
处理文本域
此库包含通过 WordPress 翻译函数运行的字符串。因此,需要采取额外步骤以确保将占位符 %TEXTDOMAIN%
替换为您的项目文本域。
如果您使用 Strauss 作为 .phar
文件(推荐)
"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" ] }
如果您在 vendor/bin
目录内使用 Strauss
"scripts": { "strauss": [ "vendor/stellarwp/installer/bin/set-domain domain=YOUR_PROJECTS_TEXT_DOMAIN", "vendor/bin/strauss" ] }
初始化
在 plugins_loaded
动作期间,初始化安装程序。
namespace StellarWP\Installer\Config; namespace StellarWP\Installer\Installer; add_action( 'plugins_loaded', function () { Config::set_hook_prefix( 'boomshakalaka' ); Installer::init(); } );
注册插件
应在 plugins_loaded
动作期间(或之后)注册用于安装的插件。
$installer->register_plugin( $slug, $plugin_name, $download_link, $did_action );
简单注册
use StellarWP\Installer\Installer; add_action( 'plugins_loaded', function () { $installer = Installer::get(); $installer->register_plugin( 'event-tickets', 'Event Tickets' ); } );
带下载链接的注册
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' ); } );
带表示插件已激活的动作的注册
use StellarWP\Installer\Installer; add_action( 'plugins_loaded', function () { $installer = Installer::get(); $installer->register_plugin( 'event-tickets', 'Event Tickets', null, 'event_tickets_plugin_loaded' ); } );
渲染安装/激活按钮
按钮是此库的主要功能。您可以选择获取或渲染按钮。当您这样做时,相关的 JavaScript 将被排队以将按钮与 admin-ajax.php 连接起来。
渲染按钮
use StellarWP\Installer\Installer; Installer::get()->render_plugin_button( 'event-tickets', 'install', 'Install Event Tickets' );
获取按钮
use StellarWP\Installer\Installer; Installer::get()->get_plugin_button( 'event-tickets', 'install', 'Install Event Tickets' );
获取或渲染按钮并重定向
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 - 动作
stellarwp/installer/{$hook_prefix}/deregister_plugin
当插件被注销时触发。
参数: 字符串 $slug
stellarwp/installer/{$hook_prefix}/register_plugin
在注册插件后触发。
参数: 字符串 $slug
, 字符串 $plugin_name
, 字符串 $download_link = null
, 字符串 $did_action = null
PHP - 过滤器
stellarwp/installer/{$hook_prefix}/activated_label
过滤用于 "已激活" 按钮的标签。
参数: 字符串 $label
, 字符串 $slug
, StellarWP\Installer\Contracts\Handler $handler
默认: 已激活!
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
过滤用于 "激活中" 按钮的标签。
参数: 字符串 $label
, 字符串 $slug
, StellarWP\Installer\Contracts\Handler $handler
默认: 激活中...
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
过滤用于 "忙碌" 状态的类。
参数: 字符串 $class
默认: 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
过滤按钮的类。
参数: 数组 $classes
, 字符串 $slug
, StellarWP\Installer\Contracts\Handler $handler
默认: 默认命名空间类数组。
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
过滤按钮的 id 属性。
参数: 字符串 $id
, 字符串 $slug
, StellarWP\Installer\Contracts\Handler $handler
默认: null
stellarwp/installer/{$hook_prefix}/download_url
过滤用于插件安装的下载链接。
stellarwp/installer/{$hook_prefix}/get_permission
过滤用于插件安装的权限。
stellarwp/installer/{$hook_prefix}/install_error_message
过滤安装错误信息。
stellarwp/installer/{$hook_prefix}/installed_label
过滤用于“已安装”按钮的标签。
参数: 字符串 $label
, 字符串 $slug
, StellarWP\Installer\Contracts\Handler $handler
默认: 已安装!
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
过滤用于“安装中”按钮的标签。
参数: 字符串 $label
, 字符串 $slug
, StellarWP\Installer\Contracts\Handler $handler
默认: 正在安装...
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
与安装/激活按钮交互时使用的nonce字段的名称。
stellarwp/installer/{$hook_prefix}/wordpress_org_data
过滤从WordPress.org插件仓库返回的数据。
JS - 动作
stellarwp_installer_{$hook_prefix}_error
在插件安装过程中发生错误时触发。
wp.hooks.addAction( 'stellarwp_installer_HOOK_PREFIX_error', function( selector, slug, action, message, hookPrefix ) { alert( message ); } );
致谢
感谢The Events Calendar团队为这个库的初始发布所付出的努力。