diff --git a/bp-compliments-core.php b/bp-compliments-core.php index f46696f..ddbc3b7 100644 --- a/bp-compliments-core.php +++ b/bp-compliments-core.php @@ -178,6 +178,12 @@ public function setup_nav( $main_nav = array(), $sub_nav = array() ) { $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_compliment_can_see_others_comp == 'yes') { $show_for_displayed_user = true; } elseif ($bp_compliment_can_see_others_comp == 'members_only') { diff --git a/bp-compliments.php b/bp-compliments.php index 70f5d28..2461cbe 100644 --- a/bp-compliments.php +++ b/bp-compliments.php @@ -144,3 +144,13 @@ 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

"; + } +} diff --git a/change_log.txt b/change_log.txt index 133f5ee..339161f 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,3 +1,7 @@ +v1.0.2 +Category support added for compliments - ADDED +Compliment user settings page - ADDED + v1.0.1 Use singular name instead of slug name - FIXED Admin can delete compliments - ADDED diff --git a/css/bp-compliments.css b/css/bp-compliments.css index 200bad3..2a71d42 100644 --- a/css/bp-compliments.css +++ b/css/bp-compliments.css @@ -176,4 +176,52 @@ width: 32px; height: 32px; margin: 0 auto; -} \ No newline at end of file +} + +.comp-modal-category { + border-bottom: 1px solid #ddd; + list-style-type: none; + font-size: 14px; +} + +.comp-modal-category > li { + float: left; + margin-bottom: -1px; +} + +.comp-modal-category > li > a { + position: relative; + display: block; + padding: 10px 15px; + margin-right: 2px; + line-height: 1.42857143; + border: 1px solid transparent; + border-radius: 4px 4px 0 0; +} + +.comp-modal-category > li > a:hover { + border-color: #eee #eee #ddd; +} + +.comp-modal-category > li.selected > a, +.comp-modal-category > li.selected > a:hover, +.comp-modal-category > li.selected > a:focus { + color: #555; + cursor: default; + background-color: #fff; + border: 1px solid #ddd; + border-bottom-color: transparent; + opacity: 1; + font-weight: normal; +} + +.comp-modal-category:before, +.comp-modal-category:after { + display: table; + content: ""; + line-height: 0; +} + +.comp-modal-category:after { + clear: both; +} diff --git a/includes/bp-compliments-actions.php b/includes/bp-compliments-actions.php index 2ad1d4b..f2dd165 100644 --- a/includes/bp-compliments-actions.php +++ b/includes/bp-compliments-actions.php @@ -55,7 +55,13 @@ function handle_compliments_form_data() { $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 == '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_compliment_can_see_others_comp == 'yes') { $show_for_displayed_user = true; } elseif ($bp_compliment_can_see_others_comp == 'members_only') { if (is_user_logged_in()) { diff --git a/includes/bp-compliments-activity.php b/includes/bp-compliments-activity.php index 47f2b83..1f3ce8b 100644 --- a/includes/bp-compliments-activity.php +++ b/includes/bp-compliments-activity.php @@ -150,6 +150,11 @@ 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)) { $bp_compliment_can_see_others_comp = 'yes'; } @@ -200,6 +205,11 @@ 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)) { $bp_compliment_can_see_others_comp = 'yes'; } diff --git a/includes/bp-compliments-forms.php b/includes/bp-compliments-forms.php index d7ee9e7..f747008 100644 --- a/includes/bp-compliments-forms.php +++ b/includes/bp-compliments-forms.php @@ -14,8 +14,9 @@ * * @param int $pid The post ID. * @param int $receiver_id Compliment receiver ID. + * @param int $category_id Compliment category ID. */ -function bp_compliments_modal_form($pid = 0, $receiver_id = 0) { +function bp_compliments_modal_form($pid = 0, $receiver_id = 0, $category_id = 0) { if (!$receiver_id && bp_displayed_user_id()) { $receiver_id = bp_displayed_user_id(); } @@ -26,12 +27,56 @@ function bp_compliments_modal_form($pid = 0, $receiver_id = 0) {

-
+ 'name', + 'hide_empty' => 0, + ); + $cat_terms = get_terms('compliment_category', $cat_args); + $output = ""; + echo $output; + } + ?> + false, 'orderby' => 'id' ); + if ($category_id) { + $cat_meta = get_option("taxonomy_$category_id"); + if ($cat_meta) { + $cat_ids = array(); + foreach ($cat_meta as $id) { + $cat_ids[] = (int) $id; + } + $args['include'] = $cat_ids; + } + } $terms = get_terms( 'compliment', $args ); if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){ echo '
- __('Compliments', 'bp-compliments'), + 'slug' => 'compliments', + 'parent_url' => trailingslashit($user_domain . $settings_slug), + 'parent_slug' => $settings_slug, + 'screen_function' => 'bp_comp_settings_submenu_page_content', + 'position' => 20, + 'user_has_access' => bp_core_can_edit_settings() + )); + } + +} +add_action('bp_setup_nav', 'bp_comp_settings_submenu', 16); + +function bp_comp_settings_submenu_page_content() { + //add title and content here - last is to call the members plugin.php template + //add_action( 'bp_template_title', 'bp_comp_settings_submenu_page_show_screen_title' ); + add_action( 'bp_template_content', 'bp_comp_settings_submenu_page_show_screen_content' ); + bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) ); +} + +//function bp_comp_settings_submenu_page_show_screen_title() { +// echo __('Compliments Settings'); +//} + +function bp_comp_settings_submenu_page_show_screen_content() { + if (bp_displayed_user_id()) { + $user_id = bp_displayed_user_id(); + } elseif (bp_loggedin_user_id()) { + $user_id = bp_loggedin_user_id(); + } else { + $user_id = null; + } + + if (isset( $_POST['bp-comp-settings-submit'] )) { + if (! isset( $_POST['bp-compl-settings-field'] ) || ! wp_verify_nonce( $_POST['bp-compl-settings-field'], 'bp_compl_settings_action' )) { + ?> +
+

+ +

+
+ +
+

+ +

+
+ +
+ + + + + + + + + + + + +
+ +
+
+ + +
+
+ 'Categories', + 'singular_name' => 'Category', + 'search_items' => __( 'Search Categories', 'bp-compliments' ), + 'all_items' => __( 'All Categories', 'bp-compliments' ), + 'parent_item' => __( 'Parent Category', 'bp-compliments' ), + 'parent_item_colon' => __( 'Parent Category:', 'bp-compliments' ), + 'edit_item' => __( 'Edit Category', 'bp-compliments' ), + 'update_item' => __( 'Update Category', 'bp-compliments' ), + 'add_new_item' => __( 'Add New Category', 'bp-compliments' ), + 'new_item_name' => __( 'New Category Name', 'bp-compliments' ), + 'menu_name' => 'Category', + ); + + $cat_args = array( + 'hierarchical' => true, + 'labels' => $cat_labels, + 'show_ui' => true, + 'show_admin_column' => true, + 'query_var' => true, + 'rewrite' => array( 'slug' => 'compliment_category' ), + ); + + $bp_compliment_enable_categories_value = esc_attr( get_option('bp_compliment_enable_categories')); + $bp_compliment_enable_categories = $bp_compliment_enable_categories_value ? $bp_compliment_enable_categories_value : 'no'; + + if ($bp_compliment_enable_categories == 'yes') { + register_taxonomy( 'compliment_category', array(), $cat_args ); + } } //compliment icons @@ -83,6 +128,34 @@ function compliments_enqueue_admin_js( $hook_suffix ) { */ function compliments_taxonomy_add_new_meta_field() { ?> + +
+ 'name', + 'hide_empty' => 0, + ); + $terms = get_terms( 'compliment_category', $cat_args ); + ?> + + "; + $output .= ""; + foreach($terms as $term){ + $term_id = $term->term_id; + $term_name =$term->name; + $output .= ""; + } + $output .= ""; + echo $output; + ?> +
+

@@ -106,7 +179,43 @@ function compliments_taxonomy_add_new_meta_field() { */ function compliments_taxonomy_edit_meta_field($term) { $t_id = $term->term_id; - $term_meta = get_option( "taxonomy_$t_id" ); ?> + $term_meta = get_option( "taxonomy_$t_id" ); + ?> + + + 'name', + 'hide_empty' => 0, + ); + $terms = get_terms( 'compliment_category', $cat_args ); + ?> + + + "; + $output .= ""; + foreach($terms as $term){ + $term_id = $term->term_id; + $term_name =$term->name; + $output .= ""; + } + $output .= ""; + echo $output; + ?> + + + @@ -142,6 +251,24 @@ function save_taxonomy_custom_meta( $term_id ) { $term_meta[$key] = $_POST['term_meta'][$key]; } } + + $bp_compliment_enable_categories_value = esc_attr( get_option('bp_compliment_enable_categories')); + $bp_compliment_enable_categories = $bp_compliment_enable_categories_value ? $bp_compliment_enable_categories_value : 'no'; + + if ($bp_compliment_enable_categories == 'yes') { + $cat_id = $_POST['term_meta']['compliments_category']; + //save the cat id + if ($cat_id) { + $t_id = (int)$t_id; + $cat_meta = get_option("taxonomy_$cat_id"); + if (!$cat_meta) { + $cat_meta = array(); + } + $cat_meta[$t_id] = $t_id; + update_option("taxonomy_$cat_id", $cat_meta); + } + } + // Save the option array. update_option( "taxonomy_$t_id", $term_meta ); } @@ -165,6 +292,14 @@ function modify_compliment_columns($columns) { 'name' => __('Name', 'bp-compliments'), 'icon' => __('Icon', 'bp-compliments'), ); + + $bp_compliment_enable_categories_value = esc_attr( get_option('bp_compliment_enable_categories')); + $bp_compliment_enable_categories = $bp_compliment_enable_categories_value ? $bp_compliment_enable_categories_value : 'no'; + + if ($bp_compliment_enable_categories == 'yes') { + $new_columns['category'] = __('Category', 'bp-compliments'); + } + return $new_columns; } @@ -183,11 +318,17 @@ function modify_compliment_columns($columns) { function manage_bp_compliment_columns($out, $column_name, $t_id) { $term_meta = get_option( "taxonomy_$t_id" ); $term_icon = esc_attr( $term_meta['compliments_icon'] ) ? esc_attr( $term_meta['compliments_icon'] ) : ""; + $term_category = esc_attr( $term_meta['compliments_category'] ) ? esc_attr( $term_meta['compliments_category'] ) : ""; switch ($column_name) { case 'icon': $out .= ''; break; + case 'category': + $term = get_term_by('id', $term_category, 'compliment_category'); + $out .= $term->name; + break; + default: break; } @@ -257,4 +398,96 @@ function bp_comp_custom_css() { $value) { + $icon_meta = get_option("taxonomy_$icon_id"); + if ($icon_meta && is_array($icon_meta)) { + $icon_meta['compliments_category'] = ''; + update_option("taxonomy_$icon_id", $icon_meta); + } + } + } + } + + if ($taxonomy == 'compliment') { + $t_id = $term; + $term_meta = get_option("taxonomy_$t_id"); + if ($term_meta) { + $cat_id = $term_meta['compliments_category']; + if ($cat_id) { + $cat_id = (int) $cat_id; + $cat_meta = get_option("taxonomy_$cat_id"); + if ($cat_meta) { + unset($cat_meta[$t_id]); + update_option("taxonomy_$cat_id", $cat_meta); + } + } + } + } +} +add_action('pre_delete_term', 'bp_comp_delete_category', 10, 2); + +add_filter("manage_edit-compliment_category_columns", 'modify_compliment_category_columns'); +/** + * Modify compliment category page admin columns. + * + * @since 0.0.1 + * @package BuddyPress_Compliments + * + * @param array $columns The column array. + * @return array Modified column array. + */ +function modify_compliment_category_columns($columns) { + + unset($columns['posts']); + $columns['item_count'] = __('Count', 'bp-compliments'); + + return $columns; +} + +add_filter("manage_compliment_category_custom_column", 'manage_bp_compliment_category_columns', 10, 3); +/** + * Modify compliment category page admin column content. + * + * @since 0.0.1 + * @package BuddyPress_Compliments + * + * @param string $out The html output. + * @param string $column_name The column name. + * @param int $t_id The term ID. + * @return string The modified html output. + */ +function manage_bp_compliment_category_columns($out, $column_name, $t_id) { + $term_meta = get_option( "taxonomy_$t_id" ); + switch ($column_name) { + case 'item_count': + if ($term_meta && is_array($term_meta)) { + $out .= count($term_meta); + } else { + $out .= "0"; + } + break; + + default: + break; + } + return $out; +} + +add_action('admin_head', 'hide_bp_comp_category_parent_field'); +function hide_bp_comp_category_parent_field() { + ?> + +