Changeset 1859904
- Timestamp:
- 04/17/2018 05:32:12 PM (8 years ago)
- Location:
- octify/trunk
- Files:
-
- 3 edited
-
Libs/OctifyApi.php (modified) (4 diffs)
-
Octify.php (modified) (1 diff)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
octify/trunk/Libs/OctifyApi.php
r1859060 r1859904 220 220 221 221 $imageMeta = wp_get_attachment_metadata( $id ); 222 $imageUrl = $uploadDirs['baseurl'] . '/' . $imageMeta['file'];222 $imageUrl = wp_get_attachment_image_url( $id, 'full' ); 223 223 $imagePath = $uploadDirs['basedir'] . '/' . $imageMeta['file']; 224 224 $imageToProcess[ $id ] = array( … … 237 237 $imageToProcess = array_filter( $imageToProcess ); 238 238 if ( count( $imageToProcess ) ) { 239 $request = wp_remote_post( self::API_ENDPOINT . 'v1/image/bulk_compress2', array( 240 'body' => array( 241 'images' => json_encode( $imageToProcess ) 242 ), 243 'timeout' => 30 244 ) ); 245 if ( is_wp_error( $request ) ) { 246 return $request; 247 } 248 $body = wp_remote_retrieve_body( $request ); 249 $body = json_decode( $body, true ); 250 if ( ! is_array( $body ) ) { 251 return new \WP_Error( 'invalid_response', 'Please try again' ); 252 } 253 if ( $body['status'] == 1 ) { 254 return array( 255 'success' => array_keys( $imageToProcess ), 256 'fail' => array() 257 ); 258 } else { 259 //get the error and success 260 $success = array_keys( $imageToProcess ); 261 $fail = array(); 262 foreach ( $body['error'] as $error ) { 263 unset( $success[ $error['meta'] ] ); 264 $fail[] = array( 265 'id' => $error['meta'], 266 'error' => $error['error'], 267 'code' => $error['errorCode'] 268 ); 269 if ( $error['errorCode'] == 'expired' ) { 270 $license = get_option( self::LICENSE_NAME, false ); 271 $license['isExpired'] = true; 272 update_option( self::LICENSE_NAME, $license ); 239 $chunks = array_chunk( $imageToProcess, 10 ); 240 $data = array( 241 'success' => array(), 242 'fail' => array() 243 ); 244 foreach ( $chunks as $chunk ) { 245 $request = wp_remote_post( self::API_ENDPOINT . 'v1/image/bulk_compress2', array( 246 'body' => array( 247 'images' => json_encode( $chunk ) 248 ), 249 'timeout' => 60 250 ) ); 251 252 if ( is_wp_error( $request ) ) { 253 return $request; 254 } 255 $body = wp_remote_retrieve_body( $request ); 256 $body = json_decode( $body, true ); 257 if ( ! is_array( $body ) ) { 258 259 return new \WP_Error( 'invalid_response', 'Please try again' ); 260 } 261 if ( $body['status'] == 1 ) { 262 $data['success'] = array_merge( $data['success'], array_keys( $imageToProcess ) ); 263 } else { 264 //get the error and success 265 $success = array_keys( $imageToProcess ); 266 $fail = array(); 267 foreach ( $body['error'] as $error ) { 268 unset( $success[ $error['meta'] ] ); 269 $fail[] = array( 270 'id' => $error['meta'], 271 'error' => $error['error'], 272 'code' => $error['errorCode'] 273 ); 274 if ( $error['errorCode'] == 'expired' ) { 275 $license = get_option( self::LICENSE_NAME, false ); 276 $license['isExpired'] = true; 277 update_option( self::LICENSE_NAME, $license ); 278 } 273 279 } 280 $data['success'] = array_merge( $data['success'], $success ); 281 $data['fail'] = array_merge( $data['fail'], $fail ); 274 282 } 275 276 return array( 277 'success' => $success, 278 'fail' => $fail 279 ); 280 } 283 } 284 285 return $data; 281 286 } else { 282 287 return false; … … 313 318 return; 314 319 } 315 file_put_contents( __DIR__ . '/test', var_export( $data, true ) . PHP_EOL, FILE_APPEND );316 320 $comparedHmac = $data['hmac']; 317 321 unset( $data['hmac'] ); … … 347 351 } 348 352 $tmp = download_url( $data['image_url'] ); 349 350 353 if ( is_wp_error( $tmp ) ) { 351 354 update_post_meta( $attachmentId, self::META_STATUS, 'error' ); -
octify/trunk/Octify.php
r1859162 r1859904 4 4 * Plugin URI: https://octify.io 5 5 * Description: Octify Image Compression for WordPress. 6 * Version: 1.1. 26 * Version: 1.1.3 7 7 * Author: Octify 8 8 * Author URI: https://octify.io -
octify/trunk/readme.txt
r1859162 r1859904 1 1 === WordPress Image Compression Plugin - Octify === 2 2 Plugin Name: Octify 3 Version: 1.1. 13 Version: 1.1.3 4 4 Author: Octify 5 5 Author URI: https://octify.io/ … … 7 7 Tags: Image Compression, Image Optimisation, resize, optimise, performance, optimize, compress images, optimize images, optimise images, image optimization. 8 8 Tested up to: 4.9.5 9 Stable tag: 1.1. 29 Stable tag: 1.1.3 10 10 Requires PHP: 5.2.4 11 11 License: GPLv2 … … 141 141 == Changelog == 142 142 143 == 1.1.3 == 144 145 * Fix issue with sending images to API timing out 146 * Improve chunked data 147 148 == 1.1.2 == 149 150 * Small fixes 151 143 152 == 1.1.1 == 144 153 * Add top level menu link
Note: See TracChangeset
for help on using the changeset viewer.