-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprotect-directory-urls.php
More file actions
50 lines (47 loc) · 1.38 KB
/
Copy pathprotect-directory-urls.php
File metadata and controls
50 lines (47 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php # -*- coding: utf-8 -*-
/**
* Plugin Name: Protect directory URLs
* Description: Prevents the creation of permalinks matching existing directories.
* Plugin URI: http://marketpress.com/
* Version: 2014.01.27
* Author: MarketPress, Thomas Scholz
* Author URI: http://marketpress.com/
* Licence: GPL 2
* License URI: http://opensource.org/licenses/GPL-2.0
*/
// Pages and other hierarchical post types.
add_filter(
'wp_unique_post_slug_is_bad_hierarchical_slug',
'marketpress_prevent_directory_slugs',
10, 2
);
// Posts and other non-hierarchical post types.
add_filter(
'wp_unique_post_slug_is_bad_flat_slug',
'marketpress_prevent_directory_slugs',
10, 2
);
// Attachments.
add_filter(
'wp_unique_post_slug_is_bad_attachment_slug',
'marketpress_prevent_directory_slugs',
10, 2
);
/**
* Do not allow slugs matching existing directories.
*
* @author MarketPress.com
* @see wp_unique_post_slug()
* @wp-hook wp_unique_post_slug_is_bad_hierarchical_slug
* @wp-hook wp_unique_post_slug_is_bad_flat_slug
* @wp-hook wp_unique_post_slug_is_bad_attachment_slug
* @param bool $bool Boolean value passed by the hook, default to false.
* @param string $slug
* @return bool TRUE if there is a directory with the same name.
*/
function marketpress_prevent_directory_slugs( $bool, $slug )
{
if ( is_dir( ABSPATH . '/' . $slug ) )
return TRUE;
return $bool;
}