PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/wordpress3.4.2/wp-admin/network/themes.php

https://bitbucket.org/ch3tag/mothers
PHP | 267 lines | 214 code | 44 blank | 9 comment | 23 complexity | 19d33e1a15005207c5b364a5e0829ee1 MD5 | raw file
  1. <?php
  2. /**
  3. * Multisite themes administration panel.
  4. *
  5. * @package WordPress
  6. * @subpackage Multisite
  7. * @since 3.1.0
  8. */
  9. /** Load WordPress Administration Bootstrap */
  10. require_once( './admin.php' );
  11. if ( ! is_multisite() )
  12. wp_die( __( 'Multisite support is not enabled.' ) );
  13. $menu_perms = get_site_option( 'menu_items', array() );
  14. if ( empty( $menu_perms['themes'] ) && ! is_super_admin() )
  15. wp_die( __( 'Cheatin&#8217; uh?' ) );
  16. if ( !current_user_can('manage_network_themes') )
  17. wp_die( __( 'You do not have sufficient permissions to manage network themes.' ) );
  18. $wp_list_table = _get_list_table('WP_MS_Themes_List_Table');
  19. $pagenum = $wp_list_table->get_pagenum();
  20. $action = $wp_list_table->current_action();
  21. $s = isset($_REQUEST['s']) ? $_REQUEST['s'] : '';
  22. // Clean up request URI from temporary args for screen options/paging uri's to work as expected.
  23. $temp_args = array( 'enabled', 'disabled', 'deleted', 'error' );
  24. $_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI'] );
  25. $referer = remove_query_arg( $temp_args, wp_get_referer() );
  26. if ( $action ) {
  27. $allowed_themes = get_site_option( 'allowedthemes' );
  28. switch ( $action ) {
  29. case 'enable':
  30. check_admin_referer('enable-theme_' . $_GET['theme']);
  31. $allowed_themes[ $_GET['theme'] ] = true;
  32. update_site_option( 'allowedthemes', $allowed_themes );
  33. if ( false === strpos( $referer, '/network/themes.php' ) )
  34. wp_redirect( network_admin_url( 'themes.php?enabled=1' ) );
  35. else
  36. wp_safe_redirect( add_query_arg( 'enabled', 1, $referer ) );
  37. exit;
  38. break;
  39. case 'disable':
  40. check_admin_referer('disable-theme_' . $_GET['theme']);
  41. unset( $allowed_themes[ $_GET['theme'] ] );
  42. update_site_option( 'allowedthemes', $allowed_themes );
  43. wp_safe_redirect( add_query_arg( 'disabled', '1', $referer ) );
  44. exit;
  45. break;
  46. case 'enable-selected':
  47. check_admin_referer('bulk-themes');
  48. $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
  49. if ( empty($themes) ) {
  50. wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
  51. exit;
  52. }
  53. foreach( (array) $themes as $theme )
  54. $allowed_themes[ $theme ] = true;
  55. update_site_option( 'allowedthemes', $allowed_themes );
  56. wp_safe_redirect( add_query_arg( 'enabled', count( $themes ), $referer ) );
  57. exit;
  58. break;
  59. case 'disable-selected':
  60. check_admin_referer('bulk-themes');
  61. $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
  62. if ( empty($themes) ) {
  63. wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
  64. exit;
  65. }
  66. foreach( (array) $themes as $theme )
  67. unset( $allowed_themes[ $theme ] );
  68. update_site_option( 'allowedthemes', $allowed_themes );
  69. wp_safe_redirect( add_query_arg( 'disabled', count( $themes ), $referer ) );
  70. exit;
  71. break;
  72. case 'update-selected' :
  73. check_admin_referer( 'bulk-themes' );
  74. if ( isset( $_GET['themes'] ) )
  75. $themes = explode( ',', $_GET['themes'] );
  76. elseif ( isset( $_POST['checked'] ) )
  77. $themes = (array) $_POST['checked'];
  78. else
  79. $themes = array();
  80. $title = __( 'Update Themes' );
  81. $parent_file = 'themes.php';
  82. require_once(ABSPATH . 'wp-admin/admin-header.php');
  83. echo '<div class="wrap">';
  84. screen_icon();
  85. echo '<h2>' . esc_html( $title ) . '</h2>';
  86. $url = self_admin_url('update.php?action=update-selected-themes&amp;themes=' . urlencode( join(',', $themes) ));
  87. $url = wp_nonce_url($url, 'bulk-update-themes');
  88. echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";
  89. echo '</div>';
  90. require_once(ABSPATH . 'wp-admin/admin-footer.php');
  91. exit;
  92. break;
  93. case 'delete-selected':
  94. if ( ! current_user_can( 'delete_themes' ) )
  95. wp_die( __('You do not have sufficient permissions to delete themes for this site.') );
  96. check_admin_referer( 'bulk-themes' );
  97. $themes = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array();
  98. unset( $themes[ get_option( 'stylesheet' ) ], $themes[ get_option( 'template' ) ] );
  99. if ( empty( $themes ) ) {
  100. wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
  101. exit;
  102. }
  103. $files_to_delete = $theme_info = array();
  104. foreach ( $themes as $key => $theme ) {
  105. $theme_info[ $theme ] = wp_get_theme( $theme );
  106. $files_to_delete = array_merge( $files_to_delete, list_files( $theme_info[ $theme ]->get_stylesheet_directory() ) );
  107. }
  108. if ( empty( $themes ) ) {
  109. wp_safe_redirect( add_query_arg( 'error', 'main', $referer ) );
  110. exit;
  111. }
  112. include(ABSPATH . 'wp-admin/update.php');
  113. $parent_file = 'themes.php';
  114. if ( ! isset( $_REQUEST['verify-delete'] ) ) {
  115. wp_enqueue_script( 'jquery' );
  116. require_once( ABSPATH . 'wp-admin/admin-header.php' );
  117. ?>
  118. <div class="wrap">
  119. <?php
  120. $themes_to_delete = count( $themes );
  121. screen_icon();
  122. echo '<h2>' . _n( 'Delete Theme', 'Delete Themes', $themes_to_delete ) . '</h2>';
  123. ?>
  124. <div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php echo _n( 'This theme may be active on other sites in the network.', 'These themes may be active on other sites in the network.', $themes_to_delete ); ?></p></div>
  125. <p><?php echo _n( 'You are about to remove the following theme:', 'You are about to remove the following themes:', $themes_to_delete ); ?></p>
  126. <ul class="ul-disc">
  127. <?php foreach ( $theme_info as $theme )
  128. echo '<li>', sprintf( __('<strong>%1$s</strong> by <em>%2$s</em>' ), $theme->display('Name'), $theme->display('Author') ), '</li>'; /* translators: 1: theme name, 2: theme author */ ?>
  129. </ul>
  130. <p><?php _e('Are you sure you wish to delete these themes?'); ?></p>
  131. <form method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" style="display:inline;">
  132. <input type="hidden" name="verify-delete" value="1" />
  133. <input type="hidden" name="action" value="delete-selected" />
  134. <?php
  135. foreach ( (array) $themes as $theme )
  136. echo '<input type="hidden" name="checked[]" value="' . esc_attr($theme) . '" />';
  137. ?>
  138. <?php wp_nonce_field('bulk-themes') ?>
  139. <?php submit_button( _n( 'Yes, Delete this theme', 'Yes, Delete these themes', $themes_to_delete ), 'button', 'submit', false ); ?>
  140. </form>
  141. <form method="post" action="<?php echo esc_url(wp_get_referer()); ?>" style="display:inline;">
  142. <?php submit_button( __( 'No, Return me to the theme list' ), 'button', 'submit', false ); ?>
  143. </form>
  144. <p><a href="#" onclick="jQuery('#files-list').toggle(); return false;"><?php _e('Click to view entire list of files which will be deleted'); ?></a></p>
  145. <div id="files-list" style="display:none;">
  146. <ul class="code">
  147. <?php
  148. foreach ( (array) $files_to_delete as $file )
  149. echo '<li>' . esc_html( str_replace( WP_CONTENT_DIR . "/themes", '', $file) ) . '</li>';
  150. ?>
  151. </ul>
  152. </div>
  153. </div>
  154. <?php
  155. require_once(ABSPATH . 'wp-admin/admin-footer.php');
  156. exit;
  157. } // Endif verify-delete
  158. foreach ( $themes as $theme )
  159. $delete_result = delete_theme( $theme, esc_url( add_query_arg( array('verify-delete' => 1), $_SERVER['REQUEST_URI'] ) ) );
  160. $paged = ( $_REQUEST['paged'] ) ? $_REQUEST['paged'] : 1;
  161. wp_redirect( network_admin_url( "themes.php?deleted=".count( $themes )."&paged=$paged&s=$s" ) );
  162. exit;
  163. break;
  164. }
  165. }
  166. $wp_list_table->prepare_items();
  167. add_thickbox();
  168. add_screen_option( 'per_page', array('label' => _x( 'Themes', 'themes per page (screen options)' )) );
  169. get_current_screen()->add_help_tab( array(
  170. 'id' => 'overview',
  171. 'title' => __('Overview'),
  172. 'content' =>
  173. '<p>' . __('This screen enables and disables the inclusion of themes available to choose in the Appearance menu for each site. It does not activate or deactivate which theme a site is currently using.') . '</p>' .
  174. '<p>' . __('If the network admin disables a theme that is in use, it can still remain selected on that site. If another theme is chosen, the disabled theme will not appear in the site&#8217;s Appearance > Themes screen.') . '</p>' .
  175. '<p>' . __('Themes can be enabled on a site by site basis by the network admin on the Edit Site screen (which has a Themes tab); get there via the Edit action link on the All Sites screen. Only network admins are able to install or edit themes.') . '</p>'
  176. ) );
  177. get_current_screen()->set_help_sidebar(
  178. '<p><strong>' . __('For more information:') . '</strong></p>' .
  179. '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Themes_Screen" target="_blank">Documentation on Network Themes</a>') . '</p>' .
  180. '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
  181. );
  182. $title = __('Themes');
  183. $parent_file = 'themes.php';
  184. require_once(ABSPATH . 'wp-admin/admin-header.php');
  185. ?>
  186. <div class="wrap">
  187. <?php screen_icon('themes'); ?>
  188. <h2><?php echo esc_html( $title ); if ( current_user_can('install_themes') ) { ?> <a href="theme-install.php" class="add-new-h2"><?php echo esc_html_x('Add New', 'theme'); ?></a><?php }
  189. if ( $s )
  190. printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( $s ) ); ?>
  191. </h2>
  192. <?php
  193. if ( isset( $_GET['enabled'] ) ) {
  194. $_GET['enabled'] = absint( $_GET['enabled'] );
  195. echo '<div id="message" class="updated"><p>' . sprintf( _n( 'Theme enabled.', '%s themes enabled.', $_GET['enabled'] ), number_format_i18n( $_GET['enabled'] ) ) . '</p></div>';
  196. } elseif ( isset( $_GET['disabled'] ) ) {
  197. $_GET['disabled'] = absint( $_GET['disabled'] );
  198. echo '<div id="message" class="updated"><p>' . sprintf( _n( 'Theme disabled.', '%s themes disabled.', $_GET['disabled'] ), number_format_i18n( $_GET['disabled'] ) ) . '</p></div>';
  199. } elseif ( isset( $_GET['deleted'] ) ) {
  200. $_GET['deleted'] = absint( $_GET['deleted'] );
  201. echo '<div id="message" class="updated"><p>' . sprintf( _nx( 'Theme deleted.', '%s themes deleted.', $_GET['deleted'], 'network' ), number_format_i18n( $_GET['deleted'] ) ) . '</p></div>';
  202. } elseif ( isset( $_GET['error'] ) && 'none' == $_GET['error'] ) {
  203. echo '<div id="message" class="error"><p>' . __( 'No theme selected.' ) . '</p></div>';
  204. } elseif ( isset( $_GET['error'] ) && 'main' == $_GET['error'] ) {
  205. echo '<div class="error"><p>' . __( 'You cannot delete a theme while it is active on the main site.' ) . '</p></div>';
  206. }
  207. ?>
  208. <form method="get" action="">
  209. <?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?>
  210. </form>
  211. <?php
  212. $wp_list_table->views();
  213. if ( 'broken' == $status )
  214. echo '<p class="clear">' . __('The following themes are installed but incomplete. Themes must have a stylesheet and a template.') . '</p>';
  215. ?>
  216. <form method="post" action="">
  217. <input type="hidden" name="theme_status" value="<?php echo esc_attr($status) ?>" />
  218. <input type="hidden" name="paged" value="<?php echo esc_attr($page) ?>" />
  219. <?php $wp_list_table->display(); ?>
  220. </form>
  221. </div>
  222. <?php
  223. include(ABSPATH . 'wp-admin/admin-footer.php');