Plugin Directory


Ignore:
Timestamp:
08/21/2020 05:13:06 PM (5 years ago)
Author:
roytanck
Message:

Version 1.2.

Location:
display-environment-type
Files:
6 added
2 edited

Legend:

Unmodified
Added
Removed
  • display-environment-type/trunk/display-environment-type.php

    r2366476 r2366697  
    44 * Plugin URI:        https://roytanck.com/2020/08/21/new-wordpress-plugin-display-environment-type/
    55 * Description:       Display the site's environment type in wp-admin.
    6  * Version:           1.1
     6 * Version:           1.2
    77 * Requires at least: 5.5
    88 * Requires PHP:      5.6
     
    9494         */
    9595        private function check_display() {
    96             // Don't display if no user logged in.
    97             if( ! is_user_logged_in() ) {
    98                 return false;
    99             }
     96            // Set the return value to the default (false).
     97            $display = false;
    10098            // Always display if in wp-admin.
    10199            if( is_admin() ) {
    102                 return true;
     100                $display = true;
     101            } else {
     102                // Display on the front-end only if user has certain capability.
     103                if( is_user_logged_in() && current_user_can( 'manage_options' ) ) {
     104                    $display = true;
     105                }
    103106            }
    104             // Display on the front-end only if user has certain capability.
    105             if( current_user_can( 'manage_options' ) ) {
    106                 return true;
    107             }
    108             // Default: false.
    109             return false;
     107            /**
     108             * Filter whether or not the environent type should be displayed.
     109             *
     110             * Allows you to perform checks like user capabilities or is_admin()
     111             * and return true to display the environment type, or false to not.
     112             *
     113             * @since 1.2
     114             *
     115             * @param boolean $display Should the environment type be displayed?
     116             */
     117            $display = ( apply_filters( 'det_display_environment_type', $display ) === true );
     118            // Return the filtered boolean.
     119            return $display;
    110120        }
    111121
  • display-environment-type/trunk/readme.txt

    r2366476 r2366697  
    55Tested up to: 5.5
    66Requires PHP: 5.6
    7 Stable tag: 1.1
     7Stable tag: 1.2
    88License: GPLv3
    99
    10 Displays WordPress 5.5's new environment type setting in the admin bar and the 'at a glance' dashboard widget. 
     10Displays WordPress 5.5's new environment type setting in the admin bar and the 'at a glance' dashboard widget.
    1111 
    1212== Description ==
     
    2424= Can I set custom color for my environment types? =
    2525 
    26 The colors a currently fixed. This was done to avoid possible confusion. If the colors were user-configurable, they would need to be set up exactly the same on all related servers.
     26The colors are currently fixed. This was done to avoid possible confusion. If the colors were user-configurable, they would need to be set up exactly the same on all related servers.
    2727 
    2828= What will happen when I define custom environment types? =
    2929 
    30 Custom types will be displayed in blue, with a lightbulb icon. There's currently no way to set different colors for your custom types is you have more than one.
     30Custom types will be displayed in blue, with a lightbulb icon. There's currently no way to set different colors for your custom types if you have more than one.
    3131
    3232= Why is there no display on the front-end of the site, for logged-in users with the admin bar enabled? =
    3333
    34 There's no display for non-admin users. The reasoning behind this is that in most cases, you'd probably not want to bother logged-in subscribers with a bright-colored box in their admin bar.
     34There's no display for non-admin users. The reasoning behind this is that in most cases, you'd probably not want to bother logged-in subscribers with a bright-colored box on their admin bar.
     35
     36For additional control, you can use the 'det_display_environment_type' filter hook:
     37
     38    function rt_det_display_filter( $display ){
     39        // Disable the environment type display for user ID 2.
     40        return ( get_current_user_id() !== 2 );
     41    }
     42    add_filter( 'det_display_environment_type', 'rt_det_display_filter' );
    3543
    3644== Screenshots ==
     
    4048 
    4149== Changelog ==
     50
     51= 1.2 (2020-08-21) =
     52* Adds a filter hook to allow you to determine whether the environmment is displayed.
    4253
    4354= 1.1 (2020-08-21) =
Note: See TracChangeset for help on using the changeset viewer.