/var/www/html_uk/wp-content/plugins/automatewoo/includes/AdminNotices.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php

namespace AutomateWoo;

/**
 * Class to manage admin notices.
 *
 * @since   4.7.0
 * @package AutomateWoo
 */
class AdminNotices {

    
/**
     * Store of admin notices.
     *
     * @var array
     */
    
private static $notices;

    
/**
     * Whether notices have been changed and need to be saved.
     *
     * @var bool
     */
    
private static $has_changes false;

    
/**
     * Define whether AdminNotices::init() has run.
     *
     * @var bool
     */
    
private static $did_init false;

    
/**
     * Init admin notices.
     */
    
public static function init() {
        if ( 
self::$did_init ) {
            return;
        }

        
self::$did_init true;
        
add_action'shutdown', [ __CLASS__'save_notices' ] );

        if ( 
Permissions::can_manage() ) {
            
add_action'wp_ajax_automatewoo_remove_notice', [ __CLASS__'handle_ajax_remove_notice' ] );
            
add_action'admin_notices', [ __CLASS__'output_notices' ] );
        }
    }

    
/**
     * Get current admin notices.
     *
     * @return array
     */
    
public static function get_notices() {
        if ( ! isset( 
self::$notices ) ) {
            
self::$notices get_option'automatewoo_admin_notices', [] );
        }
        return 
self::$notices;
    }

    
/**
     * Add a notice.
     *
     * @param string $name
     */
    
public static function add_notice$name ) {
        
self::init();

        
self::$notices     array_uniquearray_mergeself::get_notices(), [ $name ] ) );
        
self::$has_changes true;
    }

    
/**
     * Remove a notice.
     *
     * @param string $name
     */
    
public static function remove_notice$name ) {
        
self::init();

        
self::$notices     array_diffself::get_notices(), [ $name ] );
        
self::$has_changes true;
    }

    
/**
     * Save notices to database.
     */
    
public static function save_notices() {
        if ( 
self::$has_changes ) {
            
update_option'automatewoo_admin_notices'self::get_notices() );
        }
    }

    
/**
     * Output admin notices.
     */
    
public static function output_notices() {
        
// Only show notices on AW screens
        
if ( ! Admin::is_automatewoo_screen() ) {
            return;
        }

        
$notices self::get_notices();

        foreach ( 
$notices as $notice ) {
            
$method_name "output_{$notice}_notice";
            if ( 
is_callable( [ __CLASS__$method_name ] ) ) {
                
call_user_func( [ __CLASS__$method_name ] );
            } else {
                
do_action"automatewoo/admin_notice/{$notice});
            }
        }
    }

    
/**
     * Remove notice by ajax request.
     */
    
public static function handle_ajax_remove_notice() {
        if ( ! 
wp_verify_noncesanitize_keyaw_get_post_var'nonce' ) ), 'aw-remove-notice' ) ) {
            
wp_dieesc_html__'Action failed. Please refresh the page and retry.''automatewoo' ) );
        }

        
$notice Clean::stringaw_get_post_var'notice' ) );
        if ( 
$notice ) {
            
self::remove_notice$notice );
        }
        die;
    }

    
/**
     * Output the notice about upcoming minimum requirements changes.
     *
     * @since 4.9.5
     */
    
private static function output_requirements_changes_notice() {
        
$notice_identifier 'requirements_changes';

        
// No upcoming requirements changes.
        
if (
            
version_compareAUTOMATEWOO_MIN_WP_VERAUTOMATEWOO_NOTICE_WP_VER'=' )
            && 
version_compareAUTOMATEWOO_MIN_WC_VERAUTOMATEWOO_NOTICE_WC_VER'=' )
        ) {
            
self::remove_notice$notice_identifier );
            return;
        }

        
// Upcoming version is the same as or less than the current version.
        
if ( version_compareAUTOMATEWOO_VERSIONAUTOMATEWOO_NOTICE_AW_VER'>=' ) ) {
            
self::remove_notice$notice_identifier );
            return;
        }

        global 
$wp_version;
        
$warn_wp version_compare$wp_versionAUTOMATEWOO_NOTICE_WP_VER'<' );
        
$warn_wc version_compareWC()->versionAUTOMATEWOO_NOTICE_WC_VER'<' );

        
// Nothing is behind the new requirements.
        
if ( ! $warn_wp && ! $warn_wc ) {
            
self::remove_notice$notice_identifier );
            return;
        }

        
$aw_pretty_version aw_prettify_versionAUTOMATEWOO_NOTICE_AW_VER );
        
$wp_pretty_version aw_prettify_versionAUTOMATEWOO_NOTICE_WP_VER );
        
$wc_pretty_version aw_prettify_versionAUTOMATEWOO_NOTICE_WC_VER );

        if ( 
$warn_wp && $warn_wc ) {
            
$message sprintf(
                
/* translators: %1$s AutomateWoo version, %2$s WordPress version, %3$s WooCommerce version */
                
__'AutomateWoo %1$s will require WordPress version %2$s or newer and WooCommerce version %3$s or newer.''automatewoo' ),
                
$aw_pretty_version,
                
$wp_pretty_version,
                
$wc_pretty_version
            
);
        } elseif ( 
$warn_wp ) {
            
$message sprintf(
                
/* translators: %1$s AutomateWoo version, %2$s WordPress version */
                
__'AutomateWoo %1$s will require WordPress version %2$s or newer.''automatewoo' ),
                
$aw_pretty_version,
                
$wp_pretty_version
            
);
        } elseif ( 
$warn_wc ) {
            
$message sprintf(
                
/* translators: %1$s AutomateWoo version, %2$s WooCommerce version */
                
__'AutomateWoo %1$s will require WooCommerce version %2$s or newer.''automatewoo' ),
                
$aw_pretty_version,
                
$wc_pretty_version
            
);
        }
        
Admin::get_view(
            
'simple-notice',
            [
                
'notice_identifier' => $notice_identifier,
                
'type'              => 'warning',
                
'class'             => 'is-dismissible',
                
'strong'            => __'Update required soon:''automatewoo' ),
                
'message'           => $message,
            ]
        );
    }
}