Title: [Plugin: JSON API] Problem in creating External controllers
Last modified: August 19, 2016

---

# [Plugin: JSON API] Problem in creating External controllers

 *  [Parminder](https://wordpress.org/support/users/parminder/)
 * (@parminder)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-json-api-problem-in-creating-external-controllers/)
 * First of all i would like to thank dphiffer for providing such a wonderful plugin.
   I have downloaded it just today, so i am new with it..
 * I am facing a problem while i tried to create an External controller as follow:
 * I add this code at my theme’s function.php
 *     ```
       function add_hello_controller($controllers) {
         $controllers[] = 'hello';
       }
       add_filter('json_api_controllers', 'add_hello_controller');
   
       function set_hello_controller_path() {
         return TEMPLATEPATH."/jsonAPI/hello.php"; // TEMPLATEPATH is my theme's path..
       }
       add_filter('json_api_hello_controller_path', 'set_hello_controller_path');
       ```
   
 * and create simple hello.php under “jsonAPI” directory at my theme as explained
   in description Section 5.
 * it is giving warning at front end as follow:
    Warning: array_map() [function.
   array-map]: Argument #2 should be an array in P:\odwroot\wp301\wp-content\plugins\
   json-api\singletons\api.php on line 285
 * Warning: array_intersect() [function.array-intersect]: Argument #1 is not an 
   array in P:\odwroot\wp301\wp-content\plugins\json-api\singletons\api.php on line
   20
 * Plus an additional waring at admin side JSON API Settings:
    Warning: Invalid 
   argument supplied for foreach() in P:\odwroot\wp301\wp-content\plugins\json-api\
   singletons\api.php on line 141
 * and cannot see any controller there..
 * however if i create controller within the plug-in directory, it is working fine.
 * Kindly help..
 * Regards,
    Parminder

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

 *  Thread Starter [Parminder](https://wordpress.org/support/users/parminder/)
 * (@parminder)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-json-api-problem-in-creating-external-controllers/#post-1664095)
 * Kind Attention “dphiffer”…
 * Can any body help me to find a solution for this problem????
 *  [shortster](https://wordpress.org/support/users/shortster/)
 * (@shortster)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/plugin-json-api-problem-in-creating-external-controllers/#post-1664199)
 * Having the same problem. Please provide a working example.
 *  [i906](https://wordpress.org/support/users/i906/)
 * (@i906)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/plugin-json-api-problem-in-creating-external-controllers/#post-1664201)
 * I also have the same problem before. The code below works for me.
 * This is the code in the theme’s functions.php
 *     ```
       // the external controller file
       require 'json-api.php';
   
       function add_hello_controller($controllers) {
         $controllers[] = 'iprofile';
         return $controllers;
       }
       add_filter('json_api_controllers', 'add_hello_controller');
   
       function set_hello_controller_path() {
         return "../wp-content/themes/iProfile3/json-api.php";
       }
       add_filter('json_api_iprofile_controller_path', 'set_hello_controller_path');
       ```
   
 * For some reasons, I cannot use numbers in the controller names.
 *  Plugin Author [dphiffer](https://wordpress.org/support/users/dphiffer/)
 * (@dphiffer)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/plugin-json-api-problem-in-creating-external-controllers/#post-1664219)
 * Sorry guys, there was a mistake in the documentation. The `return $controllers`
   part was a critical omission. i906’s code includes it and it sounds like it works
   as a result.
 * I’ll look into the numbers/filters thing…
 *  [granviller](https://wordpress.org/support/users/granviller/)
 * (@granviller)
 * [15 years ago](https://wordpress.org/support/topic/plugin-json-api-problem-in-creating-external-controllers/#post-1664246)
 * I know that this is an old thread, but I was trying to get an external controller
   to work and I am having problems because it won’t find the file when you try 
   to go to a dev url for a given function in the controller.
 * example.com/api/hello/hello_world/?dev=1
 * I get a message of unknown controller. I traced this down to line 35 of the api.
   php file. I had to edit the strings to determine which one it was.
 * The problem function seems to be in api.php and is named controller_path(). It
   seems to always look for controllers in the json_api_dir/controllers folder.
 * For now I have to put my controller file into the json_api/controlders folder
   for it to work. Not a big deal, but I like the idea of the external controller.
   Should the function be passing the directory to the apply filters, or should 
   it be passing a function name like “set_$controller_controller_path”?
 * Gran
 *  [granviller](https://wordpress.org/support/users/granviller/)
 * (@granviller)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/plugin-json-api-problem-in-creating-external-controllers/#post-1664247)
 * Looks like I was wrong and did get it to work, but was receiving a message that
   reflected an error with what was being accomplished. that Error message that 
   got returned made me thing I didn’t get the external controller working properly.
 * Talk about embarrassing.
 * Thank you for making such a great plugin that is highly extensible.

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

The topic ‘[Plugin: JSON API] Problem in creating External controllers’ 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/)

 * 6 replies
 * 5 participants
 * Last reply from: [granviller](https://wordpress.org/support/users/granviller/)
 * Last activity: [14 years, 12 months ago](https://wordpress.org/support/topic/plugin-json-api-problem-in-creating-external-controllers/#post-1664247)
 * Status: not resolved