Wallet shortcodes display forms to the front-end that let the users access their cryptocurrency accounts.

All the operations accessible via shortcodes are only relevant to logged in users. The shortcodes will only display if:

  1. the user is logged in, and
  2. the user has the has_wallets capability, and
  3. there is at least one coin adapter online.

Note: The same set of UI elements is also available as widgets to be inserted in your theme’s widget area. Navigate to Appearance β†’ Widgets to configure, or set via the Customizer.

wallet shortcodes reference

deposit funds

Use the [wallets_deposit] shortcode to display a form that will let the user know which address they can send coins to if they wish to make a deposit.

Use the [wallets_deposit] shortcode to display a form that will let the user know which address they can send coins to if they wish to make a deposit.

withdraw funds

Use the [wallets_withdraw] shortcode to display a form that will let the user withdraw funds. The user will be notified by email when the withdrawal succeeds.

Use the [wallets_withdraw] shortcode to display a form that will let the user withdraw funds. The user will be notified by email when the withdrawal succeeds.

transfer funds to other users

Use the [wallets_move] shortcode to display a form that lets the user transfer coins to other users on your site. Both users will be notified by email when the transaction succeeds.

Use the [wallets_move] shortcode to display a form that lets the user transfer coins to other users on your site. Both users will be notified by email when the transaction succeeds.

display user balance(s)

Use the [wallets_balance] shortcode to show the current user’s balances.

Use the [wallets_balance] shortcode to show the current user’s balances.

view past transactions

Use the [wallets_transactions] shortcode to display an interactive table that shows past deposits, withdrawals and transfers that affect the user’s account. The table is paginated and data is loaded dynamically.

Use the [wallets_transactions] shortcode to display an interactive table that shows past deposits, withdrawals and transfers that affect the user’s account. The table is paginated and data is loaded dynamically.

capturing events on the front-side

Withdraw and move forms use JavaScript to emit bubbling DOM events to denote that a withdrawal or a transfer to another user has succeeded.

The event names are:

  • wallets_do_withdraw, and
  • wallets_do_move.

The default behavior is to display informative message boxes using the browser’s alert() function.

You can bind handlers to these DOM events to override, or to add to, this behavior.

The event handlers have access to the response of the JSON API, and to the form values entered by the user. Here’s some example JavaScript code:

Observing transfers between users:

jQuery('body').on( 'wallets_do_move', function( event, response, symbol, amount, toaccount, comment ) {
    if ( typeof(response.result) == 'string') {
        if ( response.result == 'success' ) {
            alert( 'Successfully sent ' + amount + ' ' + symbol );
        } else {
            alert( "Move failed: \n" + response.message );
        }
    } else {
        alert( "Move failed!" );
    }
    event.preventDefault();
});

Observing withdrawals:

jQuery('body').on( 'wallets_do_withdraw', function( event, response, symbol, amount, address, comment, commentto ) {
    if ( typeof(response.result) == 'string') {
        if ( response.result == 'success' ) {
            alert( 'Successfully withdrew ' + amount + ' ' + symbol + ' to ' + address );
        } else {
            alert( "Move failed: \n" + response.message );
        }
    } else {
        alert( "Move failed!" );
    }
    event.preventDefault();
});

The above examples override the default handlers. If you wish to add to the default behavior, simply delete the event.preventDefault() statements and let the events bubble up.

overriding the default UI

Using CSS

All the UI elements have the dashed-slug-wallets class to help you with CSS styling:

.dashed-slug-wallets.move { }
.dashed-slug-wallets.withdraw { }
.dashed-slug-wallets.balance { }
.dashed-slug-wallets.deposit { }
.dashed-slug-wallets.transactions { }

Using HTML and PHP and JavaScript and CSS and stuff!

If you are a developer, you can override the default forms provided to do much more than just change the styling.

All the UI elements are implemented as knockout.js forms that talk to the provided JSON API.

These forms live in the wp-content/plugins/wallets/includes/views directory of your WordPress installation:

wp-content/plugins/wallets/includes/views/balance.php
wp-content/plugins/wallets/includes/views/move.php
wp-content/plugins/wallets/includes/views/deposit.php
wp-content/plugins/wallets/includes/views/withdraw.php
wp-content/plugins/wallets/includes/views/transactions.php

You can copy these files to another directory of your choosing. Make sure to override the views directory using the wallets_views_dir filter, to let the plugin know where to look for the templates. Here’s sample code for how to do this:

function my_wallets_views_dir_override( $dir ) {
    return '/path/to/the/directory/where/the/new/templates/are/copied';
}
add_filter( 'wallets_views_dir', 'my_wallets_views_dir_override' );

download

Visit the download area to get this plugin!

Make sure to download the bundle to get the documentation too!

Wallet shortcodes

Updated on 2017-06-09T12:54:48+00:00, by alexg.