[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * BuddyPress Member Theme Compat.
   4   *
   5   * @package BuddyPress
   6   * @subpackage MembersScreens
   7   * @since 1.7.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * The main theme compat class for BuddyPress Members.
  15   *
  16   * This class sets up the necessary theme compatibility actions to safely output
  17   * member template parts to the_title and the_content areas of a theme.
  18   *
  19   * @since 1.7.0
  20   */
  21  class BP_Members_Theme_Compat {
  22  
  23      /**
  24       * Set up the members component theme compatibility.
  25       *
  26       * @since 1.7.0
  27       */
  28  	public function __construct() {
  29          add_action( 'bp_setup_theme_compat', array( $this, 'is_members' ) );
  30      }
  31  
  32      /**
  33       * Are we looking at something that needs members theme compatibility?
  34       *
  35       * @since 1.7.0
  36       */
  37  	public function is_members() {
  38  
  39          // Bail if not looking at the members component or a user's page.
  40          if ( ! bp_is_members_component() && ! bp_is_user() ) {
  41              return;
  42          }
  43  
  44          // User page.
  45          if ( bp_is_user() ) {
  46  
  47              // If we're on a single activity permalink page, we shouldn't use the members
  48              // template, so stop here!
  49              if ( bp_is_active( 'activity' ) && bp_is_single_activity() ) {
  50                  return;
  51              }
  52  
  53              /**
  54               * Fires if looking at Members user page when needing theme compat.
  55               *
  56               * @since 1.5.0
  57               */
  58              do_action( 'bp_members_screen_display_profile' );
  59  
  60              add_filter( 'bp_get_buddypress_template',                array( $this, 'single_template_hierarchy' ) );
  61              add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'single_dummy_post'    ) );
  62              add_filter( 'bp_replace_the_content',                    array( $this, 'single_dummy_content' ) );
  63  
  64          // Members Directory.
  65          } elseif ( ! bp_current_action() && ! bp_current_item() ) {
  66              bp_update_is_directory( true, 'members' );
  67  
  68              /**
  69               * Fires if looking at Members directory when needing theme compat.
  70               *
  71               * @since 1.5.0
  72               */
  73              do_action( 'bp_members_screen_index' );
  74  
  75              add_filter( 'bp_get_buddypress_template',                array( $this, 'directory_template_hierarchy' ) );
  76              add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'directory_dummy_post' ) );
  77              add_filter( 'bp_replace_the_content',                    array( $this, 'directory_content'    ) );
  78          }
  79      }
  80  
  81      /** Directory *************************************************************/
  82  
  83      /**
  84       * Add template hierarchy to theme compat for the members directory page.
  85       *
  86       * This is to mirror how WordPress has
  87       * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
  88       *
  89       * @since 1.8.0
  90       *
  91       * @param array $templates The templates from bp_get_theme_compat_templates().
  92       * @return array $templates Array of custom templates to look for.
  93       */
  94  	public function directory_template_hierarchy( $templates = array() ) {
  95  
  96          // Set up the template hierarchy.
  97          $new_templates = array();
  98          if ( '' !== bp_get_current_member_type() ) {
  99              $new_templates[] = 'members/index-directory-type-' . sanitize_file_name( bp_get_current_member_type() ) . '.php';
 100          }
 101          $new_templates[] = 'members/index-directory.php';
 102  
 103          /**
 104           * Filters the template hierarchy for theme compat and members directory page.
 105           *
 106           * @since 1.8.0
 107           *
 108           * @param array $value Array of template paths to add to hierarchy.
 109           */
 110          $new_templates = apply_filters( 'bp_template_hierarchy_members_directory', $new_templates );
 111  
 112          // Merge new templates with existing stack
 113          // @see bp_get_theme_compat_templates().
 114          $templates = array_merge( (array) $new_templates, $templates );
 115  
 116          return $templates;
 117      }
 118  
 119      /**
 120       * Update the global $post with directory data.
 121       *
 122       * @since 1.7.0
 123       */
 124  	public function directory_dummy_post() {
 125          bp_theme_compat_reset_post( array(
 126              'ID'             => 0,
 127              'post_title'     => bp_get_directory_title( 'members' ),
 128              'post_author'    => 0,
 129              'post_date'      => 0,
 130              'post_content'   => '',
 131              'post_type'      => 'page',
 132              'post_status'    => 'publish',
 133              'is_page'        => true,
 134              'comment_status' => 'closed'
 135          ) );
 136      }
 137  
 138      /**
 139       * Filter the_content with the members index template part.
 140       *
 141       * @since 1.7.0
 142       */
 143  	public function directory_content() {
 144          return bp_buffer_template_part( 'members/index', null, false );
 145      }
 146  
 147      /** Single ****************************************************************/
 148  
 149      /**
 150       * Add custom template hierarchy to theme compat for member pages.
 151       *
 152       * This is to mirror how WordPress has
 153       * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
 154       *
 155       * @since 1.8.0
 156       *
 157       * @param string $templates The templates from
 158       *                          bp_get_theme_compat_templates().
 159       * @return array $templates Array of custom templates to look for.
 160       */
 161  	public function single_template_hierarchy( $templates ) {
 162          // Setup some variables we're going to reference in our custom templates.
 163          $user_nicename = buddypress()->displayed_user->userdata->user_nicename;
 164  
 165          /**
 166           * Filters the template hierarchy for theme compat and member pages.
 167           *
 168           * @since 1.8.0
 169           *
 170           * @param array $value Array of template paths to add to hierarchy.
 171           */
 172          $new_templates = apply_filters( 'bp_template_hierarchy_members_single_item', array(
 173              'members/single/index-id-'        . (int) bp_displayed_user_id()                 . '.php',
 174              'members/single/index-nicename-'  . sanitize_file_name( $user_nicename )         . '.php',
 175              'members/single/index-action-'    . sanitize_file_name( bp_current_action() )    . '.php',
 176              'members/single/index-component-' . sanitize_file_name( bp_current_component() ) . '.php',
 177              'members/single/index.php'
 178          ) );
 179  
 180          // Merge new templates with existing stack
 181          // @see bp_get_theme_compat_templates().
 182          $templates = array_merge( (array) $new_templates, $templates );
 183  
 184          return $templates;
 185      }
 186  
 187      /**
 188       * Update the global $post with the displayed user's data.
 189       *
 190       * @since 1.7.0
 191       */
 192  	public function single_dummy_post() {
 193          bp_theme_compat_reset_post( array(
 194              'ID'             => 0,
 195              'post_title'     => bp_get_displayed_user_fullname(),
 196              'post_author'    => 0,
 197              'post_date'      => 0,
 198              'post_content'   => '',
 199              'post_type'      => 'page',
 200              'post_status'    => 'publish',
 201              'is_page'        => true,
 202              'comment_status' => 'closed'
 203          ) );
 204      }
 205  
 206      /**
 207       * Filter the_content with the members' single home template part.
 208       *
 209       * @since 1.7.0
 210       */
 211  	public function single_dummy_content() {
 212          return bp_buffer_template_part( 'members/single/home', null, false );
 213      }
 214  }


Generated: Sun Dec 22 01:00:54 2024 Cross-referenced by PHPXref 0.7.1