BBP_Default
加载论坛默认主题功能
描述
根据WordPress标准,这不是一个真正的主题,而是作为任何没有论坛模板的WordPress主题的备用主题。
为了使你的自定义主题论坛兼容和自定义模板,你可以复制这些文件到你的主题,而不需要合并任何东西在一起;论坛应该安全地处理剩下的事情。
另请参阅
- BBP_Theme_Compat():更多。
源
文件:bp-forums /模板/ / bbpress-functions.php违约
bbp_default类扩展bbp_theme_compat {/ **函数************************************************************* / / ** *主论坛(默认)加载器* * @since bbpress(r3732)* * @uses bbp_default :: setup_globals()* @uses bbp_default :: setup_actions()* / public function __construct($ properties = array()){parent :: __构造(bbp_parse_args($属性,array('id'=>'默认','name'=> __('博览会默认','buddyboss'),'版本'=> bbp_get_version(),'dir'=> trailinglast(bbpress() - > themes_dir。'默认'),'url'=> trailinglashit(bbpress() ->主题_URL。'默认'),),'default_theme'));$ this-> setup_actions();} / ** *设置主题挂钩* * @since bbpress(r3732)* @access private * * * @uses add_filter()添加各种过滤器* @uses add_action()以添加各种操作* / private函数setup_actions(){/ **脚本************************************************************* / add_action('bbp_enqueue_scripts',array($ this,'enqueue_scripts'));// enqueue主题js add_filter('bbp_enqueue_scripts',array($ this,'localize_topic_script'));// enqueue主题脚本本地化add_action('bbp_ajax_favorite',array($ this,'ajax_favorite'));//处理主题ajax收藏/不利地add_action('bbp_ajax_subscription',array($ this,'ajax_subscription')); // Handles the topic ajax subscribe/unsubscribe add_action( 'bbp_ajax_forum_subscription', array( $this, 'ajax_forum_subscription' ) ); // Handles the forum ajax subscribe/unsubscribe /** Template Wrappers *************************************************/ add_action( 'bbp_before_main_content', array( $this, 'before_main_content' ) ); // Top wrapper HTML add_action( 'bbp_after_main_content', array( $this, 'after_main_content' ) ); // Bottom wrapper HTML /** Override **********************************************************/ do_action_ref_array( 'bbp_theme_compat_actions', array( &$this ) ); } /** * Inserts HTML at the top of the main content area to be compatible with * the Twenty Twelve theme. * * @since bbPress (r3732) */ public function before_main_content() { ?>'js/editor.js', 'dependencies' => array( 'jquery' ) ); wp_enqueue_script( 'bp-medium-editor' ); wp_enqueue_style( 'bp-medium-editor' ); wp_enqueue_style( 'bp-medium-editor-beagle' ); } // Forum-specific scripts if ( bbp_is_single_forum() ) { $scripts['bbpress-forum'] = array( 'file' => 'js/forum.js', 'dependencies' => array( 'jquery' ) ); } // Topic-specific scripts if ( bbp_is_single_topic() ) { // Topic favorite/unsubscribe $scripts['bbpress-topic'] = array( 'file' => 'js/topic.js', 'dependencies' => array( 'jquery' ) ); // Hierarchical replies if ( bbp_thread_replies() ) { $scripts['bbpress-reply'] = array( 'file' => 'js/reply.js', 'dependencies' => array( 'jquery' ) ); } } // User Profile edit if ( bbp_is_single_user_edit() ) { $scripts['bbpress-user'] = array( 'file' => 'js/user.js', 'dependencies' => array( 'user-query' ) ); } $scripts['bbpress-common'] = array( 'file' => 'js/common.js', 'dependencies' => array( 'jquery' ) ); // Filter the scripts $scripts = apply_filters( 'bbp_default_scripts', $scripts ); // Enqueue the scripts foreach ( $scripts as $handle => $attributes ) { bbp_enqueue_script( $handle, $attributes['file'], $attributes['dependencies'], $this->version, 'screen' ); } } /** * Load localizations for topic script * * These localizations require information that may not be loaded even by init. * * @since bbPress (r3732) * * @uses bbp_is_single_forum() To check if it's the forum page * @uses bbp_is_single_topic() To check if it's the topic page * @uses is_user_logged_in() To check if user is logged in * @uses bbp_get_current_user_id() To get the current user id * @uses bbp_get_forum_id() To get the forum id * @uses bbp_get_topic_id() To get the topic id * @uses bbp_get_favorites_permalink() To get the favorites permalink * @uses bbp_is_user_favorite() To check if the topic is in user's favorites * @uses bbp_is_subscriptions_active() To check if the subscriptions are active * @uses bbp_is_user_subscribed() To check if the user is subscribed to topic * @uses bbp_get_topic_permalink() To get the topic permalink * @uses wp_localize_script() To localize the script */ public function localize_topic_script() { // Single forum if ( bbp_is_single_forum() ) { wp_localize_script( 'bbpress-forum', 'bbpForumJS', array( 'bbp_ajaxurl' => bbp_get_ajax_url(), 'generic_ajax_error' => __( 'Something went wrong. Refresh your browser and try again.', 'buddyboss' ), 'is_user_logged_in' => is_user_logged_in(), 'subs_nonce' => wp_create_nonce( 'toggle-subscription_' . get_the_ID() ) ) ); // Single topic } elseif ( bbp_is_single_topic() ) { wp_localize_script( 'bbpress-topic', 'bbpTopicJS', array( 'bbp_ajaxurl' => bbp_get_ajax_url(), 'generic_ajax_error' => __( 'Something went wrong. Refresh your browser and try again.', 'buddyboss' ), 'is_user_logged_in' => is_user_logged_in(), 'fav_nonce' => wp_create_nonce( 'toggle-favorite_' . get_the_ID() ), 'subs_nonce' => wp_create_nonce( 'toggle-subscription_' . get_the_ID() ) ) ); } } /** * AJAX handler to Subscribe/Unsubscribe a user from a forum * * @since bbPress (r5155) * * @uses bbp_is_subscriptions_active() To check if the subscriptions are active * @uses bbp_is_user_logged_in() To check if user is logged in * @uses bbp_get_current_user_id() To get the current user id * @uses current_user_can() To check if the current user can edit the user * @uses bbp_get_forum() To get the forum * @uses wp_verify_nonce() To verify the nonce * @uses bbp_is_user_subscribed() To check if the forum is in user's subscriptions * @uses bbp_remove_user_subscriptions() To remove the forum from user's subscriptions * @uses bbp_add_user_subscriptions() To add the forum from user's subscriptions * @uses bbp_ajax_response() To return JSON */ public function ajax_forum_subscription() { // Bail if subscriptions are not active if ( ! bbp_is_subscriptions_active() ) { bbp_ajax_response( false, __( 'Subscriptions are no longer active.', 'buddyboss' ), 300 ); } // Bail if user is not logged in if ( ! is_user_logged_in() ) { bbp_ajax_response( false, __( 'Please login to subscribe to this forum.', 'buddyboss' ), 301 ); } // Get user and forum data $user_id = bbp_get_current_user_id(); $id = intval( $_POST['id'] ); // Bail if user cannot add favorites for this user if ( ! current_user_can( 'edit_user', $user_id ) ) { bbp_ajax_response( false, __( 'You do not have permission to do this.', 'buddyboss' ), 302 ); } // Get the forum $forum = bbp_get_forum( $id ); // Bail if forum cannot be found if ( empty( $forum ) ) { bbp_ajax_response( false, __( 'The forum could not be found.', 'buddyboss' ), 303 ); } // Bail if user did not take this action if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'toggle-subscription_' . $forum->ID ) ) { bbp_ajax_response( false, __( 'Are you sure you meant to do that?', 'buddyboss' ), 304 ); } // Take action $status = bbp_is_user_subscribed( $user_id, $forum->ID ) ? bbp_remove_user_subscription( $user_id, $forum->ID ) : bbp_add_user_subscription( $user_id, $forum->ID ); // Bail if action failed if ( empty( $status ) ) { bbp_ajax_response( false, __( 'The request was unsuccessful. Please try again.', 'buddyboss' ), 305 ); } // Put subscription attributes in convenient array $attrs = array( 'forum_id' => $forum->ID, 'user_id' => $user_id ); // Action succeeded bbp_ajax_response( true, bbp_get_forum_subscription_link( $attrs, $user_id, false ), 200 ); } /** * AJAX handler to add or remove a topic from a user's favorites * * @since bbPress (r3732) * * @uses bbp_is_favorites_active() To check if favorites are active * @uses bbp_is_user_logged_in() To check if user is logged in * @uses bbp_get_current_user_id() To get the current user id * @uses current_user_can() To check if the current user can edit the user * @uses bbp_get_topic() To get the topic * @uses wp_verify_nonce() To verify the nonce & check the referer * @uses bbp_is_user_favorite() To check if the topic is user's favorite * @uses bbp_remove_user_favorite() To remove the topic from user's favorites * @uses bbp_add_user_favorite() To add the topic from user's favorites * @uses bbp_ajax_response() To return JSON */ public function ajax_favorite() { // Bail if favorites are not active if ( ! bbp_is_favorites_active() ) { bbp_ajax_response( false, __( 'Saving discussions is no longer active.', 'buddyboss' ), 300 ); } // Bail if user is not logged in if ( ! is_user_logged_in() ) { bbp_ajax_response( false, __( 'Please login to make this discussion a favorite.', 'buddyboss' ), 301 ); } // Get user and topic data $user_id = bbp_get_current_user_id(); $id = !empty( $_POST['id'] ) ? intval( $_POST['id'] ) : 0; // Bail if user cannot add favorites for this user if ( ! current_user_can( 'edit_user', $user_id ) ) { bbp_ajax_response( false, __( 'You do not have permission to do this.', 'buddyboss' ), 302 ); } // Get the topic $topic = bbp_get_topic( $id ); // Bail if topic cannot be found if ( empty( $topic ) ) { bbp_ajax_response( false, __( 'The discussion could not be found.', 'buddyboss' ), 303 ); } // Bail if user did not take this action if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'toggle-favorite_' . $topic->ID ) ) { bbp_ajax_response( false, __( 'Are you sure you meant to do that?', 'buddyboss' ), 304 ); } // Take action $status = bbp_is_user_favorite( $user_id, $topic->ID ) ? bbp_remove_user_favorite( $user_id, $topic->ID ) : bbp_add_user_favorite( $user_id, $topic->ID ); // Bail if action failed if ( empty( $status ) ) { bbp_ajax_response( false, __( 'The request was unsuccessful. Please try again.', 'buddyboss' ), 305 ); } // Put subscription attributes in convenient array $attrs = array( 'topic_id' => $topic->ID, 'user_id' => $user_id ); // Action succeeded bbp_ajax_response( true, bbp_get_user_favorites_link( $attrs, $user_id, false ), 200 ); } /** * AJAX handler to Subscribe/Unsubscribe a user from a topic * * @since bbPress (r3732) * * @uses bbp_is_subscriptions_active() To check if the subscriptions are active * @uses bbp_is_user_logged_in() To check if user is logged in * @uses bbp_get_current_user_id() To get the current user id * @uses current_user_can() To check if the current user can edit the user * @uses bbp_get_topic() To get the topic * @uses wp_verify_nonce() To verify the nonce * @uses bbp_is_user_subscribed() To check if the topic is in user's subscriptions * @uses bbp_remove_user_subscriptions() To remove the topic from user's subscriptions * @uses bbp_add_user_subscriptions() To add the topic from user's subscriptions * @uses bbp_ajax_response() To return JSON */ public function ajax_subscription() { // Bail if subscriptions are not active if ( ! bbp_is_subscriptions_active() ) { bbp_ajax_response( false, __( 'Subscriptions are no longer active.', 'buddyboss' ), 300 ); } // Bail if user is not logged in if ( ! is_user_logged_in() ) { bbp_ajax_response( false, __( 'Please login to subscribe to this discussion.', 'buddyboss' ), 301 ); } // Get user and topic data $user_id = bbp_get_current_user_id(); $id = intval( $_POST['id'] ); // Bail if user cannot add favorites for this user if ( ! current_user_can( 'edit_user', $user_id ) ) { bbp_ajax_response( false, __( 'You do not have permission to do this.', 'buddyboss' ), 302 ); } // Get the topic $topic = bbp_get_topic( $id ); // Bail if topic cannot be found if ( empty( $topic ) ) { bbp_ajax_response( false, __( 'The discussion could not be found.', 'buddyboss' ), 303 ); } // Bail if user did not take this action if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'toggle-subscription_' . $topic->ID ) ) { bbp_ajax_response( false, __( 'Are you sure you meant to do that?', 'buddyboss' ), 304 ); } // Take action $status = bbp_is_user_subscribed( $user_id, $topic->ID ) ? bbp_remove_user_subscription( $user_id, $topic->ID ) : bbp_add_user_subscription( $user_id, $topic->ID ); // Bail if action failed if ( empty( $status ) ) { bbp_ajax_response( false, __( 'The request was unsuccessful. Please try again.', 'buddyboss' ), 305 ); } // Put subscription attributes in convenient array $attrs = array( 'topic_id' => $topic->ID, 'user_id' => $user_id ); // Action succeeded bbp_ajax_response( true, bbp_get_user_subscribe_link( $attrs, $user_id, false ), 200 ); } }
更新日志
版本 | 描述 |
---|---|
bbPress (r3732) | 介绍了。 |
方法
- __construct-主论坛(默认)加载器
- after_main_content-在主要内容区域的底部插入HTML以与2012主题兼容。
- ajax_favorite- AJAX处理程序,从用户的收藏夹中添加或删除主题
- ajax_forum_subscription- AJAX处理程序订阅/退订用户从论坛
- ajax_subscription- AJAX处理程序订阅/取消订阅用户的主题
- before_main_content-在主要内容区域的顶部插入HTML,以与2012主题兼容。
- enqueue_scripts-进入所需的Javascript文件队列
- localize_topic_script-加载主题脚本的本地化
- media_localize_script为论坛的媒体组件本地化脚本
- mentions_script- Enqueue @提到JS。
- setup_actions-设置主题钩子