WikiPro and BuddyPress activity stream

Does anybody know how I can make WikiPro appear in the activity stream?

i.e. User has published 'wiki'
User has edited 'wiki'

etc

Any help appreciated!

  • Patrick
    • Support Monkey

    Hi there @Alex

    Welcome to WPMU DEV, glad to have you aboard!

    Yes indeedy! That possibility is actually built into BuddyPress since version 2.2. But you'll need to add a bit of code yourself to your bp-custom.php file to specify the post-type(s), and customize the generic "posted a new item" activity entry message.

    You'll find all the info you need in the BuddyPress codex here:
    https://codex.buddypress.org/plugindev/post-types-activities/#use-add_post_type_support-post_type-buddypress-activity

    I hope this helps! And don't hesitate to post again if you need more help with this.

  • Alex
    • New Recruit

    I've used this code and so far it's not working:

    <?php
    add_post_type_support( 'incsub_wiki', 'buddypress-activity' );

    function customize_page_tracking_args() {
    // Check if the Activity component is active before using it.
    if ( ! bp_is_active( 'activity' ) ) {
    return;
    }

    bp_activity_set_post_type_tracking_args( 'incsub_wiki', array(
    'component_id' => buddypress()->blogs->id,
    'action_id' => 'new_blog_page',
    'bp_activity_admin_filter' => __( 'Published a new page', 'custom-domain' ),
    'bp_activity_front_filter' => __( 'Pages', 'custom-domain' ),
    'contexts' => array( 'activity', 'member' ),
    'activity_comment' => true,
    'bp_activity_new_post' => __( '%1$s posted a new page', 'custom-textdomain' ),
    'bp_activity_new_post_ms' => __( '%1$s posted a new page, on the site %3$s', 'custom-textdomain' ),
    'position' => 100,
    ) );
    }
    add_action( 'bp_init', 'customize_page_tracking_args' );
    ?>

  • Patrick
    • Support Monkey

    Hi again @Alex

    The following works just fine for me:
    add_post_type_support( 'incsub_wiki', 'buddypress-activity' )

    Unzip the attached folder and upload the bp-custom.php in there to your wp-content/plugins/ folder. That, at least, will get the activity steam to recognize new wikis, as seen on my test site here:
    http://wiki.pcwriter.net/activity/

    However, my brain appears to be a bit mushy today as I cannot, for the life of me, get the other bit of code to behave so we can customize the name of the entry items.

    So I've asked for a bit of help from our 2nd-level wiz-kids to see if they can get it working. One of them should be dropping in here shortly to lend a hand.

  • Ash
    • WordPress Hacker

    Hello @Alex

    I hope you are well today.

    Would you please try the following code:

    add_action( 'save_post', 'add_wiki_activity_to_bp' );
    function add_wiki_activity_to_bp( $post_id ) {
    	if( get_post_type( $post_id ) == 'incsub_wiki' ) {
    
    		if ( ! function_exists( 'bp_activity_add' ) ) return false;
    
    		$user_id = get_current_user_id();
    		$user_info = get_userdata( $user_id );
    		$post = get_post( $post_id );
    
    		if( ( $_POST['post_status'] == 'publish' ) && ( $_POST['original_post_status'] != 'publish' ) ) {
    			bp_activity_add( array(
    			'user_id' => $user_id,
    			'action' => bp_core_get_userlink( $user_id ) . ' has published <a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a>',
    			'component' => 'profile',
    			'type' => 'created_wiki'
    			) );
    		}elseif( ( $_POST['post_status'] == 'publish' ) ) {
    			bp_activity_add( array(
    			'user_id' => $user_id,
    			'action' => bp_core_get_userlink( $user_id ) . ' has edited <a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a>',
    			'component' => 'profile',
    			'type' => 'created_wiki'
    			) );
    		}
    	}
    }

    You can download from here too: https://gist.github.com/bappi-d-great/9e84dcf73e0dcb3012ce

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

  • Ash
    • WordPress Hacker

    Hello @bitcoinstyle

    I hope you are well today.

    I have just tested again the same code with latest version of wiki and buddypress and it's working fine as it should, screenshot attached.

    Would you please deactivate all other plugins except BuddyPress and Wiki and enable default WP theme and try again?

    Please let me know.

    Cheers
    Ash

  • bitcoinstyle
    • WPMU DEV Initiate

    Nope. 2015 and no other plugins. I think it has to do with wiki and bp on seperate sites. Bp is network activated, but wiki is not. Edit: i just network activated wiki. No change.
    Maybe this is just because of multisite?
    Maybe i put your script in the wrong place(at the bottom of functions in the them... you know what? Lemme put your code in the 2015 theme, and also try my theme with the network activated wiki. Ill be back with results. Heres hoping its not just because its multisite

  • bitcoinstyle
    • WPMU DEV Initiate

    And no. None of that makes a difference. Not even publishing/editing a page on the same site. Im thinkin Its a multisite thing. Would you happen to know a quick fix to let wordpress know which site id to get that custom post from(could that even be a solution?)

  • Ash
    • WordPress Hacker

    Hello @bitcoinstyle

    Okay, let me create a test site like you.

    You have a multisite. Which plugin is network activated? Which one is activated in a subsite? Are you check user personal profile or sitewide activity?

    If you please let me know the full scenario, I will create a test site like that and try in my install. Please let me know.

    Cheers
    Ash

  • bitcoinstyle
    • WPMU DEV Initiate

    Wow. Sorry i didnt check back sooner.
    Buddypress is network active with a wp-config line that tells it to use a site id for its main.The wiki is activated only on the root site. And i am lookin on the activity tab of the profiles of admin and a test user for the announcements . I hope thats not too off the wall, but thank you for putting time into this.

  • Ash
    • WordPress Hacker

    Hello @bitcoinstyle

    I hope you are well today.

    Would you please send me admin login details and ftp details?

    To send me details, please use our contact form: https://premium.wpmudev.org/contact/

    Select: I have a different question
    Subject: Attn-Ash (this ensures that it will be assigned to me)
    Details:
    1. Send all requested details
    2. Send a link of this thread so that I can track
    3. Send any other relevant link

    I will be happy to take a look :slight_smile:

    Cheers
    Ash

  • bitcoinstyle
    • WPMU DEV Initiate

    Quick update: i got it working as far as i can tell. I took out the checks for the && and the elseif, then switched the published and edited. It seems to work, it catches all wiki pages, and no posts, comments or forum topics(using the forum plugin that i still like more than bbpress). I guess it had trouble determining what the post status used to be across the network.

    if ( ! function_exists( 'bp_activity_add' ) ) return false;

    $user_id = get_current_user_id();

    $user_info = get_userdata( $user_id );

    $post = get_post( $post_id );

    if ($_POST['post_status'] == 'publish') {

    bp_activity_add( array(

    'user_id' => $user_id,

    'action' => bp_core_get_userlink( $user_id ) . ' has edited ID ) . '">' . $post->post_title . '',

    'component' => 'profile',

    'type' => 'created_wiki'

    ) );

    }else{

    bp_activity_add( array(

    'user_id' => $user_id,

    'action' => bp_core_get_userlink( $user_id ) . ' has published ID ) . '">' . $post->post_title . '',

    'component' => 'profile',

    'type' => 'created_wiki'

    ) );

    }

    }

    }

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.