Need some help with php

I have a plugin that displaysa widget of who is online and and the links to their profiles however since the wordpress site is now a buddypress site the links that point to members profiles from the widget are now broken because now the link needs to be /members/membersname/ . The current link is linking to /author/membersname/

The plugin developer said in the updates that he added a filter to change the link displayed but unfortunately I do not understand it as my php knowledge is slim to none. Here is the code.

* Return HTML for a single blog user for the widget.
*
* @uses apply_filters() Calls 'wpwhosonline_author_link' on the author link element
* @return string HTML for the user row
*/
function wpwhosonline_user( $last_online_ts, $user ) {
$avatar = get_avatar( $user->user_email, 32 );
$name = $user->display_name;
$link = '<a href="' . get_author_posts_url( $user->ID, $user->user_nicename ) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $user->display_name) ) . '">' . $name . '</a>';

$link = apply_filters( 'wpwhosonline_author_link', $link, $user );

Can anyone please tell me or show me where I have to enter members in this code? I can tell that this outputs a link but everything I have tried has failed miserably :expressionless:

  • aristath
    • Recruit

    Hello there @dubbinz,

    Change this line

    $link = '<a href="' . get_author_posts_url( $user->ID, $user->user_nicename ) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $user->display_name) ) . '">' . $name . '</a>';

    to

    $link = '<a href="/members/' . get_author_posts_url( $user->ID, $user->user_nicename ) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $user->display_name) ) . '">' . $name . '</a>';

    Let me know if that works for you…

    Cheers,

    Ari.

  • dubbinz
    • Design Lord, Child of Thor

    http://domain-name.com/members/http://domain-name.com/author/membersname/

    is what’s returning but we are obviously getting somewhere the area it was put in was correct. I’ll post in as much code as I can. I think this is what you need.

    /**
    * Return HTML for a single blog user for the widget.
    *
    * @uses apply_filters() Calls 'wpwhosonline_author_link' on the author link element
    * @return string HTML for the user row
    */
    function wpwhosonline_user( $last_online_ts, $user ) {
    $avatar = get_avatar( $user->user_email, 32 );
    $name = $user->display_name;
    $link = '<a href="/members/' . get_author_posts_url( $user->ID, $user->user_nicename ) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $user->display_name) ) . '">' . $name . '</a>';

    $link = apply_filters( 'wpwhosonline_author_link', $link, $user );

    // this should always exist; we queried using this meta
    if ( ! $last_online_ts ) {
    continue;
    }

    $now = time();
    if ( $now - $last_online_ts < 120 ) {
    $last_online = 'Online now!';
    } else {
    $last_online = human_time_diff( $now, $last_online_ts ) . ' ago';
    }

    $last_online_title = date_i18n( get_option('date_format') . ' ' . get_option('time_format'), $last_online_ts );

    if ( $last_online ) {
    $last_online = '<span title="Last online: ' . esc_attr( $last_online_title ) . '">' . $last_online . '</a>';
    }

    return $avatar . $link . '<br>' . $last_online;
    }

    function wpwhosonline_class( $lastonline ) {
    $diff = time() - $lastonline;
    if( $diff > 7200 ) {
    return 'wpwhosonline-ancient';
    } elseif( $diff > 600 ) {
    return 'wpwhosonline-recent';
    } else {
    return 'wpwhosonline-active';
    }
    }

    function widget_wpwhosonline_init() {

  • dubbinz
    • Design Lord, Child of Thor

    the links now display as http://domain-name.com/members/

    a list of text has appeared right at the top of the list like this membernamemembernamemembername

    It’s almost there.

    If you want to play around with the plugin you can get it here

    http://wordpress.org/extend/plugins/wp-whos-online/

    There is also a topic that is in the support area that I think will help us here

    http://wordpress.org/support/topic/plugin-whos-online-directory-location-for-user-profiles?replies=4

    I really appreciate the help thus far, thankyou.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.