Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
18 changed files
with
1,110 additions
and
1,110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,130 +1,130 @@ | ||
<?php /* | ||
************************************************************************** | ||
Plugin Name: Allow Numeric Stubs | ||
Plugin URI: http://www.viper007bond.com/wordpress-plugins/allow-numeric-stubs/ | ||
Description: Allows Pages to have a stub that is only a number. Sacrifices the <code><!--nextpage--></code> ability in Pages to accomplish it. | ||
Version: 2.1.0 | ||
Author: Viper007Bond | ||
Author URI: http://www.viper007bond.com/ | ||
************************************************************************** | ||
Copyright (C) 2008-2010 Viper007Bond | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
**************************************************************************/ | ||
|
||
class Allow_Numeric_Stubs { | ||
|
||
function allow_numeric_stubs() { | ||
register_activation_hook( __FILE__, array( &$this, 'flush_rewrite_rules' ) ); | ||
|
||
add_filter( 'page_rewrite_rules', array( &$this, 'page_rewrite_rules' ) ); | ||
|
||
add_action( 'save_post', array( &$this, 'maybe_fix_stub' ), 2, 2 ); | ||
add_filter( 'editable_slug', array( &$this, 'maybe_fix_editable_slug' ) ); | ||
} | ||
|
||
|
||
// Force a flush of the rewrite rules (for when this plugin is activated) | ||
function flush_rewrite_rules() { | ||
global $wp_rewrite; | ||
$wp_rewrite->flush_rules(); | ||
} | ||
|
||
|
||
// Remove the rewrite rule that "breaks" it (paged content) and replace it with one that allows numeric stubs | ||
function page_rewrite_rules( $rules ) { | ||
unset( $rules['(.?.+?)(/[0-9]+)?/?$'] ); | ||
|
||
$rules['(.?.+?)?/?$'] = 'index.php?pagename=$matches[1]'; | ||
|
||
return $rules; | ||
} | ||
|
||
|
||
// WordPress will add "-2" to numeric stubs as they aren't normally allowed. | ||
// Undo that for numeric page slugs when the post is saved. | ||
function maybe_fix_stub( $post_ID, $post ) { | ||
|
||
// Pages only | ||
if ( 'page' != $post->post_type ) | ||
return; | ||
|
||
// Only mess with numeric stubs or stubs that are 12345-2 | ||
if ( ! is_numeric( $post->post_name ) && $post->post_name == $this->maybe_unsuffix_slug( $post->post_name ) ) | ||
return; | ||
|
||
// Infinite loops are bad | ||
remove_action( 'save_post', array( &$this, 'maybe_fix_stub' ), 2, 2 ); | ||
|
||
// Update the post with a filter active that'll fix the slug back to what it was supposed to be | ||
add_filter( 'wp_insert_post_data', array(&$this, 'slug_fixer'), 10, 2 ); | ||
wp_update_post( $post ); | ||
remove_filter( 'wp_insert_post_data', array(&$this, 'slug_fixer'), 10, 2 ); | ||
|
||
// Put this filter back incase any other posts are updated on this pageload | ||
add_action( 'save_post', array( &$this, 'maybe_fix_stub' ), 2, 2 ); | ||
} | ||
|
||
|
||
// 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 | ||
function slug_fixer( $data, $postarr ) { | ||
// $data['post_name'] = $postarr['post_name']; // Not sure why this isn't working | ||
|
||
$data['post_name'] = $this->maybe_unsuffix_slug( $postarr['post_name'] ); | ||
|
||
return $data; | ||
} | ||
|
||
|
||
// Re-fix the page slug for the editable URL | ||
function maybe_fix_editable_slug( $slug ) { | ||
global $post; | ||
|
||
if ( empty( $post ) ) | ||
$thispost = get_post( $_POST['post_id'] ); | ||
else | ||
$thispost = $post; | ||
|
||
if ( empty( $thispost->post_type ) ) | ||
return $slug; | ||
|
||
if ( 'page' == $thispost->post_type ) | ||
$slug = $this->maybe_unsuffix_slug( $slug ); | ||
|
||
return $slug; | ||
} | ||
|
||
|
||
// Checks to see if a string is numeric with "-2" on the end of it | ||
// If so, it returns the original numeric string | ||
function maybe_unsuffix_slug( $slug ) { | ||
if ( '-2' == substr( $slug, -2 ) ) { | ||
$nonsuffixslug = substr( $slug, 0, -2 ); | ||
|
||
if ( is_numeric( $nonsuffixslug ) ) | ||
$slug = $nonsuffixslug; | ||
} | ||
|
||
return $slug; | ||
} | ||
} | ||
|
||
$Allow_Numeric_Stubs = new Allow_Numeric_Stubs(); | ||
|
||
<?php /* | ||
************************************************************************** | ||
Plugin Name: Allow Numeric Stubs | ||
Plugin URI: http://www.viper007bond.com/wordpress-plugins/allow-numeric-stubs/ | ||
Description: Allows Pages to have a stub that is only a number. Sacrifices the <code><!--nextpage--></code> ability in Pages to accomplish it. | ||
Version: 2.1.0 | ||
Author: Viper007Bond | ||
Author URI: http://www.viper007bond.com/ | ||
************************************************************************** | ||
Copyright (C) 2008-2010 Viper007Bond | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
**************************************************************************/ | ||
|
||
class Allow_Numeric_Stubs { | ||
|
||
function allow_numeric_stubs() { | ||
register_activation_hook( __FILE__, array( &$this, 'flush_rewrite_rules' ) ); | ||
|
||
add_filter( 'page_rewrite_rules', array( &$this, 'page_rewrite_rules' ) ); | ||
|
||
add_action( 'save_post', array( &$this, 'maybe_fix_stub' ), 2, 2 ); | ||
add_filter( 'editable_slug', array( &$this, 'maybe_fix_editable_slug' ) ); | ||
} | ||
|
||
|
||
// Force a flush of the rewrite rules (for when this plugin is activated) | ||
function flush_rewrite_rules() { | ||
global $wp_rewrite; | ||
$wp_rewrite->flush_rules(); | ||
} | ||
|
||
|
||
// Remove the rewrite rule that "breaks" it (paged content) and replace it with one that allows numeric stubs | ||
function page_rewrite_rules( $rules ) { | ||
unset( $rules['(.?.+?)(/[0-9]+)?/?$'] ); | ||
|
||
$rules['(.?.+?)?/?$'] = 'index.php?pagename=$matches[1]'; | ||
|
||
return $rules; | ||
} | ||
|
||
|
||
// WordPress will add "-2" to numeric stubs as they aren't normally allowed. | ||
// Undo that for numeric page slugs when the post is saved. | ||
function maybe_fix_stub( $post_ID, $post ) { | ||
|
||
// Pages only | ||
if ( 'page' != $post->post_type ) | ||
return; | ||
|
||
// Only mess with numeric stubs or stubs that are 12345-2 | ||
if ( ! is_numeric( $post->post_name ) && $post->post_name == $this->maybe_unsuffix_slug( $post->post_name ) ) | ||
return; | ||
|
||
// Infinite loops are bad | ||
remove_action( 'save_post', array( &$this, 'maybe_fix_stub' ), 2, 2 ); | ||
|
||
// Update the post with a filter active that'll fix the slug back to what it was supposed to be | ||
add_filter( 'wp_insert_post_data', array(&$this, 'slug_fixer'), 10, 2 ); | ||
wp_update_post( $post ); | ||
remove_filter( 'wp_insert_post_data', array(&$this, 'slug_fixer'), 10, 2 ); | ||
|
||
// Put this filter back incase any other posts are updated on this pageload | ||
add_action( 'save_post', array( &$this, 'maybe_fix_stub' ), 2, 2 ); | ||
} | ||
|
||
|
||
// 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 | ||
function slug_fixer( $data, $postarr ) { | ||
// $data['post_name'] = $postarr['post_name']; // Not sure why this isn't working | ||
|
||
$data['post_name'] = $this->maybe_unsuffix_slug( $postarr['post_name'] ); | ||
|
||
return $data; | ||
} | ||
|
||
|
||
// Re-fix the page slug for the editable URL | ||
function maybe_fix_editable_slug( $slug ) { | ||
global $post; | ||
|
||
if ( empty( $post ) ) | ||
$thispost = get_post( $_POST['post_id'] ); | ||
else | ||
$thispost = $post; | ||
|
||
if ( empty( $thispost->post_type ) ) | ||
return $slug; | ||
|
||
if ( 'page' == $thispost->post_type ) | ||
$slug = $this->maybe_unsuffix_slug( $slug ); | ||
|
||
return $slug; | ||
} | ||
|
||
|
||
// Checks to see if a string is numeric with "-2" on the end of it | ||
// If so, it returns the original numeric string | ||
function maybe_unsuffix_slug( $slug ) { | ||
if ( '-2' == substr( $slug, -2 ) ) { | ||
$nonsuffixslug = substr( $slug, 0, -2 ); | ||
|
||
if ( is_numeric( $nonsuffixslug ) ) | ||
$slug = $nonsuffixslug; | ||
} | ||
|
||
return $slug; | ||
} | ||
} | ||
|
||
$Allow_Numeric_Stubs = new Allow_Numeric_Stubs(); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,50 @@ | ||
=== Allow Numeric Stubs === | ||
Contributors: Viper007Bond | ||
Donate link: http://www.viper007bond.com/donate/ | ||
Tags: page, pages, numeric, number | ||
Requires at least: 3.3 | ||
Tested up to: 3.3 | ||
Stable tag: trunk | ||
Allows Pages to have a stub that is only a number. Sacrifices the paged content ability in Pages to accomplish it. | ||
== Description == | ||
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. | ||
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. | ||
== Installation == | ||
###Updgrading From A Previous Version### | ||
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. | ||
###Installing The Plugin### | ||
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. | ||
= See Also:** ["Installing Plugins" article on the WP Codex](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins) | ||
== ChangeLog == | ||
= Version 2.1.0 = | ||
* Update for WordPress 3.3 and it's newer rewrite rules. | ||
= Version 2.0.1 = | ||
* Re-add the `save_post` filter after fixing the slug incase multiple posts are updated in one pageload. | ||
= Version 2.0.0 = | ||
* 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. | ||
= Version 1.0.0 = | ||
* Initial release. | ||
== Upgrade Notice == | ||
= 2.1.0 = | ||
=== Allow Numeric Stubs === | ||
Contributors: Viper007Bond | ||
Donate link: http://www.viper007bond.com/donate/ | ||
Tags: page, pages, numeric, number | ||
Requires at least: 3.3 | ||
Tested up to: 3.3 | ||
Stable tag: trunk | ||
|
||
Allows Pages to have a stub that is only a number. Sacrifices the paged content ability in Pages to accomplish it. | ||
|
||
== Description == | ||
|
||
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. | ||
|
||
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. | ||
|
||
== Installation == | ||
|
||
###Updgrading From A Previous Version### | ||
|
||
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. | ||
|
||
###Installing The Plugin### | ||
|
||
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. | ||
|
||
= See Also:** ["Installing Plugins" article on the WP Codex](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins) | ||
|
||
== ChangeLog == | ||
|
||
= Version 2.1.0 = | ||
|
||
* Update for WordPress 3.3 and it's newer rewrite rules. | ||
|
||
= Version 2.0.1 = | ||
|
||
* Re-add the `save_post` filter after fixing the slug incase multiple posts are updated in one pageload. | ||
|
||
= Version 2.0.0 = | ||
|
||
* 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. | ||
|
||
= Version 1.0.0 = | ||
|
||
* Initial release. | ||
|
||
== Upgrade Notice == | ||
|
||
= 2.1.0 = | ||
WordPress 3.3 compatibility. |
Oops, something went wrong.