felixarntz/wp-network-roles 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

felixarntz/wp-network-roles

Composer 安装命令:

composer require felixarntz/wp-network-roles

包简介

Implements network-wide user roles in WordPress.

README 文档

README

Build Status Latest Stable Version License

WP Network Roles

Implements network-wide user roles in WordPress.

What it does

  • introduces classes WP_Network_Role and WP_Network_Roles for managing network-wide roles
  • introduces internal class WPNR_User_With_Network_Roles that stores network roles and capabilities for a user
  • introduces relationships between users and networks
  • allows to query users for specific network roles or whether they are part of a network
  • uses user meta to store network-wide roles and capabilities, in a similar fashion like WordPress core stores site roles and capabilities)
  • introduces two initial network roles "administrator" (similar to Super Admin for a network) and "member" (no capabilities, simply a member of a network)
  • synchronizes and migrates super admins to the network role "administrator"
  • adds network relationships to existing users by assigning them the "member" network role
  • includes wp network-role and wp network-cap commands for WP-CLI
  • supports the WP Multi Network plugin

How to install

The plugin can either be installed as a network-wide regular plugin or alternatively as a must-use plugin.

Recommendations

  • Do not set any of the following global variables:
    • $super_admins (WordPress core)
    • $wp_user_roles (WordPress core)
    • $wp_network_roles
    • $wp_network_user_roles
  • Do not rely on is_super_admin(), but rather on actual capabilities
  • While it is a best practice to prefix plugin functions and classes, this plugin is a proof-of-concept for WordPress core, and several functions may end up there eventually. This plugin only prefixes functions and classes that are specific to the plugin, internal helper functions for itself or hooks. Non-prefixed functions and classes are wrapped in a conditional so that, if WordPress core adapts them, their core variant will be loaded instead. Therefore, do not define any of the following functions or classes:
    • wp_network_roles()
    • get_network_role()
    • add_network_role()
    • remove_network_role()
    • get_networks_of_user()
    • count_network_users()
    • wp_get_users_with_no_network_role()
    • WP_Network_Role
    • WP_Network_Roles

Usage

Managing Network Roles

  • Function: wp_network_roles(): WP_Network_Roles
  • Function: get_network_role( string $role ): WP_Network_Role|null
  • Function: add_network_role( string $role, string $display_name, array $capabilities )
  • Function: remove_network_role( string $role )

Managing User Network Roles

  • Function: nr_get_user_with_network_roles( WP_User $user ): WPNR_User_With_Network_Roles -- Since it is impossible to extend the WP_User class in a reliable way in a plugin, this function must be used to retrieve an instance of a special class to manage network roles of the user object passed. That instance will be internally cached inside of the original WP_User instance.
  • Method: WPNR_User_With_Network_Roles::add_network_role( string $role )
  • Method: WPNR_User_With_Network_Roles::remove_network_role( string $role )
  • Method: WPNR_User_With_Network_Roles::set_network_role( string $role )
  • Method: WPNR_User_With_Network_Roles::for_network( int $network_id ) -- Initializes the instance for a specific network.
  • Method: WPNR_User_With_Network_Roles::get_network_id() -- Gets the ID of the network for which the instance is currently initialized.

Hooks

  • Action: wp_network_roles_init
  • Action: add_network_user_role
  • Action: remove_network_user_role
  • Action: set_network_user_role
  • Filter: network_role_has_cap
  • Filter: pre_get_networks_of_user
  • Filter: get_networks_of_user

felixarntz/wp-network-roles 适用场景与选型建议

felixarntz/wp-network-roles 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 54 次下载、GitHub Stars 达 9, 最近一次更新时间为 2017 年 11 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 9
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2017-11-21