bbp_parse_query (WP_Queryposts_query美元

将对论坛条件的检查添加到parse_query操作中

描述

如果是用户页面,WP_Query::bbp_is_single_user设置为true。如果是用户编辑页面,WP_Query::bbp_is_single_user_edit设置为true,并包含' wp-admin/includes/user.php '文件。此外,在用户/用户编辑页面上,WP_Query::home被设置为false并添加了带有显示的用户id的查询变量' bbp_user_id '和带有显示的用户nicename的' author_name '。

如果是论坛编辑,WP_Query::bbp_is_forum_edit设置为true如果是主题编辑,WP_Query::bbp_is_topic_edit设置为true如果是回复编辑,WP_Query::bbp_is_reply_edit设置为true。

如果是一个搜索页面,WP_Query::bbp_is_search设置为true

参数

posts_query美元

WP_Query(必需)

文件:bp-forums /核心/ template-functions.php

函数bbp_parse_query($ posts_query){// bail如果$ posts_query不是主循环(!$ posts_query-> is_main_query())返回;//保释如果在此查询上抑制过滤器(true === $ posts_query-> get('suppress_filters'))返回;//如果在admin(is_admin())返回;//获取查询变量$ bbp_view = $ posts_query-> get(bbp_get_view_rewrite_id());$ bbp_user = $ posts_query-> get(bbp_get_user_rewrite_id());$ is_edit = $ posts_query-> get(bbp_get_edit_rewrite_id());//它是一个用户页面 - 如果(!空($ bbp_user)){/ **找到用户*********************************************************** ///设置默认用户变量$ the_user=假;//如果使用相当永久链接,始终使用sluk if(get_option('permalink_structure')){$ the_user = get_user_by('slug',$ bbp_user);//如果不使用相当永久链接,始终使用数字ID} elsef(is_numeric($ bbp_user)){$ the_user = get_user_by('id',$ bbp_user); } // 404 and bail if user does not have a profile if ( empty( $the_user->ID ) || ! bbp_user_has_profile( $the_user->ID ) ) { $posts_query->set_404(); return; } /** User Exists *******************************************************/ $is_favs = $posts_query->get( bbp_get_user_favorites_rewrite_id() ); $is_subs = $posts_query->get( bbp_get_user_subscriptions_rewrite_id() ); $is_topics = $posts_query->get( bbp_get_user_topics_rewrite_id() ); $is_replies = $posts_query->get( bbp_get_user_replies_rewrite_id() ); // View or edit? if ( !empty( $is_edit ) ) { // We are editing a profile $posts_query->bbp_is_single_user_edit = true; // Load the core WordPress contact methods if ( !function_exists( '_wp_get_user_contactmethods' ) ) { include_once( ABSPATH . 'wp-includes/registration.php' ); } // Load the edit_user functions if ( !function_exists( 'edit_user' ) ) { require_once( ABSPATH . 'wp-admin/includes/user.php' ); } // Load the grant/revoke super admin functions if ( is_multisite() && !function_exists( 'revoke_super_admin' ) ) { require_once( ABSPATH . 'wp-admin/includes/ms.php' ); } // Editing a user $posts_query->bbp_is_edit = true; // User favorites } elseif ( ! empty( $is_favs ) ) { $posts_query->bbp_is_single_user_favs = true; // User subscriptions } elseif ( ! empty( $is_subs ) ) { $posts_query->bbp_is_single_user_subs = true; // User topics } elseif ( ! empty( $is_topics ) ) { $posts_query->bbp_is_single_user_topics = true; // User topics } elseif ( ! empty( $is_replies ) ) { $posts_query->bbp_is_single_user_replies = true; // User profile } else { $posts_query->bbp_is_single_user_profile = true; } // Looking at a single user $posts_query->bbp_is_single_user = true; // Make sure 404 is not set $posts_query->is_404 = false; // Correct is_home variable $posts_query->is_home = false; // User is looking at their own profile if ( get_current_user_id() === $the_user->ID ) { $posts_query->bbp_is_single_user_home = true; } // Set bbp_user_id for future reference $posts_query->set( 'bbp_user_id', $the_user->ID ); // Set author_name as current user's nicename to get correct posts $posts_query->set( 'author_name', $the_user->user_nicename ); // Set the displayed user global to this user bbpress()->displayed_user = $the_user; // View Page } elseif ( !empty( $bbp_view ) ) { // Check if the view exists by checking if there are query args are set $view_args = bbp_get_view_query_args( $bbp_view ); // Bail if view args is false (view isn't registered) if ( false === $view_args ) { $posts_query->set_404(); return; } // Correct is_home variable $posts_query->is_home = false; // We are in a custom topic view $posts_query->bbp_is_view = true; // Search Page } elseif ( isset( $posts_query->query_vars[ bbp_get_search_rewrite_id() ] ) ) { // Check if there are search query args set $search_terms = bbp_get_search_terms(); if ( !empty( $search_terms ) ) $posts_query->bbp_search_terms = $search_terms; // Correct is_home variable $posts_query->is_home = false; // We are in a search query $posts_query->bbp_is_search = true; // Forum/Topic/Reply Edit Page } elseif ( !empty( $is_edit ) ) { // Get the post type from the main query loop $post_type = $posts_query->get( 'post_type' ); // Check which post_type we are editing, if any if ( !empty( $post_type ) ) { switch( $post_type ) { // We are editing a forum case bbp_get_forum_post_type() : $posts_query->bbp_is_forum_edit = true; $posts_query->bbp_is_edit = true; break; // We are editing a topic case bbp_get_topic_post_type() : $posts_query->bbp_is_topic_edit = true; $posts_query->bbp_is_edit = true; break; // We are editing a reply case bbp_get_reply_post_type() : $posts_query->bbp_is_reply_edit = true; $posts_query->bbp_is_edit = true; break; } // We are editing a topic tag } elseif ( bbp_is_topic_tag() ) { $posts_query->bbp_is_topic_tag_edit = true; $posts_query->bbp_is_edit = true; } // We save post revisions on our own remove_action( 'pre_post_update', 'wp_save_post_revision' ); // Topic tag page } elseif ( bbp_is_topic_tag() ) { $posts_query->set( 'bbp_topic_tag', get_query_var( 'term' ) ); $posts_query->set( 'post_type', bbp_get_topic_post_type() ); $posts_query->set( 'posts_per_page', bbp_get_topics_per_page() ); // Do topics on forums root } elseif ( is_post_type_archive( array( bbp_get_forum_post_type(), bbp_get_topic_post_type() ) ) && ( 'topics' === bbp_show_on_root() ) ) { $posts_query->bbp_show_topics_on_root = true; } }

更新日志

更新日志
版本 描述
bbPress (r2688) 介绍了。

问题吗?

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