Skip to content

Commit da2a59a

Browse files
committed
All: Normalize line endings
Fixes jquerygh-304
1 parent 4dfcb3c commit da2a59a

File tree

18 files changed

+1110
-1110
lines changed

18 files changed

+1110
-1110
lines changed
Lines changed: 129 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,130 @@
1-
<?php /*
2-
3-
**************************************************************************
4-
5-
Plugin Name: Allow Numeric Stubs
6-
Plugin URI: http://www.viper007bond.com/wordpress-plugins/allow-numeric-stubs/
7-
Description: Allows Pages to have a stub that is only a number. Sacrifices the <code>&lt;!--nextpage--&gt;</code> ability in Pages to accomplish it.
8-
Version: 2.1.0
9-
Author: Viper007Bond
10-
Author URI: http://www.viper007bond.com/
11-
12-
**************************************************************************
13-
14-
Copyright (C) 2008-2010 Viper007Bond
15-
16-
This program is free software: you can redistribute it and/or modify
17-
it under the terms of the GNU General Public License as published by
18-
the Free Software Foundation, either version 3 of the License, or
19-
(at your option) any later version.
20-
21-
This program is distributed in the hope that it will be useful,
22-
but WITHOUT ANY WARRANTY; without even the implied warranty of
23-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24-
GNU General Public License for more details.
25-
26-
You should have received a copy of the GNU General Public License
27-
along with this program. If not, see <http://www.gnu.org/licenses/>.
28-
29-
**************************************************************************/
30-
31-
class Allow_Numeric_Stubs {
32-
33-
function allow_numeric_stubs() {
34-
register_activation_hook( __FILE__, array( &$this, 'flush_rewrite_rules' ) );
35-
36-
add_filter( 'page_rewrite_rules', array( &$this, 'page_rewrite_rules' ) );
37-
38-
add_action( 'save_post', array( &$this, 'maybe_fix_stub' ), 2, 2 );
39-
add_filter( 'editable_slug', array( &$this, 'maybe_fix_editable_slug' ) );
40-
}
41-
42-
43-
// Force a flush of the rewrite rules (for when this plugin is activated)
44-
function flush_rewrite_rules() {
45-
global $wp_rewrite;
46-
$wp_rewrite->flush_rules();
47-
}
48-
49-
50-
// Remove the rewrite rule that "breaks" it (paged content) and replace it with one that allows numeric stubs
51-
function page_rewrite_rules( $rules ) {
52-
unset( $rules['(.?.+?)(/[0-9]+)?/?$'] );
53-
54-
$rules['(.?.+?)?/?$'] = 'index.php?pagename=$matches[1]';
55-
56-
return $rules;
57-
}
58-
59-
60-
// WordPress will add "-2" to numeric stubs as they aren't normally allowed.
61-
// Undo that for numeric page slugs when the post is saved.
62-
function maybe_fix_stub( $post_ID, $post ) {
63-
64-
// Pages only
65-
if ( 'page' != $post->post_type )
66-
return;
67-
68-
// Only mess with numeric stubs or stubs that are 12345-2
69-
if ( ! is_numeric( $post->post_name ) && $post->post_name == $this->maybe_unsuffix_slug( $post->post_name ) )
70-
return;
71-
72-
// Infinite loops are bad
73-
remove_action( 'save_post', array( &$this, 'maybe_fix_stub' ), 2, 2 );
74-
75-
// Update the post with a filter active that'll fix the slug back to what it was supposed to be
76-
add_filter( 'wp_insert_post_data', array(&$this, 'slug_fixer'), 10, 2 );
77-
wp_update_post( $post );
78-
remove_filter( 'wp_insert_post_data', array(&$this, 'slug_fixer'), 10, 2 );
79-
80-
// Put this filter back incase any other posts are updated on this pageload
81-
add_action( 'save_post', array( &$this, 'maybe_fix_stub' ), 2, 2 );
82-
}
83-
84-
85-
// Ensure that post_name stays as we pass it as wp_unique_post_slug() will try and add a "-2" to the end of it
86-
function slug_fixer( $data, $postarr ) {
87-
// $data['post_name'] = $postarr['post_name']; // Not sure why this isn't working
88-
89-
$data['post_name'] = $this->maybe_unsuffix_slug( $postarr['post_name'] );
90-
91-
return $data;
92-
}
93-
94-
95-
// Re-fix the page slug for the editable URL
96-
function maybe_fix_editable_slug( $slug ) {
97-
global $post;
98-
99-
if ( empty( $post ) )
100-
$thispost = get_post( $_POST['post_id'] );
101-
else
102-
$thispost = $post;
103-
104-
if ( empty( $thispost->post_type ) )
105-
return $slug;
106-
107-
if ( 'page' == $thispost->post_type )
108-
$slug = $this->maybe_unsuffix_slug( $slug );
109-
110-
return $slug;
111-
}
112-
113-
114-
// Checks to see if a string is numeric with "-2" on the end of it
115-
// If so, it returns the original numeric string
116-
function maybe_unsuffix_slug( $slug ) {
117-
if ( '-2' == substr( $slug, -2 ) ) {
118-
$nonsuffixslug = substr( $slug, 0, -2 );
119-
120-
if ( is_numeric( $nonsuffixslug ) )
121-
$slug = $nonsuffixslug;
122-
}
123-
124-
return $slug;
125-
}
126-
}
127-
128-
$Allow_Numeric_Stubs = new Allow_Numeric_Stubs();
129-
1+
<?php /*
2+
3+
**************************************************************************
4+
5+
Plugin Name: Allow Numeric Stubs
6+
Plugin URI: http://www.viper007bond.com/wordpress-plugins/allow-numeric-stubs/
7+
Description: Allows Pages to have a stub that is only a number. Sacrifices the <code>&lt;!--nextpage--&gt;</code> ability in Pages to accomplish it.
8+
Version: 2.1.0
9+
Author: Viper007Bond
10+
Author URI: http://www.viper007bond.com/
11+
12+
**************************************************************************
13+
14+
Copyright (C) 2008-2010 Viper007Bond
15+
16+
This program is free software: you can redistribute it and/or modify
17+
it under the terms of the GNU General Public License as published by
18+
the Free Software Foundation, either version 3 of the License, or
19+
(at your option) any later version.
20+
21+
This program is distributed in the hope that it will be useful,
22+
but WITHOUT ANY WARRANTY; without even the implied warranty of
23+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+
GNU General Public License for more details.
25+
26+
You should have received a copy of the GNU General Public License
27+
along with this program. If not, see <http://www.gnu.org/licenses/>.
28+
29+
**************************************************************************/
30+
31+
class Allow_Numeric_Stubs {
32+
33+
function allow_numeric_stubs() {
34+
register_activation_hook( __FILE__, array( &$this, 'flush_rewrite_rules' ) );
35+
36+
add_filter( 'page_rewrite_rules', array( &$this, 'page_rewrite_rules' ) );
37+
38+
add_action( 'save_post', array( &$this, 'maybe_fix_stub' ), 2, 2 );
39+
add_filter( 'editable_slug', array( &$this, 'maybe_fix_editable_slug' ) );
40+
}
41+
42+
43+
// Force a flush of the rewrite rules (for when this plugin is activated)
44+
function flush_rewrite_rules() {
45+
global $wp_rewrite;
46+
$wp_rewrite->flush_rules();
47+
}
48+
49+
50+
// Remove the rewrite rule that "breaks" it (paged content) and replace it with one that allows numeric stubs
51+
function page_rewrite_rules( $rules ) {
52+
unset( $rules['(.?.+?)(/[0-9]+)?/?$'] );
53+
54+
$rules['(.?.+?)?/?$'] = 'index.php?pagename=$matches[1]';
55+
56+
return $rules;
57+
}
58+
59+
60+
// WordPress will add "-2" to numeric stubs as they aren't normally allowed.
61+
// Undo that for numeric page slugs when the post is saved.
62+
function maybe_fix_stub( $post_ID, $post ) {
63+
64+
// Pages only
65+
if ( 'page' != $post->post_type )
66+
return;
67+
68+
// Only mess with numeric stubs or stubs that are 12345-2
69+
if ( ! is_numeric( $post->post_name ) && $post->post_name == $this->maybe_unsuffix_slug( $post->post_name ) )
70+
return;
71+
72+
// Infinite loops are bad
73+
remove_action( 'save_post', array( &$this, 'maybe_fix_stub' ), 2, 2 );
74+
75+
// Update the post with a filter active that'll fix the slug back to what it was supposed to be
76+
add_filter( 'wp_insert_post_data', array(&$this, 'slug_fixer'), 10, 2 );
77+
wp_update_post( $post );
78+
remove_filter( 'wp_insert_post_data', array(&$this, 'slug_fixer'), 10, 2 );
79+
80+
// Put this filter back incase any other posts are updated on this pageload
81+
add_action( 'save_post', array( &$this, 'maybe_fix_stub' ), 2, 2 );
82+
}
83+
84+
85+
// Ensure that post_name stays as we pass it as wp_unique_post_slug() will try and add a "-2" to the end of it
86+
function slug_fixer( $data, $postarr ) {
87+
// $data['post_name'] = $postarr['post_name']; // Not sure why this isn't working
88+
89+
$data['post_name'] = $this->maybe_unsuffix_slug( $postarr['post_name'] );
90+
91+
return $data;
92+
}
93+
94+
95+
// Re-fix the page slug for the editable URL
96+
function maybe_fix_editable_slug( $slug ) {
97+
global $post;
98+
99+
if ( empty( $post ) )
100+
$thispost = get_post( $_POST['post_id'] );
101+
else
102+
$thispost = $post;
103+
104+
if ( empty( $thispost->post_type ) )
105+
return $slug;
106+
107+
if ( 'page' == $thispost->post_type )
108+
$slug = $this->maybe_unsuffix_slug( $slug );
109+
110+
return $slug;
111+
}
112+
113+
114+
// Checks to see if a string is numeric with "-2" on the end of it
115+
// If so, it returns the original numeric string
116+
function maybe_unsuffix_slug( $slug ) {
117+
if ( '-2' == substr( $slug, -2 ) ) {
118+
$nonsuffixslug = substr( $slug, 0, -2 );
119+
120+
if ( is_numeric( $nonsuffixslug ) )
121+
$slug = $nonsuffixslug;
122+
}
123+
124+
return $slug;
125+
}
126+
}
127+
128+
$Allow_Numeric_Stubs = new Allow_Numeric_Stubs();
129+
130130
?>
Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1-
=== Allow Numeric Stubs ===
2-
Contributors: Viper007Bond
3-
Donate link: http://www.viper007bond.com/donate/
4-
Tags: page, pages, numeric, number
5-
Requires at least: 3.3
6-
Tested up to: 3.3
7-
Stable tag: trunk
8-
9-
Allows Pages to have a stub that is only a number. Sacrifices the paged content ability in Pages to accomplish it.
10-
11-
== Description ==
12-
13-
It is not possible to have a page slug (the page's name in the URL) that is a number. For example this will not work: `yoursite.com/about/2/`. That URL conflicts with paged content feature where you can posts and pages with multiple pages of content by adding `<!--nextpage-->` within your content.
14-
15-
This plugin allows you to have Pages with numbers as stubs by giving up the ability to have paged content pages which isn't a big deal as most people don't use paged content pages anyway.
16-
17-
== Installation ==
18-
19-
###Updgrading From A Previous Version###
20-
21-
To upgrade from a previous version of this plugin, delete the entire folder and files from the previous version of the plugin and then follow the installation instructions below.
22-
23-
###Installing The Plugin###
24-
25-
Go to your WordPress administration area and then navigate to Plugins -> Add New in the menu. Search for this plugin's name and then press the install link.
26-
27-
= See Also:** ["Installing Plugins" article on the WP Codex](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins)
28-
29-
== ChangeLog ==
30-
31-
= Version 2.1.0 =
32-
33-
* Update for WordPress 3.3 and it's newer rewrite rules.
34-
35-
= Version 2.0.1 =
36-
37-
* Re-add the `save_post` filter after fixing the slug incase multiple posts are updated in one pageload.
38-
39-
= Version 2.0.0 =
40-
41-
* Recoded for WordPress 3.0+. WordPress now won't let you manually enter a numeric stub -- it will prefix "-2" onto the end of it so that the page is viewable. This new plugin version works around it.
42-
43-
= Version 1.0.0 =
44-
45-
* Initial release.
46-
47-
== Upgrade Notice ==
48-
49-
= 2.1.0 =
1+
=== Allow Numeric Stubs ===
2+
Contributors: Viper007Bond
3+
Donate link: http://www.viper007bond.com/donate/
4+
Tags: page, pages, numeric, number
5+
Requires at least: 3.3
6+
Tested up to: 3.3
7+
Stable tag: trunk
8+
9+
Allows Pages to have a stub that is only a number. Sacrifices the paged content ability in Pages to accomplish it.
10+
11+
== Description ==
12+
13+
It is not possible to have a page slug (the page's name in the URL) that is a number. For example this will not work: `yoursite.com/about/2/`. That URL conflicts with paged content feature where you can posts and pages with multiple pages of content by adding `<!--nextpage-->` within your content.
14+
15+
This plugin allows you to have Pages with numbers as stubs by giving up the ability to have paged content pages which isn't a big deal as most people don't use paged content pages anyway.
16+
17+
== Installation ==
18+
19+
###Updgrading From A Previous Version###
20+
21+
To upgrade from a previous version of this plugin, delete the entire folder and files from the previous version of the plugin and then follow the installation instructions below.
22+
23+
###Installing The Plugin###
24+
25+
Go to your WordPress administration area and then navigate to Plugins -> Add New in the menu. Search for this plugin's name and then press the install link.
26+
27+
= See Also:** ["Installing Plugins" article on the WP Codex](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins)
28+
29+
== ChangeLog ==
30+
31+
= Version 2.1.0 =
32+
33+
* Update for WordPress 3.3 and it's newer rewrite rules.
34+
35+
= Version 2.0.1 =
36+
37+
* Re-add the `save_post` filter after fixing the slug incase multiple posts are updated in one pageload.
38+
39+
= Version 2.0.0 =
40+
41+
* Recoded for WordPress 3.0+. WordPress now won't let you manually enter a numeric stub -- it will prefix "-2" onto the end of it so that the page is viewable. This new plugin version works around it.
42+
43+
= Version 1.0.0 =
44+
45+
* Initial release.
46+
47+
== Upgrade Notice ==
48+
49+
= 2.1.0 =
5050
WordPress 3.3 compatibility.

0 commit comments

Comments
 (0)