myCRED_Settings

Codex / mycred/core / Classes / myCRED_Settings

Navigation:

  1. Description
  2. Usage
  3. Properties
  4. Methods
  5. Related Functions

Description

The myCRED_Settings class is the core myCRED class used by all features.

Besides containing your point type settings, it also contains a large set of commonly used functions such as get a users balance, check if a user is excluded from using a particular point type or awarding / deducting points.

While you can initialize the class directly, you should use the mycred function to access this class.

 

Note that the mycred function was introduced in version 1.4. Older versions must use the mycred_get_settings function which works the same with but without support for multiple point types.

Usage

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

// Echo the singular name
echo $mycred->name['singular'];

// Check if a given user can edit this plugin
if ( $mycred->can_edit_plugin( $user_id ) ) {
	// do something if true
}

// Check if user is "excluded".
if ( $mycred->exclude_user( $user_id ) ) {
	// do something if true
}

// Get a users balance
$balance = $mycred->get_users_balance( $user_id );

// Get a users balance for a different point type then what was used when initializing this class
$balance = $mycred->get_users_balance( $user_id, 'mytype' );

Properties

  • $core (array)
    Associative array of “General Settings” saved under mycred_pref_core.
    Note! On Multisite installations, if the “Master Template” feature is enabled, the main site’s (blog id 1) settings are retrieved.

Note! When this class is initiated, the constructor will automatically add the arrays first level keys and it’s values as a property allowing you to access these keys directly.

Example: Two ways to access the singular name, both returning the same value.

$mycred = mycred();
echo $mycred->core->name['singular'];
echo $mycred->name['singular'];

Methods

  1. myCRED_Settings()Grabs the plugin settings and populates the $core property.
  2. singular()Returns the singular name.
  3. plural()Returns the plural name.
  4. zero()Returns zero formatted according to your setup with or without decimals.
  5. number( $number )Returns the given value either as an integer or as a float.
    • $number (int|float) required
      The initial value to format.
  6. format_number( $number )Returns a given value formated according to setup. Mainly checks to see if decimals are used. Uses number_format().
    • $number (int|float) required
      The initial value to format.

    Filter: mycred_format_number

  7. format_creds( $number, $before, $after, $force_in )Returns a given value formatted with prefix and/or suffix. You can also insert a custom string before or after the formated value.
    • $number (int|float) required
      The value to format.
    • $before (string)
      Optional string to insert before the value.
    • $after (string)
      Optional string to isnert after the value.
    • $force_in (boolean)
      Option to force $before after prefix and $after before suffix.

    Filter: mycred_format_creds

  8. round_value( $amount, $up_down, $precision )Will round a given value either up or down with the option to use precision.
    • $amount (int|float) required
      The value to be rounded.
    • $up_down (string|boolean)
      Choice of rounding up or down. Using false bypasses this function.
    • $precision (int)
      The optional number of decimal digits to round to. Defaults to 0.
  9. apply_exchange_rate( $amount, $rate, $round )Devides the $amount value with $rate with the option to round the value using round().
    • $amount (int|float) required
      The initial value.
    • $rate (int|float) required
      Value to divide $amount with.
    • $round (bool)
      Option to round the value. Defaults to true.
  10. parse_template_tags( $content, $log_entry )Replaces template tags in a given string while using the $log_entry as reference. Used for each log entry row before displaying the result. The log entry object must be supplied for this method to work.
    • $content (string) required
      The string containing the template tags.
    • $log_entry (object) required
      The Log entry object

    Filter: mycred_parse_log_entry
    Filter: mycred_parse_log_entry_{$reference}
    Filter: mycred_parse_tags_{$type}

  11. template_tags_general( $text )Replaces General Template Tags: %singular%, %plural%, %login_url%, %logout_url% etc.
    • $text (string) required
      The string containing the template tags.

    Filter: mycred_parse_tags_general

  12. template_tags_amount( $text, $amount )Replaces Amount Template Tags: %cred% and %cred_f%.
    • $text (string) required
      The string containing the template tags.
    • $amount (int) required
      The amount to be formated.

    Filter: mycred_parse_tags_amount

  13. template_tags_post( $text, $ref_id, $data )Replaces Post Template Tags: %link_with_title%, %post_title%, %post_type% and %post_url%. Requires that the reference ID is a post id!
    • $text (string) required
      The string containing the template tags.
    • $ref_id (int) required
      The post id used as reference id.
    • $data (object)
      Optional extra data. When used to parse the log, the data columns content is passed as $data.

    Filter: mycred_parse_tags_post

  14. template_tags_user( $text, $ref_id, $data )Replaces User Template Tags: %display_name%, %user_id%, %user_name%, %user_name_ec%, %user_profile_link% and %user_profile_url%. Requires that the reference ID is a user id!
    • $text (string) required
      The string containing the template tags.
    • $ref_id (int|bool) required
      Either false, if the user object is passed along though $data else a user id.
    • $data (array|object)
      Optional extra data. Either the user object or an associative array of user details. Used when the user object is available and no new query is required. Changed in 1.2

    Filter: mycred_parse_tags_user

  15. template_tags_comment( $text, $ref_id, $data )Replaces Comment Template Tags: %comment_id%, %c_link_with_title%, %c_post_id%, %c_post_title% and %c_post_url%. Requires that the reference ID is a comment id!
    • $text (string) required
      The string containing the template tags.
    • $ref_id (int) required
      The comment id used as reference id.
    • $data (object)
      Optional extra data. When used to parse the log, the data columns content is passed as $data.

    Filter: mycred_parse_tags_comment

  16. has_tags()Checks if a string has any of the defined template tags. Used by template tag parsers.
  17. allowed_tags( $data, $allow )Strips HTML tags from a given string.
    • $data (string)
      String to strip.
    • $allow (string)
      Optional overwrite of the allowed HTML tags.

    Filter: mycred_allowed_tags

  18. edit_creds_cap()Returns the set edit creds capability.
  19. can_edit_creds( $user_id )Check if a given user or the current user can edit users creds. Uses edit_creds_cap().
    • $user_id (int)
      User id to check for. Defaults to the current user.
  20. edit_plugin_cap()Returns the set edit plugin capability.
  21. can_edit_plugin( $user_id )Check if a given user or the current user can edit the myCRED plugin. Uses edit_plugin_cap().
    • $user_id (int)
      User id to check for. Defaults to the current user.
  22. in_exclude_list( $user_id )Check if user id is in exclude list. Returns true or false.
    • $user_id (int)
      User id to check for. Defaults to the current user.
  23. exclude_plugin_editors()Check if plugin editors should be excluded. Returns true or false.
  24. exclude_creds_editors()Check if cred editors should be excluded. Returns true or false.
  25. exclude_user( $user_id )Checks is the given user id should be excluded.
    • $user_id (int)
      User id to check.
  26. get_cred_id()Returns the set cred id.
  27. get_users_balance( $user_id, $type )Returns the given users cred balance. Note that no formatting is done to the returned value. Returns either an integer or float.
    • $user_id (int) required
      User id.

    Filter: mycred_get_users_cred

  28. update_users_balance( $user_id, $amount )Returns the updated balance of the given user.
    • $user_id (int) required
      User id.
    • $amount (int|float)
      Amount to add/deduct from users balance. This value must be pre-formated.

    This method was renamed from update_users_cred in version 1.0.9.2

    Action: mycred_update_user_balance

  29. add_creds( $ref, $user_id, $cred, $entry, $ref_id, $data, $type )Adds creds to a given user. A refernece ID, user id and number of creds must be given. Important! This function will not check if the user should be excluded from gaining points, this must be done before calling this function!
    • $ref (string)
      Required reference id.
    • $user_id (int)
      Required User id.
    • $cred (int|float)
      Amount to be added/deducted.
    • $entry (string)
      Log entry.
    • $ref_id (int)
      Optional reference id.
    • $data (int|string|array|object)
      Optional extra data to be saved with the entry. Note that arrays get serialized before saved.
    • $type (string)
      Optional cred type.

    Filter: mycred_add

  30. update_rankings( $force, $type )Updates Rankings for a given post type.
    • $foce (bool)
      If rankings are updated on a set interval, this option can override and force a new setting to be saved. Defaults to false
    • $user_id (int) required
      User id.
  31. add_to_log( $ref, $user_id, $cred, $entry, $ref_id, $data, $type )Adds a new entry into the log. A reference id, user id and number of credits must be set.
    • $ref (string)
      Required reference id.
    • $user_id (int)
      Required User id.
    • $cred (int|float)
      Amount to be added/deducted.
    • $entry (string)
      Log entry.
    • $ref_id (int)
      Optional reference id.
    • $data (int|string|array|object)
      Optional extra data to be saved with the entry. Note that arrays get serialized before saved.
    • $type (string)
      Optional cred type.
  32. has_entry( $reference, $ref_id, $user_id, $data )Moved from the myCRED_Hook abstract class in 1.2. Checks for a log entry with the given variables. Returns true or false.
    • $reference (string)
      Reference to check.
    • $ref_id (int)
      Reference ID to check. Reference IDs are always integers.
    • $user_id (int)
      User ID check.
    • $data (string)
      Data to check.

Related Functions

Last edited March 5, 2016