/** * Registers new activity actions for IdeaStream * * By default, IdeaStream activity actions will be attached * to the blogs component. * * @package WP Idea Stream * @subpackage buddypress/activity * * @since 2.0.0 * * @uses buddypress() to get BuddyPress main instance * @uses add_post_type_support() to add the ideas post type to BuddyPress activities * @uses bp_activity_set_post_type_tracking_arg() to register the plugin's activity actions * @uses apply_filters() call 'wp_idea_stream_buddypress_get_activity_actions' to override/add activity actions */ public function register_activity_actions() { /** * Used internally to add the IdeaStream Groups activities * @see WP_Idea_Stream_Group::group_activity_context() * * @param array the list of activity actions */ $this->activity_actions = apply_filters('wp_idea_stream_buddypress_get_activity_actions', array('new_' . $this->post_type => (object) array('component' => buddypress()->blogs->id, 'type' => 'new_' . $this->post_type, 'admin_caption' => sprintf(_x('New %s published', 'activity admin dropdown caption', 'wp-idea-stream'), mb_strtolower($this->post_type_object->labels->singular_name, 'UTF-8')), 'action_callback' => array($this, 'format_idea_activity_action'), 'front_caption' => sprintf(_x('%s', 'activity front dropdown caption', 'wp-idea-stream'), $this->post_type_object->labels->name), 'contexts' => array('activity', 'member')), 'new_blog_comment' => (object) array('component' => buddypress()->blogs->id, 'type' => 'new_' . $this->post_type . '_comment', 'admin_caption' => sprintf(_x('New %s comment posted', 'activity comment admin dropdown caption', 'wp-idea-stream'), mb_strtolower($this->post_type_object->labels->singular_name, 'UTF-8')), 'action_callback' => array($this, 'format_idea_comment_activity_action'), 'front_caption' => sprintf(_x('%s comments', 'activity comments front dropdown caption', 'wp-idea-stream'), $this->post_type_object->labels->singular_name), 'contexts' => array('activity', 'member')))); // Only add the new idea to BuddyPress tracked post types add_post_type_support($this->post_type, 'buddypress-activity'); $tracking_args = $this->activity_actions['new_' . $this->post_type]; bp_activity_set_post_type_tracking_args($this->post_type, array('component_id' => $tracking_args->component, 'action_id' => $tracking_args->type, 'bp_activity_admin_filter' => $tracking_args->admin_caption, 'bp_activity_front_filter' => $tracking_args->front_caption, 'contexts' => $tracking_args->contexts, 'activity_comment' => false, 'format_callback' => $tracking_args->action_callback, 'position' => 50)); }
public function question_answer_tracking() { // Check if the Activity component is active before using it. if (!function_exists('bp_is_active') || !bp_is_active('activity')) { return; } bp_activity_set_post_type_tracking_args('question', array('component_id' => 'activity', 'action_id' => 'new_question', 'contexts' => array('activity', 'member'), 'bp_activity_admin_filter' => __('Question', 'anspress-question-answer'), 'bp_activity_front_filter' => __('Question', 'anspress-question-answer'), 'bp_activity_new_post' => __('%1$s asked a new <a href="AP_CPT_LINK">question</a>', 'anspress-question-answer'), 'bp_activity_new_post_ms' => __('%1$s asked a new <a href="AP_CPT_LINK">question</a>, on the site %3$s', 'anspress-question-answer'))); bp_activity_set_post_type_tracking_args('answer', array('component_id' => 'activity', 'action_id' => 'new_answer', 'contexts' => array('activity', 'member'), 'bp_activity_admin_filter' => __('Answer', 'anspress-question-answer'), 'bp_activity_front_filter' => __('Answer', 'anspress-question-answer'), 'bp_activity_new_post' => __('%1$s <a href="AP_CPT_LINK">answered</a> a question', 'anspress-question-answer'), 'bp_activity_new_post_ms' => __('%1$s <a href="AP_CPT_LINK">answered</a> a question, on the site %3$s', 'anspress-question-answer'))); }
/** * @group bp_blogs_comment_sync_activity_comment * @group post_type_comment_activities */ public function test_bp_blogs_comment_sync_activity_comment_for_custom_post_type() { if (is_multisite()) { $b = $this->factory->blog->create(); switch_to_blog($b); add_filter('comment_flood_filter', '__return_false'); } else { $b = get_current_blog_id(); } $u = $this->factory->user->create(); $userdata = get_userdata($u); $labels = array('name' => 'bars', 'singular_name' => 'bar'); register_post_type('foo', array('labels' => $labels, 'public' => true, 'supports' => array('comments'))); add_post_type_support('foo', 'buddypress-activity'); bp_activity_set_post_type_tracking_args('foo', array('comment_action_id' => 'new_foo_comment')); add_filter('bp_disable_blogforum_comments', '__return_false'); $p = $this->factory->post->create(array('post_author' => $u, 'post_type' => 'foo')); $a1 = bp_activity_get_activity_id(array('type' => 'new_foo', 'filter' => array('item_id' => $b, 'secondary_item_id' => $p))); $c = wp_new_comment(array('comment_post_ID' => $p, 'comment_author' => $userdata->user_nicename, 'comment_author_url' => 'http://buddypress.org', 'comment_author_email' => $userdata->user_email, 'comment_content' => 'this is a foo comment', 'comment_type' => '', 'comment_parent' => 0, 'user_id' => $u)); $a2 = bp_activity_new_comment(array('content' => 'this should generate a new foo comment', 'user_id' => $u, 'activity_id' => $a1)); $activity_args = array('type' => 'activity_comment', 'display_comments' => 'stream', 'meta_query' => array(array('key' => 'bp_blogs_foo_comment_id', 'compare' => 'exists'))); $a = bp_activity_get($activity_args); $aids = wp_list_pluck($a['activities'], 'id'); $cids = wp_list_pluck(get_approved_comments($p), 'comment_ID'); foreach ($aids as $aid) { $this->assertTrue(in_array(bp_activity_get_meta($aid, 'bp_blogs_foo_comment_id'), $cids), 'The comment ID should be in the activity meta'); } foreach ($cids as $cid) { $this->assertTrue(in_array(get_comment_meta($cid, 'bp_activity_comment_id', true), $aids), 'The activity ID should be in the comment meta'); } _unregister_post_type('foo'); if (is_multisite()) { restore_current_blog(); remove_filter('comment_flood_filter', '__return_false'); } remove_filter('bp_disable_blogforum_comments', '__return_false'); }
/** * @group bp_activity_set_post_type_tracking_args * @group activity_tracking */ public function test_bp_activity_set_post_type_tracking_args_check_post_type_global() { $labels = array('bp_activity_admin_filter' => 'New Foo', 'bp_activity_front_filter' => 'Foos'); $bp_activity_args = array('action_id' => 'new_foo', 'contexts' => array('activity'), 'position' => 40); register_post_type('foo', array('labels' => $labels, 'supports' => array('buddypress-activity'), 'bp_activity' => $bp_activity_args)); $register_bp_activity = get_post_type_object('foo')->bp_activity; _unregister_post_type('foo'); register_post_type('foo', array('label' => 'foo', 'supports' => array('buddypress-activity'))); bp_activity_set_post_type_tracking_args('foo', $labels + $bp_activity_args); $set_bp_activity = get_post_type_object('foo')->bp_activity; _unregister_post_type('foo'); $this->assertSame($set_bp_activity, $register_bp_activity); }
/** * @group bp_activity_can_comment */ public function test_bp_activity_can_comment_post_type_activity() { global $activities_template; $bp = buddypress(); $reset_activities_template = $activities_template; $reset_activity_track = $bp->activity->track; $activities_template = new stdClass(); $activities_template->disable_blogforum_replies = true; register_post_type('foo', array('label' => 'foo', 'public' => true, 'supports' => array('buddypress-activity'))); $bp->activity->track = bp_activity_get_post_types_tracking_args(); $activities_template->activity = (object) array('type' => 'new_foo'); $this->assertTrue(bp_activity_can_comment(), 'If post type does not support comments, a post type activity can be commented'); add_post_type_support('foo', 'comments'); $bp->activity->track = bp_activity_get_post_types_tracking_args(); $this->assertFalse(bp_activity_can_comment(), 'If post type support comments, a post type activity cannot be commented'); $bp_activity_support = (array) $bp->activity->track['new_foo']; $bp_activity_support['activity_comment'] = true; bp_activity_set_post_type_tracking_args('foo', $bp_activity_support); $bp->activity->track = bp_activity_get_post_types_tracking_args(); $this->assertTrue(bp_activity_can_comment(), 'If post type supports activity comments, a post type activity can be commented'); // clean up! $activities_template = $reset_activities_template; $bp->activity->track = $reset_activity_track; }
/** * @group bp_activity_set_post_type_tracking_args * @group activity_tracking */ public function test_bp_activity_set_post_type_tracking_args() { $bp = buddypress(); add_post_type_support('page', 'buddypress-activity'); bp_activity_set_post_type_tracking_args('page', array('component_id' => $bp->blogs->id, 'dummy' => 'dummy value')); // Build the actions to fetch the tracking args bp_activity_get_actions(); $u = $this->factory->user->create(); $post_id = $this->factory->post->create(array('post_author' => $u, 'post_status' => 'publish', 'post_type' => 'page')); $a = bp_activity_get(array('action' => 'new_page', 'item_id' => get_current_blog_id(), 'secondary_item_id' => $post_id)); $this->assertSame($bp->blogs->id, $a['activities'][0]->component); remove_post_type_support('page', 'buddypress-activity'); // Reset globals unset($bp->activity->actions->blogs->new_page); $bp->activity->track = array(); }
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('story', array('component_id' => 'activity', 'action_id' => 'new_story', 'bp_activity_admin_filter' => __('Published a new story', 'custom-domain'), 'bp_activity_front_filter' => __('Stories', 'custom-domain'), 'contexts' => array('activity', 'member'), 'bp_activity_new_post' => __('%1$s published a new <a href="%2$s">Story</a>', '1sentence'), 'bp_activity_new_post_ms' => __('%1$s published a new <a href="%2$s">Story</a>, on the site %3$s', '1sentence'), 'position' => 100)); }