Buddypress:upload image and custom field for image category in activity
-
I am using buddypress to develop photo sharing social media website.I m using BuddyPress Activity Plus plugin to share images,videos and links.Using it i m able to upload image.But additionally I want to add dropdown box to specify the category for the image like nature,painting,wild photography etc.I was not able to add custom image category field using hooks like bp_activity_posted_update,bp_groups_posted_update.I am searching for solution to customize Buddypress Activity Plus to add custom fields to whats-new-form.Thank you for your help in advance.
https://www.ads-software.com/plugins/buddypress-activity-plus/
-
Hello vaibhav125shukla,
I’m afraid Activity Plus will not give you ability to add addtional fileds with hooks because it does not use it. Whole interface is handled with JS, you can find it in /wp-content/plugins/buddypress-activity-plus/js/bpfb_interface.js
So if you want to add something there you also need to use JavaScript.kind regards,
KasiaHey Kasia,thank u for your reply.I am following the same bpfb_interface.js which you mentioned.I will be able to add the category field along with the image being uploaded only if i get the data insertion flow.I find it difficult to figure out the data insertion flow of activity content and image upload into the database.Any further insight,direction from your side will help definitely me.See if you can.
Hello vaibhav125shukla,
Please check this file /wp-content/plugins/buddypress-activity-plus/lib/class_bpfb_binder.php line 319. There is function function ajax_update_activity_contents () – its function that actually save activity updates.
If you will go back to bpfb_interface.js there in line 435 is this$(document).on('click', '#bpfb_submit', function ()
this one is using ajax to send data to ajax_update_activity_contents that is doing saving.
kind regards,
KasiaThanks Kasia.I already followed the same.I was able to add new field for image category into wp_bp_activity_meta.Thank you very much for your kind support.
Hi vaibhav125shukla,
Please do share your results if you can get this to work. I too (as I am sure others) would love to have categories for photos with this plug.
Thanks.Hello vaibhav125shukla,
Glad to see you get that working! If you could share solution with us it would be really awesome!
kind regards,
KasiaYes why not.I m sharing the solution.
As per client suggestion,i have given field name for category as preference.
In my theme ‘boss’,under buddypress folder,i have activity post form post_form.php.
It contents are as follows:
post_form.php:<div id="whats-new-textarea"> <textarea class="bp-suggestions" name="whats-new" id="whats-new" cols="50" rows="10" <?php if ( bp_is_group() ) : ?>data-suggestions-group-id="<?php echo esc_attr( (int) bp_get_current_group_id() ); ?>" <?php endif; ?> ><?php if ( isset( $_GET['r'] ) ) : ?>@<?php echo esc_textarea( $_GET['r'] ); ?> <?php endif; ?></textarea> <select name="preference" id="preference"> <option value="">Select Preference</option> <?php foreach($pref_result as $pref):?> <option value="<?php echo $pref->ap_title;?>"><?php echo $pref->ap_title;?></option> <?php endfor</strong>each;?> </select> </div>
In bpfb_interface.js,i have variable preference,which stores selected preference.
bpfb_interface.js:var $preference; function init () { $form = $("#whats-new-form"); $text = $form.find('textarea[name="whats-new"]'); $textContainer = $form.find('#whats-new-textarea'); $preference=$form.find('select[name="preference"]'); createMarkup(); $('#bpfb_addPhotos').click(function () { if (_bpfbActiveHandler) _bpfbActiveHandler.destroy(); _bpfbActiveHandler = new BpfbPhotoHandler(); $("#bpfb_cancel_action").show(); return false; }); $('#bpfb_addLinks').click(function () { if (_bpfbActiveHandler) _bpfbActiveHandler.destroy(); _bpfbActiveHandler = new BpfbLinkHandler(); $("#bpfb_cancel_action").show(); return false; }); $('#bpfb_addVideos').click(function () { if (_bpfbActiveHandler) _bpfbActiveHandler.destroy(); _bpfbActiveHandler = new BpfbVideoHandler(); $("#bpfb_cancel_action").show(); return false; }); $('#bpfb_cancel_action').click(function () { $(".bpfb_toolbarItem.bpfb_active").removeClass("bpfb_active"); _bpfbActiveHandler.destroy(); $("#bpfb_cancel_action").hide(); return false; }); $(".bpfb_toolbarItem").click(function () { $(".bpfb_toolbarItem.bpfb_active").removeClass("bpfb_active"); $(this).addClass("bpfb_active"); }); $(document).on('click', '#bpfb_submit', function () { var params = _bpfbActiveHandler.get(); if($('#preference').val().length!=0){ var group_id = $('#whats-new-post-in').length ? $('#whats-new-post-in').val() : 0; $.post(ajaxurl, { "action": "bpfb_update_activity_contents", "data": params, "content": $text.val(), <strong> "preference": $('#preference').val(),</strong> "group_id": group_id }, function (data) { _bpfbActiveHandler.destroy(); $text.val(''); $('#activity-stream').prepend(data.activity); /** * Handle image scaling in previews. */ $(".bpfb_final_link img").each(function () { $(this).width($(this).parents('div').width()); }); }); }else{ alert('You must select preference.'); } }); $(document).on('click', '#bpfb_cancel', function () { $(".bpfb_toolbarItem.bpfb_active").removeClass("bpfb_active"); _bpfbActiveHandler.destroy(); }); }
In buddypress_activity_plus’ lib folder,inside class_bpfb_binder.php there is a function ajax_update_activity_contents.Its code is given below.
class_bpfb_binder.php:function ajax_update_activity_contents () { $bpfb_code = $activity = ''; $aid = 0; $codec = new BpfbCodec; if (!empty($_POST['data'])) { if (!empty($_POST['data']['bpfb_video_url'])) { $bpfb_code = $codec->create_video_tag($_POST['data']['bpfb_video_url']); } if (!empty($_POST['data']['bpfb_link_url'])) { $bpfb_code = $codec->create_link_tag( $_POST['data']['bpfb_link_url'], $_POST['data']['bpfb_link_title'], $_POST['data']['bpfb_link_body'], $_POST['data']['bpfb_link_image'] ); } if (!empty($_POST['data']['bpfb_photos'])) { $images = $this->move_images($_POST['data']['bpfb_photos']); $bpfb_code = $codec->create_images_tag($images); } } $bpfb_code = apply_filters('bpfb_code_before_save', $bpfb_code); // All done creating tags. Now, save the code $gid = !empty($_POST['group_id']) && is_numeric($_POST['group_id']) ? (int)$_POST['group_id'] : false ; if ($bpfb_code) { $content = !empty($_POST['content']) ? $_POST['content'] : ''; $content .= "\n{$bpfb_code}"; $content = apply_filters('bp_activity_post_update_content', $content); $preference = !empty($_POST['preference']) ? $_POST['preference'] : ''; $aid = $gid ? groups_post_update(array('content' => $content, 'group_id' => $gid)) : bp_activity_post_update(array('content' => $content,'preference'=>$preference)) ; global $blog_id; bp_activity_update_meta($aid, 'bpfb_blog_id', $blog_id); bp_activity_update_meta($aid, 'preference', $preference); } if ($aid) { ob_start(); if ( bp_has_activities ( 'include=' . $aid ) ) { while ( bp_activities() ) { bp_the_activity(); if (function_exists('bp_locate_template')) bp_locate_template( array( 'activity/entry.php' ), true ); else locate_template( array( 'activity/entry.php' ), true ); } } $activity = ob_get_clean(); } header('Content-type: application/json'); echo json_encode(array( 'code' => $bpfb_code, 'id' => $aid, 'activity' => $activity, )); exit(); }
If you get any problem,do notify me.Thank you guys.
Guys please have a look at one new problem posted by me.It is related to buddypress activity sharing.
Reshare buddypress activity to only me,friends or allSaludos @ wpmudev-support2 I need a favor, in the activities of the registered users, the text appears first and then the image, even when it is much text is fractioned with the read more and no longer see the image until seeing the complete note; What should I do to make the image appear first and then the text? Thank you.
Hi @redlvd,
Could you please start your own thread per forum welcome and we will looking into this for you ??
Cheers,
PredragHi @wpmudev-support2,i have started new thread titled Buddypress activity plus-Keep original size or aspect ration of images intact.Please kindly go thru it.buddypress activity plus uploaded image size
- The topic ‘Buddypress:upload image and custom field for image category in activity’ is closed to new replies.