Skip to content

Instantly share code, notes, and snippets.

@imath
Created March 25, 2015 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imath/36f588e77a7a574600cb to your computer and use it in GitHub Desktop.
Save imath/36f588e77a7a574600cb to your computer and use it in GitHub Desktop.
BackCompat for 'bp_blogs_activity_new_post_action'
<?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',
'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