Support custom login pages
- Add the button (and error messages) to every wp_login_form() form via login_form_top/login_form_bottom; in button-only mode the password fields are wrapped and hidden there. - New template functions m365_login_button() and m365_login_messages(); the shortcode gains divider and messages attributes. - New setting for the custom login page URL: failed sign-ins, the fallback link and the logout redirect point there instead of wp-login.php. Must be a same-site URL. - Button-only mode now blocks every interactive password sign-in through the authenticate filter, not only wp-login.php; XML-RPC, REST, WP-CLI and cron are exempt, plus a filter for trusted exceptions. - Fallback key accepted on any page (init) instead of login_init only. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JJxAHYdMfKPoN4koRc4Ci2
This commit is contained in:
parent
e5db0d49be
commit
701e85ab88
15 changed files with 804 additions and 300 deletions
|
|
@ -51,6 +51,9 @@ class M365_Login_Settings {
|
|||
'button_radius' => 4,
|
||||
'button_position' => 'below',
|
||||
'divider_text' => __( 'or', 'm365-login' ),
|
||||
// Custom login pages.
|
||||
'custom_login_url' => '',
|
||||
'inject_form' => 1, // Add the button to wp_login_form() output.
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -209,7 +212,31 @@ class M365_Login_Settings {
|
|||
*/
|
||||
public function fallback_url() {
|
||||
$key = $this->fallback_key();
|
||||
return '' === $key ? '' : add_query_arg( 'm365_fallback', $key, wp_login_url() );
|
||||
return '' === $key ? '' : add_query_arg( 'm365_fallback', $key, $this->login_page_url() );
|
||||
}
|
||||
|
||||
/**
|
||||
* URL of a custom login page (same site), or empty string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function custom_login_url() {
|
||||
$url = (string) $this->get( 'custom_login_url', '' );
|
||||
if ( '' === $url ) {
|
||||
return '';
|
||||
}
|
||||
$validated = wp_validate_redirect( $url, '' );
|
||||
return is_string( $validated ) ? $validated : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Where users land after a failed Microsoft sign-in (custom page or wp-login.php).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function login_page_url() {
|
||||
$custom = $this->custom_login_url();
|
||||
return '' !== $custom ? $custom : wp_login_url();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -309,6 +336,20 @@ class M365_Login_Settings {
|
|||
}
|
||||
$out['fallback_key'] = $key;
|
||||
|
||||
// Custom login page (must be on this site).
|
||||
$custom = isset( $input['custom_login_url'] ) ? esc_url_raw( trim( wp_unslash( $input['custom_login_url'] ) ) ) : '';
|
||||
if ( '' !== $custom ) {
|
||||
if ( 0 === strpos( $custom, '/' ) ) {
|
||||
$custom = home_url( $custom );
|
||||
}
|
||||
if ( '' === wp_validate_redirect( $custom, '' ) ) {
|
||||
add_settings_error( M365_LOGIN_OPTION, 'custom_login_url', __( 'The custom login page must be a URL on this site.', 'm365-login' ) );
|
||||
$custom = $current['custom_login_url'];
|
||||
}
|
||||
}
|
||||
$out['custom_login_url'] = $custom;
|
||||
$out['inject_form'] = empty( $input['inject_form'] ) ? 0 : 1;
|
||||
|
||||
// Button.
|
||||
$text = isset( $input['button_text'] ) ? sanitize_text_field( wp_unslash( $input['button_text'] ) ) : '';
|
||||
$out['button_text'] = '' === trim( $text ) ? $defaults['button_text'] : mb_substr( $text, 0, 80 );
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue