[ 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              $title = __( 'Create an Account', 'buddypress' );
 101  
 102              if ( 'completed-confirmation' == bp_get_current_signup_step() ) {
 103                  $title = __( 'Check Your Email To Activate Your Account!', 'buddypress' );
 104              }
 105  
 106          // Activation page.
 107          } else {
 108              $title = __( 'Activate Your Account', 'buddypress' );
 109  
 110              if ( bp_account_was_activated() ) {
 111                  $title = __( 'Account Activated', 'buddypress' );
 112              }
 113          }
 114  
 115          bp_theme_compat_reset_post( array(
 116              'ID'             => 0,
 117              'post_title'     => $title,
 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 either the register or activate templates.
 130       *
 131       * @since 1.7.0
 132       */
 133  	public function dummy_content() {
 134          if ( bp_is_register_page() ) {
 135              return bp_buffer_template_part( 'members/register', null, false );
 136          } else {
 137              return bp_buffer_template_part( 'members/activate', null, false );
 138          }
 139      }
 140  }


Generated: Sun Jul 21 01:01:44 2019 Cross-referenced by PHPXref 0.7.1