/** * @return string url */ function download_url($theme_name, $allow_cache = true) { if (empty($theme_name)) { $theme_temp = wp_get_theme(); $theme_name = $theme_temp->Name; } $installed_theme = $this->retrieve_installed_theme($theme_name); if ($installed_theme == null) { $transalated_message = __('The theme <b>:theme_name</b> is not installed.<br><i>If you are certain the theme it is installed, please contact support.</i>', 'rosa_txtd'); $this->errors = array(strtr($transalated_message, array(':theme_name' => $theme_name))); return null; } ob_start(); $purchased_themes = $this->api->wp_list_themes($allow_cache); $errors = $this->api->api_errors(); $internal_errors = ob_get_clean(); if (!empty($internal_errors) || $purchased_themes === false) { $transalated_message = __('TeamForest/Envato API error.', 'rosa_txtd'); $this->errors = array($transalated_message); return null; } if ($errors !== null) { $this->errors = array(__('Failed to retrieve theme list via Envato API.', 'rosa_txtd')); return null; } $marketplace_theme_data = null; foreach ($purchased_themes as $purchased) { if ($this->is_matching_themes($installed_theme, $purchased)) { if ($this->is_newer_version_available($installed_theme['Version'], $purchased->version)) { $marketplace_theme_data = $purchased; break; } else { // no new version available $transalated_message = __('There is no update available for the theme <b>:theme_name</b>', 'rosa_txtd'); $this->errors = array(strtr($transalated_message, array(':theme_name' => $theme_name))); return null; } } } if ($marketplace_theme_data == null) { $transalated_message = __('Failed to find <b>:theme_name</b> in your list of purchased themes. (please contact support)', 'rosa_txtd'); $this->errors = array(strtr($transalated_message, array(':theme_name' => $theme_name))); return null; } $result = $this->api->wp_download($marketplace_theme_data->item_id); if (is_array($result)) { $this->errors = $result; return null; } return $result; }