Skip to content

Instantly share code, notes, and snippets.

@imath imath/bp-custom.php Secret
Created Jun 10, 2015

Embed
What would you like to do?
Code to test the BuddyPress Post Type Activities and particularly the comments tracking feature (BP6482)
<?php
/**
* BuddyPress Custom
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Test Post Type Activities - the comments!
*/
function test_post_type_comments_support() {
if ( ! bp_is_active( 'activity' ) ) {
return;
}
if ( bp_is_active( 'blogs' ) ) {
// test add_post_type_support()
add_post_type_support( 'page', 'buddypress-activity' );
// test bp_activity_set_post_type_tracking_args()
bp_activity_set_post_type_tracking_args( 'page', 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 <a href="%2$s">page</a>', 'custom-textdomain' ),
'bp_activity_new_post_ms' => __( '%1$s posted a new <a href="%2$s">page</a>, on the site %3$s', 'custom-textdomain' ),
'position' => 100,
/* Add post type comments tracking support */
'comment_action_id' => 'new_blog_page_comment',
/* Add post type comments tracking labels */
'bp_activity_comments_admin_filter' => __( 'Posted a comment on a page', 'custom-domain' ),
'bp_activity_comments_front_filter' => __( 'Page comments', 'custom-domain' ),
'bp_activity_new_comment' => __( '%1$s commented on the <a href="%2$s">page</a>', 'custom-textdomain' ),
'bp_activity_new_comment_ms' => __( '%1$s commented on the <a href="%2$s">page</a>, on the site %3$s', 'custom-textdomain' ),
) );
}
// Test register post type
$labels = array(
'name' => _x( 'Books', 'post type general name', 'your-plugin-textdomain' ),
'singular_name' => _x( 'Book', 'post type singular name', 'your-plugin-textdomain' ),
'menu_name' => _x( 'Books', 'admin menu', 'your-plugin-textdomain' ),
'name_admin_bar' => _x( 'Book', 'add new on admin bar', 'your-plugin-textdomain' ),
'add_new' => _x( 'Add New', 'book', 'your-plugin-textdomain' ),
'add_new_item' => __( 'Add New Book', 'your-plugin-textdomain' ),
'new_item' => __( 'New Book', 'your-plugin-textdomain' ),
'edit_item' => __( 'Edit Book', 'your-plugin-textdomain' ),
'view_item' => __( 'View Book', 'your-plugin-textdomain' ),
'all_items' => __( 'All Books', 'your-plugin-textdomain' ),
'search_items' => __( 'Search Books', 'your-plugin-textdomain' ),
'parent_item_colon' => __( 'Parent Books:', 'your-plugin-textdomain' ),
'not_found' => __( 'No books found.', 'your-plugin-textdomain' ),
'not_found_in_trash' => __( 'No books found in Trash.', 'your-plugin-textdomain' ),
'bp_activity_admin_filter' => __( 'Published a new book', 'custom-domain' ),
'bp_activity_front_filter' => __( 'Books', 'custom-domain' ),
'bp_activity_new_post' => __( '%1$s posted a new <a href="%2$s">book</a>', 'custom-textdomain' ),
'bp_activity_new_post_ms' => __( '%1$s posted a new <a href="%2$s">book</a>, on the site %3$s', 'custom-textdomain' ),
/* Add post type comments tracking labels */
'bp_activity_comments_admin_filter' => __( 'Posted a comment on a book', 'custom-domain' ),
'bp_activity_comments_front_filter' => __( 'Book comments', 'custom-domain' ),
'bp_activity_new_comment' => __( '%1$s commented on a <a href="%2$s">book</a>', 'custom-textdomain' ),
'bp_activity_new_comment_ms' => __( '%1$s commented on a <a href="%2$s">book</a>, on the site %3$s', 'custom-textdomain' ),
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'book' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments', 'buddypress-activity' ),
'bp_activity' => array(
'action_id' => 'new_book',
'contexts' => array( 'activity', 'member' ),
'position' => 40,
/* Add post type comments tracking support */
'comment_action_id' => 'new_book_comment',
),
);
register_post_type( 'book', $args );
}
add_action( 'bp_init', 'test_post_type_comments_support' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.