[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * BuddyPress Member Screens.
   4   *
   5   * Handlers for member screens that aren't handled elsewhere.
   6   *
   7   * @package BuddyPress
   8   * @subpackage MembersScreens
   9   * @since 1.7.0
  10   */
  11  
  12  // Exit if accessed directly.
  13  defined( 'ABSPATH' ) || exit;
  14  
  15  /**
  16   * The main theme compat class for BuddyPress Registration.
  17   *
  18   * This class sets up the necessary theme compatibility actions to safely output
  19   * registration template parts to the_title and the_content areas of a theme.
  20   *
  21   * @since 1.7.0
  22   */
  23  class BP_Registration_Theme_Compat {
  24  
  25      /**
  26       * Setup the groups component theme compatibility.
  27       *
  28       * @since 1.7.0
  29       */
  30  	public function __construct() {
  31          add_action( 'bp_setup_theme_compat', array( $this, 'is_registration' ) );
  32      }
  33  
  34      /**
  35       * Are we looking at either the registration or activation pages?
  36       *
  37       * @since 1.7.0
  38       */
  39  	public function is_registration() {
  40  
  41          // Bail if not looking at the registration or activation page.
  42          if ( ! bp_is_register_page() && ! bp_is_activation_page() ) {
  43              return;
  44          }
  45  
  46          // Not a directory.
  47          bp_update_is_directory( false, 'register' );
  48  
  49          // Setup actions.
  50          add_filter( 'bp_get_buddypress_template',                array( $this, 'template_hierarchy' ) );
  51          add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'dummy_post'    ) );
  52          add_filter( 'bp_replace_the_content',                    array( $this, 'dummy_content' ) );
  53      }
  54  
  55      /** Template ***********************************************************/
  56  
  57      /**
  58       * Add template hierarchy to theme compat for registration/activation pages.
  59       *
  60       * This is to mirror how WordPress has
  61       * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
  62       *
  63       * @since 1.8.0
  64       *
  65       * @param string $templates The templates from bp_get_theme_compat_templates().
  66       * @return array $templates Array of custom templates to look for.
  67       */
  68  	public function template_hierarchy( $templates ) {
  69          $component = sanitize_file_name( bp_current_component() );
  70  
  71          /**
  72           * Filters the template hierarchy for theme compat and registration/activation pages.
  73           *
  74           * This filter is a variable filter that depends on the current component
  75           * being used.
  76           *
  77           * @since 1.8.0
  78           *
  79           * @param array $value Array of template paths to add to hierarchy.
  80           */
  81          $new_templates = apply_filters( "bp_template_hierarchy_{$component}", array(
  82              "members/index-{$component}.php"
  83          ) );
  84  
  85          // Merge new templates with existing stack
  86          // @see bp_get_theme_compat_templates().
  87          $templates = array_merge( (array) $new_templates, $templates );
  88  
  89          return $templates;
  90      }
  91  
  92      /**
  93       * Update the global $post with dummy data.
  94       *
  95       * @since 1.7.0
  96       */
  97  	public function dummy_post() {
  98          // Registration page.
  99          if ( bp_is_register_page() ) {
 100              if ( bp_get_membership_requests_required() ) {
 101                  $title = __( 'Request Membership', 'buddypress' );
 102              } else {
 103                  $title = __( 'Create an Account', 'buddypress' );
 104              }
 105  
 106              if ( 'completed-confirmation' == bp_get_current_signup_step() ) {
 107                  if ( bp_get_membership_requests_required() ) {
 108                      $title = __( 'Your Membership Request has been submitted.', 'buddypress' );
 109                  } else {
 110                      $title = __( 'Check Your Email To Activate Your Account!', 'buddypress' );
 111                  }
 112              }
 113  
 114          // Activation page.
 115          } else {
 116              $title = __( 'Activate Your Account', 'buddypress' );
 117  
 118              if ( bp_account_was_activated() ) {
 119                  $title = __( 'Account Activated', 'buddypress' );
 120              }
 121          }
 122  
 123          bp_theme_compat_reset_post( array(
 124              'ID'             => 0,
 125              'post_title'     => $title,
 126              'post_author'    => 0,
 127              'post_date'      => 0,
 128              'post_content'   => '',
 129              'post_type'      => 'page',
 130              'post_status'    => 'publish',
 131              'is_page'        => true,
 132              'comment_status' => 'closed'
 133          ) );
 134      }
 135  
 136      /**
 137       * Filter the_content with either the register or activate templates.
 138       *
 139       * @since 1.7.0
 140       */
 141  	public function dummy_content() {
 142          if ( bp_is_register_page() ) {
 143              return bp_buffer_template_part( 'members/register', null, false );
 144          } else {
 145              return bp_buffer_template_part( 'members/activate', null, false );
 146          }
 147      }
 148  }


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