Skip to content

Instantly share code, notes, and snippets.

@imath
Created March 26, 2015 13:37
Show Gist options
  • Save imath/8c7c9702df3cd57d583b to your computer and use it in GitHub Desktop.
Save imath/8c7c9702df3cd57d583b to your computer and use it in GitHub Desktop.
Back Compat for plugins filtering bp_blogs_record_comment_post_types / bp_blogs_record_post_post_types
<?php
function create_post_type_resource() {
register_post_type( 'resource', array(
'labels' => array(
'name' => __( 'Resources' ),
'singular_name' => __( 'Resource' ),
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Add New Resource' ),
'edit' => __( 'Edit' ),
'edit_item' => __( 'Edit Resource' ),
'new_item' => __( 'New Resource' ),
'view' => __( 'View Resources' ),
'view_item' => __( 'View Resource' ),
'search_items' => __( 'Search Resources' ),
'not_found' => __( 'No Resources found' ),
'not_found_in_trash' => __( 'No Resources found in Trash' )
),
'public' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'resource' ),
'exclude_from_search' => false,
'has_archive' => true,
'map_meta_cap' => true,
'hierarchical' => false,
'supports' => array( 'title', 'editor', 'thumbnail', 'author', 'comments' ),
'bp_activity' => array(
'component_id' => 'blogs',
'action_id' => 'new_blog_post',
'format_callback' => 'bp_blogs_format_activity_action_new_blog_post',
),
) );
}
add_action( 'init', 'create_post_type_resource' );
function record_resource_activity( $post_types ) {
$post_types[] = 'resource';
return $post_types;
}
add_filter( 'bp_blogs_record_post_post_types', 'record_resource_activity', 1, 1 );
add_filter( 'bp_blogs_record_comment_post_types', 'record_resource_activity', 10, 1 );
function record_resource_activity_action( $activity_action, $post, $post_permalink ) {
global $bp;
if( $post->post_type == 'resource' ) {
$activity_action = sprintf( __( '%1$s Added a new Resource, %2$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
}
return $activity_action;
}
add_filter('bp_blogs_activity_new_post_action', 'record_resource_activity_action', 1, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment