WordPress 3.0 beta 1 documentation kindly provided to you by Hay Kranen
| [ Index ] |
PHP Cross Reference of WordPress 3.0 beta 1 |
|
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Network installation administration panel. 4 * 5 * A multi-step process allowing the user to enable a network of WordPress sites. 6 * 7 * @since 3.0.0 8 * 9 * @package WordPress 10 * @subpackage Administration 11 */ 12 13 /** WordPress Administration Bootstrap */ 14 require_once ( './admin.php' ); 15 16 if ( ! is_super_admin() ) 17 wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ) ); 18 19 if ( is_multisite() && ! defined( 'MULTISITE' ) ) 20 wp_die( __('The Network creation panel is not for WordPress MU networks.') ); 21 22 // We need to create references to ms global tables to enable Network. 23 foreach ( $wpdb->tables( 'ms_global' ) as $table => $prefixed_table ) 24 $wpdb->$table = $prefixed_table; 25 26 /** 27 * Check for an existing network. 28 * 29 * @since 3.0.0 30 * @return Whether a network exists. 31 */ 32 function network_domain_check() { 33 global $wpdb; 34 if ( $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) ) 35 return $wpdb->get_var( "SELECT domain FROM $wpdb->site ORDER BY id ASC LIMIT 1" ); 36 return false; 37 } 38 39 /** 40 * Allow subdomain install 41 * 42 * @since 3.0.0 43 * @return bool - whether subdomain install is allowed 44 */ 45 function allow_subdomain_install() { 46 $domain = preg_replace( '|https?://[^/]|', '', get_option( 'siteurl' ) ); 47 if( false !== strpos( $domain, '/' ) || 'localhost' == $_SERVER[ 'HTTP_HOST' ] ) 48 return false; 49 50 return true; 51 } 52 /** 53 * Get base domain of network. 54 * 55 * @since 3.0.0 56 * @return string Base domain. 57 */ 58 function get_clean_basedomain() { 59 if ( $existing_domain = network_domain_check() ) 60 return $existing_domain; 61 $domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) ); 62 if ( $slash = strpos( $domain, '/' ) ) 63 $domain = substr( $domain, 0, $slash ); 64 return $domain; 65 } 66 67 if ( ! network_domain_check() && ( ! defined( 'WP_ALLOW_MULTISITE' ) || ! WP_ALLOW_MULTISITE ) ) 68 wp_die( __( 'You must define the <code>WP_ALLOW_MULTISITE</code> constant as true in your wp-config.php file to allow creation of a Network.' ) ); 69 70 $title = __( 'Create a Network of WordPress Sites' ); 71 $parent_file = 'tools.php'; 72 73 // @todo: Documentation? 74 // add_contextual_help( $current_screen, ... ); 75 76 include ( './admin-header.php' ); 77 ?> 78 <div class="wrap"> 79 <?php screen_icon(); ?> 80 <h2><?php echo esc_html( $title ); ?></h2> 81 82 <form method="post"> 83 <?php 84 /** 85 * Prints step 1 for Network installation process. 86 * 87 * @todo Realistically, step 1 should be a welcome screen explaining what a Network is and such. Navigating to Tools > Network 88 * should not be a sudden "Welcome to a new install process! Fill this out and click here." See also contextual help todo. 89 * 90 * @since 3.0.0 91 */ 92 function network_step1( $errors = false ) { 93 94 if ( get_option( 'siteurl' ) != get_option( 'home' ) ) { 95 echo '<div class="error"><p><strong>' . __('Error:') . '</strong> ' . sprintf( __( 'Your <strong>WordPress address</strong> must match your <strong>Site address</strong> before creating a Network. See <a href="%s">General Settings</a>.' ), esc_url( admin_url( 'options-general.php' ) ) ) . '</strong></p></div>'; 96 include ('./admin-footer.php' ); 97 die(); 98 } 99 100 $active_plugins = get_option( 'active_plugins' ); 101 if ( ! empty( $active_plugins ) ) { 102 echo '<div class="updated"><p><strong>' . __('Warning:') . '</strong> ' . sprintf( __( 'Please <a href="%s">deactivate</a> your plugins before enabling the Network feature.' ), admin_url( 'plugins.php' ) ) . '</p></div><p>' . __(' Once the network is created, you may reactivate your plugins.' ) . '</p>'; 103 include ( './admin-footer.php' ); 104 die(); 105 } 106 107 $hostname = get_clean_basedomain(); 108 $has_ports = strstr( $hostname, ':' ); 109 if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443' ) ) ) 110 || ( $no_ip = preg_match( '|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|', $hostname ) ) ) { 111 echo '<div class="error"><p><strong>' . __( 'Error:') . '</strong> ' . __( 'You cannot install a network of sites with your server address.' ) . '</strong></p></div>'; 112 if ( $no_ip ) 113 echo '<p>' . __('You cannot use an IP address such as <code>127.0.0.1</code>.' ) . '</p>'; 114 else 115 echo '<p>' . sprintf( __('You cannot use port numbers such as <code>%s</code>.' ), $has_ports ) . '</p>'; 116 echo '<a href="' . esc_url( admin_url() ) . '">' . __( 'Return to Dashboard' ) . '</a>'; 117 include ( './admin-footer.php' ); 118 die(); 119 } 120 121 wp_nonce_field( 'install-network-1' ); 122 123 $error_codes = array(); 124 if ( is_wp_error( $errors ) ) { 125 echo '<div class="error"><p><strong>' . __( 'ERROR: The network could not be created.' ) . '</strong></p>'; 126 foreach ( $errors->get_error_messages() as $error ) 127 echo "<p>$error</p>"; 128 echo '</div>'; 129 $error_codes = $errors->get_error_codes(); 130 } 131 132 $site_name = ( ! empty( $_POST['sitename'] ) && ! in_array( 'empty_sitename', $error_codes ) ) ? $_POST['sitename'] : sprintf( _x('%s Sites', 'Default network name' ), get_option( 'blogname' ) ); 133 $admin_email = ( ! empty( $_POST['email'] ) && ! in_array( 'invalid_email', $error_codes ) ) ? $_POST['email'] : get_option( 'admin_email' ); 134 ?> 135 <p><?php _e( 'Welcome to the Network installation process!' ); ?></p> 136 <p><?php _e( "Fill in the information below and you'll be on your way to creating a network of WordPress sites. We'll create configuration files in the next step." ); ?></p> 137 <?php 138 139 // @todo IIS and ! $is_apache 140 if ( isset( $_POST['subdomain_install'] ) ) { 141 $subdomain_install = (bool) $_POST['subdomain_install']; 142 } elseif ( apache_mod_loaded('mod_rewrite') ) { // assume nothing 143 $subdomain_install = true; 144 } else { 145 $subdomain_install = false; 146 if ( got_mod_rewrite() ) // dangerous assumptions 147 echo '<div class="updated inline"><p><strong>' . __( 'Note:' ) . '</strong> ' . __( 'Please make sure the Apache <code>mod_rewrite</code> module is installed as it will be used at the end of this install.' ) . '</p>'; 148 else 149 echo '<div class="error inline"><p><strong>' . __( 'Warning!' ) . '</strong> ' . __( 'It looks like the Apache <code>mod_rewrite</code> module is not installed.' ) . '</p>'; 150 echo '<p>' . __( 'If <code>mod_rewrite</code> is disabled, ask your administrator to enable that module, or look at the <a href="http://httpd.apache.org/docs/mod/mod_rewrite.html">Apache documentation</a> or <a href="http://www.google.com/search?q=apache+mod_rewrite">elsewhere</a> for help setting it up.' ) . '</p></div>'; 151 } 152 153 if ( allow_subdomain_install() ) : ?> 154 <h3><?php esc_html_e( 'Addresses of Sites in your Network' ); ?></h3> 155 <p><?php _e( 'Please choose whether you would like sites in your WordPress network to use sub-domains or sub-directories. <strong>You cannot change this later.</strong>' ); ?></p> 156 <p><?php _e( "You will need a wildcard DNS record if you're going to use the virtual host (sub-domain) functionality." ); ?></p> 157 <?php // @todo: Link to an MS readme? ?> 158 <table class="form-table"> 159 <tr> 160 <th><label><input type='radio' name='subdomain_install' value='1'<?php checked( $subdomain_install ); ?> /> Sub-domains</label></th> 161 <td><?php printf( _x( 'like <code>site1.%1$s</code> and <code>site2.%1$s</code>', 'subdomain examples' ), $hostname ); ?></td> 162 </tr> 163 <tr> 164 <th><label><input type='radio' name='subdomain_install' value='0'<?php checked( ! $subdomain_install ); ?> /> Sub-directories</label></th> 165 <td><?php printf( _x( 'like <code>%1$s/site1</code> and <code>%1$s/site2</code>', 'subdirectory examples' ), $hostname ); ?></td> 166 </tr> 167 </table> 168 169 <?php 170 endif; 171 172 $is_www = ( 0 === strpos( $hostname, 'www.' ) ); 173 if ( $is_www ) : 174 ?> 175 <h3><?php esc_html_e( 'Server Address' ); ?></h3> 176 <p><?php printf( __( 'We recommend you change your siteurl to <code>%1$s</code> before enabling the network feature. It will still be possible to visit your site using the "www" prefix with an address like <code>%2$s</code> but any links will not have the "www" prefix.' ), substr( $hostname, 4 ), $hostname ); ?></h3> 177 <table class="form-table"> 178 <tr> 179 <th scope='row'><?php esc_html_e( 'Server Address' ); ?></th> 180 <td> 181 <?php printf( __( 'The Internet address of your network will be <code>%s</code>.' ), $hostname ); ?> 182 </td> 183 </tr> 184 </table> 185 <?php endif; ?> 186 187 <h3><?php esc_html_e( 'Network Details' ); ?></h3> 188 <table class="form-table"> 189 <?php if ( 'localhost' == $hostname ) : ?> 190 <tr> 191 <th scope="row"><?php esc_html_e( 'Sub-directory Install' ); ?></th> 192 <td><?php _e('Because you are using <code>localhost</code>, the sites in your WordPress network must use sub-directories. Consider using <code>localhost.localdomain</code> if you wish to use sub-domains.'); ?></td> 193 </tr> 194 <?php elseif ( !allow_subdomain_install() ) : ?> 195 <tr> 196 <th scope="row"><?php esc_html_e( 'Sub-directory Install' ); ?></th> 197 <td><?php _e('Because your install is in a directory, the sites in your WordPress network must use sub-directories.'); ?></td> 198 </tr> 199 <?php endif; ?> 200 <?php if ( ! $is_www ) : ?> 201 <tr> 202 <th scope='row'><?php esc_html_e( 'Server Address' ); ?></th> 203 <td> 204 <?php printf( __( 'The Internet address of your network will be <code>%s</code>.' ), $hostname ); ?> 205 </td> 206 </tr> 207 <?php endif; ?> 208 <tr> 209 <th scope='row'><?php esc_html_e( 'Network Title' ); ?></th> 210 <td> 211 <input name='sitename' type='text' size='45' value='<?php echo esc_attr( $site_name ); ?>' /> 212 <br /><?php _e( 'What would you like to call your network?' ); ?> 213 </td> 214 </tr> 215 <tr> 216 <th scope='row'><?php esc_html_e( 'Admin E-mail Address' ); ?></th> 217 <td> 218 <input name='email' type='text' size='45' value='<?php echo esc_attr( $admin_email ); ?>' /> 219 <br /><?php _e( 'Your email address.' ); ?> 220 </td> 221 </tr> 222 </table> 223 <p class='submit'><input class="button-primary" name='submit' type='submit' value='<?php esc_attr_e( 'Install' ); ?>' /></p> 224 <?php 225 } 226 227 /** 228 * Prints step 2 for Network installation process. 229 * 230 * @since 3.0.0 231 */ 232 function network_step2( $errors = false ) { 233 global $base, $wpdb; 234 $hostname = get_clean_basedomain(); 235 236 // Wildcard DNS message. 237 if ( is_wp_error( $errors ) ) 238 echo '<div class="error">' . $errors->get_error_message() . '</div>'; 239 240 if ( $_POST ) { 241 $vhost = !allow_subdomain_install() ? false : (bool) $_POST['subdomain_install']; 242 } else { 243 if ( is_multisite() ) { 244 $vhost = is_subdomain_install(); 245 ?> 246 <div class="updated"><p><strong><?php _e( 'Notice: The Network feature is already enabled.' ); ?></strong> <?php _e( 'The original configuration steps are shown here for reference.' ); ?></p></div> 247 <?php } else { 248 $vhost = (bool) $wpdb->get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" ); 249 ?> 250 <div class="error"><p><strong><?php _e('Warning:'); ?></strong> <?php _e( 'An existing WordPress network was detected.' ); ?></p></div> 251 <p><?php _e( 'Please complete the configuration steps. To create a new network, you will need to empty or remove the network database tables.' ); ?></p> 252 <?php 253 } 254 } 255 256 if ( $_POST || ! is_multisite() ) { 257 ?> 258 <h3><?php esc_html_e( 'Enabling the Network' ); ?></h3> 259 <p><?php _e( 'Complete the following steps to enable the features for creating a network of sites.' ); ?></p> 260 <div class="updated inline"><p><?php _e( '<strong>Caution:</strong> We recommend you backup your existing <code>wp-config.php</code> and <code>.htaccess</code> files.' ); ?></p></div> 261 <?php 262 } 263 ?> 264 <ol> 265 <li><p><?php printf( __( 'Create a <code>blogs.dir</code> directory in <code>%s</code>. This directory is used to stored uploaded media for your additional sites and must be writeable by the web server.' ), WP_CONTENT_DIR ); ?></p></li> 266 <li><p><?php printf( __( 'Add the following to your <code>wp-config.php</code> file in <code>%s</code>:' ), ABSPATH ); ?></p> 267 <textarea class="code" readonly="readonly" cols="100" rows="7"> 268 define( 'MULTISITE', true ); 269 define( 'VHOST', '<?php echo $vhost ? 'yes' : 'no'; ?>' ); 270 $base = '<?php echo $base; ?>'; 271 define( 'DOMAIN_CURRENT_SITE', '<?php echo $hostname; ?>' ); 272 define( 'PATH_CURRENT_SITE', '<?php echo $base; ?>' ); 273 define( 'SITE_ID_CURRENT_SITE', 1 ); 274 define( 'BLOG_ID_CURRENT_SITE', 1 );</textarea> 275 <?php 276 $keys_salts = array( 'AUTH_KEY' => '', 'SECURE_AUTH_KEY' => '', 'LOGGED_IN_KEY' => '', 'NONCE_KEY' => '', 'AUTH_SALT' => '', 'SECURE_AUTH_SALT' => '', 'LOGGED_IN_SALT' => '', 'NONCE_SALT' => '' ); 277 foreach ( $keys_salts as $c => $v ) { 278 if ( defined( $c ) ) 279 unset( $keys_salts[ $c ] ); 280 } 281 if ( ! empty( $keys_salts ) ) { 282 $from_api = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' ); 283 if ( is_wp_error( $from_api ) ) { 284 foreach ( $keys_salts as $c => $v ) { 285 $keys_salts[ $c ] = wp_generate_password( 64, true, true ); 286 } 287 } else { 288 $from_api = explode( "\n", wp_remote_retrieve_body( $from_api ) ); 289 foreach ( $keys_salts as $c => $v ) { 290 $keys_salts[ $c ] = substr( array_shift( $from_api ), 28, 64 ); 291 } 292 } 293 $num_keys_salts = count( $keys_salts ); 294 ?> 295 <p><?php 296 echo _n( 'This unique authentication key is also missing from your <code>wp-config.php</code> file.', 'These unique authentication keys are also missing from your <code>wp-config.php</code> file.', $num_keys_salts ); ?> <?php _e( 'To make your installation more secure, you should also add:' ) ?></p> 297 <textarea class="code" readonly="readonly" cols="100" rows="<?php echo $num_keys_salts; ?>"><?php 298 foreach ( $keys_salts as $c => $v ) { 299 echo "\ndefine( '$c', '$v' );"; 300 } 301 ?></textarea> 302 <?php 303 } 304 ?> 305 </li> 306 <?php 307 // Construct an htaccess file. 308 $htaccess_file = 'RewriteEngine On 309 RewriteBase ' . $base . ' 310 RewriteRule ^index\.php$ - [L] 311 312 # uploaded files 313 RewriteRule ^' . ( $vhost ? '' : '([_0-9a-zA-Z-]+/)?' ) . 'files/(.+) wp-includes/ms-files.php?file=$' . ( $vhost ? 1 : 2 ) . ' [L]' . "\n"; 314 315 if ( ! $vhost ) 316 $htaccess_file .= "\n# add a trailing slash to /wp-admin\n" . 'RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]' . "\n"; 317 318 $htaccess_file .= "\n" . 'RewriteCond %{REQUEST_FILENAME} -f [OR] 319 RewriteCond %{REQUEST_FILENAME} -d 320 RewriteRule ^ - [L]'; 321 322 // @todo custom content dir. 323 if ( ! $vhost ) 324 $htaccess_file .= "\n" . 'RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L] 325 RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]'; 326 327 $htaccess_file .= "\nRewriteRule . index.php [L]"; 328 329 ?> 330 <li><p><?php printf( __( 'Add the following to your <code>.htaccess</code> file in <code>%s</code>, replacing other WordPress rules:' ), ABSPATH ); ?></p> 331 <textarea class="code" readonly="readonly" cols="100" rows="<?php echo $vhost ? 11 : 16; ?>"> 332 <?php echo wp_htmledit_pre( $htaccess_file ); ?> 333 </textarea></li> 334 </ol> 335 <?php if ( !is_multisite() ) { ?> 336 <p><?php printf( __( 'Once you complete these steps, your network is enabled and configured.') ); ?> <a href="<?php echo esc_url( admin_url() ); ?>"><?php _e( 'Return to Dashboard' ); ?></a></p> 337 <?php 338 } 339 } 340 341 $base = trailingslashit( stripslashes( dirname( dirname( $_SERVER['SCRIPT_NAME'] ) ) ) ); 342 343 if ( $_POST ) { 344 check_admin_referer( 'install-network-1' ); 345 346 require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' ); 347 // create network tables 348 install_network(); 349 $hostname = get_clean_basedomain(); 350 $subdomain_install = !allow_subdomain_install() ? false : (bool) $_POST['subdomain_install']; 351 if ( ! network_domain_check() ) { 352 $result = populate_network( 1, get_clean_basedomain(), sanitize_email( $_POST['email'] ), $_POST['sitename'], $base, $subdomain_install ); 353 if ( is_wp_error( $result ) ) { 354 if ( 1 == count( $result->get_error_codes() ) && 'no_wildcard_dns' == $result->get_error_code() ) 355 network_step2( $result ); 356 else 357 network_step1( $result ); 358 } else { 359 network_step2(); 360 } 361 } else { 362 network_step2(); 363 } 364 } elseif ( is_multisite() || network_domain_check() ) { 365 network_step2(); 366 } else { 367 network_step1(); 368 } 369 ?> 370 </form> 371 </div> 372 373 <?php include ( './admin-footer.php' ); ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Apr 5 14:26:09 2010 | Cross-referenced by PHPXref 0.7 |