我该如何转“加好友”?链接到一个按钮?它的功能与“发送消息”等不同.链接


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

发送私信功能作为按钮使用

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

插入到PHP文件中:

<!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">
<head> 
  <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>

但是当我在标签之间插入这个时,它将不起作用。它只显示文字"取消友谊"

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

我试着找到来源,但有很多比我想象的明显。因为一开始按钮是"添加朋友",如果用户是你的朋友,它会显示"取消友谊"。

任何想法?

我可以寻找背后的代码添加/取消友谊链接,如果这可能有助于解决它?!

看起来您需要为函数提供好友ID,因为声明如下:

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

否则,则由另一个函数检索ID:

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 );
}

您可以在这里检查BuddyPress的功能:http://phpxref.ftwr.co.uk/buddypress/nav.html?_functions/index.html希望它有所帮助。

我认为你想在标签中显示好友请求和拒绝链接。

请尝试下面的代码:

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