Ticket #5669: bsc.1.7.patch
File bsc.1.7.patch, 7.1 KB (added by , 10 years ago) |
---|
-
includes/bp-example-activity.php
diff --git includes/bp-example-activity.php includes/bp-example-activity.php index 90448ff..ff5fcd2 100644
function bp_example_register_activity_actions() { 29 29 $bp->example->id, 30 30 'accepted_terms', 31 31 __( 'Accepted terms', 'bp-example' ), 32 'bp_example_format_accepted_terms_activity_action' 32 'bp_example_format_accepted_terms_activity_action', 33 __( 'Accepted terms', 'bp-example' ), 34 array( 'activity', 'member' ) 33 35 ); 34 36 35 37 bp_activity_set_action( 36 38 $bp->example->id, 37 39 'rejected_terms', 38 40 __( 'Rejected terms', 'bp-example' ), 39 'bp_example_format_rejected_terms_activity_action' 40 ); 41 42 bp_activity_set_action( 43 $bp->example->id, 44 'new_high_five', 45 __( 'High fives', 'bp-example' ), 46 'bp_example_format_high_fives_activity_action' 41 'bp_example_format_rejected_terms_activity_action', 42 __( 'Rejected terms', 'bp-example' ), 43 array( 'activity', 'member' ) 47 44 ); 48 45 49 46 do_action( 'bp_example_register_activity_actions' ); … … function bp_example_format_rejected_terms_activity_action( $action, $activity ) 79 76 } 80 77 81 78 function bp_example_format_high_fives_activity_action( $action, $activity ) { 82 if ( empty( $action ) || empty( $activity) )79 if ( empty( $activity ) || ( empty( $action ) && empty( $activity->id ) ) ) 83 80 return false; 84 81 85 82 $from_user_link = bp_core_get_userlink( $activity->user_id ); … … function bp_example_format_high_fives_activity_action( $action, $activity ) { 107 104 */ 108 105 function bp_example_activity_options() { 109 106 107 if ( function_exists( 'bp_activity_show_filters' ) ) 108 return; 109 110 110 $bp_example_actions = buddypress()->activity->actions->example; 111 111 112 112 foreach ( $bp_example_actions as $action ) { … … add_action( 'bp_example_reject_terms', 'bp_example_record_rejected_terms_activit 177 177 /** 178 178 * Hooking bp_example_send_high_five to record an activity 179 179 */ 180 function bp_example_record_high_five_activity( $ to_user_id = 0, $from_user_id = 0) {180 function bp_example_record_high_five_activity( $post_id = 0, $post = null ) { 181 181 // Bail if we don't have the needed inputs 182 if ( empty( $ to_user_id ) || empty( $from_user_id) )182 if ( empty( $post ) ) 183 183 return; 184 184 185 185 /* Now record the new 'new_high_five' activity item */ 186 $to_user_link = bp_core_get_userlink( $to_user_id);187 $from_user_link = bp_core_get_userlink( $ from_user_id);186 $to_user_link = bp_core_get_userlink( bp_displayed_user_id() ); 187 $from_user_link = bp_core_get_userlink( $post->post_author ); 188 188 189 189 bp_example_record_activity( array( 190 190 'type' => 'new_high_five', 191 191 'action' => apply_filters( 'bp_example_new_high_five_activity_action', sprintf( __( '%s high-fived %s!', 'bp-example' ), $from_user_link, $to_user_link ), $from_user_link, $to_user_link ), 192 'item_id' => $to_user_id,192 'item_id' => bp_displayed_user_id(), 193 193 ) ); 194 194 } 195 // 9 priority is used to fire before the notifications196 add_action( 'bp_example_send_high_five', 'bp_example_record_high_five_activity', 9, 2 );197 195 198 196 /** 199 197 * bp_example_record_activity() -
includes/bp-example-loader.php
diff --git includes/bp-example-loader.php includes/bp-example-loader.php index 5efc0b2..3ad0e90 100755
class BP_Example_Component extends BP_Component { 62 62 * components in the database. 63 63 */ 64 64 $bp->active_components[ $this->id ] = '1'; 65 66 /**67 * Hook the register_post_types() method. If you're using68 * custom post types to store data (which is recommended), you69 * will need to hook your function manually to 'init'.70 */71 add_action( 'init', array( &$this, 'register_post_types' ) );72 65 } 73 66 74 67 /** … … class BP_Example_Component extends BP_Component { 417 410 * @since 1.6 418 411 * @see http://codex.wordpress.org/Function_Reference/register_post_type 419 412 */ 420 function register_post_types( ) {413 function register_post_types( $post_types = array() ) { 421 414 // Set up some labels for the post type 422 415 $labels = array( 423 416 'name' => __( 'High Fives', 'bp-example' ), 424 417 'singular' => __( 'High Five', 'bp-example' ) 425 418 ); 426 419 427 // Set up the argument array for register_post_type() 420 /** 421 * Set up the argument array for register_post_type() 422 * 423 * If buddypress arg is defined, you can set the activity recording 424 * for your component where 425 * - type : is your component's activity type 426 * - description : is your component's activity description for the administration screen dropdown 427 * - format_callback : is the format callback to use to build your component's activity action 428 * - label : is your component's front end dropdown option label 429 * 430 * - context : is an array of the contexts your component's dropdown option should show 431 * - activity > the Activity directory page 432 * - member > the user's activity profile pages 433 * - member_groups > the user's groups activity profile page 434 * - group > the group's activity page (generally group's home page) 435 * 436 * Using context can avoid using the front-end dropdown hooks such as bp_activity_filter_options. Although, it's possible 437 * some themes didn't upgraded to BuddyPress 2.1 way of displaying new activity types in front end dropdowns. 438 * So you might check if bp_activity_show_filters() function exists to be sure of it, see bp_example_activity_options() 439 * for an example. 440 * 441 * - track : whether to record or not an activity for your component 442 * - publish_callback (optional) : your specific callback if you want to have more control on the way activities will be recorded 443 * - unpublish_callback (optional) : your specific callback if you want to have more control on the way activities will be removed 444 * - update_callback (optional) : your specific callback if you want to have more control on the way activities will be updated 445 * - untrash_callback (optional) : your specific callback if you want to have more control on the way activities will be reverted 446 * - remove_callback (optional) : your specific callback if you want to have more control on the way activities will be removed 447 */ 428 448 $args = array( 429 449 'label' => __( 'High Fives', 'bp-example' ), 430 450 'labels' => $labels, 431 451 'public' => false, 432 452 'show_ui' => true, 433 'supports' => array( 'title' ) 453 'supports' => array( 'title' ), 454 'buddypress' => array( 455 'type' => 'new_high_five', 456 'description' => __( 'High fives', 'bp-example' ), 457 'format_callback' => 'bp_example_format_high_fives_activity_action', 458 'label' => __( 'high fived', 'bp-example' ), 459 'context' => array( 'activity', 'member' ), 460 'track' => true, 461 'publish_callback' => 'bp_example_record_high_five_activity' 462 ) 434 463 ); 435 464 436 // Register the post type. 437 // Here we are using $this->id ('example') as the name of the 438 // post type. You may choose to use a different name for the 439 // post type; if you register more than one, you will have to 440 // declare more names. 441 register_post_type( $this->id, $args ); 442 443 parent::register_post_types(); 465 parent::register_post_types( array( $this->id => $args ) ); 444 466 } 445 467 446 468 function register_taxonomies() {