$id,
'enabled' => ! empty( $b['enabled'] ),
'style' => $style,
'label' => $label,
'placement' => $placement,
);
}
/**
* wp_footer callback: auto-inject the badge when placement is "footer".
*/
public function maybe_render_footer() {
if ( self::$rendered ) {
return;
}
if ( is_admin() || is_feed() || is_preview() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
return;
}
$c = $this->get_config();
// Deliberately NOT gated on having an affiliate ID. Someone who wants to
// credit us should be able to, whether or not they have signed up to the
// affiliate programme yet. Without an ID it is simply a plain link with
// no referral attribution, which costs them nothing and still helps us.
if ( ! $c['enabled'] || 'footer' !== $c['placement'] ) {
return;
}
// build_html() escapes every dynamic part.
echo '
' . $this->build_html( $c ) . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
* [aeo_badge] shortcode for manual placement.
*
* @param array $atts Shortcode attributes.
* @return string
*/
public function shortcode( $atts ) {
if ( is_admin() ) {
return '';
}
$c = $this->get_config();
if ( ! $c['enabled'] || 'off' === $c['placement'] ) {
return '';
}
$atts = shortcode_atts( array( 'style' => $c['style'] ), $atts, 'aeo_badge' );
if ( in_array( $atts['style'], array( 'light', 'dark', 'minimal' ), true ) ) {
$c['style'] = $atts['style'];
}
return $this->build_html( $c );
}
/**
* Build the badge anchor (with the inline CSS prepended on first output).
*
* @param array $c Config.
* @return string
*/
private function build_html( $c ) {
self::$rendered = true;
// With an ID the link goes through the referral path so the click can be
// attributed. Without one it points at the plain homepage: still a real
// link, just no commission, rather than no badge at all.
$base = ( '' !== $c['id'] )
? self::VENDOR_BASE . rawurlencode( $c['id'] ) . '/'
: self::VENDOR_HOME;
$url = add_query_arg(
array(
'campaign' => 'badge',
'utm_source' => 'badge',
'utm_medium' => 'plugin',
),
$base
);
$bolt = '';
/*
* rel is hardcoded "nofollow sponsored noopener" on purpose and is NOT
* exposed in the UI. AffiliateWP attributes commission from the click +
* its 45-day cookie, not from passed link equity, so nofollow costs zero
* commission. Thousands of identical dofollow badge links would read as a
* link scheme to Google and endanger aeogodmode.io's own rankings, which
* contradicts the product's anti-SEO-gaming brand. Do not make this
* configurable. See WordPress.org Plugin Guideline 12.
*/
$anchor = sprintf(
'%3$s%4$s (%5$s)',
esc_attr( $c['style'] ),
esc_url( $url ),
$bolt,
esc_html( $c['label'] ),
esc_html__( 'opens in a new tab', 'aeo-god-mode' )
);
return $this->css() . $anchor;
}
/**
* Inline CSS, printed once per request.
*
* @return string
*/
private function css() {
if ( self::$css_done ) {
return '';
}
self::$css_done = true;
$css = '.aeo-godmode-badge{display:inline-flex;align-items:center;gap:6px;padding:6px 10px;border-radius:6px;font-family:inherit;font-size:12px;font-weight:600;line-height:1;text-decoration:none;box-sizing:border-box;border:1px solid transparent;vertical-align:middle;transition:opacity .15s ease}'
. '.aeo-godmode-badge .aeo-godmode-badge__mark{flex:0 0 auto}'
. '.aeo-godmode-badge:hover{opacity:.85}'
. '.aeo-godmode-badge:focus-visible{outline:2px solid #338dff;outline-offset:2px}'
. '.aeo-godmode-badge--light{background:#fff;color:#1f2937;border-color:#e5e7eb}'
. '.aeo-godmode-badge--light .aeo-godmode-badge__mark{color:#338dff}'
. '.aeo-godmode-badge--dark{background:#0f172a;color:#f8fafc;border-color:#0f172a}'
. '.aeo-godmode-badge--dark .aeo-godmode-badge__mark{color:#fff}'
. '.aeo-godmode-badge--minimal{background:transparent;color:#6b7280;padding:4px 0;border:0}'
. '.aeo-godmode-badge--minimal .aeo-godmode-badge__mark{color:#338dff}'
. '.aeo-godmode-badge--minimal:hover{text-decoration:underline;opacity:1}';
return '';
}
}