BBP_Forums_Group_Extension
加载组扩展的论坛组件
描述
源
bbp_forums_group_extension sext扩展bp_group_extension {/ **方法*************************************************************** / ** *设置论坛组扩展变量* * @since bbpress(r3552)* / public function __construct(){$ this- > setup_variables();$ this-> setup_actions();$ this-> setup_filters();$ this-> mays_unset_forum_menu();} / ** *设置组论坛类变量* * @since bbpress()* / private函数setup_variables(){//组件名称$ this-> name = __('讨论','buddyboss');$ this-> nav_item_name = __('讨论','buddyboss');//组件slugs(硬编码为匹配论坛1.x功能)$ this-> slug = get_option('_bbp_forum_slug','forum');$以下 - >主题_slug = get_option('_bbp_topic_slug','讨论');$ this-> reply_slug = get_option('_bbp_reply_slug','回复'); // Forum component is visible $this->visibility = 'public'; // Set positions towards end $this->create_step_position = 15; $this->nav_item_position = 10; // Allow create step and show in nav $this->enable_create_step = true; $this->enable_nav_item = true; $this->enable_edit_item = true; // Template file to load, and action to hook display on to $this->template_file = 'groups/single/plugins'; $this->display_hook = 'bp_template_content'; } /** * Setup the group forums class actions * * @since bbPress (r4552) */ private function setup_actions() { // Possibly redirect add_action( 'bbp_template_redirect', array( $this, 'redirect_canonical' ) ); // Remove group forum cap map when view is done add_action( 'bbp_after_group_forum_display', array( $this, 'remove_group_forum_meta_cap_map' ) ); // Forums needs to listen to BuddyBoss group deletion. add_action( 'groups_before_delete_group', array( $this, 'disconnect_forum_from_group' ) ); // Adds a Forums metabox to the new BuddyBoss Group Admin UI add_action( 'bp_groups_admin_meta_boxes', array( $this, 'group_admin_ui_edit_screen' ) ); // Saves the Forums options if they come from the BuddyBoss Group Admin UI add_action( 'bp_group_admin_edit_after', array( $this, 'edit_screen_save' ) ); // Adds a hidden input value to the "Group Settings" page add_action( 'bp_before_group_settings_admin', array( $this, 'group_settings_hidden_field' ) ); } /** * Setup the group forums class filters * * @since bbPress (r4552) */ private function setup_filters() { // Group forum pagination add_filter( 'bbp_topic_pagination', array( $this, 'topic_pagination' ) ); add_filter( 'bbp_replies_pagination', array( $this, 'replies_pagination' ) ); // Tweak the redirect field add_filter( 'bbp_new_topic_redirect_to', array( $this, 'new_topic_redirect_to' ), 10, 3 ); add_filter( 'bbp_new_reply_redirect_to', array( $this, 'new_reply_redirect_to' ), 10, 3 ); // Map forum/topic/replys permalinks to their groups add_filter( 'bbp_get_forum_permalink', array( $this, 'map_forum_permalink_to_group' ), 10, 2 ); add_filter( 'bbp_get_topic_permalink', array( $this, 'map_topic_permalink_to_group' ), 10, 2 ); add_filter( 'bbp_get_reply_permalink', array( $this, 'map_reply_permalink_to_group' ), 10, 2 ); // Map reply edit links to their groups add_filter( 'bbp_get_reply_edit_url', array( $this, 'map_reply_edit_url_to_group' ), 10, 2 ); // Map assorted template function permalinks add_filter( 'post_link', array( $this, 'post_link' ), 10, 2 ); add_filter( 'page_link', array( $this, 'page_link' ), 10, 2 ); add_filter( 'post_type_link', array( $this, 'post_type_link' ), 10, 2 ); // Map group forum activity items to groups add_filter( 'bbp_before_record_activity_parse_args', array( $this, 'map_activity_to_group' ) ); /** Caps **************************************************************/ // Only add these filters if inside a group forum if ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'forum' ) ) { // Allow group member to view private/hidden forums add_filter( 'bbp_map_meta_caps', array( $this, 'map_group_forum_meta_caps' ), 10, 4 ); // Group member permissions to view the topic and reply forms add_filter( 'bbp_current_user_can_access_create_topic_form', array( $this, 'form_permissions' ) ); add_filter( 'bbp_current_user_can_access_create_reply_form', array( $this, 'form_permissions' ) ); } } /** * The primary display function for group forums * * @since bbPress (r3746) * * @param int $group_id ID of the current group. Available only on BP 2.2+. */ public function display( $group_id = null ) { // Prevent Topic Parent from appearing add_action( 'bbp_theme_before_topic_form_forum', array( $this, 'ob_start' ) ); add_action( 'bbp_theme_after_topic_form_forum', array( $this, 'ob_end_clean' ) ); add_action( 'bbp_theme_after_topic_form_forum', array( $this, 'topic_parent' ) ); // Prevent Forum Parent from appearing add_action( 'bbp_theme_before_forum_form_parent', array( $this, 'ob_start' ) ); add_action( 'bbp_theme_after_forum_form_parent', array( $this, 'ob_end_clean' ) ); add_action( 'bbp_theme_after_forum_form_parent', array( $this, 'forum_parent' ) ); // Hide breadcrumb add_filter( 'bbp_no_breadcrumb', '__return_true' ); $this->display_forums( 0 ); } /** * Maybe unset the group forum nav item if group does not have a forum * * @since bbPress (r4552) * * @return If not viewing a single group */ public function maybe_unset_forum_menu() { // Bail if not viewing a single group if ( ! bp_is_group() ) return; // Are forums enabled for this group? $checked = bp_get_new_group_enable_forum() || groups_get_groupmeta( bp_get_new_group_id(), 'forum_id' ); // Tweak the nav item variable based on if group has forum or not $this->enable_nav_item = (bool) $checked; } /** * Allow group members to have advanced priviledges in group forum topics. * * @since bbPress (r4434) * * @param array $caps * @param string $cap * @param int $user_id * @param array $args * @return array */ public function map_group_forum_meta_caps( $caps = array(), $cap = '', $user_id = 0, $args = array() ) { switch ( $cap ) { // If user is a group mmember, allow them to create content. case 'read_forum' : case 'publish_replies' : case 'publish_topics' : case 'read_hidden_forums' : case 'read_private_forums' : if ( bbp_group_is_member() || bbp_group_is_mod() || bbp_group_is_admin() ) { $caps = array( 'participate' ); } break; // If user is a group mod ar admin, map to participate cap. case 'moderate' : case 'edit_topic' : case 'edit_reply' : case 'view_trash' : case 'edit_others_replies' : case 'edit_others_topics' : if ( bbp_group_is_mod() || bbp_group_is_admin() ) { $caps = array( 'participate' ); } break; // If user is a group admin, allow them to delete topics and replies. case 'delete_topic' : case 'delete_reply' : if ( bbp_group_is_admin() ) { $caps = array( 'participate' ); } break; } return apply_filters( 'bbp_map_group_forum_topic_meta_caps', $caps, $cap, $user_id, $args ); } /** * Remove the topic meta cap map, so it doesn't interfere with sidebars. * * @since bbPress (r4434) */ public function remove_group_forum_meta_cap_map() { remove_filter( 'bbp_map_meta_caps', array( $this, 'map_group_forum_meta_caps' ), 99, 4 ); } /** Edit ******************************************************************/ /** * Show forums and new forum form when editing a group * * @since bbPress (r3563) * @param object $group (the group to edit if in Group Admin UI) * @uses is_admin() To check if we're in the Group Admin UI * @uses bbp_get_template_part() */ public function edit_screen( $group = false ) { $forum_id = 0; $group_id = empty( $group->id ) ? bp_get_new_group_id() : $group->id ; $forum_ids = bbp_get_group_forum_ids( $group_id ); // Get the first forum ID if ( !empty( $forum_ids ) ) { $forum_id = (int) is_array( $forum_ids ) ? $forum_ids[0] : $forum_ids; } // Should box be checked already? $checked = is_admin() ? bp_group_is_forum_enabled( $group ) : bp_get_new_group_enable_forum() || bp_group_is_forum_enabled( bp_get_group_id() ); ?>slug, 'forum_group_admin_ui' ); } else { wp_nonce_field( 'groups_edit_save_' . $this->slug ); } } /** * Save the Group Forum data on edit * * @since bbPress (r3465) * @param int $group_id (to handle Group Admin UI hook bp_group_admin_edit_after ) * @uses bbp_new_forum_handler() To check for forum creation * @uses bbp_edit_forum_handler() To check for forum edit */ public function edit_screen_save( $group_id = 0 ) { // Bail if not a POST action if ( ! bbp_is_post_request() ) return; // Admin Nonce check if ( is_admin() ) { check_admin_referer( 'groups_edit_save_' . $this->slug, 'forum_group_admin_ui' ); // Theme-side Nonce check } elseif ( ! bbp_verify_nonce_request( 'groups_edit_save_' . $this->slug ) ) { bbp_add_error( 'bbp_edit_group_forum_screen_save', __( 'ERROR: Are you sure you wanted to do that?', 'buddyboss' ) ); return; } $edit_forum = !empty( $_POST['bbp-edit-group-forum'] ) ? true : false; $forum_id = 0; $group_id = !empty( $group_id ) ? $group_id : bp_get_current_group_id(); // Keymasters have the ability to reconfigure forums if ( bbp_is_user_keymaster() ) { $forum_ids = ! empty( $_POST['bbp_group_forum_id'] ) ? (array) (int) $_POST['bbp_group_forum_id'] : array(); // Use the existing forum IDs } else { $forum_ids = array_values( bbp_get_group_forum_ids( $group_id ) ); } // Normalize group forum relationships now if ( !empty( $forum_ids ) ) { // Loop through forums, and make sure they exist foreach ( $forum_ids as $forum_id ) { // Look for forum $forum = bbp_get_forum( $forum_id ); // No forum exists, so break the relationship if ( empty( $forum ) ) { $this->remove_forum( array( 'forum_id' => $forum_id ) ); unset( $forum_ids[$forum_id] ); } } // No support for multiple forums yet $forum_id = (int) ( is_array( $forum_ids ) ? $forum_ids[0] : $forum_ids ); } // Update the group ID and forum ID relationships bbp_update_group_forum_ids( $group_id, (array) $forum_ids ); bbp_update_forum_group_ids( $forum_id, (array) $group_id ); // Update the group forum setting $group = $this->toggle_group_forum( $group_id, $edit_forum ); // Create a new forum if ( empty( $forum_id ) && ( true === $edit_forum ) ) { // Set the default forum status switch ( $group->status ) { case 'hidden' : $status = bbp_get_hidden_status_id(); break; case 'private' : $status = bbp_get_private_status_id(); break; case 'public' : default : $status = bbp_get_public_status_id(); break; } // Create the initial forum $forum_id = bbp_insert_forum( array( 'post_parent' => bbp_get_group_forums_root_id(), 'post_title' => $group->name, 'post_content' => $group->description, 'post_status' => $status ) ); // Setup forum args with forum ID $new_forum_args = array( 'forum_id' => $forum_id ); // If in admin, also include the group ID if ( is_admin() && !empty( $group_id ) ) { $new_forum_args['group_id'] = $group_id; } // Run the BP-specific functions for new groups $this->new_forum( $new_forum_args ); } // Redirect after save when not in admin if ( !is_admin() ) { bp_core_redirect( trailingslashit( bp_get_group_permalink( buddypress()->groups->current_group ) . '/admin/' . $this->slug ) ); } } /** * Adds a metabox to BuddyBoss Group Admin UI * * @since bbPress (r4814) * * @uses add_meta_box * @uses BBP_Forums_Group_Extension::group_admin_ui_display_metabox() To display the edit screen */ public function group_admin_ui_edit_screen() { add_meta_box( 'bbpress_group_admin_ui_meta_box', __( 'Discussion Forum', 'buddyboss' ), array( $this, 'group_admin_ui_display_metabox' ), get_current_screen()->id, 'side', 'core' ); } /** * Displays the Forums metabox in BuddyBoss Group Admin UI * * @since bbPress (r4814) * * @param object $item (group object) * @uses add_meta_box * @uses BBP_Forums_Group_Extension::edit_screen() To get the html */ public function group_admin_ui_display_metabox( $item ) { $this->edit_screen( $item ); } /** Create ****************************************************************/ /** * Show forums and new forum form when creating a group * * @since bbPress (r3465) */ public function create_screen( $group_id = 0 ) { // Bail if not looking at this screen if ( !bp_is_group_creation_step( $this->slug ) ) return false; // Check for possibly empty group_id if ( empty( $group_id ) ) { $group_id = bp_get_new_group_id(); } $checked = bp_get_new_group_enable_forum() || groups_get_groupmeta( $group_id, 'forum_id' ); ?>
slug ) ) { bbp_add_error( 'bbp_create_group_forum_screen_save', __( 'ERROR: Are you sure you wanted to do that?', 'buddyboss' ) ); return; } // Check for possibly empty group_id if ( empty( $group_id ) ) { $group_id = bp_get_new_group_id(); } $create_forum = !empty( $_POST['bbp-create-group-forum'] ) ? true : false; $forum_id = 0; $forum_ids = bbp_get_group_forum_ids( $group_id ); if ( !empty( $forum_ids ) ) $forum_id = (int) is_array( $forum_ids ) ? $forum_ids[0] : $forum_ids; // Create a forum, or not switch ( $create_forum ) { case true : // Bail if initial content was already created if ( !empty( $forum_id ) ) return; // Set the default forum status switch ( bp_get_new_group_status() ) { case 'hidden' : $status = bbp_get_hidden_status_id(); break; case 'private' : $status = bbp_get_private_status_id(); break; case 'public' : default : $status = bbp_get_public_status_id(); break; } // Create the initial forum $forum_id = bbp_insert_forum( array( 'post_parent' => bbp_get_group_forums_root_id(), 'post_title' => bp_get_new_group_name(), 'post_content' => bp_get_new_group_description(), 'post_status' => $status ) ); // Run the BP-specific functions for new groups $this->new_forum( array( 'forum_id' => $forum_id ) ); // Update forum active groups_update_groupmeta( bp_get_new_group_id(), '_bbp_forum_enabled_' . $forum_id, true ); // Toggle forum on $this->toggle_group_forum( bp_get_new_group_id(), true ); break; case false : // Forum was created but is now being undone if ( !empty( $forum_id ) ) { // Delete the forum wp_delete_post( $forum_id, true ); // Delete meta values groups_delete_groupmeta( bp_get_new_group_id(), 'forum_id' ); groups_delete_groupmeta( bp_get_new_group_id(), '_bbp_forum_enabled_' . $forum_id ); // Toggle forum off $this->toggle_group_forum( bp_get_new_group_id(), false ); } break; } } /** * Used to start an output buffer */ public function ob_start() { ob_start(); } /** * Used to end an output buffer */ public function ob_end_clean() { ob_end_clean(); } /** * Creating a group forum or category (including root for group) * * @since bbPress (r3653) * @param type $forum_args * @uses bbp_get_forum_id() * @uses bp_get_current_group_id() * @uses bbp_add_forum_id_to_group() * @uses bbp_add_group_id_to_forum() * @return if no forum_id is available */ public function new_forum( $forum_args = array() ) { // Bail if no forum_id was passed if ( empty( $forum_args['forum_id'] ) ) return; // Validate forum_id $forum_id = bbp_get_forum_id( $forum_args['forum_id'] ); $group_id = !empty( $forum_args['group_id'] ) ? $forum_args['group_id'] : bp_get_current_group_id(); bbp_add_forum_id_to_group( $group_id, $forum_id ); bbp_add_group_id_to_forum( $forum_id, $group_id ); } /** * Removing a group forum or category (including root for group) * * @since bbPress (r3653) * @param type $forum_args * @uses bbp_get_forum_id() * @uses bp_get_current_group_id() * @uses bbp_add_forum_id_to_group() * @uses bbp_add_group_id_to_forum() * @return if no forum_id is available */ public function remove_forum( $forum_args = array() ) { // Bail if no forum_id was passed if ( empty( $forum_args['forum_id'] ) ) return; // Validate forum_id $forum_id = bbp_get_forum_id( $forum_args['forum_id'] ); $group_id = !empty( $forum_args['group_id'] ) ? $forum_args['group_id'] : bp_get_current_group_id(); bbp_remove_forum_id_from_group( $group_id, $forum_id ); bbp_remove_group_id_from_forum( $forum_id, $group_id ); } /** * Listening to BuddyBoss Group deletion to remove the forum * * @param int $group_id The group ID * @uses bbp_get_group_forum_ids() * @uses BBP_Forums_Group_Extension::remove_forum() */ public function disconnect_forum_from_group( $group_id = 0 ) { // Bail if no group ID available if ( empty( $group_id ) ) { return; } // Get the forums for the current group $forum_ids = bbp_get_group_forum_ids( $group_id ); // Use the first forum ID if ( empty( $forum_ids ) ) return; // Get the first forum ID $forum_id = (int) is_array( $forum_ids ) ? $forum_ids[0] : $forum_ids; $this->remove_forum( array( 'forum_id' => $forum_id, 'group_id' => $group_id ) ); } /** * Toggle the enable_forum group setting on or off * * @since bbPress (r4612) * * @param int $group_id The group to toggle * @param bool $enabled True for on, false for off * @uses groups_get_group() To get the group to toggle * @return False if group is not found, otherwise return the group */ public function toggle_group_forum( $group_id = 0, $enabled = false ) { // Get the group $group = groups_get_group( array( 'group_id' => $group_id ) ); // Bail if group cannot be found if ( empty( $group ) ) return false; // Set forum enabled status $group->enable_forum = (int) $enabled; // Save the group $group->save(); // Maybe disconnect forum from group if ( empty( $enabled ) ) { $this->disconnect_forum_from_group( $group_id ); } // Update Forums' internal private and forum ID variables bbp_repair_forum_visibility(); // Return the group return $group; } /** Display Methods *******************************************************/ /** * Output the forums for a group in the edit screens * * As of right now, Forums only supports 1-to-1 group forum relationships. * In the future, many-to-many should be allowed. * * @since bbPress (r3653) * @uses bp_get_current_group_id() * @uses bbp_get_group_forum_ids() * @uses bbp_has_forums() * @uses bbp_get_template_part() */ public function display_forums( $offset = 0 ) { global $wp_query; // Allow actions immediately before group forum output do_action( 'bbp_before_group_forum_display' ); // Load up Forums once $bbp = bbpress(); /** Query Resets ******************************************************/ // Forum data $forum_action = bp_action_variable( $offset ); $forum_ids = bbp_get_group_forum_ids( bp_get_current_group_id() ); $forum_id = array_shift( $forum_ids ); // Always load up the group forum bbp_has_forums( array( 'p' => $forum_id, 'post_parent' => null ) ); // Set the global forum ID $bbp->current_forum_id = $forum_id; // Assume forum query bbp_set_query_name( 'bbp_single_forum' ); ?>
$forum_ids, 'selected' => bbp_get_form_topic_forum() ) ); ?>
更新日志
版本 | 描述 |
---|---|
bbPress (r3552) | 介绍了。 |
方法
- __构造-设置论坛组扩展变量
- create_screen.-显示论坛和新的论坛形式时,创建一个组
- create_screen_save-在创建时保存群组论坛数据
- disconnect_forum_from_group-听BuddyBoss群删除论坛
- 显示—群组论坛的主要显示功能
- display_forums-在编辑屏幕中输出一个组的论坛
- edit_redirect_to-重定向到组管理论坛编辑屏幕
- edit_screen.- 编辑组时显示论坛和新论坛表格
- edit_screen_save-在编辑时保存群组论坛数据
- form_permissions-在BuddyBoss组中查看“新主题”/“回复”形式的权限。
- forum_parent——形式助手 *********************************************************
- group_admin_ui_display_metabox-在BuddyBoss组管理界面中显示论坛元框
- group_admin_ui_edit_screen- 为Buddyboss Group Admin UI添加一个Metabox
- group_settings_hidden_field-如果群组论坛是启用的,在群组设置页面添加一个隐藏的输入字段。
- hide_super_sticky_admin_link-丑陋的preg_replace隐藏到前端管理链接
- map_activity_to_group-将论坛帖子映射到群组活动流中相应的群组。
- map_forum_permalink_to_group-映射一个论坛永久链接到它对应的组
- map_group_forum_meta_caps- 允许小组成员在组论坛主题中具有高级私权。
- map_reply_edit_url_to_group.-映射一个回复编辑链接到它的小组论坛
- map_reply_permalink_to_group-映射一个回复永久链接到它的小组论坛
- map_topic_permalink_to_group-映射一个主题永久链接到它的小组论坛
- maybe_map_permalink_to_group-可能映射一个论坛论坛/主题/回复永久链接到相应的组
- maybe_unset_forum_menu- 如果组没有论坛,则可能取消设置组论坛NAV项目
- new_forum-创建一个群组论坛或类别(包括群组根)
- new_reply_redirect_to-重定向到群组论坛屏幕
- new_topic_redirect_to-重定向到群组论坛屏幕
- no_super_stickies—去掉主题查询中的超级粘性
- ob_end_clean—用于结束输出缓冲区
- ob_start—用于启动输出缓冲区
- page_link.-映射一个页面链接到它的小组论坛
- post_link-映射一个帖子链接到它的论坛
- post_type_link-映射一个自定义的帖子类型链接到它的论坛
- redirect_canonical.-确保与BuddyBoss组关联的论坛内容只能通过组URL查看。
- remove_forum删除一个群组论坛或类别(包括群组根)
- remove_group_forum_meta_cap_map.-删除主题元帽地图,这样它就不会干扰侧边栏。
- replies_pagination-修复在主题视图上回复的分页
- setup_actions-设置组论坛类行动
- setup_filters-设置组论坛类过滤器
- setup_variables- 设置组论坛类变量
- toggle_group_forum—开启或关闭enable_forum组设置
- topic_pagination-修复在论坛视图的主题分页
- topic_parent
- unset_super_sticky—从主题类型中取消设置类型超级粘性