Plugin Directory

Changeset 2497410


Ignore:
Timestamp:
03/16/2021 10:41:20 PM (5 years ago)
Author:
tfrommen
Message:

Version 1.4.0

Location:
wp-dobby/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wp-dobby/trunk/dobby.php

    r1733044 r2497410  
    1 <?php # -*- coding: utf-8 -*-
    2 
    3 /*
    4  * Plugin Name: Dobby
    5  * Plugin URI:  https://wordpress.org/plugins/wp-dobby/
    6  * Description: Dobby, the friendly Admin Elf, takes care of all your (unwanted) admin notices.
    7  * Author:      Thorsten Frommen
    8  * Author URI:  https://tfrommen.de
    9  * Version:     1.3.0
    10  * Text Domain: wp-dobby
    11  * License:     MIT
     1<?php
     2/**
     3 * Dobby
     4 *
     5 * @package           tfrommen\Dobby
     6 * @author            Thorsten Frommen
     7 * @license           MIT
     8 *
     9 * @wordpress-plugin
     10 * Plugin Name:       Dobby
     11 * Plugin URI:        https://wordpress.org/plugins/wp-dobby/
     12 * Description:       Dobby, the friendly Admin Elf, takes care of all your (unwanted) admin notices.
     13 * Version:           1.4.0
     14 * Requires at least: 3.1
     15 * Requires PHP:      5.4
     16 * Author:            Thorsten Frommen
     17 * Author URI:        https://tfrommen.de
     18 * License:           MIT
     19 * Text Domain:       wp-dobby
    1220 */
    1321
     
    3038
    3139/**
    32  * Bootstraps the plugin.
     40 * Bootstrap the plugin.
    3341 *
    3442 * @since 1.0.0
     
    4654        $action = 'admin_notices';
    4755    }
    48     add_action( $action, function () {
    4956
    50         ob_start();
    51     }, (int) ( PHP_INT_MAX + 1 ) );
     57    add_action(
     58        $action,
     59        function () {
    5260
    53     add_action( 'all_admin_notices', function () {
     61            ob_start();
     62        },
     63        (int) ( PHP_INT_MAX + 1 )
     64    );
    5465
    55         $contents = trim( ob_get_clean() );
    56         if ( '' === $contents ) {
    57             return;
    58         }
     66    add_action(
     67        'all_admin_notices',
     68        function () {
    5969
    60         load_plugin_textdomain( 'wp-dobby' );
     70            $contents = trim( ob_get_clean() );
     71            if ( '' === $contents ) {
     72                return;
     73            }
    6174
    62         $dobby_id = 'dobby';
     75            load_plugin_textdomain( 'wp-dobby' );
    6376
    64         $closet_id = 'dobby-closet';
    65         ?>
    66         <div id="<?php echo esc_attr( $dobby_id ); ?>" class="notice hide-if-js">
    67             <p>
    68                 <span>&#x2728;</span>
    69                 <?php esc_html_e( 'Dobby took care of your admin notices.', 'wp-dobby' ); ?>
    70                 <button class="button"><?php esc_html_e( 'Reveal', 'wp-dobby' ); ?></button>
    71             </p>
    72         </div>
    73         <div id="<?php echo esc_attr( $closet_id ); ?>" class="hide-if-js">
     77            $dobby_id = 'dobby';
     78
     79            $closet_id = 'dobby-closet';
     80            ?>
     81            <div id="<?php echo esc_attr( $dobby_id ); ?>" class="notice hide-if-js">
     82                <p>
     83                    <span>&#x2728;</span>
     84                    <?php esc_html_e( 'Dobby took care of your admin notices.', 'wp-dobby' ); ?>
     85                    <button class="button"><?php esc_html_e( 'Reveal', 'wp-dobby' ); ?></button>
     86                </p>
     87            </div>
     88            <div id="<?php echo esc_attr( $closet_id ); ?>" class="hide-if-js">
     89                <?php
     90                // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
     91                echo $contents;
     92                ?>
     93            </div>
    7494            <?php
    75             // @codingStandardsIgnoreLine
    76             echo $contents;
    77             ?>
    78         </div>
    79         <?php
    80         wp_enqueue_script(
    81             'dobby',
    82             plugin_dir_url( __FILE__ ) . 'assets/js/dobby.js',
    83             [ 'jquery' ],
    84             filemtime( plugin_dir_path( __FILE__ ) . 'assets/js/dobby.js' )
    85         );
     95            wp_enqueue_script(
     96                'dobby',
     97                plugin_dir_url( __FILE__ ) . 'assets/js/dobby.js',
     98                [ 'jquery' ],
     99                filemtime( plugin_dir_path( __FILE__ ) . 'assets/js/dobby.js' ),
     100                [ 'in_footer' => true ]
     101            );
    86102
    87         /**
    88          * Filters the minimum number of admin notices required for Dobby to take action.
    89          *
    90          * @since 1.1.0
    91          *
    92          * @param int $threshold Required minimum number of admin notices.
    93          */
    94         $threshold = (int) apply_filters( FILTER_THRESHOLD, 1 );
    95         wp_localize_script( 'dobby', 'dobbySettings', [
    96             'selectorCloset' => "#{$closet_id}",
    97             'selectorDobby'  => "#{$dobby_id}",
    98             'threshold'      => max( 1, $threshold ),
    99         ] );
    100     }, PHP_INT_MAX );
     103            /**
     104             * Filter the minimum number of admin notices required for Dobby to take action.
     105             *
     106             * @since 1.1.0
     107             *
     108             * @param int $threshold Required minimum number of admin notices.
     109             */
     110            $threshold = (int) apply_filters( FILTER_THRESHOLD, 1 );
     111            wp_localize_script(
     112                'dobby',
     113                'dobbySettings',
     114                [
     115                    'selectorCloset' => "#{$closet_id}",
     116                    'selectorDobby'  => "#{$dobby_id}",
     117                    'threshold'      => max( 1, $threshold ),
     118                ]
     119            );
     120        },
     121        PHP_INT_MAX
     122    );
    101123}
    102124
  • wp-dobby/trunk/readme.txt

    r1733044 r2497410  
    33Tags: admin, notices
    44Requires at least: 3.1.0
    5 Tested up to: 4.8
    6 Stable tag: v1.3.0
     5Tested up to: 5.7
     6Stable tag: 1.4.0
    77Requires PHP: 5.4
    88
     
    3030
    3131== Changelog ==
     32
     33= 1.4.0 =
     34* Bump "Tested up to" header, see [issue #12](https://github.com/tfrommen/Dobby/issues/12).
    3235
    3336= 1.3.0 =
Note: See TracChangeset for help on using the changeset viewer.