PageRenderTime 53ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/network/site-info.php

https://gitlab.com/ReneMC/Custom-wordpress-theme
PHP | 222 lines | 172 code | 34 blank | 16 comment | 26 complexity | 009a87e11a02fa093f6c3a7c3d36e243 MD5 | raw file
  1. <?php
  2. /**
  3. * Edit Site Info 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 ( ! is_multisite() ) {
  12. wp_die( __( 'Multisite support is not enabled.' ) );
  13. }
  14. if ( ! current_user_can( 'manage_sites' ) ) {
  15. wp_die( __( 'You do not have sufficient permissions to edit this site.' ) );
  16. }
  17. get_current_screen()->add_help_tab( array(
  18. 'id' => 'overview',
  19. 'title' => __( 'Overview' ),
  20. 'content' =>
  21. '<p>' . __( 'The menu is for editing information specific to individual sites, particularly if the admin area of a site is unavailable.' ) . '</p>' .
  22. '<p>' . __( '<strong>Info</strong> &mdash; The site URL is rarely edited as this can cause the site to not work properly. The Registered date and Last Updated date are displayed. Network admins can mark a site as archived, spam, deleted and mature, to remove from public listings or disable.' ) . '</p>' .
  23. '<p>' . __( '<strong>Users</strong> &mdash; This displays the users associated with this site. You can also change their role, reset their password, or remove them from the site. Removing the user from the site does not remove the user from the network.' ) . '</p>' .
  24. '<p>' . sprintf( __( '<strong>Themes</strong> &mdash; This area shows themes that are not already enabled across the network. Enabling a theme in this menu makes it accessible to this site. It does not activate the theme, but allows it to show in the site&#8217;s Appearance menu. To enable a theme for the entire network, see the <a href="%s">Network Themes</a> screen.' ), network_admin_url( 'themes.php' ) ) . '</p>' .
  25. '<p>' . __( '<strong>Settings</strong> &mdash; This page shows a list of all settings associated with this site. Some are created by WordPress and others are created by plugins you activate. Note that some fields are grayed out and say Serialized Data. You cannot modify these values due to the way the setting is stored in the database.' ) . '</p>'
  26. ) );
  27. get_current_screen()->set_help_sidebar(
  28. '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  29. '<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Sites_Screen" target="_blank">Documentation on Site Management</a>' ) . '</p>' .
  30. '<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>' ) . '</p>'
  31. );
  32. $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
  33. if ( ! $id ) {
  34. wp_die( __('Invalid site ID.') );
  35. }
  36. $details = get_blog_details( $id );
  37. if ( ! $details ) {
  38. wp_die( __( 'The requested site does not exist.' ) );
  39. }
  40. if ( ! can_edit_network( $details->site_id ) ) {
  41. wp_die( __( 'You do not have permission to access this page.' ), 403 );
  42. }
  43. $parsed_scheme = parse_url( $details->siteurl, PHP_URL_SCHEME );
  44. $is_main_site = is_main_site( $id );
  45. if ( isset( $_REQUEST['action'] ) && 'update-site' == $_REQUEST['action'] ) {
  46. check_admin_referer( 'edit-site' );
  47. switch_to_blog( $id );
  48. // Rewrite rules can't be flushed during switch to blog.
  49. delete_option( 'rewrite_rules' );
  50. $blog_data = wp_unslash( $_POST['blog'] );
  51. $blog_data['scheme'] = $parsed_scheme;
  52. if ( $is_main_site ) {
  53. // On the network's main site, don't allow the domain or path to change.
  54. $blog_data['domain'] = $details->domain;
  55. $blog_data['path'] = $details->path;
  56. } else {
  57. // For any other site, the scheme, domain, and path can all be changed. We first
  58. // need to ensure a scheme has been provided, otherwise fallback to the existing.
  59. $new_url_scheme = parse_url( $blog_data['url'], PHP_URL_SCHEME );
  60. if ( ! $new_url_scheme ) {
  61. $blog_data['url'] = esc_url( $parsed_scheme . '://' . $blog_data['url'] );
  62. }
  63. $update_parsed_url = parse_url( $blog_data['url'] );
  64. // If a path is not provided, use the default of `/`.
  65. if ( ! isset( $update_parsed_url['path'] ) ) {
  66. $update_parsed_url['path'] = '/';
  67. }
  68. $blog_data['scheme'] = $update_parsed_url['scheme'];
  69. $blog_data['domain'] = $update_parsed_url['host'];
  70. $blog_data['path'] = $update_parsed_url['path'];
  71. }
  72. $existing_details = get_blog_details( $id, false );
  73. $blog_data_checkboxes = array( 'public', 'archived', 'spam', 'mature', 'deleted' );
  74. foreach ( $blog_data_checkboxes as $c ) {
  75. if ( ! in_array( $existing_details->$c, array( 0, 1 ) ) ) {
  76. $blog_data[ $c ] = $existing_details->$c;
  77. } else {
  78. $blog_data[ $c ] = isset( $_POST['blog'][ $c ] ) ? 1 : 0;
  79. }
  80. }
  81. update_blog_details( $id, $blog_data );
  82. // Maybe update home and siteurl options.
  83. $new_details = get_blog_details( $id, false );
  84. $old_home_url = trailingslashit( esc_url( get_option( 'home' ) ) );
  85. $old_home_parsed = parse_url( $old_home_url );
  86. if ( $old_home_parsed['host'] === $existing_details->domain && $old_home_parsed['path'] === $existing_details->path ) {
  87. $new_home_url = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
  88. update_option( 'home', $new_home_url );
  89. }
  90. $old_site_url = trailingslashit( esc_url( get_option( 'siteurl' ) ) );
  91. $old_site_parsed = parse_url( $old_site_url );
  92. if ( $old_site_parsed['host'] === $existing_details->domain && $old_site_parsed['path'] === $existing_details->path ) {
  93. $new_site_url = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
  94. update_option( 'siteurl', $new_site_url );
  95. }
  96. restore_current_blog();
  97. wp_redirect( add_query_arg( array( 'update' => 'updated', 'id' => $id ), 'site-info.php' ) );
  98. exit;
  99. }
  100. if ( isset( $_GET['update'] ) ) {
  101. $messages = array();
  102. if ( 'updated' == $_GET['update'] ) {
  103. $messages[] = __( 'Site info updated.' );
  104. }
  105. }
  106. $title = sprintf( __( 'Edit Site: %s' ), esc_html( $details->blogname ) );
  107. $parent_file = 'sites.php';
  108. $submenu_file = 'sites.php';
  109. require( ABSPATH . 'wp-admin/admin-header.php' );
  110. ?>
  111. <div class="wrap">
  112. <h1 id="edit-site"><?php echo $title; ?></h1>
  113. <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>
  114. <h2 class="nav-tab-wrapper nav-tab-small wp-clearfix">
  115. <?php
  116. $tabs = array(
  117. 'site-info' => array( 'label' => __( 'Info' ), 'url' => 'site-info.php' ),
  118. 'site-users' => array( 'label' => __( 'Users' ), 'url' => 'site-users.php' ),
  119. 'site-themes' => array( 'label' => __( 'Themes' ), 'url' => 'site-themes.php' ),
  120. 'site-settings' => array( 'label' => __( 'Settings' ), 'url' => 'site-settings.php' ),
  121. );
  122. foreach ( $tabs as $tab_id => $tab ) {
  123. $class = ( $tab['url'] == $pagenow ) ? ' nav-tab-active' : '';
  124. echo '<a href="' . $tab['url'] . '?id=' . $id .'" class="nav-tab' . $class . '">' . esc_html( $tab['label'] ) . '</a>';
  125. }
  126. ?>
  127. </h2>
  128. <?php
  129. if ( ! empty( $messages ) ) {
  130. foreach ( $messages as $msg ) {
  131. echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
  132. }
  133. }
  134. ?>
  135. <form method="post" action="site-info.php?action=update-site">
  136. <?php wp_nonce_field( 'edit-site' ); ?>
  137. <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
  138. <table class="form-table">
  139. <?php
  140. // The main site of the network should not be updated on this page.
  141. if ( $is_main_site ) : ?>
  142. <tr class="form-field">
  143. <th scope="row"><?php _e( 'Site Address (URL)' ); ?></th>
  144. <td><?php echo esc_url( $details->domain . $details->path ); ?></td>
  145. </tr>
  146. <?php
  147. // For any other site, the scheme, domain, and path can all be changed.
  148. else : ?>
  149. <tr class="form-field form-required">
  150. <th scope="row"><?php _e( 'Site Address (URL)' ); ?></th>
  151. <td><input name="blog[url]" type="text" id="url" value="<?php echo $parsed_scheme . '://' . esc_attr( $details->domain ) . esc_attr( $details->path ); ?>" /></td>
  152. </tr>
  153. <?php endif; ?>
  154. <tr class="form-field">
  155. <th scope="row"><label for="blog_registered"><?php _ex( 'Registered', 'site' ) ?></label></th>
  156. <td><input name="blog[registered]" type="text" id="blog_registered" value="<?php echo esc_attr( $details->registered ) ?>" /></td>
  157. </tr>
  158. <tr class="form-field">
  159. <th scope="row"><label for="blog_last_updated"><?php _e( 'Last Updated' ); ?></label></th>
  160. <td><input name="blog[last_updated]" type="text" id="blog_last_updated" value="<?php echo esc_attr( $details->last_updated ) ?>" /></td>
  161. </tr>
  162. <?php
  163. $attribute_fields = array( 'public' => __( 'Public' ) );
  164. if ( ! $is_main_site ) {
  165. $attribute_fields['archived'] = __( 'Archived' );
  166. $attribute_fields['spam'] = _x( 'Spam', 'site' );
  167. $attribute_fields['deleted'] = __( 'Deleted' );
  168. }
  169. $attribute_fields['mature'] = __( 'Mature' );
  170. ?>
  171. <tr>
  172. <th scope="row"><?php _e( 'Attributes' ); ?></th>
  173. <td>
  174. <fieldset>
  175. <legend class="screen-reader-text"><?php _e( 'Set site attributes' ) ?></legend>
  176. <?php foreach ( $attribute_fields as $field_key => $field_label ) : ?>
  177. <label><input type="checkbox" name="blog[<?php echo $field_key; ?>]" value="1" <?php checked( (bool) $details->$field_key, true ); disabled( ! in_array( $details->$field_key, array( 0, 1 ) ) ); ?> />
  178. <?php echo $field_label; ?></label><br/>
  179. <?php endforeach; ?>
  180. <fieldset>
  181. </td>
  182. </tr>
  183. </table>
  184. <?php submit_button(); ?>
  185. </form>
  186. </div>
  187. <?php
  188. require( ABSPATH . 'wp-admin/admin-footer.php' );