BP_Activity_Theme_Compat
The main theme compat class for BuddyBoss Activity.
Description
This class sets up the necessary theme compatibility actions to safely output activity template parts to the_title and the_content areas of a theme.
Source
File: bp-activity/classes/class-bp-activity-theme-compat.php
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | class BP_Activity_Theme_Compat { /** * Set up the activity component theme compatibility. * * @since BuddyPress 1.7.0 */ public function __construct() { add_action( 'bp_setup_theme_compat' , array ( $this , 'is_activity' ) ); } /** * Set up the theme compatibility hooks, if we're looking at an activity page. * * @since BuddyPress 1.7.0 */ public function is_activity() { // Bail if not looking at a group. if ( ! bp_is_activity_component() ) return ; // Activity Directory. if ( ! bp_displayed_user_id() && ! bp_current_action() ) { bp_update_is_directory( true, 'activity' ); /** This action is documented in bp-activity/bp-activity-screens.php */ do_action( 'bp_activity_screen_index' ); add_filter( 'bp_get_buddypress_template' , array ( $this , 'directory_template_hierarchy' ) ); add_action( 'bp_template_include_reset_dummy_post_data' , array ( $this , 'directory_dummy_post' ) ); add_filter( 'bp_replace_the_content' , array ( $this , 'directory_content' ) ); // Single activity. } elseif ( bp_is_single_activity() ) { add_filter( 'bp_get_buddypress_template' , array ( $this , 'single_template_hierarchy' ) ); add_action( 'bp_template_include_reset_dummy_post_data' , array ( $this , 'single_dummy_post' ) ); add_filter( 'bp_replace_the_content' , array ( $this , 'single_dummy_content' ) ); } } /** Directory *************************************************************/ /** * Add template hierarchy to theme compat for the activity directory page. * * This is to mirror how WordPress has {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}. * * @since BuddyPress 1.8.0 * * @param string $templates The templates from bp_get_theme_compat_templates(). * @return array $templates Array of custom templates to look for. */ public function directory_template_hierarchy( $templates ) { /** * Filters the template hierarchy for the activity directory page. * * @since BuddyPress 1.8.0 * * @param array $index-directory Array holding template names to be merged into template list. */ $new_templates = apply_filters( 'bp_template_hierarchy_activity_directory' , array ( 'activity/index-directory.php' ) ); // Merge new templates with existing stack // @see bp_get_theme_compat_templates(). $templates = array_merge ( ( array ) $new_templates , $templates ); return $templates ; } /** * Update the global $post with directory data. * * @since BuddyPress 1.7.0 */ public function directory_dummy_post() { bp_theme_compat_reset_post( array ( 'ID' => 0, 'post_title' => bp_get_directory_title( 'activity' ), 'post_author' => 0, 'post_date' => 0, 'post_content' => '' , 'post_type' => 'page' , 'post_status' => 'publish' , 'is_page' => true, 'comment_status' => 'closed' ) ); } /** * Filter the_content with the groups index template part. * * @since BuddyPress 1.7.0 */ public function directory_content() { return bp_buffer_template_part( 'activity/index' , null, false ); } /** Single ****************************************************************/ /** * Add custom template hierarchy to theme compat for activity permalink pages. * * This is to mirror how WordPress has {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}. * * @since BuddyPress 1.8.0 * * @param string $templates The templates from bp_get_theme_compat_templates(). * @return array $templates Array of custom templates to look for. */ public function single_template_hierarchy( $templates ) { /** * Filters the template hierarchy for the activity permalink pages. * * @since BuddyPress 1.8.0 * * @param array $index Array holding template names to be merged into template list. */ $new_templates = apply_filters( 'bp_template_hierarchy_activity_single_item' , array ( 'activity/single/index.php' ) ); // Merge new templates with existing stack // @see bp_get_theme_compat_templates(). $templates = array_merge ( ( array ) $new_templates , $templates ); return $templates ; } /** * Update the global $post with the displayed user's data. * * @since BuddyPress 1.7.0 */ public function single_dummy_post() { bp_theme_compat_reset_post( array ( 'ID' => 0, 'post_title' => __( 'News Feed' , 'buddyboss' ), 'post_author' => 0, 'post_date' => 0, 'post_content' => '' , 'post_type' => 'page' , 'post_status' => 'publish' , 'is_page' => true, 'comment_status' => 'closed' ) ); } /** * Filter the_content with the members' activity permalink template part. * * @since BuddyPress 1.7.0 */ public function single_dummy_content() { return bp_buffer_template_part( 'activity/single/home' , null, false ); } } |
Changelog
Version | Description |
---|---|
BuddyPress 1.7.0 | Introduced. |
Methods
- __construct — Set up the activity component theme compatibility.
- directory_content — Filter the_content with the groups index template part.
- directory_dummy_post — Update the global $post with directory data.
- directory_template_hierarchy — Add template hierarchy to theme compat for the activity directory page.
- is_activity — Set up the theme compatibility hooks, if we're looking at an activity page.
- single_dummy_content — Filter the_content with the members' activity permalink template part.
- single_dummy_post — Update the global $post with the displayed user's data.
- single_template_hierarchy — Add custom template hierarchy to theme compat for activity permalink pages.
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.