Skip to main content

Email Subscription Form — Lead Magnet

WPCodeBox Snippet Reference

PropertyValue
Snippet ID2
TitleOpshell Subscribe Shortcode
TypePHP
Run Typealways
Code Length~12.3 KB
Hookcustom_root (priority 10)
Statusenabled

Shortcode Usage

[opshell_subscribe type="terminal"]
[opshell_subscribe type="benefits"]
AttributeValuesDefaultDescription
typeterminal, benefitsterminalRender mode for the form

Terminal Mode (active)

$ subscribe --access
Access our essential protected content — download scripts, Ansible playbooks,
CI/CD templates, cheat sheets, and more.

[Your name ] [your@email.com ] [Subscribe →]

Benefits Mode (draft — ID 9581)

$ unlock --toolkit
Access our essential protected content:

▸ 15 Linux automation scripts ▸ 5 Ansible playbooks
▸ CI/CD pipeline templates ▸ Opshell cheat sheets

[Your name ] [your@email.com ] [Unlock Access →]

Form Fields

FieldName AttributeTypeRequired
Honeypotops_hptext (hidden)No (anti-spam)
Nonceops_subscribe_noncehiddenYes (CSRF)
Nameops_subscribe_nametextYes
Emailops_subscribe_emailemailYes

Data Flow

Security Layers

LayerTypePurpose
HoneypotHidden fieldCatches automated bots
NonceWordPressCSRF protection
ReoonEmail verificationValidates deliverable email (reuses API key from contact form)
Input sanitizationPHP functionsPrevents XSS and injection

Storage

  • Successful subscriptions: /opshell-subscribers/subscribers.csv
  • Failed verifications: /opshell-subscribers/failed-verifications.csv
  • Directory created at dirname(ABSPATH, 2) . "/opshell-subscribers"
  • Index.php added to prevent directory listing
  • CSV columns: no, timestamp, name, email, ip (the no is a sequential subscriber number)

subscribers.csv

no,timestamp,name,email,ip
1,2026-06-30 12:30:21,John Doe,john@example.com,192.168.1.1

failed-verifications.csv

timestamp,name,email,ip,reason
2026-06-30 12:31:00,Spam Bot,spam@invalid.com,10.0.0.1,Email verification failed

Created on demand by opshell_save_failed_subscriber_csv() — it only exists once an email actually fails Reoon verification. Verified working in production 2026-08-09: submitting test@nonexistent-domain-12345.com (Reoon is_safe_to_send: false) appended a row with reason "Please use a valid, deliverable email address." while subscribers.csv stayed unchanged and no Telegram was sent.

Backup sync

The opshell-subscribers/ directory is synced every 15 minutes to /home/rezriz/github/subscriber/opshell.dev/ on GSM16 via sync-opshell-subscribers.sh (rsync, */15 cron). It pulls *.csv (including failed-verifications.csv once it exists) plus index.php.

Auto-Responder Email

Sent via SMTP (reuses SMTP settings from contact form):

FieldValue
Subject"Your access to Opshell essential content is ready"
FromConfigured via Contact Form SMTP settings
ContentHTML email with toolkit download link
GreetingHi {name}, if name provided, else "Hey there,"

Telegram Notification

On successful subscription, a Telegram notification is sent to a dedicated subscriber chat, separate from the contact-form channel (uses opshell_subscribe_telegram_bot_token and opshell_subscribe_telegram_chat_id options — the main bot and subscriber_notification group). It includes:

  • Subscriber No. (the no assigned in subscribers.csv)
  • Timestamp, IP Address, Name, Email

Sent via opshell_send_subscriber_telegram() using the Bot API sendMessage endpoint with HTML parse_mode.

Channel separation: subscriber and contact-form notifications use independent bots/chats.

FunctionPurpose
opshell_subscribe_dir()Creates/returns subscriber storage directory
opshell_count_subscriber_csv_rows()Counts data rows (record-based, handles multiline fields)
opshell_save_subscriber()Appends subscriber to CSV with flock locking, returns assigned no
opshell_save_failed_subscriber_csv()Logs failed Reoon verifications
opshell_subscribe_phpmailer()Configures PHPMailer with SMTP settings
opshell_send_subscriber_email()Sends auto-responder via SMTP
opshell_send_subscriber_telegram()Sends Telegram notification via Bot API
opshell_render_subscribe_form()Shortcode handler — renders form and processes submissions

CSS — Form Fields

The form fields use inline styles applied via PHP string concatenation in the shortcode. The styles mirror the contact form's .opshell-contact-form CSS.

Input Fields

/* Equivalent CSS (applied as inline styles in PHP) */
.opshell-subscribe-form input[type="text"],
.opshell-subscribe-form input[type="email"] {
padding: 12px 14px;
background: #010409;
border: 1px solid var(--ops-border);
border-radius: 6px;
color: var(--ops-text);
font-family: var(--ops-font-mono);
font-size: 0.95rem;
min-width: 0; /* Allow flex shrink */
}

.opshell-subscribe-form input[type="text"]:focus,
.opshell-subscribe-form input[type="email"]:focus {
border-color: var(--ops-accent-green);
outline: none;
box-shadow: 0 0 0 2px rgba(63, 185, 80, 0.12);
}

Flex Row Layout

The name, email, and button are placed in a single flex row with wrapping:

.opshell-subscribe-fields {
display: flex;
flex-wrap: wrap;
gap: 10px;
align-items: stretch; /* Match heights */
}

/* Name field — minimum 140px before wrap */
.opshell-subscribe-fields input[name="ops_subscribe_name"] {
flex: 1 1 140px;
}

/* Email field — minimum 180px before wrap */
.opshell-subscribe-fields input[name="ops_subscribe_email"] {
flex: 1 1 180px;
}
BreakpointLayout
> 650pxName
450–650pxName
< 450pxAll three stack vertically

Button (Solid Green)

/* Applied as inline styles with !important to override theme */
.opshell-subscribe-form button[type="submit"] {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 6px;
padding: 12px 22px;
border: 1px solid var(--ops-accent-green);
border-radius: 6px;
background: var(--ops-accent-green) !important;
color: var(--ops-bg) !important;
font-family: var(--ops-font-mono);
font-size: 0.95rem;
cursor: pointer;
transition: background-color 0.15s, border-color 0.15s;
}

.opshell-subscribe-form button[type="submit"]:hover {
background: #2ea043 !important;
}

Inline Style Source (PHP)

The button styles are set via a PHP variable in the WPCodeBox snippet:

$btn_style = "style=\"display:inline-flex;align-items:center;
justify-content:center;gap:6px;padding:12px 22px;
border:1px solid var(--ops-accent-green);border-radius:6px;
background:var(--ops-accent-green) !important;
color:var(--ops-bg) !important;
font-family:var(--ops-font-mono);font-size:0.95rem;
cursor:pointer;transition:background-color 0.15s,border-color 0.15s;\"";

Hover State (JavaScript fallback)

Since the inline style cannot use :hover, the hover effect is handled via onmouseover / onmouseout:

<button ... onmouseover="this.style.background='#2ea043'!important"
onmouseout="this.style.background='var(--ops-accent-green)'!important">
Subscribe
</button>

Success & Error Messages

.opshell-contact-success {
padding: 14px 18px;
margin-bottom: 20px;
border: 1px solid var(--ops-accent-green);
border-radius: 6px;
font-family: var(--ops-font-mono);
font-size: 0.9rem;
color: var(--ops-accent-green);
background: rgba(63, 185, 80, 0.06);
}

.opshell-contact-error {
padding: 14px 18px;
margin-bottom: 20px;
border: 1px solid var(--ops-danger);
border-radius: 6px;
font-family: var(--ops-font-mono);
font-size: 0.9rem;
color: var(--ops-danger);
background: rgba(248, 81, 73, 0.06);
}

Full PHP Snippet Source

The complete snippet code (ID 2) is stored in the wp_wpcb_snippets database table. Fetch it with WP-CLI:

wp db query --skip-column-names --raw 'SELECT code FROM wp_wpcb_snippets WHERE id=2' > /tmp/subscribe-code.php

Key functions:

FunctionPurpose
opshell_subscribe_dir()Creates/returns subscriber storage directory
opshell_count_subscriber_csv_rows()Counts data rows (record-based)
opshell_save_subscriber()Appends subscriber to CSV with flock locking, returns assigned no
opshell_save_failed_subscriber_csv()Logs failed Reoon verifications
opshell_subscribe_phpmailer()Configures PHPMailer with SMTP settings
opshell_send_subscriber_email()Sends auto-responder via SMTP
opshell_send_subscriber_telegram()Sends Telegram notification via Bot API
opshell_render_subscribe_form()Shortcode handler — renders form and processes submissions

Usage on Site

The shortcode is embedded inside the GP Element content (ID 9579) and rendered via GeneratePress Elements on the front page:

<section class="opshell-landing">
<div class="opshell-hero">
<div class="opshell-hero__terminal"><span class="opshell-prompt">$</span> opshell --mission</div>
<h1>Build, automate, and operate from the terminal.</h1>
<p class="opshell-hero__lead">Practical Linux, CLI, automation, DevOps, AI, and code workflows for builders who prefer the shell.</p>
[opshell_subscribe type="terminal"]
</div>
</section>