Skip to:
Content

BuddyPress.org

Ticket #1708: activity-allow-custom-post-action.patch

File activity-allow-custom-post-action.patch, 2.2 KB (added by johnjamesjacoby, 16 years ago)

Just dance, do do do, just dance

  • ajax.php

     
    6868                return false;
    6969        }
    7070
    71         if ( (int)$_POST['group'] ) {
    72                 $activity_id = groups_post_update( array(
    73                         'content' => $_POST['content'],
    74                         'group_id' => $_POST['group']
    75                 ));
    76         } else {
    77                 $activity_id = bp_activity_post_update( array(
    78                         'content' => $_POST['content']
    79                 ));
     71        /* Allow item_id and component to be filtered */
     72        $item_id = apply_filters( 'bp_dtheme_post_update_item_id', $item_id );
     73        $component = apply_filters( 'bp_dtheme_post_update_component', $component );
     74
     75        switch ( $component ) {
     76                case $bp->profile->id :
     77                        $activity_id = bp_activity_post_update( array(
     78                                'content' => $_POST['content']
     79                        ));
     80                        break;
     81
     82                case $bp->groups->id :
     83                        $activity_id = groups_post_update( array(
     84                                'content' => $_POST['content'],
     85                                'group_id' => $_POST['group']
     86                        ));
     87                        break;
     88
     89                default:
     90                        $activity_id = apply_filters( 'bp_custom_activity_update', $item_id, $component, $_POST['content'], $_POST['group'] );
     91                        break;
    8092        }
    8193
    8294        if ( !$activity_id ) {
     
    92104}
    93105add_action( 'wp_ajax_post_update', 'bp_dtheme_post_update' );
    94106
     107/* Filters for default core components that support activity updates */
     108function bp_dtheme_profile_post_update_item_id( $item_id ) {
     109        if ( !(int)$_POST['group'] )
     110                return $bp->loggedin_user->id;
     111}
     112add_filter( 'bp_dtheme_post_update_item_id', 'bp_dtheme_profile_post_update_item_id' );
     113
     114function bp_dtheme_profile_post_update_component( $component ) {
     115        if ( !(int)$_POST['group'] )
     116                return $bp->profile->id;
     117}
     118add_filter( 'bp_dtheme_post_update_component', 'bp_dtheme_profile_post_update_component' );
     119
     120function bp_dtheme_groups_post_update_item_id( $item_id ) {
     121        if ( (int)$_POST['group'] )
     122                return $_POST['group'];
     123}
     124add_filter( 'bp_dtheme_post_update_item_id', 'bp_dtheme_groups_post_update_item_id' );
     125
     126function bp_dtheme_groups_post_update_component( $component ) {
     127        if ( (int)$_POST['group'] )
     128                return $bp->groups->id;
     129}
     130add_filter( 'bp_dtheme_post_update_item_id', 'bp_dtheme_groups_post_update_component' );
     131
    95132function bp_dtheme_new_activity_comment() {
    96133        global $bp;
    97134