Membership - Source Excerpt 02
Summary
This source excerpt preserves a bounded section of Anti-Christ.org/wp-content/plugins/fftac-membership/inc/membership.php so readers can inspect the evidence without opening the full source file.
**Source path:** Anti-Christ.org/wp-content/plugins/fftac-membership/inc/membership.php
if ($page_id) {
$page_url = get_permalink($page_id);
if ($page_url) {
return $page_url;
}
}
$page_definitions = antichrist_engine_membership_page_definitions();
$page_definition = $page_definitions[$page_key] ?? null;
if (!$page_definition) {
return home_url('/');
}
return home_url('/' . trim($page_definition['slug'], '/') . '/');
}
/**
* Gets the portal URL with an optional view.
*
* @param string $view Optional current view.
* @param array $args Additional query args.
* @return string
*/
function antichrist_engine_membership_get_portal_url($view = '', $args = array())
{
$url = antichrist_engine_membership_get_page_url('portal');
if ($view) {
$args['view'] = $view;
}
if (!$args) {
return $url;
}
return add_query_arg($args, $url);
}
/**
* Builds a logout URL that routes back through the portal.
*
* @param string $redirect_to Optional redirect target after logout.
* @return string
*/
function antichrist_engine_membership_get_logout_url($redirect_to = '')
{
$redirect_target = antichrist_engine_membership_normalize_redirect(
$redirect_to,
antichrist_engine_membership_get_portal_url('login')
);
return wp_nonce_url(
add_query_arg(array(
'action' => 'antichrist_engine_membership_logout',
'redirect_to' => rawurlencode($redirect_target),
), admin_url('admin-post.php')),
'antichrist_engine_membership_logout'
);
}
/**
* Normalizes safe redirect targets.
*
* @param string $redirect_to Raw redirect target.
* @param string $fallback Safe fallback URL.
* @return string
*/
function antichrist_engine_membership_normalize_redirect($redirect_to = '', $fallback = '')
{
$fallback = $fallback ?: antichrist_engine_membership_get_page_url('members');
if (!$redirect_to) {
return $fallback;
}
return wp_validate_redirect($redirect_to, $fallback);
}
/**
* Reads the requested portal view from the current URL.
*
* @return string
*/
function antichrist_engine_membership_get_current_view()
{
$view = isset($_GET['view']) ? sanitize_key(wp_unslash($_GET['view'])) : 'login';
if (!in_array($view, array('login', 'register', 'recover'), true)) {
return 'login';
}
return $view;
}
/**
* Gets a redirect target supplied by the current request.
*
* @return string
*/
function antichrist_engine_membership_get_requested_redirect()
{
$redirect_to = isset($_GET['redirect_to']) ? wp_unslash($_GET['redirect_to']) : '';
return antichrist_engine_membership_normalize_redirect(
$redirect_to,
antichrist_engine_membership_get_page_url('members')
);
}
/**
* Parses membership notices from the query string.
*
* @return array<string, mixed>
*/
function antichrist_engine_membership_get_notice()
{
$status = isset($_GET['membership_status']) ? sanitize_key(wp_unslash($_GET['membership_status'])) : '';
$context = isset($_GET['membership_context']) ? sanitize_key(wp_unslash($_GET['membership_context'])) : '';
$codes = isset($_GET['membership_codes']) ? sanitize_text_field(wp_unslash($_GET['membership_codes'])) : '';
if (!$status || !$context || !$codes) {
return array();
}
$messages = array();
foreach (array_filter(array_map('sanitize_key', explode(',', $codes))) as $code) {
$message = antichrist_engine_membership_get_notice_message($context, $status, $code);
if ($message) {
$messages[] = $message;
}
}
if (!$messages) {
return array();
}
return array(
'status' => $status,
'context' => $context,
'messages' => array_values(array_unique($messages)),
);
}
/**
* Maps status codes to readable membership messages.
*
* @param string $context Notice context.
* @param string $status Notice type.
* @param string $code Notice code.
* @return string
*/
function antichrist_engine_membership_get_notice_message($context, $status, $code)
{
$messages = array(
'login' => array(
'error' => array(
'empty_fields' => __('Enter your email or username and password to sign in.', 'antichrist-engine'),
'invalid_credentials' => __('Those credentials did not match an account. Try again or reset your password.', 'antichrist-engine'),
'invalid_submission' => __('The sign-in request could not be verified. Refresh the page and try again.', 'antichrist-engine'),
'rate_limited' => __('Too many sign-in attempts were received from this browser or network. Please wait a few minutes and try again.', 'antichrist-engine'),
'not_logged_in' => __('Sign in to continue into the members area.', 'antichrist-engine'),
),
'success' => array(
'logged_out' => __('You have been signed out.', 'antichrist-engine'),
),
),
'register' => array(
'error' => array(
'empty_name' => __('Add your full name so we can create the account.', 'antichrist-engine'),
'empty_email' => __('Add your email address to create the account.', 'antichrist-engine'),
'invalid_email' => __('That email address is not valid.', 'antichrist-engine'),
'email_exists' => __('An account with that email already exists. Try signing in instead.', 'antichrist-engine'),
'password_mismatch' => __('The password confirmation did not match.', 'antichrist-engine'),
'weak_password' => __('Use a password with at least 8 characters.', 'antichrist-engine'),
'password_too_long' => __('Use a password shorter than 4,096 characters.', 'antichrist-engine'),
'invalid_submission' => __('The registration request could not be verified. Refresh the page and try again.', 'antichrist-engine'),
'rate_limited' => __('Too many registration attempts were received from this browser or network. Please wait a few minutes and try again.', 'antichrist-engine'),
'registration_failed' => __('The account could not be created just now. Please try again.', 'antichrist-engine'),
),
'success' => array(
'registered' => __('Your account is ready and you are now signed in.', 'antichrist-engine'),
),
),
'recover' => array(
'error' => array(
'empty_identifier' => __('Enter the email address or username tied to your account.', 'antichrist-engine'),
'invalid_submission' => __('The recovery request could not be verified. Refresh the page and try again.', 'antichrist-engine'),
'rate_limited' => __('Too many recovery attempts were received from this browser or network. Please wait a few minutes and try again.', 'antichrist-engine'),
'recovery_failed' => __('We could not send a reset link with those details.', 'antichrist-engine'),
),
'success' => array(
'reset_sent' => __('If the account exists, a password reset link has been sent to its email address.', 'antichrist-engine'),
),
),
'profile' => array(
'error' => array(
'empty_display_name' => __('Display name cannot be empty.', 'antichrist-engine'),
'invalid_email' => __('Add a valid email address before saving the profile.', 'antichrist-engine'),
'email_exists' => __('That email address is already attached to another account.', 'antichrist-engine'),
'update_failed' => __('We could not save your changes just now. Please try again.', 'antichrist-engine'),
),
'success' => array(
'updated' => __('Your profile changes have been saved.', 'antichrist-engine'),
),
),
);
return $messages[$context][$status][$code] ?? '';
}
/**
* Creates a URL containing membership notice parameters.
*
* @param string $url Base URL.
* @param string $status Notice status.
* @param string $context Notice context.
* @param string|string[] $codes One or more message codes.
* @param array $args Additional query args.
* @return string
*/
function antichrist_engine_membership_build_notice_url($url, $status, $context, $codes, $args = array())
{
$codes = (array) $codes;
$codes = array_filter(array_map('sanitize_key', $codes));
$notice_args = array(