Skip to content

Commit 3942fec

Browse files
committed
fix: harden generated sites and contact form mail
1 parent 6634c21 commit 3942fec

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

includes/Abilities/ContentAbilities.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,13 +640,15 @@ private static function build_wpforms_form_data( string $title, string $recipien
640640
*/
641641
private static function create_contact_form_7_form( string $cf7_class, string $title, string $recipient_email, string $submit_label ): array {
642642
$form_markup = self::build_contact_form_7_markup( $submit_label );
643+
$sender = self::contact_form_sender_address();
643644
$mail = [
644645
'subject' => sprintf(
645646
/* translators: %s: contact form title */
646647
__( '%s submission', 'superdav-ai-agent' ),
647648
$title
648649
),
649-
'sender' => '[your-name] <[your-email]>',
650+
// Keep the visitor address in Reply-To; using it as From fails DMARC/SPF.
651+
'sender' => $sender,
650652
'body' => "From: [your-name] <[your-email]>\nSubject: [your-subject]\n\nMessage:\n[your-message]",
651653
'recipient' => $recipient_email,
652654
'additional_headers' => 'Reply-To: [your-email]',
@@ -708,6 +710,22 @@ private static function create_contact_form_7_form( string $cf7_class, string $t
708710
];
709711
}
710712

713+
/**
714+
* Return a same-site sender address for generated forms.
715+
*
716+
* @return string Sender in Contact Form 7's "Name <address>" format.
717+
*/
718+
private static function contact_form_sender_address(): string {
719+
$host = (string) wp_parse_url( home_url( '/' ), PHP_URL_HOST );
720+
$host = strtolower( preg_replace( '/[^a-z0-9.-]/i', '', $host ) ?? '' );
721+
if ( '' === $host ) {
722+
$host = 'localhost';
723+
}
724+
$name = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
725+
$name = '' !== $name ? $name : __( 'Website', 'superdav-ai-agent' );
726+
return sprintf( '%s <wordpress@%s>', $name, $host );
727+
}
728+
711729
/**
712730
* Build Contact Form 7 form markup.
713731
*

includes/Core/SystemInstructionBuilder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,10 @@ public static function default_system_instruction(): string {
569569
. "- **To set a static front page:** (1) Create a page titled \"Home\" or similar using `sd-ai-agent/create-post` with post_type=\"page\". (2) Get its post ID from the response. (3) Use `sd-ai-agent/update-option` twice: first with option_name=\"show_on_front\" and option_value=\"page\", then with option_name=\"page_on_front\" and option_value=<post_id>.\n"
570570
. "- **To create and assign a navigation menu:** (1) Use `sd-ai-agent/create-menu` with the menu name (e.g. \"Main Menu\"). (2) Add menu items using `sd-ai-agent/add-menu-item` for each page/link. (3) Assign the menu to a theme location using `sd-ai-agent/assign-menu-location` (e.g. location=\"primary\" or \"header\").\n"
571571
. "- Always verify these settings are actually applied before claiming completion.\n\n"
572+
. "## Launch-quality website checks (MANDATORY)\n"
573+
. "- Do not leave theme starter content in a client site. Inspect the rendered header and footer after building. Remove or replace every placeholder label/link (for example Careers, Brand Assets, Features, Pricing, Demo, Visit Ollie, or links to the theme vendor) unless it points to a real page or a URL the user explicitly supplied. Every visible footer link must resolve to an existing published page or a valid intended external URL; remove unsupported links rather than inventing destinations.\n"
574+
. "- After creating a contact form, insert the returned `block` or `shortcode` into the Contact/booking page with `sd-ai-agent/update-post`, then fetch the public page and verify the form is actually rendered. Submit a test payload when the environment permits it. If mail transport, recipient suppression, or SMTP configuration prevents delivery, report that exact limitation and do not claim the form is working; preserve the visitor's email as Reply-To and use a same-domain From address.\n"
575+
. "- Before reporting completion, crawl the public pages you created (including the footer) and check internal links, form presence, heading structure, and absence of sample/theme-vendor content. Fix failures and re-check rather than merely describing them.\n\n"
572576
. "## Tips\n"
573577
. "- Chain operations: create content first, then configure settings.\n"
574578
. "- After completing all steps, summarize what was done with links to the created resources.\n\n"

tests/SdAiAgent/Core/SystemInstructionBuilderTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ public function test_default_system_instruction_includes_site_configuration_guid
8383
$instruction,
8484
'System instruction should include honesty principle about claiming completion'
8585
);
86+
$this->assertStringContainsString( 'Launch-quality website checks (MANDATORY)', $instruction );
87+
$this->assertStringContainsString( 'placeholder label/link', $instruction );
88+
$this->assertStringContainsString( 'same-domain From address', $instruction );
8689
}
8790

8891
/**

0 commit comments

Comments
 (0)