Example #1
0
 /**
  * Saves the value of the setting.
  *
  * @since  1.0.0
  * @access public
  * @return void
  */
 public function save($post_id)
 {
     $old_value = $this->get_value($post_id);
     $new_value = $this->get_posted_value();
     //wp_die( var_dump( $new_value !== $old_value ) );
     // If we have don't have a new value but do have an old one, delete it.
     if (!$new_value && $old_value) {
         thds_delete_theme_meta($post_id, $this->name);
     } else {
         if ($new_value !== $old_value) {
             thds_set_theme_meta($post_id, $this->name, $new_value);
         }
     }
 }
 /**
  * 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;
         }
     }
 }