Skip to:
Content

BuddyPress.org

Ticket #5669: bsc.1.7.patch

File bsc.1.7.patch, 7.1 KB (added by imath, 7 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() { 
    2929                $bp->example->id,
    3030                'accepted_terms',
    3131                __( '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' )
    3335        );
    3436
    3537        bp_activity_set_action(
    3638                $bp->example->id,
    3739                'rejected_terms',
    3840                __( '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' )
    4744        );
    4845
    4946        do_action( 'bp_example_register_activity_actions' );
    function bp_example_format_rejected_terms_activity_action( $action, $activity ) 
    7976}
    8077
    8178function bp_example_format_high_fives_activity_action( $action, $activity ) {
    82         if ( empty( $action ) || empty( $activity ) )
     79        if (  empty( $activity ) || ( empty( $action ) && empty( $activity->id ) ) )
    8380                return false;
    8481
    8582        $from_user_link = bp_core_get_userlink( $activity->user_id );
    function bp_example_format_high_fives_activity_action( $action, $activity ) { 
    107104 */
    108105function bp_example_activity_options() {
    109106
     107        if ( function_exists( 'bp_activity_show_filters' ) )
     108                return;
     109
    110110        $bp_example_actions = buddypress()->activity->actions->example;
    111111
    112112        foreach ( $bp_example_actions as $action ) {
    add_action( 'bp_example_reject_terms', 'bp_example_record_rejected_terms_activit 
    177177/**
    178178 * Hooking bp_example_send_high_five to record an activity
    179179 */
    180 function bp_example_record_high_five_activity( $to_user_id = 0, $from_user_id = 0 ) {
     180function bp_example_record_high_five_activity( $post_id = 0, $post = null ) {
    181181        // Bail if we don't have the needed inputs
    182         if ( empty( $to_user_id ) || empty( $from_user_id ) )
     182        if ( empty( $post ) )
    183183                return;
    184184
    185185        /* 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 );
    188188
    189189        bp_example_record_activity( array(
    190190                'type' => 'new_high_five',
    191191                '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(),
    193193        ) );
    194194}
    195 // 9 priority is used to fire before the notifications
    196 add_action( 'bp_example_send_high_five', 'bp_example_record_high_five_activity', 9, 2 );
    197195
    198196/**
    199197 * 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 { 
    6262                 * components in the database.
    6363                 */
    6464                $bp->active_components[ $this->id ] = '1';
    65 
    66                 /**
    67                  * Hook the register_post_types() method. If you're using
    68                  * custom post types to store data (which is recommended), you
    69                  * will need to hook your function manually to 'init'.
    70                  */
    71                 add_action( 'init', array( &$this, 'register_post_types' ) );
    7265        }
    7366
    7467        /**
    class BP_Example_Component extends BP_Component { 
    417410         * @since 1.6
    418411         * @see http://codex.wordpress.org/Function_Reference/register_post_type
    419412         */
    420         function register_post_types() {
     413        function register_post_types( $post_types = array() ) {
    421414                // Set up some labels for the post type
    422415                $labels = array(
    423416                        'name'     => __( 'High Fives', 'bp-example' ),
    424417                        'singular' => __( 'High Five', 'bp-example' )
    425418                );
    426419
    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                 */
    428448                $args = array(
    429449                        'label'    => __( 'High Fives', 'bp-example' ),
    430450                        'labels'   => $labels,
    431451                        'public'   => false,
    432452                        '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                        )
    434463                );
    435464
    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 ) );
    444466        }
    445467
    446468        function register_taxonomies() {