$object = new myCRED_Account();
Package: mycred/core Category: Objects

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

Back To Top

$object = new myCRED_Badge();
Package: mycred/badge Category: Objects

Description

The badge object holds the badge levels, each levels requirements and badge images.

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_Badge Object (
post_id int The badge post objects ID.
title string The badge title.
earnedby int The number of users that has earned this badge.
manual bool Indicates if the badge has been set to be manually awarded.
levels array Array of all the levels setup for this badge.
level array If a particular level is requested when the object is constructed, that selected levels settings are populated here.
level_label int If a particular level is requested when the object is constructed, that selected levels title is populated here.
level_image string If a particular level is requested when the object is constructed, that selected levels image is populated here.
main_image string The main badge image (if set).
image_width int The set value for the MYCRED_BADGE_WIDTH constant.
image_height int The set value for the MYCRED_BADGE_HEIGHT constant.
)

Methods

Variable Type Required Description
class myCRED_Badge extends myCRED_Object {
function __construct( $badge_id = NULL, $level = NULL ) {
$badge_id int Yes The badge post ID.
$level int No The badge level to populate.
}
public function get_image( $image = NULL ) {
$image string No The image to return. Accepts main to get the main image or the badge level.
}
}

Associated Functions

The badge object can be accessed via the mycred_get_badge function.

Object Example

myCRED_Badge Object
(
    [post_id] => 11516
    [title] => Spender
    [earnedby] => 0
    [manual] => 
    [levels] => Array
        (
            [0] => Array
                (
                    [attachment_id] => 0
                    [image_url] => 
                    [label] => 
                    [compare] => AND
                    [requires] => Array
                        (
                            [0] => Array
                                (
                                    [type] => mycred_default
                                    [reference] => approved_comment
                                    [amount] => 3
                                    [by] => count
                                )

                            [1] => Array
                                (
                                    [type] => mycred_default
                                    [reference] => visitor_referral
                                    [amount] => 1
                                    [by] => count
                                )

                        )

                    [reward] => Array
                        (
                            [type] => mycred_default
                            [log] => 
                            [amount] => 0
                        )

                )

            [1] => Array
                (
                    [attachment_id] => 0
                    [image_url] => 
                    [label] => 
                    [compare] => AND
                    [requires] => Array
                        (
                            [0] => Array
                                (
                                    [type] => mycred_default
                                    [reference] => approved_comment
                                    [amount] => 10
                                    [by] => count
                                )

                            [1] => Array
                                (
                                    [type] => mycred_default
                                    [reference] => visitor_referral
                                    [amount] => 10
                                    [by] => count
                                )

                        )

                    [reward] => Array
                        (
                            [type] => mycred_default
                            [log] => 
                            [amount] => 0
                        )

                )

        )

    [level] => 
    [level_label] => 
    [level_image] => 
    [main_image] => <img src="http://website.com/level-image.png" alt="" />
    [image_width] => 100
    [image_height] => 100

Last edited June 23, 2016

Back To Top

$object = new myCRED_Balance();
Package: mycred/balance Category: Objects

Description

The Balance object consists of the balance values for both the current and total balance along with the point type. A balance object only holds information about one particular point type.

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_Balance Object (
current int or float The balances current value. This represents the users current balance for this point type.
accumulated int or float The balances accumulated value. This represents the users total balance for this point type.
type object Holds the myCRED_Point_Type object with information about the point type associated with this balance.
)

Methods

Variable Type Required Description
class myCRED_Balance extends myCRED_Object {
function __construct( $user_id = NULL, $type = '', $mycred = NULL ) {
$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.
$mycred object No The myCRED_Settings class object, if available.
}
}

Object Example

myCRED_Balance Object
(
    [current] => 125
    [accumulated] => 125
    [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] => ,
                        )

                )

        )

)

Last edited June 23, 2016

Back To Top

$object = new myCRED_Point_Type();
Package: mycred/balance Category: Objects

Description

This object holds the format and name of a given point type that has been setup in myCRED.

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_Point_Type Object (
cred_id string The point type key.
singular string The point types given name in singular form.
plural string The point types given name in plural form.
prefix string The set prefix for this point type (if used).
suffix string The set suffix for this point type (if used).
format array An associated array about the format set for this point type. this includes:
  • type The type format used in the database. Bigint or decimal.
  • decimals The number of decimal places used for this point type.
  • separators An array containing the decimal and thousand separators.
)

Methods

Variable Type Required Description
class myCRED_Point_Type extends myCRED_Object {
function __construct( $type = '', $mycred = NULL ) {
$type string Yes The point type key to return.
$mycred object No The myCRED_Settings class object, if available.
}
public function number( $number ) {
$number int or float Yes A string value that is to be converted into an int or float based on the point type setup.
}
public function format( $number ) {
$number int or float Yes A point value to format with prefix / suffix based on the point type setup.
}
}

Object Example

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

Back To Top

$object = new myCRED_Rank();
Package: mycred/rank Category: Objects

Description

The rank object contains the rank post object, the set title, logo details, requirements and user count.

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_Rank Object (
post_id int The rank post objects ID.
post obj The WordPress post object as returned by get_post.
title string The rank title.
minimum string or float The minimum point requirement set for this rank.
maximum string or float The maximum point requirement set for this rank.
count string The total number of users with this rank.
has_logo bool True if the rank has a logo attachment set or false if not.
logo_id int The numeric attachment ID set as the rank logo.
logo_url string The rank logo URL. This is the URL to the original file and not to cropped versions.
image_width int The set value for the MYCRED_RANK_WIDTH constant.
image_height int The set value for the MYCRED_RANK_HEIGHT constant.
point_type obj Holds the myCRED_Point_Type object with information about the point type associated with this balance.
)

Methods

Variable Type Required Description
class myCRED_Rank extends myCRED_Object {
function __construct( $rank_id = NULL ) {
$rank_id int Yes The rank post ID.
}
public function get_image( $image = 'logo' ) {
$image string No The image to return. Right now it only supports "logo".
}
}

Associated Functions

The rank object can be accessed via the mycred_get_rank function.

Object Example

myCRED_Rank Object
(
    [post_id] => 2140
    [post] => WP_Post Object
        (
            [ID] => 2140
            [post_author] => 1
            [post_date] => 2013-11-22 12:24:20
            [post_date_gmt] => 2013-11-22 11:24:20
            [post_content] => 
            [post_title] => Senior Member
            [post_excerpt] => 
            [post_status] => publish
            [comment_status] => closed
            [ping_status] => closed
            [post_password] => 
            [post_name] => senior-member
            [to_ping] => 
            [pinged] => 
            [post_modified] => 2014-05-22 00:39:05
            [post_modified_gmt] => 2014-05-21 22:39:05
            [post_content_filtered] => 
            [post_parent] => 0
            [guid] => http://website.com/?post_type=mycred_rank&p=2140
            [menu_order] => 0
            [post_type] => mycred_rank
            [post_mime_type] => 
            [comment_count] => 0
            [filter] => raw
        )

    [title] => Senior Member
    [minimum] => 1000
    [maximum] => 4999
    [count] => 1
    [has_logo] => 1
    [logo_id] => 6627
    [logo_url] => http://website.com/wp-content/uploads/2013/11/rank-three.png
    [image_width] => 250
    [image_height] => 250
    [point_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] => ,
                        )

                )

        )

)

Last edited June 23, 2016

Back To Top

Last edited June 23, 2016