alledia/wordpress-plugin-framework

Alledia 框架,用于创建 WordPress 插件。

1.0.1 2020-08-11 17:24 UTC

README

⚠️ 此库已停用:请使用 https://github.com/publishpress/WordPress-Version-Notices 代替!

这是在 Alledia 上创建 WordPress 插件的基本库。

仅在主插件中使用它。对于附加组件,使用 此库 添加 EDD 集成。

模块

附加组件

此模块处理附加组件及其许可证密钥。它是可选的。

资产

此模块负责框架资产,并由核心初始化。

评论

评论模块帮助显示管理员通知,请求根据自定义规则进行5星评价。

升级

升级模块在主插件的(可选)管理页面上显示侧边栏横幅,为用户提供升级到专业计划的折扣。

如何使用它

安装

使用 composer 添加为依赖项

$ composer require alledia/wordpress-plugin-framework 

或手动将其添加到 composer.json 文件中

{
  "require": {
    "alledia/wordpress-plugin-framework": "*"
  }
} 

加载和初始化

<?php

// Call the autoloader.
require __DIR__ . '/vendor/autoload.php';

// Initialize the framework.
$pluginBaseName = plugin_basename('you-plugin/your-plugin.php');
$eddApiUrl      = 'https://your-plugin-site.com';
$pluginAuthor   = 'Your Company/Plugin';

$framework = new Allex\Core($pluginBaseName, $eddApiUrl, $pluginAuthor);
$famrwork->init();

使用附加组件模块

<?php
add_filter('allex_addons', 'filter_allex_addons', 10, 2);

// Initialize the module.
$framework->get_service('module_addons')->init();

/**
 * @param $addons
 * @param $plugin_name
 *
 * @return array
 */
function filter_allex_addons($addons, $plugin_name)
{
    if ('you-plugin' === $plugin_name) {
        $addons = [
            'addon-1' => [
                'slug'        => 'addon-1',
                'title'       => __('Add-on 1', 'your-plugin'),
                'description' => __('The first Add-on', 'your-plugin'),
                'icon_class'  => 'fa fa-check-circle',
                'edd_id'      => 6323,
            ],
            'addon-2' => [
                'slug'        => 'addon-2',
                'title'       => __('Add-on 2', 'your-plugin'),
                'description' => __('The second Add-on', 'your-plugin'),
                'icon_class'  => 'fab fa-bell',
                'edd_id'      => 8217,
            ],
        ];
    }
    
    return $addons;
}

许可证密钥和状态将存储在以下选项中

- {$pluginSlug}_license_key
- {$pluginSlug}_license_status

您可以使用以下钩子来自定义或覆盖它

<?php
add_action('allex_addon_update_license', 'action_allex_addon_update_license', 10, 4);
add_filter('allex_addons_get_license_key', 'filter_allex_addons_get_license_key', 10, 2);
add_filter('allex_addons_get_license_status', 'filter_allex_addons_get_license_status', 10, 2);

/**
 * @param $plugin_name
 * @param $addon_slug
 * @param $license_key
 * @param $license_status
 */
function action_allex_addon_update_license($plugin_name, $addon_slug, $license_key, $license_status)
{
    // ...
}

/**
 * @param $license_key
 * @param $addon_slug
 *
 * @return string
 */
function filter_allex_addons_get_license_key($license_key, $addon_slug)
{
    return $license_key;
}

/**
 * @param $license_status
 * @param $addon_slug
 *
 * @return string
 */
function filter_allex_addons_get_license_status($license_status, $addon_slug)
{
    return $license_status;
}