Created
July 11, 2017 10:44
-
-
Save anonymous/83373cc480abf8d322e7d81ddae26ddd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: MF - Tiekie-hook - CBX WP Bookmark | |
Plugin URI: http://geekspeak.co.za | |
Description: Ken tiekies toe wanneer 'n artikel geboekmerk word | |
Author: Kobus Bezuidenhout | |
Version: 2.0 | |
Author URI: http://geekspeak.co.za | |
License: GPL2 | |
Changelog: | |
2.0 - Herstruktureer sodat dit saam met badges werk | |
1.0 - Eerste weergawe | |
*/ | |
/** | |
* Register Hook | |
*/ | |
add_filter( 'mycred_setup_hooks', 'register_mf_boekmerk_hook' ); | |
function register_mf_boekmerk_hook( $installed ) | |
{ | |
$installed['boekmerk'] = array( | |
'title' => 'Boekmerk artikel', | |
'description' => 'This hook award / deducts points from users who favourite posts.', | |
'callback' => array( 'mf_boekmerk_hook_class' ) | |
); | |
return $installed; | |
} | |
/** | |
* Favorites Hook | |
*/ | |
add_action( 'mycred_load_hooks', 'load_mf_boekmerk_hook' ); | |
function load_mf_boekmerk_hook() { | |
if ( ! class_exists( 'mf_boekmerk_hook_class' ) && class_exists( 'myCRED_Hook' ) ) { | |
// myCRED Custom Hook Class | |
class mf_boekmerk_hook_class extends myCRED_Hook { | |
/** | |
* Construct | |
*/ | |
function __construct( $hook_prefs, $type = 'mf_tiekies' ) { | |
parent::__construct( array( | |
'id' => 'boekmerk', | |
'defaults' => array( | |
'creds' => 1, | |
'log' => '%plural% vir boekmerk', | |
'limit' => '0/x' | |
) | |
), $hook_prefs, $type ); | |
} | |
/** | |
* Hook into WordPress | |
*/ | |
public function run() { | |
// Since we are running a single instance, we do not need to check | |
// if points are set to zero (disable). myCRED will check if this | |
// hook has been enabled before calling this method so no need to check | |
// that either. | |
add_action( 'wp_ajax_cbx_add_bookmark', array( $this, 'boekmerk' ), 10, 4 ); | |
} | |
/** | |
* Check if the user qualifies for points | |
*/ | |
public function boekmerk( $post_id, $status, $site_id, $user_id ) { | |
// Check if user is excluded (required) | |
if ( $this->core->exclude_user( $user_id ) ) return; | |
// Make sure this is a unique event | |
if ( $this->has_entry( 'boekmerk', $post_id, $user_id ) ) { | |
return; | |
} else { | |
// Execute | |
$this->core->add_creds( | |
'boekmerk', | |
$user_id, | |
$this->prefs['creds'], | |
$this->prefs['log'], | |
$post_id, | |
'', | |
$this->mycred_type | |
); | |
} | |
} | |
/** | |
* Add Settings | |
*/ | |
public function preferences() { | |
// Our settings are available under $this->prefs | |
$prefs = $this->prefs; ?> | |
<!-- First we set the amount --> | |
<label class="subheader"><?php echo $this->core->plural(); ?></label> | |
<ol> | |
<li> | |
<div class="h2"><input type="text" name="<?php echo $this->field_name( 'creds' ); ?>" id="<?php echo $this->field_id( 'creds' ); ?>" value="<?php echo $this->core->format_number( $prefs['creds'] ); ?>" size="8" /></div> | |
</li> | |
</ol> | |
<!-- Then the log template --> | |
<label class="subheader"><?php _e( 'Log template', 'mycred' ); ?></label> | |
<ol> | |
<li> | |
<div class="h2"><input type="text" name="<?php echo $this->field_name( 'log' ); ?>" id="<?php echo $this->field_id( 'log' ); ?>" value="<?php echo $prefs['log']; ?>" class="long" /></div> | |
</li> | |
</ol> | |
<!-- Then the impose limits dropdown --> | |
<label class="subheader"><label for="<?php echo $this->field_id( 'limit' ); ?>"><?php _e( 'Limit', 'mycred' ); ?></label></label> | |
<ol> | |
<li> | |
<div class="h2"> | |
<?php echo $this->hook_limit_setting( $this->field_name( 'limit' ), $this->field_id( 'limit' ), $prefs['limit'] ); ?> | |
</div> | |
</li> | |
</ol> | |
<?php | |
} | |
/** | |
* Sanitize Preferences | |
*/ | |
public function sanitise_preferences( $data ) { | |
$new_data = $data; | |
// Apply defaults if any field is left empty | |
$new_data['creds'] = ( !empty( $data['creds'] ) ) ? $data['creds'] : $this->defaults['creds']; | |
$new_data['log'] = ( !empty( $data['log'] ) ) ? sanitize_text_field( $data['log'] ) : $this->defaults['log']; | |
$new_data['limit'] = ( !empty( $data['limit'] ) ) ? sanitize_text_field( $data['limit'] ) : $this->defaults['limit']; | |
return $new_data; | |
} | |
} | |
} | |
} | |
/** | |
* Add References | |
* Sien http://codex.mycred.me/filters/mycred_all_references/ | |
*/ | |
add_filter( 'mycred_all_references', 'add_mf_boekmerk_references' ); | |
function add_mf_boekmerk_references( $list ) { | |
$list['boekmerk'] = 'Boekmerk artikel (CBX WP Bookmark)'; | |
return $list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment