$post_title, 'post_type' => 'domain', 'post_status' => 'publish' ); // Check if editing existing post if (isset($_POST['post_id']) && !empty($_POST['post_id'])) { $post_data['ID'] = intval($_POST['post_id']); $post_id = wp_update_post($post_data); $new_post = false; $message = ['status' => 'success', 'message' => 'Domain updated successfully.']; } else { // Prepare WP_Query to check for an existing post with the same title $args = [ 'post_type' => 'domain', // Replace with your post type 'post_status' => 'any', 'title' => $post_title, 'fields' => 'id', 'posts_per_page' => 1 ]; $query = new WP_Query($args); if ($query->have_posts()) { log_to_file("Domain Edit template - Domain {$post_title} already exists: "); $message = ['status' => 'error', 'message' => 'Domain already exists.']; } else { $post_id = wp_insert_post($post_data); $new_post = true; $message = ['status' => 'success', 'message' => 'Domain added successfully.']; if (!is_wp_error($post_id)) { update_post_meta($post_id, 'cloudflare_api_email', $cloudflare_email); update_post_meta($post_id, 'cloudflare_api_key', $cloudflare_key); update_post_meta($post_id, 'domain_in_use', $domain_in_use); if ($new_post) { // set the owner_id to the creator of the post if this is a new domain update_post_meta($post_id, 'owner_id', $current_user_id); // Run a domain health check $domain_report_id = RL_MailWarmer_Domain_Helper::save_domain_health_report($post_id); } } else { $message = ['status' => 'error', 'message' => 'Error: ' . $post_id->get_error_message()]; // $message = 'Error: ' . $post_id->get_error_message(); } if (isset($_POST['update_dns']) && !empty($_POST['update_dns'])) { log_to_file("Domain Edit template - Running Fix Domain"); $results = RL_MailWarmer_Domain_Helper::fix_deliverability_dns_issues($post_id); log_to_file("Domain Edit template - Results: ", $results); } if ($domain_in_use) { log_to_file("Domain Edit template - Domain in use: {$post_title}. Not modifying MX records"); } else { log_to_file("Domain Edit template - Domain not in use: {$post_title}. Setting MX to Mailferno server "); // Set MX to 'server' of $post_id $server = get_field('defaut_mailferno_mx', 'option'); log_to_file("Domain Edit template - Default Mailferno MX Server: ", $server); $update_MX_result = RL_MailWarmer_Domain_Helper::update_mx_record($post_id, $server->post_title, 0, $ttl = 3600); log_to_file("Domain Edit template - CloudFlare Response: {$update_MX_result}"); } if ( !(isset($_POST['stay_on_page']) && ($_POST['stay_on_page'] === 'on')) ) { // log_to_file("Domain Edit template - stay_on_page not set; redirecting!"); wp_redirect( get_permalink( $post_id ) ); exit; } } // Reset post data wp_reset_postdata(); } } // Get existing post data if editing if (isset($_GET['edit'])) { $post_id = intval($_GET['edit']); $new_post = false; } else { $post_id = 0; } $domain_name = ''; $cloudflare_email = ''; $cloudflare_key = ''; $domain_in_use = ''; if ($post_id > 0) { $post_item = get_post($post_id); if ($post_item && $post_item->post_type === 'domain') { $domain_name = $post_item->post_title; $cloudflare_email = get_post_meta($post_id, 'cloudflare_api_email', true) ?: ''; $cloudflare_key = get_post_meta($post_id, 'cloudflare_api_key', true) ?: ''; $domain_in_use = get_post_meta($post_id, 'domain_in_use', true) ?: ''; } } get_header(); ?>
>
>
>
>

>

class=""> Warning! This will attempt to update your DNS records!
class=""> If the domain is already in use we won't change the MX records

CloudFlare Settings

Only if different than the credentials in your profile

'', // ) // ); ?>