diff --git a/.gitignore b/.gitignore index 9f11b75..b9991e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ .idea/ + +/vendor/ diff --git a/bp-compliments-core.php b/bp-compliments-core.php index ddbc3b7..df0465e 100644 --- a/bp-compliments-core.php +++ b/bp-compliments-core.php @@ -229,6 +229,7 @@ public function enqueue_scripts() { wp_enqueue_script( 'bp-compliments-js', constant( 'BP_COMPLIMENTS_URL' ) . 'js/bp-compliments.js', array( 'jquery' ) ); wp_register_style( 'bp-compliments-css', constant( 'BP_COMPLIMENTS_URL' ) . 'css/bp-compliments.css' ); wp_enqueue_style( 'bp-compliments-css' ); + wp_enqueue_style( 'dashicons' ); } } diff --git a/bp-compliments.php b/bp-compliments.php index 7e1ffb4..9a212cf 100644 --- a/bp-compliments.php +++ b/bp-compliments.php @@ -8,22 +8,22 @@ * * @wordpress-plugin * Plugin Name: BuddyPress Compliments - * Plugin URI: http://wpgeodirectory.com/ + * Plugin URI: https://appwp.io/ * Description: Compliments module for BuddyPress. - * Version: 1.0.7 - * Author: GeoDirectory - * Author URI: http://wpgeodirectory.com + * Version: 1.0.9 + * Author: AyeCode Ltd + * Author URI: https://ayecode.io * Text Domain: bp-compliments * Domain Path: /languages * Requires at least: 3.1 - * Tested up to: 4.7 + * Tested up to: 5.2 */ // Exit if accessed directly if ( !defined( 'ABSPATH' ) ) exit; // Define the plugin version. -define( 'BP_COMPLIMENTS_VER', '1.0.7' ); +define( 'BP_COMPLIMENTS_VER', '1.0.9' ); /** * BuddyPress compliments text domain. @@ -65,19 +65,43 @@ function bp_compliments_init() { $table_prefix = apply_filters( 'bp_core_get_table_prefix', $wpdb->base_prefix ); ////define the plugin table. define( 'BP_COMPLIMENTS_TABLE', $table_prefix . 'bp_compliments' ); - + if( file_exists(BP_COMPLIMENTS_DIR . 'vendor/autoload.php' ) ){ + require_once( BP_COMPLIMENTS_DIR . 'vendor/autoload.php' ); + } // only supported in BP 1.5+ if ( version_compare( BP_VERSION, '1.3', '>' ) ) { require( constant( 'BP_COMPLIMENTS_DIR' ) . '/bp-compliments-core.php' ); - // show admin notice for users on BP 1.2.x } else { add_action( 'admin_notices', 'bp_compliments_older_version_notice' ); - return; } } add_action( 'bp_include', 'bp_compliments_init' ); +add_action( 'init', 'bp_compliments_plugin_init' ); +/** + * Hook into actions and filters on site init. + */ +function bp_compliments_plugin_init(){ + add_action( 'tgmpa_register', 'bp_compliments_require_plugins'); +} + +/** + * Add required plugin check. + */ +function bp_compliments_require_plugins(){ + $plugins = array( /* The array to install plugins */ ); + $plugins = array( + array( + 'name' => 'BuddPress', + 'slug' => 'buddypress', + 'required' => true, // this plugin is recommended + 'version' => '1.5' + ) + ); + $config = array( /* The array to configure TGM Plugin Activation */ ); + tgmpa( $plugins, $config ); +} /** * Creates Custom table for BuddyPress compliments. @@ -147,7 +171,10 @@ function bp_compliments_deactivate() { function bp_compliments_activation_redirect() { if ( get_option( 'bp_compliments_activation_redirect', false ) ) { delete_option( 'bp_compliments_activation_redirect' ); - wp_redirect( admin_url( 'admin.php?page=bp-compliment-settings' ) ); + if(class_exists('BuddyPress')){ + wp_redirect( admin_url( 'admin.php?page=bp-compliment-settings' ) ); + exit; + } } } @@ -172,19 +199,8 @@ function bp_compliments_localization() { } add_action( 'plugins_loaded', 'bp_compliments_localization' ); -add_action( 'admin_notices', 'bp_compliments_required_plugins_nag' ); -function bp_compliments_required_plugins_nag() { - // Check for BuddyPress - $class = "update-nag"; - $url = 'https://wordpress.org/plugins/buddypress/'; - $message = sprintf( wp_kses( __( 'BuddyPress Compliments requires BuddyPress plugin.', 'bp-compliments' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( $url ) ); - if(!class_exists('BuddyPress')){ - echo"

$message

"; - } -} - function bp_compliments_older_version_notice() { $older_version_notice = __( "Hey! BP Compliments requires BuddyPress 1.5 or higher.", 'bp-compliments' ); - + echo '

' . $older_version_notice . '

'; } \ No newline at end of file diff --git a/change_log.txt b/change_log.txt deleted file mode 100644 index 6177aaa..0000000 --- a/change_log.txt +++ /dev/null @@ -1,75 +0,0 @@ -v1.0.8 -Fix issue for plugin installation via WP-CLI - FIXED - -v1.0.7 -Send compliment button can be displayed in /members page - ADDED -PHP undefined notices in wordpress admin - FIXED -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 - -v1.0.5 -Email notifications not working - FIXED -Compliment line break and clickable support removed. Use filter to override - CHANGED - -v1.0.4 -Compliment user settings page - ADDED -Linebreaks are removed on compliment messages - FIXED -Compliments message links are clickable - ADDED - -v1.0.1 -Use singular name instead of slug name - FIXED -Admin can delete compliments - ADDED -404 page when deleting compliments - FIXED - -v1.0.0 -Compliment message uses slug name instead of singular name - FIXED -Send modal form not showing properly in mobile - FIXED - - -v0.0.9 -Changed textdomain from defined constant to a string - CHANGED -Added filters and actions for whoop theme compatibility - ADDED -Notification not showing properly - FIXED -Added support for member only compliment display - ADDED - -v0.0.8 -Option added to enable/disable activity component - ADDED -Option added to enable/disable notifications component - ADDED -Added placeholder text to message textarea - ADDED -Compliments in activity dropdown filter is ambiguous - FIXED -Undefined property ID notice - FIXED - -v0.0.7 -Compliments can be renamed to anything Ex: "Gifts" - ADDED - -v0.0.5 -404 error while sending compliments - FIXED - -v0.0.4 -Members can see other members compliment page? setting - ADDED - -v0.0.3 -Validation added when adding compliment, icon required - FIXED -Some strings are not translatable - FIXED -Docblocks added to all functions, filters and actions - ADDED -Members can delete compliments received? setting - ADDED -Number of Compliments to display per page setting - ADDED -Custom CSS styles setting - ADDED - -v0.0.2 -BP compliments now supports notification component - ADDED -Send compliment modal form z-index bug - FIXED -Compliment Icon upload form uses latest media uploader - CHANGED -BP compliments now supports activity component - ADDED -Translation support - ADDED -Compliments can be deleted by the receiver - ADDED - -v0.0.1 -Initial release - RELEASE diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..d7a2791 --- /dev/null +++ b/composer.json @@ -0,0 +1,17 @@ +{ + "name": "ayeCode/buddypress_compliments", + "description": "Compliments module for BuddyPress.", + "type": "project", + "require": { + "tgmpa/tgm-plugin-activation": "dev-master" + }, + "authors": [ + { + "name": "AyeCode", + "email": "contact@ayecode.io", + "homepage": "https://ayecode.io", + "role": "Developer" + } + ], + "minimum-stability": "dev" +} diff --git a/css/bp-compliments.css b/css/bp-compliments.css index ca15e0e..ca114b8 100644 --- a/css/bp-compliments.css +++ b/css/bp-compliments.css @@ -3,10 +3,12 @@ display: inline-block; font-size: 14px; } + .comp-form-ul li span img { border-radius: 4px; margin-bottom: 0 !important; } + .comp-form-ul { margin: -3px; display: block; @@ -15,6 +17,7 @@ text-align: left; padding: 0; } + .comp-form-ul li { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; @@ -28,15 +31,18 @@ padding: 0 3px; margin: 3px 0; } + .comp-form-ul li input[type="radio"] { box-sizing: border-box; padding: 0; margin-right: 5px; } + .comp-form-ul label { display: block; margin: 0 0 6px; } + .comp-modal { width: 400px; z-index: 1999; @@ -49,16 +55,19 @@ left: 35%; top: 20%; } + .comp-modal-content textarea { width: 100%; margin: 10px 0; } + @media only screen and (min-width: 661px) and (max-width: 1000px) { .comp-modal { left: 28%; top: 15%; } } + @media only screen and (max-width: 660px) { .comp-modal { left: 11%; @@ -66,6 +75,7 @@ top: 10%; } } + @media only screen and (max-width: 480px) { .comp-modal { width: 80%; @@ -73,6 +83,7 @@ top: 10%; } } + .comp-modal-content-wrap { position: relative; z-index: 6; @@ -80,6 +91,7 @@ background: #fff; border-radius: 6px; } + .comp-modal-title { margin: 0; background: #fff; @@ -87,65 +99,79 @@ border-bottom: 1px solid #b0b0b0; padding-bottom: 11px; } + .comp-modal-title h2 { margin: 0 20px 0 0; font-size: 18px; line-height: 1.33333em; - text-shadow: 0 1px 0 rgba(255,255,255,0.5); + text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5); font-weight: bold; } + .comp-modal-content, .comp-modal-title { padding: 12px 18px; } + .comp-user-ul { margin: 0; padding: 0; } + .comp-user img { margin-right: 10px !important; margin-bottom: 0 !important; } + .comp-user a { text-decoration: none; } -.comp-user-ul > li { + +.comp-user-ul>li { overflow: hidden; display: block; border-bottom: 1px solid #ccccc8; padding: 10px 5px; margin-left: 0; } + .gd-list-item-author.comp-user { padding-left: 0; } + .comp-user-message { width: 100%; float: left; } + .comp-user-header { overflow: hidden; margin-bottom: 10px; } + .comp-user-header img { border-radius: 4px; margin-bottom: 0 !important; } + .comp-user-header em { margin-left: 10px; font-size: 10px; font-style: normal; } + .comp-loading-icon { text-align: center; padding: 50px 0; } + .comp-close-x { cursor: pointer; position: absolute; right: 18px; top: 15px; } + #bp_compliments_modal_shadow { position: fixed; top: 0; @@ -156,21 +182,26 @@ background-color: #000; opacity: 0.5; } + .comp-user-avatar { float: left; } + .comp-username { display: block; text-align: center; margin-right: 10px; } + .comp-user-header img { margin-right: 5px; } + .bp-compliments-wrap .pagination a, .bp-compliments-wrap .pagination span { display: inline-block; } + .bp-comp-loading-icon { background-image: url("../images/loading.gif"); width: 32px; diff --git a/includes/bp-compliments-actions.php b/includes/bp-compliments-actions.php index de9ba1b..967b267 100644 --- a/includes/bp-compliments-actions.php +++ b/includes/bp-compliments-actions.php @@ -119,16 +119,12 @@ function handle_compliments_form_data() { * @package BuddyPress_Compliments */ function delete_single_complement() { + global $wpdb; + if (!bp_is_user()) { return; } - if (!current_user_can( 'manage_options' )) { - if ( bp_displayed_user_id() != bp_loggedin_user_id() ) { - return; - } - } - if (!isset($_GET['c_id']) OR !isset($_GET['action']) ) { return; } @@ -150,6 +146,31 @@ function delete_single_complement() { return; } + $table_name = BP_COMPLIMENTS_TABLE; + $sender_id = $wpdb->get_var( $wpdb->prepare( "SELECT sender_id FROM {$table_name} WHERE id = %d", $c_id ) ); + + //Admins can delete any complement + $current_user_can_delete = current_user_can( 'manage_options' ); + + //Complement sender and receiver can delete compliment if admin has allowed it + if( is_user_logged_in() ){ + + //Is this the receiver + if( bp_loggedin_user_id() == bp_displayed_user_id() ){ + $current_user_can_delete = true; + } + + //Is this the sender + if( bp_loggedin_user_id() == $sender_id ){ + $current_user_can_delete = true; + } + } + + if ( false == $current_user_can_delete ) { + return; + } + + /** * Functions hooked to this action will be processed before deleting the complement. * diff --git a/includes/bp-compliments-forms.php b/includes/bp-compliments-forms.php index 5dc9b16..6b13c57 100644 --- a/includes/bp-compliments-forms.php +++ b/includes/bp-compliments-forms.php @@ -22,6 +22,7 @@ function bp_compliments_modal_form($pid = 0, $receiver_id = 0 ) { ?>
+

@@ -56,29 +57,29 @@ function bp_compliments_modal_form($pid = 0, $receiver_id = 0 ) { ?> - +
- +
diff --git a/includes/bp-compliments-notifications.php b/includes/bp-compliments-notifications.php index aeb6b7f..5cc022f 100644 --- a/includes/bp-compliments-notifications.php +++ b/includes/bp-compliments-notifications.php @@ -44,14 +44,11 @@ function bp_compliments_format_notifications( $action, $item_id, $secondary_item case 'new_compliment': $link = false; $text = false; - - 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 ); - 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; - } + $text = sprintf( __( '%s has sent you a %s', 'bp-compliments' ), bp_core_get_user_displayname( $item_id ), BP_COMP_SINGULAR_NAME ); + 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; @@ -83,29 +80,56 @@ function bp_compliments_format_notifications( $action, $item_id, $secondary_item break; } - if ( ! $link || ! $text ) { - return false; - } - if ( 'string' == $format ) { - /** - * Filters the notification link. - * - * @since 0.0.1 - * @package BuddyPress_Compliments - * - * @param int $total_items Total items. - * @param string $link Notification URL. - * @param string $text Notification Text. - * @param int $item_id User ID. - * @param int $secondary_item_id Secondary Item ID. - */ - return apply_filters( 'bp_compliments_new_compliment_notification', '' . $text . '', $total_items, $link, $text, $item_id, $secondary_item_id ); - } else { - return apply_filters( 'bp_compliments_new_toolbar_compliment_notification', array( - 'link' => $link, - 'text' => $text - ), (int) $total_items, $item_id ); + if ( 1 == $total_items ) { + if ( 'string' == $format ) { + /** + * Filters the notification link. + * + * @since 0.0.1 + * @package BuddyPress_Compliments + * + * @param int $total_items Total items. + * @param string $link Notification URL. + * @param string $text Notification Text. + * @param int $item_id User ID. + * @param int $secondary_item_id Secondary Item ID. + */ + return apply_filters( 'bp_compliments_new_compliment_notification', + '' . $text . '', $total_items, + $link, $text, $item_id, $secondary_item_id ); + } else { + return apply_filters( 'bp_compliments_new_toolbar_compliment_notification', + array( + 'link' => $link, + 'text' => $text + ), (int) $total_items, $item_id ); + } + }else{ + $text = sprintf( __( 'You have %d new compliments', 'bp-compliments' ), $total_items ); + if ( 'string' == $format ) { + /** + * Filters the notification link. + * + * @since 0.0.1 + * @package BuddyPress_Compliments + * + * @param int $total_items Total items. + * @param string $link Notification URL. + * @param string $text Notification Text. + * @param int $item_id User ID. + * @param int $secondary_item_id Secondary Item ID. + */ + return apply_filters( 'bp_compliments_multiple_new_compliments_notification', + '' . $text . '', $total_items, + $link, $text, $item_id, $secondary_item_id ); + } else { + return apply_filters( 'bp_compliments_multiple_new_toolbar_compliments_notification', + array( + 'link' => $link, + 'text' => $text + ), (int) $total_items, $item_id ); + } } } diff --git a/includes/bp-compliments-templatetags.php b/includes/bp-compliments-templatetags.php index c064cfb..a3381d9 100644 --- a/includes/bp-compliments-templatetags.php +++ b/includes/bp-compliments-templatetags.php @@ -48,7 +48,7 @@ function bp_compliments_get_add_compliment_button( $args = '' ) { 'link_title' => '', 'wrapper_class' => '', 'link_class' => 'compliments-popup', - 'wrapper' => 'div' + 'wrapper' => 'li' ) ); if ( ! $r['receiver_id'] || ! $r['sender_id'] ) diff --git a/includes/templates/buddypress/members/single/compliments.php b/includes/templates/buddypress/members/single/compliments.php index acc5b90..ec2cbc4 100644 --- a/includes/templates/buddypress/members/single/compliments.php +++ b/includes/templates/buddypress/members/single/compliments.php @@ -98,7 +98,21 @@ class='preview-upload'/> $bp_compliment_can_delete = 'yes'; } - if (is_user_logged_in() && (($bp->loggedin_user->id == $bp->displayed_user->id) || current_user_can( 'manage_options' )) && ($bp_compliment_can_delete == 'yes')) { + //Admins can delete any complement + $current_user_can_delete = current_user_can( 'manage_options' ); + + //Complement sender and receiver can delete compliment if admin has allowed it + if( is_user_logged_in() ){ + //Is this the receiver + if( $bp->loggedin_user->id == $bp->displayed_user->id ){ + $current_user_can_delete = true; + } + //Is this the sender + if( $bp->loggedin_user->id == $comp->sender_id ){ + $current_user_can_delete = true; + } + } + if ( $current_user_can_delete && ($bp_compliment_can_delete == 'yes')) { $receiver_url = bp_core_get_userlink( $comp->receiver_id, false, true ); $compliment_url = $receiver_url . BP_COMPLIMENTS_SLUG . '/?c_id='.$comp->id.'&action=delete'; ?> diff --git a/languages/bp-compliments-en_US.mo b/languages/bp-compliments-en_US.mo index 4282339..4cfa84f 100644 Binary files a/languages/bp-compliments-en_US.mo and b/languages/bp-compliments-en_US.mo differ diff --git a/languages/bp-compliments-en_US.po b/languages/bp-compliments-en_US.po index 7bb1da8..c3a7932 100644 --- a/languages/bp-compliments-en_US.po +++ b/languages/bp-compliments-en_US.po @@ -1,15 +1,15 @@ msgid "" msgstr "" -"Project-Id-Version: BuddyPress Compliments 1.0.7\n" +"Project-Id-Version: BuddyPress Compliments 1.0.9\n" "POT-Creation-Date: 2016-12-01 12:47+0000\n" -"PO-Revision-Date: 2016-12-01 12:47+0000\n" +"PO-Revision-Date: 2019-05-20 21:03+0530\n" "Last-Translator: \n" "Language-Team: GeoDirectory \n" "Language: en_US\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Generator: Poedit 1.8.7.1\n" +"X-Generator: Poedit 2.2.1\n" "X-Poedit-Basepath: ..\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "X-Poedit-KeywordsList: __;_e;_n:1,2;_x\n" diff --git a/readme.txt b/readme.txt index 4e2aedf..766f484 100644 --- a/readme.txt +++ b/readme.txt @@ -3,8 +3,8 @@ Contributors: viruthagiri, stiofansisland, paoltaia Donate link: http://wpgeodirectory.com/ Tags: buddypress, buddypress compliments, WordPress yelp compliments, buddypress integration, business directory plugin, directory, directory plugin, geodirectory, geodirectory buddypress, geodirectory buddypress integration, social network, yelp clone, yelp compliments Requires at least: 3.1 -Tested up to: 4.7 -Stable tag: 1.0.7 +Tested up to: 5.2 +Stable tag: 1.0.9 License: GPLv3 License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -71,12 +71,23 @@ No questions so far, but don't hesitate to ask! 4. Submitted compliments will be visible in user's compliments section. == Changelog == += 1.0.9 = +Fix issue for plugin installation via WP-CLI - FIXED +Compliments can be deleted by the sender - ADDED +Installation redirects only if user has BP - FIXED +Add a close button at the top of lightboxes - ADDED +Add multiple compliment notification issue - ADDED +Fix invalid html issue for send compliment button - FIXED = 1.0.7 = Send compliment button can be displayed in /members page - ADDED PHP undefined notices in wordpress admin - FIXED 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 = 1.0.6 = Notification incorrect from email - FIXED