Kineta (@kineta)

Forum Replies Created

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

  • Kineta
    Participant

    @kineta

    Because that would prevent *everyone* from editing their posts. Which is not an acceptable solution.

    Surely there is a way to change the reply author without going into the admin panel?

    I’m trying to use the bbp_edit_reply_pre_insert filter, without much luck.


    Kineta
    Participant

    @kineta

    Okay, how about this – how do I add metadata when submitting the edit form?

    I’m trying to use add_post_meta but I don’t think I’m intercepting the submit button.


    Kineta
    Participant

    @kineta

    No one? This seems like it should be easy.


    Kineta
    Participant

    @kineta

    @ajoyce2016 you’re welcome. glad I could be helpful 😉


    Kineta
    Participant

    @kineta

    Here you go. I have this in my theme’s functions.php file. I posted this code a while ago, but there was a small mistake which is fixed here.

    function jpr_buddypress_add_notification( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false, $reply_to = 0 ) {
    	
    		
    		// this is who the notification goes to. whose post is replied to
    		$topic_author_id = bbp_get_topic_author_id( $reply_to );
    
    		// Bail if somehow this is hooked to an edit action
    		if ( !empty( $is_edit ) ) {
    			return;
    		}
    
    		// Get author information
    		// $topic_author_id   = bp_loggedin_user_id();
    		$secondary_item_id = $author_id;
    
    		// Hierarchical replies
    		if ( !empty( $reply_to ) ) {			
    			$reply_to_item_id = bbp_get_topic_author_id( $reply_to );
    			// if not replying to OP:
    			$topic_id = $reply_to;
    		}		
    
    		
    		// Get some reply information
    		$args = array(
    			'user_id'          => $topic_author_id,
    			'item_id'          => $topic_id,
    			'component_name'   => bbp_get_component_name(),
    			'component_action' => 'bbp_new_reply',
    			'date_notified'    => get_post( $reply_id )->post_date_gmt,
    		);
    	 	
    		// Notify the topic author if not the current reply author
    	 	if ( $author_id !== $topic_author_id ) {
    			$args['secondary_item_id'] = $secondary_item_id ;
    
    			bp_notifications_add_notification( $args );
    	 	}
    	 	// Notify the immediate reply author if not the current reply author
    	 	if ( !empty( $reply_to ) && ( $author_id !== $reply_to_item_id ) ) {
    			$args['secondary_item_id'] = $secondary_item_id;
    			
    			bp_notifications_add_notification( $args );
    	 }
    }
    // remove the bbpress notification function so we don't get dupicate notifications
    remove_action( 'bbp_new_reply', 'bbp_buddypress_add_notification', 10, 7 );
    add_action( 'bbp_new_reply', 'jpr_buddypress_add_notification', 10, 7 );
    
    // remove the bbpress format notification function before using our custom function
    remove_filter( 'bp_notifications_get_notifications_for_user', 'bbp_format_buddypress_notifications', 10, 5 );
    
    function jpr_format_buddypress_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
    
    	// New reply notifications
    	if ( 'bbp_new_reply' === $action ) {
    		$topic_id    = bbp_get_reply_id( $item_id );
    		$topic_title = bbp_get_reply_title( $item_id );
    		$topic_link  = wp_nonce_url( add_query_arg( array( 'action' => 'bbp_mark_read', 'topic_id' => $topic_id ), bbp_get_reply_url( $item_id ) ), 'bbp_mark_topic_' . $topic_id );
    		$title_attr  = __( 'Topic Replies', 'bbpress' );
    
    		if ( (int) $total_items > 1 ) {
    			$text   = sprintf( __( 'You have %d new replies', 'bbpress' ), (int) $total_items );
    			$filter = 'bbp_multiple_new_subscription_notification';
    		} else {
    			if ( !empty( $secondary_item_id ) ) {
    				$text = sprintf( __( 'You have %d new reply to %2$s from %3$s', 'bbpress' ), (int) $total_items, $topic_title, bp_core_get_user_displayname( $secondary_item_id ) );
    			} else {
    				$text = sprintf( __( 'You have %d new reply to %s',             'bbpress' ), (int) $total_items, $topic_title );
    			}
    			$filter = 'bbp_single_new_subscription_notification';
    		}
    
    		// WordPress Toolbar
    		if ( 'string' === $format ) {
    			$return = apply_filters( $filter, '<a href="' . esc_url( $topic_link ) . '" title="' . esc_attr( $title_attr ) . '">' . esc_html( $text ) . '</a>', (int) $total_items, $text, $topic_link );
    			
    		// Deprecated BuddyBar
    		} else {
    			$return = apply_filters( $filter, array(
    				'text' => $text,
    				'link' => $topic_link
    			), $topic_link, (int) $total_items, $text, $topic_title );
    		}
    
    		do_action( 'jpr_format_buddypress_notifications', $action, $item_id, $secondary_item_id, $total_items );
    
    		return $return;
    	}
    }
    add_filter( 'bp_notifications_get_notifications_for_user', 'jpr_format_buddypress_notifications', 10, 5 );
    
    

    Kineta
    Participant

    @kineta

    @ajoyce2016 – I created a fix for the site I’m working on that doesn’t require hacking the core. I’ll post it when I get home from work.


    Kineta
    Participant

    @kineta

    @robin-w Thanks Robin. I still need to use the loop-single-reply as it is, what I’m trying to do is call an additional custom loop that also threads. (I’m putting an index of linked post titles above the threaded replies. Example on my test site: http://jpr-test.com/boards/topic/lets-make-a-giant-thread/ )

    The solution I came up with isn’t very elegant, but it works. I ended up creating a copy of the BBP_Walker_Reply class with a different name, just to direct it to a different loop. Seems like a lot of duplicated code to change one line. But I can’t think of any other way to do it.


    Kineta
    Participant

    @kineta

    @veelow – That was exactly the problem I was having. It seems to be generated from the bbPress function: bbp_buddypress_add_notification (notification with your name instead of the person who responded). The code I posted addresses that problem. Did you try it?


    Kineta
    Participant

    @kineta

    I came up with a solution, based on the start @davidstriga made. I’ve been meaning to post it for anyone else having the same issue. I don’t have the same goal he did to notify everyone in a forum, just the person being replied to, so I removed the foreach loop. I also wanted the notification to go to the actual replied-to post in the thread and not just the initial topic at the top of the page. The forum I’m working on has titles on all the replies – but if you aren’t using titles on replies the notification just shows the topic title, but the link still goes to the relevant post/reply.

    If anyone is interested, here’s my solution. It’s working great on our site and takes care of the duplicate issues, as well as the GMT timestamp problem.

    Put this in your theme’s functions.php

    /* notifications */
    
    function jpr_buddypress_add_notification( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false, $reply_to = 0 ) {
    
    	$current_topic_id = bbp_get_topic_id();
    	$ids_of_subs = bbp_get_topic_subscribers($current_topic_id);
    		
    		// this is who the notification goes to. whose post is replied to
    		$topic_author_id = bbp_get_topic_author_id( $reply_to );
    
    		// Bail if somehow this is hooked to an edit action
    		if ( !empty( $is_edit ) ) {
    			return;
    		}
    
    		// Get author information
    		// $topic_author_id   = bp_loggedin_user_id();
    		$secondary_item_id = $author_id;
    
    		// Hierarchical replies
    		if ( !empty( $reply_to ) ) {			
    			$reply_to_item_id = bbp_get_topic_author_id( $reply_to );
    		}		
    
    		// pass the $reply_id to the function that formats the notification
    		$topic_id = $reply_to;
    		
    		// Get some reply information
    		$args = array(
    			'user_id'          => $topic_author_id,
    			'item_id'          => $topic_id,
    			'component_name'   => bbp_get_component_name(),
    			'component_action' => 'bbp_new_reply',
    			'date_notified'    => get_post( $reply_id )->post_date_gmt,
    		);
    	 	
    		// Notify the topic author if not the current reply author
    	 	if ( $author_id !== $topic_author_id ) {
    			$args['secondary_item_id'] = $secondary_item_id ;
    
    			bp_notifications_add_notification( $args );
    	 	}
    	 	// Notify the immediate reply author if not the current reply author
    	 	if ( !empty( $reply_to ) && ( $author_id !== $reply_to_item_id ) ) {
    			$args['secondary_item_id'] = $secondary_item_id;
    			
    			bp_notifications_add_notification( $args );
    	 }
    }
    // remove the bbpress notification function so we don't get dupicate notifications
    remove_action( 'bbp_new_reply', 'bbp_buddypress_add_notification', 10, 7 );
    add_action( 'bbp_new_reply', 'jpr_buddypress_add_notification', 10, 7 );
    
    // remove the bbpress format notification function before using our custom function
    remove_filter( 'bp_notifications_get_notifications_for_user', 'bbp_format_buddypress_notifications', 10, 5 );
    
    function jpr_format_buddypress_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
    
    	// New reply notifications
    	if ( 'bbp_new_reply' === $action ) {
    		$topic_id    = bbp_get_reply_id( $item_id );
    		$topic_title = bbp_get_reply_title( $item_id );
    		$topic_link  = wp_nonce_url( add_query_arg( array( 'action' => 'bbp_mark_read', 'topic_id' => $topic_id ), bbp_get_reply_url( $item_id ) ), 'bbp_mark_topic_' . $topic_id );
    		$title_attr  = __( 'Topic Replies', 'bbpress' );
    
    		if ( (int) $total_items > 1 ) {
    			$text   = sprintf( __( 'You have %d new replies', 'bbpress' ), (int) $total_items );
    			$filter = 'bbp_multiple_new_subscription_notification';
    		} else {
    			if ( !empty( $secondary_item_id ) ) {
    				$text = sprintf( __( 'You have %d new reply to %2$s from %3$s', 'bbpress' ), (int) $total_items, $topic_title, bp_core_get_user_displayname( $secondary_item_id ) );
    			} else {
    				$text = sprintf( __( 'You have %d new reply to %s',             'bbpress' ), (int) $total_items, $topic_title );
    			}
    			$filter = 'bbp_single_new_subscription_notification';
    		}
    
    		// WordPress Toolbar
    		if ( 'string' === $format ) {
    			$return = apply_filters( $filter, '<a href="' . esc_url( $topic_link ) . '" title="' . esc_attr( $title_attr ) . '">' . esc_html( $text ) . '</a>', (int) $total_items, $text, $topic_link );
    
    		// Deprecated BuddyBar
    		} else {
    			$return = apply_filters( $filter, array(
    				'text' => $text,
    				'link' => $topic_link
    			), $topic_link, (int) $total_items, $text, $topic_title );
    		}
    
    		do_action( 'jpr_format_buddypress_notifications', $action, $item_id, $secondary_item_id, $total_items );
    
    		return $return;
    	}
    }
    add_filter( 'bp_notifications_get_notifications_for_user', 'jpr_format_buddypress_notifications', 10, 5 ); 

    Kineta
    Participant

    @kineta

    I’m being a little dense with this due to my inexperience. It seems two variable in this function need to be flipped and I’m not figuring out which they are. The notification is showing for the person who makes the reply rather than the person being replied to and it says it’s from the person that the reply is to. So close…


    Kineta
    Participant

    @kineta

    Thanks much! Very helpful.


    Kineta
    Participant

    @kineta

    sorry, that should be:

    
    ( function($) {	
    $(document).ready(function() {	
    
       // all the javascript goes here...
    
    });
    } )( jQuery );

    Kineta
    Participant

    @kineta

    Would you be willing to share what you’ve got so far? It would be helpful. Thanks.


    Kineta
    Participant

    @kineta

    If you look at a javascript debugger are you getting a console error that reads something like “Failed to execute ‘insertBefore’ on ‘Node’” (I can’t remember the exact text)?

    If not then it’s probably a different issue than what I was dealing with.

    If you’re getting that error, it’s because a function in bbPress is trying to move the TinyMCE editor. Since the above code is an overwrite of the addReply.moveForm function, it needs to be loaded after the bbPress script. Because my example is using jquery you might need to make sure it’s in the right place for that. I’m not sure, you might need to change the $ to ‘jQuery’. Or write the code to use vanilla javascript. I have my .js file set up for jquery, following the Twentysixteen theme: everything is between:

    ( function($) {	
    $(document).ready(function() {	
    
       // all the javascript goes here...
    
    })
    })

    Kineta
    Participant

    @kineta

    @maketheest – sounds like the error coming from the bbPress code, which uses “insertBefore”. Make sure the overwrite is being called *after* the bbPress javascript. Or try clearing your browser cache. Also make sure all the divs & textarea is named the same as my js – or change accordingly.

    The heart of it is that the TinyMCE editor doesn’t like being moved around in the DOM, which is what the bbPress function is trying to do. You need to remove it first, then re-initialize it after moving the container. The last piece is to put the parentId, which is passed by the function, into the hidden field (should have the id of bbp_reply_to) that accompanies the editor.


    Kineta
    Participant

    @kineta

    $current_user = wp_get_current_user();
    $nickname = $current_user->nickname;

    ?


    Kineta
    Participant

    @kineta

    You can try putting this inside a .js file in your theme. You’ll have to adjust the tinymce editor settings in this code to your liking.

    addReply = {
    		moveForm : function(replyId, parentId, respondId, postId) {
    			
    			// remove the instance of tinymce before moving it's container
    			tinymce.remove('#bbp_reply_content');
    			// it can't possibly be this easy:
    			$('#post-container-'+parentId).after($('#'+respondId)); 
    			
    			tinyMCE.init({   
    				selector: 'textarea', 
    				plugins: 'hr, wplink, textcolor, paste, image, media, wpemoji, emoticons, charmap, fullscreen',
    				forced_root_block : "",
    				menubar: false,
    				toolbar1: 'styleselect,bold,italic,underline,strikethrough,blockquote,bullist,numlist,alignleft,aligncenter,alignright,fullscreen',
    				toolbar2: 'fontsizeselect,forecolor,outdent,indent,hr,charmap,emoticons,image,media,link,unlink,wp_help'
    			  });
    			
    			// write the correct reply-to id to the hidden field that stores it
    			// this prevents the wrong id inserted because we're returing false at the end of the function.
    			$('input#bbp_reply_to').val(parentId)
    			
    			// return false to prevent page reload, losing all the work.
    			return false; 
    		}
    	}

    Kineta
    Participant

    @kineta

    Funny, I could have sworn reply notifications worked when we were first testing and trying to find a forum platform that met our needs. Must have hallucinated that!

    Email notifications are fine for some things, but on a very active discussion board they would be overwhelming.

    I’ve been trying to hack the code in the includes/extend/buddypress/notifications.php file. But I’m pretty green with both php and wordpress/bbpress development. It does look like all the parts are there to extend it. But I’m a bit perplexed about some things in the code.


    Kineta
    Participant

    @kineta

    I’ve encountered the same issue. I’ve been beating my head against this thinking it was an issue in the theme I’m developing. Finally stripped everything down to just the bbPress & BuddyPress plugins and used the TwentySixteen theme to test.

    If someone replies to a post inside a threaded topic and that post was made by the person who created the original topic, then they will get TWO notifications. One will say it’s from the name of the person who replied (good so far) and the second will say it’s from the name of the person getting the notification (and/or OP author). Also, no notifications are sent if the reply isn’t to the author of the original post/topic.

    I’m very happy to see there’s a ticket for this. Any hope that it will get fixed any time soon? Selfish reason for asking – this stands to put a kibosh on my project as the two main requirements for the community forum I’m developing the theme for require threaded replies and notifications.


    Kineta
    Participant

    @kineta

    Anyone else have this issue? It’s a real roadblock for our project and I’ve been trying to debug it. I’m 99% certain this happened during one of the last two bbPress upgrades.


    Kineta
    Participant

    @kineta

    This bug isn’t just in Chrome. It’s actually because TinyMce editor doesn’t like being moved around the DOM, which is what the the function in bbPress is trying to do – tying to move the editor under the post you’re replying to.

    I wish this bug would get fixed, but in the meantime you can overwrite the javascript function in a .js file in your theme. This is what I did – remove the editor before moving the containing element, then reinitialize it. Works well for me.

    FYI: in case you don’t know javascript well – this needs to be inside jquery $(document).ready()

    // overwrite bbPress's broken function that moves the reply form under the replied to post in threaded topics
    	
    	addReply = {
    		moveForm : function(replyId, parentId, respondId, postId) {
    						
    			tinymce.remove('#bbp_reply_content');
    			// it can't possibly be this easy:
    			$('#post-container-'+parentId).after($('#'+respondId)); 
    			
    			tinyMCE.init({   
    				selector: 'textarea', 
    				plugins: 'hr, wplink, textcolor, paste, image, media, wpemoji, emoticons, charmap, fullscreen',
    				forced_root_block : "",
    				menubar: false,
    				toolbar1: 'styleselect,bold,italic,underline,strikethrough,blockquote,bullist,numlist,alignleft,aligncenter,alignright,fullscreen',
    				toolbar2: 'fontsizeselect,forecolor,outdent,indent,hr,charmap,emoticons,image,media,link,unlink,wp_help'
    			  });
    			
    			// write the correct reply-to id to the hidden field that stores it
    			// this prevents the wrong id inserted because we're returing false at the end of the function.
    			$('input#bbp_reply_to').val(parentId)
    			
    			// return false to prevent page reload, losing all the work.
    			return false; 
    		}
    	}

    Kineta
    Participant

    @kineta

    I achieved this by using jquery/javascript to set those fields to be hidden, then copy over the value from the field that’s visible to the hidden fields.

    I’ll post my code if you’d like. It’s easy enough to do.

    In reply to: bbPress 2.5.9

    Kineta
    Participant

    @kineta

    Where is the best place to log bugs? Thanks.


    Kineta
    Participant

    @kineta

    This is just what I need for the project I’m working on. I have the same question about how to do this without hacking the core files. Any guidance for a wordpress/bbpress beginner?


    Kineta
    Participant

    @kineta

    This is my code, fwiw. I don’t want any role but keymasters to add tags. Participant level is working as expected i.e *not* showing but the moderator level is still showing the tag field.

    add_filter( 'bbp_get_caps_for_role', 'my_bbp_role_caps', 10, 2 );
     
    function my_bbp_role_caps( $caps, $role ) {
       if ( $role == 'bbp_participant' ) {
          $caps['assign_topic_tags'] = false;
       }
       if ( $role == 'bbp_moderator' ) {
          $caps['assign_topic_tags'] = false;
       }
       return $caps;
    }
Viewing 25 replies - 1 through 25 (of 25 total)