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

/src/wp-admin/network/site-themes.php

https://gitlab.com/morganestes/wordpress-develop
PHP | 226 lines | 166 code | 35 blank | 25 comment | 29 complexity | 2b8001ce2061c65d08d11fbf11ff658e MD5 | raw file
  1. <?php
  2. /**
  3. * Edit Site Themes Administration Screen
  4. *
  5. * @package WordPress
  6. * @subpackage Multisite
  7. * @since 3.1.0
  8. */
  9. /** Load WordPress Administration Bootstrap */
  10. require_once( dirname( __FILE__ ) . '/admin.php' );
  11. if ( ! current_user_can( 'manage_sites' ) ) {
  12. wp_die( __( 'Sorry, you are not allowed to manage themes for this site.' ) );
  13. }
  14. get_current_screen()->add_help_tab( get_site_screen_help_tab_args() );
  15. get_current_screen()->set_help_sidebar( get_site_screen_help_sidebar_content() );
  16. get_current_screen()->set_screen_reader_content(
  17. array(
  18. 'heading_views' => __( 'Filter site themes list' ),
  19. 'heading_pagination' => __( 'Site themes list navigation' ),
  20. 'heading_list' => __( 'Site themes list' ),
  21. )
  22. );
  23. $wp_list_table = _get_list_table( 'WP_MS_Themes_List_Table' );
  24. $action = $wp_list_table->current_action();
  25. $s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
  26. // Clean up request URI from temporary args for screen options/paging uri's to work as expected.
  27. $temp_args = array( 'enabled', 'disabled', 'error' );
  28. $_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI'] );
  29. $referer = remove_query_arg( $temp_args, wp_get_referer() );
  30. if ( ! empty( $_REQUEST['paged'] ) ) {
  31. $referer = add_query_arg( 'paged', (int) $_REQUEST['paged'], $referer );
  32. }
  33. $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
  34. if ( ! $id ) {
  35. wp_die( __( 'Invalid site ID.' ) );
  36. }
  37. $wp_list_table->prepare_items();
  38. $details = get_site( $id );
  39. if ( ! $details ) {
  40. wp_die( __( 'The requested site does not exist.' ) );
  41. }
  42. if ( ! can_edit_network( $details->site_id ) ) {
  43. wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
  44. }
  45. $is_main_site = is_main_site( $id );
  46. if ( $action ) {
  47. switch_to_blog( $id );
  48. $allowed_themes = get_option( 'allowedthemes' );
  49. switch ( $action ) {
  50. case 'enable':
  51. check_admin_referer( 'enable-theme_' . $_GET['theme'] );
  52. $theme = $_GET['theme'];
  53. $action = 'enabled';
  54. $n = 1;
  55. if ( ! $allowed_themes ) {
  56. $allowed_themes = array( $theme => true );
  57. } else {
  58. $allowed_themes[ $theme ] = true;
  59. }
  60. break;
  61. case 'disable':
  62. check_admin_referer( 'disable-theme_' . $_GET['theme'] );
  63. $theme = $_GET['theme'];
  64. $action = 'disabled';
  65. $n = 1;
  66. if ( ! $allowed_themes ) {
  67. $allowed_themes = array();
  68. } else {
  69. unset( $allowed_themes[ $theme ] );
  70. }
  71. break;
  72. case 'enable-selected':
  73. check_admin_referer( 'bulk-themes' );
  74. if ( isset( $_POST['checked'] ) ) {
  75. $themes = (array) $_POST['checked'];
  76. $action = 'enabled';
  77. $n = count( $themes );
  78. foreach ( (array) $themes as $theme ) {
  79. $allowed_themes[ $theme ] = true;
  80. }
  81. } else {
  82. $action = 'error';
  83. $n = 'none';
  84. }
  85. break;
  86. case 'disable-selected':
  87. check_admin_referer( 'bulk-themes' );
  88. if ( isset( $_POST['checked'] ) ) {
  89. $themes = (array) $_POST['checked'];
  90. $action = 'disabled';
  91. $n = count( $themes );
  92. foreach ( (array) $themes as $theme ) {
  93. unset( $allowed_themes[ $theme ] );
  94. }
  95. } else {
  96. $action = 'error';
  97. $n = 'none';
  98. }
  99. break;
  100. default:
  101. if ( isset( $_POST['checked'] ) ) {
  102. check_admin_referer( 'bulk-themes' );
  103. $themes = (array) $_POST['checked'];
  104. $n = count( $themes );
  105. $screen = get_current_screen()->id;
  106. /**
  107. * Fires when a custom bulk action should be handled.
  108. *
  109. * The redirect link should be modified with success or failure feedback
  110. * from the action to be used to display feedback to the user.
  111. *
  112. * The dynamic portion of the hook name, `$screen`, refers to the current screen ID.
  113. *
  114. * @since 4.7.0
  115. *
  116. * @param string $redirect_url The redirect URL.
  117. * @param string $action The action being taken.
  118. * @param array $items The items to take the action on.
  119. * @param int $site_id The site ID.
  120. */
  121. $referer = apply_filters( "handle_network_bulk_actions-{$screen}", $referer, $action, $themes, $id );
  122. } else {
  123. $action = 'error';
  124. $n = 'none';
  125. }
  126. }
  127. update_option( 'allowedthemes', $allowed_themes );
  128. restore_current_blog();
  129. wp_safe_redirect(
  130. add_query_arg(
  131. array(
  132. 'id' => $id,
  133. $action => $n,
  134. ), $referer
  135. )
  136. );
  137. exit;
  138. }
  139. if ( isset( $_GET['action'] ) && 'update-site' == $_GET['action'] ) {
  140. wp_safe_redirect( $referer );
  141. exit();
  142. }
  143. add_thickbox();
  144. add_screen_option( 'per_page' );
  145. /* translators: %s: site name */
  146. $title = sprintf( __( 'Edit Site: %s' ), esc_html( $details->blogname ) );
  147. $parent_file = 'sites.php';
  148. $submenu_file = 'sites.php';
  149. require( ABSPATH . 'wp-admin/admin-header.php' ); ?>
  150. <div class="wrap">
  151. <h1 id="edit-site"><?php echo $title; ?></h1>
  152. <p class="edit-site-actions"><a href="<?php echo esc_url( get_home_url( $id, '/' ) ); ?>"><?php _e( 'Visit' ); ?></a> | <a href="<?php echo esc_url( get_admin_url( $id ) ); ?>"><?php _e( 'Dashboard' ); ?></a></p>
  153. <?php
  154. network_edit_site_nav(
  155. array(
  156. 'blog_id' => $id,
  157. 'selected' => 'site-themes',
  158. )
  159. );
  160. if ( isset( $_GET['enabled'] ) ) {
  161. $enabled = absint( $_GET['enabled'] );
  162. if ( 1 == $enabled ) {
  163. $message = __( 'Theme enabled.' );
  164. } else {
  165. $message = _n( '%s theme enabled.', '%s themes enabled.', $enabled );
  166. }
  167. echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $enabled ) ) . '</p></div>';
  168. } elseif ( isset( $_GET['disabled'] ) ) {
  169. $disabled = absint( $_GET['disabled'] );
  170. if ( 1 == $disabled ) {
  171. $message = __( 'Theme disabled.' );
  172. } else {
  173. $message = _n( '%s theme disabled.', '%s themes disabled.', $disabled );
  174. }
  175. echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $disabled ) ) . '</p></div>';
  176. } elseif ( isset( $_GET['error'] ) && 'none' == $_GET['error'] ) {
  177. echo '<div id="message" class="error notice is-dismissible"><p>' . __( 'No theme selected.' ) . '</p></div>';
  178. }
  179. ?>
  180. <p><?php _e( 'Network enabled themes are not shown on this screen.' ); ?></p>
  181. <form method="get">
  182. <?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?>
  183. <input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
  184. </form>
  185. <?php $wp_list_table->views(); ?>
  186. <form method="post" action="site-themes.php?action=update-site">
  187. <input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
  188. <?php $wp_list_table->display(); ?>
  189. </form>
  190. </div>
  191. <?php include( ABSPATH . 'wp-admin/admin-footer.php' ); ?>