Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 20 replies - 1 through 20 (of 20 total)
  • Avatar of dvd3141
    David Hunt
    Participant

    @dvd3141

    Okay, phew, it wasn’t as serious as I first thought. This now won’t send an email if the content is empty (which is, apparently, the case when a user is being deleted):

    `function pa_send_notification_email( $args ) {
    // If current user deletes his/her own activity, do nothing
    if (($args['user_id'] != bp_loggedin_user_id())) {
    $ud = get_userdata($args['user_id']);
    $to = $ud->user_email;
    // Build the message
    if (($to) && ($to != ”)) {
    global $wpdb;
    $content = $wpdb->get_var( $wpdb->prepare( “SELECT content FROM “.$wpdb->prefix.”bp_activity WHERE id = %d;”, $args['id'] ) );
    if ($content != ”) {
    $subject = ‘Your post has been removed’;
    $message = ‘A moderator has removed your post. If you want to know why, please forward this message to the moderation team.
    ‘;
    $message .= ‘Removed content:
    ‘;

    $message .= wpautop( $content );
    $message .= ”;

    //Send email
    wp_mail($to, $subject, $message, ‘content-type: text/html’ );
    }
    }
    }
    }
    add_action( ‘bp_before_activity_delete’, ‘pa_send_notification_email’);`

    Avatar of dvd3141
    David Hunt
    Participant

    @dvd3141

    Hmm, the situation is not as dire as I thought. I did more testing and it appears that, when I delete a user who as posted multiple times, my function only sends one notification email to the user — but the SQL query is empty (as we might expect). So I think all I need to do is put a check in to see whether the deleted “content” is empty or not, and if it is, don’t send the email.

    I’ll keep updating this thread with my findings in case it’s useful to anyone!

    Avatar of dvd3141
    David Hunt
    Participant

    @dvd3141

    Revisiting this thread with a new issue!

    My function has been working well, except I’ve recently discovered a small flaw: if an administrator deletes a user, then the user receives an email informing him or her that his activity has been removed for each and every thing he or she has ever posted! For a prolific user, that could be hundreds or thousands of emails. Not good!

    This is by virtue of the user-delete process — it appears as though BuddyPress deletes each activity individually, and then WordPress deletes the user account.

    For reference, my function is:

    `function pa_send_notification_email( $args ) {
    // If current user deletes his/her own activity, do nothing
    // otherwise construct and send email
    if ($args['user_id'] != bp_loggedin_user_id()) {
    $ud = get_userdata($args['user_id']);
    $to = $ud->user_email;
    // Build the message
    if (($to) && ($to != ”)) {
    $subject = ‘Your post has been removed’;
    $message = ‘A moderator has removed your post. If you want to know why, please forward this message to the moderation team.
    ‘;
    $message .= ‘Removed content:
    ‘;
    global $wpdb;
    $message .= wpautop( $wpdb->get_var( $wpdb->prepare( “SELECT content FROM “.$wpdb->prefix.”bp_activity WHERE id = %d;”, $args['id'] ) ) );
    $message .= ”;

    //Send email
    wp_mail($to, $subject, $message, ‘content-type: text/html’ );
    }
    }
    }
    add_action( ‘bp_before_activity_delete’, ‘pa_send_notification_email’);`

    So what I think I need is an extra check in my function, to make sure we are not about to delete the user. I’ve thought about a secondary function to hook into the `delete_user` action to set a global variable, and then checking for this variable in my `pa_send_notification_email()` function.

    But I am not sure how to go about this. Does anyone have any thoughts?

    Avatar of dvd3141
    David Hunt
    Participant

    @dvd3141

    Finally got around to investigating this bug. It was hooking into the wrong action around activity comments. Think this is the fix.

    Edit bpModDefaultContentTypes.php and find the line (around line 53):
    `add_action(‘bp_after_activity_comment’, array(__CLASS__, ‘activity_comments_print_link’));`
    Delete/comment it out and add this instead:
    `add_action(‘bp_activity_comment_options’, array(__CLASS__, ‘activity_comments_print_link’));`

    Together with these other fixes, I think the plugin is now functional in BP 1.6+

    Avatar of dvd3141
    David Hunt
    Participant

    @dvd3141

    Ah, it’s already been logged and fixed for 1.6.2. I do wish 1.6.2 had been released already! Would have saved me a few frustrating hours.

    Avatar of dvd3141
    David Hunt
    Participant

    @dvd3141

    Well, after being driven almost bonkers, I have solved this — and found what I think is a bug in BuddyPress 1.6.1.

    I went with @shanebpx’s great suggestion of using a get_var query:


    $content_id = $args['id'];
    global $wpdb;
    $content = $wpdb->get_var( $wpdb->prepare("SELECT content FROM ".$wpdb->prefix."bp_activity WHERE id = %d;", $content_id ) );
    $message .= wpautop($content);

    However, I was baffled by the fact that $content kept coming up empty. Until I finally took a look at how BuddyPress was calling do_action( 'bp_before_activity_delete', $args ); in /bp-activity/bp-activity-functions.php:


    if ( !$activity_ids_deleted = BP_Activity_Activity::delete( $args ) )
    return false;

    // Check if the user's latest update has been deleted
    if ( empty( $args['user_id'] ) )
    $user_id = $bp->loggedin_user->id;
    else
    $user_id = $args['user_id'];

    do_action( 'bp_before_activity_delete', $args );

    Yup, it’s apparently doing the bp_before_activity_delete action after BP_Activity_Activity::delete!

    I have edited my copy of /bp-activity/bp-activity-functions.php to put the do_action before the deletion.


    do_action( 'bp_before_activity_delete', $args );
    if ( !$activity_ids_deleted = BP_Activity_Activity::delete( $args ) )
    return false;

    // Check if the user's latest update has been deleted
    if ( empty( $args['user_id'] ) )
    $user_id = bp_loggedin_user_id();
    else
    $user_id = $args['user_id'];

    and at last, my email function works!

    Now, how do I go about submitting this as a bug…?

    Avatar of dvd3141
    David Hunt
    Participant

    @dvd3141

    I guess the delete button only passes user_id and id to $args…

    Avatar of dvd3141
    David Hunt
    Participant

    @dvd3141

    @shanebpx: Thanks for that suggestion — it’s beautifully simple. Unfortunately, it appear as though $args['content'] is empty? (But there’s definitely content in the test activity I am deleting!)

    For debugging, I tried $message .= print_r($args, true);, which gave:

    Array
    (
    [id] => 31
    [action] =>
    [content] =>
    [component] =>
    [type] =>
    [primary_link] =>
    [user_id] => 52
    [item_id] =>
    [secondary_item_id] =>
    [date_recorded] =>
    [hide_sitewide] =>
    )

    I admit I’m a little bewildered as to why all those values appear empty.

    Avatar of dvd3141
    David Hunt
    Participant

    @dvd3141

    I was able to add the username to the activation email with this snippet:

    `<?php if ($user = bp_get_signup_username_value()) echo '

    Your username: ‘.$user.’

    ‘; ?>`

    We perform the `if` check because `bp_get_signup_username_value()` is only non-empty during signup, so you don’t want to be echoing it in general emails.

    Avatar of dvd3141
    David Hunt
    Participant

    @dvd3141

    It seems a bit weird that there’s no function I can call in the email template that will echo the targeted user’s username.

    Avatar of dvd3141
    David Hunt
    Participant

    @dvd3141

    Unfortunately that didn’t work. Thanks for the reply though Paul.

    Avatar of dvd3141
    David Hunt
    Participant

    @dvd3141

    Hi Paul,

    It’s a great plugin and has added a lot of value to my BuddyPress installation. Many thanks for the hard word.

    Like some of the people above, I’d also like to add the user’s username to the Activation email. (People sometimes keep them to refer to if they forget their username.) Is there any chance this sort of token replacement is available? Or failing that, do you know how to add it to the footer of the email, through hacking the email template code itself?

    Best,

    David

    Avatar of dvd3141
    David Hunt
    Participant

    @dvd3141

    I think `bp_member_user_nicename` might be function you wanted? E.g.:

    `@`

    Avatar of dvd3141
    David Hunt
    Participant

    @dvd3141

    Like mrjarbenne, I was also wondering if it’s possible to get the “Flag” link in comment replies to be inline with “Reply” and “Delete” (and of the same size)?

    Avatar of dvd3141
    David Hunt
    Participant

    @dvd3141

    I used this to handle the “Howdy” question:

    http://wordpress.org/extend/plugins/cj-change-howdy/

    Avatar of dvd3141
    David Hunt
    Participant

    @dvd3141

    Well, I found a workaround. For me it wasn’t a problem with the toggle … kind of.

    I found that in the function `invite_anyone_bypass_registration_lock()`, it was this check that was causing the failure:

    `$bp->current_component != BP_REGISTER_SLUG `

    This seems to be because (i) I had changed the slug of my BP registration page and (ii) my registration page is a child page of another page.

    Workaround: I set my slug to be “register” and set the registration page to be a main page — and lo-and-behold, email invitations work again even with site registration disabled.

    I don’t know if that’s a bug in WordPress, BuddyPress, or this plugin. Hopefully this workaround will help others to have a functional site.

    Best,

    David

    Avatar of dvd3141
    David Hunt
    Participant

    @dvd3141

    Digging around the plugin code, I found that in `by-email.php` is a section starting around line 1223 with the following comment:

    `// This is a royal hack until there is a filter on bp_get_signup_allowed()`

    It seems that since then, filtering is allowed on bp_get_signup_allowed, see here:

    http://buddypress.trac.wordpress.org/changeset/4036

    So maybe someone is able to replace that “royal hack” with the right code, would that fix the bug?

    Avatar of dvd3141
    David Hunt
    Participant

    @dvd3141

    Yes, I have also just discovered this bug. I really hope we can have a fix soon, this feature is vital to my installation! For my site, membership must be by invitation only.

    Avatar of dvd3141
    David Hunt
    Participant

    @dvd3141

    Just wanted to note that I also have this problem. If anyone can suggest a fix, please post it here.

    Avatar of dvd3141
    David Hunt
    Participant

    @dvd3141

    Thanks for confirming I wasn’t doing anything silly. :)

    Ticket posted: https://buddypress.trac.wordpress.org/ticket/4367

    (I set it as a bug rather than enhancement, because I genuinely believe this would be a big problem anytime anyone decides the change their permalink structure.)

Viewing 20 replies - 1 through 20 (of 20 total)