<?php namespace Elementor\Includes; class EditorAssetsAPI { protected array $config; const ASSETS_DATA_TRANSIENT_KEY = 'ASSETS_DATA_TRANSIENT_KEY'; const ASSETS_DATA_URL = 'ASSETS_DATA_URL'; const ASSETS_DATA_KEY = 'ASSETS_DATA_KEY'; public function __construct( array $config ) { $this->config = $config; } public function config( $key ): string { return $this->config[ $key ] ?? ''; } public function get_assets_data( $force_request = false ): array { $assets_data = $this->get_transient( $this->config( static::ASSETS_DATA_TRANSIENT_KEY ) ); if ( $force_request || false === $assets_data ) { $assets_data = $this->fetch_data(); $this->set_transient( $this->config( static::ASSETS_DATA_TRANSIENT_KEY ), $assets_data, '+1 hour' ); } return $assets_data; } private function fetch_data(): array { $response = wp_remote_get( $this->config( static::ASSETS_DATA_URL ) ); if ( is_wp_error( $response ) ) { return []; } $data = json_decode( wp_remote_retrieve_body( $response ), true ); if ( empty( $data[ $this->config( static::ASSETS_DATA_KEY ) ] ) || ! is_array( $data[ $this->config( static::ASSETS_DATA_KEY ) ] ) ) { return []; } return $data[ $this->config( static::ASSETS_DATA_KEY ) ]; } private function get_transient( $cache_key ) { $cache = get_option( $cache_key ); if ( empty( $cache['timeout'] ) ) { return false; } if ( current_time( 'timestamp' ) > $cache['timeout'] ) { return false; } return json_decode( $cache['value'], true ); } private function set_transient( $cache_key, $value, $expiration = '+12 hours' ): bool { $data = [ 'timeout' => strtotime( $expiration, current_time( 'timestamp' ) ), 'value' => wp_json_encode( $value ), ]; return update_option( $cache_key, $data, false ); } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
admin-templates | Folder | 0755 |
|
|
base | Folder | 0755 |
|
|
container | Folder | 0755 |
|
|
controls | Folder | 0755 |
|
|
editor-templates | Folder | 0755 |
|
|
elements | Folder | 0755 |
|
|
interfaces | Folder | 0755 |
|
|
libraries | Folder | 0755 |
|
|
managers | Folder | 0755 |
|
|
settings | Folder | 0755 |
|
|
template-library | Folder | 0755 |
|
|
widgets | Folder | 0755 |
|
|
api.php | File | 7.29 KB | 0644 |
|
autoloader.php | File | 9.4 KB | 0644 |
|
beta-testers.php | File | 2.99 KB | 0644 |
|
compatibility.php | File | 10.95 KB | 0644 |
|
conditions.php | File | 2.7 KB | 0644 |
|
db.php | File | 14.73 KB | 0644 |
|
editor-assets-api.php | File | 1.76 KB | 0644 |
|
embed.php | File | 8.44 KB | 0644 |
|
fonts.php | File | 62.53 KB | 0644 |
|
frontend.php | File | 39.17 KB | 0644 |
|
heartbeat.php | File | 2.57 KB | 0644 |
|
maintenance-mode.php | File | 11.13 KB | 0644 |
|
maintenance.php | File | 2.79 KB | 0644 |
|
plugin.php | File | 16.47 KB | 0644 |
|
preview.php | File | 7.66 KB | 0644 |
|
rollback.php | File | 3.63 KB | 0644 |
|
shapes.php | File | 6.41 KB | 0644 |
|
stylesheet.php | File | 8.91 KB | 0644 |
|
tracker.php | File | 15.68 KB | 0644 |
|
user.php | File | 9.88 KB | 0644 |
|
utils.php | File | 22.99 KB | 0644 |
|