bp_get_canonical_url (数组args美元数组()

获取当前页面的规范URL。

描述

参数

args美元

数组(可选)可选参数数组。

  • “include_query_args”
    (保龄球)是否在函数返回的规范URL中包含当前URL参数。

默认值:数组()

返回

(字符串)当前页面的规范URL。

文件:bp-core / bp-core-catchuri.php

function bp_get_canonical_url($args = array()){//对于非bp内容,返回请求的url,让WP完成工作。If (bp_is_blog_page()){返回bp_get_requestd_url ();} $bp = buddypress();$defaults = array('include_query_args' => false //包含URL参数,例如?foo=bar&foo2=bar2.);$r = wp_parse_args($args, $defaults);提取($ r);//特殊情况:当BuddyPress目录(如example.com/members) //设置为首页时,确保当前规范URL //为主页URL。$ page_component = array_search($page_on_front, bp_core_get_directory_page_ids()); / /分页/* *如果请求首页组件目录,规范* URL是首页。我们通过检查bp_current_action() *是否为空来检测我们是否在检测* component *directory* -也就是说,这不是一个单独的条目,一个提要,或者一个item *类型的目录。 */ if ( false !== $front_page_component && bp_is_current_component( $front_page_component ) && ! bp_current_action() && ! bp_get_current_member_type() ) { $bp->canonical_stack['canonical_url'] = trailingslashit( bp_get_root_domain() ); // Except when the front page is set to the registration page // and the current user is logged in. In this case we send to // the members directory to avoid redirect loops. } elseif ( bp_is_register_page() && 'register' == $front_page_component && is_user_logged_in() ) { /** * Filters the logged in register page redirect URL. * * @since BuddyPress 1.5.1 * * @param string $value URL to redirect logged in members to. */ $bp->canonical_stack['canonical_url'] = apply_filters( 'bp_loggedin_register_page_redirect_to', bp_get_members_directory_permalink() ); } } if ( empty( $bp->canonical_stack['canonical_url'] ) ) { // Build the URL in the address bar. $requested_url = bp_get_requested_url(); // Stash query args. $url_stack = explode( '?', $requested_url ); // Build the canonical URL out of the redirect stack. if ( isset( $bp->canonical_stack['base_url'] ) ) $url_stack[0] = $bp->canonical_stack['base_url']; if ( isset( $bp->canonical_stack['component'] ) ) $url_stack[0] = trailingslashit( $url_stack[0] . $bp->canonical_stack['component'] ); if ( isset( $bp->canonical_stack['action'] ) ) $url_stack[0] = trailingslashit( $url_stack[0] . $bp->canonical_stack['action'] ); if ( !empty( $bp->canonical_stack['action_variables'] ) ) { foreach( (array) $bp->canonical_stack['action_variables'] as $av ) { $url_stack[0] = trailingslashit( $url_stack[0] . $av ); } } // Add trailing slash. $url_stack[0] = trailingslashit( $url_stack[0] ); // Stash in the $bp global. $bp->canonical_stack['canonical_url'] = implode( '?', $url_stack ); } $canonical_url = $bp->canonical_stack['canonical_url']; if ( !$include_query_args ) { $canonical_url = array_reverse( explode( '?', $canonical_url ) ); $canonical_url = array_pop( $canonical_url ); } /** * Filters the canonical url of the current page. * * @since BuddyPress 1.6.0 * * @param string $canonical_url Canonical URL of the current page. * @param array $args Array of arguments to help determine canonical URL. */ return apply_filters( 'bp_get_canonical_url', $canonical_url, $args ); }

更新日志

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

问题吗?

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