PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-admin/includes/theme.php

http://cartonbank.googlecode.com/
PHP | 253 lines | 146 code | 37 blank | 70 comment | 32 complexity | 12cb3693340cc7742eb649c4ebf06b02 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, LGPL-2.1, AGPL-1.0, LGPL-3.0
  1. <?php
  2. /**
  3. * WordPress Theme Administration API
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /**
  9. * {@internal Missing Short Description}}
  10. *
  11. * @since unknown
  12. *
  13. * @return unknown
  14. */
  15. function current_theme_info() {
  16. $themes = get_themes();
  17. $current_theme = get_current_theme();
  18. if ( ! isset( $themes[$current_theme] ) ) {
  19. delete_option( 'current_theme' );
  20. $current_theme = get_current_theme();
  21. }
  22. $ct->name = $current_theme;
  23. $ct->title = $themes[$current_theme]['Title'];
  24. $ct->version = $themes[$current_theme]['Version'];
  25. $ct->parent_theme = $themes[$current_theme]['Parent Theme'];
  26. $ct->template_dir = $themes[$current_theme]['Template Dir'];
  27. $ct->stylesheet_dir = $themes[$current_theme]['Stylesheet Dir'];
  28. $ct->template = $themes[$current_theme]['Template'];
  29. $ct->stylesheet = $themes[$current_theme]['Stylesheet'];
  30. $ct->screenshot = $themes[$current_theme]['Screenshot'];
  31. $ct->description = $themes[$current_theme]['Description'];
  32. $ct->author = $themes[$current_theme]['Author'];
  33. $ct->tags = $themes[$current_theme]['Tags'];
  34. $ct->theme_root = $themes[$current_theme]['Theme Root'];
  35. $ct->theme_root_uri = $themes[$current_theme]['Theme Root URI'];
  36. return $ct;
  37. }
  38. /**
  39. * Remove a theme
  40. *
  41. * @since 2.8.0
  42. *
  43. * @param string $template Template directory of the theme to delete
  44. * @return mixed
  45. */
  46. function delete_theme($template) {
  47. global $wp_filesystem;
  48. if ( empty($template) )
  49. return false;
  50. ob_start();
  51. $url = wp_nonce_url('themes.php?action=delete&template=' . $template, 'delete-theme_' . $template);
  52. if ( false === ($credentials = request_filesystem_credentials($url)) ) {
  53. $data = ob_get_contents();
  54. ob_end_clean();
  55. if ( ! empty($data) ){
  56. include_once( ABSPATH . 'wp-admin/admin-header.php');
  57. echo $data;
  58. include( ABSPATH . 'wp-admin/admin-footer.php');
  59. exit;
  60. }
  61. return;
  62. }
  63. if ( ! WP_Filesystem($credentials) ) {
  64. request_filesystem_credentials($url, '', true); // Failed to connect, Error and request again
  65. $data = ob_get_contents();
  66. ob_end_clean();
  67. if ( ! empty($data) ) {
  68. include_once( ABSPATH . 'wp-admin/admin-header.php');
  69. echo $data;
  70. include( ABSPATH . 'wp-admin/admin-footer.php');
  71. exit;
  72. }
  73. return;
  74. }
  75. if ( ! is_object($wp_filesystem) )
  76. return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
  77. if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
  78. return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
  79. //Get the base plugin folder
  80. $themes_dir = $wp_filesystem->wp_themes_dir();
  81. if ( empty($themes_dir) )
  82. return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress theme directory.'));
  83. $themes_dir = trailingslashit( $themes_dir );
  84. $theme_dir = trailingslashit($themes_dir . $template);
  85. $deleted = $wp_filesystem->delete($theme_dir, true);
  86. if ( ! $deleted )
  87. return new WP_Error('could_not_remove_theme', sprintf(__('Could not fully remove the theme %s.'), $template) );
  88. // Force refresh of theme update information
  89. delete_site_transient('update_themes');
  90. return true;
  91. }
  92. /**
  93. * {@internal Missing Short Description}}
  94. *
  95. * @since unknown
  96. *
  97. * @return unknown
  98. */
  99. function get_broken_themes() {
  100. global $wp_broken_themes;
  101. get_themes();
  102. return $wp_broken_themes;
  103. }
  104. /**
  105. * Get the allowed themes for the current blog.
  106. *
  107. * @since 3.0.0
  108. *
  109. * @uses get_themes()
  110. * @uses current_theme_info()
  111. * @uses get_site_allowed_themes()
  112. * @uses wpmu_get_blog_allowedthemes
  113. *
  114. * @return array $themes Array of allowed themes.
  115. */
  116. function get_allowed_themes() {
  117. if ( !is_multisite() )
  118. return get_themes();
  119. $themes = get_themes();
  120. $ct = current_theme_info();
  121. $allowed_themes = apply_filters("allowed_themes", get_site_allowed_themes() );
  122. if ( $allowed_themes == false )
  123. $allowed_themes = array();
  124. $blog_allowed_themes = wpmu_get_blog_allowedthemes();
  125. if ( is_array( $blog_allowed_themes ) )
  126. $allowed_themes = array_merge( $allowed_themes, $blog_allowed_themes );
  127. if ( isset( $allowed_themes[ esc_html( $ct->stylesheet ) ] ) == false )
  128. $allowed_themes[ esc_html( $ct->stylesheet ) ] = true;
  129. reset( $themes );
  130. foreach ( $themes as $key => $theme ) {
  131. if ( isset( $allowed_themes[ esc_html( $theme[ 'Stylesheet' ] ) ] ) == false )
  132. unset( $themes[ $key ] );
  133. }
  134. reset( $themes );
  135. return $themes;
  136. }
  137. /**
  138. * Get the Page Templates available in this theme
  139. *
  140. * @since unknown
  141. *
  142. * @return array Key is template name, Value is template name
  143. */
  144. function get_page_templates() {
  145. $themes = get_themes();
  146. $theme = get_current_theme();
  147. $templates = $themes[$theme]['Template Files'];
  148. $page_templates = array();
  149. if ( is_array( $templates ) ) {
  150. $base = array( trailingslashit(get_template_directory()), trailingslashit(get_stylesheet_directory()) );
  151. foreach ( $templates as $template ) {
  152. $basename = str_replace($base, '', $template);
  153. // don't allow template files in subdirectories
  154. if ( false !== strpos($basename, '/') )
  155. continue;
  156. $template_data = implode( '', file( $template ));
  157. $name = '';
  158. if ( preg_match( '|Template Name:(.*)$|mi', $template_data, $name ) )
  159. $name = _cleanup_header_comment($name[1]);
  160. if ( !empty( $name ) ) {
  161. $page_templates[trim( $name )] = $basename;
  162. }
  163. }
  164. }
  165. return $page_templates;
  166. }
  167. /**
  168. * Tidies a filename for url display by the theme editor.
  169. *
  170. * @since 2.9.0
  171. * @access private
  172. *
  173. * @param string $fullpath Full path to the theme file
  174. * @param string $containingfolder Path of the theme parent folder
  175. * @return string
  176. */
  177. function _get_template_edit_filename($fullpath, $containingfolder) {
  178. return str_replace(dirname(dirname( $containingfolder )) , '', $fullpath);
  179. }
  180. /**
  181. * Check if there is an update for a theme available.
  182. *
  183. * Will display link, if there is an update available.
  184. *
  185. * @since 2.7.0
  186. *
  187. * @param object $theme Theme data object.
  188. * @return bool False if no valid info was passed.
  189. */
  190. function theme_update_available( $theme ) {
  191. static $themes_update;
  192. if ( !current_user_can('update_themes' ) )
  193. return;
  194. if ( !isset($themes_update) )
  195. $themes_update = get_site_transient('update_themes');
  196. if ( is_object($theme) && isset($theme->stylesheet) )
  197. $stylesheet = $theme->stylesheet;
  198. elseif ( is_array($theme) && isset($theme['Stylesheet']) )
  199. $stylesheet = $theme['Stylesheet'];
  200. else
  201. return false; //No valid info passed.
  202. if ( isset($themes_update->response[ $stylesheet ]) ) {
  203. $update = $themes_update->response[ $stylesheet ];
  204. $theme_name = is_object($theme) ? $theme->name : (is_array($theme) ? $theme['Name'] : '');
  205. $details_url = add_query_arg(array('TB_iframe' => 'true', 'width' => 1024, 'height' => 800), $update['url']); //Theme browser inside WP? replace this, Also, theme preview JS will override this on the available list.
  206. $update_url = wp_nonce_url('update.php?action=upgrade-theme&amp;theme=' . urlencode($stylesheet), 'upgrade-theme_' . $stylesheet);
  207. $update_onclick = 'onclick="if ( confirm(\'' . esc_js( __("Upgrading this theme will lose any customizations you have made. 'Cancel' to stop, 'OK' to upgrade.") ) . '\') ) {return true;}return false;"';
  208. if ( ! current_user_can('update_themes') )
  209. printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
  210. else if ( empty($update['package']) )
  211. printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a> <em>automatic upgrade unavailable for this theme</em>.') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
  212. else
  213. printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a> or <a href="%4$s" %5$s>upgrade automatically</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version'], $update_url, $update_onclick );
  214. }
  215. }
  216. ?>