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