BuddyDev

Search

[Resolved] Mediapress Bulk Uploads again…

  • Participant
    Level: Enlightened
    Posts: 145
    NikB on #32917

    Hi Brajesh

    This is a continuation of my previous query (here – https://buddydev.com/support/forums/topic/mediapress-bulk-uploads/) but thought it would keep things simpler to start a new thread as my thoughts have moved on a bit since then.

    What I am trying to achieve: when a user uploads several images at once, they should appear as a single activity entry (eg. X just uploaded 6 images) rather than as individual entries.

    I understand that this is currently only possible by switching off “auto publishing media to activity” and then by directing users to go to the “Edit Gallery” page where the option appears to allow users to publish outstanding images (eg. You have 6 photo not published to actvity). This works fine and produces the desired result in the activity feed BUT it’s not hugely intuitive and many users are forgetting (which of course means their images are not getting posted at all).

    Whilst ideally I’d love for the activity entry to be created “automatically” upon completion of a bulk upload, I was having trouble getting my head around the requirements and therefore came up with idea of adding the “You have 6 photo not published to actvity. PUBLISH. HIDE” link underneath the upload box (still a 2 step process but more obvious to the user as to what they need to do) by adding

    add_action( ‘mpp_after_gallery_upload_feedback’, ‘mpp_gallery_show_publish_gallery_activity_button’ );

    to my bp-custom.php.

    This looks as if it would work but, long story short, I need to find a way of calling this action AFTER the upload has completed (since it obviously won’t appear until the unpublished files have been added).

    Any suggestions on how to achieve this eg.by re-running the action and/or a hook I can look out for which indicates when the uploads are complete?

    With many thanks in advance and fingers crossed.

    Nik

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2459
    Ravi on #32918

    Hello Nik,

    Thank you for posting. There is no hook available after collection of files have been uploaded. But in js there is a trigger available after collection complete. Please check if it can help you.

    https://github.com/buddydev/mediapress/blob/master/assets/js/uploader.js#L259

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 145
    NikB on #32920

    Hi Ravi

    Thank you for the hint. That definitely looks promising although unfortunately I’m not so familiar with js so if you have any suggestions as to how I would take advantage of that in PHP, I would be very grateful.

    No worries if not… it looks like the right direction so I’ll do a bit more research of my own.

    Regards
    Nik

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2459
    Ravi on #32921

    Hello Nik,

    Try the following way. It might help you.

    
    add_action( 'mpp_enqueue_scripts', function () {
        $publish_link = sprintf( '<a href="#">%s</a>', __( 'Publish' ) );
    
    	wp_add_inline_script(
    		'mpp_uploader',
    		"jQuery(document).on( 'mpp:uploader:upload:complete', function( self, up, files ) {
    			    jQuery('div#mpp-uploaded-media-list-gallery').append('" . $publish_link .  "');
    		} );"
    	);
    }, 11 );
    
    

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 145
    NikB on #32922

    Ravi you’re a star!

    I can see how that works and can (hopefully) tweak it further in order to produce the link I need.

    Thank you so much for your asssitance.

    Nik

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2459
    Ravi on #32923

    Hello Nik,

    Thank you for your kind words. I am glad that I could assists.

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 145
    NikB on #32925

    Hi again Ravi

    Sorry to trouble you again but I now have the concept working quite well by editing your code as follows –

    `add_action( ‘mpp_enqueue_scripts’, function () {

    $gallery_id = mpp_get_current_gallery_id();

    $link = mpp_gallery_get_publish_activity_url( $gallery_id );

    $format_link = ‘<a href=”‘. $link .'” rel=”noopener”>PUBLISH</a>’;

    $publish_link = sprintf(
    “Click %s HERE.”,
    $format_link
    );

    wp_add_inline_script(
    ‘mpp_uploader’,
    “jQuery(document).on( ‘mpp:uploader:upload:complete’, function( self, up, files ) {
    jQuery(‘div#mpp-uploaded-media-list-gallery’).append(‘” . $publish_link . “‘);
    } );”
    );
    }, 11 ); `

    However… a couple of things which would make it even better, and if I can possibly trouble you just a little more, I wonder if you have any thoughts on the following –

    1. Clicking “Publish” takes the user to the Gallery Edit page (with the message “Published to activity successfully”). Whilst not a major issue, this is not ideal as a little confusing for users when they end up on a different page. Do you have any suggestions for ending up on the Upload page (but still with the success message)?

    2. This is an odd one but seems to be happening even when users click “Publish to activity” from the Edit Gallery page, so I’m actually wondering if it’s a bug ie. the activity entry created has the type “mpp_media_upload” and the entry in the activity feed simply shows the users name and a grid of the images they have uploaded. If I “manually” change the activity type in the database to “mpp_media_pubish” then the activity shows the text “X shared 2 photos to Y” (which is obviously preferable). Any idea why this is happening and/or what can be done to solve the issue?

    ie. Am I right in thinking that in this scenario (ie. single activity entry for multiple images) type SHOULD be being set as “mpp_media_publish” and if so, why isn’t this happening?

    I’ve been wanting to solve the multiple upload issue for months now, and with your assistance, I think I’m finally almost there, but would really appreciate any thoughts on these last two outstanding “tweaks”.

    Warm regards
    Nik

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2459
    Ravi on #32926

    Hello Nik,

    I will look into it and will update you soon.

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 145
    NikB on #32928

    Many thanks Ravi.

    To be honest, point 2 is more of an issue than point 1, and I can’t even work out how/why it’s happening but would definitely be great if I could find a way to solve both issues.

    I’ll look forward to hearing from you.
    Nik

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2459
    Ravi on #32930

    Hello Nik,

    There is no such thing like ‘mpp_media_publish’. But you can filter action using filter like the following way.

    
    add_filter( 'mpp_format_activity_action_media_upload', function ( $action, $activity, $media_id, $media_ids ) {
    	$activity_type = mpp_activity_get_activity_type( $activity->id );
    
    	if ( 'media_publish' === $activity_type ) {
    
    		$media_count = count( $media_ids );
    		$media_id    = current( $media_ids );
    
    		$gallery_id = mpp_activity_get_gallery_id( $activity->id );
    		$gallery    = mpp_get_gallery( $gallery_id );
    
    		$userlink = mpp_get_user_link( $activity->user_id );
    
    		$gallery_url = mpp_get_gallery_permalink( $gallery );
    		$gallery_link = '<a href="' . esc_url( $gallery_url ) . '" title="' . esc_attr( $gallery->title ) . '">' . mpp_get_gallery_title( $gallery ) . '</a>';
    
    		$type = $gallery->type;
    
    		$type = _n( strtolower( mpp_get_type_singular_name( $type ) ), strtolower( mpp_get_type_plural_name( $type ) ), $media_count ); // photo vs photos etc.
    
    		$action = sprintf( __( '%s added %d new %s to %s', 'mediapress' ), $userlink, $media_count, $type, $gallery_link );
    
    		// allow modules to filter the action and change the message.
    		$action = apply_filters( 'mpp_activity_action_media_publish', $action, $activity, $media_id, $media_ids, $gallery );
    	}
    
    	return $action;
    }, 10, 4 );
    
    

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: resolved