131 lines
No EOL
4.6 KiB
PHP
131 lines
No EOL
4.6 KiB
PHP
<?php
|
|
|
|
add_action('admin_enqueue_scripts', function () {
|
|
wp_enqueue_script(
|
|
'rl-mailwarmer-email-account-js',
|
|
RL_MAILWARMER_URL . '/js/email-account.js',
|
|
['jquery'],
|
|
null,
|
|
true
|
|
);
|
|
|
|
wp_localize_script('rl-mailwarmer-email-account-js', 'rlMailWarmerEmailAccount', [
|
|
'ajax_url' => admin_url('admin-ajax.php'),
|
|
'nonce' => wp_create_nonce('modify_email_account_nonce'),
|
|
]);
|
|
});
|
|
|
|
|
|
/**
|
|
* Add a custom metabox to the WP dashboard.
|
|
*/
|
|
add_action('wp_dashboard_setup', function () {
|
|
wp_add_dashboard_widget(
|
|
'modify_email_account_widget', // Widget ID
|
|
__('Modify Email Account', 'rl-mailwarmer'), // Title
|
|
'rl_mailwarmer_render_email_account_widget' // Callback function
|
|
);
|
|
});
|
|
|
|
/**
|
|
* Add a meta box for checking mail login.
|
|
*/
|
|
add_action('add_meta_boxes', function () {
|
|
add_meta_box(
|
|
'check_mail_login_box',
|
|
__('Check Mail Login', 'rl-mailwarmer'),
|
|
'rl_mailwarmer_render_check_mail_login_box',
|
|
'email-account',
|
|
'side',
|
|
'default'
|
|
);
|
|
});
|
|
|
|
/**
|
|
* Render the Modify Email Account metabox.
|
|
*/
|
|
function rl_mailwarmer_render_email_account_widget()
|
|
{
|
|
// Fetch email providers
|
|
$email_providers = get_posts([
|
|
'post_type' => 'email-provider',
|
|
'post_status' => 'publish',
|
|
'numberposts' => -1,
|
|
'orderby' => 'title',
|
|
'order' => 'ASC',
|
|
]);
|
|
|
|
// Render the form
|
|
?>
|
|
<form id="modify-email-account-form">
|
|
<p>
|
|
<label for="email_address"><?php esc_html_e('Email Address', 'rl-mailwarmer'); ?></label>
|
|
<input type="email" id="email_address" name="email_address" class="regular-text" required>
|
|
</p>
|
|
<p>
|
|
<label for="mail_password"><?php esc_html_e('Password (Leave empty for random)', 'rl-mailwarmer'); ?></label>
|
|
<input type="password" id="mail_password" name="mail_password" class="regular-text">
|
|
</p>
|
|
<p>
|
|
<label for="action"><?php esc_html_e('Action', 'rl-mailwarmer'); ?></label>
|
|
<select id="action" name="action" required>
|
|
<option value="create"><?php esc_html_e('Create', 'rl-mailwarmer'); ?></option>
|
|
<option value="update"><?php esc_html_e('Update', 'rl-mailwarmer'); ?></option>
|
|
<option value="delete"><?php esc_html_e('Delete', 'rl-mailwarmer'); ?></option>
|
|
</select>
|
|
</p>
|
|
<p>
|
|
<label for="email_provider"><?php esc_html_e('Email Provider', 'rl-mailwarmer'); ?></label>
|
|
<select id="email_provider" name="email_provider">
|
|
<option value=""><?php esc_html_e('-- Select Provider --', 'rl-mailwarmer'); ?></option>
|
|
<?php foreach ($email_providers as $provider): ?>
|
|
<option value="<?php echo esc_attr($provider->ID); ?>">
|
|
<?php echo esc_html($provider->post_title); ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</p>
|
|
<p>
|
|
<label for="imap_server"><?php esc_html_e('IMAP Server', 'rl-mailwarmer'); ?></label>
|
|
<input type="text" id="imap_server" name="imap_server" class="regular-text">
|
|
</p>
|
|
<p>
|
|
<button type="button" id="submit-email-account" class="button button-primary">
|
|
<?php esc_html_e('Submit', 'rl-mailwarmer'); ?>
|
|
</button>
|
|
</p>
|
|
<div id="modify-email-account-result"></div>
|
|
</form>
|
|
<?php
|
|
}
|
|
|
|
/**
|
|
* Render the meta box for checking mail login.
|
|
*
|
|
* @param WP_Post $post The current post object.
|
|
*/
|
|
function rl_mailwarmer_render_check_mail_login_box($post)
|
|
{
|
|
// Add a nonce field for security
|
|
wp_nonce_field('check_mail_login_nonce', 'check_mail_login_nonce_field');
|
|
|
|
// Render the form
|
|
?>
|
|
<form id="check-mail-login-form">
|
|
<p>
|
|
<label for="protocol"><?php esc_html_e('Protocol', 'rl-mailwarmer'); ?></label>
|
|
<select id="protocol" name="protocol" class="regular-text">
|
|
<option value=""><?php esc_html_e('-- Select Protocol --', 'rl-mailwarmer'); ?></option>
|
|
<option value="IMAP"><?php esc_html_e('IMAP', 'rl-mailwarmer'); ?></option>
|
|
<option value="SMTP"><?php esc_html_e('SMTP', 'rl-mailwarmer'); ?></option>
|
|
</select>
|
|
</p>
|
|
<p>
|
|
<button type="button" id="check-mail-login-button" class="button button-primary">
|
|
<?php esc_html_e('Check Login', 'rl-mailwarmer'); ?>
|
|
</button>
|
|
</p>
|
|
<div id="check-mail-login-result"></div>
|
|
</form>
|
|
<?php
|
|
}
|