Skip to content

Commit 63bbf8d

Browse files
committed
Enable the update_asset_paths in the admin area
1 parent 8eb3d4d commit 63bbf8d

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

php/class-assets.php

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,15 +388,33 @@ public function connect_post_type( $query ) {
388388
return $query;
389389
}
390390

391+
/**
392+
* Retrieve the assets settings.
393+
*
394+
* This method fetches the assets settings from the configuration.
395+
* If the assets settings are empty or the settings are locked, it returns an empty array.
396+
*
397+
* @return array The assets settings array.
398+
*/
399+
public function get_assets_settings() {
400+
$assets = $this->settings->get_setting( 'assets' )->get_settings();
401+
402+
if ( empty( $assets ) || $this->is_locked() ) {
403+
return array();
404+
}
405+
406+
return $assets;
407+
}
408+
391409
/**
392410
* Update asset paths.
393411
*
394412
* @return void
395413
*/
396414
public function update_asset_paths() {
397-
$assets = $this->settings->get_setting( 'assets' )->get_settings();
415+
$assets = $this->get_assets_settings();
398416

399-
if ( empty( $assets ) || ! $this->is_locked() ) {
417+
if ( empty( $assets ) ) {
400418
return;
401419
}
402420

@@ -411,10 +429,12 @@ public function update_asset_paths() {
411429
$asset_path = $this->get_asset_parent( $path );
412430

413431
if ( null === $asset_path ) {
414-
$asset_parent_id = $assets->create_asset_parent( $path, $version );
432+
$asset_parent_id = $this->create_asset_parent( $path, $version );
433+
415434
if ( is_wp_error( $asset_parent_id ) ) {
416435
return; // Bail.
417436
}
437+
418438
$asset_path = get_post( $asset_parent_id );
419439
}
420440

@@ -433,9 +453,9 @@ public function update_asset_paths() {
433453
* @return void
434454
*/
435455
protected function activate_parents() {
436-
$assets = $this->settings->get_setting( 'assets' )->get_settings();
456+
$assets = $this->get_assets_settings();
437457

438-
if ( empty( $assets ) || $this->is_locked() ) {
458+
if ( empty( $assets ) ) {
439459
return;
440460
}
441461

@@ -1204,8 +1224,12 @@ protected function register_post_type() {
12041224
* @hook cloudinary_init_settings
12051225
*/
12061226
public function setup() {
1227+
if ( is_user_logged_in() && is_admin() && ! Utils::is_rest_api() ) {
1228+
$this->update_asset_paths();
1229+
}
1230+
1231+
Cron::register_process( 'update_asset_paths', array( $this, 'update_asset_paths' ), DAY_IN_SECONDS );
12071232
$this->activate_parents();
1208-
Cron::register_process( 'update_asset_paths', array( $this, 'update_asset_paths' ), 60 );
12091233
}
12101234

12111235
/**

0 commit comments

Comments
 (0)