Now that bbPress is integrated into the Very Fabric of BuddyPress, there’s some demand for useful bbPress plugins to be ported over to BP. One of the most useful is _ck_’s excellent bb-attachments, which allows users to add attachments to their forum posts. I have spent a bit of time in the last few days porting it over to BP. If anyone out there is running a BP+bbPress setup (I think it should work in any recent version of BP, but I’ve only tested in BP 1.1) and would like to help me to test what is I think a functional BP version of the plugin, please do so. Here are the details.
- Download the plugin bb-attachments.php.zip
- Unzip and upload to your WPMU plugin directory. Activate it.
- You’ll have to make a few changes/additions to your theme files to make it work. In your BP theme directory, go to groups/single/forum/topic.php. On line 9, after the ‘template_notices’ hook, add
Next: After line 61, which reads
insert the following line
Next: On line 26, replace
<form action="" method="post" id="forum-topic-form" class="standard-form">
<form action="" method="post" id="forum-topic-form" class="standard-form" enctype="multipart/form-data">
- In the same theme directory, open edit.php and index.php. Find the <form> tags, as described in the last part of the previous step, and replace them with the alternative <form> tag (with the enctype specified)
- Follow steps 1 and 2 from here. Step 5 on that page (the “optional settings”) you can do as well, and those settings might take some tweaking for certain filetypes to be allowed.
- Start uploading!
A few caveats:
- I have not tested any of the AWS abilities. It’s possible that they will still work, as the AWS functionality is more or less abstracted from the specific bbPress hooks.
- Inline images are not yet supported. I’m working on it.
- Things look a little bit ugly with the default BP 1.1 theme. I haven’t done much to make it pretty. I’m happy to take aesthetic suggestions, if you have any.
Thanks in advance for your help. Please leave any comments here in this post’s thread.
Here’s a question that I’m sure will make you cringe!
What if you’re using the regular bb Attachments plugin on bbPress and want to use this new plugin for BP 1.1 while keeping the old attachments from the old bbPress install?
I haven’t tested your port of _ck_’s plugin yet — you say it should work with BP < 1.1 as well — but I will in due time!
Just tested on a deep-integrated BP-bbPress install (using BP 1.0.2).
It’s not liking the undeclared bbPress functions like bb_number_format_i18n() and bb_get_current_user_info(), which makes sense because bbPress isn’t integrated into the WPMU/BP stack in BP < 1.1.
I'm guessing it's probably not possible to get this working with BP < 1.1 without a lot of code refactoring.
Just wanted to say that Akismet ate my last comment on your blog.
Automattic really doesn’t like me! :p
Yeah, your question does make me cringe a bit 🙂 Actually, I don’t think that the problem is insurmountable. The structure of the bb-attachments table is exactly alike in both plugins, and they both save files in the same spot. There might be some trickiness relating to the different ways that forum paths work in bbPress standalone and in BP 1.1+, and I imagine that it would take some trickery (either in moving your files and tables around, or altering the plugin code) to get this piece of the puzzle in place. But definitely doable.
I guess I’m not all that surprised to hear that there were conflicts in BP 1.0.2. I suppose that, when I said it might work, I wasn’t really thinking straight. Part of the reason the code was relatively easily portable to BP 1.1 is because so many of the bbPress functions are loaded by that version of BP. Since that’s not the case in earlier versions, it’s unsurprising to hear that it’s not functional. On the bright side, you can still use the bbPress interface and thus _ck_’s original and much awesomer version!
It works well, if you are not trying to delete attached file. Than it shows 404. The link after deletion is:
As you can see, it’s not:
This part – “groups/wordpress/” – in after-deletion-url is missing.
And that might be a good idea to add file attachments on edit post page (when you are editing already published post in group forum).
Great catches, slaFFik. Both should be easy to fix. I won’t have access to a computer for a few days, but I’ll make the changes when I get back. At that time I’ll add the localization pack you mentioned – thanks again for that!
The plugin works fine I can upload images and download them again, but when I sign in as a different user, i see a broken image icon as well the download link is broken. I get the error ‘Sorry, download is restricted.’ on a blank page as well as a popup. I’m using the latest versions of all the software, but I’m running bbpress on a local machine using MAMP. not sure if that is part of the problem.
one more thing, the second user, no matter what their user level (even up to admin) cannot see the file the other user uploaded, nor can they even submit their own attachment. strange.
Am I supposed to install this in /mu-plugins, or in /plugins? I can’t seem to make it work either way… Am I supposed to see something in addition to the regular posting box that allows me to upload attachments? Thanks…I really want to get this working so I can launch my site. 🙂
@Deryk – Thanks for the feedback. I’m out of town for a few weeks but when I get back I will try to replicate your issues.
@Andrea – /plugins should be fine, as long as you’re sure to activate it on the main blog of your site (ie the one where BuddyPress is activated). It could be that you’re not seeing the Attachments section on the new post screens because you didn’t enter the hooks (at all, or in the correct places). Make sure that you’re putting them in the correct theme files, ie the ones at /wp-content/themes/, NOT at /wp-content/plugins/buddypress/bp-themes.
@Boone — Thanks so much! I reloaded, recoded, and reactivated, and it’s working fine now. Is there a way to increase the file upload size? Also, are movie (.mov, .wmv, etc.) uploads possible?
Hi Andrea. Yes, you can allow more file types and increase the permitted file size. Open up the plugin php file and check out the first part of the file. You’ll see a bunch of variables being defined, among which are permitted file types and file size. You’ll notice as well that permissions are separate for different kinds of users (administrators, authors, etc), permissions that I think are inherited (such that administrators can do everything that authors can do, PLUS whatever extra things you can do).
This configuration method – manually editing the plugin file – is the way that _ck_ originally set things up in the bbPress plugin. It’s nice because it doesn’t add the unnecessary overhead of an administration screen on the Dashboard, but it’s difficult for non-programmers to edit (especially given that there’s no documentation of how it works). One of my plans for improving the plugin is to move these settings – or the important ones, at least – to a regular Dashboard admin panel. Stay tuned!
In this plugin how do I modify the comment “allowed uploads: bmp (500 KB), doc (500 KB), gif (500 KB), gz (500 KB), jpeg (500 KB),
jpg (500 KB), pdf (500 KB), png (500 KB), txt (500 KB), xls (500 KB), zip (500 KB)” at the bottom of the page?
It depends what you mean.
If you want to change the permitted file types, you can do that in the configuration section of the plugin file (near the top). There you can specify the file types and sizes that can be uploaded. The text at the bottom of each page should be adjusted automatically.
If you just want to change the text, find the function bb_attachments_upload_form. You can change the words “allowed uploads” manually. The rest of the text (the list of file types) is generated automatically. You could delete some or all of it by modifying the echo line within that function.
@Deryk – Not sure if you’re following this thread, but after a bit of playing around it seems as if the view/upload permissions at the very beginning of the plugin’s settings need to be set to “read” in order to work right. Haven’t quite figured out why that’s the case, but I assume it’s because BP user roles are handled differently (or at least named differently) from bbPress roles. I don’t think it will cause a problem if you allow readers to have upload permissions, because the attachment box is located inside the new post form, which is protected from non-group-members by BuddyPress.
I’ll be making these changes to the default settings in the trunk. Thanks for your feedback.
@slaFFik – I added the upload box to the edit screens. Good call.
I tried to replicate your deletion problem, but I couldn’t. I had no problem deleting file attachments, as the URLs were all correct. Are you talking about clicking the little ‘x’ next to an attachment?
Just plugged it in and it seems to be working beautifully. Latest trunk (I think) of Buddypress and WPMU. Thanks much for porting this over.
Is there a trick to getting the file-type icons to render correctly? I know you know they’re broken, I’m just wondering if I can help. Not really a coder, though, so probably not.
Here’s my oddity: so long as I stay in Safari (mac 4.0.3), everything seems to work well. However, Firefox (3.5.5) only downloads erratically. The odd thing to me: the links seem to be generated correctly on both browsers (ie, the URLs are identical) but Firefox just can’t manage to grab the file. I get this message: “Firefox can’t find the file at http://. . . . . ” If I cut and paste that same address to the Safari toolbar, it downloads fine. For the record, I’m logged in to my install as admin in both accounts, and have also tried logging in as a different user.
OK, one more interesting note: when I upload a .doc file, it shows up correctly in my server, but when I download it it’s somehow changed to a .dot file. It still opens fine in MS Word, but I’m wondering if that has something to do with why Firefox doesn’t like it.
Thanks for working on this, it’s a great idea. I’ve installed the plugin and tried three different file types: .jpg, .doc, and .xls. All three file types uploaded, but I was only able to download the jpgs. The jpg files open within the same browser window.
Trying to download the .doc or the .xls from within the post gives me the following error:
Firefox can’t find the file at http://safe-state.com/groups/test-group/forum/topic/try-this-one/?bb_attachments=6&bbat=6.
Can you identify something I might not have done correctly?
Thanks for the comments.
What’s your server setup? Are you running Apache? Are you finding the same problem in different browsers?
I’ve had some similar problems with the plugin over the past week or so, as I try using it in different environments. I think it has to do with the plugin itself – there are issues with the way that it sends headers to the client browsers as they try to download files. My development team and I are getting closer to figuring out what the heck is going on, and once we do I’ll release a v0.2 of the plugin that addresses the issue.
Wesley, I think that you’re having the same problems as me and Mike. I’ll keep you informed as I figure out more on my end.
I’m not able to download the .xls or .doc files in IE8 either. I’m getting:
“Unable to download …(the site string)
Unable to open this internet site. The requested site is either unavailable or cannot be found. Please try again later.”
My site is hosted with shared hosting at hostgator and should be running the latest of everything.
Thanks again, looking forward to the new release. Let me know if there is anything else I can help out with.
Boone– thanks for the update. If you’d like detailed information on what I’m running on my servers, let me know and I’ll get right back to you. And I’m happy to test it on a beta site I already have up and running.
Good luck and thanks for your work on this: once it’s working, it will hugely increase the utility of Buddypress for collaboration/coordination.
What if you cannot make a directory above the httpdocs?
“make a directory /bb-attachments/ ABOVE your webroot ie./home/username/bb-attachments/”
I cannot seem to get the uploads to work. I put the bb_attachments folder in the root of the site and gave it a 777.
I can’t get this to work ata ll. Hosting with Network Solutions, so can’t create a directory outside the web root. Changed the plugin so the image path was correct, but when posting an attachment just see the page reload with a broken image link (apparently for a failed icon) along with the words:
the path to the broken image icon is utter gibberish by the way and is in the form of:
No slash after the ‘.com’ and I have no idea what the rest is meant to point at.
Viewing the forum after this initial upload shows just my post text – no attachements area, no broken icon etc.
benjaimieson – There are two problems going on. The first is that the image path seems to be wrong. Look at line 85 of the plugin file forum-attachments-for-buddypress.php. The concatenation there is _ck_’s work, and it’s intended for bbPress, so it’s unsurprising that it doesn’t work for you. I’ll figure out a way to make it BP-friendly, but in the meantime you could just hardcode the path to the forum-attachments-for-buddypress/icons directory. I think it has to be an absolute server path (ie /wwwdocs/wp-content/plugins/forum… ) but I could be wrong.
The other problem is that files aren’t uploading. That’s probably a path issue, too. Where are you putting the bb-attachments folder, if not above the web root? Try hardcoding the path on line 79 of the plugin. And make sure that you’ve set the permissions on that directly to be world-writable and world-readable (777 will definitely do it)
I changed the path on line 79 and gave it a 777 but I still get the “[failed]” next to the name of the file I tried to upload.
Paul – when you navigate to the folder via FTP do you see any uploaded files?
No there is nothing there
Thanks Boone – with a bit of fiddling, I have it half working!
Now I need to hack it to display JPG uploads inline…. maybe I’ll do that next year…. oh… hang on – that’s tomorrow.
benjamieson – If you figure out how to get images to display inline, please let me know. I have had a doozy of a time making it work (has to do with HTTP headers, I think). Glad you got it working to the extent that you have, though!
paul – Hm, I’m sort of at a loss. Are you sure you’ve got the right path? It should be an absolute server path, NOT relative to the web root.
Not sure how to figure the absolute server path out
paul – Put the following (temporary!) line directly after the <body> tag in your theme’s header.php file:
Then load a WP/BP page in your browser. The absolute path of the WP install will show at the top of your screen. (Then make sure to remove that line from header.php as soon as you’ve taken note of the path.)
If you’ve put the directory bb-attachments in the WP root (ie the same directory that contains wp-content/, wp-includes/, wp-config.php, etc), then the absolute path on line 79 of the attachments plugin file should be ABSPATH . ‘bb-attachments’, or you can hardcode it.
Not sure why WP put a space between < and ? in the code of my previous comment, but make sure that you take that space out.
Got it working, thanks for the help!
In the future it would be cool if it displayed a thumbnail of the image.
Great – glad it’s working!
You’re right – it would be great to get inline images to show up, either full-size or as thumbnails. It’s on my list of improvements. Thanks for the feedback!
Hello Boone. I am trying to get this plugin to work but no dice. I’ve followed all the instructions and even hard coded the ABSPATH, but nothing uploads, or is there anything in my error logs. Do you have any suggestions? Thanks.
Hi Joshua. Can you say a little more about what’s happening and what your setup is? Versions of BP/WP? You see the upload interface on the BP forums but nothing uploads? Do you get an error message?
I don’t get any error messages. I am using BP 1.1.3 and WP 2.8.6. No error messages show up when I try to upload. So, what I did was over write the files with new one to start over. But I guess I did not realize that the upload fields would still be there until I deactivated the plugin. I thought that’s what replacing the tags were for.
Oh, I should also mention that nothing appears in the bb-attachments directory.
Hello Boone, I have a question about your notes on this page:
If I posted a question there would you respond or should I post somewhere else on your blog?
Hi Alan – leave a comment either there or on the corresponding comment on this blog (http://teleogistic.net/2009/07/making-sitewide-tags-work/) and I’ll do my best to help!
Joshua – I’m not sure what you mean by “replacing the tags”. If you’re talking about the hooks that you added to your template files, then the explanation is that a few extra hooks are needed in templates in order to allow certain pieces of information to appear on your forum pages (to show the forum attachments underneath individual posts, for example). Other items in the plugin are attached to hooks that are already in the default BP themes. I think that the upload fields that appear underneath the entry box are among this latter group.
As for why uploads aren’t working: there are a lot of places where things could be going wrong. Are you sure that the path to bb-attachments that you hardcoded into the plugin is correct? If you’re on shared hosting, it can sometimes be a little hard to tell what your server path is. Also make sure that bb-attachments is world-writable, 777.
You might also have a look at the database, if you have access to it (through PHPMyAdmin or something like that). Look for the table bb_attachments in your WP database. 1) Does such a table exist? 2) If so, does the table have any entries in it?
@Boone, thanks for the reply and clarification. Yes, I am sure that the path is correct, it is a dedicated server, yes the database table is present and no it has no entries. Is there supposed to be a submit button for the attachment before clicking submit?
Joshua – No, there is no submit button for the attachments, just the post reply button. A couple more things to check:
<form action="" method="post" id="forum-topic-form" class="standard-form" enctype="multipart/form-data">
I’m testing the bbPress attachments plugin on BP 1.2 and it works for the most part.
I’m trying to make some cosmetic changes (changing a couple of headings), but I keep getting a cached result.
I checked out the bb_attachments_cache() function, but I’m not sure how to override the cache.
It’s probably something stupid on my part!
When you have some spare time, can you help me debug this?
I will take a detailed look sometime soon, but off the top of my head I seem to remember that bb_attachments_cache is a cached object containing all the attachment data, NOT a cache of the markup itself. Or is that what you mean?
I’m looking for some way to disable the cache, or at least, a way to see my changes.
If I try to change the header, for example, from [h3]Attachments[/h3] to [h4]Attachments – Test text[/h4], I don’t see any of the changes.
Like I said, I’m probably overlooking something very simple – I’m just not looking in the right area!
Everything works fine, except activating the plugin?
Seriously, the plugin is listed as inactive, yet I can upload and download the attachments in the forums.
I’m on WPMU 22.214.171.124 and BP 1.1.3 using the buddypress magazine theme from wpmudev.org
I made the changes to the topic, edit and index.php files before I activated the plugin, would that have mattered? I also tried to activate it site-wide before activating it simply on the main blog.
I dunno – but it works!
Just an FYI, do not confuse me (r-a-y) with “avatar” Ray above me! 😉
so… doesn’t work in BP 1.2.1, right?
– there’s no index.php in groups/single/forum/ anymore
– there’s no ‘template_notices’ hook in topics.php
anyone ported this yet or know of something with a similar capability that is BP 1.2.1 compatible?
Hi gever. I haven’t even looked at how the code works in BP 1.2+. r-a-y says above that the basic functionality (the uploading parts) still work fine, but the new bp-default theme is sufficiently different that it will probably take a fair amount of work to make all of the UI parts appear correctly.
r-a-y – Sorry for ignoring your comment for so long. I think that really I just want to ignore this plugin, as it has caused me some nightmares. In any case, you might need to make sure that the cache function is being hooked to a function that actually exists, otherwise the refresh won’t happen. I will look at the code sometime next week and let you know what I find. Ideally I’ll release something fully 1.2 compatible (and by “fully” I mean “as bug-free as my code ever gets)
Avatar Ray – I have no idea what the problem is, but as long as it’s working, I’ll put that bug fairly low on my todo list 🙂
I really don’t get this – cannot find any of the code you refer to for altering as in the instructions at the top of this page!
I am running latest version of single install of wordpress with the new version of buddypress written for this system.
I have forums enabled in buddypress which uses a bbpress install. The forums etc works ok.
I want to be able to add attachment with the forum posts but it isn’t working. It throws up errors on the screen, and although the new reply can be accessed the uploaded files are nowhere to be seen!
I am fairly new to all of this which dosen’t help.
Please can you help me?
Emma – this plugin has not yet been updated for the newest versions of BP. Others have told me that it’s possible to make this version of the plugin work with BP 1.2.1, but it takes a bit of knowledge of how templates work.
I’ll be having a look at this plugin within the next week or two and will post an update on my blog when I’ve got it working properly.
I just don’t have the know how (yet – something to work on!) but it would be a really useful plugin for me if it worked 🙂 Will keep an eye on your blog.
Not sure whether anyone is following this thread, but if so, please note that I have posted a new version of the plugin that should be quite compatible with BP 1.2: http://teleogistic.net/code/buddypress/forum-attachments-for-buddypress/. Any future comments about the plugin should go on that thread.
Pingback: Плагин: прикрепление данных в темах форумов групп | CosyDale.com: WordPress (MU) и BuddyPress
Pingback: 2009 by the numbers | Teleogistic