Skip to content

Instantly share code, notes, and snippets.

@evansolomon
Created December 3, 2012 11:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evansolomon/4194263 to your computer and use it in GitHub Desktop.
Save evansolomon/4194263 to your computer and use it in GitHub Desktop.
Custom signup form for Jetpack subscriptions
<?php
/*
Plugin Name: Jetpack Subscribe
Description: Custom subscription UI for Jetpack
Version: 1.0
Author: Evan Solomon
Author URI: http://evansolomon.me/
*/
class ES_Jetpack_Subscribe {
private static $instance;
static function get_instance() {
if ( ! self::$instance )
self::$instance = new ES_Jetpack_Subscribe;
return self::$instance;
}
private function __construct() {
add_action( 'wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ) );
add_action( 'cogitate_after_entry_meta', array( $this, 'render_form' ) );
}
public function is_enabled() {
// Only using the form on single pages
return apply_filters( 'es_jetpack_subscribe_is_enabled', is_single() );
}
public function wp_enqueue_scripts() {
if ( $this->is_enabled() )
$this->enqueue_style();
}
public function enqueue_style() {
wp_enqueue_style( __CLASS__, plugins_url( '/style.css', __FILE__ ) );
}
/**
* Mostly copied from jetpack/modules/subscriptions.php
*/
public function get_form() {
// Presumably used by Jetpack server
$referer = ( is_ssl() ? 'https' : 'http' ) . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$source = 'jetpack_custom_subscribe';
// Text fields
$header = apply_filters( 'es_jetpack_subscribe_form_header', "Want to get this magic in your inbox?" );
$email_placeholder = apply_filters( 'es_jetpack_subscribe_form_email', "Your electronic mail address" );
$button = apply_filters( 'es_jetpack_subscribe_form_button', "Please don't spam me" );
$form = '<form action="" method="POST" accept-charset="utf-8" id="subscribe-blog">';
if ( ! isset ( $_GET['subscribe'] ) )
$form .= sprintf( '<p class="subscribe-title">%s</p>', esc_html( $header ) );
$form .= sprintf( '<p>%s%s</p>',
sprintf( '<input type="text" name="email" id="subscribe-field" placeholder="%s" />', esc_attr( $email_placeholder ) ),
sprintf( '<input type="submit" value="%s" name="jetpack_subscriptions_widget" id="subscribe-submit" />', esc_attr( $button ) )
);
// Jetpack stuff
$hidden = '<input type="hidden" name="action" value="subscribe" />';
$hidden .= sprintf( '<input type="hidden" name="source" value="%s" />', esc_url( $referer ) );
$hidden .= sprintf( '<input type="hidden" name="sub-type" value="%s" />', esc_attr( $source ) );
// Append to the form
$form .= sprintf( '<p>%s</p>', $hidden );
$form .= '</form>';
return apply_filters( 'es_jetpack_subscribe_form', "<div class='jetpack-subscribe-form'>{$form}</div>" );
}
public function render_form() {
if ( $this->is_enabled() )
echo $this->get_form();
}
}
// Run the constructor
ES_Jetpack_Subscribe::get_instance();
#subscribe-blog {
width: 40%;
min-width: 250px;
margin: 30px auto;
}
.subscribe-title {
font-size: 16px;
font-family: jaf-domus-titling-web, 'Open Sans', Helvetica, Arial, sans-serif;
margin: 0 0 10px;
padding-top: 5px;
border-top: 4px double #F38630;
}
#subscribe-field {
width: 96%;
padding: 6px;
margin: 2px 0;
font-size: 30px;
}
#subscribe-submit {
display: block;
width: 80%;
min-width: 50px;
margin: 2px auto;
font-size: 16px;
}
@media (max-width: 1050px) {
.subscribe-title {
font-size: 14px;
}
#subscribe-field {
font-size: 20px;
}
}
@media (max-width: 770px) {
.subscribe-title {
font-size: 12px;
}
#subscribe-field {
font-size: 16px;
}
}
@media (max-width: 600px) {
#subscribe-submit {
font-size: 14px;
}
}
@himerge
Copy link

himerge commented May 20, 2021

Thanks, it works for my website Correctvibe , only made some changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment