Title: Get Balance via PHPApi
Last modified: February 17, 2018

---

# Get Balance via PHPApi

 *  Resolved [user1010](https://wordpress.org/support/users/user1010/)
 * (@user1010)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/get-balance-via-phpapi/)
 * Hi there,
 * i really would like to know how to get the balance output.
 * Those are my php lines, which i am trying to get work:
 * Dashed_Slug_Wallets::get_instance();
    get_balance(‘BTC’, 0, false, $user_id);
 * But everytime i get the error:
 * Fatal error: Call to undefined function get_balance() in C:\xampp\apps\wordpress\
   htdocs\wp-content\themes\test\page-templates\dboard.php on line 231
 * Sorry for the noob question, but to get started i need to understand this and
   then i will know how to use full api.
 * Can you please give me an example to display the user balance via json api? Do
   you think it would be better to use json api in matter of fastness?

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

 *  Plugin Author [dashed-slug.net](https://wordpress.org/support/users/dashedslug/)
 * (@dashedslug)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/get-balance-via-phpapi/#post-9986312)
 * Hello,
 * You are very close. A little background: The `get_instance()` static method returns
   the singleton object that has the PHP API. This was done so as not to pollute
   the global namespace with functions. Polluting the global namespace is against
   the WordPress.org guidelines, and for good reason. Using PHP namespaces on the
   other hand is not compatible with some older version of PHP.
 * **So, what you need to do is hold the object into a variable, and then call the
   methods on that object, like so:**
 *  $dsw = Dashed_Slug_Wallets::get_instance();
    $dsw->get_balance( ‘BTC’, null,
   false, $user_id );
 * I have since realized that this is not ideal. I am currently moving towards a
   new implementation of the API which will be based on WordPress actions and filters,
   so as to not need to call static methods. This will also mean that calling an
   action or filter from an extension while the main plugin is not installed will
   not cause an error, thus eliminating the need for guard clauses of the form `
   if ( class_exists( 'Dashed_Slug_Wallets' ) ) { ...` .
 * The new API will make heavy use of [wp_parse_args()](https://codex.wordpress.org/Function_Reference/wp_parse_args),
   so that it will be easier to pass any number of arguments without worrying about
   the position of those arguments or providing defaults when not needed. Therefore,
   the new call will be something like:
 *  $balance = apply_filters( ‘wallets_api_balance’, 0, array( ‘symbol’ => ‘BTC’));
 * This change is scheduled for version 3.0.0. The old calls will continue to work
   as before but will be marked deprecated and there will be a deprecation warning
   printed in the logs. The deprecated calls will delegate to the new actions and
   filters. This will all be documented with examples in the documentation.
 *  Plugin Author [dashed-slug.net](https://wordpress.org/support/users/dashedslug/)
 * (@dashedslug)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/get-balance-via-phpapi/#post-10165784)
 * The above changes I discussed have now been implemented.
 * The preferred way to get a user’s balance is now as in the example given here:
 * [https://wallets-phpdoc.dashed-slug.net/classes/Dashed_Slug_Wallets_PHP_API.html#method_api_balance_filter](https://wallets-phpdoc.dashed-slug.net/classes/Dashed_Slug_Wallets_PHP_API.html#method_api_balance_filter)
 * The old way still works but is now deprecated.
 * kind regards

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

The topic ‘Get Balance via PHPApi’ is closed to new replies.

 * ![](https://ps.w.org/wallets/assets/icon-256x256.png?rev=1570088)
 * [Bitcoin and Altcoin Wallets](https://wordpress.org/plugins/wallets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wallets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wallets/)
 * [Active Topics](https://wordpress.org/support/plugin/wallets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wallets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wallets/reviews/)

## Tags

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

 * 2 replies
 * 2 participants
 * Last reply from: [dashed-slug.net](https://wordpress.org/support/users/dashedslug/)
 * Last activity: [8 years, 2 months ago](https://wordpress.org/support/topic/get-balance-via-phpapi/#post-10165784)
 * Status: resolved