- Add trainer status system (pending, approved, active, inactive, disabled) - Create access control system based on trainer status - Refactor Master Dashboard with enhanced trainer table - Add status column and filtering - Implement search and pagination - Add bulk status update functionality - Create status pages for pending and disabled trainers - Implement approval workflow with email notifications - Add email template management to settings page - Include comprehensive test suite (unit, integration, E2E) This allows Master Trainers to manage trainer accounts, approve new registrations, and control access based on account status. Trainers must be approved before accessing dashboard features. Co-Authored-By: Claude <noreply@anthropic.com>
268 lines
No EOL
11 KiB
PHP
268 lines
No EOL
11 KiB
PHP
<?php
|
|
/**
|
|
* HVAC Community Events - Enhanced Settings with Email Templates
|
|
*
|
|
* Extends the settings page with email template editors
|
|
*
|
|
* @package HVAC_Community_Events
|
|
* @since 1.0.0
|
|
*/
|
|
|
|
// Exit if accessed directly
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Class HVAC_Enhanced_Settings
|
|
*
|
|
* Adds email template management to the plugin settings
|
|
*/
|
|
class HVAC_Enhanced_Settings {
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public function __construct() {
|
|
// Hook into settings initialization
|
|
add_action( 'admin_init', array( $this, 'register_email_template_settings' ), 20 );
|
|
|
|
// Add email templates tab to settings page
|
|
add_action( 'hvac_ce_settings_tabs', array( $this, 'add_email_templates_tab' ) );
|
|
add_action( 'hvac_ce_settings_content', array( $this, 'render_email_templates_content' ) );
|
|
|
|
// Enqueue admin scripts
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
|
|
}
|
|
|
|
/**
|
|
* Register email template settings
|
|
*/
|
|
public function register_email_template_settings() {
|
|
// Register the email templates option
|
|
register_setting( 'hvac_ce_email_templates', 'hvac_ce_email_templates', array( $this, 'sanitize_email_templates' ) );
|
|
}
|
|
|
|
/**
|
|
* Add email templates tab
|
|
*
|
|
* @param array $tabs Current tabs
|
|
* @return array Modified tabs
|
|
*/
|
|
public function add_email_templates_tab( $tabs ) {
|
|
$tabs['email_templates'] = __( 'Email Templates', 'hvac-community-events' );
|
|
return $tabs;
|
|
}
|
|
|
|
/**
|
|
* Render email templates content
|
|
*
|
|
* @param string $active_tab Active tab ID
|
|
*/
|
|
public function render_email_templates_content( $active_tab ) {
|
|
if ( $active_tab !== 'email_templates' ) {
|
|
return;
|
|
}
|
|
|
|
$templates = get_option( 'hvac_ce_email_templates', array() );
|
|
|
|
// Define template keys and their descriptions
|
|
$template_definitions = array(
|
|
'new_registration' => array(
|
|
'title' => __( 'New Registration Notification', 'hvac-community-events' ),
|
|
'description' => __( 'Sent to administrators when a new trainer registers', 'hvac-community-events' ),
|
|
'placeholders' => array(
|
|
'{trainer_name}' => 'Trainer full name',
|
|
'{trainer_email}' => 'Trainer email address',
|
|
'{business_name}' => 'Business name',
|
|
'{business_phone}' => 'Business phone',
|
|
'{business_email}' => 'Business email',
|
|
'{registration_date}' => 'Registration date',
|
|
'{application_details}' => 'Application details',
|
|
'{approval_url}' => 'Quick approval link',
|
|
),
|
|
),
|
|
'account_approved' => array(
|
|
'title' => __( 'Account Approved', 'hvac-community-events' ),
|
|
'description' => __( 'Sent to trainers when their account is approved', 'hvac-community-events' ),
|
|
'placeholders' => array(
|
|
'{trainer_name}' => 'Trainer full name',
|
|
'{trainer_email}' => 'Trainer email address',
|
|
'{business_name}' => 'Business name',
|
|
'{dashboard_url}' => 'Dashboard URL',
|
|
'{login_url}' => 'Login page URL',
|
|
'{website_name}' => 'Website name',
|
|
'{website_url}' => 'Website URL',
|
|
),
|
|
),
|
|
'account_disabled' => array(
|
|
'title' => __( 'Account Disabled', 'hvac-community-events' ),
|
|
'description' => __( 'Sent to trainers when their account is disabled', 'hvac-community-events' ),
|
|
'placeholders' => array(
|
|
'{trainer_name}' => 'Trainer full name',
|
|
'{trainer_email}' => 'Trainer email address',
|
|
'{business_name}' => 'Business name',
|
|
'{support_email}' => 'Support email address',
|
|
'{website_name}' => 'Website name',
|
|
),
|
|
),
|
|
);
|
|
|
|
?>
|
|
<div class="hvac-email-templates-settings">
|
|
<form method="post" action="options.php">
|
|
<?php settings_fields( 'hvac_ce_email_templates' ); ?>
|
|
|
|
<p><?php _e( 'Customize the email templates sent by the plugin. Use the placeholders shown for each template.', 'hvac-community-events' ); ?></p>
|
|
|
|
<?php foreach ( $template_definitions as $key => $definition ): ?>
|
|
<?php
|
|
$subject = isset( $templates[$key]['subject'] ) ? $templates[$key]['subject'] : '';
|
|
$body = isset( $templates[$key]['body'] ) ? $templates[$key]['body'] : '';
|
|
?>
|
|
|
|
<div class="email-template-section">
|
|
<h3><?php echo esc_html( $definition['title'] ); ?></h3>
|
|
<p class="description"><?php echo esc_html( $definition['description'] ); ?></p>
|
|
|
|
<div class="placeholders-info">
|
|
<strong><?php _e( 'Available placeholders:', 'hvac-community-events' ); ?></strong>
|
|
<div class="placeholders-list">
|
|
<?php foreach ( $definition['placeholders'] as $placeholder => $desc ): ?>
|
|
<code><?php echo esc_html( $placeholder ); ?></code> - <?php echo esc_html( $desc ); ?><br>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<table class="form-table">
|
|
<tr>
|
|
<th scope="row">
|
|
<label for="<?php echo esc_attr( $key ); ?>_subject">
|
|
<?php _e( 'Subject', 'hvac-community-events' ); ?>
|
|
</label>
|
|
</th>
|
|
<td>
|
|
<input type="text"
|
|
id="<?php echo esc_attr( $key ); ?>_subject"
|
|
name="hvac_ce_email_templates[<?php echo esc_attr( $key ); ?>][subject]"
|
|
value="<?php echo esc_attr( $subject ); ?>"
|
|
class="large-text" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">
|
|
<label for="<?php echo esc_attr( $key ); ?>_body">
|
|
<?php _e( 'Email Body', 'hvac-community-events' ); ?>
|
|
</label>
|
|
</th>
|
|
<td>
|
|
<?php
|
|
wp_editor( $body, $key . '_body', array(
|
|
'textarea_name' => 'hvac_ce_email_templates[' . $key . '][body]',
|
|
'textarea_rows' => 15,
|
|
'media_buttons' => false,
|
|
'teeny' => false,
|
|
'tinymce' => array(
|
|
'toolbar1' => 'bold,italic,underline,separator,alignleft,aligncenter,alignright,separator,link,unlink,separator,undo,redo',
|
|
'toolbar2' => 'formatselect,fontselect,fontsizeselect,separator,forecolor,backcolor,separator,bullist,numlist,separator,code',
|
|
),
|
|
) );
|
|
?>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<hr>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
|
|
<?php submit_button(); ?>
|
|
</form>
|
|
|
|
<div class="email-template-preview">
|
|
<h3><?php _e( 'Preview', 'hvac-community-events' ); ?></h3>
|
|
<p><?php _e( 'Select a template above to preview how it will look with sample data.', 'hvac-community-events' ); ?></p>
|
|
<div id="email-preview-container" style="border: 1px solid #ddd; padding: 20px; background: #fff; display: none;">
|
|
<div id="email-preview-subject" style="font-weight: bold; margin-bottom: 10px;"></div>
|
|
<div id="email-preview-body"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php
|
|
}
|
|
|
|
/**
|
|
* Sanitize email templates
|
|
*
|
|
* @param array $input Input data
|
|
* @return array Sanitized data
|
|
*/
|
|
public function sanitize_email_templates( $input ) {
|
|
$sanitized = array();
|
|
|
|
if ( ! is_array( $input ) ) {
|
|
return $sanitized;
|
|
}
|
|
|
|
foreach ( $input as $key => $template ) {
|
|
if ( isset( $template['subject'] ) ) {
|
|
$sanitized[$key]['subject'] = sanitize_text_field( $template['subject'] );
|
|
}
|
|
|
|
if ( isset( $template['body'] ) ) {
|
|
$sanitized[$key]['body'] = wp_kses_post( $template['body'] );
|
|
}
|
|
}
|
|
|
|
return $sanitized;
|
|
}
|
|
|
|
/**
|
|
* Enqueue admin scripts and styles
|
|
*/
|
|
public function enqueue_admin_scripts( $hook ) {
|
|
// Only load on our settings page
|
|
if ( strpos( $hook, 'hvac-community-events' ) === false ) {
|
|
return;
|
|
}
|
|
|
|
// Add custom CSS
|
|
wp_add_inline_style( 'wp-admin', '
|
|
.hvac-email-templates-settings .email-template-section {
|
|
background: #fff;
|
|
border: 1px solid #e5e5e5;
|
|
padding: 20px;
|
|
margin-bottom: 20px;
|
|
}
|
|
.hvac-email-templates-settings .placeholders-info {
|
|
background: #f5f5f5;
|
|
padding: 15px;
|
|
margin: 15px 0;
|
|
border-radius: 3px;
|
|
}
|
|
.hvac-email-templates-settings .placeholders-list {
|
|
margin-top: 10px;
|
|
line-height: 1.8;
|
|
}
|
|
.hvac-email-templates-settings .placeholders-list code {
|
|
background: #fff;
|
|
padding: 2px 5px;
|
|
border: 1px solid #ddd;
|
|
}
|
|
.hvac-email-templates-settings .email-template-preview {
|
|
margin-top: 40px;
|
|
background: #f9f9f9;
|
|
padding: 20px;
|
|
border-radius: 3px;
|
|
}
|
|
' );
|
|
|
|
// Add preview functionality
|
|
wp_add_inline_script( 'jquery', '
|
|
jQuery(document).ready(function($) {
|
|
// Preview functionality could be added here
|
|
// For now, just a placeholder
|
|
});
|
|
' );
|
|
}
|
|
}
|