bbp_theme_compat_reset_post

This fun little function fills up some WordPress globals with dummy data to stop your average page template from complaining about it missing.

Description

bbp_theme_compat_reset_post( (array) $args = array() ); 

Parameters (1)

0. $args — Optional. (array) => array()
The args.

Usage

  1. if ( !function_exists( 'bbp_theme_compat_reset_post' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/core/theme-compat.php'; 
  3.  
  4. // The args. 
  5. $args = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bbp_theme_compat_reset_post($args); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/core/theme-compat.php  
  1. function bbp_theme_compat_reset_post( $args = array() ) { 
  2. global $wp_query, $post; 
  3.  
  4. // Switch defaults if post is set 
  5. if ( isset( $wp_query->post ) ) { 
  6. $dummy = bbp_parse_args( $args, array( 
  7. 'ID' => $wp_query->post->ID,  
  8. 'post_status' => $wp_query->post->post_status,  
  9. 'post_author' => $wp_query->post->post_author,  
  10. 'post_parent' => $wp_query->post->post_parent,  
  11. 'post_type' => $wp_query->post->post_type,  
  12. 'post_date' => $wp_query->post->post_date,  
  13. 'post_date_gmt' => $wp_query->post->post_date_gmt,  
  14. 'post_modified' => $wp_query->post->post_modified,  
  15. 'post_modified_gmt' => $wp_query->post->post_modified_gmt,  
  16. 'post_content' => $wp_query->post->post_content,  
  17. 'post_title' => $wp_query->post->post_title,  
  18. 'post_excerpt' => $wp_query->post->post_excerpt,  
  19. 'post_content_filtered' => $wp_query->post->post_content_filtered,  
  20. 'post_mime_type' => $wp_query->post->post_mime_type,  
  21. 'post_password' => $wp_query->post->post_password,  
  22. 'post_name' => $wp_query->post->post_name,  
  23. 'guid' => $wp_query->post->guid,  
  24. 'menu_order' => $wp_query->post->menu_order,  
  25. 'pinged' => $wp_query->post->pinged,  
  26. 'to_ping' => $wp_query->post->to_ping,  
  27. 'ping_status' => $wp_query->post->ping_status,  
  28. 'comment_status' => $wp_query->post->comment_status,  
  29. 'comment_count' => $wp_query->post->comment_count,  
  30. 'filter' => $wp_query->post->filter,  
  31.  
  32. 'is_404' => false,  
  33. 'is_page' => false,  
  34. 'is_single' => false,  
  35. 'is_archive' => false,  
  36. 'is_tax' => false,  
  37. ), 'theme_compat_reset_post' ); 
  38. } else { 
  39. $dummy = bbp_parse_args( $args, array( 
  40. 'ID' => -9999,  
  41. 'post_status' => bbp_get_public_status_id(),  
  42. 'post_author' => 0,  
  43. 'post_parent' => 0,  
  44. 'post_type' => 'page',  
  45. 'post_date' => 0,  
  46. 'post_date_gmt' => 0,  
  47. 'post_modified' => 0,  
  48. 'post_modified_gmt' => 0,  
  49. 'post_content' => '',  
  50. 'post_title' => '',  
  51. 'post_excerpt' => '',  
  52. 'post_content_filtered' => '',  
  53. 'post_mime_type' => '',  
  54. 'post_password' => '',  
  55. 'post_name' => '',  
  56. 'guid' => '',  
  57. 'menu_order' => 0,  
  58. 'pinged' => '',  
  59. 'to_ping' => '',  
  60. 'ping_status' => '',  
  61. 'comment_status' => 'closed',  
  62. 'comment_count' => 0,  
  63. 'filter' => 'raw',  
  64.  
  65. 'is_404' => false,  
  66. 'is_page' => false,  
  67. 'is_single' => false,  
  68. 'is_archive' => false,  
  69. 'is_tax' => false,  
  70. ), 'theme_compat_reset_post' ); 
  71.  
  72. // Bail if dummy post is empty 
  73. if ( empty( $dummy ) ) { 
  74. return; 
  75.  
  76. // Set the $post global 
  77. $post = new WP_Post( (object) $dummy ); 
  78.  
  79. // Copy the new post global into the main $wp_query 
  80. $wp_query->post = $post; 
  81. $wp_query->posts = array( $post ); 
  82.  
  83. // Prevent comments form from appearing 
  84. $wp_query->post_count = 1; 
  85. $wp_query->is_404 = $dummy['is_404']; 
  86. $wp_query->is_page = $dummy['is_page']; 
  87. $wp_query->is_single = $dummy['is_single']; 
  88. $wp_query->is_archive = $dummy['is_archive']; 
  89. $wp_query->is_tax = $dummy['is_tax']; 
  90.  
  91. // Clean up the dummy post 
  92. unset( $dummy ); 
  93.  
  94. /** 
  95. * Force the header back to 200 status if not a deliberate 404 
  96. * @see http://bbpress.trac.wordpress.org/ticket/1973 
  97. */ 
  98. if ( ! $wp_query->is_404() ) { 
  99. status_header( 200 ); 
  100.  
  101. // If we are resetting a post, we are in theme compat