&lt;?php
/**
 * gc-pdf-gate.php
 * Persistent mu-plugin — PDF opt-in gate shortcode for gothamCulture
 * Deployed: 2026-05-26  Updated: 2026-05-26 (ob_start safety net)
 *
 * Usage: [gc_pdf_gate pdf_url=&quot;https://...&quot; pdf_name=&quot;Guide Title&quot;]
 * On form submit: stores lead in WP options, emails Chris, redirects to PDF.
 */

// ── SHORTCODE ────────────────────────────────────────────────────────────────

add_shortcode(&#39;gc_pdf_gate&#39;, function($atts) {
    $atts = shortcode_atts([
        &#39;pdf_url&#39;      =&gt; &#39;&#39;,
        &#39;pdf_name&#39;     =&gt; &#39;PDF Guide&#39;,
        &#39;notify_email&#39; =&gt; &#39;chris.cancialosi@gothamculture.com&#39;,
        &#39;heading&#39;      =&gt; &#39;Download Your Free Guide&#39;,
        &#39;subtext&#39;      =&gt; &#39;&#39;,
        &#39;btn_label&#39;    =&gt; &#39;Download Now →&#39;,
    ], $atts);

    if (!$atts[&#39;pdf_url&#39;]) return &#39;&lt;p&gt;Error: no pdf_url specified.&lt;/p&gt;&#39;;

    ob_start();
    ?&gt;
    &lt;div class=&quot;gc-pdf-gate&quot; style=&quot;max-width:480px;margin:32px auto;padding:36px 32px;background:#f4f7f0;border-radius:10px;border:1px solid #dde8cc;font-family:&#39;Lato&#39;,sans-serif;&quot;&gt;
        &lt;h3 style=&quot;font-family:&#39;Roboto Slab&#39;,Georgia,serif;color:#096E38;margin:0 0 10px;font-size:1.35em;line-height:1.3;&quot;&gt;&lt;?php echo esc_html($atts[&#39;heading&#39;]); ?&gt;&lt;/h3&gt;
        &lt;?php if ($atts[&#39;subtext&#39;]): ?&gt;
        &lt;p style=&quot;color:#4B4F53;margin:0 0 20px;font-size:0.95em;line-height:1.5;&quot;&gt;&lt;?php echo esc_html($atts[&#39;subtext&#39;]); ?&gt;&lt;/p&gt;
        &lt;?php else: ?&gt;
        &lt;p style=&quot;color:#4B4F53;margin:0 0 20px;font-size:0.95em;line-height:1.5;&quot;&gt;
            Enter your name and work email to get instant access to &lt;strong&gt;&lt;?php echo esc_html($atts[&#39;pdf_name&#39;]); ?&gt;&lt;/strong&gt;.
        &lt;/p&gt;
        &lt;?php endif; ?&gt;
        &lt;form method=&quot;post&quot; action=&quot;&lt;?php echo esc_url(admin_url(&#39;admin-post.php&#39;)); ?&gt;&quot; novalidate&gt;
            &lt;input type=&quot;hidden&quot; name=&quot;action&quot;       value=&quot;gc_pdf_gate_submit&quot;&gt;
            &lt;input type=&quot;hidden&quot; name=&quot;pdf_url&quot;      value=&quot;&lt;?php echo esc_attr($atts[&#39;pdf_url&#39;]); ?&gt;&quot;&gt;
            &lt;input type=&quot;hidden&quot; name=&quot;pdf_name&quot;     value=&quot;&lt;?php echo esc_attr($atts[&#39;pdf_name&#39;]); ?&gt;&quot;&gt;
            &lt;input type=&quot;hidden&quot; name=&quot;notify_email&quot; value=&quot;&lt;?php echo esc_attr($atts[&#39;notify_email&#39;]); ?&gt;&quot;&gt;
            &lt;?php wp_nonce_field(&#39;gc_pdf_gate_nonce&#39;, &#39;_wpnonce&#39;); ?&gt;
            &lt;div style=&quot;display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-bottom:14px;&quot;&gt;
                &lt;div&gt;
                    &lt;label style=&quot;display:block;font-weight:700;font-size:0.85em;color:#2a2d2f;margin-bottom:5px;&quot;&gt;First Name *&lt;/label&gt;
                    &lt;input type=&quot;text&quot; name=&quot;first_name&quot; required autocomplete=&quot;given-name&quot;
                           style=&quot;width:100%;padding:10px 12px;border:1px solid #b8c9a0;border-radius:5px;font-size:0.95em;font-family:inherit;box-sizing:border-box;&quot;&gt;
                &lt;/div&gt;
                &lt;div&gt;
                    &lt;label style=&quot;display:block;font-weight:700;font-size:0.85em;color:#2a2d2f;margin-bottom:5px;&quot;&gt;Last Name *&lt;/label&gt;
                    &lt;input type=&quot;text&quot; name=&quot;last_name&quot; required autocomplete=&quot;family-name&quot;
                           style=&quot;width:100%;padding:10px 12px;border:1px solid #b8c9a0;border-radius:5px;font-size:0.95em;font-family:inherit;box-sizing:border-box;&quot;&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div style=&quot;margin-bottom:14px;&quot;&gt;
                &lt;label style=&quot;display:block;font-weight:700;font-size:0.85em;color:#2a2d2f;margin-bottom:5px;&quot;&gt;Work Email *&lt;/label&gt;
                &lt;input type=&quot;email&quot; name=&quot;email&quot; required autocomplete=&quot;email&quot; placeholder=&quot;you@yourcompany.com&quot;
                       style=&quot;width:100%;padding:10px 12px;border:1px solid #b8c9a0;border-radius:5px;font-size:0.95em;font-family:inherit;box-sizing:border-box;&quot;&gt;
            &lt;/div&gt;
            &lt;div style=&quot;margin-bottom:16px;&quot;&gt;
                &lt;label style=&quot;display:block;font-weight:700;font-size:0.85em;color:#2a2d2f;margin-bottom:5px;&quot;&gt;Organization&lt;/label&gt;
                &lt;input type=&quot;text&quot; name=&quot;organization&quot; autocomplete=&quot;organization&quot;
                       style=&quot;width:100%;padding:10px 12px;border:1px solid #b8c9a0;border-radius:5px;font-size:0.95em;font-family:inherit;box-sizing:border-box;&quot;&gt;
            &lt;/div&gt;
            &lt;button type=&quot;submit&quot;
                    style=&quot;width:100%;padding:13px;background:#91C53D;color:#fff;border:none;border-radius:5px;font-weight:700;font-size:1em;cursor:pointer;font-family:inherit;letter-spacing:0.3px;transition:background 0.2s;&quot;
                    onmouseover=&quot;this.style.background=&#39;#096E38&#39;&quot; onmouseout=&quot;this.style.background=&#39;#91C53D&#39;&quot;&gt;
                &lt;?php echo esc_html($atts[&#39;btn_label&#39;]); ?&gt;
            &lt;/button&gt;
            &lt;p style=&quot;font-size:0.75em;color:#6b7075;margin:12px 0 0;text-align:center;line-height:1.4;&quot;&gt;
                We respect your privacy and won&#39;t share your information. No spam — ever.
            &lt;/p&gt;
        &lt;/form&gt;
    &lt;/div&gt;
    &lt;?php
    return ob_get_clean();
});


// ── OUTPUT BUFFER: catch any remaining direct PDF links in rendered HTML ──
// Runs at template_redirect (before output), catches Elementor-rendered links
// that bypass the_content filter. Belt-and-suspenders for CDN/cache edge cases.

add_action(&#39;template_redirect&#39;, function() {
    $pdf_url  = &#39;https://gothamculture.com/wp-content/uploads/org-culture-guide-internal-dl.pdf&#39;;
    $gate_url = home_url(&#39;/download-organizational-culture-guide/&#39;);
    ob_start(function($html) use ($pdf_url, $gate_url) {
        if (strpos($html, $pdf_url) !== false) {
            $html = str_replace($pdf_url, $gate_url, $html);
        }
        return $html;
    });
});


// ── FORM HANDLER ─────────────────────────────────────────────────────────────

add_action(&#39;admin_post_nopriv_gc_pdf_gate_submit&#39;, &#39;gc_pdf_gate_handle&#39;);
add_action(&#39;admin_post_gc_pdf_gate_submit&#39;,        &#39;gc_pdf_gate_handle&#39;);

function gc_pdf_gate_handle() {
    if (!isset($_POST[&#39;_wpnonce&#39;]) || !wp_verify_nonce($_POST[&#39;_wpnonce&#39;], &#39;gc_pdf_gate_nonce&#39;)) {
        wp_die(&#39;Security check failed.&#39;, &#39;Error&#39;, [&#39;response&#39; =&gt; 403, &#39;back_link&#39; =&gt; true]);
    }

    $pdf_url      = isset($_POST[&#39;pdf_url&#39;])      ? esc_url_raw(trim($_POST[&#39;pdf_url&#39;]))        : &#39;&#39;;
    $pdf_name     = isset($_POST[&#39;pdf_name&#39;])      ? sanitize_text_field($_POST[&#39;pdf_name&#39;])     : &#39;PDF&#39;;
    $first_name   = isset($_POST[&#39;first_name&#39;])    ? sanitize_text_field($_POST[&#39;first_name&#39;])   : &#39;&#39;;
    $last_name    = isset($_POST[&#39;last_name&#39;])     ? sanitize_text_field($_POST[&#39;last_name&#39;])    : &#39;&#39;;
    $email        = isset($_POST[&#39;email&#39;])         ? sanitize_email($_POST[&#39;email&#39;])             : &#39;&#39;;
    $organization = isset($_POST[&#39;organization&#39;])  ? sanitize_text_field($_POST[&#39;organization&#39;]) : &#39;&#39;;
    $notify       = isset($_POST[&#39;notify_email&#39;])  ? sanitize_email($_POST[&#39;notify_email&#39;])      : &#39;chris.cancialosi@gothamculture.com&#39;;

    if (!$pdf_url || !$first_name || !$email || !is_email($email)) {
        wp_die(&#39;Please fill in all required fields.&#39;, &#39;Missing Information&#39;, [&#39;response&#39; =&gt; 400, &#39;back_link&#39; =&gt; true]);
    }

    if (!empty($_POST[&#39;website&#39;])) { wp_redirect($pdf_url); exit; }

    $leads   = get_option(&#39;gc_pdf_gate_leads&#39;, []);
    $leads[] = [
        &#39;first_name&#39;   =&gt; $first_name,
        &#39;last_name&#39;    =&gt; $last_name,
        &#39;email&#39;        =&gt; $email,
        &#39;organization&#39; =&gt; $organization,
        &#39;pdf&#39;          =&gt; $pdf_name,
        &#39;ts&#39;           =&gt; current_time(&#39;mysql&#39;),
        &#39;ip&#39;           =&gt; isset($_SERVER[&#39;REMOTE_ADDR&#39;]) ? sanitize_text_field($_SERVER[&#39;REMOTE_ADDR&#39;]) : &#39;&#39;,
        &#39;referrer&#39;     =&gt; isset($_SERVER[&#39;HTTP_REFERER&#39;]) ? esc_url_raw($_SERVER[&#39;HTTP_REFERER&#39;]) : &#39;&#39;,
    ];
    update_option(&#39;gc_pdf_gate_leads&#39;, array_slice($leads, -1000));

    $subject = &quot;New PDF lead: {$pdf_name}&quot;;
    $body    = &quot;New download from gothamCulture.com PDF gate:\n\n&quot;
             . &quot;Name:         {$first_name} {$last_name}\n&quot;
             . &quot;Email:        {$email}\n&quot;
             . &quot;Organization: {$organization}\n&quot;
             . &quot;PDF:          {$pdf_name}\n&quot;
             . &quot;Time:         &quot; . current_time(&#39;mysql&#39;) . &quot;\n&quot;
             . &quot;IP:           &quot; . (isset($_SERVER[&#39;REMOTE_ADDR&#39;]) ? $_SERVER[&#39;REMOTE_ADDR&#39;] : &#39;n/a&#39;) . &quot;\n&quot;
             . &quot;Referrer:     &quot; . (isset($_SERVER[&#39;HTTP_REFERER&#39;]) ? $_SERVER[&#39;HTTP_REFERER&#39;] : &#39;direct&#39;) . &quot;\n&quot;;
    $headers = [&#39;Content-Type: text/plain; charset=UTF-8&#39;, &#39;From: gothamCulture Site &lt;noreply@gothamculture.com&gt;&#39;];
    wp_mail($notify, $subject, $body, $headers);

    wp_redirect($pdf_url);
    exit;
}
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//gothamculture.com/wp-content/plugins/wordpress-seo/css/main-sitemap.xsl"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
		<loc>https://gothamculture.com/post-sitemap.xml</loc>
		<lastmod>2026-05-26T16:43:06+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://gothamculture.com/page-sitemap.xml</loc>
		<lastmod>2026-06-09T23:11:55+00:00</lastmod>
	</sitemap>
</sitemapindex>
<!-- XML Sitemap generated by Yoast SEO -->