autoptimizeConfig::get_futtta_feeds()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 28

Duplication

Lines 4
Ratio 14.29 %

Importance

Changes 0
Metric Value
cc 5
nc 5
nop 1
dl 4
loc 28
rs 9.1608
c 0
b 0
f 0
1
<?php
2
/**
3
 * Main configuration logic.
4
 */
5
6
if ( ! defined( 'ABSPATH' ) ) {
7
    exit;
8
}
9
10
class autoptimizeConfig
11
{
12
    /**
13
     * Options.
14
     *
15
     * @var array
16
     */
17
    private $config = null;
18
19
    /**
20
     * Singleton instance.
21
     *
22
     * @var self|null
23
     */
24
    static private $instance = null;
25
26
    /**
27
     * Options.
28
     *
29
     * @var bool
30
     */
31
    private $settings_screen_do_remote_http = true;
32
33
    /**
34
     * Singleton.
35
     */
36
    private function __construct()
37
    {
38
        if ( is_admin() ) {
39
            // Add the admin page and settings.
40
            if ( autoptimizeOptionWrapper::is_ao_active_for_network() ) {
41
                add_action( 'network_admin_menu', array( $this, 'addmenu' ) );
42
            }
43
44
            add_action( 'admin_menu', array( $this, 'addmenu' ) );
45
            add_action( 'admin_init', array( $this, 'registersettings' ) );
46
            add_action( 'admin_init', array( 'PAnD', 'init' ) );
47
48
            // Set meta info.
49
            if ( function_exists( 'plugin_row_meta' ) ) {
50
                // 2.8 and higher.
51
                add_filter( 'plugin_row_meta', array( $this, 'setmeta' ), 10, 2 );
52
            } elseif ( function_exists( 'post_class' ) ) {
53
                // 2.7 and lower.
54
                $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
55
                add_filter( 'plugin_action_links_' . $plugin, array( $this, 'setmeta' ) );
56
            }
57
58
            // Clean cache?
59
            if ( autoptimizeOptionWrapper::get_option( 'autoptimize_cache_clean' ) ) {
60
                autoptimizeCache::clearall();
61
                autoptimizeOptionWrapper::update_option( 'autoptimize_cache_clean', 0 );
62
            }
63
64
            $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http );
65
        }
66
67
        // Adds the Autoptimize Toolbar to the Admin bar.
68
        // (we load outside the is_admin check so it's also displayed on the frontend toolbar).
69
        $toolbar = new autoptimizeToolbar();
0 ignored issues
show
Unused Code introduced by
$toolbar is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
70
    }
71
72
    /**
73
     * Instantiates aoconfig.
74
     *
75
     * @return autoptimizeConfig
76
     */
77
    static public function instance()
78
    {
79
        // Only one instance.
80
        if ( null === self::$instance ) {
81
            self::$instance = new autoptimizeConfig();
82
        }
83
84
        return self::$instance;
85
    }
86
87
    public function show_network_message() {
88
        ?>
89
        <div class="wrap">
90
            <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
91
            <?php echo $this->ao_admin_tabs(); ?>
92
            <p style="font-size:120%;"><?php echo apply_filters( 'autoptimize_filter_settingsscreen_multisite_network_message', __( 'Autoptimize is enabled and configured on a WordPress network level. Please contact your network administrator if you need Autoptimize settings changed.', 'autoptimize' ) ); ?></p>
93
        </div>
94
        <?php
95
    }
96
97
    public function show_config()
98
    {
99
        $conf = self::instance();
100
        ?>
101
<style>
102
/* title and button */
103
#ao_title_and_button:after {content:''; display:block; clear:both;}
104
105
/* form */
106
.itemDetail {
107
    background: #fff;
108
    border: 1px solid #ccc;
109
    padding: 15px;
110
    margin: 15px 10px 10px 0;
111
}
112
.itemTitle {
113
    margin-top: 0;
114
}
115
116
input[type=url]:invalid {color: red; border-color:red;} .form-table th{font-weight:normal;}
117
#autoptimize_main .cb_label {display: block; padding-left: 25px; text-indent: -25px;}
118
#autoptimize_main .form-table th {padding-top: 15px; padding-bottom: 15px;}
119
#autoptimize_main .js_not_aggregate td, #autoptimize_main .js_not_aggregate th{padding-top:0px;}
120
121
/* rss block */
122
#futtta_feed ul{list-style:outside;}
123
#futtta_feed {font-size:medium; margin:0px 20px;}
124
125
/* banner + unslider */
126
.autoptimize_banner {
127
    margin: 0 38px;
128
    padding-bottom: 5px;
129
}
130
.autoptimize_banner ul li {
131
    font-size:medium;
132
    text-align:center;
133
}
134
.unslider {
135
    position:relative;
136
}
137
.unslider-arrow {
138
    display: block;
139
    left: unset;
140
    margin-top: -35px;
141
    margin-left: 7px;
142
    margin-right: 7px;
143
    border-radius: 32px;
144
    background: rgba(0, 0, 0, 0.10) no-repeat 50% 50%;
145
    color: rgba(255, 255, 255, 0.8);
146
    font: normal 20px/1 dashicons;
147
    speak: none;
148
    padding: 3px 2px 3px 4px;
149
    -webkit-font-smoothing: antialiased;
150
    -moz-osx-font-smoothing: grayscale;
151
}
152
.unslider-arrow:hover {
153
    background-color: rgba(0, 0, 0, 0.20);
154
    color: #FFF;
155
}
156
.unslider-arrow.prev {
157
    padding: 3px 4px 3px 2px;
158
}
159
.unslider-arrow.next {
160
    right: 0px;
161
}
162
.unslider-arrow.prev::before {
163
    content: "\f341";
164
}
165
.unslider-arrow.next::before {
166
    content: "\f345";
167
}
168
169
/* responsive stuff: hide admin-feed on smaller screens */
170
@media (min-width: 961px) {
171
    #autoptimize_main {float:left;width:69%;}
172
    #autoptimize_admin_feed{float:right;width:30%;display:block !important;}
173
    }
174
@media (max-width: 960px) {
175
    #autoptimize_main {width:100%;}
176
    #autoptimize_admin_feed {width:0%;display:none !important;}
177
}
178
@media (max-width: 782px) {
179
    #autoptimize_main input[type="checkbox"] {margin-left: 10px;}
180
    #autoptimize_main .cb_label {display: block; padding-left: 45px; text-indent: -45px;}
181
}
182
</style>
183
184
<div class="wrap">
185
186
<!-- Temporary nudge to disable aoccss power-up. -->
187
<?php if ( autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) { ?>
188
    <div class="notice-info notice"><p>
189
        <?php _e( 'Autoptimize now includes the criticalcss.com integration that was previously part of the separate power-up. If you want you can simply disable the power-up and Autoptimize will take over immediately.', 'autoptimize' ); ?>
190
    </p></div>
191
<?php } ?>
192
193
<div id="autoptimize_main">
194
    <h1 id="ao_title"><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
195
    <?php echo $this->ao_admin_tabs(); ?>
196
197
<form method="post" action="<?php echo admin_url( 'options.php' ); ?>">
198
<?php settings_fields( 'autoptimize' ); ?>
199
200
<ul>
201
202
<?php
203
// Only show enable site configuration in network site option.
204
if ( is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
205
?>
206
    <li class="itemDetail multiSite">
207
        <h2 class="itemTitle"><?php _e( 'Multisite Options', 'autoptimize' ); ?></h2>
208
        <table class="form-table">
209
            <tr valign="top">
210
                <th scope="row"><?php _e( 'Enable site configuration?', 'autoptimize' ); ?></th>
211
                <td><label class="cb_label"><input type="checkbox" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ? 'checked="checked" ' : ''; ?>/>
212
                <?php _e( 'Enable Autoptimize configuration per site.', 'autoptimize' ); ?></label></td>
213
            </tr>
214
        </table>
215
    </li>
216
<?php } else { ?>
217
    <input type="hidden" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" value="on" />
218
<?php } ?>    
219
220
<li class="itemDetail">
221
<h2 class="itemTitle"><?php _e( 'JavaScript Options', 'autoptimize' ); ?></h2>
222
<table class="form-table">
223
<tr valign="top">
224
<th scope="row"><?php _e( 'Optimize JavaScript Code?', 'autoptimize' ); ?></th>
225
<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) ? 'checked="checked" ' : ''; ?>/></td>
226
</tr>
227
<tr valign="top" class="js_sub js_aggregate_master">
228
<th scope="row"><?php _e( 'Aggregate JS-files?', 'autoptimize' ); ?></th>
229
<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_aggregate" name="autoptimize_js_aggregate" <?php echo $conf->get( 'autoptimize_js_aggregate' ) ? 'checked="checked" ' : ''; ?>/>
230
<?php _e( 'Aggregate all linked JS-files to have them loaded non-render blocking? If this option is off, the individual JS-files will remain in place but will be minified.', 'autoptimize' ); ?></label></td>
231
</tr>
232
<tr valign="top" class="js_sub js_not_aggregate">
233
<th scope="row"><?php _e( 'Do not aggregate but defer?', 'autoptimize' ); ?></th>
234
<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_defer_not_aggregate" name="autoptimize_js_defer_not_aggregate" <?php echo $conf->get( 'autoptimize_js_defer_not_aggregate' ) ? 'checked="checked" ' : ''; ?>/>
235
<?php _e( 'When JS is not aggregated, all linked JS-files can be deferred instead, making them non-render-blocking.', 'autoptimize' ); ?></label></td>
236
</tr>
237
<tr valign="top" class="js_sub js_aggregate">
238
<th scope="row"><?php _e( 'Also aggregate inline JS?', 'autoptimize' ); ?></th>
239
<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_include_inline' ) ? 'checked="checked" ' : ''; ?>/>
240
<?php _e( 'Let Autoptimize also extract JS from the HTML. <strong>Warning</strong>: this can make Autoptimize\'s cache size grow quickly, so only enable this if you know what you\'re doing.', 'autoptimize' ); ?></label></td>
241
</tr>
242
<tr valign="top" class="js_sub js_aggregate">
243
<th scope="row"><?php _e( 'Force JavaScript in &lt;head&gt;?', 'autoptimize' ); ?></th>
244
<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_forcehead' ) ? 'checked="checked" ' : ''; ?>/>
245
<?php _e( 'Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize' ); ?></label></td>
246
</tr>
247 View Code Duplication
<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ) { ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
248
<tr valign="top" class="js_sub js_aggregate">
249
<th scope="row">
250
<?php
251
    _e( 'Look for scripts only in &lt;head&gt;?', 'autoptimize' );
252
    echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
253
?>
254
</th>
255
<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ? 'checked="checked" ' : ''; ?>/>
256
<?php _e( 'Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.', 'autoptimize' ); ?></label></td>
257
</tr>
258
<?php } ?>
259
<tr valign="top" class="js_sub">
260
<th scope="row"><?php _e( 'Exclude scripts from Autoptimize:', 'autoptimize' ); ?></th>
261
<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo esc_attr( autoptimizeOptionWrapper::get_option( 'autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js, js/jquery/jquery.min.js' ) ); ?>"/><br />
262
<?php
263
echo __( 'A comma-separated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated by Autoptimize.', 'autoptimize' ) . ' ' . __( 'Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize' );
264
?>
265
</label></td>
266
</tr>
267
<tr valign="top" class="js_sub js_aggregate">
268
<th scope="row"><?php _e( 'Add try-catch wrapping?', 'autoptimize' ); ?></th>
269
<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_trycatch' ) ? 'checked="checked" ' : ''; ?>/>
270
<?php _e( 'If your scripts break because of a JS-error, you might want to try this.', 'autoptimize' ); ?></label></td>
271
</tr>
272
</table>
273
</li>
274
275
<li class="itemDetail">
276
<h2 class="itemTitle"><?php _e( 'CSS Options', 'autoptimize' ); ?></h2>
277
<table class="form-table">
278
<tr valign="top">
279
<th scope="row"><?php _e( 'Optimize CSS Code?', 'autoptimize' ); ?></th>
280
<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) ? 'checked="checked" ' : ''; ?>/></td>
281
</tr>
282
<tr class="css_sub" valign="top">
283
<th scope="row"><?php _e( 'Aggregate CSS-files?', 'autoptimize' ); ?></th>
284
<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_aggregate" name="autoptimize_css_aggregate" <?php echo $conf->get( 'autoptimize_css_aggregate' ) ? 'checked="checked" ' : ''; ?>/>
285
<?php _e( 'Aggregate all linked CSS-files? If this option is off, the individual CSS-files will remain in place but will be minified.', 'autoptimize' ); ?></label></td>
286
</tr>
287
<tr valign="top" class="css_sub css_aggregate">
288
<th scope="row"><?php _e( 'Also aggregate inline CSS?', 'autoptimize' ); ?></th>
289
<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_include_inline', '1' ) ? 'checked="checked" ' : ''; ?>/>
290
<?php _e( 'Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize' ); ?></label></td>
291
</tr>
292
<tr class="css_sub css_aggregate" valign="top">
293
<th scope="row"><?php _e( 'Generate data: URIs for images?', 'autoptimize' ); ?></th>
294
<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_datauris' ) ? 'checked="checked" ' : ''; ?>/>
295
<?php _e( 'Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize' ); ?></label></td>
296
</tr>
297 View Code Duplication
<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ) { ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
298
<tr valign="top" class="css_sub css_aggregate">
299
<th scope="row">
300
<?php
301
_e( 'Look for styles only in &lt;head&gt;?', 'autoptimize' );
302
echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
303
?>
304
</th>
305
<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ? 'checked="checked" ' : ''; ?>/>
306
<?php _e( 'Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize' ); ?></label></td>
307
</tr>
308
<?php } ?>
309
<tr valign="top" class="css_sub">
310
<th scope="row"><?php _e( 'Inline and Defer CSS?', 'autoptimize' ); ?></th>
311
<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer' ) ? 'checked="checked" ' : ''; ?>/>
312
<?php
313
_e( 'Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> for more info.', 'autoptimize' );
314
echo ' ';
315
$critcss_settings_url = get_admin_url( null, 'options-general.php?page=ao_critcss' );
316
// translators: links "autoptimize critical CSS" tab.
317
echo sprintf( __( 'This can be fully automated for different types of pages on the %s tab.', 'autoptimize' ), '<a href="' . $critcss_settings_url . '">CriticalCSS</a>' );
318
?>
319
</label></td>
320
</tr>
321
<tr valign="top" class="css_sub" id="autoptimize_css_defer_inline">
322
<th scope="row"></th>
323
<td><label><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste the above the fold CSS here. You can leave this empty when using the automated Critical CSS integration.', 'autoptimize' ); ?>" name="autoptimize_css_defer_inline"><?php echo autoptimizeStyles::sanitize_css( autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer_inline' ) ); ?></textarea></label></td>
324
</tr>
325
<tr valign="top" class="css_sub css_aggregate">
326
<th scope="row"><?php _e( 'Inline all CSS?', 'autoptimize' ); ?></th>
327
<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_inline' ) ? 'checked="checked" ' : ''; ?>/>
328
<?php _e( 'Inlining all CSS is an easy way to stop the CSS from being render-blocking, but is generally not recommended because the size of the HTML increases significantly. Additionally it might push meta-tags down to a position where e.g. Facebook and Whatsapp will not find them any more, breaking thumbnails when sharing.', 'autoptimize' ); ?></label></td>
329
</tr>
330
<tr valign="top" class="css_sub">
331
<th scope="row"><?php _e( 'Exclude CSS from Autoptimize:', 'autoptimize' ); ?></th>
332
<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo esc_attr( autoptimizeOptionWrapper::get_option( 'autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css' ) ); ?>"/><br />
333
<?php
334
echo __( 'A comma-separated list of CSS you want to exclude from being optimized.', 'autoptimize' ) . ' ' . __( 'Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize' );
335
?>
336
</label></td>
337
</tr>
338
</table>
339
</li>
340
341
<li class="itemDetail">
342
<h2 class="itemTitle"><?php _e( 'HTML Options', 'autoptimize' ); ?></h2>
343
<table class="form-table">
344
<tr valign="top">
345
<th scope="row"><?php _e( 'Optimize HTML Code?', 'autoptimize' ); ?></th>
346
<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) ? 'checked="checked" ' : ''; ?>/></td>
347
</tr>
348
<tr class="html_sub" valign="top">
349
<th scope="row"><?php _e( 'Keep HTML comments?', 'autoptimize' ); ?></th>
350
<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html_keepcomments' ) ? 'checked="checked" ' : ''; ?>/>
351
<?php _e( 'Enable this if you want HTML comments to remain in the page.', 'autoptimize' ); ?></label></td>
352
</tr>
353
</table>
354
</li>
355
356
<li class="itemDetail">
357
<h2 class="itemTitle"><?php _e( 'CDN Options', 'autoptimize' ); ?></h2>
358
<table class="form-table">
359
<tr valign="top">
360
<th scope="row"><?php _e( 'CDN Base URL', 'autoptimize' ); ?></th>
361
<td><label><input id="cdn_url" type="text" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*(:\d{2,5})?\/?$" style="width:100%" value="<?php echo esc_url( autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' ), array( 'http', 'https' ) ); ?>" /><br />
362
<?php _e( 'Enter your CDN root URL to enable CDN for Autoptimized files. The URL can be http, https or protocol-relative (e.g. <code>//cdn.example.com/</code>). This is not needed for Cloudflare.', 'autoptimize' ); ?></label></td>
363
</tr>
364
</table>
365
</li>
366
367
<li class="itemDetail">
368
<h2 class="itemTitle"><?php _e( 'Cache Info', 'autoptimize' ); ?></h2>
369
<table class="form-table" >
370
<tr valign="top" >
371
<th scope="row"><?php _e( 'Cache folder', 'autoptimize' ); ?></th>
372
<td><?php echo htmlentities( AUTOPTIMIZE_CACHE_DIR ); ?></td>
373
</tr>
374
<tr valign="top" >
375
<th scope="row"><?php _e( 'Can we write?', 'autoptimize' ); ?></th>
376
<td><?php echo ( autoptimizeCache::cacheavail() ? __( 'Yes', 'autoptimize' ) : __( 'No', 'autoptimize' ) ); ?></td>
377
</tr>
378
<tr valign="top" >
379
<th scope="row"><?php _e( 'Cached styles and scripts', 'autoptimize' ); ?></th>
380
<td>
381
    <?php
382
    $ao_stat_arr = autoptimizeCache::stats();
383
    if ( ! empty( $ao_stat_arr ) && is_array( $ao_stat_arr ) ) {
384
        $ao_cache_size = size_format( $ao_stat_arr[1], 2 );
385
        $details       = '';
0 ignored issues
show
Unused Code introduced by
$details is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
386
        if ( $ao_cache_size > 0 ) {
387
            $details = ', ~' . $ao_cache_size . ' total';
0 ignored issues
show
Unused Code introduced by
$details is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
388
        }
389
        // translators: Kilobytes + timestamp shown.
390
        printf( __( '%1$s files, totalling %2$s (calculated at %3$s)', 'autoptimize' ), $ao_stat_arr[0], $ao_cache_size, date( 'H:i e', $ao_stat_arr[2] ) );
391
    }
392
    ?>
393
</td>
394
</tr>
395
</table>
396
</li>
397
398
<li class="itemDetail">
399
<h2 class="itemTitle"><?php _e( 'Misc Options', 'autoptimize' ); ?></h2>
400
<table class="form-table">
401
    <tr valign="top" >
402
    <th scope="row"><?php _e( 'Save aggregated script/css as static files?', 'autoptimize' ); ?></th>
403
    <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_nogzip', '1' ) ? 'checked="checked" ' : ''; ?>/>
404
    <?php _e( 'By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.', 'autoptimize' ); ?></label></td>
405
    </tr>
406
    <?php
407
    $_min_excl_class = '';
408
    if ( ! $conf->get( 'autoptimize_css_aggregate' ) && ! $conf->get( 'autoptimize_js_aggregate' ) ) {
409
        $_min_excl_class = 'hidden';
410
    }
411
    ?>
412
    <tr valign="top" id="min_excl_row" class="<?php echo $_min_excl_class; ?>">
413
        <th scope="row"><?php _e( 'Minify excluded CSS and JS files?', 'autoptimize' ); ?></th>
414
        <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_minify_excluded', '1' ) ? 'checked="checked" ' : ''; ?>/>
415
        <?php _e( 'When aggregating JS or CSS, excluded files that are not minified (based on filename) are by default minified by Autoptimize despite being excluded. Uncheck this option if anything breaks despite excluding.', 'autoptimize' ); ?></label></td>
416
    </tr>
417
    <tr valign="top">
418
        <th scope="row"><?php _e( 'Enable 404 fallbacks?', 'autoptimize' ); ?></th>
419
        <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '1' ) ? 'checked="checked" ' : ''; ?>/>
420
        <?php _e( 'Sometimes Autoptimized JS/ CSS is referenced in cached HTML but is already removed, resulting in broken sites. With this option on, Autoptimize will try to redirect those not-found files to "fallback"-versions, keeping the page/ site somewhat intact. In some cases this will require extra web-server level configuration to ensure <code>wp-content/autoptimize_404_handler.php</code> is set to handle 404\'s in <code>wp-content/cache/autoptimize</code>.', 'autoptimize' ); ?></label></td>
421
    </tr>
422
    <tr valign="top">
423
    <th scope="row"><?php _e( 'Also optimize for logged in editors/ administrators?', 'autoptimize' ); ?></th>
424
    <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', '1' ) ? 'checked="checked" ' : ''; ?>/>
425
    <?php _e( 'By default Autoptimize is also active for logged on editors/ administrators, uncheck this option if you don\'t want Autoptimize to optimize when logged in e.g. to use a pagebuilder.', 'autoptimize' ); ?></label></td>
426
    </tr>
427
    <?php
428
    if ( function_exists( 'is_checkout' ) || function_exists( 'is_cart' ) || function_exists( 'edd_is_checkout' ) || function_exists( 'wpsc_is_cart' ) || function_exists( 'wpsc_is_checkout' ) ) {
429
    ?>
430
    <tr valign="top" >
431
        <th scope="row"><?php _e( 'Also optimize shop cart/ checkout?', 'autoptimize' ); ?></th>
432
        <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', '0' ) ? 'checked="checked" ' : ''; ?>/>
433
            <?php _e( 'By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize' ); ?></label>
434
        </td>
435
    </tr>
436
    <?php } ?>
437
</table>
438
</li>
439
440
</ul>
441
442
<p class="submit">
443
<input type="submit" class="button-secondary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" />
444
<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e( 'Save Changes and Empty Cache', 'autoptimize' ); ?>" />
445
</p>
446
447
</form>
448
</div>
449
<div id="autoptimize_admin_feed" class="hidden">
450
    <div class="autoptimize_banner hidden">
451
    <ul>
452
    <?php
453
    if ( $this->settings_screen_do_remote_http ) {
454
        $ao_banner = get_transient( 'autoptimize_banner' );
455
        if ( empty( $ao_banner ) ) {
456
            $banner_resp = wp_remote_get( 'https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver=' . AUTOPTIMIZE_PLUGIN_VERSION );
457
            if ( ! is_wp_error( $banner_resp ) ) {
458
                if ( '200' == wp_remote_retrieve_response_code( $banner_resp ) ) {
459
                    $ao_banner = wp_kses_post( wp_remote_retrieve_body( $banner_resp ) );
460
                    set_transient( 'autoptimize_banner', $ao_banner, WEEK_IN_SECONDS );
461
                }
462
            }
463
        }
464
        echo $ao_banner;
465
    }
466
    ?>
467
        <li><?php _e( "Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize' ); ?></li>
468
        <li><?php _e( 'Happy with Autoptimize?', 'autoptimize' ); ?><br /><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php _e( 'Try my other plugins!', 'autoptimize' ); ?></a></li>
469
    </ul>
470
    </div>
471
    <div style="margin-left:10px;margin-top:-5px;">
472
        <h2>
473
            <?php _e( 'futtta about', 'autoptimize' ); ?>
474
            <select id="feed_dropdown" >
475
                <option value="1"><?php _e( 'Autoptimize', 'autoptimize' ); ?></option>
476
                <option value="2"><?php _e( 'WordPress', 'autoptimize' ); ?></option>
477
                <option value="3"><?php _e( 'Web Technology', 'autoptimize' ); ?></option>
478
            </select>
479
        </h2>
480
        <div id="futtta_feed">
481
            <div id="autoptimizefeed">
482
                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_autoptimize' ); ?>
483
            </div>
484
            <div id="wordpressfeed">
485
                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_wordpress' ); ?>
486
            </div>
487
            <div id="webtechfeed">
488
                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_webtech' ); ?>
489
            </div>
490
        </div>
491
    </div>
492
    <div style="float:right;margin:50px 15px;"><a href="https://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url() . '/' . plugin_basename( dirname( __FILE__ ) ) . '/external/do_not_donate_smallest.png'; ?>" title="<?php _e( 'Do not donate for this plugin!', 'autoptimize' ); ?>"></a></div>
493
</div>
494
495
<script type="text/javascript">
496
    var feed = new Array;
497
    feed[1]="autoptimizefeed";
498
    feed[2]="wordpressfeed";
499
    feed[3]="webtechfeed";
500
    cookiename="autoptimize_feed";
501
502
    jQuery(document).ready(function() {
503
        check_ini_state();
504
505
        jQuery('#autoptimize_admin_feed').fadeTo("slow",1).show();
506
        jQuery('.autoptimize_banner').unslider({autoplay:true, delay:3500, infinite: false, arrows:{prev:'<a class="unslider-arrow prev"></a>', next:'<a class="unslider-arrow next"></a>'}}).fadeTo("slow",1).show();
507
508
        jQuery( "#feed_dropdown" ).change(function() {
509
            jQuery("#futtta_feed").fadeTo(0,0);
510
            jQuery("#futtta_feed").fadeTo("slow",1);
511
        });
512
513
        jQuery( "#autoptimize_html" ).change(function() {
514
            if (this.checked) {
515
                jQuery(".html_sub:visible").fadeTo("fast",1);
516
            } else {
517
                jQuery(".html_sub:visible").fadeTo("fast",.33);
518
            }
519
        });
520
521
        jQuery( "#autoptimize_js" ).change(function() {
522
            if (this.checked) {
523
                jQuery(".js_sub:visible").fadeTo("fast",1);
524
            } else {
525
                jQuery(".js_sub:visible").fadeTo("fast",.33);
526
            }
527
        });
528
529
        jQuery( "#autoptimize_js_aggregate" ).change(function() {
530
            if (this.checked && jQuery("#autoptimize_js").prop('checked')) {
531
                jQuery( ".js_aggregate:visible" ).fadeTo( "fast",1 );
532
                jQuery( "#autoptimize_js_defer_not_aggregate" ).prop( 'checked', false );
533
                jQuery( ".js_not_aggregate:visible" ).fadeTo( "fast", .33 );
534
                jQuery( ".js_aggregate_master:visible" ).fadeTo( "fast", 1 );
535
                jQuery( "#min_excl_row" ).show();
536
            } else {
537
                jQuery( ".js_aggregate:visible" ).fadeTo( "fast", .33 );
538
                jQuery( ".js_not_aggregate:visible" ).fadeTo( "fast", 1 );
539
                if ( jQuery( "#autoptimize_css_aggregate" ).prop( 'checked' ) == false ) {
540
                    jQuery( "#min_excl_row" ).hide();
541
                }
542
            }
543
        });
544
        
545
        jQuery( "#autoptimize_js_defer_not_aggregate" ).change(function() {
546
            if (this.checked && jQuery("#autoptimize_js").prop('checked')) {
547
                jQuery( "#autoptimize_js_aggregate" ).prop( 'checked', false );
548
                jQuery( ".js_aggregate:visible" ).fadeTo( "fast", .33 );
549
                jQuery( ".js_aggregate_master:visible" ).fadeTo( "fast", .33 );
550
                jQuery( ".js_not_aggregate:visible" ).fadeTo( "fast", 1 );
551
            } else {
552
                jQuery( ".js_aggregate_master:visible" ).fadeTo( "fast", 1 );
553
            }
554
        });
555
556
        jQuery( "#autoptimize_css" ).change(function() {
557
            if (this.checked) {
558
                jQuery(".css_sub:visible").fadeTo("fast",1);
559
            } else {
560
                jQuery(".css_sub:visible").fadeTo("fast",.33);
561
            }
562
        });
563
564
        jQuery( "#autoptimize_css_aggregate" ).change(function() {
565
            if (this.checked && jQuery("#autoptimize_css").prop('checked')) {
566
                jQuery(".css_aggregate:visible").fadeTo("fast",1);
567
                jQuery( "#min_excl_row" ).show();
568
            } else {
569
                jQuery(".css_aggregate:visible").fadeTo("fast",.33);
570
                if ( jQuery( "#autoptimize_js_aggregate" ).prop('checked') == false ) {
571
                    jQuery( "#min_excl_row" ).hide();
572
                }
573
            }
574
        });
575
576
        jQuery( "#autoptimize_css_inline" ).change(function() {
577
            if (this.checked) {
578
                jQuery("#autoptimize_css_defer").prop("checked",false);
579
                jQuery("#autoptimize_css_defer_inline").hide("slow");
580
            }
581
        });
582
583
        jQuery( "#autoptimize_css_defer" ).change(function() {
584
            if (this.checked) {
585
                jQuery("#autoptimize_css_inline").prop("checked",false);
586
                jQuery("#autoptimize_css_defer_inline").show("slow");
587
            } else {
588
                jQuery("#autoptimize_css_defer_inline").hide("slow");
589
            }
590
        });
591
592
        jQuery( "#autoptimize_enable_site_config" ).change(function() {
593
            if (this.checked) {
594
                jQuery("li.itemDetail:not(.multiSite)").fadeTo("fast",.33);
595
            } else {
596
                jQuery("li.itemDetail:not(.multiSite)").fadeTo("fast",1);
597
            }
598
        });
599
600
        jQuery("#feed_dropdown").change(function() { show_feed(jQuery("#feed_dropdown").val()) });
601
        feedid=jQuery.cookie(cookiename);
602
        if(typeof(feedid) !== "string") feedid=1;
603
        show_feed(feedid);
604
    })
605
606
    // validate cdn_url.
607
    var cdn_url=document.getElementById("cdn_url");
608
    cdn_url_baseCSS=cdn_url.style.cssText;
609
    if ("validity" in cdn_url) {
610
        jQuery("#cdn_url").focusout(function (event) {
611
        if (cdn_url.validity.valid) {
612
            cdn_url.style.cssText=cdn_url_baseCSS;
613
        } else {
614
            cdn_url.style.cssText=cdn_url_baseCSS+"border:1px solid #f00;color:#f00;box-shadow: 0 0 2px #f00;";
615
        }});
616
    }
617
618
    function check_ini_state() {
619
        if (!jQuery("#autoptimize_css_defer").prop('checked')) {
620
            jQuery("#autoptimize_css_defer_inline").hide();
621
        }
622
        if (!jQuery("#autoptimize_html").prop('checked')) {
623
            jQuery(".html_sub:visible").fadeTo('fast',.33);
624
        }
625
        if (!jQuery("#autoptimize_css").prop('checked')) {
626
            jQuery(".css_sub:visible").fadeTo('fast',.33);
627
        }
628
        if (!jQuery("#autoptimize_css_aggregate").prop('checked')) {
629
            jQuery(".css_aggregate:visible").fadeTo('fast',.33);
630
        }
631
        if (!jQuery("#autoptimize_js").prop('checked')) {
632
            jQuery(".js_sub:visible").fadeTo('fast',.33);
633
        }
634
        if (!jQuery("#autoptimize_js_aggregate").prop('checked')) {
635
            jQuery(".js_aggregate:visible").fadeTo('fast',.33);
636
        } else {
637
            jQuery( ".js_not_aggregate:visible" ).fadeTo( 'fast', .33 );
638
        }
639
        if (jQuery("#autoptimize_enable_site_config").prop('checked')) {
640
            jQuery("li.itemDetail:not(.multiSite)").fadeTo('fast',.33);
641
        }
642
    }
643
644
    function show_feed(id) {
645
        jQuery('#futtta_feed').children().hide();
646
        jQuery('#'+feed[id]).show();
647
        jQuery("#feed_dropdown").val(id);
648
        jQuery.cookie(cookiename,id,{ expires: 365 });
649
    }
650
</script>
651
</div>
652
653
<?php
654
    }
655
656
    public function addmenu()
657
    {
658
        if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
659
            // multisite, network admin, ao network activated: add normal settings page at network level.
660
            $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_network_options', 'autoptimize', array( $this, 'show_config' ) );
661
        } elseif ( is_multisite() && ! is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
662
            // multisite, ao network activated, not network admin so site specific settings, but "autoptimize_enable_site_config" is off: show "sorry, ask network admin" message iso options.
663
            $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_network_message' ) );
664
        } else {
665
            // default: show normal options page if not multisite, if multisite but not network activated, if multisite and network activated and "autoptimize_enable_site_config" is on.
666
            $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_config' ) );
667
        }
668
669
        add_action( 'admin_print_scripts-' . $hook, array( $this, 'autoptimize_admin_scripts' ) );
670
        add_action( 'admin_print_styles-' . $hook, array( $this, 'autoptimize_admin_styles' ) );
671
    }
672
673
    public function autoptimize_admin_scripts()
674
    {
675
        wp_enqueue_script( 'jqcookie', plugins_url( '/external/js/jquery.cookie.min.js', __FILE__ ), array( 'jquery' ), null, true );
676
        wp_enqueue_script( 'unslider', plugins_url( '/external/js/unslider-min.js', __FILE__ ), array( 'jquery' ), null, true );
677
    }
678
679
    public function autoptimize_admin_styles()
680
    {
681
        wp_enqueue_style( 'unslider', plugins_url( '/external/js/unslider.css', __FILE__ ) );
682
        wp_enqueue_style( 'unslider-dots', plugins_url( '/external/js/unslider-dots.css', __FILE__ ) );
683
    }
684
685
    public function registersettings() {
686
        register_setting( 'autoptimize', 'autoptimize_html' );
687
        register_setting( 'autoptimize', 'autoptimize_html_keepcomments' );
688
        register_setting( 'autoptimize', 'autoptimize_enable_site_config' );
689
        register_setting( 'autoptimize', 'autoptimize_js' );
690
        register_setting( 'autoptimize', 'autoptimize_js_aggregate' );
691
        register_setting( 'autoptimize', 'autoptimize_js_defer_not_aggregate' );
692
        register_setting( 'autoptimize', 'autoptimize_js_exclude' );
693
        register_setting( 'autoptimize', 'autoptimize_js_trycatch' );
694
        register_setting( 'autoptimize', 'autoptimize_js_justhead' );
695
        register_setting( 'autoptimize', 'autoptimize_js_forcehead' );
696
        register_setting( 'autoptimize', 'autoptimize_js_include_inline' );
697
        register_setting( 'autoptimize', 'autoptimize_css' );
698
        register_setting( 'autoptimize', 'autoptimize_css_aggregate' );
699
        register_setting( 'autoptimize', 'autoptimize_css_exclude' );
700
        register_setting( 'autoptimize', 'autoptimize_css_justhead' );
701
        register_setting( 'autoptimize', 'autoptimize_css_datauris' );
702
        register_setting( 'autoptimize', 'autoptimize_css_defer' );
703
        register_setting( 'autoptimize', 'autoptimize_css_defer_inline' );
704
        register_setting( 'autoptimize', 'autoptimize_css_inline' );
705
        register_setting( 'autoptimize', 'autoptimize_css_include_inline' );
706
        register_setting( 'autoptimize', 'autoptimize_cdn_url' );
707
        register_setting( 'autoptimize', 'autoptimize_cache_clean' );
708
        register_setting( 'autoptimize', 'autoptimize_cache_nogzip' );
709
        register_setting( 'autoptimize', 'autoptimize_optimize_logged' );
710
        register_setting( 'autoptimize', 'autoptimize_optimize_checkout' );
711
        register_setting( 'autoptimize', 'autoptimize_minify_excluded' );
712
        register_setting( 'autoptimize', 'autoptimize_cache_fallback' );
713
    }
714
715
    public function setmeta( $links, $file = null )
716
    {
717
        // Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/.
718
        // Do it only once - saves time.
719
        static $plugin;
720
        if ( empty( $plugin ) ) {
721
            $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
722
        }
723
724
        if ( null === $file ) {
725
            // 2.7 and lower.
726
            $settings_link = sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) );
727
            array_unshift( $links, $settings_link );
728
        } else {
729
            // 2.8 and higher.
730
            // If it's us, add the link.
731
            if ( $file === $plugin ) {
732
                $newlink = array( sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) ) );
733
                $links   = array_merge( $links, $newlink );
734
            }
735
        }
736
737
        return $links;
738
    }
739
740
    /**
741
     * Provides the default options.
742
     *
743
     * @return array
744
     */
745
    public static function get_defaults()
746
    {
747
        static $config = array(
748
            'autoptimize_html'                   => 0,
749
            'autoptimize_html_keepcomments'      => 0,
750
            'autoptimize_enable_site_config'     => 1,
751
            'autoptimize_js'                     => 0,
752
            'autoptimize_js_aggregate'           => 1,
753
            'autoptimize_js_defer_not_aggregate' => 0,
754
            'autoptimize_js_exclude'             => 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js, js/jquery/jquery.min.js',
755
            'autoptimize_js_trycatch'            => 0,
756
            'autoptimize_js_justhead'            => 0,
757
            'autoptimize_js_include_inline'      => 0,
758
            'autoptimize_js_forcehead'           => 0,
759
            'autoptimize_css'                    => 0,
760
            'autoptimize_css_aggregate'          => 1,
761
            'autoptimize_css_exclude'            => 'admin-bar.min.css, dashicons.min.css, wp-content/cache/, wp-content/uploads/',
762
            'autoptimize_css_justhead'           => 0,
763
            'autoptimize_css_include_inline'     => 1,
764
            'autoptimize_css_defer'              => 0,
765
            'autoptimize_css_defer_inline'       => '',
766
            'autoptimize_css_inline'             => 0,
767
            'autoptimize_css_datauris'           => 0,
768
            'autoptimize_cdn_url'                => '',
769
            'autoptimize_cache_nogzip'           => 1,
770
            'autoptimize_optimize_logged'        => 1,
771
            'autoptimize_optimize_checkout'      => 0,
772
            'autoptimize_minify_excluded'        => 1,
773
            'autoptimize_cache_fallback'         => 1,
774
        );
775
776
        return $config;
777
    }
778
779
    /**
780
     * Returns default option values for autoptimizeExtra.
781
     *
782
     * @return array
783
     */
784
    public static function get_ao_extra_default_options()
785
    {
786
        $defaults = array(
787
            'autoptimize_extra_checkbox_field_1' => '0',
788
            'autoptimize_extra_checkbox_field_0' => '0',
789
            'autoptimize_extra_radio_field_4'    => '1',
790
            'autoptimize_extra_text_field_2'     => '',
791
            'autoptimize_extra_text_field_3'     => '',
792
            'autoptimize_extra_text_field_7'     => '',
793
        );
794
795
        return $defaults;
796
    }
797
798
    /**
799
     * Returns default option values for autoptimizeExtra.
800
     *
801
     * @return array
802
     */
803
    public static function get_ao_imgopt_default_options()
804
    {
805
        $defaults = array(
806
            'autoptimize_imgopt_checkbox_field_1' => '0', // imgopt off.
807
            'autoptimize_imgopt_select_field_2'   => '2', // quality glossy.
808
            'autoptimize_imgopt_checkbox_field_3' => '0', // lazy load off.
809
            'autoptimize_imgopt_checkbox_field_4' => '0', // webp off (might be removed).
810
            'autoptimize_imgopt_text_field_5'     => '',  // lazy load exclusions empty.
811
            'autoptimize_imgopt_text_field_6'     => '',  // optimization exclusions empty.
812
            'autoptimize_imgopt_number_field_7'   => '0', // lazy load from nth image (0 = lazyload all).
813
        );
814
        return $defaults;
815
    }
816
817
    /**
818
     * Returns preload JS onload handler.
819
     *
820
     * @param string $media media attribute value the JS to use.
821
     *
822
     * @return string
823
     */
824
    public static function get_ao_css_preload_onload( $media = 'all' )
825
    {
826
        $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.media='" . $media . "';" );
827
        return $preload_onload;
828
    }
829
830
    public function get( $key )
831
    {
832
        if ( ! is_array( $this->config ) ) {
833
            // Default config.
834
            $config = self::get_defaults();
835
836
            // Override with user settings.
837
            foreach ( array_keys( $config ) as $name ) {
838
                $conf = autoptimizeOptionWrapper::get_option( $name );
839
                if ( false !== $conf ) {
840
                    // It was set before!
841
                    $config[ $name ] = $conf;
842
                }
843
            }
844
845
            // Save for next call.
846
            $this->config = apply_filters( 'autoptimize_filter_get_config', $config );
847
        }
848
849
        if ( isset( $this->config[ $key ] ) ) {
850
            return $this->config[ $key ];
851
        }
852
853
        return false;
854
    }
855
856
    private function get_futtta_feeds( $url ) {
857
        if ( $this->settings_screen_do_remote_http ) {
858
            $rss      = fetch_feed( $url );
859
            $maxitems = 0;
860
861 View Code Duplication
            if ( ! is_wp_error( $rss ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
862
                $maxitems  = $rss->get_item_quantity( 7 );
863
                $rss_items = $rss->get_items( 0, $maxitems );
864
            }
865
            ?>
866
            <ul>
867
                <?php if ( 0 == $maxitems ) : ?>
868
                    <li><?php _e( 'No items', 'autoptimize' ); ?></li>
869
                <?php else : ?>
870
                    <?php foreach ( $rss_items as $item ) : ?>
0 ignored issues
show
Bug introduced by
The variable $rss_items does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
871
                        <li>
872
                            <a href="<?php echo esc_url( $item->get_permalink() ); ?>"
873
                                <?php // translators: the variable contains a date. ?>
874
                                title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date( 'j F Y | g:i a' ) ); ?>">
875
                                <?php echo esc_html( $item->get_title() ); ?>
876
                            </a>
877
                        </li>
878
                    <?php endforeach; ?>
879
                <?php endif; ?>
880
            </ul>
881
        <?php
882
        }
883
    }
884
885
    static function ao_admin_tabs()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
886
    {
887
        // based on http://wordpress.stackexchange.com/a/58826 .
888
        $tabs        = apply_filters( 'autoptimize_filter_settingsscreen_tabs', array( 'autoptimize' => __( 'JS, CSS  &amp; HTML', 'autoptimize' ) ) );
889
        $tab_content = '';
890
        $tabs_count  = count( $tabs );
891
        if ( $tabs_count > 1 ) {
892
            if ( isset( $_GET['page'] ) ) {
893
                $current_id = $_GET['page'];
894
            } else {
895
                $current_id = 'autoptimize';
896
            }
897
            $tab_content .= '<h2 class="nav-tab-wrapper">';
898
            foreach ( $tabs as $tab_id => $tab_name ) {
899
                if ( $current_id == $tab_id ) {
900
                    $class = ' nav-tab-active';
901
                } else {
902
                    $class = '';
903
                }
904
                $tab_content .= '<a class="nav-tab' . $class . '" href="?page=' . $tab_id . '">' . $tab_name . '</a>';
905
            }
906
            $tab_content .= '</h2>';
907
        } else {
908
            $tab_content = '<hr/>';
909
        }
910
911
        return $tab_content;
912
    }
913
914
    /**
915
     * Returns true if in admin (and not in admin-ajax.php!)
916
     *
917
     * @return bool
918
     */
919
    public static function is_admin_and_not_ajax()
920
    {
921
        return ( is_admin() && ! self::doing_ajax() );
922
    }
923
924
    /**
925
     * Returns true if doing ajax.
926
     *
927
     * @return bool
928
     */
929
    protected static function doing_ajax()
930
    {
931
        if ( function_exists( 'wp_doing_ajax' ) ) {
932
            return wp_doing_ajax();
933
        }
934
        return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
935
    }
936
937
    /**
938
     * Returns true menu or tab is to be shown.
939
     *
940
     * @return bool
941
     */
942
    public static function should_show_menu_tabs() {
943
        if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
944
            return true;
945
        } else {
946
            return false;
947
        }
948
    }
949
}
950