Manual Image Crop - Version 1.07

Version Description

  • Fixed 'Cannot use string offset as an array' error
Download this release

Release Info

Developer tomasz.sita
Plugin Icon 128x128 Manual Image Crop
Version 1.07
Comparing to
See all releases

Code changes from version 1.06 to 1.07

lib/ManualImageCrop.php CHANGED
@@ -153,11 +153,11 @@ setInterval(function() {
153
 
154
 
155
  $src_file = str_replace($uploadsDir['baseurl'], $uploadsDir['basedir'], $src_file_url[0]);
156
- $dst_file_url = wp_get_attachment_image_src($_POST['attachmentId'], $_POST['editedSize']);
157
-
158
- if (!$dst_file_url) {
159
- exit;
160
- }
161
  $dst_file = str_replace($uploadsDir['baseurl'], $uploadsDir['basedir'], $dst_file_url[0]);
162
 
163
 
153
 
154
 
155
  $src_file = str_replace($uploadsDir['baseurl'], $uploadsDir['basedir'], $src_file_url[0]);
156
+ $dst_file_url = wp_get_attachment_image_src($_POST['attachmentId'], $_POST['editedSize']);
157
+
158
+ if (!$dst_file_url) {
159
+ exit;
160
+ }
161
  $dst_file = str_replace($uploadsDir['baseurl'], $uploadsDir['basedir'], $dst_file_url[0]);
162
 
163
 
lib/ManualImageCropEditorWindow.php CHANGED
@@ -24,8 +24,7 @@ class ManualImageCropEditorWindow {
24
  }
25
 
26
  public function renderWindow() {
27
- $sizes_settings = get_option( 'mic_options' );
28
- $sizesSettings = unserialize( $sizes_settings['sizes_settings'] );
29
  ?>
30
  <div class="mic-editor-wrapper">
31
  <h4><?php _e('Pick the image size:','microp'); ?></h4>
24
  }
25
 
26
  public function renderWindow() {
27
+ $sizesSettings = MicSettingsPage::getSettings();
 
28
  ?>
29
  <div class="mic-editor-wrapper">
30
  <h4><?php _e('Pick the image size:','microp'); ?></h4>
lib/ManualImageCropSettingsPage.php CHANGED
@@ -1,172 +1,190 @@
1
- <?php
2
- class MicSettingsPage
3
- {
4
- /**
5
- * Holds the values to be used in the fields callbacks
6
- */
7
- private $options;
8
-
9
- /**
10
- * Start up
11
- */
12
- public function __construct()
13
- {
14
- add_action( 'admin_menu', array( $this, 'add_plugin_page' ) );
15
- add_action( 'admin_init', array( $this, 'page_init' ) );
16
- }
17
-
18
- /**
19
- * Add options page
20
- */
21
- public function add_plugin_page()
22
- {
23
- // This page will be under "Settings"
24
- add_options_page(
25
- 'Settings Admin',
26
- 'Manual Image Crop',
27
- 'manage_options',
28
- 'Mic-setting-admin',
29
- array( $this, 'create_admin_page' )
30
- );
31
- }
32
-
33
- /**
34
- * Options page callback
35
- */
36
- public function create_admin_page()
37
- {
38
- // Set class property
39
- $this->options = get_option( 'mic_options' );
40
- ?>
41
- <div class="wrap">
42
- <?php screen_icon(); ?>
43
- <h2>Manual Image Crop Settings</h2>
44
- <form method="post" action="options.php" class="mic-settings-page">
45
- <?php
46
- // This prints out all hidden setting fields
47
- settings_fields( 'mic_options_group' );
48
- do_settings_sections( 'Mic-setting-admin' );
49
- submit_button();
50
- ?>
51
- </form>
52
- </div>
53
- <?php
54
- }
55
-
56
- /**
57
- * Register and add settings
58
- */
59
- public function page_init()
60
- {
61
- register_setting(
62
- 'mic_options_group', // Option group
63
- 'mic_options', // Option name
64
- array( $this, 'sanitize' ) // Sanitize
65
- );
66
-
67
- add_settings_section(
68
- 'setting_section_id', // ID
69
- 'Mic Custom Settings', // Title
70
- array( $this, 'print_section_info' ), // Callback
71
- 'Mic-setting-admin' // Page
72
- );
73
-
74
- add_settings_field(
75
- 'sizes_settings', // ID
76
- 'Crop sizes settings', // Title
77
- array( $this, 'sizes_settings_callback' ), // Callback
78
- 'Mic-setting-admin', // Page
79
- 'setting_section_id' // Section
80
- );
81
- }
82
-
83
- /**
84
- * Sanitize each setting field as needed
85
- *
86
- * @param array $input Contains all settings fields as array keys
87
- */
88
- public function sanitize( $input )
89
- {
90
- $new_input = array();
91
- if( isset( $input['sizes_settings'] ) )
92
- $new_input['sizes_settings'] = serialize( $input['sizes_settings'] );
93
-
94
- return $new_input;
95
- }
96
-
97
- /**
98
- * Print the Section text
99
- */
100
- public function print_section_info()
101
- {
102
- print 'Enter your settings below:';
103
- }
104
-
105
- /**
106
- * Get the settings option array and print one of its values
107
- */
108
- public function sizes_settings_callback()
109
- {
110
- global $_wp_additional_image_sizes;
111
-
112
- $imageSizes = get_intermediate_image_sizes();
113
-
114
- $sizeLabels = apply_filters( 'image_size_names_choose', array(
115
- 'thumbnail' => __('Thumbnail'),
116
- 'medium' => __('Medium'),
117
- 'large' => __('Large'),
118
- 'full' => __('Full Size'),
119
- ) );
120
- $sizeLabels = apply_filters( 'image_size_names_choose', array() );
121
-
122
- echo '<table class="widefat fixed" cellspacing="0">';
123
- echo '<thead>
124
- <tr>
125
- <th>' . __('Size', 'microp') . '</th>
126
- <th>' . __('Visible', 'microp') . '</th>
127
- <th>' . __('Default JPEG Quality', 'microp') . '</th>
128
- <th>' . __('Custom Label', 'microp') . '</th>
129
- </tr>
130
- </thead>
131
- <tbody>';
132
-
133
- $sizesSettings = unserialize($this->options['sizes_settings']);
134
-
135
- foreach ($imageSizes as $s) {
136
- $label = isset($sizeLabels[$s]) ? $sizeLabels[$s] : ucfirst( str_replace( '-', ' ', $s ) );
137
- if (isset($_wp_additional_image_sizes[$s])) {
138
- $cropMethod = $_wp_additional_image_sizes[$s]['crop'];
139
- } else {
140
- $cropMethod = get_option($s.'_crop');
141
- }
142
-
143
- if ($cropMethod == 0) {
144
- continue;
145
- }
146
-
147
- echo '<tr>
148
- <td>' . $label. '</td>
149
- <td><select name="mic_options[sizes_settings][' . $s . '][visibility]">
150
- <option value="visible">' . __('Yes', 'microp') . '</option>
151
- <option value="hidden" ' . ( $sizesSettings[$s]['visibility'] == 'hidden' ? 'selected' : '' ) . '>' . __('No', 'microp') . '</option>
152
- </select></td>
153
- <td><select name="mic_options[sizes_settings][' . $s . '][quality]">
154
- <option value="100">' . __('100 (best quality, biggest file)', 'microp') . '</option>
155
- <option value="80" ' . ( !isset ($sizesSettings[$s]['quality']) || $sizesSettings[$s]['quality'] == '80' ? 'selected' : '' ) . '>' . __('80 (very high quality)', 'microp') . '</option>
156
- <option value="70" ' . ( $sizesSettings[$s]['quality'] == '70' ? 'selected' : '' ) . '>' . __('70 (high quality)', 'microp') . '</option>
157
- <option value="60" ' . ( $sizesSettings[$s]['quality'] == '60' ? 'selected' : '' ) . '>' . __('60 (good)', 'microp') . '</option>
158
- <option value="50" ' . ( $sizesSettings[$s]['quality'] == '50' ? 'selected' : '' ) . '>' . __('50 (average)', 'microp') . '</option>
159
- <option value="30" ' . ( $sizesSettings[$s]['quality'] == '30' ? 'selected' : '' ) . '>' . __('30 (low)', 'microp') . '</option>
160
- <option value="10" ' . ( $sizesSettings[$s]['quality'] == '10' ? 'selected' : '' ) . '>' . __('10 (very low, smallest file)', 'microp') . '</option>
161
- </select></td>
162
- <td><input name="mic_options[sizes_settings][' . $s . '][label]" type="text" placeholder="' . $label . '" value="' . str_replace('"', '&quot;', $sizesSettings[$s]['label']) . '"/></td>
163
- </tr>';
164
- }
165
- echo '</tbody></table>';
166
-
167
- }
168
- }
169
-
170
- if( is_admin() ) {
171
- $mic_settings_page = new MicSettingsPage();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  }
1
+ <?php
2
+ class MicSettingsPage
3
+ {
4
+ /**
5
+ * Holds the values to be used in the fields callbacks
6
+ */
7
+ private $options;
8
+
9
+ /**
10
+ * Start up
11
+ */
12
+ public function __construct()
13
+ {
14
+ add_action( 'admin_menu', array( $this, 'add_plugin_page' ) );
15
+ add_action( 'admin_init', array( $this, 'page_init' ) );
16
+ }
17
+
18
+ /**
19
+ * Fix of settings serialized twice or more
20
+ * @return mixed
21
+ */
22
+ static function getSettings() {
23
+ $micOptions = get_option( 'mic_options' );
24
+ if ( ! isset( $micOptions['sizes_settings'] ) ) {
25
+ return array();
26
+ }
27
+ $settings = unserialize( $micOptions['sizes_settings'] );
28
+ $i = 0;
29
+ while ( ! empty($settings) && ! is_array($settings) ) {
30
+ if ($i++ == 10) {
31
+ break;
32
+ }
33
+ $settings = unserialize($settings);
34
+ }
35
+ return $settings;
36
+ }
37
+
38
+ /**
39
+ * Add options page
40
+ */
41
+ public function add_plugin_page()
42
+ {
43
+ // This page will be under "Settings"
44
+ add_options_page(
45
+ 'Settings Admin',
46
+ 'Manual Image Crop',
47
+ 'manage_options',
48
+ 'Mic-setting-admin',
49
+ array( $this, 'create_admin_page' )
50
+ );
51
+ }
52
+
53
+ /**
54
+ * Options page callback
55
+ */
56
+ public function create_admin_page()
57
+ {
58
+ ?>
59
+ <div class="wrap">
60
+ <?php screen_icon(); ?>
61
+ <h2>Manual Image Crop Settings</h2>
62
+ <form method="post" action="options.php" class="mic-settings-page">
63
+ <?php
64
+ // This prints out all hidden setting fields
65
+ settings_fields( 'mic_options_group' );
66
+ do_settings_sections( 'Mic-setting-admin' );
67
+ submit_button();
68
+ ?>
69
+ </form>
70
+ </div>
71
+ <?php
72
+ }
73
+
74
+ /**
75
+ * Register and add settings
76
+ */
77
+ public function page_init()
78
+ {
79
+ register_setting(
80
+ 'mic_options_group', // Option group
81
+ 'mic_options', // Option name
82
+ array( $this, 'sanitize' ) // Sanitize
83
+ );
84
+
85
+ add_settings_section(
86
+ 'setting_section_id', // ID
87
+ 'Mic Custom Settings', // Title
88
+ array( $this, 'print_section_info' ), // Callback
89
+ 'Mic-setting-admin' // Page
90
+ );
91
+
92
+ add_settings_field(
93
+ 'sizes_settings', // ID
94
+ 'Crop sizes settings', // Title
95
+ array( $this, 'sizes_settings_callback' ), // Callback
96
+ 'Mic-setting-admin', // Page
97
+ 'setting_section_id' // Section
98
+ );
99
+ }
100
+
101
+ /**
102
+ * Sanitize each setting field as needed
103
+ *
104
+ * @param array $input Contains all settings fields as array keys
105
+ */
106
+ public function sanitize( $input )
107
+ {
108
+ $new_input = array();
109
+ if( isset( $input['sizes_settings'] ) ) {
110
+ $new_input['sizes_settings'] = serialize( $input['sizes_settings'] );
111
+ }
112
+ return $new_input;
113
+ }
114
+
115
+ /**
116
+ * Print the Section text
117
+ */
118
+ public function print_section_info()
119
+ {
120
+ print 'Enter your settings below:';
121
+ }
122
+
123
+ /**
124
+ * Get the settings option array and print one of its values
125
+ */
126
+ public function sizes_settings_callback()
127
+ {
128
+ global $_wp_additional_image_sizes;
129
+
130
+ $imageSizes = get_intermediate_image_sizes();
131
+
132
+ $sizeLabels = apply_filters( 'image_size_names_choose', array(
133
+ 'thumbnail' => __('Thumbnail'),
134
+ 'medium' => __('Medium'),
135
+ 'large' => __('Large'),
136
+ 'full' => __('Full Size'),
137
+ ) );
138
+ $sizeLabels = apply_filters( 'image_size_names_choose', array() );
139
+
140
+ echo '<table class="widefat fixed" cellspacing="0">';
141
+ echo '<thead>
142
+ <tr>
143
+ <th>' . __('Size', 'microp') . '</th>
144
+ <th>' . __('Visible', 'microp') . '</th>
145
+ <th>' . __('Default JPEG Quality', 'microp') . '</th>
146
+ <th>' . __('Custom Label', 'microp') . '</th>
147
+ </tr>
148
+ </thead>
149
+ <tbody>';
150
+
151
+ $sizesSettings = self::getSettings();
152
+
153
+ foreach ($imageSizes as $s) {
154
+ $label = isset($sizeLabels[$s]) ? $sizeLabels[$s] : ucfirst( str_replace( '-', ' ', $s ) );
155
+ if (isset($_wp_additional_image_sizes[$s])) {
156
+ $cropMethod = $_wp_additional_image_sizes[$s]['crop'];
157
+ } else {
158
+ $cropMethod = get_option($s.'_crop');
159
+ }
160
+
161
+ if ($cropMethod == 0) {
162
+ continue;
163
+ }
164
+
165
+ echo '<tr>
166
+ <td>' . $label. '</td>
167
+ <td><select name="mic_options[sizes_settings][' . $s . '][visibility]">
168
+ <option value="visible">' . __('Yes', 'microp') . '</option>
169
+ <option value="hidden" ' . ( $sizesSettings[$s]['visibility'] == 'hidden' ? 'selected' : '' ) . '>' . __('No', 'microp') . '</option>
170
+ </select></td>
171
+ <td><select name="mic_options[sizes_settings][' . $s . '][quality]">
172
+ <option value="100">' . __('100 (best quality, biggest file)', 'microp') . '</option>
173
+ <option value="80" ' . ( !isset ($sizesSettings[$s]['quality']) || $sizesSettings[$s]['quality'] == '80' ? 'selected' : '' ) . '>' . __('80 (very high quality)', 'microp') . '</option>
174
+ <option value="70" ' . ( $sizesSettings[$s]['quality'] == '70' ? 'selected' : '' ) . '>' . __('70 (high quality)', 'microp') . '</option>
175
+ <option value="60" ' . ( $sizesSettings[$s]['quality'] == '60' ? 'selected' : '' ) . '>' . __('60 (good)', 'microp') . '</option>
176
+ <option value="50" ' . ( $sizesSettings[$s]['quality'] == '50' ? 'selected' : '' ) . '>' . __('50 (average)', 'microp') . '</option>
177
+ <option value="30" ' . ( $sizesSettings[$s]['quality'] == '30' ? 'selected' : '' ) . '>' . __('30 (low)', 'microp') . '</option>
178
+ <option value="10" ' . ( $sizesSettings[$s]['quality'] == '10' ? 'selected' : '' ) . '>' . __('10 (very low, smallest file)', 'microp') . '</option>
179
+ </select></td>
180
+ <td><input name="mic_options[sizes_settings][' . $s . '][label]" type="text" placeholder="' . $label . '" value="' . str_replace('"', '&quot;', $sizesSettings[$s]['label']) . '"/></td>
181
+ </tr>';
182
+ }
183
+ echo '</tbody></table>';
184
+
185
+ }
186
+ }
187
+
188
+ if( is_admin() ) {
189
+ $mic_settings_page = new MicSettingsPage();
190
  }
manual-image-crop.php CHANGED
@@ -3,13 +3,13 @@
3
  Plugin Name: Manual Image Crop
4
  Plugin URI: http://www.rocketmill.co.uk/wordpress-plugin-manual-image-crop
5
  Description: Plugin allows you to manually crop all the image sizes registered in your WordPress theme (in particular featured image). Simply click on the "Crop" link next to any image in your media library and select the area of the image you want to crop.
6
- Version: 1.06
7
  Author: Tomasz Sita
8
  Author URI: http://www.rocketmill.co.uk/author/tomasz
9
  License: GPL2
10
  */
11
 
12
- define('mic_VERSION', '1.1');
13
 
14
 
15
  include_once(dirname(__FILE__) . '/lib/ManualImageCrop.php');
3
  Plugin Name: Manual Image Crop
4
  Plugin URI: http://www.rocketmill.co.uk/wordpress-plugin-manual-image-crop
5
  Description: Plugin allows you to manually crop all the image sizes registered in your WordPress theme (in particular featured image). Simply click on the "Crop" link next to any image in your media library and select the area of the image you want to crop.
6
+ Version: 1.07
7
  Author: Tomasz Sita
8
  Author URI: http://www.rocketmill.co.uk/author/tomasz
9
  License: GPL2
10
  */
11
 
12
+ define('mic_VERSION', '1.07');
13
 
14
 
15
  include_once(dirname(__FILE__) . '/lib/ManualImageCrop.php');
readme.txt CHANGED
@@ -1,12 +1,12 @@
1
  === Manual Image Crop ===
2
  Contributors: tomasz.sita
3
  Tags: crop, cropping, thumbnail, featured image, gallery, images, picture, image, image area
4
- Tested up to: 3.9.1
5
  Requires at least: 3.0.1
6
  License: GPLv2 or later
7
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
8
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WB5ZQWGUM7T96
9
- Stable tag: 1.06
10
 
11
  Plugin allows you to manually crop all the image sizes registered in your WordPress theme (in particular featured image).
12
 
@@ -45,6 +45,9 @@ Automatically:
45
  * When the plugin has been installed, Click 'Activate'
46
 
47
  == Changelog ==
 
 
 
48
  = 1.06 =
49
  * French, German, Italian, Polish, Spanish translations added
50
  * Settings page added (quality, visibility, custom labels)
1
  === Manual Image Crop ===
2
  Contributors: tomasz.sita
3
  Tags: crop, cropping, thumbnail, featured image, gallery, images, picture, image, image area
4
+ Tested up to: 3.9.2
5
  Requires at least: 3.0.1
6
  License: GPLv2 or later
7
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
8
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WB5ZQWGUM7T96
9
+ Stable tag: 1.07
10
 
11
  Plugin allows you to manually crop all the image sizes registered in your WordPress theme (in particular featured image).
12
 
45
  * When the plugin has been installed, Click 'Activate'
46
 
47
  == Changelog ==
48
+ = 1.07 =
49
+ * Fixed 'Cannot use string offset as an array' error
50
+
51
  = 1.06 =
52
  * French, German, Italian, Polish, Spanish translations added
53
  * Settings page added (quality, visibility, custom labels)