| @@ -36,11 +36,11 @@ | ||
| 36 | 36 | * |
| 37 | 37 | * @access public |
| 38 | 38 | * @static |
| 39 | 39 | * |
| 40 | - * @var string API info URL. (v2 excludes the Library info) | |
| 40 | + * @var string API info URL. | |
| 41 | 41 | */ |
| 42 | - public static $api_info_url = 'https://my.elementor.com/api/v2/info/'; | |
| 42 | + public static $api_info_url = 'https://my.elementor.com/api/v1/info/'; | |
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | * API feedback URL. |
| 46 | 46 | * |
| @@ -52,16 +52,28 @@ | ||
| 52 | 52 | * @var string API feedback URL. |
| 53 | 53 | */ |
| 54 | 54 | private static $api_feedback_url = 'https://my.elementor.com/api/v1/feedback/'; |
| 55 | 55 | |
| 56 | - private static $api_library_info_url = 'https://my.elementor.com/api/v1/templates/info/'; | |
| 57 | - | |
| 58 | - private static function get_info_data( $force_update = false, $additional_status = false ) { | |
| 56 | + /** | |
| 57 | + * Get info data. | |
| 58 | + * | |
| 59 | + * This function notifies the user of upgrade notices, new templates and contributors. | |
| 60 | + * | |
| 61 | + * @since 2.0.0 | |
| 62 | + * @access private | |
| 63 | + * @static | |
| 64 | + * | |
| 65 | + * @param bool $force_update Optional. Whether to force the data retrieval or | |
| 66 | + * not. Default is false. | |
| 67 | + * | |
| 68 | + * @return array|false Info data, or false. | |
| 69 | + */ | |
| 70 | + private static function get_info_data( $force_update = false ) { | |
| 59 | 71 | $cache_key = self::TRANSIENT_KEY_PREFIX . ELEMENTOR_VERSION; |
| 60 | 72 | |
| 61 | 73 | $info_data = get_transient( $cache_key ); |
| 62 | 74 | |
| 63 | - if ( $force_update || empty( $info_data ) ) { | |
| 75 | + if ( $force_update || false === $info_data ) { | |
| 64 | 76 | $timeout = ( $force_update ) ? 25 : 8; |
| 65 | 77 | |
| 66 | 78 | $body_request = [ |
| 67 | 79 | // Which API version is used. |
| @@ -74,13 +86,8 @@ | ||
| 74 | 86 | if ( ! empty( $site_key ) ) { |
| 75 | 87 | $body_request['site_key'] = $site_key; |
| 76 | 88 | } |
| 77 | 89 | |
| 78 | - if ( ! empty( $additional_status ) ) { | |
| 79 | - $body_request['status'] = $additional_status; | |
| 80 | - $timeout = 3; | |
| 81 | - } | |
| 82 | - | |
| 83 | 90 | $response = wp_remote_get( self::$api_info_url, [ |
| 84 | 91 | 'timeout' => $timeout, |
| 85 | 92 | 'body' => $body_request, |
| 86 | 93 | ] ); |
| @@ -85,9 +92,9 @@ | ||
| 85 | 92 | 'body' => $body_request, |
| 86 | 93 | ] ); |
| 87 | 94 | |
| 88 | 95 | if ( is_wp_error( $response ) || 200 !== (int) wp_remote_retrieve_response_code( $response ) ) { |
| 89 | - set_transient( $cache_key, [ 'last_error' => gmdate( 'c' ) ], 2 * HOUR_IN_SECONDS ); | |
| 96 | + set_transient( $cache_key, [], 2 * HOUR_IN_SECONDS ); | |
| 90 | 97 | |
| 91 | 98 | return false; |
| 92 | 99 | } |
| 93 | 100 | |
| @@ -93,14 +100,16 @@ | ||
| 93 | 100 | |
| 94 | 101 | $info_data = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 95 | 102 | |
| 96 | 103 | if ( empty( $info_data ) || ! is_array( $info_data ) ) { |
| 97 | - set_transient( $cache_key, [ 'last_error' => gmdate( 'c' ) ], 2 * HOUR_IN_SECONDS ); | |
| 104 | + set_transient( $cache_key, [], 2 * HOUR_IN_SECONDS ); | |
| 98 | 105 | |
| 99 | 106 | return false; |
| 100 | 107 | } |
| 101 | 108 | |
| 102 | 109 | if ( isset( $info_data['library'] ) ) { |
| 110 | + update_option( self::LIBRARY_OPTION_KEY, $info_data['library'], 'no' ); | |
| 111 | + | |
| 103 | 112 | unset( $info_data['library'] ); |
| 104 | 113 | } |
| 105 | 114 | |
| 106 | 115 | if ( isset( $info_data['feed'] ) ) { |
| @@ -115,13 +124,9 @@ | ||
| 115 | 124 | return $info_data; |
| 116 | 125 | } |
| 117 | 126 | |
| 118 | 127 | public static function get_site_key() { |
| 119 | - if ( null === Plugin::$instance->common ) { | |
| 120 | - return get_option( Library::OPTION_CONNECT_SITE_KEY ); | |
| 121 | - } | |
| 122 | - | |
| 123 | - /** @var Library $library */ | |
| 128 | + /** @var \Elementor\Core\Common\Modules\Connect\Apps\Library $library */ | |
| 124 | 129 | $library = Plugin::$instance->common->get_component( 'connect' )->get_app( 'library' ); |
| 125 | 130 | |
| 126 | 131 | if ( ! $library || ! method_exists( $library, 'get_site_key' ) ) { |
| 127 | 132 | return false; |
| @@ -190,57 +195,20 @@ | ||
| 190 | 195 | * |
| 191 | 196 | * @param bool $force_update Optional. Whether to force the data update or |
| 192 | 197 | * not. Default is false. |
| 193 | 198 | * |
| 194 | - * @return array The templates' data. | |
| 199 | + * @return array The templates data. | |
| 195 | 200 | */ |
| 196 | - public static function get_library_data( bool $force_update = false ): array { | |
| 197 | - /** | |
| 198 | - * Filters the body of the request to get library templates data. | |
| 199 | - * | |
| 200 | - * @param-out array $body_request The body of the request. | |
| 201 | - */ | |
| 202 | - $body_request = apply_filters( 'elementor/remote/library/templates/request/body', [] ); | |
| 201 | + public static function get_library_data( $force_update = false ) { | |
| 202 | + self::get_info_data( $force_update ); | |
| 203 | 203 | |
| 204 | - $site_key = self::get_site_key(); | |
| 205 | - if ( ! empty( $site_key ) ) { | |
| 206 | - $body_request['site_key'] = $site_key; | |
| 207 | - } | |
| 204 | + $library_data = get_option( self::LIBRARY_OPTION_KEY ); | |
| 208 | 205 | |
| 209 | - /** | |
| 210 | - * Filters the URL to get library templates data. | |
| 211 | - * | |
| 212 | - * @param-out string $url The URL to get library templates data. | |
| 213 | - */ | |
| 214 | - $url = apply_filters( 'elementor/remote/library/templates/request/url', self::$api_library_info_url ); | |
| 215 | - | |
| 216 | - $response = wp_remote_get( $url, [ | |
| 217 | - 'timeout' => 25, | |
| 218 | - 'body' => $body_request, | |
| 219 | - ] ); | |
| 220 | - | |
| 221 | - if ( is_wp_error( $response ) || 200 !== (int) wp_remote_retrieve_response_code( $response ) ) { | |
| 206 | + if ( empty( $library_data ) ) { | |
| 222 | 207 | return []; |
| 223 | 208 | } |
| 224 | 209 | |
| 225 | - $library_data = json_decode( wp_remote_retrieve_body( $response ), true ); | |
| 226 | - | |
| 227 | - /** | |
| 228 | - * Filters the library data to allow 3rd party extending the response data. | |
| 229 | - * | |
| 230 | - * @since 3.32.2 | |
| 231 | - * @param-out array $library_data an array of templates data. | |
| 232 | - */ | |
| 233 | - $library_data = apply_filters( 'elementor/remote/library/data', $library_data ); | |
| 234 | - | |
| 235 | - if ( empty( $library_data ) || ! is_array( $library_data ) ) { | |
| 236 | - return []; | |
| 237 | - } | |
| 238 | - | |
| 239 | - // the following update & get are a temporary measure, to allow 3rd party plugins inject more templates: | |
| 240 | - update_option( self::LIBRARY_OPTION_KEY, $library_data, 'no' ); | |
| 241 | - | |
| 242 | - return get_option( self::LIBRARY_OPTION_KEY, $library_data ); | |
| 210 | + return $library_data; | |
| 243 | 211 | } |
| 244 | 212 | |
| 245 | 213 | /** |
| 246 | 214 | * Get feed data. |
| @@ -265,28 +233,8 @@ | ||
| 265 | 233 | return []; |
| 266 | 234 | } |
| 267 | 235 | |
| 268 | 236 | return $feed; |
| 269 | - } | |
| 270 | - | |
| 271 | - public static function get_deactivation_data() { | |
| 272 | - $data = self::get_info_data( true, 'deactivated' ); | |
| 273 | - | |
| 274 | - if ( empty( $data['deactivate_data'] ) ) { | |
| 275 | - return false; | |
| 276 | - } | |
| 277 | - | |
| 278 | - return $data['deactivate_data']; | |
| 279 | - } | |
| 280 | - | |
| 281 | - public static function get_uninstalled_data() { | |
| 282 | - $data = self::get_info_data( true, 'uninstalled' ); | |
| 283 | - | |
| 284 | - if ( empty( $data['uninstall_data'] ) ) { | |
| 285 | - return false; | |
| 286 | - } | |
| 287 | - | |
| 288 | - return $data['uninstall_data']; | |
| 289 | 237 | } |
| 290 | 238 | |
| 291 | 239 | /** |
| 292 | 240 | * Get template content. |