bbp_theme_compat_reset_post( array $args = array() )
This fun little function fills up some WordPress globals with dummy data to stop your average page template from complaining about it missing.
Description
Parameters
- $args
-
(Optional)
Default value: array()
Source
File: bp-forums/core/theme-compat.php
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | function bbp_theme_compat_reset_post( $args = array () ) { global $wp_query , $post ; // Switch defaults if post is set if ( isset( $wp_query ->post ) ) { $dummy = bbp_parse_args( $args , array ( 'ID' => $wp_query ->post->ID, 'post_status' => $wp_query ->post->post_status, 'post_author' => $wp_query ->post->post_author, 'post_parent' => $wp_query ->post->post_parent, 'post_type' => $wp_query ->post->post_type, 'post_date' => $wp_query ->post->post_date, 'post_date_gmt' => $wp_query ->post->post_date_gmt, 'post_modified' => $wp_query ->post->post_modified, 'post_modified_gmt' => $wp_query ->post->post_modified_gmt, 'post_content' => $wp_query ->post->post_content, 'post_title' => $wp_query ->post->post_title, 'post_excerpt' => $wp_query ->post->post_excerpt, 'post_content_filtered' => $wp_query ->post->post_content_filtered, 'post_mime_type' => $wp_query ->post->post_mime_type, 'post_password' => $wp_query ->post->post_password, 'post_name' => $wp_query ->post->post_name, 'guid' => $wp_query ->post->guid, 'menu_order' => $wp_query ->post->menu_order, 'pinged' => $wp_query ->post->pinged, 'to_ping' => $wp_query ->post->to_ping, 'ping_status' => $wp_query ->post->ping_status, 'comment_status' => $wp_query ->post->comment_status, 'comment_count' => $wp_query ->post->comment_count, 'filter' => $wp_query ->post->filter, 'is_404' => false, 'is_page' => false, 'is_single' => false, 'is_archive' => false, 'is_tax' => false, ), 'theme_compat_reset_post' ); } else { $dummy = bbp_parse_args( $args , array ( 'ID' => -9999, 'post_status' => bbp_get_public_status_id(), 'post_author' => 0, 'post_parent' => 0, 'post_type' => 'page' , 'post_date' => 0, 'post_date_gmt' => 0, 'post_modified' => 0, 'post_modified_gmt' => 0, 'post_content' => '' , 'post_title' => '' , 'post_excerpt' => '' , 'post_content_filtered' => '' , 'post_mime_type' => '' , 'post_password' => '' , 'post_name' => '' , 'guid' => '' , 'menu_order' => 0, 'pinged' => '' , 'to_ping' => '' , 'ping_status' => '' , 'comment_status' => 'closed' , 'comment_count' => 0, 'filter' => 'raw' , 'is_404' => false, 'is_page' => false, 'is_single' => false, 'is_archive' => false, 'is_tax' => false, ), 'theme_compat_reset_post' ); } // Bail if dummy post is empty if ( empty ( $dummy ) ) { return ; } // Set the $post global $post = new WP_Post( (object) $dummy ); // Copy the new post global into the main $wp_query $wp_query ->post = $post ; $wp_query ->posts = array ( $post ); // Prevent comments form from appearing $wp_query ->post_count = 1; $wp_query ->is_404 = $dummy [ 'is_404' ]; $wp_query ->is_page = $dummy [ 'is_page' ]; $wp_query ->is_single = $dummy [ 'is_single' ]; $wp_query ->is_archive = $dummy [ 'is_archive' ]; $wp_query ->is_tax = $dummy [ 'is_tax' ]; // Clean up the dummy post unset( $dummy ); /** * Force the header back to 200 status if not a deliberate 404 * */ if ( ! $wp_query ->is_404() ) { status_header( 200 ); } // If we are resetting a post, we are in theme compat bbp_set_theme_compat_active( true ); } |
Changelog
Version | Description |
---|---|
bbPress (r3108) | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.