Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 1 replies (of 1 total)
  • @benjiswart

    Participant

    So after a quick schooling in buddypress and how this all works I managed to piece together the following code that does exactly what I needed to do:

    <?php
    function job_listing_activity_args() {
    	if ( ! bp_is_active( 'activity' ) ) {
    		return;
    	}
    	add_post_type_support( 'job_listing', 'buddypress-activity' );
    
    	bp_activity_set_post_type_tracking_args( 'job_listing', array(
    		'component_id'             => 'activity',
    		'action_id'                => 'new_job_listing',
            	'bp_activity_admin_filter' => __( 'Published a new Report', 'text-domain' ),
            	'bp_activity_front_filter' => __( 'Reports', 'text-domain' ),
            	'contexts'                 => array( 'activity', 'member' ),
            	'activity_comment'         => true,
            	'bp_activity_new_post'     => __( '%1$s posted a new Report: <a href="%2$s">[Job]</a> aproximately', 'text-domain' ),
            	'bp_activity_new_post_ms'  => __( '%1$s posted a new Report: <a href="%2$s">[Job]</a>, on the site %3$s', 'text-domain' ),
            	'position'                 => 100,
            	'bp_activity_new_comment'  => __( '%1$s posted a new Follow up on: <a href="%2$s">[Job]</a> aproximately', 'custom-textdomain' ),
            	'bp_activity_comments_admin_filter' => __( 'Added Follow Up', 'custom-textdomain' ),
            	'bp_activity_comments_front_filter' => __( 'Follow Ups', 'custom-textdomain' ),
            	'bp_activity_new_comment_ms'        => __( '%1$s added follow up to this <a href="%2$s">Incident</a>, on the site %3$s', 'custom-textdomain' ),
            	'comment_action_id'                 => 'new_job_listing_comment',
        	) );
    }
    add_action( 'init', 'job_listing_activity_args' );
    function job_listing_include_post_type_title( $action, $activity ) {
    	if ( empty( $activity->id ) ) {
    		return $action;
    	}
    	if ( 'new_job_listing' != $activity->type ) {
    		return $action;
    	}
    	
    	
    	preg_match_all( '/<a.*?>([^>]*)<\/a>/', $action, $matches );
    	if ( empty( $matches[1][1] ) || '[Job]' != $matches[1][1] ) {
    		return $action;
    	}
    	$post_type_title = bp_activity_get_meta( $activity->id, 'post_title' );
    	if ( empty( $post_type_title ) ) {
    		switch_to_blog( $activity->item_id );
    		$post_type_title = get_post_field( 'post_title', $activity->secondary_item_id );
    		// We have a title save it in activity meta to avoid switching blogs too much
    		if ( ! empty( $post_type_title ) ) {
    			bp_activity_update_meta( $activity->id, 'post_title', $post_type_title );
    		}
    		restore_current_blog();
    	}
    	return str_replace( $matches[1][1], esc_html( $post_type_title ), $action );
    }
    add_filter( 'bp_activity_custom_post_type_post_action', 'job_listing_include_post_type_title', 10, 2 );
    

    Hope this helps anyone else trying to figure out the same thing.

Viewing 1 replies (of 1 total)
Skip to toolbar