This codebase is designed to demonstrate an advanced user management system in WordPress, integrating features such as custom user tables, authentication using cookies, and QR code generation. It is intended as an example of robust back-end development in WordPress, utilizing best practices for database interactions, security, and extendability.
-
Custom User Management:
- Users are stored in a custom database table (
custom_users
). - Includes functions to create, update, and delete users.
- Users are stored in a custom database table (
-
Email Notifications:
- Automatically sends emails to users with credentials or recovery information.
- Tracks whether emails have been sent.
-
QR Code Generation:
- Generates QR codes for invite-based authentication.
- QR codes are stored in the WordPress media library.
-
Advanced Authentication:
- Implements cookie-based authentication with token expiration.
- Handles invite link authentication with expiration checks.
-
Integration with Advanced Custom Fields (ACF):
- Manages user data and settings using ACF fields.
- Automatically processes and synchronizes ACF-based user lists.
-
AJAX Support:
- Includes AJAX handlers for user registration, login, and password recovery.
- WordPress Environment: Ensure WordPress is installed and configured.
- Advanced Custom Fields (ACF): Required for managing user data.
- PHP Extensions: Ensure required PHP extensions, such as GD or Imagick for QR code generation, are installed.
-
User Management:
addUserToAllowedUsers
: Adds a user to the ACF-managed allowed users list.removeUserFromCustomTable
: Deletes a user from the custom database table.
-
Email Notifications:
sendEmailToUser
: Sends an email to the user with credentials or recovery details.isEmailSent
: Checks if an email has already been sent to a user.markEmailAsSent
: Marks a user's email as sent in the ACF field.
-
QR Code Generation:
generateAndSaveQrCode
: Creates and stores a QR code for invite links.addImageToMediaLibrary
: Adds generated QR code images to the WordPress media library.
-
Authentication:
setAuthCookie
: Sets an authentication cookie for a user.handleInviteIdAuth
: Handles authentication via invite links.
-
ACF Integration:
processAllowedUsersForm
: Processes changes to the allowed users list.processAllowedUsersInvite
: Processes changes to the invite-based user list.
-
User Registration:
- Users submit a registration form via AJAX.
- User data is validated and stored in the custom database table.
- Credentials are sent to the user via email.
-
Invite-Based Authentication:
- An invite link with an ID is sent to the user.
- Upon clicking the link, a QR code is generated and authenticated.
- Users are redirected to the appropriate page upon successful authentication.
-
User Management with ACF:
- Admins manage allowed users via the ACF options page.
- The system synchronizes ACF data with the custom database table.
-
Security:
- Sanitization of user inputs.
- Prepared statements for database queries.
- Secure token generation for cookies and invite links.
-
Extendability:
- Modular design with reusable private methods.
- Easy integration with other plugins or custom themes.
-
Error Handling:
- Exceptions are logged for critical processes like QR code generation.
- This code is intended for demonstration purposes and may require adjustments for production use.
- Always test thoroughly in a staging environment before deploying.