myCRED_Hook
Description
This is an abstract class used to construct myCRED Hooks. It contains a set of predefined methods to help hook constructions.
Available since version 1.0
Class Properties
Property | Declared | Type | Description |
---|---|---|---|
$id |
Public | string | The hook ID. Must be unique. |
$core |
Public | object | The main point type object. |
$point_types |
Public | array | All registered point type IDs. |
$is_main_type |
Public | bool | True if the current instance is the main point type (first instance) or false if not. |
$mycred_type |
Public | bool | The current point type instance. |
$prefs |
Public | array | Associative 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 Properties
Parameter | Type | Required | Description |
---|---|---|---|
$args |
array | Yes | The hook arguments containing the hooks ID and preferences. |
$hook_prefs |
array | Yes | The module settings array. |
$type |
string | Yes | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
data |
array | Yes | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
field |
string or array | Yes | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
field |
string or array | Yes | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
instance |
string | Yes | The hook instance to check. | |
reference |
string | Yes | The reference to check. | |
user_id |
int | Yes | The user ID to check. | |
ref_id |
int | No | Optional 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
name |
string | Yes | The settings name to use. | |
id |
string | Yes | The settings id to use. | |
selected |
string | Yes | The 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. | |||
---|---|---|---|---|
Variable | Type | Required | Description | |
reference |
string | No | The reference to check. | |
ref_id |
int | No | The reference id to check. | |
user_id |
int | No | The user id to check. | |
data |
string | No | The data to check for. If you know the data is an array, make sure this value is a serialized array. | |
type |
string | No | The point type to check. | |
} |