bp_docs->slug ) ) { $is_docs = true; } // Bail if not looking at the docs component if ( ! $is_docs ) { return; } add_filter( 'bp_get_template_stack', array( $this, 'add_plugin_templates_to_stack' ) ); add_filter( 'bp_get_buddypress_template', array( $this, 'query_templates' ) ); add_filter( 'bp_use_theme_compat_with_current_theme', 'bp_docs_do_theme_compat' ); if ( bp_docs_is_global_directory() || bp_docs_is_mygroups_directory() ) { bp_update_is_directory( true, 'docs' ); do_action( 'bp_docs_screen_index' ); add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'directory_dummy_post' ) ); add_filter( 'bp_replace_the_content', array( $this, 'directory_content' ) ); } else if ( bp_docs_is_existing_doc() ) { if ( bp_docs_is_doc_history() ) { $this->single_content_template = 'docs/single/history'; add_filter( 'bp_force_comment_status', '__return_false' ); } else if ( bp_docs_is_doc_edit() ) { $this->single_content_template = 'docs/single/edit'; add_filter( 'bp_force_comment_status', '__return_false' ); } else { $this->single_content_template = 'docs/single/index'; add_filter( 'bp_docs_allow_comment_section', '__return_false' ); // Necessary as of BP 1.9.2 remove_action( 'bp_replace_the_content', 'bp_theme_compat_toggle_is_page', 9999 ); } add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'single_dummy_post' ) ); add_filter( 'bp_replace_the_content', array( $this, 'single_content' ) ); } else if ( bp_docs_is_doc_create() ) { add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'create_dummy_post' ) ); add_filter( 'bp_replace_the_content', array( $this, 'create_content' ) ); } } /** * Add the plugin's template location to the stack * * Docs provides its own templates for fallback support with any theme * * @since 1.3 */ function add_plugin_templates_to_stack( $stack ) { $stack[] = BP_DOCS_INCLUDES_PATH . 'templates'; return $stack; } /** * Add our custom top-level query template to the top of the query * template stack * * This ensures that users can provide a Docs-specific template at the * top-level of the rendering stack * * @since 1.3 */ function query_templates( $templates ) { $templates = array_merge( array( 'plugin-buddypress-docs.php' ), $templates ); return $templates; } /** Directory *************************************************************/ /** * Update the global $post with directory data * * @since 1.3 */ public function directory_dummy_post() { bp_theme_compat_reset_post( array( 'ID' => 0, 'post_title' => __( 'Docs Directory', 'bp-docs' ), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => bp_docs_get_post_type_name(), 'post_status' => 'publish', 'is_archive' => true, 'comment_status' => 'closed' ) ); } /** * Filter the_content with the docs index template part * * @since 1.3 */ public function directory_content() { bp_buffer_template_part( 'docs/docs-loop' ); } /** Single ****************************************************************/ /** * We're not setting a dummy post for our post type, but we do need to * activate theme compat * * @todo This seems very wrong. Figure it out * * @since 1.3 */ public function single_dummy_post() { bp_set_theme_compat_active(); } /** * Filter the_content with the single doc template part * * We return ' ' as a hack, to make sure that the_content doesn't * display extra crap at the end of our documents * * @since 1.3 */ public function single_content() { bp_buffer_template_part( $this->single_content_template ); return ' '; } /** Create ****************************************************************/ /** * Update the global $post with dummy data regarding doc creation * * @since 1.3 */ public function create_dummy_post() { bp_theme_compat_reset_post( array( 'ID' => 0, 'post_title' => __( 'Create a Doc', 'bp-docs' ), 'post_author' => get_current_user_id(), 'post_date' => 0, 'post_content' => '', 'post_type' => bp_docs_get_post_type_name(), 'post_status' => 'publish', 'is_archive' => true, 'comment_status' => 'closed' ) ); } /** * Filter the_content with the doc creation template part * * @since 1.3 */ public function create_content() { bp_buffer_template_part( 'docs/single/edit' ); } } new BP_Docs_Theme_Compat(); /** * Wrapper function for bp_is_theme_compat_active() * * Needed for backward compatibility with BP < 1.7 * * @since 1.3 * @return bool */ function bp_docs_is_theme_compat_active() { $is_active = false; if ( function_exists( 'bp_is_theme_compat_active' ) ) { $is_active = bp_is_theme_compat_active(); } return $is_active; }