2003-10-26 05:25:26 +00:00
<? php
$title = 'Permalink Options' ;
2004-04-19 08:09:27 +00:00
$parent_file = 'options-general.php' ;
2003-10-26 05:25:26 +00:00
function add_magic_quotes ( $array ) {
foreach ( $array as $k => $v ) {
if ( is_array ( $v )) {
$array [ $k ] = add_magic_quotes ( $v );
} else {
$array [ $k ] = addslashes ( $v );
}
}
return $array ;
}
if ( ! get_magic_quotes_gpc ()) {
2004-04-20 22:56:47 +00:00
$_GET = add_magic_quotes ( $_GET );
$_POST = add_magic_quotes ( $_POST );
$_COOKIE = add_magic_quotes ( $_COOKIE );
2003-10-26 05:25:26 +00:00
}
2003-12-18 09:36:13 +00:00
$wpvarstoreset = array ( 'action' , 'standalone' , 'option_group_id' );
for ( $i = 0 ; $i < count ( $wpvarstoreset ); $i += 1 ) {
$wpvar = $wpvarstoreset [ $i ];
if ( ! isset ( $$wpvar )) {
2004-04-20 22:56:47 +00:00
if ( empty ( $_POST [ " $wpvar " ])) {
if ( empty ( $_GET [ " $wpvar " ])) {
2003-12-18 09:36:13 +00:00
$$wpvar = '' ;
2003-10-26 05:25:26 +00:00
} else {
2004-04-20 22:56:47 +00:00
$$wpvar = $_GET [ " $wpvar " ];
2003-10-26 05:25:26 +00:00
}
} else {
2004-04-20 22:56:47 +00:00
$$wpvar = $_POST [ " $wpvar " ];
2003-10-26 05:25:26 +00:00
}
}
}
require_once ( 'optionhandler.php' );
2004-04-20 22:56:47 +00:00
if ( $_POST [ 'Submit' ] == 'Update' ) {
update_option ( 'permalink_structure' , $_POST [ 'permalink_structure' ]);
$permalink_structure = $_POST [ 'permalink_structure' ];
2003-10-26 05:25:26 +00:00
} else {
$permalink_structure = get_settings ( 'permalink_structure' );
}
switch ( $action ) {
default :
$standalone = 0 ;
2003-12-11 00:22:36 +00:00
include_once ( 'admin-header.php' );
2004-04-11 08:15:10 +00:00
if ( $user_level <= 6 ) {
2004-03-01 19:55:45 +00:00
die ( "You have do not have sufficient permissions to edit the options for this blog." );
2003-10-26 05:25:26 +00:00
}
2004-04-11 08:15:10 +00:00
include ( 'options-head.php' );
2003-10-26 05:25:26 +00:00
?>
<div class="wrap">
<h2>Edit Permalink Structure</h2>
<p>WordPress offers you the ability to create a custom URI structure for your permalinks and archives. The following “tags” are available:</p>
<ul>
2004-01-12 00:55:14 +00:00
<li><code>%year%</code> --- The year of the post, 4 digits, for example <code>2004</code> </li>
2004-01-14 06:47:52 +00:00
<li><code>%monthnum%</code> --- Month of the year, for example <code>05</code></li>
2004-01-12 00:55:14 +00:00
<li><code>%day% </code>--- Day of the month, for example <code>28</code></li>
<li><code>%postname%</code> --- A sanitized version of the title of the post. So "This Is A Great Post!" becomes "<code>this-is-a-great-post</code>" in the URI </li>
<li><code>%post_id%</code> --- The unique ID # of the post, for example <code>423</code> <strong></strong></li>
2003-10-26 05:25:26 +00:00
</ul>
2004-04-15 07:53:45 +00:00
<p>So for example a value like </p>
<p><code>/archives/%year%/%monthnum%/%day%/%postname%/</code> </p>
<p>would give you a permalink like </p>
<p><code>/archives/2003/05/23/my-cheese-sandwich/</code> . </p>
<p> In general for this you must use mod_rewrite, however if you put a filename at the beginning WordPress will attempt to use that to pass the arguments, example:</p>
<p><code>/index.php/archives/%year%/%monthnum%/%day%/%postname%/</code> </p>
<p>If you use this option you can ignore the mod_rewrite rules. </p>
2003-12-11 00:22:36 +00:00
<form name="form" action="options-permalink.php" method="post">
2003-10-26 05:25:26 +00:00
<p>Use the template tags above to create a virtual site structure:</p>
<p>
<input name="permalink_structure" type="text" style="width: 100%;" value="<?php echo $permalink_structure; ?>" />
</p>
2004-04-19 08:09:27 +00:00
<p class="submit">
<input type="submit" name="Submit" value="Update Permalink Structure">
2003-10-26 05:25:26 +00:00
</p>
</form>
2003-10-30 15:03:30 +00:00
<?php
if ($permalink_structure) {
?>
2003-10-26 05:25:26 +00:00
<p>Using the permalink structure value you currently have, <code><?php echo $permalink_structure; ?></code>, these are the mod_rewrite rules you should have in your <code>.htaccess</code> file.</p>
<?php
2004-02-26 16:15:48 +00:00
$site_root = str_replace('http://', '', trim(get_settings('siteurl')));
2003-10-26 05:25:26 +00:00
$site_root = preg_replace('|([^/]*)(.*)|i', '$2', $site_root);
if ('/' != substr($site_root, -1)) $site_root = $site_root . '/';
?>
2003-12-10 19:06:28 +00:00
<form action"">
2004-04-15 07:53:45 +00:00
<p>
<textarea rows="5" style="width: 100%;">RewriteEngine On
2003-12-10 19:06:28 +00:00
RewriteBase <?php echo $site_root; ?>
2004-03-08 05:12:11 +00:00
<?php
2004-03-09 03:55:01 +00:00
$rewrite = rewrite_rules('', $permalink_structure);
2004-03-08 05:12:11 +00:00
foreach ($rewrite as $match => $query) {
echo 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA]\n";
}
2004-04-15 07:53:45 +00:00
?>
</textarea>
</p>
<p>If your <code>.htaccess</code> file is writable by WordPress, you can <a href="templates.php?file=.htaccess">edit it through your template interface</a>.</p>
2004-03-08 05:12:11 +00:00
</form>
2003-10-26 05:25:26 +00:00
</div>
<?php
2003-10-30 15:03:30 +00:00
} else {
?>
<p>
You are not currently using customized permalinks. No special mod_rewrite
rules are needed.
</p>
<?php
}
echo "</div>\n";
2003-10-26 05:25:26 +00:00
break;
}
2004-04-11 08:15:10 +00:00
include("admin-footer.php")
?>