Skip to:
Content
Pages
Categories
Search
Top
Bottom

Post On Buddypress Profile


  • Dono12
    Participant

    @dono12

    I wish the developers/contributors would add a post on profile button to show user posts in the next update. It makes sense to have this function as it incorporates WordPress and Buddypress respectively. There is only one plugin that I found which accomplished this feet:

    BP Posts On Profile

    by Huseyin Berberoglu. The plugin is out of date and it takes tons of modifications to get it going with an up to date Buddypress install.

    The second method is a block of code placed in functions.php

    function importSomething(){
    return include_once 'bp-custom.php';
    }
    add_action( 'bp_setup_nav', 'buddyboss_child_bp_nav_adder' );
    add_action( 'bp_template_content', 'profile_buddyboss_child_loop' );
    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    
    function buddyboss_child_bp_nav_adder() {
    global $bp;
    $post_count = count_user_posts_by_type( $bp->displayed_user->id );
    bp_core_new_nav_item(
    array(
    'name' => sprintf( __( 'Posts <span>%d</span>', 'my-poems' ), $post_count ),
    'slug' => 'Articles',
    'position' => 250,
    'show_for_displayed_user' => true,
    'screen_function' => 'buddyboss_child_list',
    'item_css_id' => 'articles',
    'default_subnav_slug' => 'public'
    ));
    }
    function buddyboss_child_list() {
    add_action( 'bp_template_content', 'profile_buddyboss_child_loop' );
    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    }
    /*------- This is end of the code for above function ---------*/
    function profile_buddyboss_child_loop() {
    $myposts = get_posts(  array(
    'posts_per_page' => -1,
    'author'         => bp_displayed_user_id(),
    'post_type'      => 'post'
    ));
    if( ! empty($myposts) ) { 
    foreach($myposts as $post) {
    setup_postdata( $post );
    if (has_post_thumbnail( $post->ID ) ):
    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'sidebar-smallthumbnew' );
    else :
    
    $image[0] = &quot;http://....com/wp-content/uploads/2015/10/userpost.jpg&quot;;
    endif;
    
    echo '<li class=&quot;sidebar mostpop post-' . $post->ID . '&quot;><span id=&quot;postimage&quot;><a>ID) . '&quot;><img src=&quot;' . $image[0] . '&quot; /></a></span><div id=&quot;postinfo&quot;><a>ID) . '&quot;>' . get_the_title($post->ID) . '</a></div></li>';
    }
    echo '</ul>';
    wp_reset_postdata();
    } else { ?>
    <div class=&quot;info&quot; id=&quot;message&quot;>
    <p><strong><?php bp_displayed_user_fullname(); ?></strong> has No posts.</p>
    </div>
    <?php }
    }
    /* This is end of the code for above function */
    remove_filter('bp_setup_nav','');
    function count_user_posts_by_type( $userid, $post_type = 'post' ) {
    global $wpdb;
    $where = get_posts_by_author_sql( $post_type, true, $userid, true);
    $count = $wpdb->get_var( &quot;SELECT COUNT(*) FROM $wpdb->posts $where&quot; );
    return apply_filters( 'get_usernumposts', $count, $userid );
    }

    This works fine but it’s quite limited. It also messes with Buddypress updates rendering the two latest Buddypress updates useless (Star message, and Upload Background image).

    Guys please get around to integrating this ability in Buddypress so one doesn’t have to spend hours searching and trouble shooting for a function which I believe and others should be an already main component.

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar