Skip to content

Commit

Permalink
redirection after registration only if bp-disalbe-activation-reloaded…
Browse files Browse the repository at this point in the history
… plugin is active
  • Loading branch information
alex-418 committed Aug 31, 2018
1 parent 226056b commit abb1a91
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1678,30 +1678,37 @@ function eypd_maybe_url( $url ) {

/**
* Redirects based on their role after registration when BP activation is skipped.
* The role value has to come from registration page $_POST, because user is not logged in yet, and
* field ID's on extended profiles differ on environments and can change
* The role value has to come from registration page $_POST, because user is not logged in yet
* Only works when the plugin bp-disable-activation-reloaded is activated
* @return mixed
*/
function eypd_redirect_after_register() {
/**
* Detect plugin. For use on Front End only.
*/
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );

// check for plugin using plugin name
if ( is_plugin_active( 'bp-disable-activation-reloaded/bp-disable-activation-loader.php' ) ) {
//plugin is activated
$needles = [ 'Learner', 'Organizer' ];
// figure out what role they selected at the registration page
$role_field_id = array_intersect( $needles, $_POST );
// set the role value
$role = reset( $role_field_id );
$html = '';

// redirect Organizers to edit events
if ( isset( $_POST['signup_username'] ) && ( $role ) ) {
if ( $role === 'Organizer' ) {
$html = '<b>Redirecting ... <meta http-equiv="refresh" content="0; URL=' . home_url() . '/edit-events/" /><a href=' . home_url() . '/edit-events/' . '>click here</a> if you are not automatically redirected.';
} else { // redirect to the homepage
$html = '<b>Redirecting ... <meta http-equiv="refresh" content="0; URL=' . home_url() . '/members/' . $_POST["signup_username"] . '/events/"/> <a href="' . home_url() . '/members/' . $_POST["signup_username"] . '/events/"/>click here</a> if you are not automatically redirected.';

$needles = [ 'Learner', 'Organizer' ];
// figure out what role they selected at the registration page
$role_field_id = array_intersect( $needles, $_POST );
// set the role value
$role = reset( $role_field_id );
$html = '';

// redirect Organizers to edit events
if ( isset( $_POST['signup_username'] ) && ( $role ) ) {
if ( $role === 'Organizer' ) {
$html = '<b>Redirecting ... <meta http-equiv="refresh" content="0; URL=' . home_url() . '/edit-events/" /><a href=' . home_url() . '/edit-events/' . '>click here</a> if you are not automatically redirected.';
} else { // redirect to the homepage
$html = '<b>Redirecting ... <meta http-equiv="refresh" content="0; URL=' . home_url() . '/members/' . $_POST["signup_username"] . '/events/"/> <a href="' . home_url() . '/members/' . $_POST["signup_username"] . '/events/"/>click here</a> if you are not automatically redirected.';

}
echo $html;
}
echo $html;
}
//
}
add_action( 'bp_after_registration_confirmed', 'eypd_redirect_after_register' );

Expand Down

0 comments on commit abb1a91

Please sign in to comment.