Description

This filter allows you to adjust the value that badges add-on saves when a user earns a new badge / badge level. By default, the add-on saves the badges level ID but if you do not use levels you can use this to store other types of data as long as it is a string or integer value.

Available since version 1.2

Parameters
Param Type Required Description
$new_level int Yes

The new level ID a user earned. Remember that Level IDs start from ZERO and not from 1.

$user_id int No

The users WordPress id.

$badge_id int No

The badges post object ID.

Used By
Package Prio. Description
Not used by any built-in package.
Description

This filter allows you to add / remove autocomplete options in the Transfer add-on.

Available since version 1.6

Parameters
Param Type Required Description
$options array Yes

An associative array of autocomplete value and label that is shown in the dropdown menu.

$settings array No

The transfer add-on settings.

Used By
Package Prio. Description
Not used by any built-in package.
Example

Example 1: Add the option to disable Autocomplete in our transfer settings.

function mycred_pro_disable_autocomplete_option( $options ) {

	$options['none'] = 'Disable Autocomplete';

	return $options;

}
add_filter( 'mycred_transfer_autofill_by', 'mycred_pro_disable_autocomplete_option' );
Description

This filter controls if the mycred_give shortcode should run or not. It can be used to either disable this shortcode or to limit when or by whom it can be used.

Available since version 1.8

Parameters
Param Type Required Description
$run bool Yes

If the shortcode is set to run (TRUE) or not (FALSE).

$atts array No

The shortcode attributes that are being used.

Used By
Package Prio. Description
Not used by any built-in package.
Example

Example 1: Disable usage of this shortcode.

add_filter( 'mycred_give_run', '__return_false' );
Description

This filter allows you to adjust the reference that the Points for Deleting Content hook uses when awarding / deducting points. Defaults to deleted_content.

Available since version 1.8

Parameters
Param Type Required Description
$reference string Yes

The reference to use. Can not be empty or no points will be awarded!

$post obj No

The WordPress post object that is getting deleted.

$hook obj No

The hook object.

Used By
Package Prio. Description
Not used by any built-in package.
Description

This filter allows you to adjust the reference that the Points for Publishing Content hook uses when awarding / deducting points. Defaults to publishing_content.

Available since version 1.8

Parameters
Param Type Required Description
$reference string Yes

The reference to use. Can not be empty or no points will be awarded!

$post obj No

The WordPress post object that is getting published.

$new_status string No

The new status the post is receiving by WordPress.

$old_status string No

The posts old status.

$hook obj No

The hook object.

Used By
Package Prio. Description
Not used by any built-in package.
Example

Example 1: Log the event under a unique reference based on the post type being published.

Description

Returns an instance of the myCRED_Chart object for building charts using the Statistics add-on.

This function is only available if the Statistics add-on is enabled.

Available since version 1.8

Returns

(obj) Returns the myCRED_Chart object.

Parameters
Param Type Required Description
function mycred_create_chart(
$args array No

An array of global arguments for charts.

) { ... }
Example

Example 1: Generate a pie chart based on the points in circulation on our website.

$global_args = array(
	'title' => 'Points in Circulation'
);

$chart       = mycred_create_chart( $global_args );

// The data to show in the chart.
$data        = mycred_get_circulation_data();

if ( ! empty( $data ) ) {

	echo $chart->pie_chart( $data );

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

Returns an instance of the myCRED_Email object based on a given email notice post ID.

This function is only available if the Email Notifications add-on is enabled.

Available since version 1.8

Returns

(bool | obj) Returns FALSE if an invalid email ID is provided else the myCRED_Email object.

Parameters
Param Type Required Description
function mycred_get_email_notice(
$notice_id int Yes

The email notifications post ID.

) { ... }
Example

Example 1: Get an instance for the email notice ID 123

$notice_id = 123;
$email     = mycred_get_email_notice( $notice_id );
if ( $email !== false ) {

	// do something

}
Description

This shortcode will render the total amount of points your users has gained / lost on a daily/weekly/monthly/yearly basis. Uses Chart.js 2.7.0

Available since version 1.8

Shortcode Attributes

Attribute Type Required Default Description
type string No line The chart type to render. Supports: line and bar
ctype string No mycred_default The point type we want to show data for. Should only be used when you need to show data for a custom point type.
ref string No - The reference we want to show history for.
period string No days The type of periods we want to use. Accepts days, weeks, months and years.
number int No 10 The number of periods to show in the chart e.g. 10 days or 12 months.
order string No DESC The order of which the periods should be sorted.
title string No - Option to set a title for the chart.
animate int No 1 If the chart should be animated (1) or not (0).
bezier int No 1 If line charts should use bezier curves (1) or not (0).
labels int No 1 If labels should be shown in the chart (1) or not (0). Not all chart types use labels, it is mainly for bar and line charts where we have both an x and y axis.
legend int No 1 If a legend should be shown in the chart (1) or not (0). Not all charts show legends.
width string No - The chart canvas width. By default the chart will render full with of the container where the shortcode is used. Can be either a pixel value (without px) or a percentage value (with %).
height string No - The chart canvas height. Can be either a pixel value (without px) or a percentage value (with %).

CSS Styling

.chart-container mycred-chart-container { }
.chart-container mycred-chart-container canvas.mycred-chart-canvas { }
Example

Example 1: Default usage.

[mycred_chart_instance_history]
Description

This shortcode will render the total amount of points a specific user has gained / lost on a daily/weekly/monthly/yearly basis. Uses Chart.js 2.7.0

Available since version 1.8

Shortcode Attributes

Attribute Type Required Default Description
type string No line The chart type to render. Supports: line and bar
ctype string No mycred_default The point type we want to show data for. Should only be used when you need to show data for a custom point type.
user_id string or int No current The user whom's history we want to show. Accepts either a numeric user ID or the keyword current to show the current users history.
period string No days The type of periods we want to use. Accepts days, weeks, months and years.
number int No 10 The number of periods to show in the chart e.g. 10 days or 12 months.
order string No DESC The order of which the periods should be sorted.
title string No - Option to set a title for the chart.
animate int No 1 If the chart should be animated (1) or not (0).
bezier int No 1 If line charts should use bezier curves (1) or not (0).
labels int No 1 If labels should be shown in the chart (1) or not (0). Not all chart types use labels, it is mainly for bar and line charts where we have both an x and y axis.
legend int No 1 If a legend should be shown in the chart (1) or not (0). Not all charts show legends.
width string No - The chart canvas width. By default the chart will render full with of the container where the shortcode is used. Can be either a pixel value (without px) or a percentage value (with %).
height string No - The chart canvas height. Can be either a pixel value (without px) or a percentage value (with %).

CSS Styling

.chart-container mycred-chart-container { }
.chart-container mycred-chart-container canvas.mycred-chart-canvas { }
Example

Example 1: Default usage.

[mycred_chart_balance_history]
Description

This shortcode will render a list of the most common ways your users gain / spend points on your site. These results are based on references. Uses Chart.js 2.7.0

Available since version 1.8

Shortcode Attributes

Attribute Type Required Default Description
type string No bar The chart type to render. Supports: pie, doughnut, line, bar, radar and polarArea
ctype string No mycred_default The point type we want to show data for. Should only be used when you need to show data for a custom point type.
number int No 10 The number of references to show.
order string No DESC The order of which the references should be sorted.
title string No - Option to set a title for the chart.
animate int No 1 If the chart should be animated (1) or not (0).
bezier int No 1 If line charts should use bezier curves (1) or not (0).
labels int No 1 If labels should be shown in the chart (1) or not (0). Not all chart types use labels, it is mainly for bar and line charts where we have both an x and y axis.
legend int No 1 If a legend should be shown in the chart (1) or not (0). Not all charts show legends.
width string No - The chart canvas width. By default the chart will render full with of the container where the shortcode is used. Can be either a pixel value (without px) or a percentage value (with %).
height string No - The chart canvas height. Can be either a pixel value (without px) or a percentage value (with %).

CSS Styling

.chart-container mycred-chart-container { }
.chart-container mycred-chart-container canvas.mycred-chart-canvas { }
Example

Example 1: Default usage.

[mycred_chart_top_instances]
Description

This shortcode will render a list of balances ordered by size. Uses Chart.js 2.7.0

Available since version 1.8

Shortcode Attributes

Attribute Type Required Default Description
type string No bar The chart type to render. Supports: pie, doughnut, line, bar, radar and polarArea
ctype string No mycred_default The point type we want to show data for. Should only be used when you need to show data for a custom point type.
number int No 10 The number of balances to show.
order string No DESC The order of which the balances should be sorted.
title string No - Option to set a title for the chart.
animate int No 1 If the chart should be animated (1) or not (0).
bezier int No 1 If line charts should use bezier curves (1) or not (0).
labels int No 1 If labels should be shown in the chart (1) or not (0). Not all chart types use labels, it is mainly for bar and line charts where we have both an x and y axis.
legend int No 1 If a legend should be shown in the chart (1) or not (0). Not all charts show legends.
width string No - The chart canvas width. By default the chart will render full with of the container where the shortcode is used. Can be either a pixel value (without px) or a percentage value (with %).
height string No - The chart canvas height. Can be either a pixel value (without px) or a percentage value (with %).

CSS Styling

.chart-container mycred-chart-container { }
.chart-container mycred-chart-container canvas.mycred-chart-canvas { }
Example

Example 1: Default usage.

[mycred_chart_top_balances]
Description

This shortcode will render the average amount of points that has been awarded on your website for a given period. You can select how far back the chart should go in days, weeks, months or years. Uses Chart.js 2.7.0

Available since version 1.8

Shortcode Attributes

Attribute Type Required Default Description
type string No line The chart type to render. Supports: line and bar
ctype string No mycred_default The point type we want to show data for. Should only be used when you need to show data for a custom point type.
period string No days The type of periods we want to use. Accepts days, weeks, months and years.
number int No 10 The number of periods to show in the chart e.g. 10 days or 12 months.
order string No DESC The order of which the periods should be sorted.
title string No - Option to set a title for the chart.
animate int No 1 If the chart should be animated (1) or not (0).
bezier int No 1 If line charts should use bezier curves (1) or not (0).
labels int No 1 If labels should be shown in the chart (1) or not (0). Not all chart types use labels, it is mainly for bar and line charts where we have both an x and y axis.
legend int No 1 If a legend should be shown in the chart (1) or not (0). Not all charts show legends.
width string No - The chart canvas width. By default the chart will render full with of the container where the shortcode is used. Can be either a pixel value (without px) or a percentage value (with %).
height string No - The chart canvas height. Can be either a pixel value (without px) or a percentage value (with %).

CSS Styling

.chart-container mycred-chart-container { }
.chart-container mycred-chart-container canvas.mycred-chart-canvas { }
Example

Example 1: Default usage.

[mycred_chart_history]
Description

This shortcode will render charts based on the amount of points that has been given to users vs. the total amount taken for a particular point type. Uses Chart.js 2.7.0

Available since version 1.8

Shortcode Attributes

Attribute Type Required Default Description
type string No pie The chart type to render. Supports: pie, doughnut, line, bar and polarArea
ctype string No mycred_default The point type we want to show data for. Should only be used when you need to show data for a custom point type.
title string No - Option to set a title for the chart.
animate int No 1 If the chart should be animated (1) or not (0).
bezier int No 1 If line charts should use bezier curves (1) or not (0).
labels int No 1 If labels should be shown in the chart (1) or not (0). Not all chart types use labels, it is mainly for bar and line charts where we have both an x and y axis.
legend int No 1 If a legend should be shown in the chart (1) or not (0). Not all charts show legends.
width string No - The chart canvas width. By default the chart will render full with of the container where the shortcode is used. Can be either a pixel value (without px) or a percentage value (with %).
height string No - The chart canvas height. Can be either a pixel value (without px) or a percentage value (with %).
gains string No - Option to use a different word than "Gains".
losses string No - Option to use a different word than "Losses".

CSS Styling

.chart-container mycred-chart-container { }
.chart-container mycred-chart-container canvas.mycred-chart-canvas { }
Example

Example 1: Default usage.

[mycred_chart_gain_loss]
Description

This shortcode will render charts based on the amount of points that currently exists amongst your users. The chart is segmented if you have more than one point type setup. Uses Chart.js 2.7.0

Available since version 1.8

Shortcode Attributes

Attribute Type Required Default Description
type string No pie The chart type to render. Supports: pie, doughnut, line, bar, radar and polarArea
title string No - Option to set a title for the chart.
animate int No 1 If the chart should be animated (1) or not (0).
bezier int No 1 If line charts should use bezier curves (1) or not (0).
labels int No 1 If labels should be shown in the chart (1) or not (0). Not all chart types use labels, it is mainly for bar and line charts where we have both an x and y axis.
legend int No 1 If a legend should be shown in the chart (1) or not (0). Not all charts show legends.
width string No - The chart canvas width. By default the chart will render full with of the container where the shortcode is used. Can be either a pixel value (without px) or a percentage value (with %).
height string No - The chart canvas height. Can be either a pixel value (without px) or a percentage value (with %).

CSS Styling

.chart-container mycred-chart-container { }
.chart-container mycred-chart-container canvas.mycred-chart-canvas { }
Example

Example 1: Default usage.

[mycred_chart_circulation]
Description

This function will returns the myCRED_Transfer object. Note that this function will not populate the object.

This function is only available if the Transfer add-on is enabled.

Available since version 1.8

Returns

(object) Returns the myCRED_Transfer object.

Parameters
Param Type Required Description
function mycred_transfer(
$transfer_id string No

The transfer ID if you plan on using the object to manipulate or process a transfer. Can be ignored when using the object to render a new transfer form.

) { ... }