| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | function modify_permalinks($permalink_structure, $category_base = '', $tag_base = '') |
|---|
| 4 | { |
|---|
| 5 | global $wp_rewrite; |
|---|
| 6 | |
|---|
| 7 | require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|---|
| 8 | require_once(ABSPATH . 'wp-admin/includes/misc.php'); |
|---|
| 9 | |
|---|
| 10 | $home_path = get_home_path(); |
|---|
| 11 | $iis7_permalinks = iis7_supports_permalinks(); |
|---|
| 12 | |
|---|
| 13 | $prefix = $blog_prefix = ''; |
|---|
| 14 | if ( ! got_mod_rewrite() && ! $iis7_permalinks ) |
|---|
| 15 | $prefix = '/index.php'; |
|---|
| 16 | if ( is_multisite() && !is_subdomain_install() && is_main_site() ) |
|---|
| 17 | $blog_prefix = '/blog'; |
|---|
| 18 | |
|---|
| 19 | if ( ! empty( $permalink_structure ) ) { |
|---|
| 20 | $permalink_structure = preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $permalink_structure ) ); |
|---|
| 21 | if ( $prefix && $blog_prefix ) |
|---|
| 22 | $permalink_structure = $prefix . preg_replace( '#^/?index\.php#', '', $permalink_structure ); |
|---|
| 23 | else |
|---|
| 24 | $permalink_structure = $blog_prefix . $permalink_structure; |
|---|
| 25 | } |
|---|
| 26 | $wp_rewrite->set_permalink_structure( $permalink_structure ); |
|---|
| 27 | |
|---|
| 28 | if ( ! empty( $category_base ) ) |
|---|
| 29 | $category_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $category_base ) ); |
|---|
| 30 | $wp_rewrite->set_category_base( $category_base ); |
|---|
| 31 | |
|---|
| 32 | if ( ! empty( $tag_base ) ) |
|---|
| 33 | $tag_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $tag_base ) ); |
|---|
| 34 | $wp_rewrite->set_tag_base( $tag_base ); |
|---|
| 35 | |
|---|
| 36 | create_initial_taxonomies(); |
|---|
| 37 | |
|---|
| 38 | $permalink_structure = get_option('permalink_structure'); |
|---|
| 39 | $category_base = get_option('category_base'); |
|---|
| 40 | $tag_base = get_option('tag_base'); |
|---|
| 41 | |
|---|
| 42 | if ( $iis7_permalinks ) { |
|---|
| 43 | if ( ( ! file_exists($home_path . 'web.config') && win_is_writable($home_path) ) || win_is_writable($home_path . 'web.config') ) |
|---|
| 44 | $writable = true; |
|---|
| 45 | else |
|---|
| 46 | $writable = false; |
|---|
| 47 | } else { |
|---|
| 48 | if ( ( ! file_exists($home_path . '.htaccess') && is_writable($home_path) ) || is_writable($home_path . '.htaccess') ) |
|---|
| 49 | $writable = true; |
|---|
| 50 | else |
|---|
| 51 | $writable = false; |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | if ( $wp_rewrite->using_index_permalinks() ) |
|---|
| 55 | $usingpi = true; |
|---|
| 56 | else |
|---|
| 57 | $usingpi = false; |
|---|
| 58 | |
|---|
| 59 | $wp_rewrite->flush_rules(); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | ?> |
|---|