diff --git a/change_log.txt b/change_log.txt index 9f62887..9f2f28c 100644 --- a/change_log.txt +++ b/change_log.txt @@ -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 diff --git a/includes/bp-compliments-actions.php b/includes/bp-compliments-actions.php index 5bfe806..de9ba1b 100644 --- a/includes/bp-compliments-actions.php +++ b/includes/bp-compliments-actions.php @@ -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']); @@ -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 ) ); @@ -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; } diff --git a/includes/bp-compliments-classes.php b/includes/bp-compliments-classes.php index 719f642..183ab45 100644 --- a/includes/bp-compliments-classes.php +++ b/includes/bp-compliments-classes.php @@ -162,7 +162,7 @@ public function save() { */ do_action_ref_array( 'bp_compliments_after_save', array( &$this ) ); - return $result; + return $wpdb->insert_id; } /** diff --git a/includes/bp-compliments-functions.php b/includes/bp-compliments-functions.php index 882311d..f55fc5f 100644 --- a/includes/bp-compliments-functions.php +++ b/includes/bp-compliments-functions.php @@ -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. * @@ -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; } /** diff --git a/includes/bp-compliments-notifications.php b/includes/bp-compliments-notifications.php index 5093f2d..aeb6b7f 100644 --- a/includes/bp-compliments-notifications.php +++ b/includes/bp-compliments-notifications.php @@ -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; @@ -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' ) ); @@ -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)) { @@ -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' );