davekellam/dont-mess-up-prod 问题修复 & 功能扩展

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

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

davekellam/dont-mess-up-prod

最新稳定版本:1.0.1

Composer 安装命令:

composer require davekellam/dont-mess-up-prod

包简介

A WordPress plugin to indicate which environment you're currently using in the admin bar

README 文档

README

This plugin displays a colored environment indicator in the WordPress admin bar to help developers and content managers identify which environment they're working in.

Environment indicator screenshot

See a live preview on Playground.

Installation

Manual

  1. Upload the plugin files to /wp-content/plugins/dont-mess-up-prod/
  2. Activate the plugin through the "Plugins" screen in WordPress
  3. Configure the plugin via the Settings → Don’t Mess Up Prod screen (or filters)

Composer

composer require davekellam/dont-mess-up-prod

Environment Detection

The plugin detects the current environment using this priority order:

  1. URL matching – Compares the current site URL against the configured environment URLs. This list will also be used to generate a list of links that appears on hover in the admin bar.

  2. wp_get_environment_type() – Which defaults to production and can be set via php constant:

    define( 'WP_ENVIRONMENT_TYPE', 'staging' );

The indicator is visible to users who either meet the minimum capability (defaults to publish_posts, filterable via dmup_minimum_capability) or whose username appears in the allowed users filter. This keeps visibility limited to the folks who need the context.

Configuration

The plugin can be configured using the WordPress admin screen or using filters.

Admin Settings

Go to Settings → Don’t Mess Up Prod to configure:

  • Colors for each environment (local, development, staging, production)
  • URLs for each environment (used for detection and quick links)

Settings are saved per environment, and defaults are provided out of the box.

Example Configuration (mu-plugin)

Create a file /wp-content/mu-plugins/dmup-config.php:

<?php
/**
 * Plugin Name: Don't Mess Up Prod Configuration
 */

/**
 * Configure minimum capability for the environment indicator
 *
 * By default, the plugin only shows to explicitly allowed users.
 * Use this filter to enable role-based access.
 *
 * @param string|false $capability Current capability setting.
 * @return string|false Modified capability setting.
 */
function dmup_set_minimum_capability( $capability ) {
    // Enable for Author level and above
    return 'publish_posts';
}
add_filter( 'dmup_minimum_capability', 'dmup_set_minimum_capability' );

/**
 * Configure allowed users for the environment indicator
 *
 * Add specific user logins that should see the environment indicator
 * regardless of their role level.
 *
 * @param array $users Current allowed users array.
 * @return array Modified allowed users array.
 */
function dmup_set_allowed_users( $users ) {
    // Add specific user logins here
    $project_users = [
        'developer-name',
        'content-manager-name',
    ];

    return array_merge( $users, $project_users );
}
add_filter( 'dmup_allowed_users', 'dmup_set_allowed_users' );

/**
 * Configure environment URLs for your project
 *
 * Customize the URLs used to detect different environments and populate child links under the admin bar menu item
 *
 * @param array $urls Current environment URLs array.
 * @return array Modified environment URLs array.
 */
function dmup_set_environment_urls( $urls ) {
    return [
        'local'       => 'http://yourproject.local',
        'development' => 'https://dev.yourproject.com',
        'staging'     => 'https://staging.yourproject.com',
        'production'  => 'https://yourproject.com',
    ];
}
add_filter( 'dmup_environment_urls', 'dmup_set_environment_urls' );

/**
 * Configure environment colors for your project
 *
 * Customize the colors used for each environment
 *
 * @param array $colors Current environment colors array.
 * @return array Modified environment colors array.
 */
function dmup_set_environment_colors( $colors ) {
    return [
        'local'       => '#17a2b8', // blue
        'development' => '#6f42c1', // purple
        'staging'     => '#ffc107', // yellow
        'production'  => '#dc3545', // red
    ];
}
// Note: Admin settings are applied at priority 20.
// If you want to override admin settings in code, use a higher priority.
add_filter( 'dmup_environment_colors', 'dmup_set_environment_colors', 30 );

License

GPL-2.0-or-later

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固