Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Use version option to check on init if rewrite rules should be flushed. #149

Merged
merged 3 commits into from

2 participants

@rachelbaker
Owner

This should fix #113.

plugin.php
@@ -135,7 +160,7 @@ 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 );
@rmccue Owner
rmccue added a note

Can probably use delete_option() here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
plugin.php
@@ -38,6 +49,20 @@ function json_api_register_rewrites() {
}
/**
+ * Determine if the rewrite rules should be flushed.
+ */
+function json_api_maybe_flush_rewrites() {
+ $version = get_option( 'json_api_plugin_version', NULL );
@rmccue Owner
rmccue added a note

null should be lowercase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rmccue rmccue was assigned by rachelbaker
@rmccue rmccue added this to the 1.0 milestone
@rmccue rmccue merged commit 81b1599 into from
@rmccue rmccue deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 29 additions and 4 deletions.
  1. +29 −4 plugin.php
View
33 plugin.php
@@ -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' );
@@ -38,6 +49,20 @@ function json_api_register_rewrites() {
}
/**
+ * 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
*
* @internal This will live in default-filters.php
@@ -135,7 +160,7 @@ 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();
@@ -143,7 +168,7 @@ function json_api_activation( $network_wide ) {
} 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' );
Something went wrong with that request. Please try again.