From 8bfe00907b2bac3fe04546b06b512810da231ca2 Mon Sep 17 00:00:00 2001 From: Giri Dhar Date: Thu, 21 Jul 2016 18:41:56 +0530 Subject: [PATCH] Send compliment button can be displayed in /members page - ADDED --- change_log.txt | 4 +++ includes/bp-compliments-activity.php | 33 ++++++++++++++++-------- includes/bp-compliments-forms.php | 26 ++++++++++++++++--- includes/bp-compliments-settings.php | 13 ++++++++++ includes/bp-compliments-templatetags.php | 22 +++++++++++++++- 5 files changed, 82 insertions(+), 16 deletions(-) diff --git a/change_log.txt b/change_log.txt index 96aafec..18734a7 100644 --- a/change_log.txt +++ b/change_log.txt @@ -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 diff --git a/includes/bp-compliments-activity.php b/includes/bp-compliments-activity.php index 1f3ce8b..2c06a51 100644 --- a/includes/bp-compliments-activity.php +++ b/includes/bp-compliments-activity.php @@ -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') { @@ -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') { diff --git a/includes/bp-compliments-forms.php b/includes/bp-compliments-forms.php index a6328c1..3ad215f 100644 --- a/includes/bp-compliments-forms.php +++ b/includes/bp-compliments-forms.php @@ -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(); } ?> @@ -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(); } @@ -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"); ?> @@ -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': '' + 'bp_compliments_nonce': '', + 'btn_id': btn_id }; jQuery.post('', data, function (response) { diff --git a/includes/bp-compliments-settings.php b/includes/bp-compliments-settings.php index 8fa066a..5d89408 100644 --- a/includes/bp-compliments-settings.php +++ b/includes/bp-compliments-settings.php @@ -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' ); @@ -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'; @@ -82,6 +86,15 @@ function bp_compliments_settings_page() { + + + + + + diff --git a/includes/bp-compliments-templatetags.php b/includes/bp-compliments-templatetags.php index 78be3c2..c064cfb 100644 --- a/includes/bp-compliments-templatetags.php +++ b/includes/bp-compliments-templatetags.php @@ -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'] ) ); -} \ No newline at end of file +} + +/** + * 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' ); \ No newline at end of file