Skip to content

Commit

Permalink
Merge pull request #35 from av3nger/release/1.6.0
Browse files Browse the repository at this point in the history
Release/1.6.0
  • Loading branch information
av3nger authored Nov 12, 2023
2 parents 2cc6048 + 56671c1 commit d980f9a
Show file tree
Hide file tree
Showing 82 changed files with 2,892 additions and 1,481 deletions.
1 change: 1 addition & 0 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
LICENSE
package.json
package-lock.json
tsconfig.json
webpack.config.js
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": [ "plugin:@wordpress/eslint-plugin/recommended-with-formatting" ],
"extends": [ "plugin:@wordpress/eslint-plugin/recommended" ],
"plugins": [],
"parserOptions": {
"ecmaVersion": 2022,
Expand All @@ -21,7 +21,7 @@
"settings": {
"import/resolver": {
"node": {
"extensions": [ ".js", ".jsx" ]
"extensions": [ ".js", ".jsx", ".ts", ".tsx" ]
}
}
}
Expand Down
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
/LICENSE export-ignore
/package.json export-ignore
/package-lock.json export-ignore
/tsconfig.json export-ignore
/webpack.config.js export-ignore
Binary file modified .wordpress-org/banner-1544x500.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .wordpress-org/banner-772x250.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .wordpress-org/screenshot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .wordpress-org/screenshot-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .wordpress-org/screenshot-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 22 additions & 5 deletions README.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
=== Offload, Store, Resize & Optimize with Cloudflare Images ===
Plugin Name: Offload, Store, Resize & Optimize with Cloudflare Images
=== Offload, AI & Optimize with Cloudflare Images ===
Plugin Name: Offload, AI & Optimize with Cloudflare Images
Contributors: vanyukov
Tags: cdn, cloudflare images, offload images, compress, cloudflare, optimize
Donate link: https://www.paypal.com/donate/?business=JRR6QPRGTZ46N&no_recurring=0&item_name=Help+support+the+development+of+the+Cloudflare+Images+plugin+for+WordPress&currency_code=AUD
Requires at least: 5.6
Requires PHP: 7.0
Tested up to: 6.4
Stable tag: 1.5.1
Stable tag: 1.6.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -31,7 +31,7 @@ Offload your media library to Cloudflare Images! Let our plugin take charge:

= But wait, there's more! =

Image AI - tag and caption your images using AI.
Image AI - tag, caption and generate new images using AI.
Compression - optimize JPEG/PNG images to decrease file size without compromising visual quality.

= A Developer's Promise =
Expand Down Expand Up @@ -90,10 +90,27 @@ If something is still not working for you, please let me know by creating a supp
== Screenshots ==

1. Plugin options and settings
2. Quick and easy setup wizard
2. Plugin AI modules
3. Quick and easy setup wizard

== Changelog ==

= 1.6.0 - 12.11.2023 =

Added:
* Generate images with AI
* Logging module
* Images in media library can now be sorted by offload status
* Integration with ShortPixel
* Compatibility option to store credentials in the database

Changed:
* Increase timeout to 15 seconds when offloading images

Fixed:
* Bulk processing stops if an image triggers an error during upload
* Settings resetting on update after using a beta version

= 1.5.1 - 28.10.2023 =

Fixed:
Expand Down
26 changes: 26 additions & 0 deletions app/api/class-ai.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,30 @@ public function caption( string $image ): string {

throw new Exception( esc_html__( 'Unable to caption image.', 'cf-images' ) );
}

/**
* Generate image.
*
* @since 1.6.0
*
* @param array $params Request arguments.
*
* @throws Exception Exception if unable to generate image.
*
* @return string
*/
public function generate( array $params ): string {
$this->set_method( 'POST' );
$this->set_timeout( 60 );
$this->set_endpoint( 'images/generate' );
$this->set_request_body( wp_json_encode( $params ) );

$response = $this->request();

if ( isset( $response->data ) ) {
return $response->data;
}

throw new Exception( esc_html__( 'Unable to generate image.', 'cf-images' ) );
}
}
16 changes: 14 additions & 2 deletions app/api/class-cloudflare.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ class Cloudflare extends Api {
protected function get_args(): array {
$args = parent::get_args();

if ( defined( 'CF_IMAGES_KEY_TOKEN' ) ) {
$api_key = constant( 'CF_IMAGES_KEY_TOKEN' );
} else {
$api_key = get_site_option( 'cf-images-api-token' );
}

$args['headers'] = array(
'Authorization' => 'Bearer ' . constant( 'CF_IMAGES_KEY_TOKEN' ),
'Authorization' => 'Bearer ' . $api_key,
);

return $args;
Expand All @@ -61,7 +67,13 @@ protected function get_args(): array {
* @return string
*/
protected function get_url(): string {
return $this->api_url . constant( 'CF_IMAGES_ACCOUNT_ID' ) . '/images/v1' . $this->endpoint;
if ( defined( 'CF_IMAGES_ACCOUNT_ID' ) ) {
$account_id = constant( 'CF_IMAGES_ACCOUNT_ID' );
} else {
$account_id = get_site_option( 'cf-images-account-id' );
}

return $this->api_url . $account_id . '/images/v1' . $this->endpoint;
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/api/class-image.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function upload( string $image, int $id = 0, string $name = '' ): stdClas

$this->set_method( 'UPLOAD' );
$this->set_endpoint( '' );
$this->set_timeout( 15 );
$this->set_request_body( $data );

$results = $this->request();
Expand Down
2 changes: 1 addition & 1 deletion app/class-activator.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static function maybe_upgrade() {
delete_option( 'cf-images-install-notice' );
}

if ( version_compare( $version, '1.5.0' ) ) {
if ( version_compare( $version, '1.5.0', '<' ) ) {
self::upgrade_150();
}

Expand Down
39 changes: 1 addition & 38 deletions app/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ public function __construct() {
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );

add_action( 'admin_menu', array( $this, 'register_menu' ) );
add_action( 'admin_notices', array( $this, 'show_notice' ) );
add_filter( 'plugin_action_links_cf-images/cf-images.php', array( $this, 'settings_link' ) );

if ( wp_doing_ajax() ) {
$settings = new Settings();
add_action( 'wp_ajax_cf_images_do_setup', array( $settings, 'ajax_do_setup' ) );
add_action( 'wp_ajax_cf_images_disconnect', array( $settings, 'ajax_disconnect' ) );
add_action( 'wp_ajax_cf_images_hide_sidebar', array( $settings, 'ajax_hide_sidebar' ) );
add_action( 'wp_ajax_cf_images_check_status', array( $settings, 'ajax_check_status' ) );

add_action( 'wp_ajax_cf_images_offload_image', array( $this->media, 'ajax_offload_image' ) );
add_action( 'wp_ajax_cf_images_bulk_process', array( $this->media, 'ajax_bulk_process' ) );
Expand Down Expand Up @@ -173,43 +173,6 @@ public function register_menu() {
);
}

/**
* Show notice.
*
* @since 1.0.0
*/
public function show_notice() {
if ( false !== $this->get_error() ) {
$message = sprintf( /* translators: %1$s - error message, %2$d - error code */
esc_html__( '%1$s (code: %2$d)', 'cf-images' ),
esc_html( $this->get_error()->get_error_message() ),
(int) $this->get_error()->get_error_code()
);

$this->render_notice( $message, 'error' );
}
}

/**
* Render notice.
*
* @since 1.0.0
*
* @param string $message Notice message.
* @param string $type Notice type.
*/
public function render_notice( string $message, string $type = 'success' ) {
?>
<div class="cf-images-notifications">
<div class="notice notice-<?php echo esc_attr( $type ); ?>" id="cf-images-notice">
<p>
<?php echo esc_html( $message ); ?>
</p>
</div>
</div>
<?php
}

/**
* Render page.
*
Expand Down
7 changes: 7 additions & 0 deletions app/class-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ private function set_cdn_domain() {
* @see Integrations\Rank_Math
* @see Integrations\Spectra
* @see Integrations\Wpml
* @see Integrations\Shortpixel
*/
private function init_integrations() {
$loader = Loader::get_instance();
Expand All @@ -185,6 +186,7 @@ private function init_integrations() {
$loader->integration( 'rank-math' );
$loader->integration( 'acf' );
$loader->integration( 'wpml' );
$loader->integration( 'shortpixel' );
}

/**
Expand All @@ -201,6 +203,8 @@ private function init_integrations() {
* @see Modules\Image_Ai
* @see Modules\Image_Compress
* @see Modules\Page_Parser
* @see Modules\Image_Generate
* @see Modules\Logging
*/
private function load_modules() {
$loader = Loader::get_instance();
Expand All @@ -214,6 +218,8 @@ private function load_modules() {
$loader->module( 'image-ai' );
$loader->module( 'image-compress' );
$loader->module( 'page-parser' );
$loader->module( 'image-generate' );
$loader->module( 'logging' );
}

/**
Expand All @@ -228,6 +234,7 @@ public function set_error( $code = '', string $message = '' ) {
if ( '' === $code ) {
self::$error = false;
} else {
do_action( 'cf_images_log', $message );
self::$error = new WP_Error( $code, $message );
}
}
Expand Down
1 change: 1 addition & 0 deletions app/class-image.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public function __construct( string $image, string $src, string $srcset ) {
private function get_attachment_id() {
if ( preg_match( '/wp-image-(\d+)/i', $this->image, $class_id ) ) {
$this->id = absint( $class_id[1] );
do_action( 'cf_images_log', 'Found attachment ID %s from image class name.', $this->id );
}
}

Expand Down
Loading

0 comments on commit d980f9a

Please sign in to comment.