options-permalink.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <?php
  2. /**
  3. * Permalink Settings Administration Screen.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /** WordPress Administration Bootstrap */
  9. require_once('./admin.php');
  10. if ( ! current_user_can( 'manage_options' ) )
  11. wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ) );
  12. $title = __('Permalink Settings');
  13. $parent_file = 'options-general.php';
  14. add_contextual_help($current_screen,
  15. '<p>' . __('This screen provides some common options for your default permalinks URL structure.') . '</p>' .
  16. '<p>' . __('If you pick an option other than Default, your general URL path with structure tags, terms surrounded by <code>%</code>, will also appear in the custom structure field and your path can be further modified there.') . '</p>' .
  17. '<p>' . __('When you assign multiple categories or tags to a post, only one can show up in the permalink: the lowest numbered category. This applies if your custom structure includes <code>%category%</code> or <code>%tag%</code>.') . '</p>' .
  18. '<p>' . __('Note that permalinks beginning with the category, tag, author or postname structure tags require more advanced server resources. Double-check your hosting details to make sure those are in place or start your permalinks with other structure tags.') . '</p>' .
  19. '<p>' . __('The Optional fields let you customize the &#8220;category&#8221; and &#8220;tag&#8221; base names that will appear in archive URLs. For example, the page listing all posts in the &#8220;Uncategorized&#8221; category could be <code>/topics/uncategorized</code> instead of <code>/category/uncategorized</code>.') . '</p>' .
  20. '<p>' . __('You must click the Save Changes button at the bottom of the screen for new settings to take effect.') . '</p>' .
  21. '<p><strong>' . __('For more information:') . '</strong></p>' .
  22. '<p>' . __('<a href="http://codex.wordpress.org/Settings_Permalinks_Screen" target="_blank">Documentation on Permalinks Settings</a>') . '</p>' .
  23. '<p>' . __('<a href="http://codex.wordpress.org/Using_Permalinks" target="_blank">Documentation on Using Permalinks</a>') . '</p>' .
  24. '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
  25. );
  26. /**
  27. * Display JavaScript on the page.
  28. *
  29. * @package WordPress
  30. * @subpackage Permalink_Settings_Screen
  31. */
  32. function add_js() {
  33. ?>
  34. <script type="text/javascript">
  35. //<![CDATA[
  36. jQuery(document).ready(function() {
  37. jQuery('input:radio.tog').change(function() {
  38. if ( 'custom' == this.value )
  39. return;
  40. jQuery('#permalink_structure').val( this.value );
  41. });
  42. jQuery('#permalink_structure').focus(function() {
  43. jQuery("#custom_selection").attr('checked', 'checked');
  44. });
  45. });
  46. //]]>
  47. </script>
  48. <?php
  49. }
  50. add_filter('admin_head', 'add_js');
  51. include('./admin-header.php');
  52. $home_path = get_home_path();
  53. $iis7_permalinks = iis7_supports_permalinks();
  54. $prefix = $blog_prefix = '';
  55. if ( ! got_mod_rewrite() && ! $iis7_permalinks )
  56. $prefix = '/index.php';
  57. if ( is_multisite() && !is_subdomain_install() && is_main_site() )
  58. $blog_prefix = '/blog';
  59. if ( isset($_POST['permalink_structure']) || isset($_POST['category_base']) ) {
  60. check_admin_referer('update-permalink');
  61. if ( isset( $_POST['permalink_structure'] ) ) {
  62. if ( isset( $_POST['selection'] ) && 'custom' != $_POST['selection'] )
  63. $permalink_structure = $_POST['selection'];
  64. else
  65. $permalink_structure = $_POST['permalink_structure'];
  66. if ( ! empty( $permalink_structure ) ) {
  67. $permalink_structure = preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $permalink_structure ) );
  68. if ( $prefix && $blog_prefix )
  69. $permalink_structure = $prefix . preg_replace( '#^/?index\.php#', '', $permalink_structure );
  70. else
  71. $permalink_structure = $blog_prefix . $permalink_structure;
  72. }
  73. $wp_rewrite->set_permalink_structure( $permalink_structure );
  74. }
  75. if ( isset( $_POST['category_base'] ) ) {
  76. $category_base = $_POST['category_base'];
  77. if ( ! empty( $category_base ) )
  78. $category_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $category_base ) );
  79. $wp_rewrite->set_category_base( $category_base );
  80. }
  81. if ( isset( $_POST['tag_base'] ) ) {
  82. $tag_base = $_POST['tag_base'];
  83. if ( ! empty( $tag_base ) )
  84. $tag_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $tag_base ) );
  85. $wp_rewrite->set_tag_base( $tag_base );
  86. }
  87. create_initial_taxonomies();
  88. }
  89. $permalink_structure = get_option('permalink_structure');
  90. $category_base = get_option('category_base');
  91. $tag_base = get_option( 'tag_base' );
  92. if ( $iis7_permalinks ) {
  93. if ( ( ! file_exists($home_path . 'web.config') && win_is_writable($home_path) ) || win_is_writable($home_path . 'web.config') )
  94. $writable = true;
  95. else
  96. $writable = false;
  97. } else {
  98. if ( ( ! file_exists($home_path . '.htaccess') && is_writable($home_path) ) || is_writable($home_path . '.htaccess') )
  99. $writable = true;
  100. else
  101. $writable = false;
  102. }
  103. if ( $wp_rewrite->using_index_permalinks() )
  104. $usingpi = true;
  105. else
  106. $usingpi = false;
  107. $wp_rewrite->flush_rules();
  108. if (isset($_POST['submit'])) : ?>
  109. <div id="message" class="updated"><p><?php
  110. if ( ! is_multisite() ) {
  111. if ( $iis7_permalinks ) {
  112. if ( $permalink_structure && ! $usingpi && ! $writable )
  113. _e('You should update your web.config now');
  114. else if ( $permalink_structure && ! $usingpi && $writable )
  115. _e('Permalink structure updated. Remove write access on web.config file now!');
  116. else
  117. _e('Permalink structure updated');
  118. } else {
  119. if ( $permalink_structure && ! $usingpi && ! $writable )
  120. _e('You should update your .htaccess now.');
  121. else
  122. _e('Permalink structure updated.');
  123. }
  124. } else {
  125. _e('Permalink structure updated.');
  126. }
  127. ?>
  128. </p></div>
  129. <?php endif; ?>
  130. <div class="wrap">
  131. <?php screen_icon(); ?>
  132. <h2><?php echo esc_html( $title ); ?></h2>
  133. <form name="form" action="options-permalink.php" method="post">
  134. <?php wp_nonce_field('update-permalink') ?>
  135. <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>
  136. <?php
  137. if ( is_multisite() && !is_subdomain_install() && is_main_site() ) {
  138. $permalink_structure = preg_replace( '|^/?blog|', '', $permalink_structure );
  139. $category_base = preg_replace( '|^/?blog|', '', $category_base );
  140. $tag_base = preg_replace( '|^/?blog|', '', $tag_base );
  141. }
  142. $structures = array(
  143. '',
  144. $prefix . '/%year%/%monthnum%/%day%/%postname%/',
  145. $prefix . '/%year%/%monthnum%/%postname%/',
  146. $prefix . '/archives/%post_id%'
  147. );
  148. ?>
  149. <h3><?php _e('Common settings'); ?></h3>
  150. <table class="form-table">
  151. <tr>
  152. <th><label><input name="selection" type="radio" value="" class="tog" <?php checked('', $permalink_structure); ?> /> <?php _e('Default'); ?></label></th>
  153. <td><code><?php echo get_option('home'); ?>/?p=123</code></td>
  154. </tr>
  155. <tr>
  156. <th><label><input name="selection" type="radio" value="<?php echo esc_attr($structures[1]); ?>" class="tog" <?php checked($structures[1], $permalink_structure); ?> /> <?php _e('Day and name'); ?></label></th>
  157. <td><code><?php echo get_option('home') . $blog_prefix . $prefix . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/sample-post/'; ?></code></td>
  158. </tr>
  159. <tr>
  160. <th><label><input name="selection" type="radio" value="<?php echo esc_attr($structures[2]); ?>" class="tog" <?php checked($structures[2], $permalink_structure); ?> /> <?php _e('Month and name'); ?></label></th>
  161. <td><code><?php echo get_option('home') . $blog_prefix . $prefix . '/' . date('Y') . '/' . date('m') . '/sample-post/'; ?></code></td>
  162. </tr>
  163. <tr>
  164. <th><label><input name="selection" type="radio" value="<?php echo esc_attr($structures[3]); ?>" class="tog" <?php checked($structures[3], $permalink_structure); ?> /> <?php _e('Numeric'); ?></label></th>
  165. <td><code><?php echo get_option('home') . $blog_prefix . $prefix; ?>/archives/123</code></td>
  166. </tr>
  167. <tr>
  168. <th>
  169. <label><input name="selection" id="custom_selection" type="radio" value="custom" class="tog" <?php checked( !in_array($permalink_structure, $structures) ); ?> />
  170. <?php _e('Custom Structure'); ?>
  171. </label>
  172. </th>
  173. <td>
  174. <?php echo $blog_prefix; ?>
  175. <input name="permalink_structure" id="permalink_structure" type="text" value="<?php echo esc_attr($permalink_structure); ?>" class="regular-text code" />
  176. </td>
  177. </tr>
  178. </table>
  179. <h3><?php _e('Optional'); ?></h3>
  180. <?php if ( $is_apache || $iis7_permalinks ) : ?>
  181. <p><?php _e('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 <kbd>topics</kbd> as your category base would make your category links like <code>http://example.org/topics/uncategorized/</code>. If you leave these blank the defaults will be used.') ?></p>
  182. <?php else : ?>
  183. <p><?php _e('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/index.php/topics/uncategorized/</code>. If you leave these blank the defaults will be used.') ?></p>
  184. <?php endif; ?>
  185. <table class="form-table">
  186. <tr>
  187. <th><label for="category_base"><?php /* translators: prefix for category permalinks */ _e('Category base'); ?></label></th>
  188. <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>
  189. </tr>
  190. <tr>
  191. <th><label for="tag_base"><?php _e('Tag base'); ?></label></th>
  192. <td><?php echo $blog_prefix; ?> <input name="tag_base" id="tag_base" type="text" value="<?php echo esc_attr($tag_base); ?>" class="regular-text code" /></td>
  193. </tr>
  194. <?php do_settings_fields('permalink', 'optional'); ?>
  195. </table>
  196. <?php do_settings_sections('permalink'); ?>
  197. <?php submit_button(); ?>
  198. </form>
  199. <?php if ( !is_multisite() ) { ?>
  200. <?php if ( $iis7_permalinks ) :
  201. if ( isset($_POST['submit']) && $permalink_structure && ! $usingpi && ! $writable ) :
  202. if ( file_exists($home_path . 'web.config') ) : ?>
  203. <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>
  204. <form action="options-permalink.php" method="post">
  205. <?php wp_nonce_field('update-permalink') ?>
  206. <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>
  207. </form>
  208. <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>
  209. <?php else : ?>
  210. <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>
  211. <form action="options-permalink.php" method="post">
  212. <?php wp_nonce_field('update-permalink') ?>
  213. <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>
  214. </form>
  215. <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>
  216. <?php endif; ?>
  217. <?php endif; ?>
  218. <?php else :
  219. if ( $permalink_structure && ! $usingpi && ! $writable ) : ?>
  220. <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>
  221. <form action="options-permalink.php" method="post">
  222. <?php wp_nonce_field('update-permalink') ?>
  223. <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>
  224. </form>
  225. <?php endif; ?>
  226. <?php endif; ?>
  227. <?php } // multisite ?>
  228. </div>
  229. <?php require('./admin-footer.php'); ?>