From 21f4b36c9b92f0c8bc5226e94b58e6835e2a4617 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Tue, 26 Nov 2024 12:01:40 +0000 Subject: [PATCH 1/2] Delay setting the plugin properties until `init` --- php/class-plugin.php | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/php/class-plugin.php b/php/class-plugin.php index f7dd3907..0ff01421 100644 --- a/php/class-plugin.php +++ b/php/class-plugin.php @@ -101,15 +101,6 @@ final class Plugin { * Plugin_Base constructor. */ public function __construct() { - require_once ABSPATH . 'wp-admin/includes/plugin.php'; - $plugin = get_plugin_data( CLDN_CORE ); - $location = $this->locate_plugin(); - $this->slug = ! empty( $plugin['TextDomain'] ) ? $plugin['TextDomain'] : $location['dir_basename']; - $this->version = $plugin['Version']; - $this->dir_path = $location['dir_path']; - $this->template_path = $this->dir_path . 'php/templates/'; - $this->dir_url = $location['dir_url']; - $this->plugin_file = pathinfo( dirname( CLDN_CORE ), PATHINFO_BASENAME ) . '/' . wp_basename( CLDN_CORE ); $this->setup_endpoints(); spl_autoload_register( array( $this, 'autoload' ) ); $this->register_hooks(); @@ -122,7 +113,7 @@ public function __construct() { * after_setup_theme priority 10. This is especially important for plugins * that extend the Customizer to ensure resources are available in time. */ - public function init() { + public function plugins_loaded() { Cron::get_instance(); $this->components['admin'] = new Admin( $this ); $this->components['state'] = new State( $this ); @@ -279,8 +270,9 @@ public function set_config() { * Register Hooks for the plugin. */ public function register_hooks() { - add_action( 'plugins_loaded', array( $this, 'init' ), 9 ); + add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ), 9 ); add_action( 'admin_enqueue_scripts', array( $this, 'register_enqueue_styles' ), 11 ); + add_action( 'init', array( $this, 'init' ) ); // Move to 100 and 200 to allow other plugins/systems to add cloudinary filters and actions that are fired within the init hooks. add_action( 'init', array( $this, 'setup' ), 100 ); add_action( 'init', array( $this, 'register_assets' ), 200 ); @@ -423,6 +415,23 @@ private function is_notice_component( $component ) { return $component instanceof Notice; } + /** + * Init the plugin properties. + * + * @return void + */ + public function init() { + require_once ABSPATH . 'wp-admin/includes/plugin.php'; + $plugin = get_plugin_data( CLDN_CORE ); + $location = $this->locate_plugin(); + $this->slug = ! empty( $plugin['TextDomain'] ) ? $plugin['TextDomain'] : $location['dir_basename']; + $this->version = $plugin['Version']; + $this->dir_path = $location['dir_path']; + $this->template_path = $this->dir_path . 'php/templates/'; + $this->dir_url = $location['dir_url']; + $this->plugin_file = pathinfo( dirname( CLDN_CORE ), PATHINFO_BASENAME ) . '/' . wp_basename( CLDN_CORE ); + } + /** * Setup hooks * From 7d9b7faa4c17bbea73a3f328082d7391d3edf8e1 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Tue, 26 Nov 2024 12:03:05 +0000 Subject: [PATCH 2/2] Bail early, if the asset is not ready --- php/class-delivery.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/php/class-delivery.php b/php/class-delivery.php index 5e0a0295..5c1a692b 100644 --- a/php/class-delivery.php +++ b/php/class-delivery.php @@ -1051,7 +1051,13 @@ public function convert_tags( $content, $context = 'view' ) { $aliases[ $local_url ] = $cached[ $local_url ]; continue; } - $cloudinary_url = $this->media->cloudinary_url( $relation['post_id'], explode( 'x', $size ), $relation['transformations'], $public_id ); + + $cloudinary_url = $this->media->cloudinary_url( $relation['post_id'], explode( 'x', $size ), $relation['transformations'], $public_id ); + // The asset is not ready. Carry on. + if ( empty( $cloudinary_url ) ) { + continue; + } + $aliases[ $local_url . '?' ] = $cloudinary_url . '&'; $aliases[ $local_url ] = $cloudinary_url;