• Hello,
    here again. Your plugin is so wonderful that I’d like to add some more feature enhancement: Add an activity update when a new document was uploaded.

    Here’s the patch:

    –> class gfold_Group_Extension
    into function __construct():

    // Add the activity actions for uploaded group documents
    add_action( 'bp_gfold_activity', array( $this, 'activity_for_gfold_upload' ) );
    add_action( 'bp_register_activity_actions', array( $this, 'register_activity_types' ) );
    add_action( 'bp_group_activity_filter_options', array( $this, 'register_filter_options' ) );
    add_action( 'bp_member_activity_filter_options', array( $this, 'register_filter_options' ) );

    new functions into same class:

    //register the activity type for Group Folder Uploads
    function register_activity_types() {
    	bp_activity_set_action( $this->gid, 'gfold_upload', __( 'New document uploaded', 'bp-gfold' ) );
    }
    
    //add filtering options for activity types for Group Folder Uploads
    function register_filter_options() { ?>
    	<option value="gfold_upload"><?php _e( 'Uploaded Documents', 'bp-gfold' ) ?></option>
    <?php }
    
    // generate activity update on document uploding
    function activity_for_gfold_upload( $success, $type = 'upload' ){
    	global $bp;
    
    	$page = get_query_var('name');
    	$files = $this->gfold->fetch($page);
    	if ($success == 1) {
    		$activity_action = sprintf(
    			__( '%s uploaded the document %s to %s in %s:', 'bp-gfold'),
    			bp_core_get_userlink( bp_loggedin_user_id() ),
    			'<strong>' . htmlspecialchars($files[0]['disp']) . '</strong>', // Name of File
    			'<a href="' . bp_get_group_permalink( $bp->groups->current_group ).$this->slug.'/">' . $this->name. '</a>', // Gfold Tab Link
    			'<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>'
    		);
    	} else {
    		for ($f = 0; $f < $success; $f++) {
    			$filename[] = htmlspecialchars($files[$f]['disp']);
    		}
    		$activity_action = sprintf(
    			__( '%s uploaded the documents %s to %s in %s:', 'bp-gfold'),
    			bp_core_get_userlink( bp_loggedin_user_id() ),
    			'<strong>' . implode(', ', $filename) . '</strong>',
    			'<a href="' . bp_get_group_permalink( $bp->groups->current_group ).$this->slug.'/">' . $this->name. '</a>',
    			'<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>'
    		);
    	}
    	unset($files);
    
    	groups_record_activity(
    		array(
    			'action' 	=> $activity_action,
    			'content' => '',
    			'primary_link' => bp_get_group_permalink( $bp->groups->current_group ).$this->slug,
    			'type' 		=> "gfold_upload",
    			'item_id' => $this->gid
    			)
    	);
    }

    And last but not least, call the action inside the function display():

    if ($success == 0) {
    	$msg = __('Upload failed.', 'bp-gfold');
    } else {
    	if ($success == $total) {
    		$msg = $total > 1 ? __('Done!', 'bp-gfold') : __('All done!', 'bp-gfold');
    	} else {
    		$msg = $success == 1 ? __('1 file uploaded successfully.', 'bp-gfold') : __('%s files uploaded successfully.', 'bp-gfold');
    	}
    	// Do activity update
    	do_action( 'bp_gfold_activity', $success, 'upload' );
    }

    https://www.ads-software.com/extend/plugins/buddypress-group-folders/

Viewing 2 replies - 1 through 2 (of 2 total)
  • I think something I do wrong, because i have this error:

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, class ‘gfold_Group_Extension’ does not have a method ‘activity_for_gfold_upload’ in /nfs/c08/h04/mnt/140927/domains/redminka.com/html/wp-includes/plugin.php on line 406

    Now i found my error. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘add activity update on upload success’ is closed to new replies.