/** * Prints the theme WordPress.org slug. * * @since 1.0.0 * @access public * @param int $theme_id * @return void */ function thds_theme_wporg_slug($theme_id = 0) { echo thds_get_theme_wporg_slug($theme_id); }
/** * Gets the URL for the theme's tickets on the Themes Trac. * * @since 1.0.0 * @access public * @param int $theme_id * @return string */ function thds_get_wporg_theme_tickets_url($theme_id = 0) { $theme_id = thds_get_theme_id($theme_id); $slug = thds_get_theme_wporg_slug($theme_id); $url = $slug ? "https://themes.trac.wordpress.org/query?keywords=theme-{$slug}" : ''; return apply_filters('thds_get_wporg_tickets_url', $url, $theme_id); }
/** * Register a new theme object * * @since 1.0.0 * @access public * @param string $slug * @return void */ public function __construct($theme_id) { // Get the theme's WordPress.org slug. $slug = thds_get_theme_wporg_slug($theme_id); // Bail if there's no slug. if (!$slug) { return; } // Get the transient based on the theme slug. $api = get_transient("thds_wporg_{$slug}"); // If there's no transient, we need to get the data from the WP Themes API. if (!$api) { // If `themes_api()` isn't available, load the file that holds the function if (!function_exists('themes_api') && file_exists(trailingslashit(ABSPATH) . 'wp-admin/includes/theme.php')) { require_once trailingslashit(ABSPATH) . 'wp-admin/includes/theme.php'; } // Make sure the function exists. if (function_exists('themes_api')) { // Get the theme info from WordPress.org. $api = themes_api('theme_information', array('slug' => $slug)); // If no error, let's roll. if (!is_wp_error($api)) { // If this is an array, let's make it an object. if (is_array($api)) { $api = (object) $api; } // Only proceed if we have an object. if (is_object($api)) { // Set the transient with the new data. set_transient("thds_wporg_{$slug}", $api, thds_get_wporg_transient_expiration()); // Back up download count as post meta. if (isset($api->downloaded)) { thds_set_theme_meta($theme_id, 'download_count', absint($api->downloaded)); } // Back up ratings as post meta. if (isset($api->rating) && isset($api->num_ratings)) { $rating = round(absint($api->rating) / 100 * 5, 2); thds_set_theme_meta($theme_id, 'rating', $rating); thds_set_theme_meta($theme_id, 'rating_count', absint($api->num_ratings)); } } } } } // If we have data, let's assign its keys to our theme object properties. if ($api && is_object($api) && !is_wp_error($api)) { foreach ($api as $key => $value) { $this->args[$key] = $value; } } }