Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Register Hook
- * @since 0.1
- * @version 1.0
- */
- add_filter( 'mycred_setup_hooks', 'mycred_hook_bp_checkins' );
- function mycred_hook_bp_checkins( $installed ) {
- // If the required plugin is installed
- if ( function_exists( 'bp_checkins_init' ) )
- $installed['bp_checkins'] = array(
- 'title' => __( 'BP Checkins', 'mycred' ),
- 'description' => __( 'Awards %_plural% to users who checking to places on your website.', 'mycred' ),
- 'callback' => array( 'myCRED_BP_Checkins' )
- );
- return $installed;
- }
- /**
- * BP Checkins
- * @since 0.1
- * @version 1.0
- */
- if ( class_exists( 'myCRED_Hook' ) && ! class_exists( 'myCRED_BP_Checkins' ) ) {
- class myCRED_BP_Checkins extends myCRED_Hook {
- /**
- * Construct
- */
- function __construct( $hook_prefs ) {
- parent::__construct( array(
- 'id' => 'bp_checkins',
- 'defaults' => array(
- 'checkin' => array(
- 'creds' => 0,
- 'log' => '%plural% for checkin',
- 'limit' => 0
- ),
- 'new_place' => array(
- 'creds' => 0,
- 'log' => '%plural% for new place',
- 'limit' => 0
- ),
- 'place_checkin' => array(
- 'creds' => 0,
- 'log' => '%plural% for checkin at place',
- 'limit' => 0
- ),
- 'place_comment' => array(
- 'creds' => 0,
- 'log' => '%plural% for place comment',
- 'limit' => 0
- ),
- 'place_checkin_comment' => array(
- 'creds' => 0,
- 'log' => '%plural% for place checkin comment',
- 'limit' => 0
- ),
- 'group_checkin' => array(
- 'creds' => 0,
- 'log' => '%plural% for group checkin',
- 'limit' => 0
- ),
- 'group_new_place' => array(
- 'creds' => 0,
- 'log' => '%plural% for new group place',
- 'limit' => 0
- ),
- 'group_place_checkin' => array(
- 'creds' => 0,
- 'log' => '%plural% for checkin at group place',
- 'limit' => 0
- ),
- 'group_place_comment' => array(
- 'creds' => 0,
- 'log' => '%plural% for group place comment',
- 'limit' => 0
- ),
- 'group_place_checkin_comment' => array(
- 'creds' => 0,
- 'log' => '%plural% for group place checkin comment',
- 'limit' => 0
- )
- )
- ), $hook_prefs );
- }
- /**
- * Run
- * @since 0.1
- * @version 1.0
- */
- public function run() {
- add_action( 'bp_activity_posted_checkin', array( $this, 'activity_checkin' ), 10, 3 );
- add_action( 'bp_groups_posted_checkin', array( $this, 'group_checkin' ), 10, 4 );
- }
- /**
- * Profile Checkin
- * @since 1.0
- * @version 1.0
- */
- public function activity_checkin( $content, $user_id, $activity_id ) {
- // Check if user is excluded
- if ( $this->core->exclude_user( $user_id ) ) return;
- // Get Activity
- $activity = bp_activity_get_specific( array( '' => $activity_id ) );
- if ( isset( $this->prefs[ $activity->type ]['creds'] ) && $this->prefs[ $activity->type ]['creds'] != 0 ) {
- $ref_id = $activity_id;
- if ( $activity->item_id !== false )
- $ref_id = $activity->item_id;
- // Make sure this is unique event
- if ( $this->core->has_entry( $activity->type, $user_id, $ref_id ) ) return;
- // Check if we are over the daily limit
- if ( $this->prefs[ $activity->type ]['limit'] > 0 ) {
- $earned = mycred_get_total_by_time( 'today', 'now', $activity->type, $user_id );
- $max = $this->core->number( $this->prefs[ $activity->type ]['limit'] * $this->prefs[ $activity->type ]['creds'] );
- if ( $earned <= $max ) return;
- }
- // Execute
- $this->core->add_creds(
- $activity->type,
- $user_id,
- $this->prefs[ $activity->type ]['creds'],
- $this->prefs[ $activity->type ]['log'],
- $ref_id
- );
- }
- }
- /**
- * Group Checkin
- * @since 1.0
- * @version 1.0
- */
- public function group_checkin( $content, $user_id, $group_id, $activity_id ) {
- // Check if user is excluded
- if ( $this->core->exclude_user( $user_id ) ) return;
- // Get Activity
- $activity = bp_activity_get_specific( array( '' => $activity_id ) );
- if ( isset( $this->prefs[ 'group_' . $activity->type ]['creds'] ) && $this->prefs[ 'group_' . $activity->type ]['creds'] != 0 ) {
- $ref_id = $activity_id;
- if ( $activity->item_id !== false )
- $ref_id = $activity->item_id;
- // Make sure this is unique event
- if ( $this->core->has_entry( 'group_' . $activity->type, $user_id, $ref_id ) ) return;
- // Check if we are over the daily limit
- if ( $this->prefs[ 'group_' . $activity->type ]['limit'] > 0 ) {
- $earned = mycred_get_total_by_time( 'today', 'now', 'group_' . $activity->type, $user_id );
- $max = $this->core->number( $this->prefs[ 'group_' . $activity->type ]['limit'] * $this->prefs[ 'group_' . $activity->type ]['creds'] );
- if ( $earned <= $max ) return;
- }
- // Execute
- $this->core->add_creds(
- $activity->component,
- $user_id,
- $this->prefs[ 'group_' . $activity->type ]['creds'],
- $this->prefs[ 'group_' . $activity->type ]['log'],
- $ref_id
- );
- }
- }
- /**
- * Preferences for Hook
- * @since 1.0
- * @version 1.0
- */
- public function preferences() {
- $prefs = $this->prefs;
- $creds_label = $this->core->plural();
- $log_label = __( 'Log template', 'mycred' );
- $limit_label = __( 'Daily Limit', 'mycred' );
- $limit_description = __( 'Optional daily limit to enforce. Use zero for unlimited.', 'mycred' );
- $available_tags = __( 'Available template tags: General.', 'mycred' );
- $available_tags_post = __( 'Available template tags: General and Post related (places).', 'mycred' ); ?>
- <label for="<?php echo $this->field_id( array( 'checkin', 'creds' ) ); ?>" class="subheader"><?php _e( 'Profile Checkin', 'mycred' ); ?></label>
- <ol>
- <li>
- <label for="<?php echo $this->field_id( array( 'checkin', 'creds' ) ); ?>"><?php echo $creds_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'checkin', 'creds' ) ); ?>" id="<?php echo $this->field_id( array( 'checkin', 'creds' ) ); ?>" value="<?php echo $this->core->number( $prefs['checkin']['creds'] ); ?>" size="8" /></div>
- </li>
- <li>
- <label for="<?php echo $this->field_id( array( 'checkin', 'log' ) ); ?>"><?php echo $log_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'checkin', 'log' ) ); ?>" id="<?php echo $this->field_id( array( 'checkin', 'log' ) ); ?>" value="<?php echo esc_attr( $prefs['checkin']['log'] ); ?>" class="long" /></div>
- <span class="description"><?php echo $available_tags; ?></span>
- </li>
- <li>
- <label for="<?php echo $this->field_id( array( 'checkin', 'limit' ) ); ?>"><?php echo $limit_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'checkin', 'limit' ) ); ?>" id="<?php echo $this->field_id( array( 'checkin', 'limit' ) ); ?>" value="<?php echo $this->core->number( $prefs['checkin']['limit'] ); ?>" size="8" /> <?php _e( '/ day', 'mycred' ); ?></div>
- <span class="description"><?php echo $limit_description; ?></span>
- </li>
- </ol>
- <label for="<?php echo $this->field_id( array( 'new_place', 'creds' ) ); ?>" class="subheader"><?php _e( 'New Place', 'mycred' ); ?></label>
- <ol>
- <li>
- <label for="<?php echo $this->field_id( array( 'new_place', 'creds' ) ); ?>"><?php echo $creds_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'new_place', 'creds' ) ); ?>" id="<?php echo $this->field_id( array( 'new_place', 'creds' ) ); ?>" value="<?php echo $this->core->number( $prefs['new_place']['creds'] ); ?>" size="8" /></div>
- </li>
- <li>
- <label for="<?php echo $this->field_id( array( 'new_place', 'log' ) ); ?>"><?php echo $log_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'new_place', 'log' ) ); ?>" id="<?php echo $this->field_id( array( 'new_place', 'log' ) ); ?>" value="<?php echo esc_attr( $prefs['new_place']['log'] ); ?>" class="long" /></div>
- <span class="description"><?php echo $available_tags_post; ?></span>
- </li>
- <li>
- <label for="<?php echo $this->field_id( array( 'new_place', 'limit' ) ); ?>"><?php echo $limit_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'new_place', 'limit' ) ); ?>" id="<?php echo $this->field_id( array( 'new_place', 'limit' ) ); ?>" value="<?php echo $this->core->number( $prefs['new_place']['limit'] ); ?>" size="8" /> <?php _e( '/ day', 'mycred' ); ?></div>
- <span class="description"><?php echo $limit_description; ?></span>
- </li>
- </ol>
- <label for="<?php echo $this->field_id( array( 'place_checkin', 'creds' ) ); ?>" class="subheader"><?php _e( 'Place Checkin', 'mycred' ); ?></label>
- <ol>
- <li>
- <label for="<?php echo $this->field_id( array( 'place_checkin', 'creds' ) ); ?>"><?php echo $creds_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'place_checkin', 'creds' ) ); ?>" id="<?php echo $this->field_id( array( 'place_checkin', 'creds' ) ); ?>" value="<?php echo $this->core->number( $prefs['place_checkin']['creds'] ); ?>" size="8" /></div>
- </li>
- <li>
- <label for="<?php echo $this->field_id( array( 'place_checkin', 'log' ) ); ?>"><?php echo $log_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'place_checkin', 'log' ) ); ?>" id="<?php echo $this->field_id( array( 'place_checkin', 'log' ) ); ?>" value="<?php echo esc_attr( $prefs['place_checkin']['log'] ); ?>" class="long" /></div>
- <span class="description"><?php echo $available_tags_post; ?></span>
- </li>
- <li>
- <label for="<?php echo $this->field_id( array( 'place_checkin', 'limit' ) ); ?>"><?php echo $limit_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'place_checkin', 'limit' ) ); ?>" id="<?php echo $this->field_id( array( 'place_checkin', 'limit' ) ); ?>" value="<?php echo $this->core->number( $prefs['place_checkin']['limit'] ); ?>" size="8" /> <?php _e( '/ day', 'mycred' ); ?></div>
- <span class="description"><?php echo $limit_description; ?></span>
- </li>
- </ol>
- <label for="<?php echo $this->field_id( array( 'place_comment', 'creds' ) ); ?>" class="subheader"><?php _e( 'Place Comment', 'mycred' ); ?></label>
- <ol>
- <li>
- <label for="<?php echo $this->field_id( array( 'place_comment', 'creds' ) ); ?>"><?php echo $creds_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'place_comment', 'creds' ) ); ?>" id="<?php echo $this->field_id( array( 'place_comment', 'creds' ) ); ?>" value="<?php echo $this->core->number( $prefs['place_comment']['creds'] ); ?>" size="8" /></div>
- </li>
- <li>
- <label for="<?php echo $this->field_id( array( 'place_comment', 'log' ) ); ?>"><?php echo $log_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'place_comment', 'log' ) ); ?>" id="<?php echo $this->field_id( array( 'place_comment', 'log' ) ); ?>" value="<?php echo esc_attr( $prefs['place_comment']['log'] ); ?>" class="long" /></div>
- <span class="description"><?php echo $available_tags_post; ?></span>
- </li>
- <li>
- <label for="<?php echo $this->field_id( array( 'place_comment', 'limit' ) ); ?>"><?php echo $limit_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'place_comment', 'limit' ) ); ?>" id="<?php echo $this->field_id( array( 'place_comment', 'limit' ) ); ?>" value="<?php echo $this->core->number( $prefs['place_comment']['limit'] ); ?>" size="8" /> <?php _e( '/ day', 'mycred' ); ?></div>
- <span class="description"><?php $limit_description; ?></span>
- </li>
- </ol>
- <label for="<?php echo $this->field_id( array( 'place_checkin_comment', 'creds' ) ); ?>" class="subheader"><?php _e( 'Place Checkin Comment', 'mycred' ); ?></label>
- <ol>
- <li>
- <label for="<?php echo $this->field_id( array( 'place_checkin_comment', 'creds' ) ); ?>"><?php echo $creds_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'place_checkin_comment', 'creds' ) ); ?>" id="<?php echo $this->field_id( array( 'place_checkin_comment', 'creds' ) ); ?>" value="<?php echo $this->core->number( $prefs['place_checkin_comment']['creds'] ); ?>" size="8" /></div>
- </li>
- <li>
- <label for="<?php echo $this->field_id( array( 'place_checkin_comment', 'log' ) ); ?>"><?php echo $log_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'place_checkin_comment', 'log' ) ); ?>" id="<?php echo $this->field_id( array( 'place_checkin_comment', 'log' ) ); ?>" value="<?php echo esc_attr( $prefs['place_checkin_comment']['log'] ); ?>" class="long" /></div>
- <span class="description"><?php echo $available_tags_post; ?></span>
- </li>
- <li>
- <label for="<?php echo $this->field_id( array( 'place_checkin_comment', 'limit' ) ); ?>"><?php echo $limit_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'place_checkin_comment', 'limit' ) ); ?>" id="<?php echo $this->field_id( array( 'place_checkin_comment', 'limit' ) ); ?>" value="<?php echo $this->core->number( $prefs['place_checkin_comment']['limit'] ); ?>" size="8" /> <?php _e( '/ day', 'mycred' ); ?></div>
- <span class="description"><?php echo $limit_description; ?></span>
- </li>
- </ol>
- <label for="<?php echo $this->field_id( array( 'group_checkin', 'creds' ) ); ?>" class="subheader"><?php _e( 'Group Profile Checkin', 'mycred' ); ?></label>
- <ol>
- <li>
- <label for="<?php echo $this->field_id( array( 'group_checkin', 'creds' ) ); ?>"><?php echo $creds_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'group_checkin', 'creds' ) ); ?>" id="<?php echo $this->field_id( array( 'group_checkin', 'creds' ) ); ?>" value="<?php echo $this->core->number( $prefs['group_checkin']['creds'] ); ?>" size="8" /></div>
- </li>
- <li>
- <label for="<?php echo $this->field_id( array( 'group_checkin', 'log' ) ); ?>"><?php echo $log_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'group_checkin', 'log' ) ); ?>" id="<?php echo $this->field_id( array( 'group_checkin', 'log' ) ); ?>" value="<?php echo esc_attr( $prefs['group_checkin']['log'] ); ?>" class="long" /></div>
- <span class="description"><?php echo $available_tags; ?></span>
- </li>
- <li>
- <label for="<?php echo $this->field_id( array( 'group_checkin', 'limit' ) ); ?>"><?php echo $limit_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'group_checkin', 'limit' ) ); ?>" id="<?php echo $this->field_id( array( 'group_checkin', 'limit' ) ); ?>" value="<?php echo $this->core->number( $prefs['group_checkin']['limit'] ); ?>" size="8" /> <?php _e( '/ day', 'mycred' ); ?></div>
- <span class="description"><?php echo $limit_description; ?></span>
- </li>
- </ol>
- <label for="<?php echo $this->field_id( array( 'group_new_place', 'creds' ) ); ?>" class="subheader"><?php _e( 'Group New Place', 'mycred' ); ?></label>
- <ol>
- <li>
- <label for="<?php echo $this->field_id( array( 'group_new_place', 'creds' ) ); ?>"><?php echo $creds_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'group_new_place', 'creds' ) ); ?>" id="<?php echo $this->field_id( array( 'group_new_place', 'creds' ) ); ?>" value="<?php echo $this->core->number( $prefs['group_new_place']['creds'] ); ?>" size="8" /></div>
- </li>
- <li>
- <label for="<?php echo $this->field_id( array( 'group_new_place', 'log' ) ); ?>"><?php echo $log_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'group_new_place', 'log' ) ); ?>" id="<?php echo $this->field_id( array( 'group_new_place', 'log' ) ); ?>" value="<?php echo esc_attr( $prefs['group_new_place']['log'] ); ?>" class="long" /></div>
- <span class="description"><?php echo $available_tags_post; ?></span>
- </li>
- <li>
- <label for="<?php echo $this->field_id( array( 'group_new_place', 'limit' ) ); ?>"><?php echo $limit_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'group_new_place', 'limit' ) ); ?>" id="<?php echo $this->field_id( array( 'group_new_place', 'limit' ) ); ?>" value="<?php echo $this->core->number( $prefs['group_new_place']['limit'] ); ?>" size="8" /> <?php _e( '/ day', 'mycred' ); ?></div>
- <span class="description"><?php echo $limit_description; ?></span>
- </li>
- </ol>
- <label for="<?php echo $this->field_id( array( 'group_place_checkin', 'creds' ) ); ?>" class="subheader"><?php _e( 'Group Place Checkin', 'mycred' ); ?></label>
- <ol>
- <li>
- <label for="<?php echo $this->field_id( array( 'group_place_checkin', 'creds' ) ); ?>"><?php echo $creds_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'group_place_checkin', 'creds' ) ); ?>" id="<?php echo $this->field_id( array( 'group_place_checkin', 'creds' ) ); ?>" value="<?php echo $this->core->number( $prefs['group_place_checkin']['creds'] ); ?>" size="8" /></div>
- </li>
- <li>
- <label for="<?php echo $this->field_id( array( 'group_place_checkin', 'log' ) ); ?>"><?php echo $log_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'group_place_checkin', 'log' ) ); ?>" id="<?php echo $this->field_id( array( 'group_place_checkin', 'log' ) ); ?>" value="<?php echo esc_attr( $prefs['group_place_checkin']['log'] ); ?>" class="long" /></div>
- <span class="description"><?php echo $available_tags_post; ?></span>
- </li>
- <li>
- <label for="<?php echo $this->field_id( array( 'group_place_checkin', 'limit' ) ); ?>"><?php echo $limit_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'group_place_checkin', 'limit' ) ); ?>" id="<?php echo $this->field_id( array( 'group_place_checkin', 'limit' ) ); ?>" value="<?php echo $this->core->number( $prefs['group_place_checkin']['limit'] ); ?>" size="8" /> <?php _e( '/ day', 'mycred' ); ?></div>
- <span class="description"><?php echo $limit_description; ?></span>
- </li>
- </ol>
- <label for="<?php echo $this->field_id( array( 'group_place_comment', 'creds' ) ); ?>" class="subheader"><?php _e( 'Group Place Comment', 'mycred' ); ?></label>
- <ol>
- <li>
- <label for="<?php echo $this->field_id( array( 'group_place_comment', 'creds' ) ); ?>"><?php echo $creds_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'group_place_comment', 'creds' ) ); ?>" id="<?php echo $this->field_id( array( 'group_place_comment', 'creds' ) ); ?>" value="<?php echo $this->core->number( $prefs['group_place_comment']['creds'] ); ?>" size="8" /></div>
- </li>
- <li>
- <label for="<?php echo $this->field_id( array( 'group_place_comment', 'log' ) ); ?>"><?php echo $log_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'group_place_comment', 'log' ) ); ?>" id="<?php echo $this->field_id( array( 'group_place_comment', 'log' ) ); ?>" value="<?php echo esc_attr( $prefs['group_place_comment']['log'] ); ?>" class="long" /></div>
- <span class="description"><?php echo $available_tags_post; ?></span>
- </li>
- <li>
- <label for="<?php echo $this->field_id( array( 'group_place_comment', 'limit' ) ); ?>"><?php echo $limit_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'group_place_comment', 'limit' ) ); ?>" id="<?php echo $this->field_id( array( 'group_place_comment', 'limit' ) ); ?>" value="<?php echo $this->core->number( $prefs['group_place_comment']['limit'] ); ?>" size="8" /> <?php _e( '/ day', 'mycred' ); ?></div>
- <span class="description"><?php echo $limit_description; ?></span>
- </li>
- </ol>
- <label for="<?php echo $this->field_id( array( 'group_place_checkin_comment', 'creds' ) ); ?>" class="subheader"><?php _e( 'Group Place Checkin Comment', 'mycred' ); ?></label>
- <ol>
- <li>
- <label for="<?php echo $this->field_id( array( 'group_place_checkin_comment', 'creds' ) ); ?>"><?php echo $creds_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'group_place_checkin_comment', 'creds' ) ); ?>" id="<?php echo $this->field_id( array( 'group_place_checkin_comment', 'creds' ) ); ?>" value="<?php echo $this->core->number( $prefs['group_place_checkin_comment']['creds'] ); ?>" size="8" /></div>
- </li>
- <li>
- <label for="<?php echo $this->field_id( array( 'group_place_checkin_comment', 'log' ) ); ?>"><?php echo $log_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'group_place_checkin_comment', 'log' ) ); ?>" id="<?php echo $this->field_id( array( 'group_place_checkin_comment', 'log' ) ); ?>" value="<?php echo esc_attr( $prefs['group_place_checkin_comment']['log'] ); ?>" class="long" /></div>
- <span class="description"><?php echo $available_tags_post; ?></span>
- </li>
- <li>
- <label for="<?php echo $this->field_id( array( 'group_place_checkin_comment', 'limit' ) ); ?>"><?php echo $limit_label; ?></label>
- <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'group_place_checkin_comment', 'limit' ) ); ?>" id="<?php echo $this->field_id( array( 'group_place_checkin_comment', 'limit' ) ); ?>" value="<?php echo $this->core->number( $prefs['group_place_checkin_comment']['limit'] ); ?>" size="8" /> <?php _e( '/ day', 'mycred' ); ?></div>
- <span class="description"><?php echo $limit_description; ?></span>
- </li>
- </ol>
- <?php
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement