[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-groups/classes/ -> class-bp-groups-theme-compat.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Groups Theme Compat.
   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 Groups.
  14   *
  15   * This class sets up the necessary theme compatibility actions to safely output
  16   * group template parts to the_title and the_content areas of a theme.
  17   *
  18   * @since 1.7.0
  19   */
  20  class BP_Groups_Theme_Compat {
  21  
  22      /**
  23       * Set up theme compatibility for the Groups component.
  24       *
  25       * @since 1.7.0
  26       */
  27  	public function __construct() {
  28          add_action( 'bp_setup_theme_compat', array( $this, 'is_group' ) );
  29      }
  30  
  31      /**
  32       * Are we looking at something that needs group theme compatibility?
  33       *
  34       * @since 1.7.0
  35       */
  36  	public function is_group() {
  37  
  38          // Bail if not looking at a group.
  39          if ( ! bp_is_groups_component() )
  40              return;
  41  
  42          // Group Directory.
  43          if ( bp_is_groups_directory() ) {
  44              bp_update_is_directory( true, 'groups' );
  45  
  46              /**
  47               * Fires at the start of the group theme compatibility setup.
  48               *
  49               * @since 1.1.0
  50               */
  51              do_action( 'groups_directory_groups_setup' );
  52  
  53              add_filter( 'bp_get_buddypress_template',                array( $this, 'directory_template_hierarchy' ) );
  54              add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'directory_dummy_post' ) );
  55              add_filter( 'bp_replace_the_content',                    array( $this, 'directory_content'    ) );
  56  
  57          // Creating a group.
  58          } elseif ( bp_is_groups_component() && bp_is_current_action( 'create' ) ) {
  59              add_filter( 'bp_get_buddypress_template',                array( $this, 'create_template_hierarchy' ) );
  60              add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'create_dummy_post' ) );
  61              add_filter( 'bp_replace_the_content',                    array( $this, 'create_content'    ) );
  62  
  63          // Group page.
  64          } elseif ( bp_is_single_item() ) {
  65              add_filter( 'bp_get_buddypress_template',                array( $this, 'single_template_hierarchy' ) );
  66              add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'single_dummy_post' ) );
  67              add_filter( 'bp_replace_the_content',                    array( $this, 'single_content'    ) );
  68  
  69          }
  70      }
  71  
  72      /** Directory *********************************************************/
  73  
  74      /**
  75       * Add template hierarchy to theme compat for the group directory page.
  76       *
  77       * This is to mirror how WordPress has
  78       * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
  79       *
  80       * @since 1.8.0
  81       *
  82       * @param string $templates The templates from bp_get_theme_compat_templates().
  83       * @return array $templates Array of custom templates to look for.
  84       */
  85  	public function directory_template_hierarchy( $templates ) {
  86          // Set up the template hierarchy.
  87          $new_templates = array();
  88          if ( '' !== bp_get_current_group_directory_type() ) {
  89              $new_templates[] = 'groups/index-directory-type-' . sanitize_file_name( bp_get_current_group_directory_type() ) . '.php';
  90          }
  91          $new_templates[] = 'groups/index-directory.php';
  92  
  93          /**
  94           * Filters the Groups directory page template hierarchy based on priority.
  95           *
  96           * @since 1.8.0
  97           *
  98           * @param array $value Array of default template files to use.
  99           */
 100          $new_templates = apply_filters( 'bp_template_hierarchy_groups_directory', $new_templates );
 101  
 102          // Merge new templates with existing stack.
 103          // @see bp_get_theme_compat_templates().
 104          $templates = array_merge( (array) $new_templates, $templates );
 105  
 106          return $templates;
 107      }
 108  
 109      /**
 110       * Update the global $post with directory data.
 111       *
 112       * @since 1.7.0
 113       */
 114  	public function directory_dummy_post() {
 115          bp_theme_compat_reset_post( array(
 116              'ID'             => 0,
 117              'post_title'     => bp_get_directory_title( 'groups' ),
 118              'post_author'    => 0,
 119              'post_date'      => 0,
 120              'post_content'   => '',
 121              'post_type'      => 'page',
 122              'post_status'    => 'publish',
 123              'is_page'        => true,
 124              'comment_status' => 'closed'
 125          ) );
 126      }
 127  
 128      /**
 129       * Filter the_content with the groups index template part.
 130       *
 131       * @since 1.7.0
 132       */
 133  	public function directory_content() {
 134          return bp_buffer_template_part( 'groups/index', null, false );
 135      }
 136  
 137      /** Create ************************************************************/
 138  
 139      /**
 140       * Add custom template hierarchy to theme compat for the group create page.
 141       *
 142       * This is to mirror how WordPress has
 143       * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
 144       *
 145       * @since 1.8.0
 146       *
 147       * @param string $templates The templates from bp_get_theme_compat_templates().
 148       * @return array $templates Array of custom templates to look for.
 149       */
 150  	public function create_template_hierarchy( $templates ) {
 151  
 152          /**
 153           * Filters the Groups create page template hierarchy based on priority.
 154           *
 155           * @since 1.8.0
 156           *
 157           * @param array $value Array of default template files to use.
 158           */
 159          $new_templates = apply_filters( 'bp_template_hierarchy_groups_create', array(
 160              'groups/index-create.php'
 161          ) );
 162  
 163          // Merge new templates with existing stack.
 164          // @see bp_get_theme_compat_templates().
 165          $templates = array_merge( $new_templates, $templates );
 166  
 167          return $templates;
 168      }
 169  
 170      /**
 171       * Update the global $post with create screen data.
 172       *
 173       * @since 1.7.0
 174       */
 175  	public function create_dummy_post() {
 176  
 177          $title = _x( 'Groups', 'Group creation page', 'buddypress' );
 178  
 179          bp_theme_compat_reset_post( array(
 180              'ID'             => 0,
 181              'post_title'     => $title,
 182              'post_author'    => 0,
 183              'post_date'      => 0,
 184              'post_content'   => '',
 185              'post_type'      => 'page',
 186              'post_status'    => 'publish',
 187              'is_page'        => true,
 188              'comment_status' => 'closed'
 189          ) );
 190      }
 191  
 192      /**
 193       * Filter the_content with the create screen template part.
 194       *
 195       * @since 1.7.0
 196       */
 197  	public function create_content() {
 198          return bp_buffer_template_part( 'groups/create', null, false );
 199      }
 200  
 201      /** Single ************************************************************/
 202  
 203      /**
 204       * Add custom template hierarchy to theme compat for group pages.
 205       *
 206       * This is to mirror how WordPress has
 207       * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
 208       *
 209       * @since 1.8.0
 210       *
 211       * @param string $templates The templates from bp_get_theme_compat_templates().
 212       * @return array $templates Array of custom templates to look for.
 213       */
 214  	public function single_template_hierarchy( $templates ) {
 215          // Setup some variables we're going to reference in our custom templates.
 216          $group = groups_get_current_group();
 217  
 218          /**
 219           * Filters the Groups single pages template hierarchy based on priority.
 220           *
 221           * @since 1.8.0
 222           *
 223           * @param array $value Array of default template files to use.
 224           */
 225          $new_templates = apply_filters( 'bp_template_hierarchy_groups_single_item', array(
 226              'groups/single/index-id-'     . (int) bp_get_current_group_id()                   . '.php',
 227              'groups/single/index-slug-'   . sanitize_file_name( bp_get_current_group_slug() ) . '.php',
 228              'groups/single/index-action-' . sanitize_file_name( bp_current_action() )         . '.php',
 229              'groups/single/index-status-' . sanitize_file_name( $group->status )              . '.php',
 230              'groups/single/index.php'
 231          ) );
 232  
 233          // Merge new templates with existing stack.
 234          // @see bp_get_theme_compat_templates().
 235          $templates = array_merge( (array) $new_templates, $templates );
 236  
 237          return $templates;
 238      }
 239  
 240      /**
 241       * Update the global $post with single group data.
 242       *
 243       * @since 1.7.0
 244       */
 245  	public function single_dummy_post() {
 246          bp_theme_compat_reset_post( array(
 247              'ID'             => 0,
 248              'post_title'     => bp_get_current_group_name(),
 249              'post_author'    => 0,
 250              'post_date'      => 0,
 251              'post_content'   => '',
 252              'post_type'      => 'page',
 253              'post_status'    => 'publish',
 254              'is_page'        => true,
 255              'comment_status' => 'closed'
 256          ) );
 257      }
 258  
 259      /**
 260       * Filter the_content with the single group template part.
 261       *
 262       * @since 1.7.0
 263       */
 264  	public function single_content() {
 265          return bp_buffer_template_part( 'groups/single/home', null, false );
 266      }
 267  }


Generated: Thu Nov 21 01:00:57 2024 Cross-referenced by PHPXref 0.7.1