Skip to content

Commit 6bba2fa

Browse files
authored
Merge pull request #10 from justcoded/develop
Check requirements on settings page
2 parents 2f1f5c3 + 6f66c2d commit 6bba2fa

File tree

6 files changed

+57
-22
lines changed

6 files changed

+57
-22
lines changed

assets/css/styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
color: red;
77
}
88

9+
.notice-nag {
10+
border-left: 4px solid red;
11+
}
12+
913
.loader {
1014
border: 10px solid #f3f3f3;
1115
border-radius: 50%;

components/Optimizer.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace JustCoded\WP\ImageOptimizer\components;
44

5-
use JustCoded\WP\ImageOptimizer\models\Settings;
65
use JustCoded\WP\ImageOptimizer\models\Media;
76
use JustCoded\WP\ImageOptimizer\models\Log;
87

@@ -26,7 +25,10 @@ public function __construct() {
2625
* Run cron job by Settings param
2726
*/
2827
protected function setup_cron() {
29-
if ( \JustImageOptimizer::$settings->auto_optimize ) {
28+
if ( \JustImageOptimizer::$settings->saved()
29+
&& \JustImageOptimizer::$settings->auto_optimize
30+
&& \JustImageOptimizer::$settings->check_requirements()
31+
) {
3032
add_action( 'init', array( $this, 'check_cron_scheduled' ) );
3133
add_filter( 'cron_schedules', array( $this, 'init_cron_schedule' ) );
3234
add_action( 'just_image_optimizer_autorun', array( $this, 'auto_optimize' ) );
@@ -113,7 +115,7 @@ public function auto_optimize() {
113115
unset( $attach_ids[ $key ] );
114116
}
115117
}
116-
} while ( ! empty( $attach_ids ) && \JustImageOptimizer::$settings->tries_count > $tries++ );
118+
} while ( ! empty( $attach_ids ) && \JustImageOptimizer::$settings->tries_count > $tries ++ );
117119
}
118120

119121
/**
@@ -136,7 +138,7 @@ public function manual_optimize() {
136138
do {
137139
$this->optimize_images( [ $attach_id ] );
138140
$optimize_status = $model->check_optimization_status( $attach_id );
139-
} while ( Media::STATUS_PROCESSED !== $optimize_status && \JustImageOptimizer::$settings->tries_count > $tries++ );
141+
} while ( Media::STATUS_PROCESSED !== $optimize_status && \JustImageOptimizer::$settings->tries_count > $tries ++ );
140142

141143
$attach_stats = $model->get_total_attachment_stats( $attach_id );
142144
$data_statistics = array(
@@ -195,6 +197,7 @@ protected function optimize_images( array $attach_ids ) {
195197
update_post_meta( $attach_id, '_just_img_opt_status', $optimize_status );
196198
}
197199
$wp_filesystem->rmdir( $dir, true );
200+
198201
return false;
199202
}
200203

@@ -227,6 +230,7 @@ protected function optimize_images( array $attach_ids ) {
227230
}
228231

229232
$wp_filesystem->rmdir( $dir, true );
233+
230234
return true;
231235
}
232236
}

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
7+
Version: 1.1.1
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.100';
81+
self::$version = '1.101';
8282
self::$opt_version = get_option( self::OPT_VERSION );
8383
self::$settings = new models\Settings();
8484
self::$service = services\ImageOptimizerFactory::create();

models/Settings.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,13 @@ public function saved() {
153153
return get_option( self::DB_OPT_KEEP_ORIGIN ) === '1';
154154
}
155155

156+
/**
157+
* Check requirements for accesses wp-content.
158+
*
159+
* @return bool true or false.
160+
*/
161+
public function check_requirements() {
162+
return wp_is_writable( WP_CONTENT_DIR );
163+
}
164+
156165
}

readme.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
=== Just Image Optimizer ===
22
Contributors: aprokopenko
33
Plugin Name: Just Image Optimizer
4-
Version: 1.1
4+
Version: 1.1.1
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
9-
Requires at least: 4.4
9+
Requires at least: 4.5
1010
Tested up to: 4.9.4
1111
Requires PHP: >=5.6
1212
License: GPLv2 or later
@@ -65,6 +65,10 @@ No special actions are required during the upgrade.
6565

6666
== Changelog ==
6767

68+
= 1.1.1 =
69+
* New: Added notice if wp-content is not writable, cause it's required for storing files.
70+
* Bug fix: Fake cron run without plugin settings saved.
71+
6872
= 1.1 =
6973
* Added compatibility with Just Responsive Images plugin (v1.5+)
7074
* Added compatibility with Regenerate Thumbnails plugin (v3+)

views/dashboard/settings.php

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
<div class="wrap">
22
<?php include( JUSTIMAGEOPTIMIZER_ROOT . '/views/_tabs.php' ); ?>
3-
<?php if ( ! $model->saved() ) : ?>
3+
<?php if ( ! $model->check_requirements() ) : ?>
4+
<div class="update-nag notice-nag">
5+
<strong>
6+
<?php echo sprintf( __( 'Make %1$s writable using the chmod command through your ftp or server software.
7+
(<em>chmod 775 %1$s</em>) and refresh this page for continued settings plugin.',
8+
\JustImageOptimizer::TEXTDOMAIN ), WP_CONTENT_DIR ); ?>
9+
</strong>
10+
</div>
11+
<?php endif; ?>
12+
<?php if ( !$model->saved() && $model->check_requirements() ) : ?>
413
<div class="update-nag">
514
<strong>Please confirm the settings below and Save them.</strong>
615
</div><br>
@@ -15,21 +24,25 @@
1524
<form method="post" action="<?php get_permalink(); ?>" enctype="multipart/form-data">
1625
<table class="form-table">
1726
<tr>
18-
<th scope="row"><?php _e( 'Automatically optimize uploads', \JustImageOptimizer::TEXTDOMAIN ); ?></th>
27+
<th scope="row">
28+
<?php _e( 'Automatically optimize uploads', \JustImageOptimizer::TEXTDOMAIN ); ?>
29+
</th>
1930
<td>
2031
<input type="hidden" name="auto_optimize" value="0">
21-
<input <?php checked($model->auto_optimize); ?>
22-
type="checkbox"
23-
name="auto_optimize"
24-
value="1">
32+
<input <?php checked( $model->auto_optimize ); ?>
33+
type="checkbox"
34+
name="auto_optimize"
35+
value="1">
2536
</td>
2637
</tr>
2738
<tr class="image_sizes_set">
28-
<th scope="row"><?php _e( 'Image sizes to optimize', \JustImageOptimizer::TEXTDOMAIN ); ?></th>
39+
<th scope="row">
40+
<?php _e( 'Image sizes to optimize', \JustImageOptimizer::TEXTDOMAIN ); ?>
41+
</th>
2942
<td class="additional_sizes">
3043
<input type="hidden" name="image_sizes_all" value="0">
3144
<label for="check_all_size">
32-
<input <?php checked($model->image_sizes_all); ?>
45+
<input <?php checked( $model->image_sizes_all ); ?>
3346
id="check_all_size" type="checkbox" name="image_sizes_all"
3447
value="1">All
3548
</label>
@@ -58,7 +71,7 @@
5871
<th scope="row"><?php _e( 'Bulk media limit', \JustImageOptimizer::TEXTDOMAIN ); ?></th>
5972
<td>
6073
<input type="text" name="image_limit"
61-
value="<?php echo $model->image_limit; ?>">
74+
value="<?php echo $model->image_limit; ?>">
6275
<p class="description">How many Media can be optimized at a time</p>
6376
</td>
6477
</tr>
@@ -78,7 +91,7 @@
7891
</td>
7992
</tr>
8093
<?php /*
81-
// TODO: add support in future releases.
94+
// TODO: add support in future releases.
8295
<tr>
8396
<th scope="row"><?php _e( 'Regenerate image thumbnails before optimize', \JustImageOptimizer::TEXTDOMAIN ); ?></th>
8497
<td>
@@ -90,18 +103,19 @@
90103
<p class="description">Can affect server performance if you upload images very often</p>
91104
</td>
92105
</tr>
93-
*/ ?>
106+
*/ ?>
94107
</table>
95-
<input
96-
type="submit" name="submit-settings" class="button button-primary" value="Save">
108+
<input <?php echo( $model->check_requirements() ? '' : 'disabled' ); ?>
109+
type="submit" name="submit-settings" class="button button-primary" value="Save">
97110
</form>
98111
</div>
99112
<style>
100113
.size_checked {
101114
padding-top: 10px;
102115
}
116+
103117
.label-checkbox {
104-
width:200px;
118+
width: 200px;
105119
display: inline-block;
106120
}
107121
</style>

0 commit comments

Comments
 (0)