$object = new myCRED_Account();

Codex / mycred/core / Objects / myCRED_Account

Description

The account object is an “umbrella” for a give users myCRED account details, such as their balance, history, badges and ranks. By default, the object mainly consists of a users balance. As you enable add-ons, this object gets extended with further details, such as their rank or earned badges for example.

The account object is constructed by myCRED on each page load where the website is accessed by a logged in user that is not set to be excluded. The $mycred_account object becomes available during WordPress’ init event. You can add your own custom details to the object using the mycred_set_globals action hook.

Available since version 1.7

Properties

Note that the constructor class will auto populate these values when the class is constructed.

Property Type Description
myCRED_Account Object (
user_id int The numeric User ID of the user as given by WordPress.
point_types array An array of point type keys that are installed on this website.
balance array An associated array of balances where the array key is the point type key and it's value a myCRED_Balance object. IF the class was constructed with a particular point type, the array will only contain one balance object and the array key will be zero instead of the point type key.
)

Methods

Variable Type Required Description
class myCRED_Account extends myCRED_Object {
function __construct( $user_id = NULL, $type = '' ) {
$user_id int Yes The user ID.
$type string No The point type key to return. Should be left empty if we want to return all point types.
}
public function get_balance( $type_id = MYCRED_DEFAULT_TYPE_KEY, $mycred = NULL ) {
$type_id string No The point type key of the balance to return.
$mycred object No The myCRED_Settings class object, if available.
}
public function get_type( $type_id = MYCRED_DEFAULT_TYPE_KEY, $mycred = NULL ) {
$type_id string No The point type key.
$mycred object No The myCRED_Settings class object, if available.
}
}

Associated Functions

The account object can be accessed via the mycred_account function.

Object Example

myCRED_Account Object
(
    [user_id] => 1
    [point_types] => Array
        (
            [mycred_default] => Tokens
            [mycred_deed] => Deeds
        )

    [balance] => Array
        (
            [mycred_default] => myCRED_Balance Object
                (
                    [current] => 4455
                    [accumulated] => 4874
                    [type] => myCRED_Point_Type Object
                        (
                            [cred_id] => mycred_default
                            [singular] => Token
                            [plural] => Tokens
                            [prefix] => 
                            [suffix] => tk.
                            [format] => Array
                                (
                                    [type] => bigint
                                    [decimals] => 0
                                    [separators] => Array
                                        (
                                            [decimal] => .
                                            [thousand] => ,
                                        )

                                )

                        )

                )

            [mycred_deed] => myCRED_Balance Object
                (
                    [current] => -203
                    [accumulated] => 47
                    [type] => myCRED_Point_Type Object
                        (
                            [cred_id] => mycred_deed
                            [singular] => Deed
                            [plural] => Deeds
                            [prefix] => 
                            [suffix] => de.
                            [format] => Array
                                (
                                    [type] => bigint
                                    [decimals] => 0
                                    [separators] => Array
                                        (
                                            [decimal] => .
                                            [thousand] => ,
                                        )

                                )

                        )

                )

        )

)

Last edited June 23, 2016