humanmade/wp-flags

一个轻量级的WordPress插件,通过基于代码(或未来可能的行政UI)标准,允许向最终用户暴露功能标志。

安装数量: 43,561

依赖关系: 0

建议者: 0

安全性: 0

星星: 34

关注者: 24

分支: 3

开放性问题: 5

类型:wordpress-plugin

0.0.8 2021-11-11 14:29 UTC

This package is auto-updated.

Last update: 2024-09-11 21:17:44 UTC


README

注意:这是一个正在开发中的插件。

安装

使用Composer

  • 在项目中要求此包

composer require humanmade/wp-flags

使用子模块

  • 将插件作为子模块添加(根据需要调整路径)

git submodule add git@github.com:humanmade/wp-flags.git content/plugins/wp-flags

使用方法

use HumanMade\Flags\Flags;

add_action( 'init', function() {
    Flags::add( 'new-flag', 'New Flag', [
        // Is the flag exposed to users ?
        'available' => function() {
            return current_user_can( 'manage_options' );
        },
        // At what level the flag can be set. One of `user` or `site`
        'scope' => 'user',
        // Default flag status
        'active' => true,
        // Is the flag controllable by users ?
        'optin' => true,
        // Custom icon ? ( dashicon-compatible )
        'icon' => 'dashboard',
        // Custom attribute ?
        'some_custom_meta_key' => 'some_value',
    ] );

    // OR just..
    $flag = Flags::add( 'another-flag', 'Another flag' );
    $flag->on( 'active', function( $active, $flag ) {
        // do something based on active status change
    } );

    // Execute logic based on flag status
    if ( Flags::get( 'new-flag' )->active ) {
        show_the_new_sidebar();
    } );
} );

设置标志的范围

标志可以在 usersite 范围内设置,这决定了如何控制标志。用户范围的标志可以由每个用户在该站点上单独打开或关闭,而站点范围的标志则为所有用户打开或关闭,并在站点设置中控制。

致谢

Shady Sharaf 编写和维护。感谢所有我们的 贡献者

有兴趣加入这个有趣的项目吗? 加入我们,成为人类!