mycred

Package: mycred/core Category: Functions
This function replaces the mycred_get_settings function as of 1.4 to add support for multiple point types.

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Example
  5. Return

Description

Constructs and returns the myCRED_Settings object based on a given point type.

Usage

<?php $mycred = mycred(); ?>

Parameters

  • type (string)
    Option to set the point type. Will default to the default point type.

Example

Example 1: Echo the plural name.

$mycred = mycred();
echo $mycred->plural();

Example 2: Echo the plural name for a custom point type called “mytype”.

$type = 'mytype';
$mycred = mycred( $type );
echo $mycred->plural();

Return

Returns the myCRED_Settings object constructed for the given point type.

Last edited September 2, 2016

Back To Top

mycred_add

Package: mycred/balance Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Example
  5. Return

Description

Adds a given amount of points to a specific user. Once the user’s balance has been updated, a new log entry is made under the given reference.

Note! This function will not check if the given user id should be excluded! This must be done before calling this function!

 

Usage

<?php mycred_add( $ref, $user_id, $amount, $entry, $ref_id, $data, $type ); ?>

 

Parameters

  • ref (string) required
    Required reference id for this update. This reference must be explanatory as myCRED will replace underscores with whitespaces and capitalize each word when viewing the log and this reference is what will be presented when filtering by reference. Example: reference = points_for_action becomes = Points For Action.
  • user_id (int) required
    Required user id.
  • amount (int|float) required
    Amount (positive or negative).
  • entry (string)
    Log entry template.
  • ref_id (int|string|array)
    Optional reference id.
  • data (int|string|array|object)
    Optional data to save with this log entry. Note that arrays are serialized!
  • type (string)
    Optional point type.

 

Example

Example 1: Add 10 points to a user.

<?php
$user_id = 12;
if ( !mycred_exclude_user( $user_id ) ) {
	// Add points and save the current year as ref_id
	mycred_add( 'birthday_present', $user_id, 10, 'Birthday %plural%!', date( 'y' ) );
}
?>

 

Return

Returns true on success else fail.

Last edited March 5, 2016

Back To Top

mycred_add_new_notice

Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Return

Description

This function allows you to add a new notification for a specific user. Notifications are shown when the user logs in (if the notice is generated when they are not online) or on the next page reload (if they are logged in).

Usage

$notice = array(
	'user_id' => 1,
	'message' => 'You have received 10 points!'
);

mycred_add_new_notice( $notice );

Parameters

  • notice (array)
    An associative array containing the users ID and the message to show.
  • lifespan (int)
    Option to set the number of days the message is saved. Defaults to 1.

Return

Void

Last edited October 19, 2015

Back To Top

mycred_assign_ranks

Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Return

Description

This function will assign ranks to every single user that has an entry in the myCRED Log.

 

Usage

if ( function_exists( 'mycred_assign_ranks' ) )
	mycred_assign_ranks();

 

Parameters

  • none

 

Return

This function does not return anything.

Last edited July 2, 2014

Back To Top

mycred_count_all_ref_instances

Package: mycred/log Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Return

Description

This function returns an associative array of references and the number of times each occur in your log. By default it will returns the top 5 most recurring references but can be changed to return all.

Usage

$all_reference_count = mycred_count_all_ref_instances( -1 );

Parameters

  • number (int) required
    The number of references to count. Use -1 to return all references.
  • order (string)
    The order in which to return references. Use DESC for descending order (default) or ASC for ascending order.
  • ctype (string)
    Option to limit counting to a specific point type.

Return

This function returns an associative array where keys are the reference and the value is the occurrence count.

Last edited March 5, 2016

Back To Top

mycred_count_ref_id_instances

Package: mycred/log Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Return

Description

This function counts the total number of occurrences a given reference combined with a ref id is used in the log either overall or for a specific user.

Requires myCRED 1.5.3 or higher.

 

Usage

if ( mycred_count_ref_id_instances( $reference, $ref_id, $user_id ) > 0 ) {
	// this user has a log entry with the given reference and ref id
}

 

Parameters

  • reference (string) required
    The reference to search for. Note this is case sensitive.
  • ref_id (int) required
    The reference id (ref_id) to include in the search. Remember that reference id’s are always integers.
  • user_id (int)
    Optional user id to include in the search. Defaults to not used.

 

Return

This function returns the number of times the reference is used in the log. Zero if no records are found or if the reference and ref_id are not provided.

Last edited March 5, 2016

Back To Top

mycred_count_ref_instances

Package: mycred/log Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Return

Description

This function counts the total number of occurrences a given reference is used in the log either overall or for a specific user.

 

Usage

if ( mycred_count_ref_instances( $reference, $user_id ) > 0 ) {
	// this user has a log entry with the given reference
}

 

Parameters

  • reference (string) required
    The reference to search for. Note this is case sensitive.
  • user_id (int)
    Optional user id to include in the search. Defaults to not used.

 

Return

This function returns the number of times the reference is used in the log. Zero if no records are found or if reference was not set.

Last edited March 5, 2016

Back To Top

mycred_exclude_user

Package: mycred/core Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Return

Description

Checks if a given user should be excluded. These are either users who are in the exclude list or if “Exclude Plugin Editors” or “Exclude Creds Editors” are set to true.

Note! This function does not check if a user is logged in or not, it assumes you either present a user id or the current user id can be retrieved.

 

Usage

<?php
if ( mycred_exclude_user( $user_id ) ) {
	// User should be excluded
}

 

Parameters

  • user_id (int)
    User id to check. If not set, the current user is checked.

 

Return

Returns true or false.

Last edited March 5, 2016

Back To Top

mycred_find_users_rank

Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Return

Description

This function will query all published ranks to see where the given user fits in. If requested, the found rank is saved for the given user.

WARNING
Do NOT use this function unless you must find a users new rank! If you just want to show a given users rank details, like the rank name or logo, use the mycred_get_users_rank function instead!

If you are ranking users according to their total points and not their current points, using this function will cause the user to gain a rank according to their current balance and not their total!

 

Usage

mycred_find_users_rank( get_current_user_id(), true, $amount );

 

Parameters

  • user_id (int) Required
    Required User ID.
  • save (bool)
    Option to save the rank for the given user. Defaults to false.
  • amount (int|float)
    If set, the given amount is added to the users balance for this query only. This allows you to find a users rank before they are awarded the given amount. Will NOT add points to a user, just used for calculation!

 

Return

  • The rank found for this user on success.
  • Empty string if user is excluded from using myCRED

Last edited July 2, 2014

Back To Top

mycred_flush_widget_cache

Package: mycred/core Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Return

Description

Flushes a given widgets cache.

 

Usage

<?php mycred_flush_widget_cache( $id ); ?>

 

Parameters

  • id (string)
    Required widget id.

 

Return

Void

Last edited March 5, 2016

Back To Top

mycred_get_my_rank

Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Return

Description

Retrieves the current users rank title. Uses mycred_get_users_rank.

 

Usage

echo 'Your Rank: ' . mycred_get_my_rank();

 

Parameters

None

 

Return

  • The current users rank title.
  • NULL if rank is not found.

Last edited July 2, 2014

Back To Top

mycred_get_published_ranks

Category: Functions

Navigation:

  1. Description
  2. Parameters
  3. Return

Description

This function returns the number of published rank posts currently available in your database. Uses the mycred_get_published_ranks filter.

 

Parameters

None

 

Return

True or false.

Last edited July 2, 2014

Back To Top

mycred_get_rank

Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Return

Description

Retrieves the rank object based on the rank name. Uses the mycred_get_rank filter.

 

Usage

$rank = mycred_get_rank( 'Newbie' );
echo 'Newbie rank ID: ' . $rank->ID;

 

Parameters

  • rank_title (string) Required
    Required Rank title. Uses get_page_by_title.

 

Return

  • The Rank Object if rank is found.
  • NULL if Rank could not be found.
  • Empty string if rank_title parameter is missing.

Last edited July 2, 2014

Back To Top

mycred_get_rank_id_from_title

Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Return

Description

Retrieves the rank ID from a rank title.

 

Usage

echo 'Your rank id is: ' . mycred_get_rank_id_from_title( 'Newbie' );

 

Parameters

  • title (string) Required
    Required Rank title.

 

Return

  • The rank ID if rank is found.
  • NULL if rank is not found.
  • Empty string if user is excluded from using myCRED

Last edited July 2, 2014

Back To Top

mycred_get_rank_logo

Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Return

Description

Retreves a given ranks logo (featured image). Uses get_the_post_thumbnail.

 

Usage

echo mycred_get_rank_logo( 'Newbie' );

 

Parameters

  • rank_id (int|string) Required
    Either the rank ID or rank title.
  • size (string|array)
    The logo size to return. Supports custom image sizes that were added with add_image_size. Defaults to ‘post-thumbnail’. For more information on available sizes please consult the WordPress Codex.
  • attr (string|array)
    Optional logo image attributes. For more information on available sizes please consult the WordPress Codex.

 

Return

Returns either the logo HTML image element or an empty string if no logo is set.

Last edited July 2, 2014

Back To Top

mycred_get_ranks

Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Return

Description

Returns an associative array of all published ranks in descending order.

 

Usage

$ranks = mycred_get_ranks( 'draft' );
echo 'There are ' . count( $ranks ) . ' Draft Ranks';

 

Parameters

  • status (string)
    Post Status to search for. Defaults to ‘published’.
  • number (int)
    Number of ranks to return. Defaults to all.
  • order (string)
    Option to select the order in which the ranks are returned. Defaults to Descending.

 

Return

  • Associative array with Rank ID as key and Rank Post object as value.
  • Empty if no ranks found.

Last edited July 2, 2014

Back To Top

mycred_get_remote

Package: mycred/core Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Default Values
  4. Example
  5. Return

Description

Returns the current settings for the myCRED Remote API.

 

Usage

<?php $mycred = mycred_get_remote(); ?>

 

Default Values

  • enabled (int)
    Zero for disabled, one (1) for enabled.
  • key (string)
    The API Key.
  • uri (string)
    The incoming call address that the API checks for to execute.
  • debug (int)
    Zero for disabled, one (1) for enabled.

 

Example

Example 1: Check if the API is enabled.

// Get API Settings
$remote = mycred_get_remote();
// Check
if ( $remote['enabled'] ) {
	// enabled ...
}
else {
	// disabled ...
}

 

Return

Returns an associative array of values.

Last edited March 5, 2016

Back To Top

mycred_get_settings

Package: mycred/core Category: Functions
This function has been depreciated in version 1.4. Please use the mycred function instead!

Navigation:

  1. Description
  2. Usage
  3. Example
  4. Return

Description

Returns the myCRED_Settings object and core settings.

 

Usage

<?php $mycred = mycred_get_settings(); ?>

 

Example

Example 1: Echo the plural name.

$mycred = mycred_get_settings();
echo $mycred->plural();

 

Return

Returns the myCRED_Settings object.

Last edited March 5, 2016

Back To Top

mycred_get_settings_network

Package: mycred/core Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Example
  4. Return

Description

Returns the myCRED Network Settings.

 

Usage

<?php $mycred = mycred_get_settings_network(); ?>

 

Example

Example 1: Check if Master Template is enforced.

$mycred_network = mycred_get_settings_network();
if ( (bool) $mycred_network['master'] == true ) {
	// It is enabled
	// do stuff...
}

 

Return

Returns either an associative array of settings or false if multisite is not enabled.

Last edited March 5, 2016

Back To Top

mycred_get_total_by_time

Package: mycred/log Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Examples
  5. Return

Description

Counts the total amount of points that has been entered into the log between two given UNIX timestamps. Optionally you can restrict counting to a specific user or specific reference (or both).

Will return false if the time stamps are incorrectly formated same for user id (must be int). If you do not want to filter by reference pass NULL and not an empty string or this function will return false. Same goes for the user id!

 

Usage

<?php mycred_get_total_by_time( $from, $to, $ref, $user_id, $type ); ?>

 

Parameters

  • from (int|string)
    Either a UNIX timestamp from when we should start counting or the string ‘today’ to start at the beginning of today. Defaults to ‘today’.
  • to (int|string)
    Either a UNIX timestamp for when we should stop counting or the string ‘now’ for the current UNIX time. Defaults to ‘now’.
  • ref (string)
    Option to get the total for a specific reference. Use NULL if not used but must be set.
  • user_id (int)
    Option to get the total for a specific user. Use NULL if not used but must be set.
  • type (string)
    Points type.

 

Examples

Example 1: Get the total amount of points that has been awarded today.

<?php
echo 'Total Today: ' . mycred_get_total_by_time();
?>

Example 2: Get the total amount of points given for logins today.

<?php
echo 'Total Login Points: ' . mycred_get_total_by_time( 'today', 'now', 'logging_in' );
?>

Example 3: Get the total amount of points the user with the ID of 5 between 1st of January 2013 and now.

<?php
$user_id = 5;
echo 'Earned points this year: ' . mycred_get_total_by_time( 1356998400, 'now', NULL, $user_id );
?>

 

Return

Returns the total amount (int|float) or error message if incorrectly used.

Last edited March 5, 2016

Back To Top

mycred_get_users_cred

Package: mycred/balance Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Example
  5. Return

Description

This function returns a given user’s current point balance without any prefix or suffix (if used). Use mycred_get_users_fcred to return the same result but with prefix and/or suffix.

 

Usage

<?php echo mycred_get_users_cred( $user_id, $type ); ?>

 

Parameters

  • user_id (int) required
    Required user id.
  • type (string)
    Optional cred id.

 

Example

Example 1: Get current users balance.

echo 'Your currently have ' . mycred_get_users_cred() . ' points.';

 

Return

Returns unformatted integer or float.

Last edited March 5, 2016

Back To Top

mycred_get_users_fcred

Package: mycred/balance Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Example
  5. Return

Description

This function returns a given user’s current point balance formated with prefix and suffix (if used). Use mycred_get_users_cred() to return the same result but without formatting.

Usage

<?php echo mycred_get_users_fcred( $user_id, $type ); ?>

Parameters

  • user_id (int) required
    Required user id.
  • type (string)
    Optional point type to show.

Example

Example 1: Show the post authors balance (must be used inside the loop).

global $post;
echo 'This authors points balance is: ' . mycred_get_users_fcred( $post->post_author );

Return

Returns the users balance formated.

Last edited March 5, 2016

Back To Top

mycred_get_users_of_rank

Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Return

Description

Returns an array of User IDs for a given rank title or rank id.

 

Usage

$newbies = mycred_get_users_of_rank( 'Newbie' );
echo 'There are ' . count( $newbies ) . ' Newbies';

 

Parameters

  • rank (int|string) Required
    Either the rank ID or rank title.
  • number (int)
    Number of users to return. Defaults to all.
  • order (string)
    Option to select the order in which the users are returned. Defaults to ‘DESC’ showing the users with the highest amount first.

 

Return

  • Array of users IDs in order of balance.
  • Empty string if if the given rank is not found.
  • Empty array if no users are found.

Last edited July 2, 2014

Back To Top

mycred_get_users_rank

Package: mycred/rank Category: Functions

Description

This function will retrieve a given users current rank object or return an empty string if no rank was found.

Available since version 1.1

This function was completely re-written in version 1.7! This documentation is incorrect for older versions of myCRED.

Parameters

Param Type Required Description
$user_id int Yes

The numeric ID of the user.

$type string No

Option to retrieve the rank for a particular point type. Should not be used if you only have one point type or only one of your point types have ranks.

Usage Example

Last edited June 22, 2016

Back To Top

mycred_have_ranks

Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Return

Description

Checks to see if there are any registered ranks.

 

Usage

if ( !mycred_have_ranks() ) {
	// No rank exists
}

 

Parameters

None

 

Return

Returns true or false.

Last edited July 2, 2014

Back To Top

mycred_is_admin

Package: mycred/core Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Return

Description

Checks if a given user or the current user can either edit the myCRED plugin or edit users creds.

Note! This function does not check if a user is logged in or not, it assumes you either present a user id or the current user id can be retrieved.

 

Usage

<?php
if ( mycred_is_admin( $user_id ) ) {
	// User is "admin"
}
?>

 

Parameters

  • user_id (int)
    User id to check. If not set, the current user is checked.

 

 

Return

Returns true or false.

Last edited March 5, 2016

Back To Top

mycred_label

Package: mycred/core Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Example
  5. Return

Description

Returns the myCRED plugin label. The myCRED label is defined under the myCRED_LABEL constant, which this function retrieves and filters via the mycred_label filter before returning. This allows you to change the myCRED name shown around your WordPress admin area.

 

Usage

<?php echo mycred_label(); ?>

 

Parameters

  • strip tags (boolean)
    By default the label can contain html elements but if set to true, all HTML tags are stipped before the label is returned.

 

Example

Example 1: Echo the plural form.

echo 'Get 10 ' . mycred_name( false );

 

Return

Returns a string or empty if names are not set.

Last edited March 5, 2016

Back To Top

mycred_lotto_random_draw

Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Return

Description

This function will draw a set of numbers at random between two set ranges.

 

Usage

<?php
$winning_numbers = mycred_lotto_random_draw( $min, $max, $num );

 

Parameters

  • min (int)
    The lowest number that can be picked.
  • max (int)
    The highest number that can be picked.
  • num (int)
    The number of values to return.

 

Return

Returns an array with the randomly selected numbers.

Last edited July 2, 2014

Back To Top

mycred_name

Package: mycred/core Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Example
  5. Return

Description

Returns the singular or plural form of the name given to your points.

 

Usage

<?php echo mycred_name( $singular ); ?>

 

Parameters

  • singular (boolean)
    Returns singular form is set to true (default) or plural if false.

 

Example

Example 1: Echo the plural form.

echo 'Get 10 ' . mycred_name( false );

 

Return

Returns a string or empty if names are not set.

Last edited March 5, 2016

Back To Top

mycred_overwrite

Package: mycred/core Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Example
  4. Return

Description

Checks to see if the Master Template feature for Multisites has been enabled.

 

Usage

<?php if ( mycred_overwrite() ) ?>

 

Example

Example 1: Check if Master Template is enforced.

if ( mycred_overwrite() ) {
	// It is enabled
	// do stuff...
}

 

Return

Returns either true or false.

Last edited March 5, 2016

Back To Top

mycred_rank_has_logo

Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Return

Description

Checks if a given rank has a logo (featured image). Returns either true or false.

 

Usage

if ( mycred_rank_has_logo( $rank_id ) ) {
	// It has a logo
}

 

Parameters

  • rank_id (int|string) Required
    Either the rank ID or rank title.

 

Return

Returns either true or false.

Last edited July 2, 2014

Back To Top

mycred_rankings

Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Example
  5. Return

Description

Returns the myCRED_Rankings object. See the myCRED_Ratings class for more information.

 

Usage

<?php $rankings = mycred_rankings( $args ); ?>

 

Parameters

  • args (string|array)
    Optional parameters for the rendered list.

 

Example

Example: Create a top 10 leaderboard.

$rankings = mycred_rankings( 'number=10' );
if ( $rankings->have_results() ) {
	echo 'Top 10 Leaderboard';
	$rankings->display();
}

 

Return

Last edited July 2, 2014

Back To Top

mycred_rankings_position

Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Example
  5. Return

Description

Returns a given user’s position (ranking) on the leaderboard, with the user who has the largest amount of points on your website having ranking 1.

Not to be confused with the Ranks you can create though the Rank add-on.

 

Usage

<?php mycred_rankings_position( $user_id ); ?>

 

Parameters

  • user_id (int)
    Required user id.

 

Example

Example 1: .

$user_id = get_current_user_id();
echo 'Your current ranking: #' . mycred_rankings_position( $user_id );

 

Return

Returns users position (int) else empty string.

Last edited July 2, 2014

Back To Top

mycred_strip_tags

Package: mycred/core Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Example
  5. Return

Description

Strips HTML tags from a given string. Optionally you can overwrite the default allowed tags. By default the following elements are allowed: <a><br><em><strong><span>

 

Usage

<?php echo mycred_strip_tags( $string, $allowed ); ?>

 

Parameters

  • string (string)
    The string to be stripped.
  • param (string)
    Optional HTML elements to allow.

 

Example

Example 1: Strip tags from a string but also allow the use of DIV elements.

echo mycred_strip_tags( '<div><p>This is a paragraph.</p></div>', '<a><br><em><strong><span><div>' );

 

Return

Returns the given string stripped of tags.

Last edited March 5, 2016

Back To Top

mycred_subtract

Package: mycred/balance Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Example
  5. Return

Description

Removes a given amount of creds from a specific user. Once the user’s balance has been updated, a new log entry is made under the given reference.

Note! This function will not check if the given user id should be excluded! This must be done before calling this function!

 

Usage

<?php mycred_subtract( $ref, $user_id, $amount, $entry, $ref_id, $data, $type ); ?>

 

Parameters

  • ref (string) required
    Required reference id for this update.
  • user_id (int) required
    Required user id.
  • amount (int|float) required
    Amount to remove. If a positive value is given it is automatically converted into a negative value!
  • entry (string)
    Log entry template.
  • ref_id (int|string|array)
    Optional reference id..
  • data (int|string|array|object)
    Optional data to save with this log entry.
  • type (string)
    Optional cred id.

 

Example

Example 1: Remove 10 points from a user.

<?php
$user_id = 12;
if ( !mycred_exclude_user( $user_id ) ) {
	mycred_subtract( 'penalty', $user_id, 10, 'Offline penalty', date( 'W' ) );
}
?<

 

Return

Returns true on success else fail.

Last edited March 5, 2016

Back To Top

mycred_transfer_render

Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Examples
  5. Return

Description

Returns the Transfer form, allowing users to send creds to each other. Used by the mycred_transfer shortcode.

Important! If transfer is possible, this function will call on the ajax script and styling under wp_footer. If you want to use this function after that wp_footer has fired you will need to include these scripts and styles manually.

 

Usage

<?php echo mycred_transfer_render( $attr, $content ); ?>

 

Parameters

  • attr (array)
    Shortcode attributes. See the mycred_transfer shortcode for more information.
  • content (string)
    Optional content to insert inside the wrapper.

 

Examples

Example 1: Default usage.

<?php echo mycred_transfer_render(); ?>

Example 2: Show users balance in form.

<?php echo mycred_transfer_render( array( 'show_balance' => 1 ) ); ?>

Example 3: Automatically insert a form after the post’s content allowing transfers to the post author. Note, this example would need to be placed inside the loop!

<?php
$user_id = get_the_author_meta( 'ID' );
echo mycred_transfer_render( array( 'pay_to' => $user_id, 'show_balance' => 1 ) );
?>

You could also use the do_shortcode() function:

<?php
$user_id = get_the_author_meta( 'ID' );
echo do_shortcode( '[mycred_transfer pay_to="' . $user_id . '" show_balance="1"]' );
?>

 

Return

Returns the transfer form.

Last edited July 2, 2014

Back To Top

mycred_user_can_transfer

Category: Functions

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Return

Description

Checks if a user can make a transfer. Checks to make sure the user’s balance is not zero and if the user has reached the transfer limit (if used).

Note! This function will not check if a user is logged in. This must be done before calling this function.

 

Usage

if ( mycred_user_can_transfer( $user_id ) ) {
	// current user can transfer. Do stuff...
}

 

Parameters

  • user_id (int)
    Optional user id to check. If not set, the function will default to the current user.

 

Return

  • low (string)
    If users balance is zero.
  • limit (string)
    User has reached transfer limit.
  • true (boolean)
    If users balance is bigger then zero and if no limit are imposed.
  • amount (int|float)
    The amount of points remaining of the transfer limit.

Last edited July 2, 2014

Back To Top

Last edited June 5, 2016