wp/wp-admin/options-permalink.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
    39 		'<p>' . __('You must click the Save Changes button at the bottom of the screen for new settings to take effect.') . '</p>',
    39 		'<p>' . __('You must click the Save Changes button at the bottom of the screen for new settings to take effect.') . '</p>',
    40 ) );
    40 ) );
    41 
    41 
    42 get_current_screen()->set_help_sidebar(
    42 get_current_screen()->set_help_sidebar(
    43 	'<p><strong>' . __('For more information:') . '</strong></p>' .
    43 	'<p><strong>' . __('For more information:') . '</strong></p>' .
    44 	'<p>' . __('<a href="http://codex.wordpress.org/Settings_Permalinks_Screen" target="_blank">Documentation on Permalinks Settings</a>') . '</p>' .
    44 	'<p>' . __('<a href="https://codex.wordpress.org/Settings_Permalinks_Screen" target="_blank">Documentation on Permalinks Settings</a>') . '</p>' .
    45 	'<p>' . __('<a href="http://codex.wordpress.org/Using_Permalinks" target="_blank">Documentation on Using Permalinks</a>') . '</p>' .
    45 	'<p>' . __('<a href="https://codex.wordpress.org/Using_Permalinks" target="_blank">Documentation on Using Permalinks</a>') . '</p>' .
    46 	'<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
    46 	'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
    47 );
    47 );
    48 
    48 
    49 /**
    49 /**
    50  * Display JavaScript on the page.
    50  * Display JavaScript on the page.
    51  *
    51  *
    52  * @since 3.5.0
    52  * @since 3.5.0
    53  */
    53  */
    54 function options_permalink_add_js() {
    54 function options_permalink_add_js() {
    55 	?>
    55 	?>
    56 <script type="text/javascript">
    56 <script type="text/javascript">
    57 //<![CDATA[
       
    58 jQuery(document).ready(function() {
    57 jQuery(document).ready(function() {
    59 	jQuery('.permalink-structure input:radio').change(function() {
    58 	jQuery('.permalink-structure input:radio').change(function() {
    60 		if ( 'custom' == this.value )
    59 		if ( 'custom' == this.value )
    61 			return;
    60 			return;
    62 		jQuery('#permalink_structure').val( this.value );
    61 		jQuery('#permalink_structure').val( this.value );
    63 	});
    62 	});
    64 	jQuery('#permalink_structure').focus(function() {
    63 	jQuery('#permalink_structure').focus(function() {
    65 		jQuery("#custom_selection").attr('checked', 'checked');
    64 		jQuery("#custom_selection").attr('checked', 'checked');
    66 	});
    65 	});
    67 });
    66 });
    68 //]]>
       
    69 </script>
    67 </script>
    70 <?php
    68 <?php
    71 }
    69 }
    72 add_filter('admin_head', 'options_permalink_add_js');
    70 add_filter('admin_head', 'options_permalink_add_js');
    73 
    71 
   115 
   113 
   116 	wp_redirect( admin_url( 'options-permalink.php?settings-updated=true' ) );
   114 	wp_redirect( admin_url( 'options-permalink.php?settings-updated=true' ) );
   117 	exit;
   115 	exit;
   118 }
   116 }
   119 
   117 
   120 $permalink_structure = get_option('permalink_structure');
   118 $permalink_structure = get_option( 'permalink_structure' );
   121 $category_base = get_option('category_base');
   119 $category_base       = get_option( 'category_base' );
   122 $tag_base = get_option( 'tag_base' );
   120 $tag_base            = get_option( 'tag_base' );
       
   121 $update_required     = false;
   123 
   122 
   124 if ( $iis7_permalinks ) {
   123 if ( $iis7_permalinks ) {
   125 	if ( ( ! file_exists($home_path . 'web.config') && win_is_writable($home_path) ) || win_is_writable($home_path . 'web.config') )
   124 	if ( ( ! file_exists($home_path . 'web.config') && win_is_writable($home_path) ) || win_is_writable($home_path . 'web.config') )
   126 		$writable = true;
   125 		$writable = true;
   127 	else
   126 	else
   128 		$writable = false;
   127 		$writable = false;
   129 } elseif ( $is_nginx ) {
   128 } elseif ( $is_nginx ) {
   130 	$writable = false;
   129 	$writable = false;
   131 } else {
   130 } else {
   132 	if ( ( ! file_exists($home_path . '.htaccess') && is_writable($home_path) ) || is_writable($home_path . '.htaccess') )
   131 	if ( ( ! file_exists( $home_path . '.htaccess' ) && is_writable( $home_path ) ) || is_writable( $home_path . '.htaccess' ) ) {
   133 		$writable = true;
   132 		$writable = true;
   134 	else
   133 	} else {
   135 		$writable = false;
   134 		$writable = false;
       
   135 		$existing_rules  = array_filter( extract_from_markers( $home_path . '.htaccess', 'WordPress' ) );
       
   136 		$new_rules       = array_filter( explode( "\n", $wp_rewrite->mod_rewrite_rules() ) );
       
   137 		$update_required = ( $new_rules !== $existing_rules );
       
   138 	}
   136 }
   139 }
   137 
   140 
   138 if ( $wp_rewrite->using_index_permalinks() )
   141 if ( $wp_rewrite->using_index_permalinks() )
   139 	$usingpi = true;
   142 	$usingpi = true;
   140 else
   143 else
   143 flush_rewrite_rules();
   146 flush_rewrite_rules();
   144 
   147 
   145 require( ABSPATH . 'wp-admin/admin-header.php' );
   148 require( ABSPATH . 'wp-admin/admin-header.php' );
   146 
   149 
   147 if ( ! empty( $_GET['settings-updated'] ) ) : ?>
   150 if ( ! empty( $_GET['settings-updated'] ) ) : ?>
   148 <div id="message" class="updated"><p><?php
   151 <div id="message" class="updated notice is-dismissible"><p><?php
   149 if ( ! is_multisite() ) {
   152 if ( ! is_multisite() ) {
   150 	if ( $iis7_permalinks ) {
   153 	if ( $iis7_permalinks ) {
   151 		if ( $permalink_structure && ! $usingpi && ! $writable )
   154 		if ( $permalink_structure && ! $usingpi && ! $writable ) {
   152 			_e('You should update your web.config now.');
   155 			_e('You should update your web.config now.');
   153 		else if ( $permalink_structure && ! $usingpi && $writable )
   156 		} elseif ( $permalink_structure && ! $usingpi && $writable ) {
   154 			_e('Permalink structure updated. Remove write access on web.config file now!');
   157 			_e('Permalink structure updated. Remove write access on web.config file now!');
   155 		else
   158 		} else {
   156 			_e('Permalink structure updated.');
   159 			_e('Permalink structure updated.');
       
   160 		}
   157 	} elseif ( $is_nginx ) {
   161 	} elseif ( $is_nginx ) {
   158 		_e('Permalink structure updated.');
   162 		_e('Permalink structure updated.');
   159 	} else {
   163 	} else {
   160 		if ( $permalink_structure && ! $usingpi && ! $writable )
   164 		if ( $permalink_structure && ! $usingpi && ! $writable && $update_required ) {
   161 			_e('You should update your .htaccess now.');
   165 			_e('You should update your .htaccess now.');
   162 		else
   166 		} else {
   163 			_e('Permalink structure updated.');
   167 			_e('Permalink structure updated.');
       
   168 		}
   164 	}
   169 	}
   165 } else {
   170 } else {
   166 	_e('Permalink structure updated.');
   171 	_e('Permalink structure updated.');
   167 }
   172 }
   168 ?>
   173 ?>
   169 </p></div>
   174 </p></div>
   170 <?php endif; ?>
   175 <?php endif; ?>
   171 
   176 
   172 <div class="wrap">
   177 <div class="wrap">
   173 <?php screen_icon(); ?>
       
   174 <h2><?php echo esc_html( $title ); ?></h2>
   178 <h2><?php echo esc_html( $title ); ?></h2>
   175 
   179 
   176 <form name="form" action="options-permalink.php" method="post">
   180 <form name="form" action="options-permalink.php" method="post">
   177 <?php wp_nonce_field('update-permalink') ?>
   181 <?php wp_nonce_field('update-permalink') ?>
   178 
   182 
   179   <p><?php _e('By default WordPress uses web <abbr title="Universal Resource Locator">URL</abbr>s which have question marks and lots of numbers in them; however, WordPress offers you the ability to create a custom URL structure for your permalinks and archives. This can improve the aesthetics, usability, and forward-compatibility of your links. A <a href="http://codex.wordpress.org/Using_Permalinks">number of tags are available</a>, and here are some examples to get you started.'); ?></p>
   183   <p><?php _e('By default WordPress uses web <abbr title="Universal Resource Locator">URL</abbr>s which have question marks and lots of numbers in them; however, WordPress offers you the ability to create a custom URL structure for your permalinks and archives. This can improve the aesthetics, usability, and forward-compatibility of your links. A <a href="https://codex.wordpress.org/Using_Permalinks">number of tags are available</a>, and here are some examples to get you started.'); ?></p>
   180 
   184 
   181 <?php
   185 <?php
   182 if ( is_multisite() && !is_subdomain_install() && is_main_site() ) {
   186 if ( is_multisite() && !is_subdomain_install() && is_main_site() ) {
   183 	$permalink_structure = preg_replace( '|^/?blog|', '', $permalink_structure );
   187 	$permalink_structure = preg_replace( '|^/?blog|', '', $permalink_structure );
   184 	$category_base = preg_replace( '|^/?blog|', '', $category_base );
   188 	$category_base = preg_replace( '|^/?blog|', '', $category_base );
   227 		</td>
   231 		</td>
   228 	</tr>
   232 	</tr>
   229 </table>
   233 </table>
   230 
   234 
   231 <h3 class="title"><?php _e('Optional'); ?></h3>
   235 <h3 class="title"><?php _e('Optional'); ?></h3>
   232 <?php
       
   233 $suffix = $prefix;
       
   234 if ( $suffix )
       
   235 	$suffix = ltrim( $suffix, '/' ) . '/';
       
   236 ?>
       
   237 <p><?php
   236 <p><?php
   238 /* translators: %s is a placeholder that must come at the start of the URL path. */
   237 /* translators: %s is a placeholder that must come at the start of the URL. */
   239 printf( __('If you like, you may enter custom structures for your category and tag <abbr title="Universal Resource Locator">URL</abbr>s here. For example, using <code>topics</code> as your category base would make your category links like <code>http://example.org/%stopics/uncategorized/</code>. If you leave these blank the defaults will be used.'), $suffix ); ?></p>
   238 printf( __('If you like, you may enter custom structures for your category and tag <abbr title="Universal Resource Locator">URL</abbr>s here. For example, using <code>topics</code> as your category base would make your category links like <code>%s/topics/uncategorized/</code>. If you leave these blank the defaults will be used.'), get_option('home') . $blog_prefix . $prefix ); ?></p>
   240 
   239 
   241 <table class="form-table">
   240 <table class="form-table">
   242 	<tr>
   241 	<tr>
   243 		<th><label for="category_base"><?php /* translators: prefix for category permalinks */ _e('Category base'); ?></label></th>
   242 		<th><label for="category_base"><?php /* translators: prefix for category permalinks */ _e('Category base'); ?></label></th>
   244 		<td><?php echo $blog_prefix; ?> <input name="category_base" id="category_base" type="text" value="<?php echo esc_attr( $category_base ); ?>" class="regular-text code" /></td>
   243 		<td><?php echo $blog_prefix; ?> <input name="category_base" id="category_base" type="text" value="<?php echo esc_attr( $category_base ); ?>" class="regular-text code" /></td>
   256   </form>
   255   </form>
   257 <?php if ( !is_multisite() ) { ?>
   256 <?php if ( !is_multisite() ) { ?>
   258 <?php if ( $iis7_permalinks ) :
   257 <?php if ( $iis7_permalinks ) :
   259 	if ( isset($_POST['submit']) && $permalink_structure && ! $usingpi && ! $writable ) :
   258 	if ( isset($_POST['submit']) && $permalink_structure && ! $usingpi && ! $writable ) :
   260 		if ( file_exists($home_path . 'web.config') ) : ?>
   259 		if ( file_exists($home_path . 'web.config') ) : ?>
   261 <p><?php _e('If your <code>web.config</code> file were <a href="http://codex.wordpress.org/Changing_File_Permissions">writable</a>, we could do this automatically, but it isn&#8217;t so this is the url rewrite rule you should have in your <code>web.config</code> file. Click in the field and press <kbd>CTRL + a</kbd> to select all. Then insert this rule inside of the <code>/&lt;configuration&gt;/&lt;system.webServer&gt;/&lt;rewrite&gt;/&lt;rules&gt;</code> element in <code>web.config</code> file.') ?></p>
   260 <p><?php _e('If your <code>web.config</code> file were <a href="https://codex.wordpress.org/Changing_File_Permissions">writable</a>, we could do this automatically, but it isn&#8217;t so this is the url rewrite rule you should have in your <code>web.config</code> file. Click in the field and press <kbd>CTRL + a</kbd> to select all. Then insert this rule inside of the <code>/&lt;configuration&gt;/&lt;system.webServer&gt;/&lt;rewrite&gt;/&lt;rules&gt;</code> element in <code>web.config</code> file.') ?></p>
   262 <form action="options-permalink.php" method="post">
   261 <form action="options-permalink.php" method="post">
   263 <?php wp_nonce_field('update-permalink') ?>
   262 <?php wp_nonce_field('update-permalink') ?>
   264 	<p><textarea rows="9" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_textarea( $wp_rewrite->iis7_url_rewrite_rules() ); ?></textarea></p>
   263 	<p><textarea rows="9" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_textarea( $wp_rewrite->iis7_url_rewrite_rules() ); ?></textarea></p>
   265 </form>
   264 </form>
   266 <p><?php _e('If you temporarily make your <code>web.config</code> file writable for us to generate rewrite rules automatically, do not forget to revert the permissions after rule has been saved.') ?></p>
   265 <p><?php _e('If you temporarily make your <code>web.config</code> file writable for us to generate rewrite rules automatically, do not forget to revert the permissions after rule has been saved.') ?></p>
   267 		<?php else : ?>
   266 		<?php else : ?>
   268 <p><?php _e('If the root directory of your site were <a href="http://codex.wordpress.org/Changing_File_Permissions">writable</a>, we could do this automatically, but it isn&#8217;t so this is the url rewrite rule you should have in your <code>web.config</code> file. Create a new file, called <code>web.config</code> in the root directory of your site. Click in the field and press <kbd>CTRL + a</kbd> to select all. Then insert this code into the <code>web.config</code> file.') ?></p>
   267 <p><?php _e('If the root directory of your site were <a href="https://codex.wordpress.org/Changing_File_Permissions">writable</a>, we could do this automatically, but it isn&#8217;t so this is the url rewrite rule you should have in your <code>web.config</code> file. Create a new file, called <code>web.config</code> in the root directory of your site. Click in the field and press <kbd>CTRL + a</kbd> to select all. Then insert this code into the <code>web.config</code> file.') ?></p>
   269 <form action="options-permalink.php" method="post">
   268 <form action="options-permalink.php" method="post">
   270 <?php wp_nonce_field('update-permalink') ?>
   269 <?php wp_nonce_field('update-permalink') ?>
   271 	<p><textarea rows="18" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_textarea( $wp_rewrite->iis7_url_rewrite_rules(true) ); ?></textarea></p>
   270 	<p><textarea rows="18" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_textarea( $wp_rewrite->iis7_url_rewrite_rules(true) ); ?></textarea></p>
   272 </form>
   271 </form>
   273 <p><?php _e('If you temporarily make your site&#8217;s root directory writable for us to generate the <code>web.config</code> file automatically, do not forget to revert the permissions after the file has been created.') ?></p>
   272 <p><?php _e('If you temporarily make your site&#8217;s root directory writable for us to generate the <code>web.config</code> file automatically, do not forget to revert the permissions after the file has been created.') ?></p>
   274 		<?php endif; ?>
   273 		<?php endif; ?>
   275 	<?php endif; ?>
   274 	<?php endif; ?>
   276 <?php elseif ( ! $is_nginx ) :
   275 <?php elseif ( ! $is_nginx ) :
   277 	if ( $permalink_structure && ! $usingpi && ! $writable ) : ?>
   276 	if ( $permalink_structure && ! $usingpi && ! $writable && $update_required ) : ?>
   278 <p><?php _e('If your <code>.htaccess</code> file were <a href="http://codex.wordpress.org/Changing_File_Permissions">writable</a>, we could do this automatically, but it isn&#8217;t so these are the mod_rewrite rules you should have in your <code>.htaccess</code> file. Click in the field and press <kbd>CTRL + a</kbd> to select all.') ?></p>
   277 <p><?php _e('If your <code>.htaccess</code> file were <a href="https://codex.wordpress.org/Changing_File_Permissions">writable</a>, we could do this automatically, but it isn&#8217;t so these are the mod_rewrite rules you should have in your <code>.htaccess</code> file. Click in the field and press <kbd>CTRL + a</kbd> to select all.') ?></p>
   279 <form action="options-permalink.php" method="post">
   278 <form action="options-permalink.php" method="post">
   280 <?php wp_nonce_field('update-permalink') ?>
   279 <?php wp_nonce_field('update-permalink') ?>
   281 	<p><textarea rows="6" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_textarea( $wp_rewrite->mod_rewrite_rules() ); ?></textarea></p>
   280 	<p><textarea rows="6" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_textarea( $wp_rewrite->mod_rewrite_rules() ); ?></textarea></p>
   282 </form>
   281 </form>
   283 	<?php endif; ?>
   282 	<?php endif; ?>