Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Register Hook
- * @since 0.1
- * @version 1.0.1
- */
- add_filter( 'mycred_setup_hooks', 'mycred_register_bookmark_hook', 40 );
- function mycred_register_bookmark_hook( $installed )
- {
- $installed['hook_bookmark'] = array(
- 'title' => __( 'Bookmark', 'mycred' ),
- 'description' => __( 'Awards %_plural% for bookmarking a site.', 'mycred' ),
- 'callback' => array( 'myCRED_BP_Bookmarks' )
- );
- }
- return $installed;
- }
- /**
- * myCRED_BP_Bookmarks class
- * Creds for bookmarks
- * @since 0.1
- * @version 1.3
- */
- add_action( 'mycred_load_hooks', 'mycred_load_bookmark_hook', 40 );
- function mycred_load_bookmark_hook() {
- // myCRED Custom Hook Class
- class myCRED_BP_Bookmarks extends myCRED_Hook {
- /**
- * Construct
- */
- function __construct( $hook_prefs, $type = 'mycred_default' ) {
- parent::__construct( array(
- 'id' => 'hook_bookmark',
- 'defaults' => array(
- 'bookmark' => array(
- 'creds' => 1,
- 'log' => '%plural% for bookmarking a site',
- 'limit' => '0/x'
- )
- )
- ), $hook_prefs, $type );
- }
- /**
- * Run
- * @since 0.1
- * @version 1.0
- */
- public function run() {
- if ( $this->prefs['bookmark']['creds'] != 0 )
- add_action( 'bp_activity_bookmark_published', array( $this, 'bookmarks' ), 10, 3 );
- }
- /**
- * New Bookmark
- * @since 0.1
- * @version 1.2
- */
- public function new_bookmark( $content, $user_id, $activity_id ) {
- // Check if user is excluded
- if ( $this->core->exclude_user( $user_id ) ) return;
- // Limit
- if ( $this->over_hook_limit( 'bookmark', 'new_bookmark', $user_id ) ) return;
- // Make sure this is unique event
- if ( $this->core->has_entry( 'new_bookmark', $activity_id, $user_id ) ) return;
- // Execute
- $this->core->add_creds(
- 'new_bookmark',
- $user_id,
- $this->prefs['bookmark']['creds'],
- $this->prefs['bookmark']['log'],
- $activity_id,
- 'bp_activity',
- $this->mycred_type
- );
- }
- /**
- * Preferences
- * @since 0.1
- * @version 1.2
- */
- public function preferences() {
- $prefs = $this->prefs;
- ?>
- <!-- Creds for Bookmark -->
- <label for="<?php echo $this->field_id( array( 'bookmark', 'creds' ) ); ?>" class="subheader"><?php _e( 'New Bookmark', 'mycred' ); ?></label>
- <ol>
- <li>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'bookmark', 'creds' ) ); ?>" id="<?php echo $this->field_id( array( 'bookmark', 'creds' ) ); ?>" value="<?php echo $this->core->number( $prefs['bookmark']['creds'] ); ?>" size="8" /></div>
- </li>
- <li>
- <label for="<?php echo $this->field_id( array( 'bookmark', 'limit' ) ); ?>"><?php _e( 'Limit', 'mycred' ); ?></label>
- <?php echo $this->hook_limit_setting( $this->field_name( array( 'bookmark', 'limit' ) ), $this->field_id( array( 'bookmark', 'limit' ) ), $prefs['bookmark']['limit'] ); ?>
- </li>
- <li class="empty"> </li>
- <li>
- <label for="<?php echo $this->field_id( array( 'bookmark', 'log' ) ); ?>"><?php _e( 'Log template', 'mycred' ); ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'bookmark', 'log' ) ); ?>" id="<?php echo $this->field_id( array( 'bookmark', 'log' ) ); ?>" value="<?php echo esc_attr( $prefs['bookmark']['log'] ); ?>" class="long" /></div>
- <span class="description"><?php echo $this->available_template_tags( array( 'general' ) ); ?></span>
- </li>
- </ol>
- <?php
- }
- /**
- * Sanitise Preferences
- * @since 1.6
- * @version 1.1
- */
- function sanitise_preferences( $data ) {
- if ( isset( $data['bookmark']['limit'] ) && isset( $data['bookmark']['limit_by'] ) ) {
- $limit = sanitize_text_field( $data['bookmark']['limit'] );
- if ( $limit == '' ) $limit = 0;
- $data['bookmark']['limit'] = $limit . '/' . $data['bookmark']['limit_by'];
- unset( $data['bookmark']['limit_by'] );
- }
- return $data;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement