Files
WooCow/includes/class-woocow-pw-sync.php
Malin 2ee81efacf feat: initial WooCow plugin — Mailcow/WooCommerce integration
- Mailcow API client wrapping domains, mailboxes, aliases endpoints
- Admin backend: server management, customer-domain assignments, mailbox overview
- WooCommerce My Account: email hosting tab with mailbox/alias management
- Per-mailbox password change (independent of WP account password)
- Optional WP account password sync to all customer mailboxes
- Installer creates wp_woocow_servers and wp_woocow_assignments DB tables
- Full nonce + capability + ownership verification on all AJAX endpoints

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-27 08:06:22 +01:00

52 lines
1.6 KiB
PHP

<?php
/**
* Adds an optional "sync password to mailboxes" checkbox on the
* WooCommerce My Account > Account Details page.
*
* Loaded automatically from woocow.php when WooCommerce is active.
*/
defined( 'ABSPATH' ) || exit;
class WooCow_PW_Sync {
public function __construct() {
// Render the checkbox below the password fields
add_action( 'woocommerce_edit_account_form', [ $this, 'render_checkbox' ] );
}
public function render_checkbox(): void {
// Only show if the current customer has mailcow assignments
global $wpdb;
$count = (int) $wpdb->get_var( $wpdb->prepare(
"SELECT COUNT(*) FROM {$wpdb->prefix}woocow_assignments WHERE customer_id = %d",
get_current_user_id()
) );
if ( ! $count ) {
return;
}
?>
<fieldset class="woocow-pw-sync-field">
<legend><?php esc_html_e( 'Email Hosting', 'woocow' ); ?></legend>
<label for="woocow_sync_pw">
<input type="checkbox" name="woocow_sync_pw" id="woocow_sync_pw" value="1">
<?php esc_html_e( 'Also update password for all my email mailboxes (only applies when changing password above)', 'woocow' ); ?>
</label>
</fieldset>
<style>
.woocow-pw-sync-field {
border: 1px dashed #ddd;
border-radius: 6px;
padding: 12px 16px;
margin-top: 20px;
}
.woocow-pw-sync-field legend {
font-weight: 700;
padding: 0 6px;
color: #2271b1;
}
</style>
<?php
}
}