BP_Button

创建BuddyPress按钮的API。

描述

参数

args美元

数组(必需)数组的参数。

  • “id”
    (字符串)描述按钮类型的字符串。
  • “组件”
    (字符串)按钮所属组件的名称。默认值:“核心”。
  • “must_be_logged_in”
    (保龄球)可选的。用户是否需要登录才能看到这个按钮?默认值:真的。
  • “block_self”
    (保龄球)可选的。如果在用户查看自己的个人资料时该按钮应该被隐藏,则为。默认值:真的。
  • “parent_element”
    (字符串)可选的。环绕按钮的父元素。默认值:div。
  • “parent_attr”
    (数组)可选的。父元素的元素属性。将'id', 'class'等属性设置为数组键。
  • “button_element”
    (字符串)可选的。按钮元素。默认值:“一个”。
  • “button_attr”
    (数组)可选的。按钮的属性。将'id', 'class'等属性设置为数组键。
  • “link_text”
    (字符串)可选的。显示在按钮上的文本。默认值:”。
  • “包装器”
    (字符串| bool)弃用。使用$ parent_element代替。
  • “wrapper_id”
    (字符串)弃用。使用$parent_attr并设置'id'为数组键。
  • “wrapper_class”
    (字符串)弃用。使用$parent_attr并设置'class'为数组键。
  • “link_href”
    (字符串)弃用。使用$button_attr并设置'href'作为数组键。
  • “link_class”
    (字符串)弃用。使用$button_attr并设置'class'为数组键。
  • “link_id”
    (字符串)弃用。使用$button_attr并设置'id'为数组键。
  • “link_rel”
    (字符串)弃用。使用$button_attr并设置'rel'作为数组键。
  • “link_title”
    (字符串)弃用。使用$button_attr并设置'title'为数组键。

文件:bp-core /类/ class-bp-button.php

BP_BUTTON等级{/ **按钮属性******************************************************* / / ** *按钮ID。* * @since buddypress 1.2.6 * * * @var字符串* / public $ id ='';/ ** *按钮所属的组件的名称。* * @since buddypress 1.2.6 * * * @var字符串* / public $ component ='core';/ ** *用户是否需要登录以查看此按钮?* * @since buddypress 1.2.6 * * * @var bool * / public $ must_be_logging_in = true;/ ** *查看自己的个人资料时应隐藏按钮。* * @since buddypress 1.2.6 * * * @var bool * / public $ block_self = true;/ **包装包装***************************************************************** / / ** *父元素以缠绕按钮。 * * @since BuddyPress 2.7.0 * * @var string Default: 'div'. */ public $parent_element = ''; /** * Element attributes for parent element. * * @since BuddyPress 2.7.0 * * @var array Set whatever attributes like 'id', 'class' as array key. */ public $parent_attr = array(); /** Button ****************************************************************/ /** * Button element. * * @since BuddyPress 2.7.0 * * @var string Default: 'a'. */ public $button_element = 'a'; /** * Button attributes. * * @since BuddyPress 2.7.0 * * @var array Set whatever attributes like 'id', 'href' as array key. */ public $button_attr = array(); /** * The contents of the button link. * * @since BuddyPress 1.2.6 * * @var string */ public $link_text = ''; /** * HTML result. * * @since BuddyPress 1.2.6 * * @var string */ public $contents = ''; /** Deprecated ***********************************************************/ /** * The type of DOM element to use for a wrapper. * * @since BuddyPress 1.2.6 * @deprecated 2.7.0 Use $parent_element instead. * * @var string|bool */ public $wrapper = 'div'; /** * The DOM class of the button wrapper. * * @since BuddyPress 1.2.6 * @deprecated 2.7.0 Set 'class' key in $parent_attr instead. * * @var string */ public $wrapper_class = ''; /** * The DOM ID of the button wrapper. * * @since BuddyPress 1.2.6 * @deprecated 2.7.0 Set 'id' key in $parent_attr instead. * * @var string */ public $wrapper_id = ''; /** * The destination link of the button. * * @since BuddyPress 1.2.6 * @deprecated 2.7.0 Set 'href' key in $button_attr instead. * * @var string */ public $link_href = ''; /** * The DOM class of the button link. * * @since BuddyPress 1.2.6 * @deprecated 2.7.0 Set 'class' key in $button_attr instead. * * @var string */ public $link_class = ''; /** * The DOM ID of the button link. * * @since BuddyPress 1.2.6 * @deprecated 2.7.0 Set 'id' key in $button_attr instead. * * @var string */ public $link_id = ''; /** * The DOM rel value of the button link. * * @since BuddyPress 1.2.6 * @deprecated 2.7.0 Set 'rel' key in $button_attr instead. * * @var string */ public $link_rel = ''; /** * Title of the button link. * * @since BuddyPress 1.2.6 * @deprecated 2.7.0 Set 'title' key in $button_attr instead. * * @var string */ public $link_title = ''; /** Methods ***************************************************************/ /** * Builds the button based on class parameters. * * @since BuddyPress 1.2.6 * * @param array|string $args See {@BP_Button}. */ public function __construct( $args = '' ) { $r = wp_parse_args( $args, get_class_vars( __CLASS__ ) ); // Backward compatibility with deprecated parameters. $r = $this->backward_compatibility_args( $r ); // Deprecated. Subject to removal in a future release. $this->wrapper = $r['wrapper']; if ( !empty( $r['link_id'] ) ) $this->link_id = ' id="' . $r['link_id'] . '"'; if ( !empty( $r['link_href'] ) ) $this->link_href = ' href="' . $r['link_href'] . '"'; if ( !empty( $r['link_title'] ) ) $this->link_title = ' title="' . $r['link_title'] . '"'; if ( !empty( $r['link_rel'] ) ) $this->link_rel = ' rel="' . $r['link_rel'] . '"'; if ( !empty( $r['link_class'] ) ) $this->link_class = ' class="' . $r['link_class'] . '"'; if ( !empty( $r['link_text'] ) ) $this->link_text = $r['link_text']; // Required button properties. $this->id = $r['id']; $this->component = $r['component']; $this->must_be_logged_in = (bool) $r['must_be_logged_in']; $this->block_self = (bool) $r['block_self']; // $id and $component are required and component must be active. if ( empty( $r['id'] ) || empty( $r['component'] ) || ! bp_is_active( $this->component ) ) { return false; } // No button for guests if must be logged in. if ( true == $this->must_be_logged_in && ! is_user_logged_in() ) { return false; } // The block_self property. if ( true == $this->block_self ) { /* * No button if you are the current user in a members loop. * * This condition takes precedence, because members loops can be found on user * profiles. */ if ( bp_get_member_user_id() ) { if ( is_user_logged_in() && bp_loggedin_user_id() == bp_get_member_user_id() ) { return false; } // No button if viewing your own profile (and not in a members loop). } elseif ( bp_is_my_profile() ) { return false; } } // Should we use a parent element? if ( ! empty( $r['parent_element'] ) ) { if ( ! isset( $r['parent_attr']['class'] ) ) { $r['parent_attr']['class'] = ''; } // Always add 'generic-button' class. if ( false === strpos( $r['parent_attr']['class'], 'generic-button' ) ) { if ( ! is_array( $r['parent_attr'] ) ) { $r['parent_attr'] = array(); } if ( ! empty( $r['parent_attr']['class'] ) ) { $r['parent_attr']['class'] .= ' '; } $r['parent_attr']['class'] .= 'generic-button'; } // Set parent element props. $this->parent_element = $r['parent_element']; $this->parent_attr = $r['parent_attr']; // Render parent element attributes. $parent_elem = new BP_Core_HTML_Element( array( 'element' => $r['parent_element'], 'attr' => $r['parent_attr'] ) ); // Set before and after. $before = $parent_elem->get( 'open_tag' ); $after = $parent_elem->get( 'close_tag' ); // No parent element. } else { $before = $after = ''; } // Button properties. $button = ''; if ( ! empty( $r['button_element'] ) ) { $button = new BP_Core_HTML_Element( array( 'element' => $r['button_element'], 'attr' => $r['button_attr'], 'inner_html' => ! empty( $r['link_text'] ) ? $r['link_text'] : '' ) ); $button = $button->contents(); } // Build the button. $this->contents = $before . $button . $after; /** * Filters the button based on class parameters. * * This filter is a dynamic filter based on component and component ID and * allows button to be manipulated externally. * * @since BuddyPress 1.2.6 * @since BuddyPress 2.7.0 Added $r as a parameter. * * @param string $contents HTML being used for the button. * @param BP_Button $this Current BP_Button instance. * @param string $before HTML appended before the actual button. * @param string $after HTML appended after the actual button. * @param array $r Parsed button arguments. */ $this->contents = apply_filters( 'bp_button_' . $this->component . '_' . $this->id, $this->contents, $this, $before, $after, $r ); } /** * Provide backward compatibility for deprecated button arguments. * * @since BuddyPress 2.7.0. * * @param array $r See {@link BP_Button} class for full documentation. * @return array */ protected function backward_compatibility_args( $r = array() ) { // Array of deprecated arguments. $backpat_args = array( 'wrapper', 'wrapper_class', 'wrapper_id', 'link_href', 'link_class', 'link_id', 'link_rel', 'link_title' ); foreach ( $backpat_args as $prop ) { if ( empty( $r[ $prop ] ) ) { continue; } $parent = $child = false; $sep = strpos( $prop, '_' ); // Check if this is an attribute. if ( false !== $sep ) { $child = true; $parent = substr( $prop, 0, $sep ); } else { $parent = $prop; } if ( 'wrapper' === $parent ) { $parent = 'parent'; } else { $parent = 'button'; } // Set element. if ( false === $child && empty( $r[ "{$parent}_element" ] ) ) { $r[ "{$parent}_element" ] = $r[ $prop ]; // Set attributes. } elseif ( true === $child ) { $new_prop = substr( $prop, strpos( $prop, '_' ) +1 ); if ( empty( $r[ "{$parent}_attr" ] ) ) { $r[ "{$parent}_attr" ] = array(); } if ( empty( $r[ "{$parent}_attr" ][ $new_prop ] ) ) { $r[ "{$parent}_attr" ][ $new_prop ] = $r[ $prop ]; } } } return $r; } /** * Return the markup for the generated button. * * @since BuddyPress 1.2.6 * * @return string Button markup. */ public function contents() { return $this->contents; } /** * Output the markup of button. * * @since BuddyPress 1.2.6 */ public function display() { if ( !empty( $this->contents ) ) echo $this->contents; } }

更新日志

更新日志
版本 描述
BuddyPress 1.2.6 介绍了。

方法

问题吗?

我们总是很乐意帮助您解决代码或其他问题!搜索我们的开发人员文档联络支持,或与我们联系销售团队