Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion php/cache/class-cache-point.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Cache_Point {
/**
* Holds a list of pre-found cached urls before querying to find cached items
*
* @var array.
* @var array
*/
protected $pre_cached = array();
/**
Expand Down
16 changes: 12 additions & 4 deletions php/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Admin {
/**
* Holds notices object.
*
* @var Settings
* @var Setting
*/
protected $notices;

Expand Down Expand Up @@ -522,16 +522,24 @@ public function render_notices() {
}

/**
* Get admin notices.
* Absorb WordPress settings errors into the plugin notice store and return
* the renderable notice setting, if any notices are pending.
*
* @return Setting[]
* @return Setting|null
*/
public function get_admin_notices() {
$setting_notices = get_settings_errors();
foreach ( $setting_notices as $key => $notice ) {
$this->add_admin_notice( $notice['code'], $notice['message'], $notice['type'], true );
}

return $setting_notices;
$notices = $this->notices->get_value();
if ( empty( $notices ) ) {
return null;
}

sort( $notices );

return $this->init_components( $notices, self::NOTICE_SLUG );
}
}
5 changes: 3 additions & 2 deletions php/class-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ public function get_active_asset_parents() {
*
* @param int $asset_id The asset id.
*
* @return \WP_Post|null;
* @return \WP_Post|null
*/
public function find_parent( $asset_id ) {
$path = $this->clean_path( $this->media->local_url( $asset_id ) );
Expand Down Expand Up @@ -1792,7 +1792,8 @@ protected function add_external_settings() {
*/
protected function add_asset_parent( $post ) {
if ( is_multisite() ) {
$post->blog_id = get_current_blog_id();
// Dynamically stash the current blog ID on the post object for later multisite checks.
$post->blog_id = get_current_blog_id(); // @phpstan-ignore property.notFound
}

$this->asset_parents[ $post->post_title ] = $post;
Expand Down
88 changes: 38 additions & 50 deletions php/class-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Cloudinary\Cache\Cache_Point;
use Cloudinary\Cache\File_System;
use Cloudinary\Component\Setup;
use Cloudinary\Settings\Setting;
use WP_Error;
use WP_HTTP_Response;
use WP_REST_Request;
Expand Down Expand Up @@ -720,33 +719,17 @@ public function setup() {
}

/**
* Adds the individual setting tabs.
*/
protected function setup_setting_tabs() {
$cache_settings = $this->get_cache_settings();
foreach ( $cache_settings as $setting ) {
$callback = $setting->get_param( 'callback' );
if ( is_callable( $callback ) ) {
call_user_func( $callback ); // Init the settings.
}
}
}

/**
* Get all the Cache settings.
* Register the cache-path hooks for each cache tab.
*
* @return Setting[]
* The settings structures themselves are registered declaratively via
* settings(); this only wires the per-tab cache_point path callbacks that
* run on the cloudinary_cache_init_cache_points action.
*/
public function get_cache_settings() {
static $settings = array();
if ( empty( $settings ) ) {
$main_setting = $this->settings->get_setting( 'cache_paths' );
foreach ( $main_setting->get_settings() as $slug => $setting ) {
$settings[ $slug ] = $setting;
}
}

return $settings;
protected function setup_setting_tabs() {
add_action( 'cloudinary_cache_init_cache_points', array( $this, 'add_plugin_cache_paths' ) );
add_action( 'cloudinary_cache_init_cache_points', array( $this, 'add_theme_cache_paths' ) );
add_action( 'cloudinary_cache_init_cache_points', array( $this, 'add_wp_cache_paths' ) );
add_action( 'cloudinary_cache_init_cache_points', array( $this, 'add_content_cache_paths' ) );
}

/**
Expand Down Expand Up @@ -783,7 +766,9 @@ public function add_cache_paths( $setting, $cache_point_setting, $all_cache_sett
}

/**
* Add the plugin cache settings page.
* Get the plugin cache settings structure.
*
* @return array
*/
protected function add_plugin_settings() {

Expand Down Expand Up @@ -821,8 +806,8 @@ protected function add_plugin_settings() {
$plugins_setup,
),
);
$this->settings->create_setting( 'plugins_settings', $params, $this->settings->get_setting( 'cache_plugins' ) );
add_action( 'cloudinary_cache_init_cache_points', array( $this, 'add_plugin_cache_paths' ) );

return $params;
}

/**
Expand All @@ -834,7 +819,9 @@ public function add_plugin_cache_paths() {
}

/**
* Add Theme Settings page.
* Get the theme cache settings structure.
*
* @return array
*/
protected function add_theme_settings() {

Expand Down Expand Up @@ -873,8 +860,7 @@ protected function add_theme_settings() {
),
);

$this->settings->create_setting( 'theme_settings', $params, $this->settings->get_setting( 'cache_themes' ) );
add_action( 'cloudinary_cache_init_cache_points', array( $this, 'add_theme_cache_paths' ) );
return $params;
}

/**
Expand All @@ -886,7 +872,9 @@ public function add_theme_cache_paths() {
}

/**
* Add WP Settings page.
* Get the WordPress cache settings structure.
*
* @return array
*/
protected function add_wp_settings() {

Expand Down Expand Up @@ -925,8 +913,7 @@ protected function add_wp_settings() {
),
);

$this->settings->create_setting( 'wordpress_settings', $params, $this->settings->get_setting( 'cache_wordpress' ) );
add_action( 'cloudinary_cache_init_cache_points', array( $this, 'add_wp_cache_paths' ) );
return $params;
}

/**
Expand All @@ -938,7 +925,9 @@ public function add_wp_cache_paths() {
}

/**
* Add WP Settings page.
* Get the content cache settings structure.
*
* @return array
*/
protected function add_content_settings() {

Expand Down Expand Up @@ -977,8 +966,7 @@ protected function add_content_settings() {
),
);

$this->settings->create_setting( 'content_settings', $params, $this->settings->get_setting( 'cache_content' ) );
add_action( 'cloudinary_cache_init_cache_points', array( $this, 'add_content_cache_paths' ) );
return $params;
}

/**
Expand Down Expand Up @@ -1046,24 +1034,24 @@ public function settings() {
'default' => 'off',
),
array(
'slug' => 'cache_plugins',
'type' => 'frame',
'callback' => array( $this, 'add_plugin_settings' ),
'slug' => 'cache_plugins',
'type' => 'frame',
$this->add_plugin_settings(),
),
array(
'slug' => 'cache_themes',
'type' => 'frame',
'callback' => array( $this, 'add_theme_settings' ),
'slug' => 'cache_themes',
'type' => 'frame',
$this->add_theme_settings(),
),
array(
'slug' => 'cache_wordpress',
'type' => 'frame',
'callback' => array( $this, 'add_wp_settings' ),
'slug' => 'cache_wordpress',
'type' => 'frame',
$this->add_wp_settings(),
),
array(
'slug' => 'cache_content',
'type' => 'frame',
'callback' => array( $this, 'add_content_settings' ),
'slug' => 'cache_content',
'type' => 'frame',
$this->add_content_settings(),
),
),
array(
Expand Down
10 changes: 10 additions & 0 deletions php/class-connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ public function rest_test_connection( WP_REST_Request $request ) {
$url = $request->get_param( 'cloudinary_url' );
$result = $this->test_connection( $url );

/**
* The analytics component.
*
* @var \Cloudinary\Analytics $analytics
*/
$analytics = $this->plugin->get_component( 'analytics' );
if ( $analytics ) {
$success = isset( $result['type'] ) && 'connection_success' === $result['type'];
Expand Down Expand Up @@ -240,6 +245,11 @@ public function rest_save_wizard( WP_REST_Request $request ) {
);
}

/**
* The analytics component.
*
* @var \Cloudinary\Analytics $analytics
*/
$analytics = $this->plugin->get_component( 'analytics' );
if ( $analytics ) {
$analytics->track(
Expand Down
13 changes: 12 additions & 1 deletion php/class-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,19 @@ public function __construct( Plugin $plugin ) {
* @return bool
*/
public function has_data() {
/**
* The sync component.
*
* @var \Cloudinary\Sync $sync
*/
$sync = $this->plugin->get_component( 'sync' );
$data = $sync->managers['queue']->get_total_synced_media();
/**
* The sync queue manager.
*
* @var \Cloudinary\Sync\Sync_Queue $queue
*/
$queue = $sync->managers['queue'];
$data = $queue->get_total_synced_media();

return ! empty( $data );
}
Expand Down
5 changes: 5 additions & 0 deletions php/class-deactivation.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,11 @@ protected function cleanup_options() {
$this->settings->delete( $slug );
}

/**
* The sync queue manager.
*
* @var \Cloudinary\Sync\Sync_Queue $queue
*/
$queue = $this->plugin->get_component( 'sync' )->managers['queue'];
$all_threads = $queue->get_threads( 'all' );
foreach ( $all_threads as $threads ) {
Expand Down
16 changes: 11 additions & 5 deletions php/class-delivery.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ function ( $post ) {
/**
* Determine if attributes should be added to image tags.
*
* @param WP_REST_Response $response The response object.
* @param WP_REST_Server $handler The request handler.
* @param WP_REST_Request|null $request The request object, if available.
* @param \WP_REST_Response $response The response object.
* @param \WP_REST_Server $handler The request handler.
* @param \WP_REST_Request|null $request The request object, if available.
*
* @return WP_REST_Response
* @return \WP_REST_Response
*/
public function maybe_unset_attributes( $response, $handler, $request ) {
$route = $request->get_route();
Expand Down Expand Up @@ -2110,7 +2110,13 @@ public function catch_urls( $content, $context = 'view' ) {

// Check if we are saving. If so, bail.
// This is to prevent the replacement from happening in the shutdown, signaling content changes in the editor.
if ( $this->plugin->get_component( 'replace' )->doing_save() ) {
/**
* The string replace component.
*
* @var \Cloudinary\String_Replace $replace
*/
$replace = $this->plugin->get_component( 'replace' );
if ( $replace->doing_save() ) {
return;
}
$this->init_delivery();
Expand Down
Loading
Loading