Activity Plus wont hook into BuddyDev Sitewide Activity post widget

Hi WPMUDEV team!

So we're looking for the ability to post activity from a widget using buddydev's sitewide activity with the Activity Plus functionality of uploading media. As of now, I cannot get the Activity Plus options to load as they do on the /activity and group pages.

Here it's working at the dev site /activity page
But not working on the dev site homepage (scroll down to sidebar)

I have called the necessary scripts to get this to work on the homepage in functions.php using the code in Buddypress activity plus and sitewide activity widget and I can see it in the source code for the homepage but:

1. It's is still not working, ie. not dynamically adding the options to the what's new post form, and

2. I'm trying to get it to work on all pages using sitewide activity plus as opposed to simply the home page.

Could anyone help point me in the right direction? I'm not sure what I'm missing. I was going to hardcode the html into the buddydev plugin's post-form.php but it looks like activity plus html is dynamically generated with js? I can see it when I inspect element in chrome dev tools but not when I view source.

Any help would be greatly appreciated!

  • Jude

    Hi there Jim

    I went through your post and looked through the codebases of both plugins. Its a bit more complex than I initially thought. I have written a plugin that handles this smoothly for you, simply select add a new plugin and upload the attached zip file and it should work.

    I have called the necessary scripts to get this to work on the homepage in functions.php

    Apart from calling the scripts you need to refactor some code, basically you need to prefix "swa" to the respective fields and append the AJAX responses to the correct container.

    I was going to hardcode the html into the buddydev plugin's post-form.php

    This approach wont work because it contains a lot of AJAX calls and the HTML itself is dynamic

    Could anyone help point me in the right direction? I'm not sure what I'm missing.

    I could explain but it would take a lot of threads back and forth as there is quite a bit of tinkering needed to get this to work.

    I am posting the php code in the next post, but the JS is around 500 lines so if you need that explained let me know ill post a gist here.

    You can use this as is or make some modifications if your site requires.

    Hope this helps

    Cheers
    Jude

  • Jim

    @Jude Thank you. This is wonderful. I'm really grateful for your time and efforts and impressed with wpmudev in general. I tested it and added it to the live site as well. Works pretty much perfectly.

    I'm going to mark this as resolved.

    For future readers with this issue, it does look like you can post text or share an activity plus media type. If a comment is added, it gets lost in the post when opting to share a link or image. For our purposes this works.

  • Jim

    Hey @Jude I'm realizing that when someone uses the Activity Plus feature to post an image, link, etc., in a specific group by using that drop down of where to post to, that it only posts to their activity feed. Do you have any thoughts about a direction for that? It appears that the text area input and the groups select fields aren't being accounted for.

    <div id="swa-whats-new-post-in-box"> Post in:
    	<select id="swa-whats-new-post-in" name="swa-whats-new-post-in">
    		<option selected="selected" value="0">My Profile</option>
    		<option value="7">#Philly Pics</option>
    		<option value="6">Business</option>
    		<option value="5">Entertainment</option>
    		<option value="4">Food</option>
    		<option value="2">Lifestyle</option>
    		<option value="3">Music & Arts</option>
    		<option value="8">News</option>
    		<option value="1">Sports</option>
    	</select>
    </div>
    <input type="hidden" id="swa-whats-new-post-object" name="swa-whats-new-post-object" value="groups">

    I really appreciate all of the work you've done. If you could even just point me in the right direction, I'd greatly appreciate it.

  • Jude

    Hey Jim,

    Thanks for you kind words.

    For future readers with this issue, it does look like you can post text or share an activity plus media type. If a comment is added, it gets lost in the post when opting to share a link or image. For our purposes this works.

    This is actually a small bug, I missed one of the form ids as I was scanning through the code, its fixed now.

    When I was working on the fix for this I saw your second post, its another small fix so I applied that as well.

    Here is the updated plugin, simply overwriting the folder will apply the fix for you :slight_smile:

    Hope this helps

    Cheers,
    Jude

    PS: This is the PHP Code should anybody want to try a similar integration in future

    if(! class_exists('Swa_Bpfb') ):
    
    include_once(plugin_dir_path( dirname(__FILE__) ).'buddypress-activity-plus/lib/class_bpfb_binder.php');
    
    class Swa_Bpfb{
    
    	var $swa_bpfb ;
    
        function __construct(){
        		$this->swa_bpfb =new BpfbBinder() ;
    			add_action( 'wp_footer', array ( $this, 'inject_styles' ));
    	        add_action( 'wp_footer', array ( $this, 'inject_scripts' ));
            }
    
    	function inject_styles() {
    		wp_enqueue_style('thickbox');
    		wp_enqueue_style('file_uploader_style', BPFB_PLUGIN_URL . '/css/external/fileuploader.css');
    		if (!current_theme_supports('bpfb_interface_style')) {
    			wp_enqueue_style('bpfb_interface_style', BPFB_PLUGIN_URL . '/css/bpfb_interface.css');
    		}
    		if (!current_theme_supports('bpfb_toolbar_icons')) {
    			wp_enqueue_style('bpfb_toolbar_icons', BPFB_PLUGIN_URL . '/css/bpfb_toolbar.css');
    		}
    	return;
    	}
    
    	function inject_scripts() {
    		wp_enqueue_script('jquery');
    		wp_enqueue_script('thickbox');
    		if (!current_theme_supports('bpfb_file_uploader')) {
    			wp_enqueue_script('file_uploader', BPFB_PLUGIN_URL . '/js/external/fileuploader.js', array('jquery'));
    		}
    		wp_enqueue_script('bpfb_integrate_script', plugin_dir_url( __FILE__ ) . '/integrate.js', array('jquery'));
    		$this->swa_bpfb->js_plugin_url();
    		wp_localize_script('bpfb_integrate_script', 'l10nBpfb', array(
    			'add_photos' => __('Add photos', 'bpfb'),
    			'add_remote_image' => __('Add image URL', 'bpfb'),
    			'add_another_remote_image' => __('Add another image URL', 'bpfb'),
    			'add_videos' => __('Add videos', 'bpfb'),
    			'add_video' => __('Add video', 'bpfb'),
    			'add_links' => __('Add links', 'bpfb'),
    			'add_link' => __('Add link', 'bpfb'),
    			'add' => __('Add', 'bpfb'),
    			'cancel' => __('Cancel', 'bpfb'),
    			'preview' => __('Preview', 'bpfb'),
    			'drop_files' => __('Drop files here to upload', 'bpfb'),
    			'upload_file' => __('Upload a file', 'bpfb'),
    			'choose_thumbnail' => __('Choose thumbnail', 'bpfb'),
    			'no_thumbnail' => __('No thumbnail', 'bpfb'),
    			'paste_video_url' => __('Paste video URL here', 'bpfb'),
    			'paste_link_url' => __('Paste link here', 'bpfb'),
    			'images_limit_exceeded' => sprintf(__("You tried to add too many images, only %d will be posted.", 'bpfb'), BPFB_IMAGE_LIMIT),
    			// Variables
    			'_max_images' => BPFB_IMAGE_LIMIT,
    		));
    	return;
    	}
    }
    endif ;
    
    $integrate = new Swa_Bpfb() ;

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.