Support » Plugin: BP Activity Share » Custom post type activities

  • magland

    (@magland)


    https://codex.buddypress.org/plugindev/post-types-activities/

    Hi, I’m using code similar to the above link to post timeline activities
    from several of my registered custom post types.

    If I share one of these custom post type activities, the header text is missing the name of the original poster.

    Instead it just appears as “shared ‘s update”

    It should be “shared [NAME HERE]‘s update”

    I have found the function bp_activity_action_bp_share_activity() in class-bp-activity-share-public-ajax.php

    I have attempted to debug the function as below:

    It appears that the $action variable is wrong in this particular instance:

    		// Prepare activity arguments.
    		$activity_args = array(
    			'user_id'           => $current_user_id,
    			'action'            => $action,
    			'component'         => $component,
    			'content'           => $content,
    			'type'              => 'bp_activity_share',
    			'primary_link'      => $current_profile_link,
    			'secondary_item_id' => $secondary_item_id,
    			'item_id'           => $item_id,
    		);
    
    		$activity_id = bp_activity_add( $activity_args );

    $action uses sprintf (in various places in that function) to replace $parent_profile_link.

    // Parent activity user's profile link.
    $parent_profile_link = bp_core_get_userlink( $user_id );

    It would appear that $user_id is wrong when sharing a custom post type activity.

    Any help?

Viewing 1 replies (of 1 total)
  • magland

    (@magland)

    I’ve continued to attempt to fix this, the below seems to be working for me. I’ve highlighted by changes / additions in bold. This starts at line 68 in bp_activity_action_bp_share_activity() in class-bp-activity-share-public-ajax.php

    // Checking if sharing is in site-wide activity or in the group.
    if ( ‘bpas-sitewide-activity’ === $share_to ) {

    // If current activity’s component is activity.

    if ( ‘activity’ === $current_activity[‘activities’][0]->component ) {

    if ( 0 === $current_activity[‘activities’][0]->item_id || 0 === $current_activity[‘activities’][0]->secondary_item_id || null === $current_activity[‘activities’][0]->secondary_item_id ) {
    // User ID as a current activity’s User ID
    $user_id = $current_activity[‘activities’][0]->user_id;

    // Item id as an activity ID.
    $item_id = $current_activity[‘activities’][0]->id;
    } else {
    $activity_id = $current_activity[‘activities’][0]->secondary_item_id;

    if($activity_id == “” ) {
    $activity_id = $current_activity[‘activities’][0]->activity_id;
    }

    // Getting parent activity using Item ID.
    $parent_activity = bp_activity_get_specific( array( ‘activity_ids’ => $activity_id ) );

    if($parent_activity[‘activities’][0]->user_id == “”) {
    $parent_activity = $current_activity;
    }

    // User ID as a parent activity’s User ID.
    $user_id = $parent_activity[‘activities’][0]->user_id;

    // Item id as an item ID.
    $item_id = $current_activity[‘activities’][0]->item_id;
    }

    } elseif ( in_array( $current_activity[‘activities’][0]->component, array( ‘groups’, ‘profile’ ), true ) ) {

Viewing 1 replies (of 1 total)
  • The topic ‘Custom post type activities’ is closed to new replies.