开发者

How do I turn a "add a friend" link to a button? It functions differently than e.g. "send message" link

The function "send private message" works as a button

<div><a href="<?php bp_send_private_message_link() ?>" class="myButton"></a></div>

when inserted here in the PHP file:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<he开发者_JS百科ad> 
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <title>IS THIS THING ON?</title>
  <link rel="stylesheet" href="./wp-content/themes/cosmicbuddy/_inc/css/screen.css" type="text/css" />
</style>
</head>
<body>
  <div>
      <a href="<?php bp_send_private_message_link() ?>" class="myButton"></a>
  </div>
  <div>
      <a href="<?php bp_send_public_message_link() ?>" class="myButton"></a>
  </div>
</body>
</html>

but when I insert this between the tags it won't work. It just shows text "Cancel friendship"

<?php if ( function_exists( 'bp_add_friend_button' ) ) : ?>
   <?php bp_add_friend_button() ?>
<?php endif; ?>

I tried to find the source, but there's a lot more to it than I thought obv. Because at first the button is "add friend", if the user is your friend, it'll show "cancel friendship".

Any ideas?

I can look for the code that is behind the add/cancel friendship link if that might help solving it?!


Looks like you will need to provide the friend ID to the function, as the declaration is:

function bp_add_friend_button( $potential_friend_id = 0, $friend_status = false )

otherwise, the ID is retrieved by another function:

function bp_get_potential_friend_id( $user_id = 0 ) {
    global $friends_template;

    if ( empty( $user_id ) && isset( $friends_template->friendship->friend ) )
        $user_id = $friends_template->friendship->friend->id;
    else if ( empty( $user_id ) && !isset( $friends_template->friendship->friend ) )
        $user_id = bp_displayed_user_id();
    return apply_filters( 'bp_get_potential_friend_id', (int) $user_id );
}

You can examine the functions for BuddyPress here: http://phpxref.ftwr.co.uk/buddypress/nav.html?_functions/index.html Hope it helps.


I think you want to display the friends request and reject link in a tag.

Please try below code:

<div><a href="<?php echo bp_get_friend_accept_request_link() ?>" class="myButton">Friends Accept</a></div>

<div><a href="<?php echo bp_get_friend_reject_request_link() ?>" class="myButton">Friends Reject</a></div>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜