Permalink
Browse files

Merge pull request WP-API#149 from WP-API/mu-flush

Use version option to check on init if rewrite rules should be flushed.
  • Loading branch information...
rmccue committed Apr 28, 2014
2 parents f8e4a45 + 9d9c8cc commit da2ef66abfa45200ac7ef9809e6e6e8825335e65
Showing with 29 additions and 4 deletions.
  1. +29 −4 plugin.php
View
@@ -7,6 +7,17 @@
* Version: 0.9
* Plugin URI: https://github.com/rmccue/WP-API
*/
/**
* Version number for our API
*
* @var string
*/
define('JSON_API_VERSION', '0.9');
/**
* Include our files for the API
*/
include_once( dirname( __FILE__ ) . '/lib/class-jsonserializable.php' );
include_once( dirname( __FILE__ ) . '/lib/class-wp-json-datetime.php' );
@@ -37,6 +48,20 @@ function json_api_register_rewrites() {
add_rewrite_rule( '^wp-json(.*)?','index.php?json_route=$matches[1]','top' );
}
/**
* Determine if the rewrite rules should be flushed.
*/
function json_api_maybe_flush_rewrites() {
$version = get_option( 'json_api_plugin_version', null );
if ( empty( $version ) || $version !== JSON_API_VERSION ) {
flush_rewrite_rules();
update_option( 'json_api_plugin_version', JSON_API_VERSION );
}
}
add_action( 'init', 'json_api_maybe_flush_rewrites', 999 );
/**
* Register the default JSON API filters
*
@@ -135,15 +160,15 @@ function json_api_activation( $network_wide ) {
switch_to_blog( $mu_blog['blog_id'] );
json_api_register_rewrites();
flush_rewrite_rules();
update_option( 'json_api_plugin_version', null );
}
restore_current_blog();
} else {
json_api_register_rewrites();
flush_rewrite_rules();
update_option( 'json_api_plugin_version', null );
}
}
register_activation_hook( __FILE__, 'json_api_activation' );
@@ -159,14 +184,14 @@ function json_api_deactivation( $network_wide ) {
foreach ( $mu_blogs as $mu_blog ) {
switch_to_blog( $mu_blog['blog_id'] );
flush_rewrite_rules();
delete_option( 'json_api_plugin_version' );
}
restore_current_blog();
} else {
flush_rewrite_rules();
delete_option( 'json_api_plugin_version' );
}
}
register_deactivation_hook( __FILE__, 'json_api_deactivation' );

0 comments on commit da2ef66

Please sign in to comment.