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-
2120class 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}
0 commit comments