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