[buddypress-trac] [BuddyPress Trac] #6736: Allow users to create WP posts on Buddypress Profile

buddypress-trac noreply at wordpress.org
Sat Jul 8 13:13:10 UTC 2017


#6736: Allow users to create WP posts on Buddypress Profile
--------------------------+----------------------
 Reporter:  Dono12        |       Owner:
     Type:  enhancement   |      Status:  closed
 Priority:  normal        |   Milestone:
Component:  Members       |     Version:  2.4.0
 Severity:  normal        |  Resolution:  invalid
 Keywords:  dev-feedback  |
--------------------------+----------------------

Old description:

> Can the developers/contributors 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:
>
> <a href="https://wordpress.org/plugins/bp-posts-on-profile/">BP Posts On
> Profile</a>
>
> 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] = "http://www.movemie.com/wp-
> content/uploads/2015/10/userpost.jpg";
> endif;
>
> echo '<li class="sidebar mostpop post-' . $post->ID . '"><span
> id="postimage"><a href="' . get_permalink($post->ID) . '"><img src="' .
> $image[0] . '" /></a></span><div id="postinfo"><a href="' .
> get_permalink($post->ID) . '">' . get_the_title($post->ID) .
> '</a></div></li>';
> }
> echo '</ul>';
> wp_reset_postdata();
> } else { ?>
> <div class="info" id="message">
> <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( "SELECT COUNT(*) FROM $wpdb->posts $where" );
> 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.

New description:

 Can the developers/contributors 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:

 <a href="https://wordpress.org/plugins/bp-posts-on-profile/">BP Posts On
 Profile</a>

 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] = "http://www.example.com/wp-
 content/uploads/2015/10/userpost.jpg";
 endif;

 echo '<li class="sidebar mostpop post-' . $post->ID . '"><span
 id="postimage"><a href="' . get_permalink($post->ID) . '"><img src="' .
 $image[0] . '" /></a></span><div id="postinfo"><a href="' .
 get_permalink($post->ID) . '">' . get_the_title($post->ID) .
 '</a></div></li>';
 }
 echo '</ul>';
 wp_reset_postdata();
 } else { ?>
 <div class="info" id="message">
 <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( "SELECT COUNT(*) FROM $wpdb->posts $where" );
 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.

--

Comment (by boonebgorges):

 Changed.

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/6736#comment:6>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list