Title: Update: Upgrade breaks API path
Last modified: August 22, 2016

---

# Update: Upgrade breaks API path

 *  Resolved [archon810](https://wordpress.org/support/users/archon810/)
 * (@archon810)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/update-upgrade-breaks-api-path/)
 * This is an update on the topic of the /api/ path breaking and 404ing sometimes,
   which we discussed here: [http://wordpress.org/support/topic/upgrade-breaks-api-path](http://wordpress.org/support/topic/upgrade-breaks-api-path),
   but since that topic is closed for new replies, and I have new information to
   share, I’m starting a new post.
 * After hitting the 404 a few more times, I finally diagnosed it on my end. Please
   take a look and advise on a fix if possible.
 * The /api/ starts 404ing when I add a new custom feed, flush rewrite rules so 
   that this feed is registered, and then uncomment the flush command, as per best
   practices ([http://codex.wordpress.org/Function_Reference/flush_rewrite_rules](http://codex.wordpress.org/Function_Reference/flush_rewrite_rules)).
 * Here’s the code in my functions.php:
 *     ```
       function my_rewrite_rules( $wp_rewrite ) {
         $new_rules = array(
           'feed(?:/|\?|$)(.+)' => 'index.php?feed='.$wp_rewrite->preg_index(1)
         );
         $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
       }
       function my_add_custom_feeds() {
         global $wp_rewrite;
         add_feed('blabla_feed', 'my_full_feed');
       /***** RE-ENABLE THESE LINES IF YOU ADD A NEW FEED, BUT KEEP DISABLED OTHERWISE *****/
       //  add_action('generate_rewrite_rules', 'my_rewrite_rules');
       //  $wp_rewrite->flush_rules();
       }
       add_action('init', 'my_add_custom_feeds');
       ```
   
 * When I add a new feed, I add a new add_feed call, uncomment add_action and flush_rules,
   hit the site, then comment them back. As soon as I comment them back, the JSON
   API /api/ path becomes a 404.
 * Thoughts on fixing this?
 * [https://wordpress.org/plugins/json-api/](https://wordpress.org/plugins/json-api/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [archon810](https://wordpress.org/support/users/archon810/)
 * (@archon810)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/update-upgrade-breaks-api-path/#post-5195950)
 * Actually, there seems to be some sort of a race condition here. If I just keep
   the two lines that flush rules live and watch the value of wp_options rewrite_rules,
   it keeps flopping between 72 and 74 values – with 2 JSON API rules and without.
   So it really depends on timing when I comment them out – it could end up with
   JSON API rules, or it could end up without.
 *  Thread Starter [archon810](https://wordpress.org/support/users/archon810/)
 * (@archon810)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/update-upgrade-breaks-api-path/#post-5195951)
 * OK, I figured it out.
 * The flopping occurred because we use a plugin called wptouch (very popular plugin
   for mobile themes), and in that plugin, there’s a Compatibility section that 
   allows us to dynamically disable plugins on the fly, so that they don’t run and
   use up CPU/db cycles when the mobile theme is active. JSON API was one such checkbox,
   so it was being dynamically disabled on every mobile hit.
 * However, functions.php is loaded on every hit, mobile or not. So sometimes, it
   would write new rewrite rules with JSON API ones and sometimes it’d be as if 
   JSON API was never installed, and its rules would be missing.
 * As soon as I unchecked the JSON API in the list of plugins to disable in wptouch,
   the flopping stopped.
 * Phew. Hope this helps someone in the future. I’m still not sure why a possible
   JSON API upgrade might break rewrite rules, but I bet it’s something similar,
   if it’s really what happens.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Update: Upgrade breaks API path’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/json-api.svg)
 * [JSON API](https://wordpress.org/plugins/json-api/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/json-api/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/json-api/)
 * [Active Topics](https://wordpress.org/support/plugin/json-api/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/json-api/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/json-api/reviews/)

 * 2 replies
 * 1 participant
 * Last reply from: [archon810](https://wordpress.org/support/users/archon810/)
 * Last activity: [11 years, 9 months ago](https://wordpress.org/support/topic/update-upgrade-breaks-api-path/#post-5195951)
 * Status: resolved