Permalinks: Validate custom permalink structures.

Custom permalink structures require at least one valid structure tag, e.g. `%postname%`. If none is included, it would leave users with broken permalinks.
Let's make sure this won't happen by validating the permalink structure.

Adds unit tests.

Props rockwell15 for initial patch.
Fixes #35936.

git-svn-id: https://develop.svn.wordpress.org/trunk@37747 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Pascal Birchler
2016-06-19 12:01:11 +00:00
parent db843d80ab
commit d40f2eed2c
3 changed files with 68 additions and 31 deletions

View File

@@ -4204,6 +4204,14 @@ function sanitize_option( $option, $value ) {
$value = esc_url_raw( $value );
$value = str_replace( 'http://', '', $value );
}
if ( 'permalink_structure' === $option && '' !== $value && ! preg_match( '/%[^\/%]+%/', $value ) ) {
$error = sprintf(
/* translators: %s: Codex URL */
__( 'A structure tag is required when using custom permalinks. <a href="%s">Learn more</a>' ),
__( 'https://codex.wordpress.org/Using_Permalinks#Choosing_your_permalink_structure' )
);
}
break;
case 'default_role' :