Title: Import Wordfence Settings from php code
Last modified: September 27, 2021

---

# Import Wordfence Settings from php code

 *  Resolved [gregnowak](https://wordpress.org/support/users/gregnowak/)
 * (@gregnowak)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/import-wordfence-settings-from-php-code/)
 * Hello!
 * I can see the wordfence API documentation: [https://www.wordfence.com/help/advanced/wordfence-api/](https://www.wordfence.com/help/advanced/wordfence-api/)
 * It has the function: wordfence::importSettings($token)
 * If I make a php script “test.php” server side like this:
 *     ```
       <?php
       require_once 'wordfenceConstants.php';
       require_once 'wordfenceClass.php';
   
       wordfence::importSettings('MY_SECRET_TOKEN')
   
       ?>
       ```
   
 * Then I get errors, any hints, tips or tricks? Thanks!:
 *     ```
       php test.php 
       PHP Fatal error:  Uncaught Error: Call to undefined function wp_cache_get() in /home/www/example.com/wp-content/plugins/wordfence/lib/wfConfig.php:285
       Stack trace:
       #0 /home/www/example.com/wp-content/plugins/wordfence/lib/wfConfig.php(368): wfConfig::loadAllOptions()
       #1 /home/www/example.com/wp-content/plugins/wordfence/lib/wfConfig.php(520): wfConfig::hasCachedOption()
       #2 /home/www/example.com/wp-content/plugins/wordfence/lib/wfCredentialsController.php(12): wfConfig::get()
       #3 /home/www/example.com/wp-content/plugins/wordfence/lib/wfCredentialsController.php(16): wfCredentialsController::allowLegacy2FA()
       #4 /home/www/example.com/wp-content/plugins/wordfence/lib/wordfenceClass.php(48): wfCredentialsController::useLegacy2FA()
       #5 /home/www/example.com/wp-content/plugins/wordfence/lib/test.php(3): require_once('/home/www/example...')
       #6 {main}
         thrown in /home/www/example.com/wp-content/plugins/wordfence/lib/wfConfig.php on line 285
       ```
   

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

 *  Thread Starter [gregnowak](https://wordpress.org/support/users/gregnowak/)
 * (@gregnowak)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/import-wordfence-settings-from-php-code/#post-14914882)
 * Or is the wordfence-api only available for the paid version of the wordfence 
   plugin?
 *  Plugin Support [wfpeter](https://wordpress.org/support/users/wfpeter/)
 * (@wfpeter)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/import-wordfence-settings-from-php-code/#post-14916625)
 * Hi [@gregnowak](https://wordpress.org/support/users/gregnowak/), thanks for getting
   in touch.
 * The missing function `wp_cache_get()` can be fixed by also requiring `wp-load.
   php` at the stop of your page code.
 * Thanks,
 * Peter.
 *  Thread Starter [gregnowak](https://wordpress.org/support/users/gregnowak/)
 * (@gregnowak)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/import-wordfence-settings-from-php-code/#post-14918979)
 * Hi [@wfpeter](https://wordpress.org/support/users/wfpeter/)!
 * Thank you very much for the info about wp-load.php, this did the trick and import
   function works!
 * Is there anywhere I can find this information in the documentation?
 * Thanks again.
 * /Greg
 *  Plugin Support [wfpeter](https://wordpress.org/support/users/wfpeter/)
 * (@wfpeter)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/import-wordfence-settings-from-php-code/#post-14942863)
 * Hi [@gregnowak](https://wordpress.org/support/users/gregnowak/),
 * I have notified the development team that this may need to be made clearer. Thanks
   for getting back to me and I’m glad it’s working now for you.
 * Peter.
 *  Thread Starter [gregnowak](https://wordpress.org/support/users/gregnowak/)
 * (@gregnowak)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/import-wordfence-settings-from-php-code/#post-14945795)
 * Hi [@wfpeter](https://wordpress.org/support/users/wfpeter/)!
 * Great, thank you!
 * /Greg

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

The topic ‘Import Wordfence Settings from php code’ is closed to new replies.

 * ![](https://ps.w.org/wordfence/assets/icon.svg?rev=2070865)
 * [Wordfence Security - Firewall, Malware Scan, and Login Security](https://wordpress.org/plugins/wordfence/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordfence/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordfence/)
 * [Active Topics](https://wordpress.org/support/plugin/wordfence/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordfence/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordfence/reviews/)

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)

 * 5 replies
 * 2 participants
 * Last reply from: [gregnowak](https://wordpress.org/support/users/gregnowak/)
 * Last activity: [4 years, 8 months ago](https://wordpress.org/support/topic/import-wordfence-settings-from-php-code/#post-14945795)
 * Status: resolved