• Resolved SheerHeartAttack

    (@sheerheartattack)


    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!

    https://www.ads-software.com/extend/plugins/wp-biographia/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author vicchi

    (@vicchi)

    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 website field 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_info and wp_biographia_link_item filters, 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’s functions.php or 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 author role by using the WordPress roles and capabilities API calls to check that the current logged in user is an author (in the wp_biographia_contact_info filter) so that the new field only appears in authors profiles and check that the author of the current post (in the wp_biographia_link_item filter) has a role of author.

    -Gary

    Thread Starter SheerHeartAttack

    (@sheerheartattack)

    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: https://codex.www.ads-software.com/Function_Reference/current_user_can but I’m not sure exactly how to combine it with the functions.

    Thanks for your help!

    Plugin Author vicchi

    (@vicchi)

    Can you show the complete code, including the call to add_filter … ?

    In your wp_biographia_link_item filter handler, $icon_dir_url is 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 the Alternate Icon Set setting in the plugin’s Content tab?

    You’re on the right lines with current_user_can but 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 – https://docs.appthemes.com/tutorials/wordpress-check-user-role-function/

    -Gary

    Thread Starter SheerHeartAttack

    (@sheerheartattack)

    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?)

    Plugin Author vicchi

    (@vicchi)

    The code looks OK … what version of WP Biographia and WordPress are you using and what’s the precise error message?

    Enclose the add_filter call in the is an author conditional so that you’ll only get the authorsite value added to the Biography Box if the user is an author.

    Thread Starter SheerHeartAttack

    (@sheerheartattack)

    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!

    Plugin Author vicchi

    (@vicchi)

    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.

    Thread Starter SheerHeartAttack

    (@sheerheartattack)

    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.)

    Plugin Author vicchi

    (@vicchi)

    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_filter for wp_biographia_link_items to 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_filter in the capabilities/role check as there’s no point adding the wp_biographia_link_items filter if you haven’t added the wp_biographia_contact_info_filter as 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_website and add_authorsite_link are 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

    Thread Starter SheerHeartAttack

    (@sheerheartattack)

    Perfect! Thank you so much!

    Plugin Author vicchi

    (@vicchi)

    You’re welcome. Glad we got there in the end!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Different website for bio box / comment link?’ is closed to new replies.