Skip to content

Commit

Permalink
Merge pull request #20 from GeoDirectory/master
Browse files Browse the repository at this point in the history
Merge from master
  • Loading branch information
kprajapatii authored Nov 25, 2016
2 parents 617ccc6 + 9849f74 commit ac59de0
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
2 changes: 2 additions & 0 deletions change_log.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Option added to remove plugin data on plugin delete - ADDED
Email headers changed from string to array() and MIME-Version removed - CHANGED
Compliment not displaying content in activity page - FIXED
Filter added to prevent duplicate compliments - ADDED
Compliment can be redirected to individual compliment page after send - ADDED
Compliment can be redirected to individual compliment from notifications - ADDED

v1.0.6
Notification incorrect from email - FIXED
Expand Down
16 changes: 12 additions & 4 deletions includes/bp-compliments-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function handle_compliments_form_data() {
return;
}


$insert_id = false;
$term_id = strip_tags($_POST['term_id']);
// post id is required for geodirectory's whoop theme.
$post_id = strip_tags($_POST['post_id']);
Expand Down Expand Up @@ -55,14 +55,16 @@ function handle_compliments_form_data() {
if ($count != 0) {
bp_core_add_message( __( 'Duplicate compliment detected.', 'bp-compliments' ), 'error' );
} else {
if ( ! bp_compliments_start_compliment($args)) {
$insert_id = bp_compliments_start_compliment($args);
if ( ! $insert_id) {
bp_core_add_message( sprintf( __( 'There was a problem when trying to send %s to %s, please contact administrator.', 'bp-compliments' ), strtolower(BP_COMP_SINGULAR_NAME), $receiver_name ), 'error' );
} else {
bp_core_add_message( sprintf( __( 'Your %s sent to %s.', 'bp-compliments' ), BP_COMP_SINGULAR_NAME, $receiver_name ) );
}
}
} else {
if ( ! bp_compliments_start_compliment($args)) {
$insert_id = bp_compliments_start_compliment($args);
if ( ! $insert_id) {
bp_core_add_message( sprintf( __( 'There was a problem when trying to send %s to %s, please contact administrator.', 'bp-compliments' ), strtolower(BP_COMP_SINGULAR_NAME), $receiver_name ), 'error' );
} else {
bp_core_add_message( sprintf( __( 'Your %s sent to %s.', 'bp-compliments' ), BP_COMP_SINGULAR_NAME, $receiver_name ) );
Expand Down Expand Up @@ -94,7 +96,13 @@ function handle_compliments_form_data() {
}

if ($show_for_displayed_user) {
$redirect = $redirect_url.BP_COMPLIMENTS_SLUG.'/';
$redirect_to_single_comp = apply_filters('redirect_to_single_comp', false);
if ($insert_id && $redirect_to_single_comp) {
$redirect = $redirect_url.BP_COMPLIMENTS_SLUG.'/?c_id='.$insert_id;
} else {
$redirect = $redirect_url.BP_COMPLIMENTS_SLUG.'/';
}

} else {
$redirect = $redirect_url;
}
Expand Down
1 change: 1 addition & 0 deletions includes/bp-compliments-activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ function compliments_merge_filter( $filters, $context ){
}
add_filter('bp_get_activity_show_filters_options', 'compliments_merge_filter', 10, 2);

add_filter('compliments_format_activity_action_compliment_sent', 'bp_comp_add_compliment_received_content', 10, 2);
add_filter('compliments_format_activity_action_compliment_received', 'bp_comp_add_compliment_received_content', 10, 2);
function bp_comp_add_compliment_received_content($action, $activity) {

Expand Down
2 changes: 1 addition & 1 deletion includes/bp-compliments-classes.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function save() {
*/
do_action_ref_array( 'bp_compliments_after_save', array( &$this ) );

return $result;
return $wpdb->insert_id;
}

/**
Expand Down
7 changes: 5 additions & 2 deletions includes/bp-compliments-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ function bp_compliments_start_compliment( $args = '' ) {

$compliment = new BP_Compliments( $r['receiver_id'], $r['sender_id'], $r['term_id'], $r['post_id'], $r['message'] );

if ( ! $compliment->save() ) {
$insert_id = $compliment->save();
if ( ! $insert_id ) {
return false;
}

// Add compliment ID
$compliment->id = $insert_id;
/**
* Functions hooked to this action will be processed after compliments data stored into the db.
*
Expand All @@ -52,7 +55,7 @@ function bp_compliments_start_compliment( $args = '' ) {
*/
do_action_ref_array( 'bp_compliments_start_compliment', array( &$compliment ) );

return true;
return $insert_id;
}

/**
Expand Down
18 changes: 16 additions & 2 deletions includes/bp-compliments-notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ function bp_compliments_format_notifications( $action, $item_id, $secondary_item

if ( 1 == $total_items ) {
$text = sprintf( __( '%s has sent you a %s', 'bp-compliments' ), bp_core_get_user_displayname( $item_id ), BP_COMP_SINGULAR_NAME );
$link = bp_core_get_user_domain( $bp->loggedin_user->id ) .BP_COMPLIMENTS_SLUG. '/?bpc_read=true&bpc_sender_id='.$item_id;
if ($secondary_item_id) {
$link = bp_core_get_user_domain( $bp->loggedin_user->id ) .BP_COMPLIMENTS_SLUG. '/?c_id='.$secondary_item_id.'&bpc_read=true&bpc_sender_id='.$item_id;
} else {
$link = bp_core_get_user_domain( $bp->loggedin_user->id ) .BP_COMPLIMENTS_SLUG. '/?bpc_read=true&bpc_sender_id='.$item_id;
}
}
break;

Expand Down Expand Up @@ -121,6 +125,7 @@ function bp_compliments_notifications_add_on_compliment( BP_Compliments $complim
bp_notifications_add_notification( array(
'item_id' => $compliment->sender_id,
'user_id' => $compliment->receiver_id,
'secondary_item_id' => $compliment->id,
'component_name' => buddypress()->compliments->id,
'component_action' => 'new_compliment'
) );
Expand Down Expand Up @@ -347,6 +352,11 @@ function bp_compliments_notifications_mark_compliments_as_read() {
return;
}

$compliment_id = false;
if ( isset($_GET['c_id'])) {
$compliment_id = (int) strip_tags(esc_sql($_GET['c_id']));
}

$sender_id = (int) strip_tags(esc_sql($_GET['bpc_sender_id']));

if (!is_int($sender_id)) {
Expand All @@ -366,7 +376,11 @@ function bp_compliments_notifications_mark_compliments_as_read() {
bp_core_delete_notifications_by_item_id( bp_loggedin_user_id(), $sender_id, buddypress()->compliments->id, 'new_compliment' );
}
// Redirect
bp_core_redirect( bp_displayed_user_domain() . BP_COMPLIMENTS_SLUG . '/' );
if ($compliment_id) {
bp_core_redirect( bp_displayed_user_domain() . BP_COMPLIMENTS_SLUG . '/?c_id='.$compliment_id);
} else {
bp_core_redirect( bp_displayed_user_domain() . BP_COMPLIMENTS_SLUG . '/' );
}
}
add_action( 'bp_actions', 'bp_compliments_notifications_mark_compliments_as_read' );

Expand Down

0 comments on commit ac59de0

Please sign in to comment.