Support » Plugin: Bitcoin and Altcoin Wallets » Get Balance via PHPApi

  • Resolved user1010

    (@user1010)



    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

    (@dashedslug)

    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(), 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

    (@dashedslug)

    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

    The old way still works but is now deprecated.

    kind regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.