mattbru (@mattbru)

Forum Replies Created

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

  • mattbru
    Participant

    @mattbru

    Ill work on it some more and definitely post here if I figure out a solution.
    Thanks for all your help.


    mattbru
    Participant

    @mattbru

    Thank you!
    It now reloads the page okay. (doesnt appear to use ajax). So its not going to a 404 page. But id prefer it not to reload the page. Hm.


    mattbru
    Participant

    @mattbru

    Thanks Robin.

    I gave it a try.
    If i click the icon – It gives me a white page, basically a 404.
    But then i go back to the homepage and refresh and I get the normal page and whatever i clicked on looks like it toggles on/off fine. So it works but theres still an issue w/ the 404 page.

    I checked the php error log, and there’s nothing in there.
    Maybe Ill have to rewrite a whole new ajax function.


    mattbru
    Participant

    @mattbru

    Go to the homepage

    Topics


    Hover over the “critter gold” icon in upper right corner of the post image, you should get a popup tooltip. Then click it.

    Or, if you are on a single topic page like this:

    Bearded Dragon Care Guide


    You just click the “critter gold” icon in the upper right. Its the normal place where the “favorite” link usually is.


    mattbru
    Participant

    @mattbru

    Robin, Yes – I’ve dug pretty deep myself and it is all pretty complicated.

    I’ve tried the action you provided and it does not do anything different, unfortunately.

    Topics

    Earlier – I did try “hacking” (editing bbpress core plugin code) and changing the redirect as you did here with the hook. But I could not get it to stay on the homepage then either.

    Hm. Maybe its not possible? I coudlnt find the exact code where it was happening. I thought it was inside the bbp_favorites_handler() function located here: bbpress/includes/users/functions.php line 430 Looks like youre using that hook on line 481 (bbp_favorites_handler).

    I wonder if it has to do with either of these actions:
    template_redirect
    bbp_template_redirect

    I tried this modified version of your hook code:

    add_action( 'bbp_favorites_handler', 'tcdf_redirect_to_home_page' , 99, 1) ;
    function tcdf_redirect_to_home_page ($success) {
    	if ( true === $success && (is_front_page() || is_home() || is_page(2)) ) {
    		$redirect = home_url() ;
    		wp_safe_redirect( $redirect );
    		// For good measure
    		exit();
    	}		
    }

    No luck. 🙁


    mattbru
    Participant

    @mattbru

    Thank you for taking a look Robin.
    Below is the entire block of code for the post block.
    The lines youll be concerned with are 76-80 and 84-93. But ultimately it is line 92 <?php bbp_user_favorites_link($fav_args); ?>

    
    <?php
    /**
     * BuddyPress topic "query"
     * Show grid of all topics inside "ul.container"
     * @link http://hookr.io/plugins/bbpress/2.5.9/functions/bbp_has_topics/
     * 
     */
    	$topic_id = bbp_get_topic_id();
    	$forum_id = bbp_get_topic_forum_id($topic_id);
    	$date = bbp_get_topic_post_date($topic_id,true);
    	$time = reformat_bbp_post_time($date);
    
    	$title = bbp_get_topic_title();
    		$content = strip_tags(bbp_get_topic_content());
    		$content = trim(preg_replace('/^[ \t]*[\r\n]+/m','',$content)); 
    		$content = preg_replace('/(Attachments:).*$/','',$content); 
    		$content = preg_replace('/(This topic was modified).*$/m','',$content); 
    		$excerpt = getSummary($content,186);
    
    	$forum_title = get_post_field( 'post_title', $forum_id, 'raw' );
    	$forum_link = bbp_get_forum_permalink( $forum_id );
    	
    	$user_id = get_post_field('post_author', $topic_id);
    	$avatar = get_avatar( $user_id, 30 );
    	$author_name = esc_html( get_the_author_meta( 'display_name', $user_id ) );
    	
    	$voice_count = bbp_get_topic_voice_count($topic_id);
    	$voice_label = $voice_count === 1 ? 'voice' : 'voices';
    	$reply_count = bbp_get_topic_reply_count($topic_id);
    	$reply_label = $reply_count === 1 ? 'comment' : 'comments';
    	$image_size = 'post-featured';
    
    	// get topic post featured image
    	$src = wp_get_attachment_image_src( get_post_thumbnail_id($topic_id), $image_size);
    	$imgsrc = get_the_post_thumbnail($topic_id) != '' ? $src[0] : '';
    	$image_type = 'img';
    	$has_image = true;
    
    	// attempt to get the file attachment
    	$attachments = d4p_get_post_attachments($topic_id);
    	$attachment_url = wp_get_attachment_image_src( $attachments[0]->ID, $image_size);
    	$attachment_url = $attachment_url[0];
    
    	$cn = d4p_topic_attachments_count($topic_id);
    	
    	// if its empty, set src as attachment url
    	if ($imgsrc == '' && !empty($attachment_url)) {
    		$imgsrc = $attachment_url;
    		$image_type = 'bg-img attachment';
    	}
    	
    	// if its still empty, set src as first image found in the post
    	if (empty($imgsrc)) {
    		/**
    		 * catch_that_image()
    		 * Gets the first image in the body of the post
    		 * defined in /library/custom-theme-functions.php
    		 */
    		$imgsrc = catch_that_image($title,true);
    		if (empty($imgsrc)) {
    			$has_image = false;
    			$image_type = 'none';
    		} else {
    			$image_type = 'bg-img catch';
    		}
    	}
    
    	$is_ss = bbp_is_topic_super_sticky() ? 'super-sticky' : 'not-super-sticky';
    	$bgcolor = get_post_meta( $topic_id, 'sticky_post_color', $single = false );
    	$bgcolor = (!empty($bgcolor)) ? $bgcolor[0] : '';
    
    	if (!empty($bgcolor)) {
    		$image_type .= ' color-'.$bgcolor;
    	}
    
    	// gold count
    	$gold_count = bbp_get_topic_favoriters($topic_id);
    	$gold_count = count($gold_count);
    	$before_html = '<span class="gold-count">'.$gold_count.'</span>';
    	$fav_args = array('before' => $before_html);
    
    ?>
    	<li class="fourth a <?php echo $image_type; ?>" data-id="<?php echo $topic_id; ?>" data-userid="<?php echo $user_id; ?>" data-sticky="<?php echo $is_ss; ?>">
    		<?php if (!is_user_logged_in()) : ?>
    			<span id="favorite-toggle">
    				<?php echo $before_html; ?>
    				<span id="favorite-<?php echo $topic_id ?>" data-tooltip="Give Critter Gold">
    					<a href="#" class="favorite-toggle" data-topic="<?php echo $topic_id ?>" rel="nofollow">Favorite</a>
    				</span>
    			</span>
    		<?php else : ?>
    			<?php bbp_user_favorites_link($fav_args); ?>
    		<?php endif; ?>
    		
    		<a class="bbp-topic-permalink" href="<?php bbp_topic_permalink(); ?>">
    			<figure <?php if($has_image) : ?> style="background-image: url('<?php echo $imgsrc; ?>');"<?php endif; ?> class="<?php if(!$has_image) { echo 'no-img'; } ?>">
    			<?php if ($has_image) : ?>
    				<img src="<?php echo $imgsrc; ?>" alt="<?php echo $title; ?>">
    			<?php else : ?>
    				<h3><?php echo $title; ?></h3>
    			<?php endif; ?>
    				<span class="meta-inside">
    					<span class="read">Read Post</span>
    					<span class="data">
    						<span class="replies"><?php echo $reply_count; ?> <?php echo $reply_label; ?></span>
    					</span>
    					<span class="author">Started By <?php echo $avatar; ?> <?php echo $author_name; ?></span>
    				</span>
    			</figure>
    			<!-- <a href="<?php echo $forum_link; ?>"><?php echo $forum_title; ?></a> |  -->
    			<figcaption>
    			<?php if ($has_image) : ?>
    				<h3><?php echo $title; ?></h3>
    			<?php endif; ?>
    				<span class="meta">
    					<span class="category"><?php echo $forum_title; ?></span><span> | </span>
    <?php /*
    					<span><?php echo $voice_count; ?> <?php echo $voice_label; ?></span> | 
    */ ?>
    					<span class="comments"><?php echo $reply_count; ?> <?php echo $reply_label; ?></span> |
    					<time><?php echo $time; ?></time>
    				</span>
    			<?php if ($has_image) : ?>
    				<p><?php echo $excerpt; ?></p>
    			<?php endif; ?>
    			</figcaption>
    		</a>
    	</li>
    

    mattbru
    Participant

    @mattbru

    Okay, I GOT IT!
    The key is to compare the topic id and the reply id. If they are equal, then its the first reply in bbpress.

    Here is my full solution:

    <?php
    function add_content_before_first_reply_content($content,$id){
    
    	$post = get_post($id);
    	$topic_id = bbp_get_topic_id();
    	$reply_id = bbp_get_reply_id();
    	$content_to_add = '';
    
    	if ($topic_id === $reply_id) {
    		// do whatever you need to in  here
    		$content .= $content_to_add;
    	}
    
    	return $content;
    
    }
    add_filter( 'bbp_get_reply_content', 'add_content_before_first_reply_content', 99, 2 );

    mattbru
    Participant

    @mattbru

    Thank you Robin W. But that does not work.

    $count = get_post_meta($topic_id, '_bbp_reply_count', false);
    is the same as
    $count = bbp_get_topic_reply_count($topic_id);
    Except the second one returns a number, first one gives you an array.
    The results of what you suggested gives me array([0]=>6) , meaning there are six replies to the topic.

    If you do a conditional like this: if ($count === 0) { // then code } , its only going to run the code if there are no replies to the post. That’s not what I need.

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