| @@ -26,10 +26,8 @@ | ||
| 26 | 26 | * Elementor feed option key. |
| 27 | 27 | */ |
| 28 | 28 | const FEED_OPTION_KEY = 'elementor_remote_info_feed_data'; |
| 29 | 29 | |
| 30 | - const TRANSIENT_KEY_PREFIX = 'elementor_remote_info_api_data_'; | |
| 31 | - | |
| 32 | 30 | /** |
| 33 | 31 | * API info URL. |
| 34 | 32 | * |
| 35 | 33 | * Holds the URL of the info API. |
| @@ -36,11 +34,11 @@ | ||
| 36 | 34 | * |
| 37 | 35 | * @access public |
| 38 | 36 | * @static |
| 39 | 37 | * |
| 40 | - * @var string API info URL. (v2 excludes the Library info) | |
| 38 | + * @var string API info URL. | |
| 41 | 39 | */ |
| 42 | - public static $api_info_url = 'https://my.elementor.com/api/v2/info/'; | |
| 40 | + public static $api_info_url = 'https://my.elementor.com/api/v1/info/'; | |
| 43 | 41 | |
| 44 | 42 | /** |
| 45 | 43 | * API feedback URL. |
| 46 | 44 | * |
| @@ -52,42 +50,42 @@ | ||
| 52 | 50 | * @var string API feedback URL. |
| 53 | 51 | */ |
| 54 | 52 | private static $api_feedback_url = 'https://my.elementor.com/api/v1/feedback/'; |
| 55 | 53 | |
| 56 | - private static $api_library_info_url = 'https://my.elementor.com/api/v1/templates/info/'; | |
| 54 | + /** | |
| 55 | + * Get info data. | |
| 56 | + * | |
| 57 | + * This function notifies the user of upgrade notices, new templates and contributors. | |
| 58 | + * | |
| 59 | + * @since 2.0.0 | |
| 60 | + * @access private | |
| 61 | + * @static | |
| 62 | + * | |
| 63 | + * @param bool $force_update Optional. Whether to force the data retrieval or | |
| 64 | + * not. Default is false. | |
| 65 | + * | |
| 66 | + * @return array|false Info data, or false. | |
| 67 | + */ | |
| 68 | + private static function get_info_data( $force_update = false ) { | |
| 69 | + $cache_key = 'elementor_remote_info_api_data_' . ELEMENTOR_VERSION; | |
| 57 | 70 | |
| 58 | - private static function get_info_data( $force_update = false, $additional_status = false ) { | |
| 59 | - $cache_key = self::TRANSIENT_KEY_PREFIX . ELEMENTOR_VERSION; | |
| 60 | - | |
| 61 | 71 | $info_data = get_transient( $cache_key ); |
| 62 | 72 | |
| 63 | - if ( $force_update || empty( $info_data ) ) { | |
| 73 | + if ( $force_update || false === $info_data ) { | |
| 64 | 74 | $timeout = ( $force_update ) ? 25 : 8; |
| 65 | 75 | |
| 66 | - $body_request = [ | |
| 67 | - // Which API version is used. | |
| 68 | - 'api_version' => ELEMENTOR_VERSION, | |
| 69 | - // Which language to return. | |
| 70 | - 'site_lang' => get_bloginfo( 'language' ), | |
| 71 | - ]; | |
| 72 | - | |
| 73 | - $site_key = self::get_site_key(); | |
| 74 | - if ( ! empty( $site_key ) ) { | |
| 75 | - $body_request['site_key'] = $site_key; | |
| 76 | - } | |
| 77 | - | |
| 78 | - if ( ! empty( $additional_status ) ) { | |
| 79 | - $body_request['status'] = $additional_status; | |
| 80 | - $timeout = 3; | |
| 81 | - } | |
| 82 | - | |
| 83 | 76 | $response = wp_remote_get( self::$api_info_url, [ |
| 84 | 77 | 'timeout' => $timeout, |
| 85 | - 'body' => $body_request, | |
| 78 | + 'body' => [ | |
| 79 | + // Which API version is used. | |
| 80 | + 'api_version' => ELEMENTOR_VERSION, | |
| 81 | + // Which language to return. | |
| 82 | + 'site_lang' => get_bloginfo( 'language' ), | |
| 83 | + ], | |
| 86 | 84 | ] ); |
| 87 | 85 | |
| 88 | 86 | 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 ); | |
| 87 | + set_transient( $cache_key, [], 2 * HOUR_IN_SECONDS ); | |
| 90 | 88 | |
| 91 | 89 | return false; |
| 92 | 90 | } |
| 93 | 91 | |
| @@ -93,14 +91,16 @@ | ||
| 93 | 91 | |
| 94 | 92 | $info_data = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 95 | 93 | |
| 96 | 94 | if ( empty( $info_data ) || ! is_array( $info_data ) ) { |
| 97 | - set_transient( $cache_key, [ 'last_error' => gmdate( 'c' ) ], 2 * HOUR_IN_SECONDS ); | |
| 95 | + set_transient( $cache_key, [], 2 * HOUR_IN_SECONDS ); | |
| 98 | 96 | |
| 99 | 97 | return false; |
| 100 | 98 | } |
| 101 | 99 | |
| 102 | 100 | if ( isset( $info_data['library'] ) ) { |
| 101 | + update_option( self::LIBRARY_OPTION_KEY, $info_data['library'], 'no' ); | |
| 102 | + | |
| 103 | 103 | unset( $info_data['library'] ); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | if ( isset( $info_data['feed'] ) ) { |
| @@ -114,23 +114,8 @@ | ||
| 114 | 114 | |
| 115 | 115 | return $info_data; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - 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 */ | |
| 124 | - $library = Plugin::$instance->common->get_component( 'connect' )->get_app( 'library' ); | |
| 125 | - | |
| 126 | - if ( ! $library || ! method_exists( $library, 'get_site_key' ) ) { | |
| 127 | - return false; | |
| 128 | - } | |
| 129 | - | |
| 130 | - return $library->get_site_key(); | |
| 131 | - } | |
| 132 | - | |
| 133 | 118 | /** |
| 134 | 119 | * Get upgrade notice. |
| 135 | 120 | * |
| 136 | 121 | * Retrieve the upgrade notice if one exists, or false otherwise. |
| @@ -171,12 +156,8 @@ | ||
| 171 | 156 | |
| 172 | 157 | public static function get_promotion_widgets() { |
| 173 | 158 | $data = self::get_info_data(); |
| 174 | 159 | |
| 175 | - if ( ! isset( $data['pro_widgets'] ) ) { | |
| 176 | - $data['pro_widgets'] = []; | |
| 177 | - } | |
| 178 | - | |
| 179 | 160 | return $data['pro_widgets']; |
| 180 | 161 | } |
| 181 | 162 | |
| 182 | 163 | /** |
| @@ -190,57 +171,20 @@ | ||
| 190 | 171 | * |
| 191 | 172 | * @param bool $force_update Optional. Whether to force the data update or |
| 192 | 173 | * not. Default is false. |
| 193 | 174 | * |
| 194 | - * @return array The templates' data. | |
| 175 | + * @return array The templates data. | |
| 195 | 176 | */ |
| 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', [] ); | |
| 177 | + public static function get_library_data( $force_update = false ) { | |
| 178 | + self::get_info_data( $force_update ); | |
| 203 | 179 | |
| 204 | - $site_key = self::get_site_key(); | |
| 205 | - if ( ! empty( $site_key ) ) { | |
| 206 | - $body_request['site_key'] = $site_key; | |
| 207 | - } | |
| 180 | + $library_data = get_option( self::LIBRARY_OPTION_KEY ); | |
| 208 | 181 | |
| 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 ) ) { | |
| 182 | + if ( empty( $library_data ) ) { | |
| 222 | 183 | return []; |
| 223 | 184 | } |
| 224 | 185 | |
| 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 ); | |
| 186 | + return $library_data; | |
| 243 | 187 | } |
| 244 | 188 | |
| 245 | 189 | /** |
| 246 | 190 | * Get feed data. |
| @@ -267,28 +211,8 @@ | ||
| 267 | 211 | |
| 268 | 212 | return $feed; |
| 269 | 213 | } |
| 270 | 214 | |
| 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 | - } | |
| 290 | - | |
| 291 | 215 | /** |
| 292 | 216 | * Get template content. |
| 293 | 217 | * |
| 294 | 218 | * Retrieve the templates content received from a remote server. |
| @@ -344,12 +268,8 @@ | ||
| 344 | 268 | * @static |
| 345 | 269 | */ |
| 346 | 270 | public static function ajax_reset_api_data() { |
| 347 | 271 | check_ajax_referer( 'elementor_reset_library', '_nonce' ); |
| 348 | - | |
| 349 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 350 | - wp_send_json_error( 'Permission denied' ); | |
| 351 | - } | |
| 352 | 272 | |
| 353 | 273 | self::get_info_data( true ); |
| 354 | 274 | |
| 355 | 275 | wp_send_json_success(); |