Skip to content

Commit de2440e

Browse files
authored
Merge pull request #11 from justcoded/develop
Update method get_images_disk_usage
2 parents 6bba2fa + e7fc6d5 commit de2440e

File tree

11 files changed

+124
-28
lines changed

11 files changed

+124
-28
lines changed

assets/css/styles.css

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66
color: red;
77
}
88

9-
.notice-nag {
10-
border-left: 4px solid red;
9+
.jio-admin-page .update-nag {
10+
display: block;
11+
}
12+
.jio-admin-page .update-nag.error-nag {
13+
border-left: 4px solid red !important;
14+
}
15+
.jio-admin-page .update-nag.success-nag {
16+
border-left: 4px solid green !important;
1117
}
1218

1319
.loader {

just-image-optimizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Plugin Name: Just Image Optimizer
55
Description: Compress image files, improve performance and boost your SEO rank using Google Page Speed Insights compression and optimization.
66
Tags: image, resize, optimize, optimise, compress, performance, optimisation, optimise JPG, pictures, optimizer, Google Page Speed
7-
Version: 1.1.1
7+
Version: 1.1.2
88
Author: JustCoded
99
License: GPLv2 or later
1010
*/
@@ -78,7 +78,7 @@ protected function __construct() {
7878
$loader = new core\PluginLoader();
7979
// init plugin name and version.
8080
self::$plugin_name = __( 'Just Image Optimizer', self::TEXTDOMAIN );
81-
self::$version = '1.101';
81+
self::$version = '1.102';
8282
self::$opt_version = get_option( self::OPT_VERSION );
8383
self::$settings = new models\Settings();
8484
self::$service = services\ImageOptimizerFactory::create();

models/Media.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,11 +387,11 @@ public function get_images_stat( $all = false ) {
387387
*/
388388
public function get_images_disk_usage() {
389389
$disk_usage = 0;
390-
$args = $args = $this->query_args;
391-
$query = new \WP_Query( $args );
392-
while ( $query->have_posts() ) {
393-
$query->the_post();
394-
$disk_usage = $disk_usage + $this->get_file_sizes( get_the_ID(), 'total' );
390+
// Init ms-functions for get_dirsize.
391+
require_once ABSPATH . WPINC .'/ms-functions.php';
392+
$get_path = self::get_uploads_path();
393+
foreach( $get_path as $path ) {
394+
$disk_usage = $disk_usage + get_dirsize( $path );
395395
}
396396

397397
return $disk_usage;

models/Settings.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,15 @@ public function saved() {
156156
/**
157157
* Check requirements for accesses wp-content.
158158
*
159+
* @param bool $force_check Ignore caches within requriements check.
160+
*
159161
* @return bool true or false.
160162
*/
161-
public function check_requirements() {
162-
return wp_is_writable( WP_CONTENT_DIR );
163+
public function check_requirements( $force_check = false ) {
164+
$php_vers = version_compare( phpversion(), '7.0', '>' );
165+
$wp_content = wp_is_writable( WP_CONTENT_DIR );
166+
$service = \JustImageOptimizer::$service && \JustImageOptimizer::$service->check_availability( $force_check );
167+
return $php_vers && $wp_content && $service;
163168
}
164169

165170
}

readme.txt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
=== Just Image Optimizer ===
22
Contributors: aprokopenko
33
Plugin Name: Just Image Optimizer
4-
Version: 1.1.1
4+
Version: 1.1.2
55
Description: Compress image files, improve performance and boost your SEO rank using Google Page Speed Insights compression and optimization.
66
Tags: image, resize, optimize, optimise, compress, performance, optimisation, optimise JPG, pictures, optimizer, Google Page Speed
77
Author: JustCoded
88
Author URI: https://justcoded.com
99
Requires at least: 4.5
10-
Tested up to: 4.9.4
10+
Tested up to: 4.9.5
1111
Requires PHP: >=5.6
1212
License: GPLv2 or later
1313
License URI: https://www.gnu.org/licenses/gpl-2.0.html
@@ -23,6 +23,11 @@ The plugin uses Google Page Speed Insights API to optimize images. All you need
2323

2424
Image Optimization runs in the background on Google servers, so the site will keep its performance intact. There are no special server requirements.
2525

26+
= Requirements =
27+
28+
* Site should be available for Google Page Speed test
29+
* PHP 7
30+
2631
= Issues tracker =
2732

2833
If you have any feedback or ideas, please raise an issue in our GitHub repository:
@@ -46,6 +51,13 @@ In the upcoming releases, we plan to add compatibility with WordPress MultiSite
4651

4752
== Frequently Asked Questions ==
4853

54+
= My image optimization is always "0.00% saved" =
55+
56+
* Please open plugin Settings page. It will check for plugin requirements on your server.
57+
* If you don't have any errors on Settings page, then please check logs. You should see that plugin try to optimize at least 1 attachment.
58+
* Next step is to check that Optimize request URL is accessible by Google Page Speed (just copy it and try to test it with the service).
59+
* If nothing help, please write to us on Github with screenshots of your Settings page, Log page and last Log details page.
60+
4961
= Can I revert original images quality? =
5062

5163
To revert original quality of the images, you can use [Regenerate Thumbnails](https://wordpress.org/plugins/regenerate-thumbnails/) plugin.
@@ -65,6 +77,11 @@ No special actions are required during the upgrade.
6577

6678
== Changelog ==
6779

80+
= 1.1.2 =
81+
* New: Added notice if site is not available online.
82+
* New: Added notice if PHP version is below 7.0.
83+
* Bug fix: Dashboard image size statistics fatal error.
84+
6885
= 1.1.1 =
6986
* New: Added notice if wp-content is not writable, cause it's required for storing files.
7087
* Bug fix: Fake cron run without plugin settings saved.

services/GooglePagespeed.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ public function __construct() {
3535
add_action( 'init', array( $this, 'add_rewrite_rules' ), 0 );
3636
}
3737

38+
/**
39+
* User friendly service name.
40+
*
41+
* @return string
42+
*/
43+
public function name() {
44+
return 'Google Page Speed';
45+
}
46+
3847
/**
3948
* Check Service credentials to be valid
4049
*
@@ -48,6 +57,30 @@ public function check_api_key() {
4857
return ( 200 === $code );
4958
}
5059

60+
61+
/**
62+
* Check Service availability (that it has correct mode or site access)
63+
*
64+
* @param bool $force_check Ignore caches within requriements check.
65+
*
66+
* @return bool
67+
*/
68+
public function check_availability( $force_check = false ) {
69+
// generate unique transient key based on domain, this will minimize requests on same domain.
70+
$transient_key = 'jio_service_availability.google_page_speed.' . home_url();
71+
72+
$status = get_transient( $transient_key );
73+
if ( false === $status || $force_check ) {
74+
$url_req = self::API_URL . 'url=' . home_url() . '&key=' . $this->api_key . '';
75+
$response = wp_remote_get( $url_req, array( 'timeout' => 60 ) );
76+
$code = wp_remote_retrieve_response_code( $response );
77+
78+
$status = (int) ( 200 === $code );
79+
set_transient( $transient_key, $status, 3600 * 60 * 24 );
80+
}
81+
return $status;
82+
}
83+
5184
/**
5285
* Optimize images and save to destination directory
5386
*

services/ImageOptimizerInterface.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,29 @@
55

66
interface ImageOptimizerInterface {
77

8+
/**
9+
* User friendly service name.
10+
*
11+
* @return string
12+
*/
13+
public function name();
14+
815
/**
916
* Check Service credentials to be valid
1017
*
1118
* @return bool
1219
*/
1320
public function check_api_key();
1421

22+
/**
23+
* Check Service availability (that it has correct mode or site access)
24+
*
25+
* @param bool $force_check Ignore caches within requriements check.
26+
*
27+
* @return bool
28+
*/
29+
public function check_availability( $force_check = false );
30+
1531
/**
1632
* Optimize images and save to destination directory
1733
*

views/dashboard/_requirements.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
if ( ! isset( $force_requirements_check ) ) {
3+
$force_requirements_check = false;
4+
}
5+
?>
6+
<?php if ( ! \JustImageOptimizer::$settings->check_requirements( $force_requirements_check ) ) : ?>
7+
<div class="update-nag error-nag">
8+
<strong>Please check that all requirements are met:</strong>
9+
<ul>
10+
<li>PHP version should be at least 7.0 (you have <?php echo esc_html( phpversion() ); ?>).</li>
11+
<li>
12+
<?php
13+
echo esc_html(
14+
sprintf(
15+
__( 'Make sure directory "%1$s" is writable.',
16+
\JustImageOptimizer::TEXTDOMAIN ), WP_CONTENT_DIR
17+
)
18+
);
19+
?>
20+
</li>
21+
<li>Your site is online and can be accessible by <?php echo esc_html( \JustImageOptimizer::$service->name() ); ?></li>
22+
</ul>
23+
</div>
24+
<?php endif; ?>

views/dashboard/connect.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<div class="wrap">
1+
<div class="wrap jio-admin-page">
22
<?php include( JUSTIMAGEOPTIMIZER_ROOT . '/views/_tabs.php' ); ?>
33
<?php if ( $saved ) : ?>
4-
<div class="update-nag" style="border-left-color: green !important">
4+
<div class="update-nag success-nag">
55
<strong>Connection options updated!</strong>
66
</div>
77
<?php endif; ?>
88
<?php if ( $saved === false ) : ?>
9-
<div class="update-nag" style="border-left-color: red !important">
9+
<div class="update-nag error-nag">
1010
<strong>API key is invalid!</strong>
1111
</div>
1212
<?php endif; ?>

views/dashboard/index.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
$chart_saving = $model->size_format_explode( $dash_saving_size );
77
$chart_disk_space = $model->size_format_explode( $model->get_disk_space_size() );
88
?>
9-
<div class="wrap">
9+
<div class="wrap jio-admin-page">
1010
<?php include( JUSTIMAGEOPTIMIZER_ROOT . '/views/_tabs.php' ); ?>
11+
<?php include( JUSTIMAGEOPTIMIZER_ROOT . '/views/dashboard/_requirements.php' ); ?>
12+
1113
<?php if ( empty( \JustImageOptimizer::$settings->auto_optimize ) ) : ?>
1214
<div class="update-nag">
1315
<strong>Automatic image optimization is disabled. Please check

0 commit comments

Comments
 (0)