Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Register Hook
- * @since 0.1
- * @version 1.0.1
- */
- add_action( 'mycred_setup_hooks', 'mycredpro_register_bp_bookmarklet_hook', 40 );
- function mycredpro_register_bp_bookmarklet_hook( $installed ) {
- $installed['bpbookmarklet'] = array(
- 'title' => __( 'BP-Bookmarklet Plugin for Profile', 'mycred' ),
- 'description' => __( 'Awards %_plural% for bookmarking a site in profile.', 'mycred' ),
- 'callback' => array( 'myCRED_Hook_BP_Bookmarklet' )
- );
- return $installed;
- }
- /**
- * BP Bookmarklet Hook
- * @since 0.1
- * @version 1.7
- */
- add_action( 'mycred_load_hooks', 'mycredpro_load_bp_bookmarklet_mycred_hook', 40 );
- function mycredpro_load_bp_bookmarklet_mycred_hook() {
- class myCRED_Hook_BP_Bookmarklet extends myCRED_Hook {
- /**
- * Construct Hook
- */
- function __construct( $hook_prefs, $type = MYCRED_DEFAULT_TYPE_KEY ) {
- parent::__construct( array(
- 'id' => 'bpbookmarklet',
- 'defaults' => array(
- 'creds' => 1,
- 'log' => '%plural% for bookmarking a site in profile',
- 'limit' => '0/x'
- */
- public function run() {
- if ( $this->prefs['bookmarks']['creds'] != 0 )
- add_action( 'bp_bookmarklet_format_activity_action_published', array( $this, 'bookmark_published' ), 10, 2 );
- }
- /**
- * Bookmark Published
- * @since 0.1
- * @version 1.2
- */
- public function bookmark_published( $content, $user_id ) {
- // Check if user is excluded
- if ( $this->core->exclude_user( $user_id ) ) return;
- // Limit
- if ( $this->over_hook_limit( '', 'new_bookmarking_site', $user_id ) ) return;
- // Execute
- $this->core->add_creds(
- 'new_bookmarking_site',
- $user_id,
- $this->prefs['creds'],
- $this->prefs['log'],
- 0,
- 'bp_activity',
- $this->mycred_type
- );
- }
- /**
- * Preferences
- * @since 0.1
- * @version 1.1
- */
- public function preferences() {
- $prefs = $this->prefs;?>
- <!-- Creds for bookmarking sites -->
- <label for="<?php echo $this->field_id( 'creds' ); ?>" class="subheader"><?php echo $this->core->template_tags_general( __( '%plural% for Bookmarking a Site in Profile', 'mycred' ) ); ?></label>
- <ol>
- <li>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( 'creds' ); ?>" id="<?php echo $this->field_id( array( 'bookmarks', 'creds' ) ); ?>" value="<?php echo $this->core->number( $prefs['creds'] ); ?>" size="8" /></div>
- </li>
- </ol>
- <ol>
- <li>
- <label for="<?php echo $this->field_id( 'limit' ); ?>"><?php _e( 'Limit', 'mycred' ); ?></label>
- <?php echo $this->hook_limit_setting( $this->field_name( 'limit' ), $this->field_id( 'limit' ), $prefs['limit'] ); ?>
- </li>
- </ol>
- <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 esc_attr( $prefs['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['limit'] ) && isset( $data['limit_by'] ) ) {
- $limit = sanitize_text_field( $data['limit'] );
- if ( $limit == '' ) $limit = 0;
- $data['limit'] = $limit . '/' . $data['limit_by'];
- unset( $data['limit_by'] );
- }
- return $data;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement