Different website for bio box / comment link?
-
We have a multi-author site, and I’d like to allow our authors to have a link to their personal websites in their biography box. However, the way it’s set up now, that URL is also what their name links to in comments, and I’d rather that link to our own site to indicate they’re on staff. Is there any way to set a URL for the biography box other than inputting it into the website field in the profile? Maybe set up a separate field for bio box website? Could it be limited to authors, if so?
Thanks so much — this is one of the best-made plugins I’ve come across!
-
Although it might not be immediately obvious, this is one of the plugin’s Frequently Asked Questions.
As you can control the users on your site, you’ll need to ensure that your authors have your site’s URL set in the
websitefield in their user profiles. This will then automagically ensure that any comments they make under their user account will link back to your site, indicating they’re on staff.You can then augment the list of contact methods in a user’s profile via the plugin’s
wp_biographia_contact_infoandwp_biographia_link_itemfilters, by adding code similar to the examples you’ll see in the plugin’s Filter Support and Usage documentation to add an additional author’s website contact link, or whatever you want to label it as. This code needs to go either in your theme’sfunctions.phpor into whatever plugin or method you use for site specific customisations.By default, the method shown in the example code adds additional contact details to a user’s profile and to the plugin’s Biography Box for all users but you could constrain this to only users who have the
authorrole by using the WordPress roles and capabilities API calls to check that the current logged in user is anauthor(in thewp_biographia_contact_infofilter) so that the new field only appears inauthors profiles and check that the author of the current post (in thewp_biographia_link_itemfilter) has a role ofauthor.-Gary
Thank you! That works perfectly for the wp_biographia_contact_info function, but with the wp_biographia_link_item function I get the following error:
Warning: Missing argument 2 for add_authorsite_link()
What am I missing? Here’s my code in functions.php:
function add_authorsite_link ($links, $icon_dir_url) { // links = array (field => array (link_title => title, link_text => text, link_icon => URL) $links['authorsite'] = array ( 'link_title' => __('Author Website'), 'link_text' => __('Author Website'), 'link_icon' => $icon_dir_url . 'authorsite.png' ); return $links; }I am using an alternate icon directory, if that makes a difference. The authorsite.png icon is not currently showing up (my other icons are).
I also can’t quite figure out the capabilities check — I believe it’s this call: http://codex.wordpress.org/Function_Reference/current_user_can but I’m not sure exactly how to combine it with the functions.
Thanks for your help!
Can you show the complete code, including the call to
add_filter… ?In your
wp_biographia_link_itemfilter handler,$icon_dir_urlis passed in from the plugin with the value set to where the plugin is looking for its icons. How are you specifying an alternate icon set … from theAlternate Icon Setsetting in the plugin’s Content tab?You’re on the right lines with
current_user_canbut that only checks for a capability not for a role. WordPress doesn’t (yet) have an API function that allows you to say is this user an author (or administrator, or editor and so on). But you can roll you own easily, see this post for details – http://docs.appthemes.com/tutorials/wordpress-check-user-role-function/-Gary
add_filter ('wp_biographia_link_items', 'add_authorsite_link', 2); function add_authorsite_link ($links, $icon_dir_url) { // links = array (field => array (link_title => title, link_text => text, link_icon => URL) $links['authorsite'] = array ( 'link_title' => __('Author Website'), 'link_text' => __('Author Website'), 'link_icon' => $icon_dir_url . 'authorsite.png' ); return $links; }Yes, I’ve specified the alternate icon directory in the settings. I have two other icons (email and Twitter) in there that show up properly.
So using the “is this user an author” check, would I include that as a separate function? Or do I put the “if” part surrounding the rest of the function? (Or both?)
The code looks OK … what version of WP Biographia and WordPress are you using and what’s the precise error message?
Enclose the
add_filtercall in the is an author conditional so that you’ll only get theauthorsitevalue added to the Biography Box if the user is an author.WP 3.5.1, WP Biographia 3.3.0. The error message is:
Warning: Missing argument 2 for add_authorsite_link() in /home/jasontd/public_html/fandomania.com/wp-content/themes/megazine_v1-04/functions.php on line 219
And thanks, I think I got the author check part working now!
Hmm. I’ll take a look at this tomorrow and see what I can find out. In the meantime, if you could post the code you have so far, including the author check, I can see if I can replicate this with your code.
Here’s the whole thing:
if ( current_user_can( 'publish_posts' )) { ( add_filter ('wp_biographia_contact_info', 'add_author_website') ); } function add_author_website ($contacts) { // contacts = array (field => array (field => field-name, contactmethod => description)) $contacts['authorsite'] = array ( 'field' => 'authorsite', 'contactmethod' => __('Author Website') ); return $contacts; } add_filter ('wp_biographia_link_items', 'add_authorsite_link', 2); function add_authorsite_link ($links, $icon_dir_url) { // links = array (field => array (link_title => title, link_text => text, link_icon => URL) $links['authorsite'] = array ( 'link_title' => __('Author Website'), 'link_text' => __('Author Website'), 'link_icon' => $icon_dir_url . 'authorsite.png' ); return $links; }(I went with the capability check instead of user type after all, because it seemed better/easier especially since we have both authors and admins, and it seemed to work fine.)
OK. I’ve found the problem and it’s entirely my fault. I used your code (from the previous post) and got exactly the same PHP messages as you did.
It turns out I’d made a typo in the plugin’s documentation. If you change the call to
add_filterforwp_biographia_link_itemsto this …add_filter ('wp_biographia_link_items', 'add_authorsite_link', 10, 2);… all should be well. I’ve updated the documentation for this on my website and the plugin’s documentation has also been changed and this typo fix will be in the next release.
The only other suggestion I have is to wrap both calls to
add_filterin the capabilities/role check as there’s no point adding thewp_biographia_link_itemsfilter if you haven’t added thewp_biographia_contact_info_filteras well, so it would look like this …if (current_user_can ('publish_posts')) { add_filter ('wp_biographia_contact_info', 'add_author_website'); add_filter ('wp_biographia_link_items', 'add_authorsite_link', 10, 2); }… you could also ensure that your two filter function definitions,
add_author_websiteandadd_authorsite_linkare also wrapped in the capabilities/role check so you don’t define functions you’ll not actually be using if the current user can’t publish posts. It’ll give a slight performance boost, but only a slight one.Apologies for all of this but thanks for helping me spot my mistake as well!
-Gary
Perfect! Thank you so much!
You’re welcome. Glad we got there in the end!
The topic ‘Different website for bio box / comment link?’ is closed to new replies.