Completed
Push — master ( 9cf8ee...c7671f )
by Askupa
02:18 queued 27s
created

bootstrap.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 19 and the first side effect is on line 13.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * WordPress Admin Notifications
4
 *
5
 * Add static/dismissible admin notifications to WordPress
6
 *
7
 * @package   wp-admin-notification
8
 * @author    Askupa Software <[email protected]>
9
 * @link      https://github.com/askupasoftware/wp-admin-notification
10
 * @copyright 2016 Askupa Software
11
 */
12
13
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
14
15
/**
16
 * Prevent loading the library more than once
17
 */
18
if( defined( 'WP_ADMIN_NOTIFICATION' ) ) return;
19
define( 'WP_ADMIN_NOTIFICATION', true );
20
21
/**
22
 * Require the handler class and initiate it:
23
 */
24
require_once 'handler.php';
25
if(!function_exists('_wp_admin_notification_init'))
26
{
27
    function _wp_admin_notification_init() 
28
    {
29
        $notifier = WPAdminNotifications::get_instance();
30
        $notifier->init();
31
    }
32
    add_action( 'init', '_wp_admin_notification_init' );
33
}
34
35
if(!function_exists('wp_admin_notification'))
36
{
37
    /**
38
     * Register an admin notification.
39
     * 
40
     * @param type $handle
41
     * @param type $html
42
     * @param type $type
43
     * @param type $dismissible
44
     * @param type $class
45
     * @param type $network
46
     */
47
    function wp_admin_notification( $handle, $html, $type = 'success', $dismissible = false, $class = '', $network = false )
48
    {
49
        $notifier = WPAdminNotifications::get_instance();
50
        $notifier->register_notification($handle, array(
51
            'dismissible'   => $dismissible,
52
            'class'         => $class,
53
            'type'          => $type,
54
            'html'          => $html,
55
            'network'       => $network
56
        ));
57
    }
58
}
59
60
if(!function_exists('wp_reset_admin_notification'))
61
{
62
    /**
63
     * 
64
     * @param string $handle
65
     */
66
    function wp_reset_admin_notification( $handle )
67
    {
68
        $dismissed = get_option( 'wp_dismissed_notices' );
69
        $offset = 0;
70
        foreach($dismissed as $id)
71
        {
72
            if( $id === $handle ) break;
73
            $offset++;
74
        }
75
        array_splice( $dismissed, $offset, 1);
76
        update_option( 'wp_dismissed_notices', $dismissed );
77
    }
78
}