BuddyDev

Search

[Resolved] Create Gallery – Extend entry in activity

  • Participant
    Level: Initiated
    Posts: 13
    Maurice on #45186

    when i create a new gallery, a short activity entry is generated: “User Created a photo Gallery”.

    How can I extend this entry?

    1) Show the name of the gallery
    2.) Show the thumbnail of the gallery

    thanks for your help

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2405
    Ravi on #45194

    Hello Maurice,

    Thank you for posting. Please try the following code:

    
    
    add_filter( 'mpp_do_not_record_create_gallery_activity', '__return_true' );
    
    add_action( 'mpp_gallery_created', function ( $gallery_id ) {
    	$gallery   = mpp_get_gallery( $gallery_id );
    	$user_link = mpp_get_user_link( $gallery->user_id );
    
    	$link   = mpp_get_gallery_permalink( $gallery );
    	$action = sprintf(
    		__( '%s created a %s <a href="%s">gallery</a>', 'mediapress' ),
    		$user_link,
    		strtolower( mpp_get_type_singular_name( $gallery->type ) ),
    		$link
    	);
    
    	$content = '';
    
    	$content .= sprintf(
    		'<a href="%s"><img src="%s" /></a>',
    		esc_url( $link ),
    		esc_url( mpp_get_default_gallery_cover_image_src( $gallery, 'thumbnail' ) )
    	);
    
    	$content .= sprintf(
    		'<a href="%s">%s</a>',
    		esc_url( $link ),
    		mpp_get_gallery_title( $gallery )
    	);
    
    	// record gallery creation as activity, there will be issue with wall gallery though.
    	mpp_gallery_record_activity(
    		array(
    			'gallery_id' => $gallery_id,
    			'type'       => 'create_gallery',
    			'content'    => $content,
    			'action'     => $action,
    		)
    	);
    }, 15 );
    
    

    Gallery cover is not available at the time of creation so showing the default cover image.

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 13
    Maurice on #45440

    thx. your code works wonderfully 😉

    but the placeholder image is always displayed as the gallery image in the activity…
    can you also insert the path to the gallery image in the code?

    I know the gallery image is not available at the beginning.
    can’t you add a query that only when available the
    real cover image is inserted …?

    thx, maurice…

    • This reply was modified 1 week, 4 days ago by Maurice.
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2405
    Ravi on #45442

    Hello Maurice,

    Thank you for the acknowledgement. Please use the following code with the above code:

    
    
    add_filter( 'bp_get_activity_content_body', function ( $content, $activity ) {
    
    	if ( ! function_exists( 'mediapress' ) || empty( $activity ) || empty( $activity->id ) ) {
    		return $content;
    	}
    
    	$activity_type = bp_activity_get_meta( $activity->id, '_mpp_activity_type', true );
    	$gallery_id    = bp_activity_get_meta( $activity->id, '_mpp_gallery_id', true );
    
    	if ( ! $activity_type || ! $gallery_id || 'create_gallery' != $activity_type ) {
    		return $content;
    	}
    
    	$gallery_permalink = mpp_get_gallery_permalink( $gallery_id );
    
    	$new_content = '';
    	if ( mpp_gallery_has_cover_image( $gallery_id ) ) {
    		$new_content = sprintf(
    			'<a href="%s"><img src="%s" /></a>',
    			esc_url( $gallery_permalink ),
    			esc_url( mpp_get_gallery_cover_src( 'thumbnail', $gallery_id ) )
    		);
    
    		$new_content .= sprintf(
    			'<a href="%s">%s</a>',
    			esc_url( $gallery_permalink ),
    			mpp_get_gallery_title( $gallery_id )
    		);
    	}
    
    	return $new_content ? $new_content : $content;
    }, 10, 2 );
    
    

    Please check and let me know if it works.

    Regards
    Ravi

    • This reply was modified 1 week, 3 days ago by Ravi.
  • Participant
    Level: Initiated
    Posts: 13
    Maurice on #45454

    yes! its perfect! thx ;))

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2405
    Ravi on #45455

    Hello Maurice,

    Thank you for the acknowledgement. I am glad that I could help.

    Regards
    Ravi

The topic ‘ [Resolved] Create Gallery – Extend entry in activity’ is closed to new replies.

This topic is: resolved