Objects

Estimated reading: 34 minutes 1247 views
$object = new myCRED_Account();
Package: mycred/core Category: Objects
 

Description

The account object is an “umbrella” object of a given users myCRED related data. This includes their balance, history and data related to any add-ons that are enabled in your installation.

 

Interacting with Object

The account object can be accessed via the mycred_get_account function.

Object Properties

 PropertyTypeDescription
myCRED_Account Object (
 public $user_idINTThe users WordPress ID.
public $point_typesARRAYAn array of point type keys that the user is not excluded from.
public $balanceARRAYAn array of myCRED_Balance objects for all existing point types. If a user is excluded from a certain type, the value for the point type will be FALSE instead of a Point Type Object.
public $total_balanceINT or FLOATAll current balances added up into one lump sum.
public $historyARRAYAn array of point type keys that the user has log entries for. This property is only available if the Log module is enabled.
public $badgesARRAYAn array of myCRED_Badge objects that a user has earned or been assigned. This property is only available if the Badges add-on has been enabled.
public $badge_idsARRAYAn array of badge IDs and the level the user has reached. Note that badge levels start with the ID zero.This property is only available if the Badges add-on has been enabled.
public $ranksARRAYThe total number of ranks a user has. In most cases this is 1 but if you have ranks setup for multiple point types, this would equal to the number of point types a user has access to. This property is only available if the Ranks add-on has been enabled.
)

Object Methods

public function __construct( $user_id = NULL ) {
 Description:Constructs the account object if a valid user ID is provided.
VariableTypeRequiredDescription
$user_idINTYesThe users numeric ID.
}
public function get_balance( $type_id = MYCRED_DEFAULT_TYPE_KEY ) {
 Description:Retrieves the myCRED_Balance object of a given point type.
VariableTypeRequiredDescription
$type_idSTRINGNoThe point type key of the balance to return.
}

Object Example

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

    [balance] => Array
        (
            [mycred_default] => myCRED_Balance Object
                (
                    [current] => 4455
                    [accumulated] => 4874
                    [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] => ,
                                        )

                                )

                        )

                )

            [mycred_deed] => myCRED_Balance Object
                (
                    [current] => -203
                    [accumulated] => 47
                    [point_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] => ,
                                        )

                                )

                        )

                )

        )

    [total_balance] => 54689
    [history] => Array
        (
            [0] => mycred_default
            [1] => mycred_credit
        )
)
				
			
$object = new myCRED_Badge();
Package: mycred/badge Category: Objects
 

Description

This object holds all relevant information about a specific myCRED badge, along with a set of methods to manipulate the badge along with assigning it to users.

 

Interacting with Object

The badge object can be accessed via the mycred_get_badge function.

Object Properties

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

 PropertyTypeDescription
myCRED_Badge Object (
 public $post_idINTThe badge post object ID.
public $titleSTRINGThe badge title.
public $earnedbyINTThe number of users that has earned this badge.
public $manualBOOLIndicates if the badge has been set to be manually awarded.
public $levelsARRAYArray of all the levels setup for this badge.
public $main_imageSTRINGThe main badge image (if set).
public $levelARRAYIf a particular level is requested when the object is constructed, that selected levels settings are populated here.
public $level_idINTIf a particular level is requested when the object is constructed, that selected levels title is populated here.
public $level_labelSTRINGIf a particular level is requested when the object is constructed, that selected levels label is populated here.
public $level_imageSTRINGIf a particular level is requested when the object is constructed, that selected levels image is populated here (if the level has one).
public $image_widthINTThe set value for the MYCRED_BADGE_WIDTH constant.
public $image_heightINTThe set value for the MYCRED_BADGE_HEIGHT constant.
public $referencesARRAYAn array of reference keys that are used as a requirement for this badge.
public $referencesARRAYAn array of point type keys that are used as a requirement for this badge.
protected $user_meta_keySTRINGThe user meta key that is used to connect this badge with a particular user. This meta key differs if you use Multisites from regular WordPress installs.
public $current_levelINTIf a user is associated with this badge, this will indicate the level a user has reached. Remember that level IDs begin with zero for the first level.
)

Object Methods

public function __construct( $object = NULL, $level = NULL ) {
 Description:Constructs and populates the badge object.
VariableTypeRequiredDescription
$objectINT or OBJYesEither the badges post object or the post object ID.
$levelINTNoOption to populate a specific level of the badge.
}
public function get_user_count( $level_id = NULL ) {
 Description:Returns the total number of users that has earned this badge. A level ID can be provided to return a count for a specific badge level.
VariableTypeRequiredDescription
$level_idINTNoOption to return the count for a specific badge level.
}
public function get_level( $level_id = false ) {
 Description:Returns a specific level of this badge. Note that in it’s current form, this is an associative array of data. As of version 1.9, this will be replaced with a new myCRED_Badge_Level object. Returns FALSE if the badge level does not exists or an invalid level ID is provided.
VariableTypeRequiredDescription
$level_idINTYesThe badge level ID.
}
public function get_level_requirements( $level_id = false ) {
 Description:Returns a specific levels requirements as an associative array. Returns FALSE if the badge level does not exists or an invalid level ID is provided.
VariableTypeRequiredDescription
$level_idINTYesThe badge level ID.
}
public function get_level_reward( $level_id = false ) {
 Description:Returns a specific levels reward setup as an associative array. Returns FALSE if the badge level does not exists or an invalid level ID is provided.
VariableTypeRequiredDescription
$level_idINTYesThe badge level ID.
}
public function user_has_badge( $user_id = false, $level_id = 0 ) {
 Description:Checks to see if a specific user has earned this badge with the option to check if the user also has reached a certain level. Returns TRUE or FALSE. Note that if no $user_id is provided, this method will return FALSE.
VariableTypeRequiredDescription
$user_idINTYesThe users numeric ID.
$level_idINTNoOption to check if a user has reached a certain level.
}
public function get_users_current_level( $user_id = false ) {
 Description:Returns the level ID that a given user has reached with this badge. Will return FALSE if the user has not yet earned this badge.
VariableTypeRequiredDescription
$user_idINTYesThe users numeric ID.
}
public function query_users_level( $user_id = false ) {
 Description:This method will run the badge requirements and query the database for which level a user has reached. Will return FALSE if no level was reached (not yet earned the badge). This should only be used when new log entries have been added to the database and we need to run a new query. If you just need to get the users current level, use the get_users_current_level() method instead.
VariableTypeRequiredDescription
$user_idINTYesThe users numeric ID.
}
public function get_users_next_level_id( $user_id = false ) {
 Description:Returns the next level ID a user can reach based on their current position. If the user has reached the highest level, that levels ID is returned.
VariableTypeRequiredDescription
$user_idINTYesThe users numeric ID.
}
public function get_users_next_level( $user_id = false ) {
 Description:Returns the next level user can reach based on their current position. If the user has reached the highest level, that levels is returned.
VariableTypeRequiredDescription
$user_idINTYesThe users numeric ID.
}
public function assign( $user_id = false, $level_id = 0 ) {
 Description:Assigns a specific user to this badge with the option to also set a particular level that the user has reached.
VariableTypeRequiredDescription
$user_idINTYesThe users numeric ID.
$level_idINTYesThe badge level ID the user has reached. For the first level or if no levels are used, use zero.
}
public function payout_reward( $previous_level = -1, $new_level = 0 ) {
 Description:This method will payout the reward (if set) set for the levels a user reaches. If the user jumps multiple levels in one event, this method will payout the reward for every level the user jumped over.
VariableTypeRequiredDescription
$previous_levelINTYesThe previous level a user reached with this badge. If the user just now earned the badge, this variable should be -1 since level IDs start from zero.
$new_levelINTYesThe ID of the new level the user reached.
}
public function assign_all() {
 Description:This method will try to assign those users that have earned this badge. This is used when a badge is published for the first time or when the “Assign” button is used when editing a badge. Depending on your log size and user count, this method can require a lot of server resources to run. Please make sure you only run this when necessary!
}
public function divest( $user_id = false ) {
 Description:Removes this badge from a given user.
VariableTypeRequiredDescription
$user_idINTYesThe users numeric ID.
}
public function divest_all() {
 Description:Removes this badge from all users.
}
public function delete( $delete_post = false ) {
 Description:This method will delete this badge. Note that this method uses divest_all() to delete the badge form your users before deleting the badge’s setup.
VariableTypeRequiredDescription
$delete_postBOOLNoOption to also delete the WordPress post object. Warning! This will delete the object not trash it!
}
public function get_image( $image = NULL ) {
 Description:This method will return either the main badge image (used for when a badge has not yet been earned) or a specific levels image.
VariableTypeRequiredDescription
$imageINT or STRINGYesEither the keyword main to show the main image or the level ID for the image of a particular level.
}

Object Example

				
					myCRED_Badge Object
    (
        [post_id] => 29
        [title] => Best User
        [earnedby] => 1
        [manual] => 
        [levels] => Array
            (
                [0] => Array
                    (
                        [attachment_id] => 165
                        [image_url] => 
                        [label] => Commended
                        [compare] => AND
                        [requires] => Array
                            (
                                [0] => Array
                                    (
                                        [type] => mycred_default
                                        
    <span ezd-note-serial="1" id="serial-id-1" class="ezd-footnotes-link-item" data-bs-original-title="">
        <i onclick="location.href='#note-name-1'">
            [1]
        </i>
        <span></span>
    </span>

	 => manual
                                        [amount] => 1000
                                        [by] => sum
                                    )
                            )
                        [reward] => Array
                            (
                                [type] => mycred_default
                                [log] => 
                                [amount] => 0
                            )
                    )
                [1] => Array
                    (
                        [attachment_id] => 166
                        [image_url] => 
                        [label] => Hero
                        [compare] => AND
                        [requires] => Array
                            (
                                [0] => Array
                                    (
                                        [type] => mycred_default
                                        
    <span ezd-note-serial="1" id="serial-id-1" class="ezd-footnotes-link-item" data-bs-original-title="">
        <i onclick="location.href='#note-name-1'">
            [1]
        </i>
        <span></span>
    </span>

	 => manual
                                        [amount] => 5000
                                        [by] => sum
                                    )
                            )
                        [reward] => Array
                            (
                                [type] => mycred_default
                                [log] => 
                                [amount] => 0
                            )
                    )
            )
        [main_image] => ''
        [level] => Array
            (
            )

        [level_id] => 0
        [level_label] => ''
        [level_image] => Best User
        [image_width] => 100
        [image_height] => 100
        [references] => Array
            (
                [0] => manual
            )
        [point_types] => Array
            (
                [0] => mycred_default
            )
        [user_meta_key:protected] => mycred_badge29
        [user_id] => 125
        [current_level] => 0
        [compare] => AND
    )
				
			
$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.

 

Object Properties

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

 PropertyTypeDescription
myCRED_Balance Object (
 public $currentINT or FLOATThe balances current value. This represents the users current balance for this point type.
public $accumulatedINT or FLOATThe balances accumulated value. This represents the users total balance for this point type. This will always be zero if the total balance has been disabled using the MYCRED_ENABLE_TOTAL_BALANCE constant.
public $point_typeOBJECTThe myCRED_Point_Type object.
public $historyOBJECTThe myCRED_History object. This property is only available if the Log module is enabled.
public $rankOBJECTThe myCRED_Rank object. This property is only available if the Ranks add-on has been enabled.
)

Object Methods

Like all objects, the myCRED_Balance object has a populate method which is not publicly accessible. This object does inherit the methods of the myCRED_Object class.

Object Example

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

                )
            [history] => myCRED_History Object
                (
                    [has_history] => 1
                    [should_log] => 1
                    [data] => Array
                        (
                        )
                    [total_data] => 0

                )
            [rank] => myCRED_Rank Object
                (
                    [post_id] => 1
                    [post] => Array
                        (
                        )
                    [title] => Beginner
                    [minimum] => 100
                    [maximum] => 999
                    [count] => 125
                    [has_logo] => 1
                    [logo_id] => 0
                    [logo_url] => 'https://mysite.com/wp-content/uploads/rank-beginner.png'
                    [image_width] => 125
                    [image_height] => 125

                )

        )

)
				
			
$object = new myCred_Chart();
Package: mycred/stats Category: Objects
 

Description

This object is used to generate the chart HTML canvas element and construct the required JavaScript data for Chart.js. Used by the Statistics add-on. While the method only returns an empty HTML canvas element, the actual chart JavaScript data is populated using the $mycred_charts global. The statistics add-on uses this global to render the actual data in the footer of your website.

 

Interacting with Object

This object should be accessed using the mycred_create_chart function.

Object Properties

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

 PropertyTypeDescription
myCRED_Chart Object (
 public $argsARRAYGlobal attributes for the chart we want to render.
public $nowINTThe current UNIX timestamp.
public $point_typesARRAYAn associative array of point type keys and myCRED_Point_Type objects.
public $point_colorsARRAYAn associative array of point type keys and the colors saved to be used for each type.
public $date_formatSTRINGThe date format set in our WordPress settings.
public $time_formatSTRINGThe time format set in our WordPress settings.
)

Global Arguments:

KeyTypeDefaultDescription
typeSTRINGpieThe chart type we plan on constructing.
colorSTRING or ARRAYOption to set the color to use. This can be a string containing one color (mainly used for line charts) or an array containing a color for positive values and one for negative.
animateBOOLAdd-on SettingsIf the chart should be animated or not. Will enforce the default setting that you chose in your add-on settings.
bezierBOOLAdd-on SettingsIf the chart should use bezier curves for lines or not. Will enforce the default setting that you chose in your add-on settings.
x_labelsBOOLTRUEIf the labels for the X axis should be shown or not. Some references have long names and this can cause the chart to render small with long names.
label_maxINT20The maximum character length of the X axis label.
legendBOOLTRUEIf the chart legend should be shown or not.
titleSTRING or ARRAYOption to set a title for the chart. You can also provide an array of settings for more control of the rendered title.
widthINT or STRINGThe width of the canvas element. By default the element will be full width.
heightINT or STRING250The height of the canvas element.

Object Methods

public function __construct( $args = array() ) {
 Description:Constructs the objects and populates the object properties. It also parses the global arguments you provided.
VariableTypeRequiredDescription
$argsARRAYNoAn associative array of global arguments to use for the chart we are about to render.
}
public function apply_defaults( $args = array() ) {
 Description:This menthod will apply the default arguments to the arguments provided when the object was constructed.
VariableTypeRequiredDescription
$argsARRAYNoAn associative array of global arguments.
}
public function parse_args( $args = array() ) {
 Description:Parses your given global arguments, ensuring that valid values are used.
VariableTypeRequiredDescription
$argsARRAYNoAn associative array of global arguments.
}
public function get_chart_options() {
 Description:Returns the chart options object.
}
public function generate_element_id() {
 Description:Returns a unique ID to be applied on the canvas element.
}
public function get_canvas_styling() {
 Description:Returns the CSS styling that needs to be applied to the canvas element based on our global arguments.
}
public function get_reference_label( $reference = '' ) {
 Description:Returns the label for the given reference id.
VariableTypeRequiredDescription
$referenceSTRINGYesThe reference key.
}
public function generate_canvas( $type = '', $input = array() ) {
 Description:Returns the chart options object.
VariableTypeRequiredDescription
$typeSTRINGYesThe chart type we want to use.
$inputARRAYYesAn array of data to process.
}
public function pie_chart( $input = array() ) {
 Description:Generates a pie chart based on the provided $input data.
VariableTypeRequiredDescription
$inputARRAYYesAn array of data to process.
}
public function doughnut_chart( $input = array() ) {
 Description:Generates a doughnut chart based on the provided $input data.
VariableTypeRequiredDescription
$inputARRAYYesAn array of data to process.
}
public function line_chart( $input = array() ) {
 Description:Generates a line chart based on the provided $input data.
VariableTypeRequiredDescription
$inputARRAYYesAn array of data to process.
}
public function bar_chart( $input = array() ) {
 Description:Generates a bar chart based on the provided $input data.
VariableTypeRequiredDescription
$inputARRAYYesAn array of data to process.
}
public function polar_chart( $input = array() ) {
 Description:Generates a polar area chart based on the provided $input data.
VariableTypeRequiredDescription
$inputARRAYYesAn array of data to process.
}
public function radar_chart( $input = array() ) {
 Description:Generates a radar chart based on the provided $input data.
VariableTypeRequiredDescription
$inputARRAYYesAn array of data to process.
}

Object Example

				
					myCRED_Chart Object
(
    [args] => Array
        (
            [type] => pie
            [color] => 
            [animate] => true
            [bezier] => true
            [x_labels] => true
            [legend] => true
            [title] => 
            [width] => 
            [height] => 250
            [label_max] => 20
        )
    [point_types] => Array
        (
            [mycred_default] => 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] => ,
                                )

                        )
                    [lowest_value] => 1
                )
        )
    [point_colors] => Array
        (
            [mycred_default] => Array
                (
                    [positive] => #dedede
                    [negative] => #ddd000
                )
        )
    [date_format] => Y-m-d
    [time_format] => H:i
)
				
			
$object = new myCRED_Email();
Package: mycred/email Category: Objects
 

Description

This object holds all settings and data relevant to a given email notice along with a set of methods to process or parse emails.

 

 

Interacting with Object

This object should be accessed using the mycred_get_email_notice function.

Object Properties

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

 PropertyTypeDescription
myCRED_Email Object (
 public $post_idINTThe WordPress post object ID for the email notification.
public $postOBJECTThe WordPress post object.
public $point_typesARRAYAn array of point type keys that trigger this email.
public $emailnoticesARRAYThe Email Notice add-on’s settings.
public $settingsARRAYThe email notices settings.
protected $triggerSTRINGThe myCRED reference or keyword that triggers this email.
public $last_runINTUnix timestamp of the last time the email was triggered.
)

Object Methods

public function __construct( $notice_id = NULL ) {
 Description:Constructs the email notice object if provided a valid email notice post object ID.
VariableTypeRequiredDescription
$notice_idINTYesThe WordPress post object ID.
}
public function save_settings( $setup = array() ) {
 Description:Saves the email notice’s recipient, from email, from name and reply to field values.
VariableTypeRequiredDescription
$setupARRAYYesAn associative array of the settings we want to save.
}
public function get_trigger() {
 Description:Retrieves the emails set trigger. Will return an empty string if no trigger is set. Uses the mycred_get_emails_trigger filter.
}
public function set_trigger( $instance = '' ) {
 Description:Saves and sets a given instance as the new trigger for this email notice.
VariableTypeRequiredDescription
$instanceSTRINGYesThe keyword or reference (single or comma separated).
}
public function schedule( $event = array(), $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
 Description:Schedules an event of a given point type to be sent later. This method should not be used if emails are not scheduled but sent immediately. Note that this method does not check if the event should trigger an email, that should be done before this method is called.
VariableTypeRequiredDescription
$eventARRAYYesThe myCRED instance that triggered this email.
$point_typeSTRINGNoThe point type key that triggered this email.
}
public function send( $event = array(), $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
 Description:Sends an email based on a given event for a particular point type. Note that this method does not check if the event should trigger an email, that should be done before this method is called.
VariableTypeRequiredDescription
$eventARRAYYesThe myCRED instance that triggered this email.
$point_typeSTRINGNoThe point type key that triggered this email.
}
public function update_last_run( $timestamp = NULL ) {
 Description:Saves the unix timestamp that indicates when the email notice was last sent.
VariableTypeRequiredDescription
$timestampINTYesA UNIX timestamp.
}
public function get_email_styling() {
 Description:Returns the CSS styling set for this email notice. If the email notice has no CSS styling set, the CSS styling set in the add-on settings is returned instead.
}
public function get_recipients( $user = '', $admin = '' ) {
 Description:Returns an array of email addresses that the email should be sent to based on the recipient option.
VariableTypeRequiredDescription
$userSTRINGYesThe users email address.
$adminSTRINGYesThe administrators email address.
}
public function get_headers() {
 Description:Returns the email headers that should accompany the email.
}
public function get_subject( $event = array(), $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
 Description:Returns the emails subject (post title). Note that the subject field is parsed for general and amount related template tags.
VariableTypeRequiredDescription
$eventARRAYYesThe event that triggered this email. This is used to render template tags.
$point_typeSTRINGNoThe point type ID that triggered the email.
}
public function get_body( $event = array(), $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
 Description:Returns the emails body (post content). Note that the subject field is parsed for general and amount related template tags.
VariableTypeRequiredDescription
$eventARRAYYesThe event that triggered this email. This is used to render template tags.
$point_typeSTRINGNoThe point type ID that triggered the email.
}
public function get_message( $event = array(), $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
 Description:Returns the emails body (post content). Unlike the get_body() method, this method renders the content if the email is set to use HTML format. If you know that all emails are sent in plain text format, you can use the get_body() method instead. If emails are both plain text and HTML, it is recommended that you use this method instead.
VariableTypeRequiredDescription
$eventARRAYYesThe event that triggered this email. This is used to render template tags.
$point_typeSTRINGNoThe point type ID that triggered the email.
}

Object Example

				
					myCRED_Email Object
(
    [post_id] => 140
    [post] => WP_Post Object
        (
            [ID] => 140
            [post_author] => 2
            [post_date] => 2017-06-27 13:41:00
            [post_date_gmt] => 2017-06-27 11:41:00
            [post_content] => Congrats! You have successfully deposited %amount% coins into your account!
            [post_title] => Gaining Coins
            [post_excerpt] => 
            [post_status] => publish
            [comment_status] => closed
            [ping_status] => closed
            [post_password] => 
            [post_name] => gaining-coins
            [to_ping] => 
            [pinged] => 
            [post_modified] => 2017-09-27 22:19:53
            [post_modified_gmt] => 2017-09-27 20:19:53
            [post_content_filtered] => 
            [post_parent] => 0
            [guid] => http://yourwebsite.com/?post_type=mycred_email_notice&p=140
            [menu_order] => 0
            [post_type] => mycred_email_notice
            [post_mime_type] => 
            [comment_count] => 0
            [filter] => raw
        )
    [point_types] => Array
        (
            [0] => mycred_default
            [1] => mycred_credit
        )
    [emailnotices] => Array
        (
            [use_html] => 0
            [filter] => Array
                (
                    [subject] => 1
                    [content] => 1
                )
            [from] => Array
                (
                    [name] => The Laboratory
                    [email] => support@website.com
                    [reply_to] => support@website.com
                )
            [content] => 
            [styling] => 
            [send] => 
            [override] => 0
        )
    [settings] => Array
        (
            [recipient] => user
            [senders_name] => The Laboratory
            [senders_email] => donotreply@website.com
            [reply_to] => donotreply@website.com
        )
    [trigger:protected] => buy_scratch_card
    [last_run] => 1505314880
)
				
			
$object = new myCRED_History();
Package: mycred/log Category: Objects
 

Description

This object contains log related data for a given myCRED balance. It contains an array of data to help with certain history checks, such as checking if a user got a record of getting points for a certain object ID (e.g. post or page).

Note that this object is not available if the Log module has been disabled!

 

Object Properties

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

 PropertyTypeDescription
myCRED_History Object (
 public $has_historyBOOLIndicates if a given user has any log entries in the database.
public $should_logBOOLIndicates if the given users actions should be logged.
public $dataARRAY

An associative array of log entry data that belongs to the user. These log entries are grouped by reference, with the following data being available for each one:

  • rows The total number of log entries that exists for this reference and user.
  • reference The reference key.
  • total The sum of all log entries added up for this reference and user.
  • last_entry The timestamp of the latest log entry for this reference and user.
  • reference_ids An array of reference IDs amongst the log entries for this reference and user. Note that this array will only contain unique integers.
public $total_dataINTThe total number of log entries that exists in the database for the given user.
)

Object Methods

public function __construct( $user_id = NULL, $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
 Description:Constructs the history object for a specific user and for a specific point type.
VariableTypeRequiredDescription
$user_idINTYesThe users numeric ID.
$point_typeSTRINGYesThe point type key.
}
public function update_data( $reference = '', $value = '' ) {
 Description:Updates the data array for a given reference. Note that this only updates the object values, it does not actually save the given value anywhere, that should be done before using this method.
VariableTypeRequiredDescription
$referenceSTRINGYesThe reference key to update.
$valueARRAYYesThe actual data to add to the given reference.
}

Object Example

				
					myCRED_History Object
(
    [has_history] => 1
    [should_log] => 1
    [data] => Array
        (
            [buy_scratch_card] => stdClass Object
                (
                    [rows] => 10
                    
    <span ezd-note-serial="1" id="serial-id-1" class="ezd-footnotes-link-item" data-bs-original-title="">
        <i onclick="location.href='#note-name-1'">
            [1]
        </i>
        <span></span>
    </span>

	 => buy_scratch_card
                    [total] => -100
                    [last_entry] => 1505848450
                    [reference_ids] => Array
                        (
                            [0] => 149
                            [1] => 48
                        )
                )
            [win_scratch_card] => stdClass Object
                (
                    [rows] => 1
                    
    <span ezd-note-serial="1" id="serial-id-1" class="ezd-footnotes-link-item" data-bs-original-title="">
        <i onclick="location.href='#note-name-1'">
            [1]
        </i>
        <span></span>
    </span>

	 => win_scratch_card
                    [total] => 500
                    [last_entry] => 1498573857
                    [reference_ids] => Array
                        (
                            [1] => 48
                        )
                )
        )
    [total_data] => 11
)
				
			
$object = new myCRED_Point_Type();
Package: mycred/balance Category: Objects
 

Description

The myCRED_Point_Type object holds the structure and formatting of a given point type. It is used to ensure values are formatted correctly and are valid. It is used for both calculations as well as displaying or rendering point values.

 

Object Properties

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

 PropertyTypeDescription
myCRED_Point_Type Object (
 public $cred_idSTRINGThe point type key.
public $singularSTRINGThe point types given name in singular form.
public $pluralSTRINGThe point types given name in plural form.
public $prefixSTRINGThe set prefix for this point type (if used).
public $suffixSTRINGThe set suffix for this point type (if used).
public $formatARRAY

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.
public $lowest_valueINT or FLOATThis is the lowest point value that can be processed based on the format setup.
)
Object Methods
public function __construct( $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
 Description:Constructs the point type object based on a point type key.
VariableTypeRequiredDescription
$point_typeSTRINGYesThe point type key.
}
public function get_lowest_value() {
 Description:Returns the lowest amount this point type setup can handle. For point types that use integers, this will be 1 while if using two decimal places, it would be 0.01. Used to ensure myCRED does not attempt to handle partial points.
}
public function number( $number = '' ) {
 Description:Formats a given value based on the format setup used by this point type. A point type that uses decimals will be returned as a float else an integer.
VariableTypeRequiredDescription
$numberSTRINGYesA value that is to be converted into an int or float based on the point type setup.
}
public function format( $number = '' ) {
 Description:Returns a given value in a string form with separators, prefix or suffix applied. This method should only be used to display values and not for calculations.
VariableTypeRequiredDescription
$numberSTRINGYesThe point value to format.
}

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] => ,
                )

        )
    [lowest_value] => 1
)
				
			
$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.

 

 

Interacting with Object

The rank object can be accessed via the mycred_get_rank function.

Object Properties

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

 PropertyTypeDescription
myCRED_Rank Object (
 public $post_idINTThe rank post objects ID.
public $postOBJThe WordPress post object.
public $titleSTRINGThe rank title.
public $minimumINT or FLOATThe minimum point requirement set for this rank.
public $maximumINT or FLOATThe maximum point requirement set for this rank.
public $countINTThe total number of users with this rank.
public $has_logoBOOLTrue if the rank has a logo attachment set or false if not.
public $logo_idINTThe numeric attachment ID set as the rank logo.
public $logo_urlSTRINGThe rank logo URL. This is the URL to the original file and not to cropped versions.
public $image_widthINTThe set value for the MYCRED_RANK_WIDTH constant.
public $image_heightINTThe set value for the MYCRED_RANK_HEIGHT constant.
public $point_typeOBJHolds the myCRED_Point_Type object with information about the point type associated with this balance.
public $is_manualBOOLIndicates if the rank is using manual mode.
)

Object Methods

public function __construct( $rank_id = NULL ) {
 Description:Constructs and populates the object based on the given rank post ID.
VariableTypeRequiredDescription
$rank_idINTYesThe rank post object ID.
}
public function user_has_rank( $user_id = false ) {
 Description:Returns TRUE if the given user has this rank else FALSE.
VariableTypeRequiredDescription
$user_idINTYesThe users numeric ID.
}
public function assign( $user_id = false ) {
 Description:Assigns a specific user to this rank. Will return TRUE if successful else FALSE.
VariableTypeRequiredDescription
$user_idINTYesThe users numeric ID.
}
public function assign_all() {
 Description:Will attempt to assign all users that meet the requirements set for this rank.
}
public function divest( $user_id = false ) {
 Description:Removes a given user from this rank.
VariableTypeRequiredDescription
$user_idINTYesThe users numeric ID.
}
public function divest_all() {
 Description:Removes all users from this rank. Note that if the rank is set to use manual mode, this method will do nothing.
}
public function delete( $delete_post = true ) {
 Description:Deletes the rank post object. This method uses the divest_all() method before deleting the object.
VariableTypeRequiredDescription
$delete_postBOOLNoOption to just divest all users or also delete the post object.
}
public function get_image( $image = 'logo' ) {
 Description:Constructs and populates the object based on the given rank post ID.
VariableTypeRequiredDescription
$imageSTRINGYesCurrently only supports the logo keyword.
}

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] => ,
                        )

                )

        )

)
				
			
$object = new myCRED_Transfer();
Package: mycred/transfer Category: Objects
 

Description

The Transfer object is used for creating new transfers, rendering the transfer form or just retreating information about a particular transfer.


Interacting with Object

This is a utility object and it should not be accessed directly. Instead use one of the appropriate functions below:

Function Description
mycred_get_transfer Retrieves a specific, existing transfer based on the transfer ID.
mycred_new_transfer Attempts to process a transfer request. The request is first validated before it is executed (if now issues were found).
mycred_refund_transfer Attempts to refund a completed transfer.
mycred_transfer Returns a newly constructed myCRED_Transfer object. Should be used when you want to do multiple transfer related tasks or render a transfer form.

Object Properties

  Property Type Description
myCRED_Transfer Object (
  public $transfer_id STRING The transfers unique transaction ID.
public $reference STRING The reference used for this transfer.
public $status STRING The transfers status.
public $sender_id INT The numeric ID of the user that initiated the transfer.
public $recipient_id INT The numeric ID of the user that is the recipient of this transfer.
public $point_type OBJ Holds the myCRED_Point_Type object used in this transfer.
public $transfer_amount INT or FLOAT The original amount the sender requested to transfer to the recipient.
public $transfer_charge INT or FLOAT The amount that was charged from the senders account for this transfer.
public $transfer_payout INT or FLOAT The amount the transfer recipient received.
public $data ARRAY The transfer data array. This are used by some features to store additional information about the transfer. The transfer message is stored here.
public $message STRING The transfer message (if used).
public $settings ARRAY The transfer add-ons settings.
public $now INT The current UNIX timestamp.
public $args ARRAY The arguments that is used for rendering the transfer form. Populated when rendering the transfer form.
public $request ARRAY The transfer request. Populated when making a new transfer request.
public $valid_request BOOL Indicates if a new transfer request is valid or not. Populated when a new transfer request is created.
public $transferable_types ARRAY An array of point type keys that a given user can transfer. Populated when a new transfer request is created.
public $balances ARRAY An associative array of point type keys and balances of the user making a transfer. Populated when a new transfer request is created.
public $limits ARRAY An array of limits that exists for each point type that is transferrable. Populated when a new transfer request is created.
public $minimum INT or FLOAT The minimum amount a user must transfer. Populated when a new transfer request is created.
public $errors ARRAY Any errors that occur during a new transfer request or transfer process is stored in this array.
)

Object Methods

public function __construct( $transfer_id = false ) {
  Description: Constructs the object.
Variable Type Required Description
$transfer_id STRING No A transfer ID unless a new transfer request is about to be made.
}
public function generate_new_transfer_id( $sender_id = 0, $recipient_id = 0 ) {
  Description: Generates a new transfer ID based on the senders and recipients IDs.
Variable Type Required Description
$sender_id INT Yes The numeric ID of the user sending the transfer.
$recipient_id INT Yes The numeric ID of the recipient of the transfer.
}
public function get_transfer( $transfer_id = false ) {
  Description: Retrieves a particular transfer from the database and populates the object. Returns FALSE if the transfer could not be found or the transfer ID value is invalid.
Variable Type Required Description
$transfer_id STRING or ARRAY Yes Either the transaction ID or if you have the two transfer log entries for the transfer, an array of this two log entries.
}
public function get_transfer_statuses() {
  Description:

Returns all possible transfer statuses. The default statuses are:

  • empty an empty status indicates the transfer is new.
  • incomplete Incomplete transfer. This indicates new transfers that has not yet been processed or if the request is invalid.
  • completed Completed transfer.
  • refunded Refunded transfer.
}
public function get_transfer_status() {
  Description: Retrieves the transfer current status code.
}
public function display_transfer_status( $status = NULL ) {
  Description: Translates a status code into a readable status description.
Variable Type Required Description
$status STRING No Option to render a different status then the status set in the object.
}
public function new_instance( $request = array() ) {
  Description: Creates a new transfer instance. Before a user can make a transfer, we need to setup an instance that tells myCRED what kind of transfer this is by setting a reference key, which point types that can be transferred along with limits and minimum requirement. Optionally this can also include what point amounts can be transferred and who the recipient is for the transfer. Once this instance is created, we can check if a user that wants to make a transfer can do so. This method should be used before rendering any transfer forms.
Variable Type Required Description
$request ARRAY No The transfer request array.
}
public function user_can_transfer_minimum() {
  Description: Checks if the given user in the current instance can transfer the minimum amount we have set in our transfer settings.
}
public function get_transfer_limit() {
  Description: Returns either FALSE if no transfer limit is set or a standard class of the limit setup based on your Transfer add-on settings.
}
public function get_transfer_limit_desc( $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
  Description: Converts any limit that exists for a particular point type into something readable. If no limit is set, the method will return “No Limit”.
Variable Type Required Description
$point_type STRING No The point type key.
}
public function user_is_over_limit() {
  Description: Checks if the user making a transfer is over their transfer limit for each point type that they can transfer. Returns either TRUE or FALSE.
}
public function is_valid_transfer_request( $request = array(), $posted = array() ) {
  Description: Validates a new transfer request that was submitted by a transfer form.
Variable Type Required Description
$request ARRAY Yes The transfer request array.
$posted ARRAY Yes The content of the submitted transfer form.
}
public function new_transfer() {
  Description:

Processes a valid transfer request. This method should only be called after using is_valid_transfer_request() method or if we have validated the request ourselves. Returns FALSE if the transfer failed else a status array:

  • amount – The point amount that the sender was charged.
  • css – The CSS class selector for the point type that was transferred.
  • balance – The senders remaining balance after the transfer formatted.
  • zero – Indicates if the transfer has lead to the senders account to reach zero or below.
}
public function refund() {
  Description: Attempts to refund the current transfer. Requires the transfer to be populated before this method is called. Returns TRUE on success else FALSE.
}
public function get_transfer_form( $args = array() ) {
  Description: Returns a transfer form in a string format based on both the transfer instance we created and the arguments provided.
Variable Type Required Description
$args ARRAY Yes

An array of arguments related to the form that we want to render. This includes:

  • button – The submit button label.
  • button_class – The submit buttons class.
  • show_balance – Indicates if a users balance should be shown in the form.
  • show_limit – Indicates if limits should be shown in the form.
  • placeholder – The placeholder text to use for the recipient field.
  • recipient_label – The recipient field label.
  • amount_label – The amount field label.
  • balance_label – The balance label.
  • message_label – The message field label.
}
public function get_transfer_recipient_field( $return = false ) {
  Description: Renders the transfer recipient field.
Variable Type Required Description
$return BOOL No Indicates if the HTML code should be echoed or returned.
}
public function get_transfer_points_field( $return = false ) {
  Description: Renders columns for the transfer amount and point type fields. This method will render columns based on which of these two fields is needed.
Variable Type Required Description
$return BOOL No Indicates if the HTML code should be echoed or returned.
}
public function get_transfer_amount_field( $return = false ) {
  Description: Renders the transfer amount field.
Variable Type Required Description
$return BOOL No Indicates if the HTML code should be echoed or returned.
}
public function get_transfer_point_type_field( $return = false ) {
  Description: Renders the point type selection field. Used only when more than one point type can be transferred.
Variable Type Required Description
$return BOOL No Indicates if the HTML code should be echoed or returned.
}
public function get_transfer_extra_fields( $return = false ) {
  Description: Renders extra transfer information such as balances and limits (if used and set to show).
Variable Type Required Description
$return BOOL No Indicates if the HTML code should be echoed or returned.
}
public function get_error_message( $return = false ) {
  Description: Renders any errors that a request has generated.
Variable Type Required Description
$return BOOL No Indicates if the HTML code should be echoed or returned.
}

Object Example

				
					myCRED_Transfer Object
(
    [transfer_id] => 68bae8
    
    <span ezd-note-serial="1" id="serial-id-1" class="ezd-footnotes-link-item" data-bs-original-title="">
        <i onclick="location.href='#note-name-1'">
            [1]
        </i>
        <span></span>
    </span>

	 => transfer
    [status] => completed
    [sender_id] => 2
    [recipient_id] => 4
    [point_type] => myCRED_Point_Type Object
        (
            [cred_id] => mycred_default
            [singular] => Coin
            [plural] => Coins
            [prefix] => 
            [suffix] => co.
            [format] => Array
                (
                    [type] => bigint
                    [decimals] => 0
                    [separators] => Array
                        (
                            [decimal] => .
                            [thousand] => ,
                        )

                )

            [lowest_value] => 1
            [sql_format] => %d
        )

    [transfer_amount] => 80
    [transfer_charge] => 80
    [transfer_payout] => 80
    [data] => Array
        (
            [ref_type] => user
            [tid] => 68bae8
        )

    [message] => 
    [settings] => Array
        (
            [types] => Array
                (
                    [0] => mycred_default
                )

            [logs] => Array
                (
                    [sending] => Transfer of %plural% to %display_name%
                    [receiving] => Transfer of %plural% from %display_name%
                )

            [errors] => Array
                (
                    [low] => You do not have enough %plural% to send.
                    [over] => You have exceeded your %limit% transfer limit.
                )

            [templates] => Array
                (
                    [login] => 
                    [balance] => Your current balance is %balance%
                    [limit] => Your current %limit% transfer limit is %left%
                    [button] => Transfer
                )

            [autofill] => user_login
            [reload] => 1
            [message] => 0
            [limit] => Array
                (
                    [amount] => 0
                    [limit] => none
                )

        )

    [now] => 1507158010
    [args] => Array
        (
        )

    [request] => Array
        (
        )

    [valid_request] => 
    [transferable_types] => Array
        (
        )

    [balances] => Array
        (
        )

    [limits] => Array
        (
        )

    [minimum] => 0
    [errors] => Array
        (
        )

)