A free points management plugin for WordPress.
myCRED Logo
myCRED Logo
  • Membership New
  • Chapters
    • Chapter I – Introduction
    • Chapter II – Getting Started
    • Chapter III – Add-ons
    • Chapter IV – Premium Add-ons
    • Chapter V – For Developers
    • Chapter VI – Reference Guides
  • Categories
    • Actions
    • Classes
    • Constants
    • Filters
    • Functions
    • Objects
    • Shortcodes
    • Hooks
    • Template Tags
  • Packages
    • mycred/api
    • mycred/badge
    • mycred/balance
    • mycred/banking
    • mycred/content
    • mycred/core
    • mycred/coupon
    • mycred/email
    • mycred/game
    • mycred/log
    • mycred/notice
    • mycred/payment
    • mycred/purchase
    • mycred/rank
    • mycred/transfer
  • Store
  • Download
Chapter I
Introduction
  1. The Plugin
  2. Points
  3. The Log
  4. Administration
  5. Automatic Points
  6. Multisites
    • Master Template
    • Central Logging
  7. Add-ons
  8. Supported Plugins
  9. BuddyPress
  10. Usage Examples
  11. Limitations
  12. myCred 2.2
    • Features
    • Point Type
    • Point Type Image
    • Add-ons
    • Built-In Add-ons
    • Free Add-ons
    • Premium Add-ons
    • Badges
    • Alignment and Layout – Badges
    • Social Share
    • Shortcodes
    • Template
    • Treasures
    • Support
    • Suggestions
  13. myCred 2.4
    • New Features
    • myCred Gutenberg Support
    • Assign Badges/Ranks Through Coupons
    • Import/Export tool
Chapter II
Getting Started
  1. Installation
  2. Point Type Settings
  3. Multiple Point Types
  4. Adjusting Balances
  5. Bulk Assign
    • Getting Started
  6. Setup Hooks
  7. Import Data
    • Importing Balances
    • Importing Log Entries
    • Import CubePoints
  8. Export Data
  9. Widgets
  10. Shortcodes
  11. Optimization
  12. Uninstall
Chapter III
Add-ons
  1. Badges
    • Achievement Types
    • Creating Badges
    • Manual Badges
    • Open Badge
    • Displaying Badges
    • Developer Resources
  2. buyCRED
    • Selling Points
    • Add-on Setup
    • Payment Gateways
    • myCred Square
    • The Checkout Page
    • Pending Payments
    • Developer Resources
  3. Coupons
    • Creating Coupons
    • Redeeming Coupons
    • Coupon Management
    • Developer Resources
  4. Email Notifications
    • Add-on Setup
    • Creating Emails
    • Unsubscribe
    • Developer Resources
  5. Gateway
    • WooCommerce
    • WP E-Commerce
    • Event Espresso
    • Events Manager
    • Developer Resources
  6. Notifications
    • Troubleshooting
    • Developer Resources
  7. Ranks
    • Introduction
    • Add-on Setup
    • Create New Rank
    • Displaying Ranks
    • Developer Resources
  8. Sell Content
    • Add-on Setup
    • Manual Mode
    • Available Shortcodes
    • Troubleshooting
    • Developer Resources
  9. Statistics
    • Available Shortcodes
    • Settings
    • For Developers
  10. Transfers
    • Add-on Setup
    • Available Shortcodes
    • Transfer Messages
    • Transfer Types
    • Developer Resources
  11. Freebies
    • myCred BuddyBoss Integration
    • myCred Learndash Points Importer
    • myCred Badgr
    • myCred WP Simple Pay
    • myCred Tutor LMS
    • myCred Credly
    • BP Group Leaderboards
    • myCred for Events Manager Pro
    • myCred Learndash
    • myCred H5P
    • myCred Github Rewards
    • myCred GiveWP
    • myCred Paid Membership Pro
    • myCred Memberpress
    • myCred Gamipress Importer
    • myCred Zoom
    • Amelia Add-on
    • myCred Anspress Integration
  12. cashCred
    • Getting Started
    • ShortCode
    • CashCred Form
    • Frontend Functionality
    • Admin Panel
    • cashCred Email Events
    • Fees
    • Gutenberg Block Support
  13. Central Deposit
    • Schedule Deposit
    • Email Triggers
Chapter IV
Premium Add-ons
  1. The myCred Store
  2. buyCRED Gateways
    • Stripe
    • Payza
    • Wepay
    • PayFast
    • 2checkout
    • Coinbase
    • ComproPago
    • Paymentwall
    • Robokassa
    • CoinPayments
  3. Third-party Bridges
    • myCred Beaver Builder
    • myCred WCVendors
    • LifterLMS Plugin Integration with myCred
    • myCred Gutenberg
    • myCred Dokan
    • myCred Elementor
    • myCred for WPBakery Page Builder
    • myCred for UserPro
    • myCred for Users Ultra
    • myCred Zapier Addon
  4. Games
    • myCred PacMan
    • Fortune Wheel Addon
  5. Enhancements
    • myCred Submission
    • Level Cred Add-on
    • myCred WooCommerce Plus
    • myCred Expiration Add on
    • myCred REST API
    • myCred Reset Point Add on
    • myCred Todo List
    • myCred Nominations
    • Progress Bar
    • myCred Social Proof
    • Notifications Plus
    • Social Share Add on
    • Transfer Plus
    • Twilio Transfers
    • Video Add-on
    • Video Add-on for JW Player
    • BuddyPress Charges
    • myCred Points Cap
    • Partial Payments – WooCommerce
    • myCred Progress map
    • myCred Email Digest
    • myCred Birthday Plus
    • myCred Daily Login Rewards
    • myCred Coupons Plus
    • myCred Anniversary Pro
    • myCred Email Plus
    • myCred Time Based Reward
  6. Store Gateways
    • Jigoshop
    • Easy Digital Downloads
    • WPMUDEV Fundraising
  7. cashCred Payment Gateways
    • cashcred PayPal
    • CashCred Paystack
    • cashcred Stripe
Chapter V
For Developers
  1. Introduction
  2. White Labeling
  3. Flowcharts
  4. Playing with Balances
  5. myCred Objects
  6. Log API
  7. Hook API
  8. Module API
  9. Gateway API
  10. Remote API
    • Version 1.0
    • Version 2.0
  11. Front-end Encryption
Chapter VI
Reference Guides
  1. Log References
  2. Shortcodes
  3. Template Tags
  4. Globals
  5. Constants
  6. Actions
  7. Filters
  8. Objects
  9. Functions
  10. Classes
$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.

Available since version 1.7

Interacting with Object

The account object can be accessed via the mycred_get_account function.

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
        )
)

Back To Top

$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.

Available since version 1.7

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.

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
                                        [reference] => 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
                                        [reference] => 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
    )

Back To Top

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

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

Available since version 1.7

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

                )

        )

)

Back To Top

$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.

Available since version 1.8

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.

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
)

Back To Top

$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.

Available since version 1.8

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.

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
)

Back To Top

$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!

Available since version 1.8

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:
  • 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_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
                    [reference] => buy_scratch_card
                    [total] => -100
                    [last_entry] => 1505848450
                    [reference_ids] => Array
                        (
                            [0] => 149
                            [1] => 48
                        )
                )
            [win_scratch_card] => stdClass Object
                (
                    [rows] => 1
                    [reference] => win_scratch_card
                    [total] => 500
                    [last_entry] => 1498573857
                    [reference_ids] => Array
                        (
                            [1] => 48
                        )
                )
        )
    [total_data] => 11
)

Back To Top

$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.

Available since version 1.7

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:
  • 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_value int or float This 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.
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
)

Back To Top

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

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

Available since version 1.7

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.

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

                )

        )

)

Back To Top

$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.

Available since version 1.8

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
    [reference] => 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
        (
        )

)

Back To Top

About myCRED

myCRED is a free, open-source and developer friendly points management tool for WordPress powered websites.

Download Rate Plugin

Documentation

  • Add-ons
  • Core Shortcodes
  • F.A.Q.
  • Tutorials
  • Third Party Plugins
  • Code Snippets

Support

  • Product Licenses
  • Customization
  • Support Forums
  • Plugin Changelog
  • Contact

Copyright 2013 - 2022 byWPExperts; All rights reserved. myCRED is licensed under GPL 2.0

Terms & Conditions • Use of Cookies • Store Policy • Community Rules

Suggest Codex Example

You can submit suggestions for codex examples that you have available as a public gist. If you are a member on the mycred.me website, you can earn Tokens for each submission. To claim these Tokens, make sure you provide your mycred.me username.

Please make sure the example you submit is relevant and if you include documentation, it's provided in English.

logo
  • Membership New
  • Chapters
    • Chapter I – Introduction
    • Chapter II – Getting Started
    • Chapter III – Add-ons
    • Chapter IV – Premium Add-ons
    • Chapter V – For Developers
    • Chapter VI – Reference Guides
  • Categories
    • Actions
    • Classes
    • Constants
    • Filters
    • Functions
    • Objects
    • Shortcodes
    • Hooks
    • Template Tags
  • Packages
    • mycred/api
    • mycred/badge
    • mycred/balance
    • mycred/banking
    • mycred/content
    • mycred/core
    • mycred/coupon
    • mycred/email
    • mycred/game
    • mycred/log
    • mycred/notice
    • mycred/payment
    • mycred/purchase
    • mycred/rank
    • mycred/transfer
  • Store
  • Download