~canonical-sysadmins/wordpress/4.8.1

« back to all changes in this revision

Viewing changes to wp-admin/options-permalink.php

  • Committer: Barry Price
  • Date: 2016-08-17 04:49:28 UTC
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: barry.price@canonical.com-20160817044928-viijiwb4tl8jwzmp
new upstream release 4.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
require_once( dirname( __FILE__ ) . '/admin.php' );
11
11
 
12
12
if ( ! current_user_can( 'manage_options' ) )
13
 
        wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ) );
 
13
        wp_die( __( 'Sorry, you are not allowed to manage options for this site.' ) );
14
14
 
15
15
$title = __('Permalink Settings');
16
16
$parent_file = 'options-general.php';
66
66
        $blog_prefix = '/blog';
67
67
}
68
68
 
 
69
$category_base       = get_option( 'category_base' );
 
70
$tag_base            = get_option( 'tag_base' );
 
71
$update_required     = false;
 
72
 
 
73
if ( $iis7_permalinks ) {
 
74
        if ( ( ! file_exists($home_path . 'web.config') && win_is_writable($home_path) ) || win_is_writable($home_path . 'web.config') )
 
75
                $writable = true;
 
76
        else
 
77
                $writable = false;
 
78
} elseif ( $is_nginx ) {
 
79
        $writable = false;
 
80
} else {
 
81
        if ( ( ! file_exists( $home_path . '.htaccess' ) && is_writable( $home_path ) ) || is_writable( $home_path . '.htaccess' ) ) {
 
82
                $writable = true;
 
83
        } else {
 
84
                $writable = false;
 
85
                $existing_rules  = array_filter( extract_from_markers( $home_path . '.htaccess', 'WordPress' ) );
 
86
                $new_rules       = array_filter( explode( "\n", $wp_rewrite->mod_rewrite_rules() ) );
 
87
                $update_required = ( $new_rules !== $existing_rules );
 
88
        }
 
89
}
 
90
 
 
91
$using_index_permalinks = $wp_rewrite->using_index_permalinks();
 
92
 
69
93
if ( isset($_POST['permalink_structure']) || isset($_POST['category_base']) ) {
70
94
        check_admin_referer('update-permalink');
71
95
 
82
106
                        else
83
107
                                $permalink_structure = $blog_prefix . $permalink_structure;
84
108
                }
 
109
 
 
110
                $permalink_structure = sanitize_option( 'permalink_structure', $permalink_structure );
 
111
 
85
112
                $wp_rewrite->set_permalink_structure( $permalink_structure );
86
113
        }
87
114
 
99
126
                $wp_rewrite->set_tag_base( $tag_base );
100
127
        }
101
128
 
 
129
        $message = __( 'Permalink structure updated.' );
 
130
 
 
131
        if ( $iis7_permalinks ) {
 
132
                if ( $permalink_structure && ! $using_index_permalinks && ! $writable ) {
 
133
                        $message = __( 'You should update your web.config now.' );
 
134
                } elseif ( $permalink_structure && ! $using_index_permalinks && $writable ) {
 
135
                        $message = __( 'Permalink structure updated. Remove write access on web.config file now!' );
 
136
                }
 
137
        } elseif ( ! $is_nginx && $permalink_structure && ! $using_index_permalinks && ! $writable && $update_required ) {
 
138
                $message = __( 'You should update your .htaccess now.' );
 
139
        }
 
140
 
 
141
        if ( ! get_settings_errors() ) {
 
142
                add_settings_error( 'general', 'settings_updated', $message, 'updated' );
 
143
        }
 
144
 
 
145
        set_transient( 'settings_errors', get_settings_errors(), 30 );
 
146
 
102
147
        wp_redirect( admin_url( 'options-permalink.php?settings-updated=true' ) );
103
148
        exit;
104
149
}
105
150
 
106
 
$category_base       = get_option( 'category_base' );
107
 
$tag_base            = get_option( 'tag_base' );
108
 
$update_required     = false;
109
 
 
110
 
if ( $iis7_permalinks ) {
111
 
        if ( ( ! file_exists($home_path . 'web.config') && win_is_writable($home_path) ) || win_is_writable($home_path . 'web.config') )
112
 
                $writable = true;
113
 
        else
114
 
                $writable = false;
115
 
} elseif ( $is_nginx ) {
116
 
        $writable = false;
117
 
} else {
118
 
        if ( ( ! file_exists( $home_path . '.htaccess' ) && is_writable( $home_path ) ) || is_writable( $home_path . '.htaccess' ) ) {
119
 
                $writable = true;
120
 
        } else {
121
 
                $writable = false;
122
 
                $existing_rules  = array_filter( extract_from_markers( $home_path . '.htaccess', 'WordPress' ) );
123
 
                $new_rules       = array_filter( explode( "\n", $wp_rewrite->mod_rewrite_rules() ) );
124
 
                $update_required = ( $new_rules !== $existing_rules );
125
 
        }
126
 
}
127
 
 
128
 
if ( $wp_rewrite->using_index_permalinks() )
129
 
        $usingpi = true;
130
 
else
131
 
        $usingpi = false;
132
 
 
133
151
flush_rewrite_rules();
134
152
 
135
153
require( ABSPATH . 'wp-admin/admin-header.php' );
136
 
 
137
 
if ( ! empty( $_GET['settings-updated'] ) ) : ?>
138
 
<div id="message" class="updated notice is-dismissible"><p><?php
139
 
if ( ! is_multisite() ) {
140
 
        if ( $iis7_permalinks ) {
141
 
                if ( $permalink_structure && ! $usingpi && ! $writable ) {
142
 
                        _e('You should update your web.config now.');
143
 
                } elseif ( $permalink_structure && ! $usingpi && $writable ) {
144
 
                        _e('Permalink structure updated. Remove write access on web.config file now!');
145
 
                } else {
146
 
                        _e('Permalink structure updated.');
147
 
                }
148
 
        } elseif ( $is_nginx ) {
149
 
                _e('Permalink structure updated.');
150
 
        } else {
151
 
                if ( $permalink_structure && ! $usingpi && ! $writable && $update_required ) {
152
 
                        _e('You should update your .htaccess now.');
153
 
                } else {
154
 
                        _e('Permalink structure updated.');
155
 
                }
156
 
        }
157
 
} else {
158
 
        _e('Permalink structure updated.');
159
 
}
160
154
?>
161
 
</p></div>
162
 
<?php endif; ?>
163
 
 
164
155
<div class="wrap">
165
156
<h1><?php echo esc_html( $title ); ?></h1>
166
157
 
242
233
  </form>
243
234
<?php if ( !is_multisite() ) { ?>
244
235
<?php if ( $iis7_permalinks ) :
245
 
        if ( isset($_POST['submit']) && $permalink_structure && ! $usingpi && ! $writable ) :
 
236
        if ( isset($_POST['submit']) && $permalink_structure && ! $using_index_permalinks && ! $writable ) :
246
237
                if ( file_exists($home_path . 'web.config') ) : ?>
247
238
<p><?php _e('If your <code>web.config</code> file were <a href="https://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>
248
239
<form action="options-permalink.php" method="post">
262
253
<?php elseif ( $is_nginx ) : ?>
263
254
        <p><?php _e( '<a href="https://codex.wordpress.org/Nginx">Documentation on Nginx configuration</a>.' ); ?></p>
264
255
<?php else:
265
 
        if ( $permalink_structure && ! $usingpi && ! $writable && $update_required ) : ?>
 
256
        if ( $permalink_structure && ! $using_index_permalinks && ! $writable && $update_required ) : ?>
266
257
<p><?php _e('If your <code>.htaccess</code> file were <a href="https://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>
267
258
<form action="options-permalink.php" method="post">
268
259
<?php wp_nonce_field('update-permalink') ?>