en slugs. * * @since 3.8.0 */ $forbidden = apply_filters( 'wd_login_forbidden_slugs', array( 'login', 'wp-admin', 'admin', 'dashboard', 'wp-login', 'wp-login.php', // For change '.' to '-'. 'wp-login-php', ) ); // Remove the double slash. $this->mask_url = ltrim( $this->mask_url, '/\\' ); if ( in_array( $this->mask_url, $forbidden, true ) ) { $this->errors[] = esc_html__( 'The slug you have provided cannot be used for masking your login area. Please try a new one.', 'wpdef' ); } elseif ( $this->is_mask_url_page_post_exists() ) { $this->errors[] = esc_html__( 'A page already exists at this URL. Please enter a unique URL for your login area.', 'wpdef' ); } elseif ( $this->mask_url === $this->redirect_traffic_url ) { $this->errors[] = esc_html__( 'Redirect URL must different from Login URL', 'wpdef' ); } } } /** * Check if Mask URL slug is empty. * * @return bool * @since 3.12.0 */ public function is_mask_url_empty(): bool { return '' === ltrim( $this->mask_url, '/\\' ); } /** * Check if page/post already exists for the Mask URL. * * @return bool * @since 3.12.0 */ public function is_mask_url_page_post_exists(): bool { $mask_url = ltrim( $this->mask_url, '/\\' ); if ( '' === $mask_url ) { return false; } $found = false; if ( is_multisite() ) { $offset = 0; $limit = 100; while ( $blog_ids = get_sites( // phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition array( 'fields' => 'ids', 'number' => $limit, 'offset' => $offset, ) ) ) { if ( is_array( $blog_ids ) ) { foreach ( $blog_ids as $blog_id ) { switch_to_blog( $blog_id ); $found = is_object( get_page_by_path( $mask_url, OBJECT, array( 'post', 'page' ) ) ); restore_current_blog(); if ( true === $found ) { break 2; } } } $offset += $limit; } } else { $found = is_object( get_page_by_path( $mask_url, OBJECT, array( 'post', 'page' ) ) ); } return $found; } /** * Retrieves the name of the Mask Login Area module. * * @return string The name of the Mask Login Area module. */ public static function get_module_name(): string { return esc_html__( 'Mask Login Area', 'wpdef' ); } /** * Check if the permalink structure is empty. * * @return bool */ public function is_permalink_structure_empty(): bool { $permalink_structure = get_option( 'permalink_structure' ); return '' === $permalink_structure; } /** * Retrieves the mask URL based on the permalink structure option. * * @return string The mask URL. */ public function get_mask_url(): string { if ( $this->is_permalink_structure_empty() ) { return '?' . $this->mask_url; } else { return $this->mask_url; } } }en slugs. * * @since 3.8.0 */ $forbidden = apply_filters( 'wd_login_forbidden_slugs', array( 'login', 'wp-admin', 'admin', 'dashboard', 'wp-login', 'wp-login.php', // For change '.' to '-'. 'wp-login-php', ) ); // Remove the double slash. $this->mask_url = ltrim( $this->mask_url, '/\\' ); if ( in_array( $this->mask_url, $forbidden, true ) ) { $this->errors[] = esc_html__( 'The slug you have provided cannot be used for masking your login area. Please try a new one.', 'wpdef' ); } elseif ( $this->is_mask_url_page_post_exists() ) { $this->errors[] = esc_html__( 'A page already exists at this URL. Please enter a unique URL for your login area.', 'wpdef' ); } elseif ( $this->mask_url === $this->redirect_traffic_url ) { $this->errors[] = esc_html__( 'Redirect URL must different from Login URL', 'wpdef' ); } } } /** * Check if Mask URL slug is empty. * * @return bool * @since 3.12.0 */ public function is_mask_url_empty(): bool { return '' === ltrim( $this->mask_url, '/\\' ); } /** * Check if page/post already exists for the Mask URL. * * @return bool * @since 3.12.0 */ public function is_mask_url_page_post_exists(): bool { $mask_url = ltrim( $this->mask_url, '/\\' ); if ( '' === $mask_url ) { return false; } $found = false; if ( is_multisite() ) { $offset = 0; $limit = 100; while ( $blog_ids = get_sites( // phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition array( 'fields' => 'ids', 'number' => $limit, 'offset' => $offset, ) ) ) { if ( is_array( $blog_ids ) ) { foreach ( $blog_ids as $blog_id ) { switch_to_blog( $blog_id ); $found = is_object( get_page_by_path( $mask_url, OBJECT, array( 'post', 'page' ) ) ); restore_current_blog(); if ( true === $found ) { break 2; } } } $offset += $limit; } } else { $found = is_object( get_page_by_path( $mask_url, OBJECT, array( 'post', 'page' ) ) ); } return $found; } /** * Retrieves the name of the Mask Login Area module. * * @return string The name of the Mask Login Area module. */ public static function get_module_name(): string { return esc_html__( 'Mask Login Area', 'wpdef' ); } /** * Check if the permalink structure is empty. * * @return bool */ public function is_permalink_structure_empty(): bool { $permalink_structure = get_option( 'permalink_structure' ); return '' === $permalink_structure; } /** * Retrieves the mask URL based on the permalink structure option. * * @return string The mask URL. */ public function get_mask_url(): string { if ( $this->is_permalink_structure_empty() ) { return '?' . $this->mask_url; } else { return $this->mask_url; } } }