Title: Access Context Variables outside plugin?
Last modified: January 18, 2018

---

# Access Context Variables outside plugin?

 *  Resolved [theonturncloak](https://wordpress.org/support/users/theonturncloak/)
 * (@theonturncloak)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/access-context-variables-outside-plugin/)
 * Hi,
 * Is it possible to access the context variables outside of the plug in?
 * I want to be able to use the context variables from chats in a database on my
   site, so is this possible and if so how do I go about doing this?
    -  This topic was modified 8 years, 4 months ago by [theonturncloak](https://wordpress.org/support/users/theonturncloak/).

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

 *  Plugin Contributor [cognitiveclass](https://wordpress.org/support/users/cognitiveclass/)
 * (@cognitiveclass)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/access-context-variables-outside-plugin/#post-9895875)
 * Hi,
 * In an upcoming update, we’ll be adding WordPress hooks for sending and receiving
   messages that will allow you to write PHP functions to access the context variables
   in addition to other data in the HTTP response. Will this satisfy your needs?
 *  Thread Starter [theonturncloak](https://wordpress.org/support/users/theonturncloak/)
 * (@theonturncloak)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/access-context-variables-outside-plugin/#post-9896615)
 * Hi,
 * I believe it would! Any time frame as to when this update will be released?
 *  Plugin Contributor [cognitiveclass](https://wordpress.org/support/users/cognitiveclass/)
 * (@cognitiveclass)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/access-context-variables-outside-plugin/#post-9899723)
 * It should be available by the end of this week. We’ll let you know as soon as
   it’s released.
 *  Thread Starter [theonturncloak](https://wordpress.org/support/users/theonturncloak/)
 * (@theonturncloak)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/access-context-variables-outside-plugin/#post-9903397)
 * Hi that’s great to know thank you!
 * Do you recommend any tutorials for WordPress hooks?
 *  Plugin Contributor [cognitiveclass](https://wordpress.org/support/users/cognitiveclass/)
 * (@cognitiveclass)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/access-context-variables-outside-plugin/#post-9907516)
 * Hi,
 * The update has been released so you can get started with it now. The WordPress
   documentation has [a detailed explanation](https://codex.wordpress.org/Plugin_API)
   of how hooks are used, though you can find a lot of other tutorials online.
 * For your case, you can use our plugin’s hook by doing the following:
 * 1. Navigate to the `wp-content/themes/yourthemename` directory and open the functions.
   php file.
    2. Add the following line anywhere in the file, but replace ‘function_name’
   with a function name of your choosing: `add_action('watsonconv_message_parsed','
   function_name');` 3. Create a PHP function with the same name. This function 
   will now be called every time a user receives a message from the chatbot, and
   it will be given the [body of the HTTP response](https://www.ibm.com/watson/developercloud/conversation/api/v1/#send_message)
   as an argument. This argument will be in array format, so you can access the 
   context like this:
 *     ```
       function get_context_variables($response) {
           $context = $response['context'];
       }
       ```
   
 * Feel free to ask if you have any questions.
    -  This reply was modified 8 years, 4 months ago by [cognitiveclass](https://wordpress.org/support/users/cognitiveclass/).
 *  Thread Starter [theonturncloak](https://wordpress.org/support/users/theonturncloak/)
 * (@theonturncloak)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/access-context-variables-outside-plugin/#post-9909005)
 * Hi, so does that mean we can only access one context variable at a time? We can
   pull it and store it elsewhere on the site?
 *  Plugin Contributor [cognitiveclass](https://wordpress.org/support/users/cognitiveclass/)
 * (@cognitiveclass)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/access-context-variables-outside-plugin/#post-9915303)
 * The “context” field in the HTTP response is an array containing the current value
   of each of the context variables. For example, if you have context variables 
   called “var1” and “var2”, you can access them using the `$context` variable like
   this:
 *     ```
       $val1 = $context['var1'];
       $val2 = $context['var2'];
       ```
   
 * You can then use PHP to store these values in your database. As you can tell,
   this will require some coding.
 *  Thread Starter [theonturncloak](https://wordpress.org/support/users/theonturncloak/)
 * (@theonturncloak)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/access-context-variables-outside-plugin/#post-9917480)
 * Fantastic, thank you very much!

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

The topic ‘Access Context Variables outside plugin?’ is closed to new replies.

 * ![](https://ps.w.org/conversation-watson/assets/icon-256x256.png?rev=1684465)
 * [Chatbot with IBM watsonx Assistant](https://wordpress.org/plugins/conversation-watson/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/conversation-watson/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/conversation-watson/)
 * [Active Topics](https://wordpress.org/support/plugin/conversation-watson/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/conversation-watson/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/conversation-watson/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [theonturncloak](https://wordpress.org/support/users/theonturncloak/)
 * Last activity: [8 years, 4 months ago](https://wordpress.org/support/topic/access-context-variables-outside-plugin/#post-9917480)
 * Status: resolved