Permalink
Browse files

Re-add the rewrite rules on permalink change

When setting the permalink structure
WP_Rewrite::set_permalink_structure() calls
WP_Rewrite::init(), which empties
$wp_rewrite->endpoints.

Then, when flushing the rules in the middle of
option-permalinks.php, the rules are also
regenerated, but without our custom endpoints.

This causes every request to change the permalinks
to generate the wrong rewrite rules. Which makes
the liveblog polling request to 404. Which is bad.

This commit Fixes the problem by adding our
rewrite rules every time the permalink structure
is changed in addition to adding them on init.

This is probably a core bug and I will further
work to make isolate and report it.

In the course of fixing the bug I isolated adding
the rewrite rules and conditionally flushing them
into separate methods, so that we can easily
hook them to init/permalink_structure_change.

Fixes #15.
  • Loading branch information...
1 parent 24a2928 commit 7994c3e2462b0527e03754a4ac9faed0df2e2068 @nb nb committed Sep 18, 2012
Showing with 6 additions and 5 deletions.
  1. +6 −5 liveblog.php
View
@@ -92,6 +92,9 @@ private static function includes() {
*/
private static function add_actions() {
add_action( 'init', array( __CLASS__, 'init' ) );
+ add_action( 'init', array( __CLASS__, 'add_rewrite_rules' ) );
+ add_action( 'permalink_structure_changed', array( __CLASS__, 'add_rewrite_rules' ) );
+ add_action( 'init', array( __CLASS__, 'flush_rewrite_rules' ) );
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) );
add_action( 'wp_ajax_liveblog_insert_entry', array( __CLASS__, 'ajax_insert_entry' ) );
add_action( 'wp_ajax_liveblog_preview_entry', array( __CLASS__, 'ajax_preview_entry' ) );
@@ -133,24 +136,22 @@ private static function add_admin_actions() {
* taxonomies, we modify endpoints and add post type support for Liveblog.
*/
public static function init() {
-
- self::add_rewite_rules();
-
/**
* Add liveblog support to the 'post' post type. This is done here so
* we can possibly introduce this to other post types later.
*/
add_post_type_support( 'post', self::key );
}
- public static function add_rewite_rules() {
+ public function add_rewrite_rules() {
add_rewrite_endpoint( self::url_endpoint, EP_PERMALINK );
+ }
+ public static function flush_rewrite_rules() {
if ( get_option( 'liveblog_rewrites_version' ) != self::rewrites_version ) {
flush_rewrite_rules();
update_option( 'liveblog_rewrites_version', self::rewrites_version );
}
-
}
/**

0 comments on commit 7994c3e

Please sign in to comment.