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.
Object Properties
Property | Type | Description | |
---|---|---|---|
myCRED_Account Object ( | |||
public $user_id | INT | The users WordPress ID. | |
public $point_types | ARRAY | An array of point type keys that the user is not excluded from. | |
public $balance | ARRAY | An 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_balance | INT or FLOAT | All current balances added up into one lump sum. | |
public $history | ARRAY | An array of point type keys that the user has log entries for. This property is only available if the Log module is enabled. | |
public $badges | ARRAY | An 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_ids | ARRAY | An 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 $ranks | ARRAY | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$user_id | INT | Yes | The users numeric ID. | |
} |
public function get_balance( $type_id = MYCRED_DEFAULT_TYPE_KEY ) { | ||||
Description: | Retrieves the myCRED_Balance object of a given point type. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$type_id | STRING | No | The 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
)
)
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.
Object Properties
Note that the constructor class will auto populate these values when the class is constructed.
Property | Type | Description | |
---|---|---|---|
myCRED_Badge Object ( | |||
public $post_id | INT | The badge post object ID. | |
public $title | STRING | The badge title. | |
public $earnedby | INT | The number of users that has earned this badge. | |
public $manual | BOOL | Indicates if the badge has been set to be manually awarded. | |
public $levels | ARRAY | Array of all the levels setup for this badge. | |
public $main_image | STRING | The main badge image (if set). | |
public $level | ARRAY | If a particular level is requested when the object is constructed, that selected levels settings are populated here. | |
public $level_id | INT | If a particular level is requested when the object is constructed, that selected levels title is populated here. | |
public $level_label | STRING | If a particular level is requested when the object is constructed, that selected levels label is populated here. | |
public $level_image | STRING | If a particular level is requested when the object is constructed, that selected levels image is populated here (if the level has one). | |
public $image_width | INT | The set value for the MYCRED_BADGE_WIDTH constant. | |
public $image_height | INT | The set value for the MYCRED_BADGE_HEIGHT constant. | |
public $references | ARRAY | An array of reference keys that are used as a requirement for this badge. | |
public $references | ARRAY | An array of point type keys that are used as a requirement for this badge. | |
protected $user_meta_key | STRING | The 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_level | INT | If 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$object | INT or OBJ | Yes | Either the badges post object or the post object ID. | |
$level | INT | No | Option 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$level_id | INT | No | Option 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$level_id | INT | Yes | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$level_id | INT | Yes | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$level_id | INT | Yes | The 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 . | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$user_id | INT | Yes | The users numeric ID. | |
$level_id | INT | No | Option 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$user_id | INT | Yes | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$user_id | INT | Yes | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$user_id | INT | Yes | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$user_id | INT | Yes | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$user_id | INT | Yes | The users numeric ID. | |
$level_id | INT | Yes | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$previous_level | INT | Yes | The 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_level | INT | Yes | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$user_id | INT | Yes | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$delete_post | BOOL | No | Option 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$image | INT or STRING | Yes | Either 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
[1]
=> 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
[1]
=> 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
)
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.
Property | Type | Description | |
---|---|---|---|
myCRED_Balance Object ( | |||
public $current | INT or FLOAT | The balances current value. This represents the users current balance for this point type. | |
public $accumulated | INT or FLOAT | The 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_type | OBJECT | The myCRED_Point_Type object. | |
public $history | OBJECT | The myCRED_History object. This property is only available if the Log module is enabled. | |
public $rank | OBJECT | The 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
)
)
)
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.
Object Properties
Note that the constructor class will auto populate these values when the class is constructed.
Property | Type | Description | |
---|---|---|---|
myCRED_Chart Object ( | |||
public $args | ARRAY | Global attributes for the chart we want to render. | |
public $now | INT | The current UNIX timestamp. | |
public $point_types | ARRAY | An associative array of point type keys and myCRED_Point_Type objects. | |
public $point_colors | ARRAY | An associative array of point type keys and the colors saved to be used for each type. | |
public $date_format | STRING | The date format set in our WordPress settings. | |
public $time_format | STRING | The time format set in our WordPress settings. | |
) |
Global Arguments:
Key | Type | Default | Description |
---|---|---|---|
type | STRING | pie | The chart type we plan on constructing. |
color | STRING or ARRAY | – | Option 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. |
animate | BOOL | Add-on Settings | If the chart should be animated or not. Will enforce the default setting that you chose in your add-on settings. |
bezier | BOOL | Add-on Settings | If the chart should use bezier curves for lines or not. Will enforce the default setting that you chose in your add-on settings. |
x_labels | BOOL | TRUE | If 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_max | INT | 20 | The maximum character length of the X axis label. |
legend | BOOL | TRUE | If the chart legend should be shown or not. |
title | STRING or ARRAY | – | Option to set a title for the chart. You can also provide an array of settings for more control of the rendered title. |
width | INT or STRING | – | The width of the canvas element. By default the element will be full width. |
height | INT or STRING | 250 | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$args | ARRAY | No | An 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$args | ARRAY | No | An associative array of global arguments. | |
} |
public function parse_args( $args = array() ) { | ||||
Description: | Parses your given global arguments, ensuring that valid values are used. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$args | ARRAY | No | An 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$reference | STRING | Yes | The reference key. | |
} |
public function generate_canvas( $type = '', $input = array() ) { | ||||
Description: | Returns the chart options object. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$type | STRING | Yes | The chart type we want to use. | |
$input | ARRAY | Yes | An array of data to process. | |
} |
public function pie_chart( $input = array() ) { | ||||
Description: | Generates a pie chart based on the provided $input data. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$input | ARRAY | Yes | An array of data to process. | |
} |
public function doughnut_chart( $input = array() ) { | ||||
Description: | Generates a doughnut chart based on the provided $input data. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$input | ARRAY | Yes | An array of data to process. | |
} |
public function line_chart( $input = array() ) { | ||||
Description: | Generates a line chart based on the provided $input data. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$input | ARRAY | Yes | An array of data to process. | |
} |
public function bar_chart( $input = array() ) { | ||||
Description: | Generates a bar chart based on the provided $input data. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$input | ARRAY | Yes | An array of data to process. | |
} |
public function polar_chart( $input = array() ) { | ||||
Description: | Generates a polar area chart based on the provided $input data. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$input | ARRAY | Yes | An array of data to process. | |
} |
public function radar_chart( $input = array() ) { | ||||
Description: | Generates a radar chart based on the provided $input data. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$input | ARRAY | Yes | An 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
)
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.
Object Properties
Note that the constructor class will auto populate these values when the class is constructed.
Property | Type | Description | |
---|---|---|---|
myCRED_Email Object ( | |||
public $post_id | INT | The WordPress post object ID for the email notification. | |
public $post | OBJECT | The WordPress post object. | |
public $point_types | ARRAY | An array of point type keys that trigger this email. | |
public $emailnotices | ARRAY | The Email Notice add-on’s settings. | |
public $settings | ARRAY | The email notices settings. | |
protected $trigger | STRING | The myCRED reference or keyword that triggers this email. | |
public $last_run | INT | Unix 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$notice_id | INT | Yes | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$setup | ARRAY | Yes | An 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$instance | STRING | Yes | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$event | ARRAY | Yes | The myCRED instance that triggered this email. | |
$point_type | STRING | No | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$event | ARRAY | Yes | The myCRED instance that triggered this email. | |
$point_type | STRING | No | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$timestamp | INT | Yes | A 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$user | STRING | Yes | The users email address. | |
$admin | STRING | Yes | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$event | ARRAY | Yes | The event that triggered this email. This is used to render template tags. | |
$point_type | STRING | No | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$event | ARRAY | Yes | The event that triggered this email. This is used to render template tags. | |
$point_type | STRING | No | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$event | ARRAY | Yes | The event that triggered this email. This is used to render template tags. | |
$point_type | STRING | No | The 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
)
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.
Property | Type | Description | |
---|---|---|---|
myCRED_History Object ( | |||
public $has_history | BOOL | Indicates if a given user has any log entries in the database. | |
public $should_log | BOOL | Indicates if the given users actions should be logged. | |
public $data | ARRAY | 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:
| |
public $total_data | INT | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$user_id | INT | Yes | The users numeric ID. | |
$point_type | STRING | Yes | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$reference | STRING | Yes | The reference key to update. | |
$value | ARRAY | Yes | The 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
[1]
=> buy_scratch_card
[total] => -100
[last_entry] => 1505848450
[reference_ids] => Array
(
[0] => 149
[1] => 48
)
)
[win_scratch_card] => stdClass Object
(
[rows] => 1
[1]
=> win_scratch_card
[total] => 500
[last_entry] => 1498573857
[reference_ids] => Array
(
[1] => 48
)
)
)
[total_data] => 11
)
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.
Property | Type | Description | |
---|---|---|---|
myCRED_Point_Type Object ( | |||
public $cred_id | STRING | The point type key. | |
public $singular | STRING | The point types given name in singular form. | |
public $plural | STRING | The point types given name in plural form. | |
public $prefix | STRING | The set prefix for this point type (if used). | |
public $suffix | STRING | The set suffix for this point type (if used). | |
public $format | ARRAY | An associated array about the format set for this point type. this includes:
| |
public $lowest_value | INT or FLOAT | This is the lowest point value that can be processed based on the format setup. | |
) |
public function __construct( $point_type = MYCRED_DEFAULT_TYPE_KEY ) { | ||||
Description: | Constructs the point type object based on a point type key. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$point_type | STRING | Yes | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$number | STRING | Yes | A 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$number | STRING | Yes | The 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
)
Description
The rank object contains the rank post object, the set title, logo details, requirements and user count.
Object Properties
Note that the constructor class will auto populate these values when the class is constructed.
Property | Type | Description | |
---|---|---|---|
myCRED_Rank Object ( | |||
public $post_id | INT | The rank post objects ID. | |
public $post | OBJ | The WordPress post object. | |
public $title | STRING | The rank title. | |
public $minimum | INT or FLOAT | The minimum point requirement set for this rank. | |
public $maximum | INT or FLOAT | The maximum point requirement set for this rank. | |
public $count | INT | The total number of users with this rank. | |
public $has_logo | BOOL | True if the rank has a logo attachment set or false if not. | |
public $logo_id | INT | The numeric attachment ID set as the rank logo. | |
public $logo_url | STRING | The rank logo URL. This is the URL to the original file and not to cropped versions. | |
public $image_width | INT | The set value for the MYCRED_RANK_WIDTH constant. | |
public $image_height | INT | The set value for the MYCRED_RANK_HEIGHT constant. | |
public $point_type | OBJ | Holds the myCRED_Point_Type object with information about the point type associated with this balance. | |
public $is_manual | BOOL | Indicates 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$rank_id | INT | Yes | The rank post object ID. | |
} |
public function user_has_rank( $user_id = false ) { | ||||
Description: | Returns TRUE if the given user has this rank else FALSE . | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$user_id | INT | Yes | The users numeric ID. | |
} |
public function assign( $user_id = false ) { | ||||
Description: | Assigns a specific user to this rank. Will return TRUE if successful else FALSE . | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$user_id | INT | Yes | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$user_id | INT | Yes | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$delete_post | BOOL | No | Option 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
$image | STRING | Yes | Currently 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] => ,
)
)
)
)
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:
|
|||
---|---|---|---|---|
} |
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
|
|||
---|---|---|---|---|
} |
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:
|
|
} |
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
[1]
=> 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
(
)
)