3 * Permalink settings administration panel.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once('./admin.php');
12 if ( ! current_user_can( 'manage_options' ) )
13 wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ) );
15 $title = __('Permalink Settings');
16 $parent_file = 'options-general.php';
18 add_contextual_help($current_screen,
19 '<p>' . __('This screen provides some common options for your default permalinks URL structure.') . '</p>' .
20 '<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>' .
21 '<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>' .
22 '<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>' .
23 '<p>' . __('The Optional fields let you customize the “category” and “tag” base names that will appear in archive URLs. For example, the page listing all posts in the “Uncategorized” category could be <code>/topics/uncategorized</code> instead of <code>/category/uncategorized</code>.') . '</p>' .
24 '<p>' . __('You must click the Save Changes button at the bottom of the screen for new settings to take effect.') . '</p>' .
25 '<p><strong>' . __('For more information:') . '</strong></p>' .
26 '<p>' . __('<a href="http://codex.wordpress.org/Settings_Permalinks_SubPanel" target="_blank">Permalinks Settings Documentation</a>') . '</p>' .
27 '<p>' . __('<a href="http://codex.wordpress.org/Using_Permalinks" target="_blank">Using Permalinks Documentation</a>') . '</p>' .
28 '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
32 * Display JavaScript on the page.
35 * @subpackage Permalink_Settings_Panel
39 <script type="text/javascript">
41 function GetElementsWithClassName(elementName, className) {
42 var allElements = document.getElementsByTagName(elementName);
43 var elemColl = new Array();
44 for (i = 0; i < allElements.length; i++) {
45 if (allElements[i].className == className) {
46 elemColl[elemColl.length] = allElements[i];
53 var inputColl = GetElementsWithClassName('input', 'tog');
54 var structure = document.getElementById('permalink_structure');
56 for (i = 0; i < inputColl.length; i++) {
57 if ( inputColl[i].checked && inputColl[i].value != '') {
58 inputs += inputColl[i].value + ' ';
61 inputs = inputs.substr(0,inputs.length - 1);
62 if ( 'custom' != inputs )
63 structure.value = inputs;
67 if (!document.getElementById) return;
69 var structure = document.getElementById('permalink_structure');
70 structure.onfocus = function () { document.getElementById('custom_selection').checked = 'checked'; }
72 var aInputs = document.getElementsByTagName('input');
74 for (var i = 0; i < aInputs.length; i++) {
75 aInputs[i].onclick = aInputs[i].onkeyup = upit;
79 window.onload = blurry;
84 add_filter('admin_head', 'add_js');
86 include('./admin-header.php');
88 $home_path = get_home_path();
89 $iis7_permalinks = iis7_supports_permalinks();
91 $prefix = $blog_prefix = '';
92 if ( ! got_mod_rewrite() && ! $iis7_permalinks )
93 $prefix = '/index.php';
94 if ( is_multisite() && !is_subdomain_install() && is_main_site() )
95 $blog_prefix = '/blog';
97 if ( isset($_POST['permalink_structure']) || isset($_POST['category_base']) ) {
98 check_admin_referer('update-permalink');
100 if ( isset( $_POST['permalink_structure'] ) ) {
101 if ( isset( $_POST['selection'] ) && 'custom' != $_POST['selection'] )
102 $permalink_structure = $_POST['selection'];
104 $permalink_structure = $_POST['permalink_structure'];
106 if ( ! empty( $permalink_structure ) ) {
107 $permalink_structure = preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $permalink_structure ) );
108 if ( $prefix && $blog_prefix )
109 $permalink_structure = $prefix . preg_replace( '#^/?index\.php#', '', $permalink_structure );
111 $permalink_structure = $blog_prefix . $permalink_structure;
113 $wp_rewrite->set_permalink_structure( $permalink_structure );
116 if ( isset( $_POST['category_base'] ) ) {
117 $category_base = $_POST['category_base'];
118 if ( ! empty( $category_base ) )
119 $category_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $category_base ) );
120 $wp_rewrite->set_category_base( $category_base );
123 if ( isset( $_POST['tag_base'] ) ) {
124 $tag_base = $_POST['tag_base'];
125 if ( ! empty( $tag_base ) )
126 $tag_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $tag_base ) );
127 $wp_rewrite->set_tag_base( $tag_base );
131 $permalink_structure = get_option('permalink_structure');
132 $category_base = get_option('category_base');
133 $tag_base = get_option( 'tag_base' );
135 if ( $iis7_permalinks ) {
136 if ( ( ! file_exists($home_path . 'web.config') && win_is_writable($home_path) ) || win_is_writable($home_path . 'web.config') )
141 if ( ( ! file_exists($home_path . '.htaccess') && is_writable($home_path) ) || is_writable($home_path . '.htaccess') )
147 if ( $wp_rewrite->using_index_permalinks() )
152 $wp_rewrite->flush_rules();
155 if (isset($_POST['submit'])) : ?>
156 <div id="message" class="updated"><p><?php
157 if ( ! is_multisite() ) {
158 if ( $iis7_permalinks ) {
159 if ( $permalink_structure && ! $usingpi && ! $writable )
160 _e('You should update your web.config now');
161 else if ( $permalink_structure && ! $usingpi && $writable )
162 _e('Permalink structure updated. Remove write access on web.config file now!');
164 _e('Permalink structure updated');
166 if ( $permalink_structure && ! $usingpi && ! $writable )
167 _e('You should update your .htaccess now.');
169 _e('Permalink structure updated.');
172 _e('Permalink structure updated.');
179 <?php screen_icon(); ?>
180 <h2><?php echo esc_html( $title ); ?></h2>
182 <form name="form" action="options-permalink.php" method="post">
183 <?php wp_nonce_field('update-permalink') ?>
185 <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>
188 if ( is_multisite() && !is_subdomain_install() && is_main_site() ) {
189 $permalink_structure = preg_replace( '|^/?blog|', '', $permalink_structure );
190 $category_base = preg_replace( '|^/?blog|', '', $category_base );
191 $tag_base = preg_replace( '|^/?blog|', '', $tag_base );
196 $prefix . '/%year%/%monthnum%/%day%/%postname%/',
197 $prefix . '/%year%/%monthnum%/%postname%/',
198 $prefix . '/archives/%post_id%'
201 <h3><?php _e('Common settings'); ?></h3>
202 <table class="form-table">
204 <th><label><input name="selection" type="radio" value="" class="tog" <?php checked('', $permalink_structure); ?> /> <?php _e('Default'); ?></label></th>
205 <td><code><?php echo get_option('home'); ?>/?p=123</code></td>
208 <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>
209 <td><code><?php echo get_option('home') . $blog_prefix . $prefix . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/sample-post/'; ?></code></td>
212 <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>
213 <td><code><?php echo get_option('home') . $blog_prefix . $prefix . '/' . date('Y') . '/' . date('m') . '/sample-post/'; ?></code></td>
216 <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>
217 <td><code><?php echo get_option('home') . $blog_prefix . $prefix; ?>/archives/123</code></td>
221 <label><input name="selection" id="custom_selection" type="radio" value="custom" class="tog" <?php checked( !in_array($permalink_structure, $structures) ); ?> />
222 <?php _e('Custom Structure'); ?>
226 <?php echo $blog_prefix; ?>
227 <input name="permalink_structure" id="permalink_structure" type="text" value="<?php echo esc_attr($permalink_structure); ?>" class="regular-text code" />
232 <h3><?php _e('Optional'); ?></h3>
233 <?php if ( $is_apache || $iis7_permalinks ) : ?>
234 <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>
236 <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>
239 <table class="form-table">
241 <th><label for="category_base"><?php /* translators: prefix for category permalinks */ _e('Category base'); ?></label></th>
242 <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>
245 <th><label for="tag_base"><?php _e('Tag base'); ?></label></th>
246 <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>
248 <?php do_settings_fields('permalink', 'optional'); ?>
251 <?php do_settings_sections('permalink'); ?>
254 <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" />
257 <?php if ( !is_multisite() ) { ?>
258 <?php if ( $iis7_permalinks ) :
259 if ( isset($_POST['submit']) && $permalink_structure && ! $usingpi && ! $writable ) :
260 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’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>/<configuration>/<system.webServer>/<rewrite>/<rules></code> element in <code>web.config</code> file.') ?></p>
262 <form action="options-permalink.php" method="post">
263 <?php wp_nonce_field('update-permalink') ?>
264 <p><textarea rows="9" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_html($wp_rewrite->iis7_url_rewrite_rules()); ?></textarea></p>
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>
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’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">
270 <?php wp_nonce_field('update-permalink') ?>
271 <p><textarea rows="18" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_html($wp_rewrite->iis7_url_rewrite_rules(true)); ?></textarea></p>
273 <p><?php _e('If you temporarily make your site’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>
277 if ( $permalink_structure && ! $usingpi && ! $writable ) : ?>
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’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">
280 <?php wp_nonce_field('update-permalink') ?>
281 <p><textarea rows="6" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_html($wp_rewrite->mod_rewrite_rules()); ?></textarea></p>
285 <?php } // multisite ?>
289 <?php require('./admin-footer.php'); ?>