| @@ -17,873 +17,871 @@ | ||
| 17 | 17 | * @since 2.0.0 bbPress (r3032) |
| 18 | 18 | */ |
| 19 | 19 | class BBP_Shortcodes { |
| 20 | 20 | |
| 21 | - /** Vars ******************************************************************/ | |
| 21 | + /** Vars ******************************************************************/ | |
| 22 | 22 | |
| 23 | - /** | |
| 24 | - * Shortcode => function. | |
| 25 | - * | |
| 26 | - * @var array | |
| 27 | - */ | |
| 28 | - public $codes = array(); | |
| 23 | + /** | |
| 24 | + * @var array Shortcode => function | |
| 25 | + */ | |
| 26 | + public $codes = array(); | |
| 29 | 27 | |
| 30 | - /** Functions *************************************************************/ | |
| 28 | + /** Functions *************************************************************/ | |
| 31 | 29 | |
| 32 | - /** | |
| 33 | - * Add the register_shortcodes action to bbp_init | |
| 34 | - * | |
| 35 | - * @since 2.0.0 bbPress (r3143) | |
| 36 | - * | |
| 37 | - */ | |
| 38 | - public function __construct() { | |
| 39 | - $this->setup_globals(); | |
| 40 | - $this->add_shortcodes(); | |
| 41 | - } | |
| 30 | + /** | |
| 31 | + * Add the register_shortcodes action to bbp_init | |
| 32 | + * | |
| 33 | + * @since 2.0.0 bbPress (r3143) | |
| 34 | + * | |
| 35 | + */ | |
| 36 | + public function __construct() { | |
| 37 | + $this->setup_globals(); | |
| 38 | + $this->add_shortcodes(); | |
| 39 | + } | |
| 42 | 40 | |
| 43 | - /** | |
| 44 | - * Shortcode globals | |
| 45 | - * | |
| 46 | - * @since 2.0.0 bbPress (r3344) | |
| 47 | - * | |
| 48 | - * @access private | |
| 49 | - */ | |
| 50 | - private function setup_globals() { | |
| 41 | + /** | |
| 42 | + * Shortcode globals | |
| 43 | + * | |
| 44 | + * @since 2.0.0 bbPress (r3344) | |
| 45 | + * | |
| 46 | + * @access private | |
| 47 | + */ | |
| 48 | + private function setup_globals() { | |
| 51 | 49 | |
| 52 | - // phpcs:disable PEAR.Functions.FunctionCallSignature.CloseBracketLine | |
| 50 | + // phpcs:disable PEAR.Functions.FunctionCallSignature.CloseBracketLine | |
| 53 | 51 | |
| 54 | - // Setup the shortcodes | |
| 55 | - $this->codes = apply_filters( | |
| 56 | - 'bbp_shortcodes', | |
| 57 | - array( | |
| 52 | + // Setup the shortcodes | |
| 53 | + $this->codes = apply_filters( | |
| 54 | + 'bbp_shortcodes', | |
| 55 | + array( | |
| 58 | 56 | |
| 59 | - /** Forums ****************************************************/ | |
| 57 | + /** Forums ********************************************************/ | |
| 60 | 58 | |
| 61 | - 'bbp-forum-index' => array( $this, 'display_forum_index' ), // Forum Index | |
| 62 | - 'bbp-forum-form' => array( $this, 'display_forum_form' ), // Topic form | |
| 63 | - 'bbp-single-forum' => array( $this, 'display_forum' ), // Specific forum - pass an 'id' attribute | |
| 59 | + 'bbp-forum-index' => array( $this, 'display_forum_index' ), // Forum Index | |
| 60 | + 'bbp-forum-form' => array( $this, 'display_forum_form' ), // Topic form | |
| 61 | + 'bbp-single-forum' => array( $this, 'display_forum' ), // Specific forum - pass an 'id' attribute | |
| 64 | 62 | |
| 65 | - /** Topics ****************************************************/ | |
| 63 | + /** Topics ********************************************************/ | |
| 66 | 64 | |
| 67 | - 'bbp-topic-index' => array( $this, 'display_topic_index' ), // Topic index | |
| 68 | - 'bbp-topic-form' => array( $this, 'display_topic_form' ), // Topic form | |
| 69 | - 'bbp-single-topic' => array( $this, 'display_topic' ), // Specific topic - pass an 'id' attribute | |
| 65 | + 'bbp-topic-index' => array( $this, 'display_topic_index' ), // Topic index | |
| 66 | + 'bbp-topic-form' => array( $this, 'display_topic_form' ), // Topic form | |
| 67 | + 'bbp-single-topic' => array( $this, 'display_topic' ), // Specific topic - pass an 'id' attribute | |
| 70 | 68 | |
| 71 | - /** Topic Tags ************************************************/ | |
| 69 | + /** Topic Tags ****************************************************/ | |
| 72 | 70 | |
| 73 | - 'bbp-topic-tags' => array( $this, 'display_topic_tags' ), // All topic tags in a cloud | |
| 74 | - 'bbp-single-tag' => array( $this, 'display_topics_of_tag' ), // Topics of Tag | |
| 71 | + 'bbp-topic-tags' => array( $this, 'display_topic_tags' ), // All topic tags in a cloud | |
| 72 | + 'bbp-single-tag' => array( $this, 'display_topics_of_tag' ), // Topics of Tag | |
| 75 | 73 | |
| 76 | - /** Replies ***************************************************/ | |
| 74 | + /** Replies *******************************************************/ | |
| 77 | 75 | |
| 78 | - 'bbp-reply-form' => array( $this, 'display_reply_form' ), // Reply form | |
| 79 | - 'bbp-single-reply' => array( $this, 'display_reply' ), // Specific reply - pass an 'id' attribute | |
| 76 | + 'bbp-reply-form' => array( $this, 'display_reply_form' ), // Reply form | |
| 77 | + 'bbp-single-reply' => array( $this, 'display_reply' ), // Specific reply - pass an 'id' attribute | |
| 80 | 78 | |
| 81 | - /** Views *****************************************************/ | |
| 79 | + /** Views *********************************************************/ | |
| 82 | 80 | |
| 83 | - 'bbp-single-view' => array( $this, 'display_view' ), // Single view | |
| 81 | + 'bbp-single-view' => array( $this, 'display_view' ), // Single view | |
| 84 | 82 | |
| 85 | - /** Search ****************************************************/ | |
| 83 | + /** Search ********************************************************/ | |
| 86 | 84 | |
| 87 | - 'bbp-search-form' => array( $this, 'display_search_form' ), // Search form | |
| 88 | - 'bbp-search' => array( $this, 'display_search' ), // Search | |
| 85 | + 'bbp-search-form' => array( $this, 'display_search_form' ), // Search form | |
| 86 | + 'bbp-search' => array( $this, 'display_search' ), // Search | |
| 89 | 87 | |
| 90 | - /** Account ***************************************************/ | |
| 88 | + /** Account *******************************************************/ | |
| 91 | 89 | |
| 92 | - 'bbp-login' => array( $this, 'display_login' ), // Login | |
| 93 | - 'bbp-register' => array( $this, 'display_register' ), // Register | |
| 94 | - 'bbp-lost-pass' => array( $this, 'display_lost_pass' ), // Lost Password | |
| 90 | + 'bbp-login' => array( $this, 'display_login' ), // Login | |
| 91 | + 'bbp-register' => array( $this, 'display_register' ), // Register | |
| 92 | + 'bbp-lost-pass' => array( $this, 'display_lost_pass' ), // Lost Password | |
| 95 | 93 | |
| 96 | - /** Others ****************************************************/ | |
| 94 | + /** Others *******************************************************/ | |
| 97 | 95 | |
| 98 | - 'bbp-stats' => array( $this, 'display_stats' ), // Stats | |
| 99 | - ) | |
| 100 | - ); | |
| 96 | + 'bbp-stats' => array( $this, 'display_stats' ), // Stats | |
| 97 | + ) | |
| 98 | + ); | |
| 101 | 99 | |
| 102 | - // phpcs:enable | |
| 103 | - } | |
| 100 | + // phpcs:enable | |
| 101 | + } | |
| 104 | 102 | |
| 105 | - /** | |
| 106 | - * Register the bbPress shortcodes | |
| 107 | - * | |
| 108 | - * @since 2.0.0 bbPress (r3344) | |
| 109 | - */ | |
| 110 | - private function add_shortcodes() { | |
| 111 | - foreach ( (array) $this->codes as $code => $function ) { | |
| 112 | - add_shortcode( $code, $function ); | |
| 113 | - } | |
| 114 | - } | |
| 103 | + /** | |
| 104 | + * Register the bbPress shortcodes | |
| 105 | + * | |
| 106 | + * @since 2.0.0 bbPress (r3344) | |
| 107 | + */ | |
| 108 | + private function add_shortcodes() { | |
| 109 | + foreach ( (array) $this->codes as $code => $function ) { | |
| 110 | + add_shortcode( $code, $function ); | |
| 111 | + } | |
| 112 | + } | |
| 115 | 113 | |
| 116 | - /** | |
| 117 | - * Unset some globals in the $bbp object that hold query related info | |
| 118 | - * | |
| 119 | - * @since 2.0.0 bbPress (r3344) | |
| 120 | - */ | |
| 121 | - private function unset_globals() { | |
| 122 | - $bbp = bbpress(); | |
| 114 | + /** | |
| 115 | + * Unset some globals in the $bbp object that hold query related info | |
| 116 | + * | |
| 117 | + * @since 2.0.0 bbPress (r3344) | |
| 118 | + */ | |
| 119 | + private function unset_globals() { | |
| 120 | + $bbp = bbpress(); | |
| 123 | 121 | |
| 124 | - // Unset global queries | |
| 125 | - $bbp->forum_query = new WP_Query(); | |
| 126 | - $bbp->topic_query = new WP_Query(); | |
| 127 | - $bbp->reply_query = new WP_Query(); | |
| 128 | - $bbp->search_query = new WP_Query(); | |
| 122 | + // Unset global queries | |
| 123 | + $bbp->forum_query = new WP_Query(); | |
| 124 | + $bbp->topic_query = new WP_Query(); | |
| 125 | + $bbp->reply_query = new WP_Query(); | |
| 126 | + $bbp->search_query = new WP_Query(); | |
| 129 | 127 | |
| 130 | - // Unset global ID's | |
| 131 | - $bbp->current_view_id = 0; | |
| 132 | - $bbp->current_forum_id = 0; | |
| 133 | - $bbp->current_topic_id = 0; | |
| 134 | - $bbp->current_reply_id = 0; | |
| 135 | - $bbp->current_topic_tag_id = 0; | |
| 128 | + // Unset global ID's | |
| 129 | + $bbp->current_view_id = 0; | |
| 130 | + $bbp->current_forum_id = 0; | |
| 131 | + $bbp->current_topic_id = 0; | |
| 132 | + $bbp->current_reply_id = 0; | |
| 133 | + $bbp->current_topic_tag_id = 0; | |
| 136 | 134 | |
| 137 | - // Reset the post data | |
| 138 | - wp_reset_postdata(); | |
| 139 | - } | |
| 135 | + // Reset the post data | |
| 136 | + wp_reset_postdata(); | |
| 137 | + } | |
| 140 | 138 | |
| 141 | - /** Output Buffers ********************************************************/ | |
| 139 | + /** Output Buffers ********************************************************/ | |
| 142 | 140 | |
| 143 | - /** | |
| 144 | - * Start an output buffer. | |
| 145 | - * | |
| 146 | - * This is used to put the contents of the shortcode into a variable rather | |
| 147 | - * than outputting the HTML at run-time. This allows shortcodes to appear | |
| 148 | - * in the correct location in the_content() instead of when it's created. | |
| 149 | - * | |
| 150 | - * @since 2.0.0 bbPress (r3344) | |
| 151 | - * | |
| 152 | - * @param string $query_name | |
| 153 | - */ | |
| 154 | - private function start( $query_name = '' ) { | |
| 141 | + /** | |
| 142 | + * Start an output buffer. | |
| 143 | + * | |
| 144 | + * This is used to put the contents of the shortcode into a variable rather | |
| 145 | + * than outputting the HTML at run-time. This allows shortcodes to appear | |
| 146 | + * in the correct location in the_content() instead of when it's created. | |
| 147 | + * | |
| 148 | + * @since 2.0.0 bbPress (r3344) | |
| 149 | + * | |
| 150 | + * @param string $query_name | |
| 151 | + */ | |
| 152 | + private function start( $query_name = '' ) { | |
| 155 | 153 | |
| 156 | - // Set query name | |
| 157 | - bbp_set_query_name( $query_name ); | |
| 154 | + // Set query name | |
| 155 | + bbp_set_query_name( $query_name ); | |
| 158 | 156 | |
| 159 | - // Start output buffer | |
| 160 | - ob_start(); | |
| 161 | - } | |
| 157 | + // Start output buffer | |
| 158 | + ob_start(); | |
| 159 | + } | |
| 162 | 160 | |
| 163 | - /** | |
| 164 | - * Return the contents of the output buffer and flush its contents. | |
| 165 | - * | |
| 166 | - * @since 2.0.0 bbPress (r3344) | |
| 167 | - * | |
| 168 | - * @return string Contents of output buffer. | |
| 169 | - */ | |
| 170 | - private function end() { | |
| 161 | + /** | |
| 162 | + * Return the contents of the output buffer and flush its contents. | |
| 163 | + * | |
| 164 | + * @since 2.0.0 bbPress (r3344) | |
| 165 | + * | |
| 166 | + * @return string Contents of output buffer. | |
| 167 | + */ | |
| 168 | + private function end() { | |
| 171 | 169 | |
| 172 | - // Unset globals | |
| 173 | - $this->unset_globals(); | |
| 170 | + // Unset globals | |
| 171 | + $this->unset_globals(); | |
| 174 | 172 | |
| 175 | - // Get the query name, for filter | |
| 176 | - $query_name = bbp_get_query_name(); | |
| 173 | + // Get the query name, for filter | |
| 174 | + $query_name = bbp_get_query_name(); | |
| 177 | 175 | |
| 178 | - // Reset the query name | |
| 179 | - bbp_reset_query_name(); | |
| 176 | + // Reset the query name | |
| 177 | + bbp_reset_query_name(); | |
| 180 | 178 | |
| 181 | - // Return and flush the output buffer | |
| 182 | - $output = ob_get_clean(); | |
| 179 | + // Return and flush the output buffer | |
| 180 | + $output = ob_get_clean(); | |
| 183 | 181 | |
| 182 | + /** | |
| 183 | + * Filters the contents of the output buffer before returning. | |
| 184 | + * | |
| 185 | + * @since 2.6.0 bbPress (r6438) | |
| 186 | + * | |
| 187 | + * @param string $output The contents of the output buffer. | |
| 188 | + * @param string $query_name The query name used for this output. | |
| 189 | + */ | |
| 190 | + return apply_filters( 'bbp_display_shortcode', $output, $query_name ); | |
| 191 | + } | |
| 192 | + | |
| 193 | + /** Forum shortcodes ******************************************************/ | |
| 194 | + | |
| 184 | 195 | /** |
| 185 | - * Filters the contents of the output buffer before returning. | |
| 196 | + * Display an index of all visible root level forums in an output buffer | |
| 197 | + * and return to ensure that post/page contents are displayed first. | |
| 186 | 198 | * |
| 187 | - * @since 2.6.0 bbPress (r6438) | |
| 199 | + * @since 2.0.0 bbPress (r3032) | |
| 188 | 200 | * |
| 189 | - * @param string $output The contents of the output buffer. | |
| 190 | - * @param string $query_name The query name used for this output. | |
| 201 | + * @return string | |
| 191 | 202 | */ |
| 192 | - return apply_filters( 'bbp_display_shortcode', $output, $query_name ); | |
| 193 | - } | |
| 203 | + public function display_forum_index() { | |
| 194 | 204 | |
| 195 | - /** Forum shortcodes ******************************************************/ | |
| 205 | + // Unset globals | |
| 206 | + $this->unset_globals(); | |
| 196 | 207 | |
| 197 | - /** | |
| 198 | - * Display an index of all visible root level forums in an output buffer | |
| 199 | - * and return to ensure that post/page contents are displayed first. | |
| 200 | - * | |
| 201 | - * @since 2.0.0 bbPress (r3032) | |
| 202 | - * | |
| 203 | - * @return string | |
| 204 | - */ | |
| 205 | - public function display_forum_index() { | |
| 208 | + // Start output buffer | |
| 209 | + $this->start( 'bbp_forum_archive' ); | |
| 206 | 210 | |
| 207 | - // Unset globals | |
| 208 | - $this->unset_globals(); | |
| 211 | + bbp_get_template_part( 'content', 'archive-forum' ); | |
| 209 | 212 | |
| 210 | - // Start output buffer | |
| 211 | - $this->start( 'bbp_forum_archive' ); | |
| 213 | + // Return contents of output buffer | |
| 214 | + return $this->end(); | |
| 215 | + } | |
| 212 | 216 | |
| 213 | - bbp_get_template_part( 'content', 'archive-forum' ); | |
| 217 | + /** | |
| 218 | + * Display the contents of a specific forum ID in an output buffer | |
| 219 | + * and return to ensure that post/page contents are displayed first. | |
| 220 | + * | |
| 221 | + * @since 2.0.0 bbPress (r3032) | |
| 222 | + * | |
| 223 | + * @param array $attr | |
| 224 | + * @param string $content | |
| 225 | + * @return string | |
| 226 | + */ | |
| 227 | + public function display_forum( $attr, $content = '' ) { | |
| 214 | 228 | |
| 215 | - // Return contents of output buffer | |
| 216 | - return $this->end(); | |
| 217 | - } | |
| 229 | + // Sanity check required info | |
| 230 | + if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) { | |
| 231 | + return $content; | |
| 232 | + } | |
| 218 | 233 | |
| 219 | - /** | |
| 220 | - * Display the contents of a specific forum ID in an output buffer | |
| 221 | - * and return to ensure that post/page contents are displayed first. | |
| 222 | - * | |
| 223 | - * @since 2.0.0 bbPress (r3032) | |
| 224 | - * | |
| 225 | - * @param array $attr | |
| 226 | - * @param string $content | |
| 227 | - * @return string | |
| 228 | - */ | |
| 229 | - public function display_forum( $attr, $content = '' ) { | |
| 234 | + // Set passed attribute to $forum_id for clarity | |
| 235 | + $forum_id = bbpress()->current_forum_id = $attr['id']; | |
| 230 | 236 | |
| 231 | - // Sanity check required info | |
| 232 | - if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) { | |
| 233 | - return $content; | |
| 234 | - } | |
| 237 | + // Bail if ID passed is not a forum | |
| 238 | + if ( ! bbp_is_forum( $forum_id ) ) { | |
| 239 | + return $content; | |
| 240 | + } | |
| 235 | 241 | |
| 236 | - // Set passed attribute to $forum_id for clarity | |
| 237 | - $forum_id = bbpress()->current_forum_id = $attr['id']; | |
| 242 | + // Start output buffer | |
| 243 | + $this->start( 'bbp_single_forum' ); | |
| 238 | 244 | |
| 239 | - // Bail if ID passed is not a forum | |
| 240 | - if ( ! bbp_is_forum( $forum_id ) ) { | |
| 241 | - return $content; | |
| 242 | - } | |
| 245 | + // Check forum caps | |
| 246 | + if ( bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) { | |
| 247 | + bbp_get_template_part( 'content', 'single-forum' ); | |
| 243 | 248 | |
| 244 | - // Start output buffer | |
| 245 | - $this->start( 'bbp_single_forum' ); | |
| 249 | + // Forum is private and user does not have caps | |
| 250 | + } elseif ( bbp_is_forum_private( $forum_id, false ) ) { | |
| 251 | + bbp_get_template_part( 'feedback', 'no-access' ); | |
| 252 | + } | |
| 246 | 253 | |
| 247 | - // Check forum caps | |
| 248 | - if ( bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) { | |
| 249 | - bbp_get_template_part( 'content', 'single-forum' ); | |
| 254 | + // Return contents of output buffer | |
| 255 | + return $this->end(); | |
| 256 | + } | |
| 250 | 257 | |
| 251 | - // Forum is private and user does not have caps | |
| 252 | - } elseif ( bbp_is_forum_private( $forum_id, false ) ) { | |
| 253 | - bbp_get_template_part( 'feedback', 'no-access' ); | |
| 254 | - } | |
| 258 | + /** | |
| 259 | + * Display the forum form in an output buffer and return to ensure | |
| 260 | + * post/page contents are displayed first. | |
| 261 | + * | |
| 262 | + * @since 2.1.0 bbPress (r3566) | |
| 263 | + */ | |
| 264 | + public function display_forum_form() { | |
| 255 | 265 | |
| 256 | - // Return contents of output buffer | |
| 257 | - return $this->end(); | |
| 258 | - } | |
| 266 | + // Start output buffer | |
| 267 | + $this->start( 'bbp_forum_form' ); | |
| 259 | 268 | |
| 260 | - /** | |
| 261 | - * Display the forum form in an output buffer and return to ensure | |
| 262 | - * post/page contents are displayed first. | |
| 263 | - * | |
| 264 | - * @since 2.1.0 bbPress (r3566) | |
| 265 | - */ | |
| 266 | - public function display_forum_form() { | |
| 269 | + // Output templates | |
| 270 | + bbp_get_template_part( 'form', 'forum' ); | |
| 267 | 271 | |
| 268 | - // Start output buffer | |
| 269 | - $this->start( 'bbp_forum_form' ); | |
| 272 | + // Return contents of output buffer | |
| 273 | + return $this->end(); | |
| 274 | + } | |
| 270 | 275 | |
| 271 | - // Output templates | |
| 272 | - bbp_get_template_part( 'form', 'forum' ); | |
| 276 | + /** Topic shortcodes ******************************************************/ | |
| 273 | 277 | |
| 274 | - // Return contents of output buffer | |
| 275 | - return $this->end(); | |
| 276 | - } | |
| 278 | + /** | |
| 279 | + * Display an index of all visible root level topics in an output buffer | |
| 280 | + * and return to ensure that post/page contents are displayed first. | |
| 281 | + * | |
| 282 | + * @since 2.0.0 bbPress (r3032) | |
| 283 | + * | |
| 284 | + * @return string | |
| 285 | + */ | |
| 286 | + public function display_topic_index() { | |
| 277 | 287 | |
| 278 | - /** Topic shortcodes ******************************************************/ | |
| 288 | + // Unset globals | |
| 289 | + $this->unset_globals(); | |
| 279 | 290 | |
| 280 | - /** | |
| 281 | - * Display an index of all visible root level topics in an output buffer | |
| 282 | - * and return to ensure that post/page contents are displayed first. | |
| 283 | - * | |
| 284 | - * @since 2.0.0 bbPress (r3032) | |
| 285 | - * | |
| 286 | - * @return string | |
| 287 | - */ | |
| 288 | - public function display_topic_index() { | |
| 291 | + // Filter the query | |
| 292 | + if ( ! bbp_is_topic_archive() ) { | |
| 293 | + add_filter( 'bbp_before_has_topics_parse_args', array( $this, 'display_topic_index_query' ) ); | |
| 294 | + } | |
| 289 | 295 | |
| 290 | - // Unset globals | |
| 291 | - $this->unset_globals(); | |
| 296 | + // Start output buffer | |
| 297 | + $this->start( 'bbp_topic_archive' ); | |
| 292 | 298 | |
| 293 | - // Filter the query | |
| 294 | - if ( ! bbp_is_topic_archive() ) { | |
| 295 | - add_filter( 'bbp_before_has_topics_parse_args', array( $this, 'display_topic_index_query' ) ); | |
| 296 | - } | |
| 299 | + // Output template | |
| 300 | + bbp_get_template_part( 'content', 'archive-topic' ); | |
| 297 | 301 | |
| 298 | - // Start output buffer | |
| 299 | - $this->start( 'bbp_topic_archive' ); | |
| 302 | + // Return contents of output buffer | |
| 303 | + return $this->end(); | |
| 304 | + } | |
| 300 | 305 | |
| 301 | - // Output template | |
| 302 | - bbp_get_template_part( 'content', 'archive-topic' ); | |
| 306 | + /** | |
| 307 | + * Display the contents of a specific topic ID in an output buffer | |
| 308 | + * and return to ensure that post/page contents are displayed first. | |
| 309 | + * | |
| 310 | + * @since 2.0.0 bbPress (r3032) | |
| 311 | + * | |
| 312 | + * @param array $attr | |
| 313 | + * @param string $content | |
| 314 | + * @return string | |
| 315 | + */ | |
| 316 | + public function display_topic( $attr, $content = '' ) { | |
| 303 | 317 | |
| 304 | - // Return contents of output buffer | |
| 305 | - return $this->end(); | |
| 306 | - } | |
| 318 | + // Sanity check required info | |
| 319 | + if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) { | |
| 320 | + return $content; | |
| 321 | + } | |
| 307 | 322 | |
| 308 | - /** | |
| 309 | - * Display the contents of a specific topic ID in an output buffer | |
| 310 | - * and return to ensure that post/page contents are displayed first. | |
| 311 | - * | |
| 312 | - * @since 2.0.0 bbPress (r3032) | |
| 313 | - * | |
| 314 | - * @param array $attr | |
| 315 | - * @param string $content | |
| 316 | - * @return string | |
| 317 | - */ | |
| 318 | - public function display_topic( $attr, $content = '' ) { | |
| 323 | + // Unset globals | |
| 324 | + $this->unset_globals(); | |
| 319 | 325 | |
| 320 | - // Sanity check required info | |
| 321 | - if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) { | |
| 322 | - return $content; | |
| 323 | - } | |
| 326 | + // Set passed attribute to $forum_id for clarity | |
| 327 | + $topic_id = bbpress()->current_topic_id = $attr['id']; | |
| 328 | + $forum_id = bbp_get_topic_forum_id( $topic_id ); | |
| 324 | 329 | |
| 325 | - // Unset globals | |
| 326 | - $this->unset_globals(); | |
| 330 | + // Bail if ID passed is not a topic | |
| 331 | + if ( ! bbp_is_topic( $topic_id ) ) { | |
| 332 | + return $content; | |
| 333 | + } | |
| 327 | 334 | |
| 328 | - // Set passed attribute to $forum_id for clarity | |
| 329 | - $topic_id = bbpress()->current_topic_id = $attr['id']; | |
| 330 | - $forum_id = bbp_get_topic_forum_id( $topic_id ); | |
| 335 | + // Do not render a non-public topic for users who cannot read it. | |
| 336 | + if ( ! bbp_is_topic_public( $topic_id ) && ! current_user_can( 'read_topic', $topic_id ) ) { | |
| 337 | + return $content; | |
| 338 | + } | |
| 331 | 339 | |
| 332 | - // Bail if ID passed is not a topic | |
| 333 | - if ( ! bbp_is_topic( $topic_id ) ) { | |
| 334 | - return $content; | |
| 335 | - } | |
| 340 | + // Reset the queries if not in theme compat | |
| 341 | + if ( ! bbp_is_theme_compat_active() ) { | |
| 336 | 342 | |
| 337 | - // Do not render a non-public topic for users who cannot read it. | |
| 338 | - if ( ! bbp_is_topic_public( $topic_id ) && ! current_user_can( 'read_topic', $topic_id ) ) { | |
| 339 | - return $content; | |
| 340 | - } | |
| 343 | + $bbp = bbpress(); | |
| 341 | 344 | |
| 342 | - // Reset the queries if not in theme compat | |
| 343 | - if ( ! bbp_is_theme_compat_active() ) { | |
| 345 | + // Reset necessary forum_query attributes for topics loop to function | |
| 346 | + $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type(); | |
| 347 | + $bbp->forum_query->in_the_loop = true; | |
| 348 | + $bbp->forum_query->post = get_post( $forum_id ); | |
| 344 | 349 | |
| 345 | - $bbp = bbpress(); | |
| 350 | + // Reset necessary topic_query attributes for topics loop to function | |
| 351 | + $bbp->topic_query->query_vars['post_type'] = bbp_get_topic_post_type(); | |
| 352 | + $bbp->topic_query->in_the_loop = true; | |
| 353 | + $bbp->topic_query->post = get_post( $topic_id ); | |
| 354 | + } | |
| 346 | 355 | |
| 347 | - // Reset necessary forum_query attributes for topics loop to function | |
| 348 | - $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type(); | |
| 349 | - $bbp->forum_query->in_the_loop = true; | |
| 350 | - $bbp->forum_query->post = get_post( $forum_id ); | |
| 356 | + // Start output buffer | |
| 357 | + $this->start( 'bbp_single_topic' ); | |
| 351 | 358 | |
| 352 | - // Reset necessary topic_query attributes for topics loop to function | |
| 353 | - $bbp->topic_query->query_vars['post_type'] = bbp_get_topic_post_type(); | |
| 354 | - $bbp->topic_query->in_the_loop = true; | |
| 355 | - $bbp->topic_query->post = get_post( $topic_id ); | |
| 356 | - } | |
| 359 | + // Check forum caps | |
| 360 | + if ( bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) { | |
| 361 | + bbp_get_template_part( 'content', 'single-topic' ); | |
| 357 | 362 | |
| 358 | - // Start output buffer | |
| 359 | - $this->start( 'bbp_single_topic' ); | |
| 363 | + // Forum is private and user does not have caps | |
| 364 | + } elseif ( bbp_is_forum_private( $forum_id, false ) ) { | |
| 365 | + bbp_get_template_part( 'feedback', 'no-access' ); | |
| 366 | + } | |
| 360 | 367 | |
| 361 | - // Check forum caps | |
| 362 | - if ( bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) { | |
| 363 | - bbp_get_template_part( 'content', 'single-topic' ); | |
| 368 | + // Return contents of output buffer | |
| 369 | + return $this->end(); | |
| 370 | + } | |
| 364 | 371 | |
| 365 | - // Forum is private and user does not have caps | |
| 366 | - } elseif ( bbp_is_forum_private( $forum_id, false ) ) { | |
| 367 | - bbp_get_template_part( 'feedback', 'no-access' ); | |
| 368 | - } | |
| 372 | + /** | |
| 373 | + * Display the topic form in an output buffer and return to ensure | |
| 374 | + * post/page contents are displayed first. | |
| 375 | + * | |
| 376 | + * Supports 'forum_id' attribute to display the topic form for a particular | |
| 377 | + * forum. This currently has styling issues from not being wrapped in | |
| 378 | + * <div id="bbpress-forums" class="bbpress-wrapper"></div> which will need to be sorted out later. | |
| 379 | + * | |
| 380 | + * @since 2.0.0 bbPress (r3042) | |
| 381 | + * | |
| 382 | + * @param array $attr | |
| 383 | + * @param string $content | |
| 384 | + * @return string | |
| 385 | + */ | |
| 386 | + public function display_topic_form( $attr = array(), $content = '' ) { | |
| 369 | 387 | |
| 370 | - // Return contents of output buffer | |
| 371 | - return $this->end(); | |
| 372 | - } | |
| 388 | + // Sanity check supplied info | |
| 389 | + if ( ! empty( $content ) || ( ! empty( $attr['forum_id'] ) && ( ! is_numeric( $attr['forum_id'] ) || ! bbp_is_forum( $attr['forum_id'] ) ) ) ) { | |
| 390 | + return $content; | |
| 391 | + } | |
| 373 | 392 | |
| 374 | - /** | |
| 375 | - * Display the topic form in an output buffer and return to ensure | |
| 376 | - * post/page contents are displayed first. | |
| 377 | - * | |
| 378 | - * Supports 'forum_id' attribute to display the topic form for a particular | |
| 379 | - * forum. This currently has styling issues from not being wrapped in | |
| 380 | - * <div id="bbpress-forums" class="bbpress-wrapper"></div> which will need to be sorted out later. | |
| 381 | - * | |
| 382 | - * @since 2.0.0 bbPress (r3042) | |
| 383 | - * | |
| 384 | - * @param array $attr | |
| 385 | - * @param string $content | |
| 386 | - * @return string | |
| 387 | - */ | |
| 388 | - public function display_topic_form( $attr = array(), $content = '' ) { | |
| 393 | + // Unset globals | |
| 394 | + $this->unset_globals(); | |
| 389 | 395 | |
| 390 | - // Sanity check supplied info | |
| 391 | - if ( ! empty( $content ) || ( ! empty( $attr['forum_id'] ) && ( ! is_numeric( $attr['forum_id'] ) || ! bbp_is_forum( $attr['forum_id'] ) ) ) ) { | |
| 392 | - return $content; | |
| 393 | - } | |
| 396 | + // If forum id is set, use the 'bbp_single_forum' query name | |
| 397 | + if ( ! empty( $attr['forum_id'] ) ) { | |
| 394 | 398 | |
| 395 | - // Unset globals | |
| 396 | - $this->unset_globals(); | |
| 399 | + // Set the global current_forum_id for future requests | |
| 400 | + bbpress()->current_forum_id = $forum_id = bbp_get_forum_id( $attr['forum_id'] ); | |
| 397 | 401 | |
| 398 | - // If forum id is set, use the 'bbp_single_forum' query name | |
| 399 | - if ( ! empty( $attr['forum_id'] ) ) { | |
| 402 | + // Start output buffer | |
| 403 | + $this->start( 'bbp_single_forum' ); | |
| 400 | 404 | |
| 401 | - // Set the global current_forum_id for future requests | |
| 402 | - bbpress()->current_forum_id = $forum_id = bbp_get_forum_id( $attr['forum_id'] ); | |
| 405 | + // No forum id was passed | |
| 406 | + } else { | |
| 403 | 407 | |
| 404 | - // Start output buffer | |
| 405 | - $this->start( 'bbp_single_forum' ); | |
| 408 | + // Set the $forum_id variable to satisfy checks below | |
| 409 | + $forum_id = 0; | |
| 406 | 410 | |
| 407 | - // No forum id was passed | |
| 408 | - } else { | |
| 411 | + // Start output buffer | |
| 412 | + $this->start( 'bbp_topic_form' ); | |
| 413 | + } | |
| 409 | 414 | |
| 410 | - // Set the $forum_id variable to satisfy checks below | |
| 411 | - $forum_id = 0; | |
| 415 | + // If the forum id is set, check forum caps else display normal topic form | |
| 416 | + if ( empty( $forum_id ) || bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) { | |
| 417 | + bbp_get_template_part( 'form', 'topic' ); | |
| 412 | 418 | |
| 413 | - // Start output buffer | |
| 414 | - $this->start( 'bbp_topic_form' ); | |
| 415 | - } | |
| 419 | + // Forum is private and user does not have caps | |
| 420 | + } elseif ( bbp_is_forum_private( $forum_id, false ) ) { | |
| 421 | + bbp_get_template_part( 'feedback', 'no-access' ); | |
| 422 | + } | |
| 416 | 423 | |
| 417 | - // If the forum id is set, check forum caps else display normal topic form | |
| 418 | - if ( empty( $forum_id ) || bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) { | |
| 419 | - bbp_get_template_part( 'form', 'topic' ); | |
| 424 | + // Return contents of output buffer | |
| 425 | + return $this->end(); | |
| 426 | + } | |
| 420 | 427 | |
| 421 | - // Forum is private and user does not have caps | |
| 422 | - } elseif ( bbp_is_forum_private( $forum_id, false ) ) { | |
| 423 | - bbp_get_template_part( 'feedback', 'no-access' ); | |
| 424 | - } | |
| 428 | + /** Replies ***************************************************************/ | |
| 425 | 429 | |
| 426 | - // Return contents of output buffer | |
| 427 | - return $this->end(); | |
| 428 | - } | |
| 430 | + /** | |
| 431 | + * Display the contents of a specific reply ID in an output buffer | |
| 432 | + * and return to ensure that post/page contents are displayed first. | |
| 433 | + * | |
| 434 | + * @since 2.1.0 bbPress (r3634) | |
| 435 | + * | |
| 436 | + * @param array $attr | |
| 437 | + * @param string $content | |
| 438 | + * @return string | |
| 439 | + */ | |
| 440 | + public function display_reply( $attr, $content = '' ) { | |
| 429 | 441 | |
| 430 | - /** Replies ***************************************************************/ | |
| 442 | + // Sanity check required info | |
| 443 | + if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) { | |
| 444 | + return $content; | |
| 445 | + } | |
| 431 | 446 | |
| 432 | - /** | |
| 433 | - * Display the contents of a specific reply ID in an output buffer | |
| 434 | - * and return to ensure that post/page contents are displayed first. | |
| 435 | - * | |
| 436 | - * @since 2.1.0 bbPress (r3634) | |
| 437 | - * | |
| 438 | - * @param array $attr | |
| 439 | - * @param string $content | |
| 440 | - * @return string | |
| 441 | - */ | |
| 442 | - public function display_reply( $attr, $content = '' ) { | |
| 447 | + // Unset globals | |
| 448 | + $this->unset_globals(); | |
| 443 | 449 | |
| 444 | - // Sanity check required info | |
| 445 | - if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) { | |
| 446 | - return $content; | |
| 447 | - } | |
| 450 | + // Set passed attribute to $reply_id for clarity | |
| 451 | + $reply_id = bbpress()->current_reply_id = $attr['id']; | |
| 452 | + $forum_id = bbp_get_reply_forum_id( $reply_id ); | |
| 448 | 453 | |
| 449 | - // Unset globals | |
| 450 | - $this->unset_globals(); | |
| 454 | + // Bail if ID passed is not a reply | |
| 455 | + if ( ! bbp_is_reply( $reply_id ) ) { | |
| 456 | + return $content; | |
| 457 | + } | |
| 451 | 458 | |
| 452 | - // Set passed attribute to $reply_id for clarity | |
| 453 | - $reply_id = bbpress()->current_reply_id = $attr['id']; | |
| 454 | - $forum_id = bbp_get_reply_forum_id( $reply_id ); | |
| 459 | + // Do not render a non-public reply or its parent topic to unauthorized users. | |
| 460 | + $topic_id = bbp_get_reply_topic_id( $reply_id ); | |
| 461 | + if ( ( ! bbp_is_reply_public( $reply_id ) && ! current_user_can( 'read_reply', $reply_id ) ) || ( ! bbp_is_topic_public( $topic_id ) && ! current_user_can( 'read_topic', $topic_id ) ) ) { | |
| 462 | + return $content; | |
| 463 | + } | |
| 455 | 464 | |
| 456 | - // Bail if ID passed is not a reply | |
| 457 | - if ( ! bbp_is_reply( $reply_id ) ) { | |
| 458 | - return $content; | |
| 459 | - } | |
| 465 | + // Reset the queries if not in theme compat | |
| 466 | + if ( ! bbp_is_theme_compat_active() ) { | |
| 460 | 467 | |
| 461 | - // Do not render a non-public reply or its parent topic to unauthorized users. | |
| 462 | - $topic_id = bbp_get_reply_topic_id( $reply_id ); | |
| 463 | - if ( ( ! bbp_is_reply_public( $reply_id ) && ! current_user_can( 'read_reply', $reply_id ) ) || ( ! bbp_is_topic_public( $topic_id ) && ! current_user_can( 'read_topic', $topic_id ) ) ) { | |
| 464 | - return $content; | |
| 465 | - } | |
| 468 | + $bbp = bbpress(); | |
| 466 | 469 | |
| 467 | - // Reset the queries if not in theme compat | |
| 468 | - if ( ! bbp_is_theme_compat_active() ) { | |
| 470 | + // Reset necessary forum_query attributes for reply loop to function | |
| 471 | + $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type(); | |
| 472 | + $bbp->forum_query->in_the_loop = true; | |
| 473 | + $bbp->forum_query->post = get_post( $forum_id ); | |
| 469 | 474 | |
| 470 | - $bbp = bbpress(); | |
| 475 | + // Reset necessary reply_query attributes for reply loop to function | |
| 476 | + $bbp->reply_query->query_vars['post_type'] = bbp_get_reply_post_type(); | |
| 477 | + $bbp->reply_query->in_the_loop = true; | |
| 478 | + $bbp->reply_query->post = get_post( $reply_id ); | |
| 479 | + } | |
| 471 | 480 | |
| 472 | - // Reset necessary forum_query attributes for reply loop to function | |
| 473 | - $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type(); | |
| 474 | - $bbp->forum_query->in_the_loop = true; | |
| 475 | - $bbp->forum_query->post = get_post( $forum_id ); | |
| 481 | + // Start output buffer | |
| 482 | + $this->start( 'bbp_single_reply' ); | |
| 476 | 483 | |
| 477 | - // Reset necessary reply_query attributes for reply loop to function | |
| 478 | - $bbp->reply_query->query_vars['post_type'] = bbp_get_reply_post_type(); | |
| 479 | - $bbp->reply_query->in_the_loop = true; | |
| 480 | - $bbp->reply_query->post = get_post( $reply_id ); | |
| 481 | - } | |
| 484 | + // Check forum caps | |
| 485 | + if ( bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) { | |
| 486 | + bbp_get_template_part( 'content', 'single-reply' ); | |
| 482 | 487 | |
| 483 | - // Start output buffer | |
| 484 | - $this->start( 'bbp_single_reply' ); | |
| 488 | + // Forum is private and user does not have caps | |
| 489 | + } elseif ( bbp_is_forum_private( $forum_id, false ) ) { | |
| 490 | + bbp_get_template_part( 'feedback', 'no-access' ); | |
| 491 | + } | |
| 485 | 492 | |
| 486 | - // Check forum caps | |
| 487 | - if ( bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) { | |
| 488 | - bbp_get_template_part( 'content', 'single-reply' ); | |
| 493 | + // Return contents of output buffer | |
| 494 | + return $this->end(); | |
| 495 | + } | |
| 489 | 496 | |
| 490 | - // Forum is private and user does not have caps | |
| 491 | - } elseif ( bbp_is_forum_private( $forum_id, false ) ) { | |
| 492 | - bbp_get_template_part( 'feedback', 'no-access' ); | |
| 493 | - } | |
| 497 | + /** | |
| 498 | + * Display the reply form in an output buffer and return to ensure | |
| 499 | + * post/page contents are displayed first. | |
| 500 | + * | |
| 501 | + * @since 2.0.0 bbPress (r3042) | |
| 502 | + */ | |
| 503 | + public function display_reply_form() { | |
| 494 | 504 | |
| 495 | - // Return contents of output buffer | |
| 496 | - return $this->end(); | |
| 497 | - } | |
| 505 | + // Start output buffer | |
| 506 | + $this->start( 'bbp_reply_form' ); | |
| 498 | 507 | |
| 499 | - /** | |
| 500 | - * Display the reply form in an output buffer and return to ensure | |
| 501 | - * post/page contents are displayed first. | |
| 502 | - * | |
| 503 | - * @since 2.0.0 bbPress (r3042) | |
| 504 | - */ | |
| 505 | - public function display_reply_form() { | |
| 508 | + // Output templates | |
| 509 | + bbp_get_template_part( 'form', 'reply' ); | |
| 506 | 510 | |
| 507 | - // Start output buffer | |
| 508 | - $this->start( 'bbp_reply_form' ); | |
| 511 | + // Return contents of output buffer | |
| 512 | + return $this->end(); | |
| 513 | + } | |
| 509 | 514 | |
| 510 | - // Output templates | |
| 511 | - bbp_get_template_part( 'form', 'reply' ); | |
| 515 | + /** Topic Tags ************************************************************/ | |
| 512 | 516 | |
| 513 | - // Return contents of output buffer | |
| 514 | - return $this->end(); | |
| 515 | - } | |
| 517 | + /** | |
| 518 | + * Display a tag cloud of all topic tags in an output buffer and return to | |
| 519 | + * ensure that post/page contents are displayed first. | |
| 520 | + * | |
| 521 | + * @since 2.0.0 bbPress (r3132) | |
| 522 | + * | |
| 523 | + * @return string | |
| 524 | + */ | |
| 525 | + public function display_topic_tags() { | |
| 516 | 526 | |
| 517 | - /** Topic Tags ************************************************************/ | |
| 527 | + // Unset globals | |
| 528 | + $this->unset_globals(); | |
| 518 | 529 | |
| 519 | - /** | |
| 520 | - * Display a tag cloud of all topic tags in an output buffer and return to | |
| 521 | - * ensure that post/page contents are displayed first. | |
| 522 | - * | |
| 523 | - * @since 2.0.0 bbPress (r3132) | |
| 524 | - * | |
| 525 | - * @return string | |
| 526 | - */ | |
| 527 | - public function display_topic_tags() { | |
| 530 | + // Start output buffer | |
| 531 | + $this->start( 'bbp_topic_tags' ); | |
| 528 | 532 | |
| 529 | - // Unset globals | |
| 530 | - $this->unset_globals(); | |
| 533 | + // Output the topic tags | |
| 534 | + wp_tag_cloud( | |
| 535 | + array( | |
| 536 | + 'smallest' => 9, | |
| 537 | + 'largest' => 38, | |
| 538 | + 'number' => 80, | |
| 539 | + 'taxonomy' => bbp_get_topic_tag_tax_id() | |
| 540 | + ) | |
| 541 | + ); | |
| 531 | 542 | |
| 532 | - // Start output buffer | |
| 533 | - $this->start( 'bbp_topic_tags' ); | |
| 543 | + // Return contents of output buffer | |
| 544 | + return $this->end(); | |
| 545 | + } | |
| 534 | 546 | |
| 535 | - // Output the topic tags | |
| 536 | - wp_tag_cloud( | |
| 537 | - array( | |
| 538 | - 'smallest' => 9, | |
| 539 | - 'largest' => 38, | |
| 540 | - 'number' => 80, | |
| 541 | - 'taxonomy' => bbp_get_topic_tag_tax_id() | |
| 542 | - ) | |
| 543 | - ); | |
| 547 | + /** | |
| 548 | + * Display the contents of a specific topic tag in an output buffer | |
| 549 | + * and return to ensure that post/page contents are displayed first. | |
| 550 | + * | |
| 551 | + * @since 2.0.0 bbPress (r3132) | |
| 552 | + * | |
| 553 | + * @param array $attr | |
| 554 | + * @param string $content | |
| 555 | + * @return string | |
| 556 | + */ | |
| 557 | + public function display_topics_of_tag( $attr, $content = '' ) { | |
| 544 | 558 | |
| 545 | - // Return contents of output buffer | |
| 546 | - return $this->end(); | |
| 547 | - } | |
| 559 | + // Sanity check required info | |
| 560 | + if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) { | |
| 561 | + return $content; | |
| 562 | + } | |
| 548 | 563 | |
| 549 | - /** | |
| 550 | - * Display the contents of a specific topic tag in an output buffer | |
| 551 | - * and return to ensure that post/page contents are displayed first. | |
| 552 | - * | |
| 553 | - * @since 2.0.0 bbPress (r3132) | |
| 554 | - * | |
| 555 | - * @param array $attr | |
| 556 | - * @param string $content | |
| 557 | - * @return string | |
| 558 | - */ | |
| 559 | - public function display_topics_of_tag( $attr, $content = '' ) { | |
| 564 | + // Unset globals | |
| 565 | + $this->unset_globals(); | |
| 560 | 566 | |
| 561 | - // Sanity check required info | |
| 562 | - if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) { | |
| 563 | - return $content; | |
| 564 | - } | |
| 567 | + // Filter the query | |
| 568 | + if ( ! bbp_is_topic_tag() ) { | |
| 569 | + add_filter( 'bbp_before_has_topics_parse_args', array( $this, 'display_topics_of_tag_query' ) ); | |
| 570 | + } | |
| 565 | 571 | |
| 566 | - // Unset globals | |
| 567 | - $this->unset_globals(); | |
| 572 | + // Start output buffer | |
| 573 | + $this->start( 'bbp_topic_tag' ); | |
| 568 | 574 | |
| 569 | - // Filter the query | |
| 570 | - if ( ! bbp_is_topic_tag() ) { | |
| 571 | - add_filter( 'bbp_before_has_topics_parse_args', array( $this, 'display_topics_of_tag_query' ) ); | |
| 572 | - } | |
| 575 | + // Set passed attribute to $ag_id for clarity | |
| 576 | + bbpress()->current_topic_tag_id = $tag_id = $attr['id']; | |
| 573 | 577 | |
| 574 | - // Start output buffer | |
| 575 | - $this->start( 'bbp_topic_tag' ); | |
| 578 | + // Output template | |
| 579 | + bbp_get_template_part( 'content', 'archive-topic' ); | |
| 576 | 580 | |
| 577 | - // Set passed attribute to $ag_id for clarity | |
| 578 | - bbpress()->current_topic_tag_id = $tag_id = $attr['id']; | |
| 581 | + // Return contents of output buffer | |
| 582 | + return $this->end(); | |
| 583 | + } | |
| 579 | 584 | |
| 580 | - // Output template | |
| 581 | - bbp_get_template_part( 'content', 'archive-topic' ); | |
| 585 | + /** | |
| 586 | + * Display the contents of a specific topic tag in an output buffer | |
| 587 | + * and return to ensure that post/page contents are displayed first. | |
| 588 | + * | |
| 589 | + * @since 2.0.0 bbPress (r3348) | |
| 590 | + * | |
| 591 | + * @return string | |
| 592 | + */ | |
| 593 | + public function display_topic_tag_form() { | |
| 582 | 594 | |
| 583 | - // Return contents of output buffer | |
| 584 | - return $this->end(); | |
| 585 | - } | |
| 595 | + // Unset globals | |
| 596 | + $this->unset_globals(); | |
| 586 | 597 | |
| 587 | - /** | |
| 588 | - * Display the contents of a specific topic tag in an output buffer | |
| 589 | - * and return to ensure that post/page contents are displayed first. | |
| 590 | - * | |
| 591 | - * @since 2.0.0 bbPress (r3348) | |
| 592 | - * | |
| 593 | - * @return string | |
| 594 | - */ | |
| 595 | - public function display_topic_tag_form() { | |
| 598 | + // Start output buffer | |
| 599 | + $this->start( 'bbp_topic_tag_edit' ); | |
| 596 | 600 | |
| 597 | - // Unset globals | |
| 598 | - $this->unset_globals(); | |
| 601 | + // Output template | |
| 602 | + bbp_get_template_part( 'content', 'topic-tag-edit' ); | |
| 599 | 603 | |
| 600 | - // Start output buffer | |
| 601 | - $this->start( 'bbp_topic_tag_edit' ); | |
| 604 | + // Return contents of output buffer | |
| 605 | + return $this->end(); | |
| 606 | + } | |
| 602 | 607 | |
| 603 | - // Output template | |
| 604 | - bbp_get_template_part( 'content', 'topic-tag-edit' ); | |
| 608 | + /** Views *****************************************************************/ | |
| 605 | 609 | |
| 606 | - // Return contents of output buffer | |
| 607 | - return $this->end(); | |
| 608 | - } | |
| 610 | + /** | |
| 611 | + * Display the contents of a specific view in an output buffer and return to | |
| 612 | + * ensure that post/page contents are displayed first. | |
| 613 | + * | |
| 614 | + * @since 2.0.0 bbPress (r3167) | |
| 615 | + * | |
| 616 | + * @param array $attr | |
| 617 | + * @param string $content | |
| 618 | + * @return string | |
| 619 | + */ | |
| 620 | + public function display_view( $attr, $content = '' ) { | |
| 609 | 621 | |
| 610 | - /** Views *****************************************************************/ | |
| 622 | + // Sanity check required info | |
| 623 | + if ( empty( $attr['id'] ) ) { | |
| 624 | + return $content; | |
| 625 | + } | |
| 611 | 626 | |
| 612 | - /** | |
| 613 | - * Display the contents of a specific view in an output buffer and return to | |
| 614 | - * ensure that post/page contents are displayed first. | |
| 615 | - * | |
| 616 | - * @since 2.0.0 bbPress (r3167) | |
| 617 | - * | |
| 618 | - * @param array $attr | |
| 619 | - * @param string $content | |
| 620 | - * @return string | |
| 621 | - */ | |
| 622 | - public function display_view( $attr, $content = '' ) { | |
| 627 | + // Set passed attribute to $view_id for clarity | |
| 628 | + $view_id = $attr['id']; | |
| 623 | 629 | |
| 624 | - // Sanity check required info | |
| 625 | - if ( empty( $attr['id'] ) ) { | |
| 626 | - return $content; | |
| 627 | - } | |
| 630 | + // Start output buffer | |
| 631 | + $this->start( 'bbp_single_view' ); | |
| 628 | 632 | |
| 629 | - // Set passed attribute to $view_id for clarity | |
| 630 | - $view_id = $attr['id']; | |
| 633 | + // Unset globals | |
| 634 | + $this->unset_globals(); | |
| 631 | 635 | |
| 632 | - // Start output buffer | |
| 633 | - $this->start( 'bbp_single_view' ); | |
| 636 | + // Set the current view ID | |
| 637 | + bbpress()->current_view_id = $view_id; | |
| 634 | 638 | |
| 635 | - // Unset globals | |
| 636 | - $this->unset_globals(); | |
| 639 | + // Load the view | |
| 640 | + bbp_view_query( $view_id ); | |
| 637 | 641 | |
| 638 | - // Set the current view ID | |
| 639 | - bbpress()->current_view_id = $view_id; | |
| 642 | + // Output template | |
| 643 | + bbp_get_template_part( 'content', 'single-view' ); | |
| 640 | 644 | |
| 641 | - // Load the view | |
| 642 | - bbp_view_query( $view_id ); | |
| 645 | + // Return contents of output buffer | |
| 646 | + return $this->end(); | |
| 647 | + } | |
| 643 | 648 | |
| 644 | - // Output template | |
| 645 | - bbp_get_template_part( 'content', 'single-view' ); | |
| 649 | + /** Search ****************************************************************/ | |
| 646 | 650 | |
| 647 | - // Return contents of output buffer | |
| 648 | - return $this->end(); | |
| 649 | - } | |
| 651 | + /** | |
| 652 | + * Display the search form in an output buffer and return to ensure | |
| 653 | + * post/page contents are displayed first. | |
| 654 | + * | |
| 655 | + * @since 2.3.0 bbPress (r4586) | |
| 656 | + */ | |
| 657 | + public function display_search_form() { | |
| 650 | 658 | |
| 651 | - /** Search ****************************************************************/ | |
| 659 | + // Bail if search is disabled | |
| 660 | + if ( ! bbp_allow_search() ) { | |
| 661 | + return; | |
| 662 | + } | |
| 652 | 663 | |
| 653 | - /** | |
| 654 | - * Display the search form in an output buffer and return to ensure | |
| 655 | - * post/page contents are displayed first. | |
| 656 | - * | |
| 657 | - * @since 2.3.0 bbPress (r4586) | |
| 658 | - */ | |
| 659 | - public function display_search_form() { | |
| 664 | + // Start output buffer | |
| 665 | + $this->start( 'bbp_search_form' ); | |
| 660 | 666 | |
| 661 | - // Bail if search is disabled | |
| 662 | - if ( ! bbp_allow_search() ) { | |
| 663 | - return; | |
| 664 | - } | |
| 667 | + // Output templates | |
| 668 | + bbp_get_template_part( 'form', 'search' ); | |
| 665 | 669 | |
| 666 | - // Start output buffer | |
| 667 | - $this->start( 'bbp_search_form' ); | |
| 670 | + // Return contents of output buffer | |
| 671 | + return $this->end(); | |
| 672 | + } | |
| 668 | 673 | |
| 669 | - // Output templates | |
| 670 | - bbp_get_template_part( 'form', 'search' ); | |
| 674 | + /** | |
| 675 | + * Display the contents of search results in an output buffer and return to | |
| 676 | + * ensure that post/page contents are displayed first. | |
| 677 | + * | |
| 678 | + * @since 2.3.0 bbPress (r4579) | |
| 679 | + * | |
| 680 | + * @param array $attr | |
| 681 | + * @param string $content | |
| 682 | + */ | |
| 683 | + public function display_search( $attr, $content = '' ) { | |
| 671 | 684 | |
| 672 | - // Return contents of output buffer | |
| 673 | - return $this->end(); | |
| 674 | - } | |
| 685 | + // Sanity check required info | |
| 686 | + if ( ! empty( $content ) ) { | |
| 687 | + return $content; | |
| 688 | + } | |
| 675 | 689 | |
| 676 | - /** | |
| 677 | - * Display the contents of search results in an output buffer and return to | |
| 678 | - * ensure that post/page contents are displayed first. | |
| 679 | - * | |
| 680 | - * @since 2.3.0 bbPress (r4579) | |
| 681 | - * | |
| 682 | - * @param array $attr | |
| 683 | - * @param string $content | |
| 684 | - */ | |
| 685 | - public function display_search( $attr, $content = '' ) { | |
| 690 | + // Bail if search is disabled | |
| 691 | + if ( ! bbp_allow_search() ) { | |
| 692 | + return; | |
| 693 | + } | |
| 686 | 694 | |
| 687 | - // Sanity check required info | |
| 688 | - if ( ! empty( $content ) ) { | |
| 689 | - return $content; | |
| 690 | - } | |
| 695 | + // Trim search attribute if it's set | |
| 696 | + if ( isset( $attr['search'] ) ) { | |
| 697 | + $attr['search'] = trim( $attr['search'] ); | |
| 698 | + } | |
| 691 | 699 | |
| 692 | - // Bail if search is disabled | |
| 693 | - if ( ! bbp_allow_search() ) { | |
| 694 | - return; | |
| 695 | - } | |
| 696 | - | |
| 697 | - // Trim search attribute if it's set | |
| 698 | - if ( isset( $attr['search'] ) ) { | |
| 699 | - $attr['search'] = trim( $attr['search'] ); | |
| 700 | - } | |
| 701 | - | |
| 702 | - // Set passed attribute to $search_terms for clarity | |
| 703 | - $search_terms = empty( $attr['search'] ) | |
| 700 | + // Set passed attribute to $search_terms for clarity | |
| 701 | + $search_terms = empty( $attr['search'] ) | |
| 704 | 702 | ? bbp_get_search_terms() |
| 705 | 703 | : $attr['search']; |
| 706 | 704 | |
| 707 | - // Get the rewrite ID (one time, to avoid repeated calls) | |
| 708 | - $rewrite_id = bbp_get_search_rewrite_id(); | |
| 705 | + // Get the rewrite ID (one time, to avoid repeated calls) | |
| 706 | + $rewrite_id = bbp_get_search_rewrite_id(); | |
| 709 | 707 | |
| 710 | - // Unset globals | |
| 711 | - $this->unset_globals(); | |
| 708 | + // Unset globals | |
| 709 | + $this->unset_globals(); | |
| 712 | 710 | |
| 713 | - // Set terms for query | |
| 714 | - set_query_var( $rewrite_id, $search_terms ); | |
| 711 | + // Set terms for query | |
| 712 | + set_query_var( $rewrite_id, $search_terms ); | |
| 715 | 713 | |
| 716 | - // Start output buffer | |
| 717 | - $this->start( $rewrite_id ); | |
| 714 | + // Start output buffer | |
| 715 | + $this->start( $rewrite_id ); | |
| 718 | 716 | |
| 719 | - // Output template | |
| 720 | - bbp_get_template_part( 'content', 'search' ); | |
| 717 | + // Output template | |
| 718 | + bbp_get_template_part( 'content', 'search' ); | |
| 721 | 719 | |
| 722 | - // Return contents of output buffer | |
| 723 | - return $this->end(); | |
| 724 | - } | |
| 720 | + // Return contents of output buffer | |
| 721 | + return $this->end(); | |
| 722 | + } | |
| 725 | 723 | |
| 726 | - /** Account ***************************************************************/ | |
| 724 | + /** Account ***************************************************************/ | |
| 727 | 725 | |
| 728 | - /** | |
| 729 | - * Display a login form | |
| 730 | - * | |
| 731 | - * @since 2.0.0 bbPress (r3302) | |
| 732 | - * | |
| 733 | - * @return string | |
| 734 | - */ | |
| 735 | - public function display_login() { | |
| 726 | + /** | |
| 727 | + * Display a login form | |
| 728 | + * | |
| 729 | + * @since 2.0.0 bbPress (r3302) | |
| 730 | + * | |
| 731 | + * @return string | |
| 732 | + */ | |
| 733 | + public function display_login() { | |
| 736 | 734 | |
| 737 | - // Unset globals | |
| 738 | - $this->unset_globals(); | |
| 735 | + // Unset globals | |
| 736 | + $this->unset_globals(); | |
| 739 | 737 | |
| 740 | - // Start output buffer | |
| 741 | - $this->start( 'bbp_login' ); | |
| 738 | + // Start output buffer | |
| 739 | + $this->start( 'bbp_login' ); | |
| 742 | 740 | |
| 743 | - // Output templates | |
| 744 | - if ( ! is_user_logged_in() ) { | |
| 745 | - bbp_get_template_part( 'form', 'user-login' ); | |
| 746 | - } else { | |
| 747 | - bbp_get_template_part( 'feedback', 'logged-in' ); | |
| 748 | - } | |
| 741 | + // Output templates | |
| 742 | + if ( ! is_user_logged_in() ) { | |
| 743 | + bbp_get_template_part( 'form', 'user-login' ); | |
| 744 | + } else { | |
| 745 | + bbp_get_template_part( 'feedback', 'logged-in' ); | |
| 746 | + } | |
| 749 | 747 | |
| 750 | - // Return contents of output buffer | |
| 751 | - return $this->end(); | |
| 752 | - } | |
| 748 | + // Return contents of output buffer | |
| 749 | + return $this->end(); | |
| 750 | + } | |
| 753 | 751 | |
| 754 | - /** | |
| 755 | - * Display a register form | |
| 756 | - * | |
| 757 | - * @since 2.0.0 bbPress (r3302) | |
| 758 | - * | |
| 759 | - * @return string | |
| 760 | - */ | |
| 761 | - public function display_register() { | |
| 752 | + /** | |
| 753 | + * Display a register form | |
| 754 | + * | |
| 755 | + * @since 2.0.0 bbPress (r3302) | |
| 756 | + * | |
| 757 | + * @return string | |
| 758 | + */ | |
| 759 | + public function display_register() { | |
| 762 | 760 | |
| 763 | - // Unset globals | |
| 764 | - $this->unset_globals(); | |
| 761 | + // Unset globals | |
| 762 | + $this->unset_globals(); | |
| 765 | 763 | |
| 766 | - // Start output buffer | |
| 767 | - $this->start( 'bbp_register' ); | |
| 764 | + // Start output buffer | |
| 765 | + $this->start( 'bbp_register' ); | |
| 768 | 766 | |
| 769 | - // Output templates | |
| 770 | - if ( ! is_user_logged_in() ) { | |
| 771 | - bbp_get_template_part( 'form', 'user-register' ); | |
| 772 | - } else { | |
| 773 | - bbp_get_template_part( 'feedback', 'logged-in' ); | |
| 774 | - } | |
| 767 | + // Output templates | |
| 768 | + if ( ! is_user_logged_in() ) { | |
| 769 | + bbp_get_template_part( 'form', 'user-register' ); | |
| 770 | + } else { | |
| 771 | + bbp_get_template_part( 'feedback', 'logged-in' ); | |
| 772 | + } | |
| 775 | 773 | |
| 776 | - // Return contents of output buffer | |
| 777 | - return $this->end(); | |
| 778 | - } | |
| 774 | + // Return contents of output buffer | |
| 775 | + return $this->end(); | |
| 776 | + } | |
| 779 | 777 | |
| 780 | - /** | |
| 781 | - * Display a lost password form | |
| 782 | - * | |
| 783 | - * @since 2.0.0 bbPress (r3302) | |
| 784 | - * | |
| 785 | - * @return string | |
| 786 | - */ | |
| 787 | - public function display_lost_pass() { | |
| 778 | + /** | |
| 779 | + * Display a lost password form | |
| 780 | + * | |
| 781 | + * @since 2.0.0 bbPress (r3302) | |
| 782 | + * | |
| 783 | + * @return string | |
| 784 | + */ | |
| 785 | + public function display_lost_pass() { | |
| 788 | 786 | |
| 789 | - // Unset globals | |
| 790 | - $this->unset_globals(); | |
| 787 | + // Unset globals | |
| 788 | + $this->unset_globals(); | |
| 791 | 789 | |
| 792 | - // Start output buffer | |
| 793 | - $this->start( 'bbp_lost_pass' ); | |
| 790 | + // Start output buffer | |
| 791 | + $this->start( 'bbp_lost_pass' ); | |
| 794 | 792 | |
| 795 | - // Output templates | |
| 796 | - if ( ! is_user_logged_in() ) { | |
| 797 | - bbp_get_template_part( 'form', 'user-lost-pass' ); | |
| 798 | - } else { | |
| 799 | - bbp_get_template_part( 'feedback', 'logged-in' ); | |
| 800 | - } | |
| 793 | + // Output templates | |
| 794 | + if ( ! is_user_logged_in() ) { | |
| 795 | + bbp_get_template_part( 'form', 'user-lost-pass' ); | |
| 796 | + } else { | |
| 797 | + bbp_get_template_part( 'feedback', 'logged-in' ); | |
| 798 | + } | |
| 801 | 799 | |
| 802 | - // Return contents of output buffer | |
| 803 | - return $this->end(); | |
| 804 | - } | |
| 800 | + // Return contents of output buffer | |
| 801 | + return $this->end(); | |
| 802 | + } | |
| 805 | 803 | |
| 806 | - /** Other *****************************************************************/ | |
| 804 | + /** Other *****************************************************************/ | |
| 807 | 805 | |
| 808 | - /** | |
| 809 | - * Display forum statistics | |
| 810 | - * | |
| 811 | - * @since 2.3.0 bbPress (r4510) | |
| 812 | - * | |
| 813 | - * @return string | |
| 814 | - */ | |
| 815 | - public function display_stats() { | |
| 806 | + /** | |
| 807 | + * Display forum statistics | |
| 808 | + * | |
| 809 | + * @since 2.3.0 bbPress (r4510) | |
| 810 | + * | |
| 811 | + * @return string | |
| 812 | + */ | |
| 813 | + public function display_stats() { | |
| 816 | 814 | |
| 817 | - // Unset globals | |
| 818 | - $this->unset_globals(); | |
| 815 | + // Unset globals | |
| 816 | + $this->unset_globals(); | |
| 819 | 817 | |
| 820 | - // Start output buffer | |
| 821 | - $this->start(); | |
| 818 | + // Start output buffer | |
| 819 | + $this->start(); | |
| 822 | 820 | |
| 823 | - // Output statistics | |
| 824 | - bbp_get_template_part( 'content', 'statistics' ); | |
| 821 | + // Output statistics | |
| 822 | + bbp_get_template_part( 'content', 'statistics' ); | |
| 825 | 823 | |
| 826 | - // Return contents of output buffer | |
| 827 | - return $this->end(); | |
| 828 | - } | |
| 824 | + // Return contents of output buffer | |
| 825 | + return $this->end(); | |
| 826 | + } | |
| 829 | 827 | |
| 830 | - /** | |
| 831 | - * Display a breadcrumb | |
| 832 | - * | |
| 833 | - * @since 2.0.0 bbPress (r3302) | |
| 834 | - * | |
| 835 | - * @return string | |
| 836 | - */ | |
| 837 | - public function display_breadcrumb() { | |
| 828 | + /** | |
| 829 | + * Display a breadcrumb | |
| 830 | + * | |
| 831 | + * @since 2.0.0 bbPress (r3302) | |
| 832 | + * | |
| 833 | + * @return string | |
| 834 | + */ | |
| 835 | + public function display_breadcrumb() { | |
| 838 | 836 | |
| 839 | - // Unset globals | |
| 840 | - $this->unset_globals(); | |
| 837 | + // Unset globals | |
| 838 | + $this->unset_globals(); | |
| 841 | 839 | |
| 842 | - // Start output buffer | |
| 843 | - $this->start(); | |
| 840 | + // Start output buffer | |
| 841 | + $this->start(); | |
| 844 | 842 | |
| 845 | - // Output breadcrumb | |
| 846 | - bbp_breadcrumb(); | |
| 843 | + // Output breadcrumb | |
| 844 | + bbp_breadcrumb(); | |
| 847 | 845 | |
| 848 | - // Return contents of output buffer | |
| 849 | - return $this->end(); | |
| 850 | - } | |
| 846 | + // Return contents of output buffer | |
| 847 | + return $this->end(); | |
| 848 | + } | |
| 851 | 849 | |
| 852 | - /** Query Filters *********************************************************/ | |
| 850 | + /** Query Filters *********************************************************/ | |
| 853 | 851 | |
| 854 | - /** | |
| 855 | - * Filter the query for the topic index | |
| 856 | - * | |
| 857 | - * @since 2.1.0 bbPress (r3637) | |
| 858 | - * | |
| 859 | - * @param array $args | |
| 860 | - * @return array | |
| 861 | - */ | |
| 862 | - public function display_topic_index_query( $args = array() ) { | |
| 863 | - $args['author'] = 0; | |
| 864 | - $args['show_stickies'] = true; | |
| 865 | - $args['order'] = 'DESC'; | |
| 866 | - return $args; | |
| 867 | - } | |
| 852 | + /** | |
| 853 | + * Filter the query for the topic index | |
| 854 | + * | |
| 855 | + * @since 2.1.0 bbPress (r3637) | |
| 856 | + * | |
| 857 | + * @param array $args | |
| 858 | + * @return array | |
| 859 | + */ | |
| 860 | + public function display_topic_index_query( $args = array() ) { | |
| 861 | + $args['author'] = 0; | |
| 862 | + $args['show_stickies'] = true; | |
| 863 | + $args['order'] = 'DESC'; | |
| 864 | + return $args; | |
| 865 | + } | |
| 868 | 866 | |
| 869 | - /** | |
| 870 | - * Filter the query for topic tags | |
| 871 | - * | |
| 872 | - * @since 2.1.0 bbPress (r3637) | |
| 873 | - * | |
| 874 | - * @param array $args | |
| 875 | - * @return array | |
| 876 | - */ | |
| 877 | - public function display_topics_of_tag_query( $args = array() ) { | |
| 878 | - $args['tax_query'] = array( | |
| 879 | - array( | |
| 880 | - 'taxonomy' => bbp_get_topic_tag_tax_id(), | |
| 881 | - 'field' => 'id', | |
| 882 | - 'terms' => bbpress()->current_topic_tag_id | |
| 883 | - ) | |
| 884 | - ); | |
| 867 | + /** | |
| 868 | + * Filter the query for topic tags | |
| 869 | + * | |
| 870 | + * @since 2.1.0 bbPress (r3637) | |
| 871 | + * | |
| 872 | + * @param array $args | |
| 873 | + * @return array | |
| 874 | + */ | |
| 875 | + public function display_topics_of_tag_query( $args = array() ) { | |
| 876 | + $args['tax_query'] = array( | |
| 877 | + array( | |
| 878 | + 'taxonomy' => bbp_get_topic_tag_tax_id(), | |
| 879 | + 'field' => 'id', | |
| 880 | + 'terms' => bbpress()->current_topic_tag_id | |
| 881 | + ) | |
| 882 | + ); | |
| 885 | 883 | |
| 886 | - return $args; | |
| 887 | - } | |
| 884 | + return $args; | |
| 885 | + } | |
| 888 | 886 | } |
| 889 | 887 | endif; |