Classes

Author: Noor 123 views

myCRED_Hook

Package: mycred/core Category: Classes
 

Description

This is an abstract class used to construct myCRED Hooks. It contains a set of predefined methods to help hook constructions.

 

Class Properties

PropertyDeclaredTypeDescription
$idPublicstringThe hook ID. Must be unique.
$corePublicOBJECTThe main point type object.
$point_typesPublicARRAYAll registered point type IDs.
$is_main_typePublicBOOLTrue if the current instance is the main point type (first instance) or false if not.
$mycred_typePublicBOOLThe current point type instance.
$prefsPublicARRAYAssociative array of the hooks saved settings.

Interacting with the Class

As an abstract class, your use this by extending your own hook class.

				
					class myCRED_Custom_Hook extends myCRED_Hook {

	function __construct( $hook_prefs, $type = MYCRED_DEFAULT_TYPE_KEY ) {

		parent::__construct( array(
			'id'       => 'hookid',
			'defaults' => array(
				'creds'   => 10,
				'log'     => '%plural% for a specific event'
			)
		), $hook_prefs, $type );

	}

}
				
			
 Class Parameters
ParameterTypeRequiredDescription
$argsARRAYYesThe hook arguments containing the hooks ID and preferences.
$hook_prefsARRAYYesThe module settings array.
$typestringYesThe point type key instance.

Class Methods

When using this class, the only requirement is that your class must define and setup it’s own run() method, all other methods are optional and not required to use.

public function run() {
 Description:If a hook is enabled, this method is run for each point type instance.
VariableTypeRequiredDescription
No variables
}
public function preferences() {
 Description:Method that displays the hooks settings in the admin area. If this method is not defined in your class, the hook will appear to have no settings when viewed in the admin area.
VariableTypeRequiredDescription
No variables
}
public function sanitise_preferences( $data ) {
 Description:Method used to sanitize or setup hook settings after they have been saved by the user in the admin area.
VariableTypeRequiredDescription
dataARRAYYesThe hooks newly submitted settings.
}
public function field_name( $field = '' ) {
 Description:Returns the hook settings field name. Should be used when displaying settings in the admin area. Ensures that field names are always correct.
VariableTypeRequiredDescription
fieldSTRING or ARRAYYesThe field name.
}
public function field_id( $field = '' ) {
 Description:Returns the hook settings field id. Should be used when displaying settings in the admin area. Ensures that field ids are always correct.
VariableTypeRequiredDescription
fieldSTRING or ARRAYYesThe field id.
}
public function over_hook_limit( $instance = '', $reference = '', $user_id = NULL, $ref_id = NULL ) {
 Description:Returns true if the hook limit has been reached (assuming one has been set), else it returns false.
VariableTypeRequiredDescription
instanceSTRINGYesThe hook instance to check.
referenceSTRINGYesThe reference to check.
user_idINTYesThe user ID to check.
ref_idINTNoOptional reference ID to check.
}
public function get_limit_types() {
 Description:Returns an array of options that can be selected in the hook limit settings dropdown.
VariableTypeRequiredDescription
No variables
}
public function hook_limit_setting( $name = '', $id = '', $selected = '' ) {
 Description:Returns the hook limit settings. This method can only be used in the preferences() method for instances that needs to support limits.
VariableTypeRequiredDescription
nameSTRINGYesThe settings name to use.
idSTRINGYesThe settings id to use.
selectedSTRINGYesThe saved settings.
}
public function has_entry( $reference = NULL, $ref_id = NULL, $user_id = NULL, $data = NULL, $type = NULL ) {
 Description:Checks if a specific log entry exists in the database.
VariableTypeRequiredDescription
referenceSTRINGNoThe reference to check.
ref_idINTNoThe reference id to check.
user_idINTNoThe user id to check.
dataSTRINGNoThe data to check for. If you know the data is an array, make sure this value is a serialized array.
typeSTRINGNoThe point type to check.
}

myCRED_Lottery

Package: mycred/game Category: Classes
 

Description

The myCRED_Lottery class handles all lottery related information. This class does not save any information to your database, it only retrieves and processes lottery details in order for you to be able to present or retrieve.

This class requires a lottery post ID to work and only handles one lottery at a time.

Usage

$lottery = new myCRED_Lottery( $lottery_id );

Properties

  • $id (int)
    Lottery post ID.
  • $post (object)
    The lottery post object.
  • $prefs (array)
    This lotteries preferences.
  • $state (string)
    The lotteries current state.
  • $mycred (array)
    The myCRED_Settings Object.

Methods

  1. myCRED_Lottery()Constructs the lottery class and populates the lottery’s ID, preferences and loads the myCRED_Settings object.

  2. lottery_exists()Checks if a lottery exists and if the lottery is found, the lottery post object is populated. If this method is not called, the post object is not populated!

  3. default_prefs()This method holds the default settings for lotteries. It is mainly used internally though this class to populate preferences. It’s main job is to make sure there are no missing settings.

  4. get_prefs()Returns the current lotteries preferences.

  5. get_type()Returns the lottery type which is stored as a post meta under ‘mycred_lottery_type’.

  6. get_schedule_prefs()Returns the lottery schedule settings.

  7. get_game_prefs()Returns the lottery game settings.

  8. get_participation_prefs()Returns the lottery participation settings.

  9. get_winnings_prefs()Returns the lottery winnings settings.

  10. get_jackpot_prefs()Returns the lottery jackpot settings.

  11. get_exclude_prefs()Returns the lottery exclude settings.

  12. get_requirements_prefs()Returns the lottery requirements settings.

  13. get_templates_prefs()Returns the lottery templates.

  14. get_state()Returns the lotteries state which is stored as a post meta under ‘mycred_lottery_status’.

  15. get_title()Returns the lottery post title.

  16. get_content()Returns the lottery post content.

  17. can_play( $user_id, $entries, $repeat )Checks if a user can play this lottery. Returns a string value.

    • $user_id (int) required
      The user id to check.
    • $entries (int) required
      The number of entries this user would like to enter. Defaults to 1.
    • $repeat (int) required
      The number of repeats that the user would like play (if allowed). Defaults to 1.

    Returned string values:

    • play – User can play
    • visitor – User is not logged in
    • closed – Lottery is closed
    • excluded – User is excluded
    • req – User does not meet minimum requirements
    • max – User has reached heir maximum number of entries in this lottery
    • insolvent – User can not afford to play
  18. is_excluded( $user_id )Checks if a user is excluded from playing according to the “Exclude” preferences. Returns true or false.

    • $user_id (int)
      The user ID to check.
  19. fail_requirements( $user_id )Checks if a user fails to reach the minimum requirements for this lottery. Returns to true or false.

    • $user_id (int)
      The user ID to check.
  20. max_entry( $user_id )Checks if a user has reached the maximum entries allowed for this lottery according to the “Participation” settings.

    • $user_id (int)
      The user ID to check.
  21. is_insolvent( $user_id, $entries, $repeat )Checks if a user has enough points to play the number of entries and repeats that is requested. Returns true or false.

    • $user_id (int) required
      The user id to check.
    • $entries (int) required
      The number of entries this user would like to enter. Defaults to 1.
    • $repeat (int) required
      The number of repeats that the user would like play (if allowed). Defaults to 1.
  22. get_entries( $users )Returns either all lottery entries or all users with entries in this lottery. Returns an associative array.

    • $users (bool)
      If set to true, an array of user ids are returned else if it is set to false, an associative array of user ids and entries are returned.
  23. get_total_users_playing()Returns the number of users that are playing this lottery.

  24. get_total_entries()Returns the total number of entries in this lottery.

  25. get_users_entries( $user_id )Returns a given users entries.

    • $user_id (int)
      The user ID.
  26. count_users_entries( $user_id )Returns the number of entries a user has in this lottery.

    • $user_id (int)
      The user ID to check.
  27. get_ticket( $entry )Converts an entry string into an assosiative array containing the entries values.

    • $entry (string)
      The entry string.
  28. get_current_ticket_id()Returns the latest lottery ticket ID.

  29. get_ticket_play( $ticket_id, $play )Returns the users play in this lottery. If the lottery is a draw winner type of lottery, the lottery ID is shown while in pick number lotteries, the users played number are returned.

    • $ticket_id (int)
      The ticket ID.
    • $play (string)
      The users play.
  30. get_ticket_run( $repeat )Returns the number of days / weeks a play will run based on the lottery schedule.

    • $repeat (int)
      The number a lottery entry is repeated.
  31. get_current_jackpot()Returns the current jackpot (if used).

  32. increment_current_jackpot()Returns the jackpot amount based on the current jackpot incremented according to the “Jackpot” settings.

Lottery Parameters

  • id (int)
    Required Lottery Post ID.

Usage Examples

Example 1: Get the lottery post object and echo the publishing date.

 

				
					$lottery_id = 1;
$lottery = new myCRED_Lottery( $lottery_id );
if ( $lottery->lottery_exists() ) {
	echo 'This lottery was published on: ' . $lottery->post->post_date;
}
else {
	echo 'Lottery not found.';
}
				
			

 

Example 2: Check if the current user can play the lottery and if they can not, show the appropriate template for why not.

				
					$user_id = get_current_user_id();
$lottery_id = 1;
$lottery = new myCRED_Lottery( $lottery_id );
$can_play = $lottery->can_play( $user_id );
// can_play() will return the string 'play' if user can play
if ( $can_play == 'play' ) {
	// user can play
}
else {
	// user can not play so we get all templates
	$templates = $lottery->get_templates_prefs();
	echo $templates[ $can_play ];
}
				
			

 

myCRED_Module

Package: mycred/core Category: Classes

Description

The myCRED_Module is an abstract class, responsible for constructing and supporting each myCRED Module via the Module API. It contains a set of commonly used functions to help you built modules with ease.

As an abstract class, your module must extend this class which will allow you to use any of the provided functions or replace them with your own.

Usage

				
					class My_Custom_Module extends myCRED_Module {
	function __construct( $point_type ) {
		parent::__construct( $module_id, $args, $point_type );
	}
}
				
			

 

Properties

  • $module_id (string)
    The unique module id. Important! Modules will fail and die if no module id is given!
  • $core (object)
    myCRED Settings.
  • $module_name (string)
    Required identifier for settings native to this module.
  • $option_id (string)
    Optional option ID this module uses.
  • $labels (array)
    Menu and Page Title labels. Only used if the module generates a sub page under the “myCRED” menu.
  • $register (boolean)
    Option to register module settings (if used). Defaults to false.
  • $screen_id (string)
    Screen ID for the module page (if used).
  • $menu_pos (int)
    Menu position.

Methods

  1. myCRED_Module( $module_id, $args )Constructs a module. If no module id is set this method will fail and die!
    • $module_id (string) required
      Constructs a module. If no module id is set this method will fail and die!.
    • $args (array)
      Module arguments.
  2. set_settings( $defaults )Populates the modules settings applying defaults if not set.
    • $defaults (array)
      Default settings.
  3. load()Hooks into myCRED. A module can overwrite this with it’s own load() method.
  4. module_pre_init()Runs before ‘init’.
  5. module_init()Runs at ‘init’.
  6. module_admin_init()Runs at ‘admin_init’.
  7. module_widgets_init()Runs at ‘widgets_init’.
  8. call( $call, $callback, $return )Either runs a given function or a class method. If $return is set, the value passed though it is passed on to the function/class method.
    • $call (string)
      Class method name to call. Ignored if function is called.
    • $callback (string)
      Function or Class to call.
    • $return (any)
      Optional value to pass on and return.
  9. add_menu()Adds a new sub menu item to the “myCRED” Admin Menu. Requires $labels and $screen_id to be set!
  10. register_settings()Registers a modules custom settings.
  11. settings_header()Outputs the “click to open” and “click to close” text to the accordion. Only used if the accordion is requested.
  12. admin_page()Outputs the admin page content. This method must be replaced by the custom module or an empty page is returned.
  13. sanitize_settings( $post )Used if the module has custom settings. This method must be replaced when used by the module and proper sanitation of the values must be made!
  14. after_general_settings()Option to insert custom content after the myCRED Core settings.
  15. sanitize_extra_settings( $new_data, $data, $core )If after_general_settings() is used, this method must be replaced by the custom module and sanitize the settings before they are saved into the DB. If not set, no settings are saved!
    • $new_data (array)
      The sanitized and correct data to save in the database.
    • $data (array)
      The initial posted data.
    • $core (object)
      myCRED Settings.

Module Arguments

				
					// default
$args = array(
	'module_name' => '',
	'option_id'   => '',
	'defaults'    => array(),
	'labels'      => array(
		'menu'        => '',
		'page_title'  => ''
	),
	'register'    => true,
	'screen_id'   => '',
	'add_to_core' => false,
	'accordion'   => false,
	'menu_pos'    => 10
);
				
			

 

  • module_name (string)
    Module name used when modules add settings that can be accessed though myCRED_Settings.
  • option_id (string)
    Optional option id used by this module.
  • defaults (array)
    Default module settings.
  • labels (array)
    Array of labels when the module has it’s own admin page.
  • register (boolean)
    Option to register a modules settings though register_setting(). Should be set to true of option_id is set.
  • screen_id (string)
    A screen id if the module generates a custom admin page.
  • add_to_core (boolean)
    Option to add module settings to the myCRED Settings page. Defaults to false.
  • accordion (boolean)
    Option to include the Accordion script on the module page. Defaults to false.
  • menu_pos (int)
    Menu position.Default positions: Log (10), Hooks (20), Add-ons (30), Settings (99).

Examples

Example 1: A module which generates a new menu item between Log and Hooks called “Custom”.

				
					class My_Custom_Module extends myCRED_Module {
	function __construct() {
		parent::__construct( 'My_Custom_Module', array(
			'module_name' => 'custom',
			'labels'      => array(
				'menu'        => __( 'Custom' ),      // Menu Label
				'page_title'  => __( 'Custom Page' )  // Page Title
			),
			'screen_id'   => 'myCRED_page_custom',
			'menu_pos'    => 15
		) );
	}

	function admin_page() {
		echo 'This is my custom page!';
	}
}
				
			

Example 2: A module which does not add a new page but instead adds new settings under myCred Settings.

				
					class My_Custom_Module extends myCRED_Module {
	function __construct() {
		parent::__construct( 'My_Custom_Module', array(
			'module_name' => 'custom',
			'defaults'    => array(
				'foo'   => 1,
				'bar'   => ''
			),
			'register'    => false,
			'add_to_core' => true
		) );
	}

	// Output our settings or content
	function after_general_settings() {
		// We can access our custom settings under $this->$module_name
		$custom_settings = $this->custom;
		echo 'Custom settings output.';
	}

	// Sanitize our settings
	function sanitize_extra_settings( $new_data, $data, $core ) {
		// Our custom settings are found under $data[$module_name]
		$new_data['custom']['foo'] = sanitize_text_field( $data['custom']['foo'] );
		$new_data['custom']['bar'] = sanitize_text_field( $data['custom']['bar'] );
	}
}
				
			

 

myCRED_Payment_Gateway

Package: mycred/purchase Category: Classes
 

Navigation:

  1. Description
  2. Usage
  3. Properties
  4. Methods

Description

The myCRED_Payment_Gateway is a template class used by the BuyCred Add-on. It contains all the neccessery class methods along with a set of template functions.

Note! You should never initiate this class directly! Instead make sure your custom hook extends it (see usage example bellow).

Usage

				
					class My_Custom_Gateway extends myCRED_Payment_Gateway {
	function __construct( $gateway_prefs ) {
		parent::__construct( $args, $gateway_prefs );
	}
}
				
			

 

Properties

  • $id (string)
    Gateway ID.
  • $core (object)
    myCRED Settings.
  • $prefs (array)
    This gateways preferences.
  • $current_user_id (int)
    The current users id (if logged in).
  • $response (string)
    Responses from the gateway or via the execution of the gateway. It can for example hold information when an error occurs.
  • $request (array)
    The purchase request being sent to the gateway to process.
  • $status (int|string)
    Payment status.
  • $errors (array)
    Holds (if any) error objects.

Methods

  1. myCRED_Payment_Gateway()Class constructor populating $current_user_id, $args, $prefs and $core.
  2. process()This method must be replaced by the child class and should manage requests from either form submissions resulting in contacting a payment gateway or by incoming notifications/verifications from a gateway.
  3. buy()This method must be replaced by the child class and should manage requests made to purchase creds. All purchase requests must nominate the gateway to avoid multiple gateway attempting to process the same purchase.
  4. returning()This method must be replaced by the child class if a purchase request were processed remotely.
  5. preferences()Outputs the gateways preferences. If not set, the default “This Gateway has no settings” is shown.
  6. sanitise_preferences( $data )Option to sanitize the gateways settings before they are saved in the database.
    • $data (array)
      The posted data.
  7. field_name( $data )Outputs this gateways field name.
    • $data (string|array)
      Either a string with the field id or an array if hook has multiple settings.
  8. field_id( $data )Outputs this gateways field id.
    • $data (string|array)
      Either a string with the field id or an array if hook has multiple settings.
  9. decode_log_entries( $entry, $object )This method decodes the log entry for purchases. When purchases are made, the buyers ID is saved under ref_id allowing us to use this users data as template tags.
    • $entry (type)
      The log entry.
    • $object (type)
      The log object.
  10. callback_url()Returns the callback URL for this gateway. Used by PayPal as the URL for the IPN callback. Can be used by any gateway that requires a callback URL.
  11. purchase_header( $title, $reload )Purchase page header.
  12. purchase_footer()The purchase page’s footer.
  13. form_with_redirect( $hidden_fields, $location, $logo_url, $custom_html, $sales_data )Generates a purchase form with the given hidden fields along with a gateway logo and optional custom html. Used by gateways with remote processors (i.e. PayPal or Skrill).
    • $hidden_fields (array)
      Required hidden form fields needed by the gateway.
    • $location (string)
      Form action URL.
    • $logo_url (string)
      Optional gateway logo URL.
    • $custom_html (string)
      Optional HTML to insert in page.
    • $sales_data (string|array)
      Optional sales data to include in page.
  14. get_to()Returns either the current user id or if gifting is enabled and used the id of the user this is gifted to.
  15. get_thankyou()Returns the “Thank You” page URL.
  16. get_cancelled()Returns the “Cancelled” page URL.
  17. get_entry( $_to, $_from )Returns the appropriate log entry template. If “Gifting” is enabled and the two values do not match the gift template is returned.
    • $_to (int)
      The user id of the recipient.
    • $_from (int)
      The user id of the purchaser.
  18. POST_to_data( $unset )Converts posted variables to local with the option to unset $_POST once done.
    • $unset (bool)
      Option to unser $_POST before returning the variables.
  19. transaction_id_is_unique( $transaction_id )Searches the log for a given transaction id. Returns false if id was found else true. Used to make sure purchases are unique.
    • $transaction_id (string|int) required
      The transaction id to look for.
  20. create_token()Returns a WP Nonce for the purchase. Uses wp_create_nonce().
  21. verify_token( $user_id, $nonce )Based on wp_verify_nonce() with the difference that a user id must be given. Returns true or false.
    • $user_id (type) required
      User id for the nonce in question.
    • $nonce (type) required
      The nonce.
  22. encode_sales_data( $data )Encodes the sales data. Uses the myCRED_Protect() class.
    • $data (string) required
      The data to be encoded.
  23. decode_sales_data( $data )Decodes the sales data. Uses the myCRED_Protect() class.
    • $data (string) required
      The data to be decoded.
  24. currencies_dropdown( $name )Generates a drop-down menu with accepted currencies. Uses the ‘mycred_dropdown_currencies’ filter.
    • $name (string) required
      The drop-down elements name.
  25. item_types_dropdown( $name )Generates a drop-down menu with available item types. Used by PayPal. Uses the ‘mycred_dropdown_item_types’ filter.
    • $name (string) required
      description.
  26. list_option_countries( $selected )Echos a list of html options for nations, highlighting the selected. Uses the ‘mycred_list_option_countries’ filter.
    • $selected (string)
      The selected countries two letter code.
  27. list_option_us_states( $selected, $non_us )Echos a list of html options for US states. If $non_us is set to true the “Outside US” option is appended.
    • $selected (string)
      The selected states two letter abbreviation.
    • $non_us (boolean)
      Option to add “Outside US”.
  28. list_option_months( $selected )Echos a list of html options for each month.
    • $selected (int) required
      The selected month number with leading zero.
  29. list_option_card_years( $selected, $number )Echos a list of html options for credit card expiry years.
    • $selected (type) required
      The selected years last two digits.
    • $number (type) required
      The number of years into the future to generate. Defaults to 16

myCRED_Query_Log

Package: mycred/log Category: Classes
 

Description

This class allows you to search the myCRED Log for entries based on a large variety of options. Similar to the WP_Query class, you can use this class to query and then loop through the results in order to show the results in any way you like. Currently the class also has a large set of functions to help you render a table where these results are presented. This feature is currently used by the Log module in your admin area and by the mycred_history shortcode / widget.

Interacting with the Class

While the class offers a large number of functions for you to use, your most common interaction will be with constructing and providing arguments for your search.

				
					// Example 1: Show the last 10 entries
$args = array(
	'number' => 10
);

// The Query
$log = new myCRED_Query_Log( $args );

// The Loop
if ( $log->have_entries() ) {

	// Display using the built-in table
	$log->display();

}
				
			
				
					// Example 2: Get log entries for user 1
$args = array(
	'user_id' => 1
);

// The Query
$log = new myCRED_Query_Log( $args );

// The Loop
if ( $log->have_entries() ) {

	// Build your custom loop
	foreach ( $log->results as $entry ) {

		// Present the results anyway you like

	}

}
				
			
 

Class Properties

PropertyDeclaredTypeDescription
$nowPublicINTThe current unix timestamp. Used for date / time rendering and parsing.
$render_modePublicBOOLIndicates if the class allows results to be rendered using the built-in methods or if only queries can be made. Added in 1.7.5
$argsPublicARRAYHolds the arguments that the class was constructed around.
$requestPublicSTRINGThe SQL query that was run to get the results you are seeing.
$num_rowsPublicINTThe number of rows the query returned.
$max_num_pagesPublicSTRINGThe maximum number of pages the results span over. Defaults to 1.
$total_rowsPublicINTThe total number of rows in the database.
$resultsPublicARRAYThe results of your query.
$headersPublicARRAYHolds an associative array of headers that the table will render.
$hidden_headersPublicARRAYHolds an array of header ids that you have selected to hide.
$corePublicOBJECTThe myCRED_Settings class object.
$is_adminPublicBOOLIndicates if the class is used in the front end or in the wp-admin area.
$referencesPublicARRAYAn array of reference IDs and their labels. This is used to translate each log entries reference when displayed in the table.
$refsPublicARRAYAn array containing all references that exists in the database, based on the current query. Added in 1.7.5
$typesPublicARRAYPopulated with the myCRED_Settings object for each point type we are searching for. This is used when you are rendering a table for the query results with multiple point types. Added in 1.7.5

Class Parameters

The class has only two parameters that you can use.

ParameterTypeRequiredDescription
$argsARRAYYesThe query arguments to return results for.
$arrayBOOLNoOption to return entries in an array format instead of object format. Can not be used when the fields argument is set to return a specific column.

Query Arguments

Arguments can be passed in string or array format. When using a string format, you separate each argument with an & character. String format is well suited in simple straightforward queries, however for more advanced queries, an array format is required.

Entry IDs

ArgumentTypeDescription
entry_idARRAY or INTRetrieve log entries based on their unique ids. Supports queries of a single id or multiple ids. Supports =!=IN and NOT IN comparisons.

Example 1: Get a single entry that has the id 1

 

				
					$log = new myCRED_Query_Log( 'entry_id=1' );

				
			

Example 2: Get multiple entries

				
					$log = new myCRED_Query_Log( array( 'entry_id' => array( 1, 2, 3 ) );


				
			

Example 3: Get entries that does not have the ids 1 or 2

				
					$args = array(
	'entry_id' => array(
		'ids'     => array( 1, 2 ),
		'compare' => 'NOT IN'
	)
);
$log  = new myCRED_Query_Log( $args );


				
			

Example 4: Get entries that does not have the id 5

				
					$args = array(
	'entry_id' => array(
		'ids'     => 5,
		'compare' => '!='
	)
);
$log  = new myCRED_Query_Log( $args );

				
			

 

Point Types

ArgumentTypeDescription
ctypeARRAY or STRINGRetrieve log entries of a particular point type or multiple types based on the point type key. Supports =!=IN and NOT IN comparisons.

Example 1: Get entries of the default point type

				
					$log = new myCRED_Query_Log( 'ctype=mycred_default' );

				
			

Example 2: Get entries of a custom point type

				
					$log = new myCRED_Query_Log( array( 'ctype' => 'mycustom_type' ) );

				
			

Example 3: Get entries that are not of a custom point type

				
					$args = array(
	'ctype' => array(
		'ids'     => array( 'mycustom_type', 'anothertype' ),
		'compare' => 'NOT IN'
	)
);
$log  = new myCRED_Query_Log( $args );
				
			

Example 4: Get entries of all point types

				
					$log = new myCRED_Query_Log( array( 'ctype' => '' ) );

				
			
 

User IDs

ArgumentTypeDescription
user_idARRAY or INTRetrieve log entries one or multiple users based on their numeric IDs. Supports =!=IN and NOT IN comparisons.

Example 1: Get entries for the user with the ID 1

				
					$log = new myCRED_Query_Log( 'user_id=1' );

				
			

Example 2: Get entries for a set of users

 
				
					$log = new myCRED_Query_Log( array( 'user_id' => array( 1, 2, 4 ) ) );

				
			

Example 3: Get entries that do not belong to users 1, 2 and 6

 
				
					$args = array(
	'user_id' => array(
		'ids'     => array( 1, 2, 6 ),
		'compare' => 'NOT IN'
	)
);
$log  = new myCRED_Query_Log( $args );
				
			

 

References

ArgumentTypeDescription
refARRAY or STRINGRetrieve log entries based on one or multiple references. Supports =!=IN and NOT IN comparisons.

Example 1: Get all manual entries

				
					$log = new myCRED_Query_Log( 'ref=manual' );

				
			

Example 2: Get entries for approved comments and published content

 
				
					$log = new myCRED_Query_Log( array( 'ref' => array( 'approved_comment', 'published_content' ) ) );

				
			

Example 3: Get all entries that are not manual

 
				
					$args = array(
	'ref' => array(
		'ids'     => 'manual',
		'compare' => '!='
	)
);
$log  = new myCRED_Query_Log( $args );
				
			

Example 4: Get all entries of a custom reference

 
				
					$args = array(
	'ref' => array(
		'ids'     => 'mycustomreference',
		'compare' => '='
	)
);
$log  = new myCRED_Query_Log( $args );
				
			

 

Reference IDs

ArgumentTypeDescription
ref_idARRAY or INTRetrieve log entries based on one or multiple reference IDs. Supports =!=<<=>=IN and NOT IN comparisons.

Example 1: Get all entries with the reference id 1

				
					$log = new myCRED_Query_Log( 'ref_id=1' );

				
			

Example 2: Get entries with a reference id of 1, 2 or 3

 
				
					$log = new myCRED_Query_Log( array( 'ref_id' => array( 1, 2, 3 ) ) );

				
			

Example 3: Get all entries with a reference id lower than 100

 
				
					$args = array(
	'ref_id' => array(
		'ids'     => 100,
		'compare' => '<'
	)
);
$log  = new myCRED_Query_Log( $args );
				
			

Example 4: Get all entries that have a reference id higher or equal to 10, no matter which point type the entry belongs to

 
				
					$args = array(
	'ref_id' => array(
		'ids'     => 10,
		'compare' => '>='
	),
	'ctype' => ''
);
$log  = new myCRED_Query_Log( $args );
				
			

 

Point Amounts

ArgumentTypeDescription
amountARRAY or INT or FLOATRetrieve log entries based on one or multiple amounts. Supports =!=<<=>=BETWEENNOT BETWEENIN and NOT IN comparisons.

Example 1: Get all entries were users gained 1000 points

				
					$log = new myCRED_Query_Log( 'amount=1000' );

				
			

Example 2: Get entries where a user gained 10, 20 or 50 points

 
				
					$log = new myCRED_Query_Log( array( 'amount' => array( 10, 20, 50 ) ) );

				
			

Example 3: Get all entries where a user has gained between 0 and 100 points

 
				
					$args = array(
	'amount' => array(
		'num'     => array( 0, 100 ),
		'compare' => 'BETWEEN'
	)
);
$log  = new myCRED_Query_Log( $args );
				
			

Example 4: Get all entries where a user lost points, no matter which point type

 
				
					$args = array(
	'amount' => array(
		'num'     => 0,
		'compare' => '<'
	),
	'ctype' => ''
);
$log  = new myCRED_Query_Log( $args );
				
			

 

Time

ArgumentTypeDescription
timeARRAY or INT or STRINGRetrieve log entries for a given time period or date/time. You can supply a well formatted date/time string, a unix timestamp or a keyword. Supported keywords: todayyesterdaythisweek and thismonth. Supports =!=<<=>=BETWEENNOT BETWEENIN and NOT IN comparisons.

 

Example 1: Get todays entries

				
					$log = new myCRED_Query_Log( 'time=today' );

				
			

Example 2: Get all entries for a specific date

 
				
					$log = new myCRED_Query_Log( array( 'time' => '2016-10-01' ) );

				
			

Example 3: Get all entries between two dates

 
				
					$args = array(
	'time' => array(
		'dates'   => array( '2016-01-01 00:00:01', '2016-12-31 23:59:59' ),
		'compare' => 'BETWEEN'
	)
);
$log  = new myCRED_Query_Log( $args );
				
			

Example 4: Get all entries before the start of today

				
					$args = array(
	'time' => array(
		'dates'   => 'today midnight',
		'compare' => '<'
	)
);
$log  = new myCRED_Query_Log( $args );
				
			

 

Searching

ArgumentTypeDescription
sINT or STRINGSearch the “entry” columns and retrieve entries that match. You can use wildcards % for LIKE comparisons.
dataINT or STRINGSearch the “data” columns and retrieve entries that match. You can use wildcards % for LIKE comparisons.

Example 1: Get entries that has the string “boo“ in their description

				
					$log = new myCRED_Query_Log( 's=boo' );

				
			

Example 2: Get entries where the “entry“ columns content starts with “Tokens“

 
				
					$log = new myCRED_Query_Log( array( 's' => 'Tokens%' ) );

				
			

Example 3: Get entries that has the string “boo“ in their data column

 
				
					$log = new myCRED_Query_Log( 'data=boo' );

				
			

Example 4: Get entries where the “data“ columns content a serialized array

 
				
					$log = new myCRED_Query_Log( array( 'data' => 'a:1:{s:8:"ref_type";s:4:"user";}' ) );

				
			

 

Sorting of Results

ArgumentTypeDescription
orderbyARRAY or STRINGSort the retrieved log entries. As of version 1.7.5 you can sort by multiple columns by providing an array of columns and their order.
orderSTRINGEither ASC for ascending or DESC for descending. Ignored if orderby is an array.

Example 1: Get entries for the user 1 ordered by time in an ascending order (latest entry is shown last)

				
					$args = array(
	'user_id' => 1,
	'orderby' => 'time',
	'order'   => 'ASC'
);
$log  = new myCRED_Query_Log( $args );

				
			

Example 2: Get “Manual“ entries sorted by the point amount (largest first), then by time

 
				
					$args = array(
	'ref'     => 'manual',
	'orderby' => array( 'creds' => 'DESC', 'time' => 'DESC' )
);
$log  = new myCRED_Query_Log( $args );
				
			

 

Return Fields

ArgumentTypeDescription
fieldsARRAY or STRINGEither the name of a particular column or an array of column names you want returned in your results. See the log structure documentation for accepted values.
idsBOOLOption to only return the log entries unique ID. Depreciated since 1.7.5 and will be removed in future versions in favour for fields.

 

Example 1: Get the log entry ids only for a specific user

				
					$args = array(
	'user_id' => 1,
	'fields'  => 'id'
);
$log  = new myCRED_Query_Log( $args );
				
			

Example 2: Get the log entry ids and the point amounts only for a specific user

 
				
					$args = array(
	'user_id' => 5,
	'fields'  => array( 'id', 'creds' )
);
$log  = new myCRED_Query_Log( $args );
				
			
 

Pagination

ArgumentTypeDescription
numberINTThe number of entries to return. By default this is 25. Use -1 to return all entries. If you are rendering the results in the class table, this will be the number of entries shown per page.
pagedINTThe page number. Retrieve entries that would show on page x when using the navigation. Defaults to 1 as in the first page.
offsetINTNumber of entries to displace or pass over. Should be used in combination with number. Defaults to zero.

Example 1: Show 15 entries per page

 
				
					$args = array(
	'user_id' => 1,
	'number'  => 15
);
$log  = new myCRED_Query_Log( $args );
				
			

Example 2: Get all manual log entries

 
				
					$args = array(
	'ref'    => 'manual',
	'number' => -1
);
$log  = new myCRED_Query_Log( $args );
				
			

 

Query Filters

Your query will trigger the following filters whenever the class is constructed:

FilterDescription
mycred_query_log_argsAllows you to manipulate the query arguments before it is processed by the class.
mycred_allowed_sortbyControls what values the query can be sorted by. By default this is the log column headers.

myCRED_Remote

Package: mycred/api Category: Classes

Description

This is the main myCRED API class allowing your site to award / deduct points based on requests from other websites. Just like everything else in myCRED, this class is pluggable and can be replaced / altered. There are also several actions and filters associated with this class allowing further customizations / expansion.

Requires myCRED 1.3 or higher.

 

Supported Actions

  • CREDIT
    Add points to a specific user.
  • DEBIT
    Deduct points from a specific user.
  • GET
    Get the current balance of a specific user.
  • PAY
    Deduct points from one user and credit the amount deducted to another user.

 

Supported Methods

  • JSON
  • _GET
  • _POST

If you are looking to create call scripts to interact with this class, please consider using the wp_remote_get or wp_remote_post WordPress functions.

 

Properties

  • $method (string)
    The method used for the incoming API call.
  • $uri (array)
    The $_SERVER[‘REQUEST_URI’] value in an array format.
  • $request (array)
    The API call request array.
  • $host (string)
    The remote callers IP address.
  • $format (string)
    The format of the API call.
  • $user (object)
    The requested user object.
  • $recipient (object)
    The requested recipient user object. Only used for transfers.
  • $reply (string)
    The reply sent back once the call has been processed. Defaults to ‘PROCESSING’. See the error list for a complete list of possible replies.
  • $core (object)
    The myCRED_Settings object.
  • $key (string)
    The API Key.

 

Methods

  1. myCRED_Remote( $key )Handles magic quotes, populates $method, $uri, $format, $host and $core. Requires the API key.

    Action: mycred_remote (ref array)

  2. handle_magic()Handles magic quotes for $_GET, $_POST, $_COOKIE and $_REQUEST.

    Action: mycred_remote_magic(ref array)

  3. set_headers()Sets the API reply headers.

    Action: mycred_remote_headers (ref array)

  4. parse_call()Parses the API call to determine how the API call is made. Supports JSON or HTML. Populates $request and $format.

    Action: mycred_remote_parse (ref array)

  5. get_host_IP()Retreaves the IP address of the caller.

    Action: mycred_remote_host_IP (ref array)

  6. validate_call()Validates the API call. This method either returns an error message or true if the call passes validation.

    Action: mycred_remote_validate (ref array)
    Returns: True (bool) or an error code (string).

  7. process()The main API processor. Processes the API request and returns a string reply. Possible values:

    Filter: mycred_transfer_acc_limit
    Action: mycred_remote_process (ref array)
    Action: mycred_remote_process_{$action} (ref array)
    Returns: The process result (string).

    • COMPLETEDThe request has been successfully completed.
    • FAILEDThe request failed.
    • DUPLICATEThe request is deemed to be a duplicate and was rejected.
    • DECLINEDThe request was declined due to insufficient funds.
    • UNKNOWNUnknown / unsupported request.

 

Error Messages

Important! The following error messages is only available if you have enabled “Debug Mode”. It is very important to disable “Debug Mode” once you are done testing / developing to prevent mischievous calls from learning about your setup!

  1. 0 – 100 Plugin related issues.

    • ERROR: 99 The API Key has not been set or is empty.
  2. 100 – 199 API Call related issues.

    • ERROR: 101 The request is empty.
    • ERROR: 102 The required “action” key is missing or empty in the request.
    • ERROR: 103 The required “account” key is missing or empty in the request.
    • ERROR: 104 The required “token” key is missing or empty in the request.
    • ERROR: 105 The required “host” key is missing or empty in the request.
  3. 200 – 299 User related issues.

    • ERROR: 201 The user count not be found. Remember that the API only supports users identified via an email address.
    • ERROR: 202 The user is excluded from using myCRED.
  4. 300 – 399 Request specific issues regardless of what action is requested.

    • ERROR: 301 Invalid security token.
    • ERROR: 302 Unknown / Unsupported Action request.
  5. 400 – 499 CREDIT & DEBIT related issues.

    • ERROR: 401 The required “ref” key is missing or empty in the request.
    • ERROR: 402 The required “entry” key is missing or empty in the request.
    • ERROR: 403 The required “amount” key is missing or empty in the request.
  6. 500 – 599 GET related issues.

    • none
  7. 600 – 699 PAY related issues.

    • ERROR: 501 The required “ref” key is missing or empty in the request.
    • ERROR: 502 The required “entry” key is missing or empty in the request.
    • ERROR: 503 The required “amount” key is missing or empty in the request.
    • ERROR: 504 The required “to” key is missing or empty in the request.
    • ERROR: 505 The required “data” key is missing or empty in the request.
    • ERROR: 506 The recipient user could not be found.
    • ERROR: 507 The recipient user ID is the same as the sender.
    • ERROR: 508 The recipient user has been excluded from using myCRED.

myCRED_Settings

Package: mycred/core Category: Classes
 

Description

This class constructs and enables a set of core tools that allows you to execute point related actions or retrieve points related details.

 

Interacting with the Class

While the class can be called directly, it is highly recommended that you instead use the mycred function.

				
					// Default usage
$mycred = mycred();

// Setup for a custom point type
$mycred = mycred( 'customtypekey' );
				
			

 

Class Properties

PropertyDeclaredTypeDescription
$corePublicarrayThe settings array for the current point type.
$log_tablePublicstringThe database table name based on your Network settings (if you use Multisite).
$cred_idPublicstringThe meta key ID of the current point type.
$is_multisitePublicBOOLThe value of the is_multisite function.
$use_master_templatePublicBOOLTrue if the master template feature is enabled. False if not using multisite.
$use_central_loggingPublicBOOLTrue if the central logging is enabled. False if not using multisite.

Class Parameters

The class has only one parameter that can be used.

ParameterTypeRequiredDescription
$typekeySTRINGNoThe point type key to construct.

Class Methods

While you can interact with balances without using this class, the methods offered here will make sure your interaction happens faster and safer. Using these methods also ensures that you always have access to all point related features in myCRED.

public function defaults() {
 Description:Returns the default settings array which is used when compiling the point type’s settings.
VariableTypeRequiredDescription
No variables
}
public function singular() {
 Description:Returns the current point types name in singular form.
VariableTypeRequiredDescription
No variables
}

Example 1: Display the point types given name in singular form

				
					$mycred = mycred();

echo $mycred->singular();
				
			
public function plural() {
 Description:Returns the current point types name in plural form.
VariableTypeRequiredDescription
No variables
}

Example 1: Display the point types given name in plural form

				
					$mycred = mycred();

echo $mycred->plural();
				
			
public function zero() {
 Description:Returns zero formatted according to the point type setup.
VariableTypeRequiredDescription
No variables
}
public function number( $number = '' ) {
 Description:Returns the given value formatted according to the point types setup. Should be used when points are used in calculations.
VariableTypeRequiredDescription
numberINT or FLOATYesThe value to format.
}
public function format_number( $number = '' ) {
 Description:Returns a given value formatted based on the point types settings as a string. Should be used when points are intended to be displayed and not used in calculations.
VariableTypeRequiredDescription
numberINT or FLOATYesThe value to format.
}
public function format_creds( $creds = 0, $before = '', $after = '', $force_in = false ) {
 Description:Returns a given value formatted based on the point types settings with prefix / suffix added (if used). Can not be used in calculations!
VariableTypeRequiredDescription
credsINT or FLOATYesThe value to format.
beforeSTRINGNoOptional string to attach before the formatted point value. If you use a prefix, this string is appended before the prefix.
afterSTRINGNoOptional string to attach after the formatted point value. If you use a suffix, this string is appended after the suffix.
force_inBOOLNoOption to force the $before or $after variables before / after the prefix / suffix.
}

Example 1: Display a users balance formatted with a prefix / suffix (if used)

				
					$mycred  = mycred();
$balance = $mycred->get_users_balance( get_current_user_id() );

echo $mycred->format_creds( $balance );
				
			
public function round_value( $amount = 0, $up_down = false, $precision = 0 ) {
 Description:Rounds a given value either up or down with an option to set the precision.
VariableTypeRequiredDescription
amountINT or FLOATYesThe value to round.
up_downSTRINGYesEither “up” to round up or “down” to round down.
precisionINTNoRounding precision. Defaults to zero.
}
public function get_lowest_value() {
 Description:Returns the lowest possible points value above zero based on the point type setup. A point type setup that does not uses any decimals would return 1 while a point type using for example 2 decimal places would return 0.01. Mainly used to prevent users from sending partial points.
VariableTypeRequiredDescription
No variables
}
public function apply_exchange_rate( $amount = 0, $rate = 1, $round = true ) {
 Description:Divides the amount by the given rate.
VariableTypeRequiredDescription
amountINT or FLOATYesThe initial point amount.
rateINT or FLOATYesThe exchange rate that are applied to the amount.
roundBOOLNoOption to round the value. Uses PHP round.
}
public function parse_template_tags( $content = '', $log_entry ) {
 Description:Parses template tags in a given string. Can only be used when a log entry object is available. Based on the data column details, this method loads the appropriate template tag processor (see below).
VariableTypeRequiredDescription
contentSTRINGYesThe string that potentially contain template tags.
log_entryOBJECTYesThe log entry object.
}
public function template_tags_general( $content = '' ) {
 Description:Converts general template tags into their appropriate values.
VariableTypeRequiredDescription
contentSTRINGYesThe string that potentially contain template tags.
}
public function template_tags_amount( $content = '', $amount = 0 ) {
 Description:Converts amount related template tags into their appropriate values. Uses template_tags_general().
VariableTypeRequiredDescription
contentSTRINGYesThe string that potentially contain template tags.
amountINT or FLOATYesThe amount to use when replacing amount related template tags.
}
public function template_tags_post( $content = '', $ref_id = NULL, $data = '' ) {
 Description:Converts post related template tags into their appropriate values. Uses template_tags_general().
VariableTypeRequiredDescription
contentSTRINGYesThe string that potentially contain template tags.
ref_idINTYesThe reference ID stored with the log entry, usually the post object ID.
dataSTRING or ARRAYNoThe data stored with the log entry. Mainly used when a post has been deleted as the old past data is stored in the data column.
}
public function template_tags_user( $content = '', $ref_id = NULL, $data = '' ) {
 Description:Converts user related template tags into their appropriate values. Uses template_tags_general().
VariableTypeRequiredDescription
contentSTRINGYesThe string that potentially contain template tags.
ref_idINTYesThe reference ID stored with the log entry, usually the user object ID.
dataSTRING or ARRAYNoThe data stored with the log entry.
}
public function template_tags_comment( $content = '', $ref_id = NULL, $data = '' ) {
 Description:Converts comment related template tags into their appropriate values. Uses template_tags_general().
VariableTypeRequiredDescription
contentSTRINGYesThe string that potentially contain template tags.
ref_idINTYesThe reference ID stored with the log entry, usually the comment object ID.
dataSTRING or ARRAYNoThe data stored with the log entry.
}
public function has_tags( $type = '', $tags = '', $content = '' ) {
 Description:Checks if a given string contains any template tags based on a set type e.g. comment, post or user. Returns true or false.
VariableTypeRequiredDescription
typeSTRINGYesThe template tag type.
tagsSTRINGYesList of template tags to check for. This list is passed on to preg_match so if more then one tag needs to be checked for, this must be separated with a horizontal line |.
contentSTRINGYesThe content string that needs to be checked.
}
public function available_template_tags( $available = array(), $custom = '' ) {
 Description:Returns a string indicating the available template tags that can be used.
VariableTypeRequiredDescription
availableARRAYYesAn array or template tag types. These will be listed after the sentence: Available Template Tags:.
customSTRINGNoOptional list of additional / special template tags that are appended at the end of the string.
}
public function allowed_tags( $data = '', $allow = '' ) {
 Description:Strips HTML tags of a given string based on the allowed html tags list provided by the allowed_html_tags method.
VariableTypeRequiredDescription
dataSTRINGYesThe string that contains HTML tags that needs to be stripped.
allowARRAY or BOOLNoEither false to strip all tags, an array or allowed HTML tags not to strip of or if left empty, a default set of tags are removed.
}
public function edit_creds_cap() {
 Description:Returns the capability set for point editors.
VariableTypeRequiredDescription
No variables
}

Example 1: Make sure the current user is a point editor.

				
					$mycred = mycred();

// If the current user is a "point editor"
if ( current_user_can( $mycred->edit_creds_cap() ) ) {

}
				
			
public function can_edit_creds( $user_id = '' ) {
 Description:Checks if a given user is a “point editor” based on the current point type. Uses user_can.
VariableTypeRequiredDescription
user_idINTYesThe user ID to check.
}
public function edit_plugin_cap() {
 Description:Returns the capability set for point administrators.
VariableTypeRequiredDescription
No variables
}

Example 1: Make sure the current user is a point editor.

				
					$mycred = mycred();

// If the current user is a "point administrator"
if ( current_user_can( $mycred->edit_plugin_cap() ) ) {

}
				
			
public function can_edit_plugin( $user_id = '' ) {
 Description:Checks if a given user is a “point administrator” based on the current point type. Uses user_can.
VariableTypeRequiredDescription
user_idINTYesThe user ID to check.
}
public function in_exclude_list( $user_id = '' ) {
 Description:Checks if a given user is in the list of excluded users. The ID is checked against the comma separated list of IDs you might have set to the current point type.
VariableTypeRequiredDescription
user_idINTYesThe user ID to check.
}
public function exclude_plugin_editors() {
 Description:Checks if the current point type has been set to exclude “point administrators”. Returns true or false.
VariableTypeRequiredDescription
No variables
}
public function exclude_creds_editors() {
 Description:Checks if the current point type has been set to exclude “point editors”. Returns true or false.
VariableTypeRequiredDescription
No variables
}
public function exclude_user( $user_id = NULL ) {
 Description:Checks if the given user is excluded from the current point type.
VariableTypeRequiredDescription
user_idINTYesThe user object ID.
}

Example 1: Check if the current user is excluded from using the current point type.

				
					$user_id = get_current_user_id();
$mycred  = mycred();

if ( ! $mycred->exclude_user( $user_id ) ) {

	// User is not excluded

}
				
			
public function count_members() {
 Description:Returns the total number of users with a balance of the current point type.
VariableTypeRequiredDescription
No variables
}
public function get_cred_id() {
 Description:Returns ID of the current point type.
VariableTypeRequiredDescription
No variables
}
public function max() {
 Description:Returns the highest value allowed for the current point type.
VariableTypeRequiredDescription
No variables
}
public function get_users_balance( $user_id = NULL, $type = NULL ) {
 Description:Returns the given users current balance for either a given point type or the current point type.
VariableTypeRequiredDescription
user_idINTYesThe users numeric ID.
typeSTRINGNoOption to retrieve a users balance for a different point type then the current one. If you are want the current point types balance then this should not be used.
}

Example 1: Get the current users balance for the current point type

				
					$user_id = get_current_user_id();
$mycred  = mycred();
$balance = 0;

// Get the balance if the user is not excluded
if ( ! $mycred->exclude_user( $user_id ) )
	$balance = $mycred->get_users_balance( $user_id );
				
			
public function update_users_balance( $user_id = NULL, $amount = NULL, $type = NULL ) {
 Description:Updates a given users points balance by a given value. This value can be positive to increase a users balance or negative to reduce a balance.
VariableTypeRequiredDescription
user_idINTYesThe users numeric ID.
amountINT or FLOATYesThe point amount to adjust the balance with. This value must be properly formatted. If the point type does not use decimals, then the amount can not use decimals either.
typeSTRINGNoOption to update a different point balance then the current point type.
}

Example 1: Add 10 points to the current users balance.

 
				
					$user_id = get_current_user_id();
$mycred  = mycred();
$amount  = 10;

// Update the balance if the user is not excluded
if ( ! $mycred->exclude_user( $user_id ) )
	$mycred->update_users_balance( $user_id, $amount );
				
			

Example 2: Deduct 50 points to the current users balance.

 
				
					$user_id = get_current_user_id();
$mycred  = mycred();
$amount  = -50;

// Update the balance if the user is not excluded
if ( ! $mycred->exclude_user( $user_id ) )
	$mycred->update_users_balance( $user_id, $amount );
				
			
public function set_users_balance( $user_id = NULL, $new_balance = NULL ) {
 Description:Changes a users balance to the given value. Added in 1.7.3. Can only be used for the current point type.
VariableTypeRequiredDescription
user_idINTYesThe users numeric ID.
new_balanceINT or FLOATYesThe point amount to adjust the balance with. This value must be properly formatted. If the point type does not use decimals, then the amount can not use decimals either.
}

Example 1: Change the current users balance to 100 points.

				
					$user_id     = get_current_user_id();
$mycred      = mycred();
$new_balance = 100;

// Update the balance if the user is not excluded
if ( ! $mycred->exclude_user( $user_id ) )
	$mycred->set_users_balance( $user_id, $new_balance );
				
			
public function add_creds( $ref = '', $user_id = '', $amount = '', $entry = '', $ref_id = '', $data = '', $type = MYCRED_DEFAULT_TYPE_KEY ) {
 Description:Adds or deducts points from a given users account and saves a log entry of the transaction. Contrarily to what the name suggests, this method can be used to adding points as well as deducting points.
VariableTypeRequiredDescription
refSTRINGYesThe reference to log the transaction under.
user_idINTYesThe users numeric ID.
amountINT or FLOATYesThe point amount to adjust the balance with. This value must be properly formatted. If the point type does not use decimals, then the amount can not use decimals either.
entrySTRINGYesThe log entry of the transaction. This is what is shown to users in the logs.
ref_idINTNoOptional reference ID to save with the log entry.
dataSTRING or ARRAYNoOptional data to save with the log entry. This can be a string or an array. Note that arrays will be serialized before saved to the log.
typeSTRINGNoThe point type to adjust and log the transaction under. Should only be used if the point type is not the current point type set in this class.
}

Example 1: Give a user 10 points and log it as a “Donation“.

				
					$user_id = 1;
$amount  = 10;
$mycred  = mycred();

if ( ! $mycred->exclude_user( $user_id ) )
	$mycred->add_creds(
		'donation',
		$user_id,
		$amount,
		'%plural% donation'
	);
				
			
 
 
public function add_to_log( $ref = '', $user_id = '', $amount = '', $entry = '', $ref_id = '', $data = '', $type = MYCRED_DEFAULT_TYPE_KEY ) {
 Description:Adds a log entry to the myCRED Log database table. Used by add_creds().
VariableTypeRequiredDescription
refSTRINGYesThe reference to log the transaction under.
user_idINTYesThe users numeric ID.
amountINT or FLOATYesThe point amount. If the point type does not use decimals, then the amount can not use decimals either.
entrySTRINGYesThe log entry of the transaction.
ref_idINTNoOptional reference ID to save with the log entry.
dataSTRING or ARRAYNoOptional data to save with the log entry. This can be a string or an array. Note that arrays will be serialized before saved to the log.
typeSTRINGNoThe point type to adjust and log the transaction under. Should only be used if the point type is not the current point type set in this class.
}
public function update_log_entry( $entry_id = NULL, $data = array(), $prep = array() ) {
 Description:Updates a given log entry. Requires that you have the log entries ID. Added in 1.6.7
VariableTypeRequiredDescription
entry_idINTYesThe unique log entry ID.
dataARRAYYesAn array of new data. Uses the $wpdb->update().
prepARRAYYesAn array of formats to be mapped to each of the values in $data..
}
public function has_entry( $reference = NULL, $ref_id = NULL, $user_id = NULL, $data = NULL, $type = NULL ) {
 Description:Checks if a specific log entry exists in the database.
VariableTypeRequiredDescription
referenceSTRINGNoThe reference to check.
ref_idINTNoThe reference id to check.
user_idINTNoThe user id to check.
dataSTRINGNoThe data to check for. If you know the data is an array, make sure this value is a serialized array.
typeSTRINGNoThe point type to check.
}