Skip to content

Commit 3053ad5

Browse files
authored
Merge pull request #294 from cloudinary/hotfix/api-calls
increase time for status cron, set usage with data, add referer
2 parents 59031a5 + 8e048ea commit 3053ad5

File tree

3 files changed

+7
-23
lines changed

3 files changed

+7
-23
lines changed

cloudinary.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Cloudinary
44
* Plugin URI: https://cloudinary.com/documentation/wordpress_integration
55
* Description: With the Cloudinary plugin, you can upload and manage your media assets in the cloud, then deliver them to your users through a fast content delivery network, improving your website’s loading speed and overall user experience. Apply multiple transformations and take advantage of a full digital asset management solution without leaving WordPress.
6-
* Version: 2.4.0
6+
* Version: 2.4.1
77
* Author: Cloudinary Ltd., XWP
88
* Author URI: https://cloudinary.com/
99
* License: GPLv2+

php/class-connect.php

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ class Connect implements Config, Setup, Notice {
102102
public function __construct( Plugin $plugin ) {
103103
$this->plugin = $plugin;
104104
add_filter( 'pre_update_option_cloudinary_connect', array( $this, 'verify_connection' ) );
105-
add_filter( 'cron_schedules', array( $this, 'get_status_schedule' ) ); // phpcs:ignore WordPress.WP.CronInterval
106105
add_action( 'cloudinary_status', array( $this, 'check_status' ) );
107106
add_action( 'cloudinary_version_upgrade', array( $this, 'upgrade_connection' ) );
108107
}
@@ -475,29 +474,13 @@ public function setup() {
475474
}
476475
}
477476

478-
/**
479-
* Add our every minute schedule.
480-
*
481-
* @param array $schedules Array of schedules.
482-
*
483-
* @return array
484-
*/
485-
public function get_status_schedule( $schedules ) {
486-
$schedules['every_minute'] = array(
487-
'interval' => MINUTE_IN_SECONDS,
488-
'display' => __( 'Every Minute', 'cloudinary' ),
489-
);
490-
491-
return $schedules;
492-
}
493-
494477
/**
495478
* Setup Status cron.
496479
*/
497480
protected function setup_status_cron() {
498481
if ( false === wp_get_schedule( 'cloudinary_status' ) ) {
499482
$now = current_time( 'timestamp' ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
500-
wp_schedule_event( $now + ( MINUTE_IN_SECONDS ), 'every_minute', 'cloudinary_status' );
483+
wp_schedule_event( $now + ( MINUTE_IN_SECONDS ), 'hourly', 'cloudinary_status' );
501484
}
502485
}
503486

@@ -514,13 +497,13 @@ public function usage_stats( $refresh = false ) {
514497
if ( ! is_wp_error( $stats ) && ! empty( $stats['media_limits'] ) ) {
515498
$stats['max_image_size'] = $stats['media_limits']['image_max_size_bytes'];
516499
$stats['max_video_size'] = $stats['media_limits']['video_max_size_bytes'];
517-
set_transient( self::META_KEYS['usage'], $stats, HOUR_IN_SECONDS );
518-
update_option( self::META_KEYS['last_usage'], $stats );// Save the last successful call to prevent crashing.
519500
} else {
520501
// Handle error by logging and fetching the last success.
521502
// @todo : log issue.
522503
$stats = get_option( self::META_KEYS['last_usage'] );
523504
}
505+
// Set useage state to the results, either new or the last, to prevent API hits.
506+
set_transient( self::META_KEYS['usage'], $stats, HOUR_IN_SECONDS );
524507
}
525508
$this->usage = $stats;
526509
}

php/connect/class-api.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,9 @@ public function set_data( $handle, $request, $url ) {
660660
* @return array|\WP_Error
661661
*/
662662
private function call( $url, $args = array(), $method = 'get' ) {
663-
$args['method'] = strtoupper( $method );
664-
$args['user-agent'] = 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ) . ' (' . $this->plugin_version . ')';
663+
$args['method'] = strtoupper( $method );
664+
$args['user-agent'] = 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ) . ' (' . $this->plugin_version . ')';
665+
$args['headers']['referer'] = get_site_url();
665666
if ( 'GET' === $args['method'] ) {
666667
$url = 'https://' . $this->credentials['api_key'] . ':' . $this->credentials['api_secret'] . '@' . $url;
667668
} else {

0 commit comments

Comments
 (0)