Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'code'

Viewing 25 results - 5,626 through 5,650 (of 32,518 total)
  • Author
    Search Results
  • #180403
    TheDream18
    Participant

    Hello,

    I used this code for clear Topic info. To show topic is not supported yet, only creater topic voices in current. I checked code was correct, but it did not work, anyone can help please?

    function none_people_discuss() {
    $voice_count = bbp_get_topic_voice_count();

    if ( $voice_count = 1 )
    echo ‘<span class=”no_support”>[No support]</span>’;
    }

    add_action( ‘bbp_theme_before_topic_title’, ‘ none_people_discuss’ );

    kajzh
    Participant

    Hello,

    I am running bbPress v2.5.12 on WordPress 4.7 with a child theme I’ve developed based on Imaginem Themes’ Sentric Theme.

    The problem:
    In my child theme’s functions, I have added the following code to make two custom roles, Professional and Member, for my Q&A/”Ask the Expert”-style forum called “Ask a Professional.” Essentially, Members can make threads asking questions, but only screened Professionals have the ability to reply and provide answers.

    I want everyone to automatically be assigned the Member role upon registration. Then I can manually “upgrade” their roles to Professional once they’ve been successfully screened. However, when a user registers and logs in, they inherit Member capabilities, but are not assigned the Member role. Manually selecting the user and assigning them the Member role doesn’t work; their role immediately reverts back to “— No role for these forums —”
    screenshot

    When I select the user and manually assign the Participant role, the role “sticks” — meaning, it doesn’t revert back to “No Role.” However, the “Member” capabilities remain.

    screenshot

    Does anyone know why this problem persists and how to fix it? This is the final thing that needs to be ironed out before my site goes live. 🙂 Thank you!

    //code to add custom roles 
     
    function add_new_roles( $bbp_roles )
    {
        /* Add a role called professional */
        $bbp_roles['bbp_professional'] = array(
            'name' => 'Professional',
            'capabilities' => custom_capabilities( 'bbp_professional' )
            );
     
        /* Add a role called member */
        $bbp_roles['bbp_member'] = array(
            'name' => 'Member',
            'capabilities' => custom_capabilities( 'bbp_member' )
            );
     
        return $bbp_roles;
    }
     
    add_filter( 'bbp_get_dynamic_roles', 'add_new_roles', 1 );
     
    function add_role_caps_filter( $caps, $role )
    {
        /* Only filter for roles we are interested in! */
        if( $role == 'bbp_professional' )
            $caps = custom_capabilities( $role );
     
        if( $role == 'bbp_member' )
            $caps = custom_capabilities( $role );
     
        return $caps;
    }
     
    add_filter( 'bbp_get_caps_for_role', 'add_role_caps_filter', 10, 2 );
     
    function custom_capabilities( $role )
    {
        switch ( $role )
        {
     
            /* Capabilities for 'professional' role */
            case 'bbp_professional':
                return array(
                     'spectate'              => true,
                    'participate'           => true,
                    'moderate'              => false,
                    'throttle'              => false,
                    'view_trash'            => false,
     
                    // Forum caps
                    'publish_forums'        => false,
                    'edit_forums'           => false,
                    'edit_others_forums'    => false,
                    'delete_forums'         => false,
                    'delete_others_forums'  => false,
                    'read_private_forums'   => true,
                    'read_hidden_forums'    => true,
     
                    // Topic caps
                    'publish_topics'        => true,
                    'edit_topics'           => true,
                    'edit_others_topics'    => false,
                    'delete_topics'         => true,
                    'delete_others_topics'  => true,
                    'read_private_topics'   => true,
     
                    // Reply caps
                    'publish_replies'       => true,
                    'edit_replies'          => true,
                    'edit_others_replies'   => false,
                    'delete_replies'        => false,
                    'delete_others_replies' => false,
                    'read_private_replies'  => true,
     
                    // Topic tag caps
                    'manage_topic_tags'     => true,
                    'edit_topic_tags'       => true,
                    'delete_topic_tags'     => true,
                    'assign_topic_tags'     => true,
                );
     
                /* Capabilities for 'member' role */
            case 'bbp_member':
                return array(
                    // Primary caps
                    'spectate'              => true,
                    'participate'           => true,
                    'moderate'              => false,
                    'throttle'              => false,
                    'view_trash'            => false,
     
                    // Forum caps
                    'publish_forums'        => false,
                    'edit_forums'           => false,
                    'edit_others_forums'    => false,
                    'delete_forums'         => false,
                    'delete_others_forums'  => false,
                    'read_private_forums'   => true,
                    'read_hidden_forums'    => false,
     
                    // Topic caps
                    'publish_topics'        => true,
                    'edit_topics'           => true,
                    'edit_others_topics'    => false,
                    'delete_topics'         => false,
                    'delete_others_topics'  => false,
                    'read_private_topics'   => true,
     
                    // Reply caps
                    'publish_replies'       => false,
                    'edit_replies'          => false,
                    'edit_others_replies'   => false,
                    'delete_replies'        => false,
                    'delete_others_replies' => false,
                    'read_private_replies'  => true,
     
                    // Topic tag caps
                    'manage_topic_tags'     => false,
                    'edit_topic_tags'       => false,
                    'delete_topic_tags'     => false,
                    'assign_topic_tags'     => false,
                );
     
                break;
     
            default :
                return $role;
        }
    }

    Troubleshooting:

    1. I’ve tried to disable plugins and see if any of them are causing this issue. This hasn’t yielded any different results.
    2. I’ve checked with the Twenty Sixteen and Twenty Seventeen theme.
    #180384
    Robin W
    Moderator

    quickest way is to add this to your .css file

    .bbp-topic-started-by {
      display: none;
    }
    #180383
    Robin W
    Moderator

    I found that the above code took away the Forums, Topics and Replies from the dashboard in bbpress.

    I found some other code and modified it as follows

    /**
      * Add REST API support to an already registered post type.
      */
      add_action( 'init', 'rew_custom_post_type_rest_support', 25 );
      
      function rew_custom_post_type_rest_support() {
      	global $wp_post_types;
      
      	$post_type_name =  bbp_get_reply_post_type();
      	if( isset( $wp_post_types[ $post_type_name ] ) ) {
      		$wp_post_types[$post_type_name]->show_in_rest = true;
      		$wp_post_types[$post_type_name]->rest_base = $post_type_name;
      		$wp_post_types[$post_type_name]->rest_controller_class = 'WP_REST_Posts_Controller';
      	}
    	$post_type_name =  bbp_get_topic_post_type();
      	if( isset( $wp_post_types[ $post_type_name ] ) ) {
      		$wp_post_types[$post_type_name]->show_in_rest = true;
      		$wp_post_types[$post_type_name]->rest_base = $post_type_name;
      		$wp_post_types[$post_type_name]->rest_controller_class = 'WP_REST_Posts_Controller';
      	}
    	$post_type_name =  bbp_get_forum_post_type();
      	if( isset( $wp_post_types[ $post_type_name ] ) ) {
      		$wp_post_types[$post_type_name]->show_in_rest = true;
      		$wp_post_types[$post_type_name]->rest_base = $post_type_name;
      		$wp_post_types[$post_type_name]->rest_controller_class = 'WP_REST_Posts_Controller';
      	}
    	  
      }


    @barryhughes-1
    – thoughts – can this be done better?

    #180378

    Topic: PHP Warnings

    in forum Installation
    avalanche
    Participant

    I’m receiving a php warning when I go to http://scafra.org/
    Warning: ksort() expects parameter 1 to be array, object given in /home/content/p3pnexwpnas01_data01/45/3635545/html/wp-content/plugins/bbpress/includes/core/template-functions.php on line 316

    When I go to /wp-login.php I receive these warnings:
    Warning: ksort() expects parameter 1 to be array, object given in /home/content/p3pnexwpnas01_data01/45/3635545/html/wp-content/plugins/bbpress/includes/core/template-functions.php on line 316

    Warning: Cannot modify header information - headers already sent by (output started at /home/content/p3pnexwpnas01_data01/45/3635545/html/wp-content/plugins/bbpress/includes/core/template-functions.php:316) in /home/content/p3pnexwpnas01_data01/45/3635545/html/wp-login.php on line 394

    Warning: Cannot modify header information - headers already sent by (output started at /home/content/p3pnexwpnas01_data01/45/3635545/html/wp-content/plugins/bbpress/includes/core/template-functions.php:316) in /home/content/p3pnexwpnas01_data01/45/3635545/html/wp-login.php on line 407

    After I attempt to login, I receive an error that my password is incorrect, and then I receive these warnings:
    Warning: ksort() expects parameter 1 to be array, object given in /home/content/p3pnexwpnas01_data01/45/3635545/html/wp-content/plugins/bbpress/includes/core/template-functions.php on line 316

    Warning: Cannot modify header information - headers already sent by (output started at /home/content/p3pnexwpnas01_data01/45/3635545/html/wp-content/plugins/bbpress/includes/core/template-functions.php:316) in /home/content/p3pnexwpnas01_data01/45/3635545/html/wp-login.php on line 394

    Warning: Cannot modify header information - headers already sent by (output started at /home/content/p3pnexwpnas01_data01/45/3635545/html/wp-content/plugins/bbpress/includes/core/template-functions.php:316) in /home/content/p3pnexwpnas01_data01/45/3635545/html/wp-login.php on line 407

    Warning: Cannot modify header information - headers already sent by (output started at /home/content/p3pnexwpnas01_data01/45/3635545/html/wp-content/plugins/bbpress/includes/core/template-functions.php:316) in /home/content/p3pnexwpnas01_data01/45/3635545/html/wp-includes/pluggable.php on line 893

    Warning: Cannot modify header information - headers already sent by (output started at /home/content/p3pnexwpnas01_data01/45/3635545/html/wp-content/plugins/bbpress/includes/core/template-functions.php:316) in /home/content/p3pnexwpnas01_data01/45/3635545/html/wp-includes/pluggable.php on line 894

    Warning: Cannot modify header information - headers already sent by (output started at /home/content/p3pnexwpnas01_data01/45/3635545/html/wp-content/plugins/bbpress/includes/core/template-functions.php:316) in /home/content/p3pnexwpnas01_data01/45/3635545/html/wp-includes/pluggable.php on line 895

    Although I can’t login via WordPress, I can FTP, but I’m not sure what to change.

    #180373
    Sadegh Hosseini
    Participant

    Hi,
    Is there any plugin (or code) to create admin per forum that each admin can moderate only his forum and don’t have moderation tools for other forums.
    Thanks

    #180355
    Alex Stine
    Participant

    Hello,

    I have a custom user meta field which is a staff label field. For people with “staff” capability, they can go to their profile in WP admin and enter some text for a label such as “Lead Developer, Writer, Support, etc. I would like to output this label on BBPress profile but cannot figure out how to do it. I am using the currently displayed profile ID. In the following file:
    /wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/members/single/members-header.php

    I know it’s bad to hack core files, I will move to my themes folder once it’s working. This is the code I have currently.

    <?php
    $member_id = bp_displayed_user_id();
    if ( user_can( $member_id, 'staff' ) ) {
    if ( get_the_author_meta( 'staff') ) {
    $x = ( get_the_author_meta( 'staff', $member_id ) == '' ) ? "Staff" : get_the_author_meta( 'staff', $member_id );
    echo '<div class="staff-label">';
    echo $x ;
    echo '</div>';
    } 
    } ?>

    This code is working fine in the comments area with different logic to grab the user ID, just not working for BuddyPress. Any suggestions?

    Thanks. 🙂

    #180354
    oyegigi
    Participant

    In case someone wants to use the code who is using pretty links.

    
    // Generate BBporess Edit Profile Link in a shortcode
    // [bbp_edit_profile text="Edit My Profile" class"my-link-style"]
    
    function bbp_edit_profile_link($atts) {
    	extract(shortcode_atts(array(
    		'text' => "",  // default value if none supplied
    		'class' => "" //Style class for link
        ), $atts));
        
        if ($text) {
    		$current_user = wp_get_current_user (); 
    		$user=$current_user->user_login;
            return '<a class="'. $class . '" href="/forums/users/' . $user . '/edit">' . $text. '</a>';
            
        } 
    }
    add_shortcode('bbp_edit_profile', 'bbp_edit_profile_link');
    
    #180351
    King-Nothing
    Participant

    I totally forgot about this thread.

    I fixed it with css:

    nav .menu li a span {
    display: none;
    font-size: 10px;
    font-weight: 400;
    opacity: 0.6;
    }

    But I guess it would be better to edit some code instead?

    Url is: http://testsentralen.no/nyfotoblogg2/

    #180341
    grimbot
    Participant

    Hi, at the top of the pages of this forum, an error shows up. It says:

    Continue reading→” />

    This error would show up from time to time on user created pages when there was a format issue. To fix it there, I would just jiggle the code around until the error went away.

    The forum pages are not user created though so I’m not sure how to clear this error.

    #180338
    scotth454
    Participant

    I am getting mine started up an have spent most of my saturday with the same problem. action-modeler.com

    <li id="menu-item-1016" class="menu-item menu-item-type-post_type_archive menu-item-object-forum menu-item-1016"><a>All Forums<span class="menu-tag">bbPress Forums</span></a></li>

    menu manager

    Adding a second all forums menu doesn’t have the extra “bbPress Forums”.

    Well I figured out setting it as a page to get the all forums. Apparently using the all forums from the “Forums” in menu manager is bugged.

    #180334
    Barry
    Participant

    …A PHP 5.2-friendly version that also covers the reply and forum post types:

    function bbpress_enable_rest_api_support() {
    	$enable_rest = array( 'show_in_rest' => true );
    	register_post_type( bbp_get_reply_post_type(), $enable_rest );
    	register_post_type( bbp_get_topic_post_type(), $enable_rest );
    	register_post_type( bbp_get_forum_post_type(), $enable_rest );
    }
    
    add_action( 'bbp_register_post_types', 'bbpress_enable_rest_api_support', 11 );
    #180333
    Barry
    Participant

    To enable default REST API support for topics you could use a snippet like this one:

    add_action( 'bbp_register_post_types', function() {
    	register_post_type( bbp_get_topic_post_type(), [ 'show_in_rest' => true ] );
    }, 11 );

    This waits until bbPress has registered its post types, then modifies the properties of the topic post type so that it is exposed via the REST API. You could of course extend it to cover forum and reply posts, too. With that in place, you should find URLs like the following work as expected:

    http://bbpress.site/wp-json/wp/v2/topic

    #180329
    Robin W
    Moderator

    ok, I’ve found a link to some code that doesn’t entirely make sense yet, but gives me some clues, but I’ll do some more digging over the next few days.

    #180328

    In reply to: Random Topic Link

    Stephen Edgar
    Keymaster

    @ johnskennedy You’re spot on, creating 8 functions is one way to do that, you’d need to make sure that each function name is unique.

    That said, the above is one way, another way is to use some conditional logic with some if/else statements which is a little trickier, possibly more fun though to update the function in this way even 😉

    See these codex docs for sme very initial hints:
    https://codex.wordpress.org/Conditional_Tags
    https://codex.bbpress.org/bbpress-conditional-tags/

    #180319
    davemiller58
    Participant

    I have the same problem as you – the shortcodes don’t work.

    I did what you said here – reset the forums – but no change – the same problem.

    Still not working …

    #180318

    In reply to: Random Topic Link

    johnskennedy
    Participant

    I have used Stephen’s code above and it works perfectly.

    However, I have 8 forums on my site so if I wanted to add a random button for each separate forum that only selects topics from that forum would I have to create 8 different function ntwb_bbpress_random_single_topic() in my .php and include only a single forum ID every time or is there a better way to implement this? Also, how and where would I add the shortcodes so that they only show on the relevant forum?

    #180317
    davemiller58
    Participant

    Am using:

    Twentythirteen wordpress theme

    bbPress – Version 2.5.12

    With bbPress I have created a number of forums

    But – when I put the following short code into a page:
    [bbp-forum-index]

    it shows nothing …

    Please – what am I doing wrong?

    #180313
    casamia743
    Participant

    I have same problem. Here is my error log

    [06-Jan-2017 10:47:16 UTC] PHP Fatal error:  Uncaught Error: [] operator not supported for strings in /Applications/MAMP/htdocs/wordpress/wp-content/plugins/bbpress/includes/forums/functions.php:1800
    Stack trace:
    #0 /Applications/MAMP/htdocs/wordpress/wp-includes/class-wp-hook.php(298): bbp_pre_get_posts_normalize_forum_visibility(Object(WP_Query))
    #1 /Applications/MAMP/htdocs/wordpress/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters('', Array)
    #2 /Applications/MAMP/htdocs/wordpress/wp-includes/plugin.php(515): WP_Hook->do_action(Array)
    #3 /Applications/MAMP/htdocs/wordpress/wp-includes/class-wp-query.php(1681): do_action_ref_array('pre_get_posts', Array)
    #4 /Applications/MAMP/htdocs/wordpress/wp-includes/class-wp-query.php(3238): WP_Query->get_posts()
    #5 /Applications/MAMP/htdocs/wordpress/wp-includes/class-wp.php(617): WP_Query->query(Array)
    #6 /Applications/MAMP/htdocs/wordpress/wp-includes/class-wp.php(735): WP->query_posts()
    #7 /Applications/MAMP/htdocs/wordpress/wp-includes/functions.php(955): WP->main(Array)
    #8 /Applications/MAMP/htdoc in /Applications/MAMP/htdocs/wordpress/wp-content/plugins/bbpress/includes/forums/functions.php on line 1800
    #180306
    Wilbur
    Participant

    Thanks. I tried http://MY_SITE.COM/wp-json/wp/v2/posts?filter[type]=topic and http://MY_SITE.COM/wp-json/wp/v2/posts?filter[type]=forum but the filter appeared not to work as blog posts was returned. Please not that I have already installed the plugin.

    #180305
    mth75
    Participant

    Hi all,

    I added an easy New Topic button (after reading a lot of other possible solutions):

    New Topic button

    Add to your loop-topics.php template (before the actual loop):

    <?php if (!is_user_logged_in() ) :?>
    <?php else : ?>
    <div class="new-topic">
    	<input type="submit" name="submit" value="New Topic"  onclick="location.href='#new-post';">
    </div>
    <?php endif; ?>

    Add some css for styling when needed:

    .new-topic {  
    	position: relative;
    	z-index:1;
    	float: right;
    }

    Regards,

    Marc

    mth75
    Participant

    Hi all,

    I’m trying to integrate the BuddyPress favorite (aka like system) system with BBPress.

    On my site: http://www.starry-night.nl I use the BuddyPress Activity page as homepage, this means that forum topics and replies are
    shown on the activity wall, and can be liked.

    SN Activity (Home) Page

    For easy navigation I made a custom “comment” button which links to the BBPress topic or reply. BBPress activity items (topics or replies)
    can be liked.

    Going to a forum topic of replies of course doesn’t show any likes in the BBPress topic and replies.

    SN Topic/Replies

    Integrating the BuddyPress favorite system with BBPress is at least in my mind the cleanest way and from a functionality point of view, the way
    to go.

    On the BuddyPress forum I found the following code (below) which implements the BuddyPress favorite button in blogpost (and this works), so a rewrite
    should be possible to make this work for BBPress.

    In single.php for blogpost and in the future in the loop-single-reply.php for BBPress.

    <?php echo get_fav_or_unfav_button_for_post( $post ); ?>

    In function.php:

    / Buddypress favorites
    function get_fav_or_unfav_button_for_post( $post ) {
    global $bp, $activities_template;
            // user is not logged ? Show nothing.
    	if ( ! is_user_logged_in() ) {
    	return '';
    	}
    	
    	$activity_id = bp_activity_get_activity_id( array(
    		'user_id' => $post->post_author,
    		'type' => 'new_blog_post',
    		'component' => 'blogs',
    		'item_id' => 1,
    		'secondary_item_id' => $post->ID
    		) );
    	
    	if ( ! $activity_id ) {
    	return '';
    	}
    	
    		bp_has_activities(); // update $activities_template of user's fav
    		$old_value = false;
    		
    		if ( isset( $activities_template->activity->id ) ) {
    		$old_value = $activities_template->activity->id;
    		$activities_template->activity->id = $activity_id;
    		} else {
    		$activities_template->activity = (object) array( 'id' => $activity_id );
    		}
    	
    		// building the template
    	$code = '';
    	$code .= '<div class="activity-meta">'."\n";
    
    		if ( ! bp_get_activity_is_favorite() ) {
    		// if not favorited, add a fav button
    		$code .= ' <a href="'.bp_get_activity_favorite_link( ).'" class="button fav bp-secondary-action" title="'.__( 'Like', 'buddypress' ).'">'.__( 'Like', 'buddyboss' ).'</a>'."\n";
    		
    		} else {
    		
    		// if already favorited, a button to unfav
    		$code .= ' <a href="'.bp_get_activity_unfavorite_link( ).'" class="button unfav bp-secondary-action" title="'.__( 'Unlike', 'buddypress' ).'">'.__( 'Unlike', 'buddyboss' ).'</a>'."\n";
    		
    		// bonus button to show user's all favs
    		$code .= ' <a href="'.bp_loggedin_user_domain() . 'activity/favorites/" class="button unfav bp-secondary-action">'.__( 'My Likes', 'buddyboss' ).'</a>'."\n";
    		}
    		
    		// closing .activity-meta
    	$code .= '</div>'."\n"; 
    
    		if ( false !== $old_value ) {
    		$activities_template->activity->id = $old_value;
    		} else {
    		$activities_template->activity = null;
    		}
    	return $code;
    }

    I’m having problems with rewriting the array for bbpress:

    $activity_id = bp_activity_get_activity_id( array(
    		'user_id' => $post->post_author,
    		'type' => 'new_blog_post',
    		'component' => 'blogs',
    		'item_id' => 1,
    		'secondary_item_id' => $post->ID
    		) );

    Help for figuring this one out is appreciated.

    Best regards,

    Marc

    #180299
    aaronbennett2097
    Participant

    I’d like to display a list of the last 5 topics the logged in user has contributed to, either by starting the topic, or replying to it.

    This is to go on a summary page for the user, so can either be shortcode or by creating a tepmplate.

    Any ideas would be appreciated.

    #180298
    roquec
    Participant

    Dear Friends,

    I’m using WP 4.7 and bbPress 2.5.12. I’m using the importer under Tools->Forums->Import forums to import a MyBB Forum (version 1.6), with 4000 topics, 50.000 messages, and 3000 users.

    The performance is Ok, it takes two hours more or less. The problem, is that at certain point, the message Conversion complete is displayed, and certainly, the users / topics count is the right one. And then, without my interaction, it starts again.

    I’m not sure if this “second pass” is the normal procedure, or it is an error.

    Any help would be very appreciate.

    That’s the output of my last attempt

    Calculating forum hierarchy (0 - 999)Converting forums (0 - 999)Delete users WordPress default passwords (5000 - 5999)Delete users WordPress default passwords (4000 - 4999)Delete users WordPress default passwords (3000 - 3999)Delete users WordPress default passwords (2000 - 2999)Delete users WordPress default passwords (1000 - 1999)Delete users WordPress default passwords (0 - 999)Converting users (2000 - 2999)Converting users (1000 - 1999)Converting users (0 - 999)<strong>Conversion Complete</strong>No reply_to parents to convertConverting replies (3000 - 3999)Converting replies (2000 - 2999)Converting replies (1000 - 1999)Converting replies (0 - 999)No tags to convertNo super stickies to stickCalculating topic stickies (0 - 999)Converting topics (51000 - 51999)Converting topics (50000 - 50999)Converting topics (49000 - 49999)Converting topics (48000 - 48999)Converting topics (47000 - 47999)Converting topics (46000 - 46999)Converting topics (45000 - 45999)Converting topics (44000 - 44999)Converting topics (43000 - 43999)Converting topics (42000 - 42999)Converting topics (41000 - 41999)Converting topics (40000 - 40999)Converting topics (39000 - 39999)Converting topics (38000 - 38999)Converting topics (37000 - 37999)Converting topics (36000 - 36999)Converting topics (35000 - 35999)Converting topics (34000 - 34999)Converting topics (33000 - 33999)Converting topics (32000 - 32999)Converting topics (31000 - 31999)Converting topics (30000 - 30999)Converting topics (29000 - 29999)Converting topics (28000 - 28999)Converting topics (27000 - 27999)Converting topics (26000 - 26999)Converting topics (25000 - 25999)Converting topics (24000 - 24999)Converting topics (23000 - 23999)Converting topics (22000 - 22999)Converting topics (21000 - 21999)Converting topics (20000 - 20999)Converting topics (19000 - 19999)Converting topics (18000 - 18999)Converting topics (17000 - 17999)Converting topics (16000 - 16999)Converting topics (15000 - 15999)Converting topics (14000 - 14999)Converting topics (13000 - 13999)Converting topics (12000 - 12999)Converting topics (11000 - 11999)Converting topics (10000 - 10999)Converting topics (9000 - 9999)Converting topics (8000 - 8999)Converting topics (7000 - 7999)Converting topics (6000 - 6999)Converting topics (5000 - 5999)Converting topics (4000 - 4999)Converting topics (3000 - 3999)Converting topics (2000 - 2999)Converting topics (1000 - 1999)Converting topics (0 - 999)Calculating forum hierarchy (0 - 999)Converting forums (0 - 999)Delete users WordPress default passwords (2000 - 2999)Delete users WordPress default passwords (1000 - 1999)Delete users WordPress default passwords (0 - 999)Converting users (2000 - 2999)Converting users (1000 - 1999)Converting users (0 - 999)Starting Conversion

    #180279
    mth75
    Participant

    The trick is to relate the activity ID to the Post ID of the forum topic or reply. This code (used for liking (aka favouriting) ) blogpost works. I’m trying to rewrite it for bbpress

    In single.php:

    <?php echo get_fav_or_unfav_button_for_post( $post ); ?>

    In function.php:

    // Buddypress favorites
    function get_fav_or_unfav_button_for_post( $post ) {
    global $bp, $activities_template;
            // user is not logged ? Show nothing.
    	if ( ! is_user_logged_in() ) {
    	return '';
    	}
    	
    	$activity_id = bp_activity_get_activity_id( array(
    		'user_id' => $post->post_author,
    		'type' => 'new_blog_post',
    		'component' => 'blogs',
    		'item_id' => 1,
    		'secondary_item_id' => $post->ID
    		) );
    	
    	if ( ! $activity_id ) {
    	return '';
    	}
    	
    		bp_has_activities(); // update $activities_template of user's fav
    		$old_value = false;
    		
    		if ( isset( $activities_template->activity->id ) ) {
    		$old_value = $activities_template->activity->id;
    		$activities_template->activity->id = $activity_id;
    		} else {
    		$activities_template->activity = (object) array( 'id' => $activity_id );
    		}
    	
    		// building the template
    	$code = '';
    	$code .= '<div class="activity-meta">'."\n";
    
    		if ( ! bp_get_activity_is_favorite() ) {
    		// if not favorited, add a fav button
    		$code .= ' <a href="'.bp_get_activity_favorite_link( ).'" class="button fav bp-secondary-action" title="'.__( 'Like', 'buddypress' ).'">'.__( 'Like', 'buddyboss' ).'</a>'."\n";
    		
    		} else {
    		
    		// if already favorited, a button to unfav
    		$code .= ' <a href="'.bp_get_activity_unfavorite_link( ).'" class="button unfav bp-secondary-action" title="'.__( 'Unlike', 'buddypress' ).'">'.__( 'Unlike', 'buddyboss' ).'</a>'."\n";
    		
    		// bonus button to show user's all favs
    		$code .= ' <a href="'.bp_loggedin_user_domain() . 'activity/favorites/" class="button unfav bp-secondary-action">'.__( 'My Likes', 'buddyboss' ).'</a>'."\n";
    		}
    		
    		// closing .activity-meta
    	$code .= '</div>'."\n"; 
    
    		if ( false !== $old_value ) {
    		$activities_template->activity->id = $old_value;
    		} else {
    		$activities_template->activity = null;
    		}
    	return $code;
    }
Viewing 25 results - 5,626 through 5,650 (of 32,518 total)
Skip to toolbar