Completed
Pull Request — master (#88)
by
unknown
03:01
created
classes/autoptimizeToolbar.php 3 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -75,18 +75,18 @@
 block discarded – undo
75 75
         $wp_admin_bar->add_node( array(
76 76
             'id'     => 'autoptimize-cache-info',
77 77
             'title'  => '<p>' . __( "Cache Info", 'autoptimize' ) . '</p>' .
78
-                   '<div class="autoptimize-radial-bar" percentage="' . $percentage . '">' .
79
-                   '<div class="circle">'.
80
-                   '<div class="mask full"><div class="fill bg-' . $color . '"></div></div>'.
81
-                   '<div class="mask half"><div class="fill bg-' . $color . '"></div></div>'.
82
-                   '<div class="shadow"></div>'.
83
-                   '</div>'.
84
-                   '<div class="inset"><div class="percentage"><div class="numbers ' . $color . '">' . $percentage . '%</div></div></div>'.
85
-                   '</div>' .
86
-                   '<table>' .
87
-                   '<tr><td>' . __( "Size", 'autoptimize' ) . ':</td><td class="size ' . $color . '">' . $size . '</td></tr>' .
88
-                   '<tr><td>' . __( "Files", 'autoptimize' ) . ':</td><td class="files white">' . $files . '</td></tr>' .
89
-                   '</table>',
78
+                    '<div class="autoptimize-radial-bar" percentage="' . $percentage . '">' .
79
+                    '<div class="circle">'.
80
+                    '<div class="mask full"><div class="fill bg-' . $color . '"></div></div>'.
81
+                    '<div class="mask half"><div class="fill bg-' . $color . '"></div></div>'.
82
+                    '<div class="shadow"></div>'.
83
+                    '</div>'.
84
+                    '<div class="inset"><div class="percentage"><div class="numbers ' . $color . '">' . $percentage . '%</div></div></div>'.
85
+                    '</div>' .
86
+                    '<table>' .
87
+                    '<tr><td>' . __( "Size", 'autoptimize' ) . ':</td><td class="size ' . $color . '">' . $size . '</td></tr>' .
88
+                    '<tr><td>' . __( "Files", 'autoptimize' ) . ':</td><td class="files white">' . $files . '</td></tr>' .
89
+                    '</table>',
90 90
             'parent' => 'autoptimize'
91 91
         ));
92 92
 
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -1,35 +1,35 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if (!defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 class autoptimizeToolbar
4 4
 {
5 5
     public function __construct()
6 6
     {
7 7
         // If Cache is not available we don't add the Autoptimize Toolbar
8
-        if( ! autoptimizeCache::cacheavail() ) {
8
+        if (!autoptimizeCache::cacheavail()) {
9 9
             return;
10 10
         }
11 11
         // Load admin toolbar feature once WordPress, all plugins, and the theme are fully loaded and instantiated.
12
-        add_action( 'wp_loaded', array( $this, 'load_toolbar' ) );
12
+        add_action('wp_loaded', array($this, 'load_toolbar'));
13 13
     }
14 14
 
15 15
     public function load_toolbar()
16 16
     {
17 17
         // Check permissions and that toolbar is not hidden via filter
18
-        if ( current_user_can( 'manage_options' ) && apply_filters( 'autoptimize_filter_toolbar_show', true ) ) {
18
+        if (current_user_can('manage_options') && apply_filters('autoptimize_filter_toolbar_show', true)) {
19 19
             // Create a handler for the AJAX toolbar requests
20
-            add_action( 'wp_ajax_autoptimize_delete_cache', array( $this, 'delete_cache' ) );
20
+            add_action('wp_ajax_autoptimize_delete_cache', array($this, 'delete_cache'));
21 21
 
22 22
             // Load custom styles, scripts and menu only when needed
23
-            if ( is_admin_bar_showing() ) {
24
-                if ( is_admin() ) {
23
+            if (is_admin_bar_showing()) {
24
+                if (is_admin()) {
25 25
                     // in the case of back-end
26
-                    add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
26
+                    add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
27 27
                 } else {
28 28
                     // in the case of front-end
29
-                    add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
29
+                    add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
30 30
                 }
31 31
                 // Add the Autoptimize Toolbar to the Admin bar
32
-                add_action( 'admin_bar_menu', array( $this, 'add_toolbar' ), 100 );
32
+                add_action('admin_bar_menu', array($this, 'add_toolbar'), 100);
33 33
             }
34 34
         }
35 35
     }
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
         $stats = autoptimizeCache::stats();
43 43
 
44 44
         // Set the Max Size recommended for cache files
45
-        $max_size = apply_filters( 'autoptimize_filter_cachecheck_maxsize', 512 * 1024 * 1024 );
45
+        $max_size = apply_filters('autoptimize_filter_cachecheck_maxsize', 512*1024*1024);
46 46
 
47 47
         // Retrieve the current Total Files in cache
48 48
         $files = $stats[0];
@@ -52,83 +52,83 @@  discard block
 block discarded – undo
52 52
         $size = $this->format_filesize($bytes);
53 53
 
54 54
         // We calculated the percentage of cache used
55
-        $percentage = ceil( $bytes / $max_size * 100 );
56
-        if ( $percentage > 100 ) {
55
+        $percentage = ceil($bytes/$max_size*100);
56
+        if ($percentage > 100) {
57 57
             $percentage = 100;
58 58
         }
59 59
         // We define the type of color indicator for the current state of cache size.
60 60
         // "green" if the size is less than 80% of the total recommended
61 61
         // "orange" if over 80%
62 62
         // "red" if over 100%
63
-        $color = ( $percentage == 100 ) ? 'red' : ( ( $percentage > 80 ) ? 'orange' : 'green' );
63
+        $color = ($percentage == 100) ? 'red' : (($percentage > 80) ? 'orange' : 'green');
64 64
 
65 65
         // Create or add new items into the Admin Toolbar.
66 66
         // Main Autoptimize node
67
-        $wp_admin_bar->add_node( array(
67
+        $wp_admin_bar->add_node(array(
68 68
             'id'    => 'autoptimize',
69
-            'title' => '<span class="ab-icon"></span><span class="ab-label">' . __( "Autoptimize", 'autoptimize' ) . '</span>',
70
-            'href'  => admin_url( 'options-general.php?page=autoptimize' ),
71
-            'meta'  => array( 'class' => 'bullet-' . $color )
69
+            'title' => '<span class="ab-icon"></span><span class="ab-label">'.__("Autoptimize", 'autoptimize').'</span>',
70
+            'href'  => admin_url('options-general.php?page=autoptimize'),
71
+            'meta'  => array('class' => 'bullet-'.$color)
72 72
         ));
73 73
 
74 74
         // Cache Info node
75
-        $wp_admin_bar->add_node( array(
75
+        $wp_admin_bar->add_node(array(
76 76
             'id'     => 'autoptimize-cache-info',
77
-            'title'  => '<p>' . __( "Cache Info", 'autoptimize' ) . '</p>' .
78
-                   '<div class="autoptimize-radial-bar" percentage="' . $percentage . '">' .
77
+            'title'  => '<p>'.__("Cache Info", 'autoptimize').'</p>'.
78
+                   '<div class="autoptimize-radial-bar" percentage="'.$percentage.'">'.
79 79
                    '<div class="circle">'.
80
-                   '<div class="mask full"><div class="fill bg-' . $color . '"></div></div>'.
81
-                   '<div class="mask half"><div class="fill bg-' . $color . '"></div></div>'.
80
+                   '<div class="mask full"><div class="fill bg-'.$color.'"></div></div>'.
81
+                   '<div class="mask half"><div class="fill bg-'.$color.'"></div></div>'.
82 82
                    '<div class="shadow"></div>'.
83 83
                    '</div>'.
84
-                   '<div class="inset"><div class="percentage"><div class="numbers ' . $color . '">' . $percentage . '%</div></div></div>'.
85
-                   '</div>' .
86
-                   '<table>' .
87
-                   '<tr><td>' . __( "Size", 'autoptimize' ) . ':</td><td class="size ' . $color . '">' . $size . '</td></tr>' .
88
-                   '<tr><td>' . __( "Files", 'autoptimize' ) . ':</td><td class="files white">' . $files . '</td></tr>' .
84
+                   '<div class="inset"><div class="percentage"><div class="numbers '.$color.'">'.$percentage.'%</div></div></div>'.
85
+                   '</div>'.
86
+                   '<table>'.
87
+                   '<tr><td>'.__("Size", 'autoptimize').':</td><td class="size '.$color.'">'.$size.'</td></tr>'.
88
+                   '<tr><td>'.__("Files", 'autoptimize').':</td><td class="files white">'.$files.'</td></tr>'.
89 89
                    '</table>',
90 90
             'parent' => 'autoptimize'
91 91
         ));
92 92
 
93 93
         // Delete Cache node
94
-        $wp_admin_bar->add_node( array(
94
+        $wp_admin_bar->add_node(array(
95 95
             'id'     => 'autoptimize-delete-cache',
96
-            'title'  => __( "Delete Cache", 'autoptimize' ),
96
+            'title'  => __("Delete Cache", 'autoptimize'),
97 97
             'parent' => 'autoptimize'
98 98
         ));
99 99
     }
100 100
 
101 101
     public function delete_cache()
102 102
     {
103
-        check_ajax_referer( 'ao_delcache_nonce', 'nonce' );
103
+        check_ajax_referer('ao_delcache_nonce', 'nonce');
104 104
         $result = false;
105
-        if ( current_user_can( 'manage_options' ) )
105
+        if (current_user_can('manage_options'))
106 106
         {
107 107
             // We call the function for cleaning the Autoptimize cache
108 108
             $result = autoptimizeCache::clearall();
109 109
         }
110
-        wp_send_json( $result );
110
+        wp_send_json($result);
111 111
     }
112 112
 
113 113
     public function enqueue_scripts()
114 114
     {
115 115
         // Autoptimize Toolbar Styles
116
-        wp_enqueue_style( 'autoptimize-toolbar', plugins_url( '/static/toolbar.css', __FILE__ ), array(), time(), 'all' );
116
+        wp_enqueue_style('autoptimize-toolbar', plugins_url('/static/toolbar.css', __FILE__), array(), time(), 'all');
117 117
         // Autoptimize Toolbar Javascript
118
-        wp_enqueue_script( 'autoptimize-toolbar', plugins_url( '/static/toolbar.js', __FILE__ ), array( 'jquery' ), time(), true );
118
+        wp_enqueue_script('autoptimize-toolbar', plugins_url('/static/toolbar.js', __FILE__), array('jquery'), time(), true);
119 119
         // Localizes a registered script with data for a JavaScript variable. (We need this for the AJAX work properly in the front-end mode)
120
-        wp_localize_script( 'autoptimize-toolbar', 'autoptimize_ajax_object', array(
121
-            'ajaxurl' => admin_url( 'admin-ajax.php' ),
122
-            'error_msg' => sprintf( __( 'Your Autoptimize cache might not have been purged successfully, please check on the <a href=%s>Autoptimize settings page</a>.', 'autoptimize' ), admin_url( 'options-general.php?page=autoptimize' ) . ' style="white-space:nowrap;"' ),
123
-            'dismiss_msg' => __( 'Dismiss this notice.' ),
124
-            'nonce' => wp_create_nonce( 'ao_delcache_nonce' )
125
-        ) );
120
+        wp_localize_script('autoptimize-toolbar', 'autoptimize_ajax_object', array(
121
+            'ajaxurl' => admin_url('admin-ajax.php'),
122
+            'error_msg' => sprintf(__('Your Autoptimize cache might not have been purged successfully, please check on the <a href=%s>Autoptimize settings page</a>.', 'autoptimize'), admin_url('options-general.php?page=autoptimize').' style="white-space:nowrap;"'),
123
+            'dismiss_msg' => __('Dismiss this notice.'),
124
+            'nonce' => wp_create_nonce('ao_delcache_nonce')
125
+        ));
126 126
     }
127 127
 
128 128
     public function format_filesize($bytes, $decimals = 2)
129 129
     {
130
-        $units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' );
131
-        for ($i = 0; ($bytes / 1024) > 0.9; $i++, $bytes /= 1024) {}
132
-        return sprintf( "%1.{$decimals}f %s", round( $bytes, $decimals ), $units[$i] );
130
+        $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
131
+        for ($i = 0; ($bytes/1024) > 0.9; $i++, $bytes /= 1024) {}
132
+        return sprintf("%1.{$decimals}f %s", round($bytes, $decimals), $units[$i]);
133 133
     }
134 134
 }
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+    exit;
4
+}
5
+// Exit if accessed directly
3 6
 class autoptimizeToolbar
4 7
 {
5 8
     public function __construct()
Please login to merge, or discard this patch.