PageRenderTime 44ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/inc/update.php

https://github.com/envex/Micro-Theme
PHP | 88 lines | 31 code | 13 blank | 44 comment | 7 complexity | 2dd870873ed745a810e8e83bdd295eb0 MD5 | raw file
  1. <?php
  2. /**
  3. * Theme Update Functions file
  4. *
  5. * The /inc/update.php file includes
  6. * the Theme's automatic update functions
  7. *
  8. * @link http://codex.wordpress.org/Function_Reference/add_filter add_filter()
  9. * @link http://codex.wordpress.org/Function_Reference/is_admin is_admin()
  10. * @link http://codex.wordpress.org/Function_Reference/get_transient get_transient()
  11. *
  12. * @package Micro
  13. * @copyright Copyright (c) 2011, UpThemes
  14. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License, v2 (or newer)
  15. *
  16. * @since Micro 1.0
  17. */
  18. /**
  19. * Check For Micro Theme Updates
  20. *
  21. * This function uses the UpThemes API to determine
  22. * if a Micro Theme update is available, in order
  23. * to hook into the WordPress core Theme update
  24. * functionality.
  25. *
  26. * @link http://codex.wordpress.org/Function_Reference/get_theme_data get_theme_data()
  27. * @link http://codex.wordpress.org/Function_Reference/get_stylesheet_uri get_stylesheet_uri()
  28. * @link http://codex.wordpress.org/Function_Reference/get_bloginfo get_bloginfo()
  29. * @link http://codex.wordpress.org/Function_Reference/wp_remote_post wp_remote_post()
  30. * @link http://codex.wordpress.org/Function_Reference/is_wp_error is_wp_error()
  31. *
  32. * @link http://php.net/manual/en/function.basename.php basename()
  33. * @link http://php.net/manual/en/function.dirname.php dirname()
  34. * @link http://php.net/manual/en/function.empty.php empty()
  35. *
  36. * @param object $checked_data (required) Transient theme update data
  37. * @return object Filtered transient theme update data
  38. *
  39. * @since Micro 1.0
  40. *
  41. */
  42. function micro_check_for_update($checked_data) {
  43. global $wp_version,$up_options;
  44. if (empty($checked_data->last_checked) && empty($up_options->api_key))
  45. return $checked_data;
  46. $api_url = 'http://upthemes.com/api/';
  47. $theme_base = basename(dirname(dirname(__FILE__)));
  48. $theme_data = get_theme_data(get_stylesheet_uri());
  49. $request = array(
  50. 'slug' => THEME_NAME,
  51. 'version' => $theme_data['Version']
  52. );
  53. // Start checking for an update
  54. $send_for_check = array(
  55. 'body' => array(
  56. 'action' => 'theme_update',
  57. 'request' => serialize($request),
  58. 'api-key' => $up_options->api_key
  59. ),
  60. 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')
  61. );
  62. $raw_response = wp_remote_post($api_url, $send_for_check);
  63. if (!is_wp_error($raw_response) && ($raw_response['response']['code'] == 200))
  64. $response = unserialize($raw_response['body']);
  65. // Feed the update data into WP updater
  66. if (!empty($response))
  67. $checked_data->response[$theme_base] = $response;
  68. return $checked_data;
  69. }
  70. // Hook micro_check_for_update() into pre_set_site_transient_update_themes
  71. add_filter( 'pre_set_site_transient_update_themes', 'micro_check_for_update' );
  72. if (is_admin())
  73. $current = get_transient('update_themes');
  74. //set_site_transient('update_themes', null);
  75. ?>