Skip to content

Commit

Permalink
Send compliment button can be displayed in /members page - ADDED
Browse files Browse the repository at this point in the history
  • Loading branch information
viruthagiri committed Jul 21, 2016
1 parent d3858b9 commit 8bfe009
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 16 deletions.
4 changes: 4 additions & 0 deletions change_log.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v1.0.7
Send compliment button can be displayed in /members page - ADDED
PHP undefined notices in wordpress admin - FIXED

v1.0.6
Notification incorrect from email - FIXED

Expand Down
33 changes: 22 additions & 11 deletions includes/bp-compliments-activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,20 @@ function compliments_format_activity_action_compliment_received( $action, $activ
$bp_compliment_can_see_others_comp_value = esc_attr( get_option('bp_compliment_can_see_others_comp'));
$bp_compliment_can_see_others_comp = $bp_compliment_can_see_others_comp_value ? $bp_compliment_can_see_others_comp_value : 'yes';

if ($bp_compliment_can_see_others_comp == 'members_choice') {
$bp_compliment_can_see_your_comp_value = esc_attr( get_user_meta($bp->displayed_user->id, 'bp_compliment_can_see_your_comp', true));
$bp_compliment_can_see_others_comp = $bp_compliment_can_see_your_comp_value ? $bp_compliment_can_see_your_comp_value : 'yes';
}

if (bp_is_user() && ($bp->loggedin_user->id == $bp->displayed_user->id)) {
if (current_user_can('manage_options')) {
$bp_compliment_can_see_others_comp = 'yes';
} else {
if ($bp_compliment_can_see_others_comp == 'members_choice') {
$bp_compliment_can_see_your_comp_value = esc_attr( get_user_meta($bp->displayed_user->id, 'bp_compliment_can_see_your_comp', true));
$bp_compliment_can_see_others_comp = $bp_compliment_can_see_your_comp_value ? $bp_compliment_can_see_your_comp_value : 'yes';
}

if (bp_is_user() && ($bp->loggedin_user->id == $bp->displayed_user->id)) {
$bp_compliment_can_see_others_comp = 'yes';
}
}


if ($bp_compliment_can_see_others_comp == 'yes') {
$action = sprintf( __( '%1$s has received a %2$s from %3$s', 'bp-compliments' ), $receiver_link, $compliment_link, $sender_link );
} elseif ($bp_compliment_can_see_others_comp == 'members_only') {
Expand Down Expand Up @@ -205,15 +210,21 @@ function compliments_format_activity_action_compliment_sent( $action, $activity
$bp_compliment_can_see_others_comp_value = esc_attr( get_option('bp_compliment_can_see_others_comp'));
$bp_compliment_can_see_others_comp = $bp_compliment_can_see_others_comp_value ? $bp_compliment_can_see_others_comp_value : 'yes';

if ($bp_compliment_can_see_others_comp == 'members_choice') {
$bp_compliment_can_see_your_comp_value = esc_attr( get_user_meta($bp->displayed_user->id, 'bp_compliment_can_see_your_comp', true));
$bp_compliment_can_see_others_comp = $bp_compliment_can_see_your_comp_value ? $bp_compliment_can_see_your_comp_value : 'yes';
}

if (bp_is_user() && ($bp->loggedin_user->id == $bp->displayed_user->id)) {
if (current_user_can('manage_options')) {
$bp_compliment_can_see_others_comp = 'yes';
} else {
if ($bp_compliment_can_see_others_comp == 'members_choice') {
$bp_compliment_can_see_your_comp_value = esc_attr( get_user_meta($bp->displayed_user->id, 'bp_compliment_can_see_your_comp', true));
$bp_compliment_can_see_others_comp = $bp_compliment_can_see_your_comp_value ? $bp_compliment_can_see_your_comp_value : 'yes';
}

if (bp_is_user() && ($bp->loggedin_user->id == $bp->displayed_user->id)) {
$bp_compliment_can_see_others_comp = 'yes';
}
}


if ($bp_compliment_can_see_others_comp == 'yes') {
$action = sprintf( __( '%1$s has sent a %2$s to %3$s', 'bp-compliments' ), $sender_link, $compliment_link, $receiver_link );
} elseif ($bp_compliment_can_see_others_comp == 'members_only') {
Expand Down
26 changes: 22 additions & 4 deletions includes/bp-compliments-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @param int $receiver_id Compliment receiver ID.
*/
function bp_compliments_modal_form($pid = 0, $receiver_id = 0 ) {
if (!$receiver_id && bp_displayed_user_id()) {
if (!$receiver_id) {
$receiver_id = bp_displayed_user_id();
}
?>
Expand Down Expand Up @@ -95,7 +95,18 @@ function bp_compliments_modal_form($pid = 0, $receiver_id = 0 ) {
function bp_compliments_modal_ajax()
{
check_ajax_referer('bp-compliments-nonce', 'bp_compliments_nonce');
bp_compliments_modal_form();

//Get the receiver id
$btn_id = strip_tags($_POST["btn_id"]);
if ($btn_id && (strpos($btn_id, '-') !== false)) {
$btn_id = explode("-", $btn_id);
$btn_id = (int) $btn_id[1];
}

if (empty($btn_id)) {
$btn_id = 0;
}
bp_compliments_modal_form(0, $btn_id);

wp_die();
}
Expand All @@ -112,9 +123,14 @@ function bp_compliments_modal_ajax()
* @package BuddyPress_Compliments
*/
function bp_compliments_modal_init() {
if (!bp_is_user() || !is_user_logged_in()){
if (!is_user_logged_in()){
return;
}

if (!bp_is_user() && !bp_is_directory()){
return;
}

$ajax_nonce = wp_create_nonce("bp-compliments-nonce");
?>
<div id="bp_compliments_modal_shadow" style="display: none;"></div>
Expand All @@ -131,11 +147,13 @@ function bp_compliments_modal_init() {
e.preventDefault();
var mod_shadow = jQuery('#bp_compliments_modal_shadow');
var container = jQuery('.comp-modal');
var btn_id = jQuery(this).attr('id');
mod_shadow.show();
container.show();
var data = {
'action': 'bp_compliments_modal_ajax',
'bp_compliments_nonce': '<?php echo $ajax_nonce; ?>'
'bp_compliments_nonce': '<?php echo $ajax_nonce; ?>',
'btn_id': btn_id
};

jQuery.post('<?php echo admin_url('admin-ajax.php'); ?>', data, function (response) {
Expand Down
13 changes: 13 additions & 0 deletions includes/bp-compliments-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function bp_compliments_register_settings() {
register_setting( 'bp-compliment-settings', 'bp_compliment_plural_name' );
register_setting( 'bp-compliment-settings', 'bp_compliment_slug' );
register_setting( 'bp-compliment-settings', 'bp_compliment_can_see_others_comp' );
register_setting( 'bp-compliment-settings', 'bp_compliment_member_dir_btn' );
register_setting( 'bp-compliment-settings', 'bp_compliment_can_delete' );
register_setting( 'bp-compliment-settings', 'bp_compliment_enable_activity' );
register_setting( 'bp-compliment-settings', 'bp_compliment_enable_notifications' );
Expand All @@ -43,6 +44,9 @@ function bp_compliments_settings_page() {
$bp_compliment_can_see_others_comp_value = esc_attr( get_option('bp_compliment_can_see_others_comp'));
$bp_compliment_can_see_others_comp = $bp_compliment_can_see_others_comp_value ? $bp_compliment_can_see_others_comp_value : 'yes';

$bp_compliment_member_dir_btn_value = esc_attr( get_option('bp_compliment_member_dir_btn'));
$bp_compliment_member_dir_btn = $bp_compliment_member_dir_btn_value ? $bp_compliment_member_dir_btn_value : 'no';

$bp_compliment_can_delete_value = esc_attr( get_option('bp_compliment_can_delete'));
$bp_compliment_can_delete = $bp_compliment_can_delete_value ? $bp_compliment_can_delete_value : 'yes';

Expand Down Expand Up @@ -82,6 +86,15 @@ function bp_compliments_settings_page() {
</select>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php echo sprintf( __( 'Display "Send %s" button in /members page?', 'bp-compliments' ), BP_COMP_SINGULAR_NAME ); ?></th>
<td>
<select id="bp_compliment_can_delete" name="bp_compliment_member_dir_btn">
<option value="yes" <?php selected( $bp_compliment_member_dir_btn, 'yes' ); ?>><?php echo __( 'Yes', 'bp-compliments' ); ?></option>
<option value="no" <?php selected( $bp_compliment_member_dir_btn, 'no' ); ?>><?php echo __( 'No', 'bp-compliments' ); ?></option>
</select>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php echo sprintf( __( 'Members can delete %s received?', 'bp-compliments' ), BP_COMP_PLURAL_NAME ); ?></th>
<td>
Expand Down
22 changes: 21 additions & 1 deletion includes/bp-compliments-templatetags.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,24 @@ function bp_compliments_get_compliments( $args = '' ) {
* @param bool|int $r['c_id'] The compliment ID.
*/
return apply_filters( 'bp_compliments_get_compliments', BP_Compliments::get_compliments( $r['user_id'], $r['offset'], $r['limit'], $r['c_id'] ) );
}
}

/**
* Add compliment button to the members page.
*
* @since 0.0.7
* @package BuddyPress_Compliments
*/
function bp_compliments_add_members_compliment_button() {
$bp_compliment_member_dir_btn_value = esc_attr( get_option('bp_compliment_member_dir_btn'));
$bp_compliment_member_dir_btn = $bp_compliment_member_dir_btn_value ? $bp_compliment_member_dir_btn_value : 'no';

if ($bp_compliment_member_dir_btn == 'yes') {
$args = array(
'receiver_id' => bp_get_member_user_id(),
'sender_id' => bp_loggedin_user_id()
);
bp_compliments_add_compliment_button($args);
}
}
add_action( 'bp_directory_members_actions', 'bp_compliments_add_members_compliment_button' );

0 comments on commit 8bfe009

Please sign in to comment.