flush_rules();
}
function AS_filter_author_link( $author_link ) {
preg_match("|^(.+)/(.+?)/$|", $author_link, $matches );
$author_nickname = $matches[2];
return get_option("siteurl") . "/" . get_option("AS_author_slug") . "/" . $author_nickname . "/";
}
function AS_add_options_page() {
add_options_page("Author slug", "Author slug", "manage_options", __FILE__, "AS_options_page");
}
function AS_options_page() {
if( isset( $_POST['AS_author_slug'] ) ) {
update_option( 'AS_author_slug', $_POST['AS_author_slug'] );
echo '
';
}
$author_slug = get_option('AS_author_slug');
?>
}
function AS_generate_rewrite_rules( $wp_rewrite ) {
$author_slug = get_option('AS_author_slug');
$new_rules = array(
$author_slug . '/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?author_name=$matches[1]&paged=$matches[2]',
$author_slug . '/(.+?)/?$' => 'index.php?author_name=$matches[1]'
);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
return $wp_rewrite->rules;
}
if( ! is_admin() ) {
add_action('init', 'AS_flush');
add_action('generate_rewrite_rules', 'AS_generate_rewrite_rules');
add_filter('author_link', 'AS_filter_author_link');
}
else {
add_action('admin_menu', 'AS_add_options_page');
}
register_activation_hook( __FILE__, 'AS_activate' );