I finally got some time to package the code into a plugin which you can download at the WordPress Plugins repository. Give it a spin and let me know how it fairs in your particular setup. The plugin should be ok on WordPress 3.2.1 to 3.8.1 running BuddyPress 1.5 to 1.9.2
Thanks very much for all the feedback I got in the comments on the behaviour of the code.
Plugin en el español (http://wordpress.org/plugins/buddypress-xprofile-image-field/) por Andrew de WebHostingHub. Gracias Andrew!
BuddyPress is a plugin that brings social networking capabilities to WordPress. It comes with features such as Friend connections, Activity streams (status posting), Private messaging, Groups and Forums. There is lot’s more you can do with it via BuddyPress Plugins. These are simply WordPress plugins that are compatible with BuddyPress. You can work with BuddyPress as just one component of your WordPress website’s functionality, or you can have it as your central component and completely hide the rest of WordPress. Just like WordPress, BuddyPress is completely open source and almost as flexible.
How BuddyPress Works
Being part of the WordPress ecosystem, BuddyPress employs hooks liberally in its implementation. These help theme and plugin developers greatly when it comes to interfacing with BuddyPress in a future-proof manner. When used correctly, the hooks allow developers to write code that doesn’t break on newer versions of BuddyPress.
Among the most important hooks in BuddyPress are:
bp_screens: It processes functions that respond to user input with visual feedback. Basically this is the hook to use when you want to output a page in response to user input. A good example is displaying a list of friends in response to the clicking of the friends menu.
bp_actions: This hook is similar to
bp_screens, but does not give visual feedback. A good example of such is when accepting a friend request. This hook is called before
bp_screens and we shall use this rule in implementing the image field.
Functionality in BuddyPress is delivered via components. Roughly, a component maps to a feature. For example the Groups feature is handled by the Group component. Components contain the various bp_screens and bp_actions hooks required to respond to user input. A fresh installation of BuddyPress has the following components:
– Extended Profiles: maintains user profile details such as name
– Friend Connections: allows users to make and accept friend requests
– Private Messaging: handles messaging between specific users. Only the users addressed in the messages can view them.
– Activity Streams: handles the posting of public statuses and generally tracking the actions of users.
– Groups: handles the creation and maintenance of user groups. Users can create groups, invite other users etc.
– Forums: this component allows topical discussions to be carried out among users either site-wide or within groups.
I recently switched to Mercurial source control and it’s proving to be a lot more fun to work with than Subversion. However there is one SVN feature that I have been missing dearly: The ability to export deployment code. SVN has an export command that I would use to generate a copy of project source files free from all the source control utility folders.
Up until recently, I had not figured out how to do this in Mercurial. I had to manually remove the .hg folder in order to move project files to production. That was until I came across this gem. Mercurial has an Archive command. It essentially does the same thing as the SVN Export command. In order to archive in TortoiseHg (Windows):
- Right-click the source code project folder and select Hg Repository Explorer.
- In the Repository Explorer, right-click on the default (tip) revision point and select Archive.
- On the Archive dialog:
- Select the Archive revision you want to export
- Supply the destination path
- Pick Directory of files as the Archive type.
- Click Archive.
You now have a copy of your source files that does not contain source control infrastructure.
Thesis is a popular premium WordPress theme. Unlike many themes that are implemented to plug directly into the WordPress-defined template structure, Thesis is a force unto itself. It’s a framework that completely redefines the approach to WordPress customization. It achieves this by supplying a rich set of hooks into the various stages of the page generation process and then creates one location where all customization code goes. One file – custom_functions.php – holds all the custom code and is safe from overwriting during theme upgrades.
The Thesis framework is sufficient for a wide range of customization needs. However, as with all popular software, users’ needs eventually go beyond the default capabilities of the software. Thesis has in-built support for creating 2-column and 3-column sites. The layouts are configured via the Design Options menu and apply site-wide. You can override the layout of particular pages (eg home page) by intercepting the page generation process in custom_functions.php. The problem with this approach is that you have to know the designation (home), name or id of the page before-hand as you customize the site. If these details change after the site has been launched, then the customization code is going to break.
What if you want to alter the layout of an arbitrary number of pages that are going to be created in the future? All you know at customization time is what the layout shall be, but not which particular pages shall use it. This obviously calls for a solution that does not involve updating the customization code every time a page requires the custom layout. Even better, it calls for a facility that can be triggered while the page is being created by the user. A facility such as the WordPress page Template selection drop-down. If you could create a custom template and have it selectable on the Template drop-down, then the user would simply pick it during page creation (or editing) and have it used for page rendering.
Thesis (version 1.6) does not support plugging in of custom template files, but it is flexible enough to pick them up if you know where to tweak. Here’s how you go about doing exactly that:
1) Problem description
The hypothetical site we shall be working with is a travel blog. The site has various sections, but the one that is of interest here is one called Places. It has pages describing various travel destinations. These pages have advertising that shows in the left column. Every other type of page on the site does not have this left column and therefore no ads showing. How do we get the ads to show on the Places pages, but not on any other page?
I’m switching source code control systems from Subversion to Mercurial. I had no idea Mercurial existed until I read this post by Joel Spolsky. He didn’t do a very good job of saying exactly what Mercurial does, but he said enough for me to go googling. I had already worked with a distributed version control system in the shape and form of git. Coming from a Windows background, I found git to be extremely unfriendly. There are a number of visual interfaces to git eg. git gui, but I realized that the most flexible way to use git was from the command line. I don’t like command lines. It wasn’t long before I went on the prowl for a more palatable source code management tool. I got hooked onto Subversion due to the incredibly handy Windows Explorer integration courtesy of TortoiseSVN. I could do my source control activities right where the files were displaying and to date I haven’t had to open the command line once.
Enter Mercurial. I like the whole idea behind distributed version control. The biggest selling point, however, is the fact that merging project branches doesn’t cause premature graying of your hair. I have avoided branching Subversion projects, but at the cost of having to run experiments on the main (only) source code branch. Now with all this talk of branching and merging, it’s kind of funny that the first hurdle you encounter has to do with getting started. It seems to have been assumed by many that you’ll already have a repository by the time you install Mercurial. But then how was that first repository created?
Step 1: Initialize the repository
Install TortoiseHg for Windows Explorer integration. It’s best to get the repository going when you already have a folder with files in it. This is the project that you want to keep track of. I shall use my project folder C:\projects\GameOfLife for illustration.
Right-click the folder and select TortoiseHg > Create Repository Here
This opens the TortoiseHg Init dialog where you click Create.
A notification comes up confirming that the repository has been created so click OK, then click Close (on the Init dialog). The folder C:\projects\GameOfLife now has a green checkmark on it indicating that it is under source control. Opening it reveals two new objects: a file .hgignore and a folder .hg.
Step 2: Setting up the Ignore Filter
It’s common for software project folders to contain files that do not need to be tracked. These files include intermediate compiler output, debugger symbol files etc. You can tell Mercurial to ignore these files so they do not get picked as files requiring some attention. To do this, right-click on the project folder and select TortoiseHg > Edit Ignore Filter
The Ignore Filter dialog opens up showing a list of all the files in the project folder (including sub-folders). Click on a file that you do not wish to track and it shows up in the Glob text field.
Click on the Add button to the right of the text field in order to have that file added to the Filters list.
If you want to ignore all the files in a particular subfolder, click on one of the subfolder’s files (eg. GameOfLife/obj/Debug/GameOfLife.pdb) and then replace the file name with *.* (eg. GameOfLife/obj/Debug/*.*)
Click Add to include the new filter in the Filters list
Continue the process of adding filters to your heart’s content then close the Ignore Filter dialog.
Step 3: Adding the project files to the repository
Mercurial cannot start keeping track of files until you tell it to, so right-click on the project folder and select TortoiseHg > Add Files.
This brings up the hg add dialog with all the project files checked. Now since you had earlier indicated the files you want to ignore, the file list should just contain the files you want tracked.
Click on Add to get them queued for the commit.
Step 4: Commit changes
Right-click on the project folder and select Hg Commit. Mercurial now has the file states initialized and all changes from this point on can be tracked.