Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Register Hook
- add_filter( 'mycred_setup_hooks', 'register_rate_hook' );
- function register_rate_hook( $installed )
- {
- $installed['complete_profile'] = array(
- 'title' => __( '%plural% for Rating a forum post'),
- 'description' => __( 'This hook award points to users who rate posts', 'CommentPress Modern Theme' ),
- 'callback' => array( 'my_rate_class' )
- );
- return $installed;
- }
- // myCRED Custom Hook Class
- class my_rate_class extends myCRED_Hook {
- /**
- * Construct
- */
- function __construct( $hook_prefs ) {
- parent::__construct( array(
- 'id' => 'rate_post',
- 'defaults' => array(
- 'creds' => 1,
- 'log' => '%plural% for rating a post'
- )
- ), $hook_prefs );
- }
- /**
- * Hook into WordPress
- */
- public function run() {
- add_action( 'bbpress_post_rating_UpdateRating', array( $this, 'rate_post' ) );
- add_action( 'bp_include', array( $this, 'rate_post' ) );
- }
- /**
- * Check if the user qualifies for points
- */
- public function rate_post( $user_id ) {
- // Check if user is excluded (required)
- if ( $this->core->exclude_user( $user_id ) ) return;
- // Execute
- $this->core->add_creds(
- 'rating_post',
- $user_id,
- $this->prefs['creds'],
- $this->prefs['log']
- );
- }
- /**
- * 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>
- <?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'];
- return $new_data;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment