AO_CUSTOM_LOGIN_URL > database value. * The rewrite handling, the settings screen, the change email and the later * WP-CLI command all read this, so they cannot disagree. * * An AO_CUSTOM_LOGIN_URL value the validator blocks fails open: `enabled` is * false (the default login keeps working) and `error` holds the validator's * result code (a key of Custom_Login_Url_Validator::get_messages(); not translated * here, because this runs at plugins_loaded). `warn` values are accepted. * * Slugs are obscurity, not authentication: never put secrets in these constants. * * @param array|null $options Saved `adminoptim_custom_login` option, or null to read it. * * @return array{slug:string,source:string,enabled:bool,error:string} `source` is * 'constant-disable', 'constant-override' or 'db'. */ function ao_get_effective_login_slug( ?array $options = null ): array { if ( null === $options ) { $options = get_option( 'adminoptim_custom_login', [] ); $options = is_array( $options ) ? $options : []; } $db_slug = isset( $options['custom_slug'] ) ? (string) $options['custom_slug'] : ''; $redirection = ''; $target = ao_get_login_redirect_target( $options ); if ( 'custom' === $target['mode'] ) { $redirection = $target['slug']; } // --- 1. AO_DISABLE_CUSTOM_LOGIN: module off, default login restored. --- if ( defined( 'AO_DISABLE_CUSTOM_LOGIN' ) && AO_DISABLE_CUSTOM_LOGIN ) { return [ 'slug' => $db_slug, 'source' => 'constant-disable', 'enabled' => false, 'error' => '', ]; } // --- 2. AO_CUSTOM_LOGIN_URL: overrides the stored slug, same validator. --- if ( defined( 'AO_CUSTOM_LOGIN_URL' ) && is_string( AO_CUSTOM_LOGIN_URL ) && '' !== trim( AO_CUSTOM_LOGIN_URL ) ) { // Post types are not registered this early, so skip the content queries. $result = Custom_Login_Url_Validator::validate( AO_CUSTOM_LOGIN_URL, [ 'redirection_slug' => $redirection, 'check_content' => false, 'with_message' => false, ] ); if ( Custom_Login_Url_Validator::STATUS_BLOCK === $result['status'] ) { return [ 'slug' => '', 'source' => 'constant-override', 'enabled' => false, 'error' => $result['code'], ]; } return [ 'slug' => $result['slug'], 'source' => 'constant-override', 'enabled' => true, 'error' => '', ]; } // --- 3. Database value. An empty redirect target means 404 mode, so only the slug is needed. --- return [ 'slug' => $db_slug, 'source' => 'db', 'enabled' => '' !== $db_slug, 'error' => '', ]; } } if ( ! function_exists( 'ao_get_login_redirect_target' ) ) { /** * Resolve where logged-out visitors of wp-login.php and wp-admin go. * * Resolved on read, nothing is migrated. With no stored `redirect_mode`, a * stored `redirection_slug` of '' or '404' means 404 mode and any other value * means custom mode with that slug. A stored mode of 'custom' with an empty * slug falls back to 404 so a half-saved form can never lock anyone out. * * @param array|null $options Saved `adminoptim_custom_login` option, or null to read it. * * @return array{mode:string,slug:string} `mode` is '404', 'home' or 'custom'. */ function ao_get_login_redirect_target( ?array $options = null ): array { if ( null === $options ) { $options = get_option( 'adminoptim_custom_login', [] ); $options = is_array( $options ) ? $options : []; } $slug = isset( $options['redirection_slug'] ) ? (string) $options['redirection_slug'] : ''; $mode = isset( $options['redirect_mode'] ) ? (string) $options['redirect_mode'] : ''; if ( ! in_array( $mode, [ '404', 'home', 'custom' ], true ) ) { $mode = ( '' === $slug || '404' === $slug ) ? '404' : 'custom'; } if ( 'custom' === $mode && ( '' === $slug || '404' === $slug ) ) { $mode = '404'; } return [ 'mode' => $mode, 'slug' => 'custom' === $mode ? $slug : '', ]; } }