Skip to content

Commit a715352

Browse files
Merge branch 'dashboard_widget'
2 parents b3f6e06 + 44efb28 commit a715352

17 files changed

Lines changed: 571 additions & 83 deletions

readme.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ A: Yes! After installing the plugin, go to *Media > Bulk Optimization*, and clic
110110

111111
== Changelog ==
112112

113+
= 2.2.0 =
114+
* New dashboard widget that shows your media library savings.
115+
113116
= 2.1.0 =
114117
* Compression of retina images generated by WP Retina 2x.
115118
* Solved a bug which caused the API key to be cleared on the settings page.

src/class-tiny-plugin.php

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
* with this program; if not, write to the Free Software Foundation, Inc., 51
1818
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1919
*/
20-
2120
class Tiny_Plugin extends Tiny_WP_Base {
22-
const VERSION = '2.1.0';
21+
const VERSION = '2.2.0';
2322
const MEDIA_COLUMN = self::NAME;
2423
const DATETIME_FORMAT = 'Y-m-d G:i:s';
2524

@@ -34,7 +33,7 @@ public static function jpeg_quality() {
3433

3534
public static function version() {
3635
/* Avoid using get_plugin_data() because it is not loaded early enough
37-
in xmlrpc.php. */
36+
in xmlrpc.php. */
3837
return self::VERSION;
3938
}
4039

@@ -68,6 +67,10 @@ public function init() {
6867
}
6968

7069
public function admin_init() {
70+
add_action('wp_dashboard_setup',
71+
$this->get_method( 'add_dashboard_widget' )
72+
);
73+
7174
add_action( 'admin_enqueue_scripts',
7275
$this->get_method( 'enqueue_scripts' )
7376
);
@@ -169,6 +172,11 @@ public function enqueue_scripts( $hook ) {
169172
array(), self::version()
170173
);
171174

175+
wp_enqueue_style( self::NAME . '_chart',
176+
plugins_url( '/css/chart.css', __FILE__ ),
177+
array(), self::version()
178+
);
179+
172180
wp_register_script( self::NAME . '_admin',
173181
plugins_url( '/js/admin.js', __FILE__ ),
174182
array(), self::version(), true
@@ -208,6 +216,11 @@ public function enqueue_scripts( $hook ) {
208216
array(), self::version()
209217
);
210218

219+
wp_enqueue_style( self::NAME .'_chart',
220+
plugins_url( '/css/chart.css', __FILE__ ),
221+
array(), self::version()
222+
);
223+
211224
wp_register_script(
212225
self::NAME . '_tiny_bulk_optimization',
213226
plugins_url( '/js/bulk-optimization.js', __FILE__ ),
@@ -431,6 +444,34 @@ public function render_bulk_optimization_page() {
431444
include( dirname( __FILE__ ) . '/views/bulk-optimization.php' );
432445
}
433446

447+
public function add_dashboard_widget() {
448+
wp_enqueue_style( self::NAME .'_chart',
449+
plugins_url( '/css/chart.css', __FILE__ ),
450+
array(), self::version()
451+
);
452+
453+
wp_enqueue_style( self::NAME .'_dashboard_widget',
454+
plugins_url( '/css/dashboard-widget.css', __FILE__ ),
455+
array(), self::version()
456+
);
457+
wp_register_script( self::NAME .'_dashboard_widget',
458+
plugins_url( '/js/dashboard-widget.js', __FILE__ ),
459+
array(), self::version(), true
460+
);
461+
462+
wp_enqueue_script( self::NAME .'_dashboard_widget' );
463+
464+
wp_add_dashboard_widget(
465+
$this->get_prefixed_name( 'dashboard_widget' ),
466+
esc_html__( 'Compress JPEG & PNG images', 'tiny-compress-images' ),
467+
$this->get_method( 'add_widget_view' )
468+
);
469+
}
470+
471+
function add_widget_view() {
472+
include( dirname( __FILE__ ) . '/views/dashboard-widget.php' );
473+
}
474+
434475
private static function retrieve_admin_colors() {
435476
global $_wp_admin_css_colors;
436477
$admin_colour_scheme = get_user_option( 'admin_color', get_current_user_id() );
@@ -475,8 +516,8 @@ private function get_ids_to_compress() {
475516
global $wpdb;
476517
return $wpdb->get_results(
477518
"SELECT ID, post_title FROM $wpdb->posts
478-
WHERE post_type = 'attachment' $condition
479-
AND (post_mime_type = 'image/jpeg' OR post_mime_type = 'image/png')
480-
ORDER BY ID DESC", ARRAY_A);
519+
WHERE post_type = 'attachment' $condition
520+
AND (post_mime_type = 'image/jpeg' OR post_mime_type = 'image/png')
521+
ORDER BY ID DESC", ARRAY_A);
481522
}
482523
}

src/css/bulk-optimization.css

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -139,52 +139,11 @@ div.tiny-bulk-optimization div.savings div.legend {
139139
margin-left: 50%;
140140
}
141141

142-
div.tiny-bulk-optimization div.savings div.chart {
143-
float: left;
144-
position: relative;
145-
width: 50%;
146-
text-align: center;
147-
}
148-
149-
div.tiny-bulk-optimization div.savings div.chart svg circle.main {
150-
fill: #ebebeb;
151-
animation: shwoosh 2s ease;
152-
transition: stroke-dasharray 1s ease;
153-
}
154-
155-
div.tiny-bulk-optimization div.savings div.chart svg circle.inner {
156-
fill: #fff;
157-
}
158-
159-
div.tiny-bulk-optimization div.savings div.chart div.value {
160-
position: absolute;
161-
top: 0;
162-
left: 0;
163-
width: 100%;
164-
color: #7acb44;
165-
text-align: center;
166-
}
167142

168-
div.tiny-bulk-optimization div.savings div.chart div.value div.percentage {
169-
width: 50%;
170-
margin-left: auto;
171-
margin-right: auto;
172-
margin-top: 65px;
173-
font-size: 2.4em;
174-
line-height: 1em;
175-
}
176-
177-
div.tiny-bulk-optimization div.savings div.chart div.value div.label {
178-
width: 50%;
179-
margin-left: auto;
180-
margin-right: auto;
181-
font-size: 1.4em;
182-
line-height: 1.2em;
183-
}
184143

185144
div.tiny-bulk-optimization div.savings div.legend {
186145
/* margin-left defined inline */
187-
padding: 30px 0;
146+
padding: 22px 0;
188147
}
189148

190149
div.tiny-bulk-optimization div.savings table {
@@ -207,13 +166,6 @@ div.tiny-bulk-optimization div.savings table td.description {
207166
color: #bbb;
208167
}
209168

210-
@media only screen and (max-width: 400px) {
211-
div.tiny-bulk-optimization div.savings div.chart {
212-
float: none;
213-
width: 100%;
214-
}
215-
}
216-
217169
@media only screen and (max-width: 400px) {
218170
div.tiny-bulk-optimization div.savings div.legend {
219171
margin-left: 0 !important;

src/css/chart.css

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#optimization-chart {
2+
float: left;
3+
position: relative;
4+
width: 50%;
5+
text-align: center;
6+
}
7+
8+
.ie8 #optimization-chart {
9+
margin: 0;
10+
}
11+
12+
#optimization-chart svg circle.main {
13+
fill: #ebebeb;
14+
animation: shwoosh 2s ease;
15+
transition: stroke-dasharray 1s ease;
16+
}
17+
18+
#optimization-chart svg circle.inner {
19+
fill: #fff;
20+
}
21+
22+
#optimization-chart div.value {
23+
position: absolute;
24+
top: 0;
25+
left: 0;
26+
width: 100%;
27+
color: #7acb44;
28+
text-align: center;
29+
}
30+
31+
#optimization-chart div.value div.percentage {
32+
width: 50%;
33+
margin-left: auto;
34+
margin-right: auto;
35+
margin-top: 56px;
36+
font-size: 2.1em;
37+
line-height: 1em;
38+
}
39+
40+
#optimization-chart div.value div.label {
41+
width: 50%;
42+
margin-left: auto;
43+
margin-right: auto;
44+
font-size: 1.4em;
45+
line-height: 1.2em;
46+
}
47+
48+
@media only screen and (max-width: 400px) {
49+
#optimization-chart {
50+
float: none;
51+
width: 100%;
52+
}
53+
}

0 commit comments

Comments
 (0)