Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compliment user settings page and category support added #20

Merged
merged 3 commits into from
Nov 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions bp-compliments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a target="_blank" href="%s">BuddyPress</a> plugin.', 'bp-compliments' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( $url ) );
if(!class_exists('BuddyPress')){
echo"<div class=\"$class\"> <p>$message</p></div>";
}
}
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.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
Expand Down
50 changes: 49 additions & 1 deletion css/bp-compliments.css
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,52 @@
width: 32px;
height: 32px;
margin: 0 auto;
}
}

.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;
}
8 changes: 7 additions & 1 deletion includes/bp-compliments-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
10 changes: 10 additions & 0 deletions includes/bp-compliments-activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down Expand Up @@ -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';
}
Expand Down
79 changes: 75 additions & 4 deletions includes/bp-compliments-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -26,12 +27,56 @@ function bp_compliments_modal_form($pid = 0, $receiver_id = 0) {
<h2><?php echo sprintf( __( 'Choose Your %s Type:', 'bp-compliments' ), BP_COMP_SINGULAR_NAME ); ?></h2>
</div>
<div class="comp-modal-content">
<form action="" method="post">
<?php
$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_args = array(
'orderby' => 'name',
'hide_empty' => 0,
);
$cat_terms = get_terms('compliment_category', $cat_args);
$output = "<ul class='comp-modal-category'>";
$count = 0;
foreach ($cat_terms as $cat_term) {
$count++;
$cat_term_id = $cat_term->term_id;
$cat_term_meta = get_option("taxonomy_$cat_term_id");
if ($cat_term_meta) {
$cat_term_name = $cat_term->name;
if ($count == 1 && !$category_id) {
$output .= "<li class='selected'>";
$category_id = $cat_term_id;
} elseif ($cat_term_id == $category_id) {
$output .= "<li class='selected'>";
} else {
$output .= "<li>";
}
$output .= "<a href='#' class='comp-modal-category-cat' data-catid='" . $cat_term_id . "'>" . $cat_term_name . "</a>";
$output .= "</li>";
}
}
$output .= "</ul>";
echo $output;
}
?>
<form action="" method="post">
<?php
$args = array(
'hide_empty' => 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 '<ul class="comp-form-ul">';
Expand All @@ -53,7 +98,7 @@ function bp_compliments_modal_form($pid = 0, $receiver_id = 0) {
<?php
}
echo '</ul>';

$ajax_nonce = wp_create_nonce("bp-compliments-nonce");
?>
<textarea placeholder="<?php echo __( 'Type your message here', 'bp-compliments' ); ?>" name="message" maxchar="1000"></textarea>
<input type="hidden" name="post_id" value="<?php echo $pid; ?>"/>
Expand All @@ -73,9 +118,28 @@ function bp_compliments_modal_form($pid = 0, $receiver_id = 0) {
container.replaceWith("<div class='comp-modal' style='display: none;'><div class='comp-modal-content-wrap'><div class='comp-modal-title comp-loading-icon'><div class='bp-loading-icon'></div></div></div></div>");
mod_shadow.hide();
});
jQuery('a.comp-modal-category-cat').click(function (e) {
e.preventDefault();
var mod_shadow = jQuery('#bp_compliments_modal_shadow');
var container = jQuery('.comp-modal');
container.html("<div class='comp-modal-content-wrap'><div class='comp-modal-title comp-loading-icon'><div class='bp-loading-icon'></div></div></div>");
var category_id = jQuery(this).data('catid');
mod_shadow.show();
var data = {
'action': 'bp_compliments_modal_ajax',
'bp_compliments_nonce': '<?php echo $ajax_nonce; ?>',
'category_id': category_id
};

jQuery.post('<?php echo admin_url('admin-ajax.php'); ?>', data, function (response) {
container.replaceWith(response);
});
});
});
</script>
<?php
} else {
echo __( 'No compliments found.', 'bp-compliments' );
}
?>
</form>
Expand All @@ -94,7 +158,14 @@ 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();

if (isset($_POST['category_id'])) {
$category_id = (int) strip_tags(esc_sql($_POST['category_id']));
bp_compliments_modal_form(0, 0, $category_id);
} else {
bp_compliments_modal_form();
}

wp_die();
}

Expand Down
127 changes: 126 additions & 1 deletion includes/bp-compliments-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function bp_compliments_register_settings() {
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' );
register_setting( 'bp-compliment-settings', 'bp_compliment_enable_categories' );
register_setting( 'bp-compliment-settings', 'bp_comp_per_page' );
register_setting( 'bp-compliment-settings', 'bp_comp_custom_css' );
}
Expand All @@ -52,6 +53,9 @@ function bp_compliments_settings_page() {
$bp_compliment_enable_notifications_value = esc_attr( get_option('bp_compliment_enable_notifications'));
$bp_compliment_enable_notifications = $bp_compliment_enable_notifications_value ? $bp_compliment_enable_notifications_value : 'yes';

$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';

$comp_per_page_value = esc_attr( get_option('bp_comp_per_page'));
$comp_per_page = $comp_per_page_value ? (int) $comp_per_page_value : 5;

Expand All @@ -78,6 +82,7 @@ function bp_compliments_settings_page() {
<option value="yes" <?php selected( $bp_compliment_can_see_others_comp, 'yes' ); ?>><?php echo __( 'Anybody', 'bp-compliments' ); ?></option>
<option value="no" <?php selected( $bp_compliment_can_see_others_comp, 'no' ); ?>><?php echo __( 'Nobody', 'bp-compliments' ); ?></option>
<option value="members_only" <?php selected( $bp_compliment_can_see_others_comp, 'members_only' ); ?>><?php echo __( 'Members Only', 'bp-compliments' ); ?></option>
<option value="members_choice" <?php selected( $bp_compliment_can_see_others_comp, 'members_choice' ); ?>><?php echo __( 'Let members take care of this setting', 'bp-compliments' ); ?></option>
</select>
</td>
</tr>
Expand Down Expand Up @@ -108,6 +113,15 @@ function bp_compliments_settings_page() {
</select>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php echo sprintf( __( 'Enable categories for %s ?', 'bp-compliments' ), strtolower(BP_COMP_PLURAL_NAME) ); ?></th>
<td>
<select id="bp_compliment_enable_categories" name="bp_compliment_enable_categories">
<option value="yes" <?php selected( $bp_compliment_enable_categories, 'yes' ); ?>><?php echo __( 'Yes', 'bp-compliments' ); ?></option>
<option value="no" <?php selected( $bp_compliment_enable_categories, 'no' ); ?>><?php echo __( 'No', 'bp-compliments' ); ?></option>
</select>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php echo sprintf( __( 'Number of %s to display per page?', 'bp-compliments' ), BP_COMP_PLURAL_NAME ); ?></th>
<td><input type="number" class="widefat" name="bp_comp_per_page" value="<?php echo $comp_per_page; ?>" /></td>
Expand All @@ -124,4 +138,115 @@ function bp_compliments_settings_page() {

</form>
</div>
<?php }
<?php }

//BuddyPress user settings
function bp_comp_settings_submenu() {
global $bp;

$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') {
if (!bp_is_active('settings')) {
return;
}

if (bp_displayed_user_domain()) {
$user_domain = bp_displayed_user_domain();
} elseif (bp_loggedin_user_domain()) {
$user_domain = bp_loggedin_user_domain();
} else {
$user_domain = null;
}

// Get the settings slug
$settings_slug = bp_get_settings_slug();

bp_core_new_subnav_item(array(
'name' => __('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' )) {
?>
<div id="message" class="error">
<p>
<?php echo __('There was an error with your form. Please contact administrator.', 'bp-compliments'); ?>
</p>
</div>
<?php
} else {
// process form data
$bp_compliment_can_see_your_comp_form_value = $_POST['bp_compliment_can_see_your_comp'];
update_user_meta($user_id, 'bp_compliment_can_see_your_comp', $bp_compliment_can_see_your_comp_form_value);
?>
<div id="message" class="updated">
<p>
<?php echo __('Setting updated successfully.', 'bp-compliments'); ?>
</p>
</div>
<?php
}
}

$bp_compliment_can_see_your_comp_value = esc_attr( get_user_meta($user_id, 'bp_compliment_can_see_your_comp', true));
$bp_compliment_can_see_your_comp = $bp_compliment_can_see_your_comp_value ? $bp_compliment_can_see_your_comp_value : 'yes';
?>
<form method="post" class="standard-form">
<table class="profile-settings">
<thead>
<tr>
<th class="title" colspan="2"><?php echo __('Compliments Settings', 'bp-compliments'); ?></th>
</tr>
</thead>
<tbody>
<tr>
<td class="field-name"><label><?php echo __('Who can see your compliment page?', 'bp-compliments'); ?></label></td>
<td class="field-visibility">
<select id="bp_compliment_can_see_your_comp" class="bp-xprofile-visibility" name="bp_compliment_can_see_your_comp">
<option value="yes" <?php selected( $bp_compliment_can_see_your_comp, 'yes' ); ?>><?php echo __( 'Anybody', 'bp-compliments' ); ?></option>
<option value="no" <?php selected( $bp_compliment_can_see_your_comp, 'no' ); ?>><?php echo __( 'Nobody', 'bp-compliments' ); ?></option>
<option value="members_only" <?php selected( $bp_compliment_can_see_your_comp, 'members_only' ); ?>><?php echo __( 'Members Only', 'bp-compliments' ); ?></option>
</select>
</td>
</tr>
</tbody>
</table>
<div class="submit">
<?php wp_nonce_field( 'bp_compl_settings_action', 'bp-compl-settings-field' ); ?>
<input type="submit" name="bp-comp-settings-submit" value="Save Settings" class="auto">
</div>
</form>
<?php
}
Loading