| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Subscribers.com |
| 4 |
Plugin URI: https://subscribers.com/ |
| 5 |
Description: Subscribers.com lets you send push notifications from your desktop or mobile website to your users. |
| 6 |
Simply enable the plugin and start collecting subscribers for your Subscribers account. |
| 7 |
Visit <a href="https://subscribers.com/">Subscribers</a> for more details. |
| 8 |
Author: Subscribers.com |
| 9 |
Version: 1.2 |
| 10 |
screenshot.png |
| 11 |
subscribers.php |
| 12 |
Author URI: https://subscribers.com |
| 13 |
|
| 14 |
This relies on the actions being present in the themes header.php and footer.php |
| 15 |
* header.php code before the closing </head> tag |
| 16 |
* wp_head(); |
| 17 |
* |
| 18 |
*/ |
| 19 |
|
| 20 |
//------------------------------------------------------------------------// |
| 21 |
//---Config---------------------------------------------------------------// |
| 22 |
//------------------------------------------------------------------------// |
| 23 |
|
| 24 |
require_once("config.php"); |
| 25 |
|
| 26 |
$subscribers_embed_script = <<<HTML |
| 27 |
<!-- Start Subscriber Embed Code --> |
| 28 |
<script type="text/javascript"> |
| 29 |
var subscribersSiteId = 'SUBSCRIBER_ID'; |
| 30 |
var subscribersServiceWorkerPath = '/?firebase-messaging-sw'; |
| 31 |
</script> |
| 32 |
<script type="text/javascript" src="https://$subscribers_cdn_host/assets/subscribers.js"></script> |
| 33 |
<!-- End Subscriber Embed Code --> |
| 34 |
HTML; |
| 35 |
|
| 36 |
//------------------------------------------------------------------------// |
| 37 |
//---Hook-----------------------------------------------------------------// |
| 38 |
//------------------------------------------------------------------------// |
| 39 |
add_action( 'wp_footer', 'subscribers_headercode', 1 ); |
| 40 |
add_action( 'admin_menu', 'subscribers_plugin_menu' ); |
| 41 |
add_action( 'admin_init', 'subscribers_register_mysettings' ); |
| 42 |
add_action( 'admin_notices', 'subscribers_warn_nosettings' ); |
| 43 |
|
| 44 |
//------------------------------------------------------------------------// |
| 45 |
//---Functions------------------------------------------------------------// |
| 46 |
//------------------------------------------------------------------------// |
| 47 |
// options page link |
| 48 |
function subscribers_plugin_menu() { |
| 49 |
add_options_page('Subscribers', 'Subscribers', 'create_users', 'subscribers_options', 'subscribers_plugin_options'); |
| 50 |
} |
| 51 |
|
| 52 |
// whitelist settings |
| 53 |
function subscribers_register_mysettings(){ |
| 54 |
register_setting('subscribers_options','subscribers_hash'); |
| 55 |
} |
| 56 |
|
| 57 |
//------------------------------------------------------------------------// |
| 58 |
//---Add "Settings" link to plugin Page-----------------------------------// |
| 59 |
//------------------------------------------------------------------------// |
| 60 |
function subscribers_plugin_settings_link($links) { |
| 61 |
$settings_link = '<a href="options-general.php?page=subscribers_options">Settings</a>'; |
| 62 |
array_unshift($links, $settings_link); |
| 63 |
return $links; |
| 64 |
} |
| 65 |
|
| 66 |
$plugin = plugin_basename(__FILE__); |
| 67 |
add_filter("plugin_action_links_$plugin", 'subscribers_plugin_settings_link' ); |
| 68 |
|
| 69 |
//------------------------------------------------------------------------// |
| 70 |
//---Redirect to Settings page after activation---------------------------// |
| 71 |
//------------------------------------------------------------------------// |
| 72 |
register_activation_hook(__FILE__, 'subscribers_plugin_activate'); |
| 73 |
add_action('admin_init', 'subscribers_plugin_redirect'); |
| 74 |
|
| 75 |
function subscribers_plugin_activate() { |
| 76 |
add_option('subscribers_plugin_do_activation_redirect', true); |
| 77 |
} |
| 78 |
|
| 79 |
function subscribers_plugin_redirect() { |
| 80 |
if (get_option('subscribers_plugin_do_activation_redirect', false)) { |
| 81 |
delete_option('subscribers_plugin_do_activation_redirect'); |
| 82 |
// Do not redirect if activated as part of a bulk activate |
| 83 |
if(!isset($_GET['activate-multi'])) { |
| 84 |
wp_redirect("options-general.php?page=subscribers_options"); |
| 85 |
// wp_redirect() does not exit automatically and should almost always be followed by exit. |
| 86 |
exit; |
| 87 |
} |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
//------------------------------------------------------------------------// |
| 92 |
//---Serving service worker-----------------------------------------------// |
| 93 |
//------------------------------------------------------------------------// |
| 94 |
add_action( 'parse_request', 'subscribers_service_worker' ); |
| 95 |
add_filter( 'query_vars', 'subscribers_query_vars' ); |
| 96 |
|
| 97 |
function subscribers_query_vars($vars) { |
| 98 |
$vars[] = 'firebase-messaging-sw'; |
| 99 |
return $vars; |
| 100 |
} |
| 101 |
|
| 102 |
// Served at `/?firebase-messaging-sw`. Needs to be at the top level in order |
| 103 |
// to be registered at the correct scope. |
| 104 |
function subscribers_service_worker($query) { |
| 105 |
if ( isset( $query->query_vars['firebase-messaging-sw'] ) ) { |
| 106 |
header( 'Content-Type: application/javascript' ); |
| 107 |
include( 'firebase-messaging-sw.js.php' ); |
| 108 |
exit; |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
//------------------------------------------------------------------------// |
| 113 |
//---Output Functions-----------------------------------------------------// |
| 114 |
//------------------------------------------------------------------------// |
| 115 |
function subscribers_headercode(){ |
| 116 |
// runs in the header |
| 117 |
global $subscribers_embed_script; |
| 118 |
$subscribers_hash = get_option('subscribers_hash'); |
| 119 |
|
| 120 |
if($subscribers_hash){ |
| 121 |
echo str_replace('SUBSCRIBER_ID', $subscribers_hash, $subscribers_embed_script); // only output if options were saved |
| 122 |
} |
| 123 |
} |
| 124 |
//------------------------------------------------------------------------// |
| 125 |
//---Page Output Functions------------------------------------------------// |
| 126 |
//------------------------------------------------------------------------// |
| 127 |
// options page |
| 128 |
function subscribers_plugin_options() { |
| 129 |
?> |
| 130 |
<div class="wrap"> |
| 131 |
<h2>Subscribers - Free Web Push Notifications</h2> |
| 132 |
<p> |
| 133 |
The Subscribers plugin will insert the necessary code into your Wordpress site just before the closing |
| 134 |
<code></body></code> tag. This will allow the subscribe popup and chicklet to be placed on your page so your |
| 135 |
visitors can subscribe. |
| 136 |
</p> |
| 137 |
<p> |
| 138 |
In order to use this plugin, you need to have a Subscribers account. Please |
| 139 |
<a target="_blank" href="https://app.subscribers.com/users/signup">sign up here</a> if you do not already have one. |
| 140 |
</p> |
| 141 |
<p> |
| 142 |
Once you sign in to your Subscribers account please click on the link in the header that says “Install the code |
| 143 |
on your site” and scroll down to where your Site ID is displayed. Copy that ID and paste it into the field |
| 144 |
below and click Save changes. |
| 145 |
</p> |
| 146 |
|
| 147 |
<form method="post" action="options.php"> |
| 148 |
<?php settings_fields( 'subscribers_options' ); ?> |
| 149 |
<?php do_settings_sections( 'subscribers_options' ); ?> |
| 150 |
|
| 151 |
<label for="subscribers_hash" style="font-size: 120%; display: block; margin-top: 2em;">Your Subscriber Site ID:</label> |
| 152 |
<input type="text" id="subscribers_hash" name="subscribers_hash" value="<?php echo get_option('subscribers_hash'); ?>" style="margin-top: 0.5em;" size="50"/> |
| 153 |
|
| 154 |
<?php submit_button(); ?> |
| 155 |
</form> |
| 156 |
|
| 157 |
<p> |
| 158 |
After you save your Site ID above, go to the homepage of your website, right click somewhere on the page and click |
| 159 |
on "View page source." A new tab will open with the code for your site. |
| 160 |
</p> |
| 161 |
|
| 162 |
<p> |
| 163 |
Next press CTRL+F (or Command+F on macOS) on your keyboard and type in "Subscriber" and if you see something like |
| 164 |
this, then you know the code has been added properly. This can take a few minutes to show up. If you have a caching |
| 165 |
plugin installed, you might need to clear your cache. |
| 166 |
</p> |
| 167 |
|
| 168 |
<img src="<?php echo plugins_url('/images/source-code-success-1x.png', __FILE__); ?>" alt="Example code" style="max-width: 100%;" /> |
| 169 |
|
| 170 |
<h3>What are web push notifications?</h3> |
| 171 |
|
| 172 |
<img src="<?php echo plugins_url('/images/pc_with_notifications-1x.png', __FILE__); ?>" alt="PC with notifications" style="max-width: 100%;" /> |
| 173 |
|
| 174 |
<p> |
| 175 |
Web push notifications are the digital marketing world’s newest best friend. They allow you to send instant |
| 176 |
notifications, similar to those found on your smartphone to your subscribers’ devices. |
| 177 |
</p> |
| 178 |
<p> |
| 179 |
This is an ideal solution for marketers looking for a new and very effective channel to reach your audience about |
| 180 |
news, sales, order status, special offers, empty shopping cart links, new content, events or anything else you can |
| 181 |
think of. |
| 182 |
</p> |
| 183 |
<p> |
| 184 |
Conversion rates, opt-in rates, and click-through rates are all returning much higher results than traditional email |
| 185 |
marketing. Don’t wait and get started today, it’s super easy to get it installed and running on your site. |
| 186 |
</p> |
| 187 |
<p> |
| 188 |
To enable it for your Wordpress site, <a target="_blank" href="https://app.subscribers.com/users/signup">sign up for free here.</a> And |
| 189 |
don’t hesitate to reach out directly to us at <a href="mailto:support@subscribers.com">support@subscribers.com</a> |
| 190 |
</p> |
| 191 |
</div> |
| 192 |
|
| 193 |
<?php |
| 194 |
} |
| 195 |
|
| 196 |
function subscribers_warn_nosettings(){ |
| 197 |
if (!is_admin()) |
| 198 |
return; |
| 199 |
|
| 200 |
$subscribers_option = get_option("subscribers_hash"); |
| 201 |
if (!$subscribers_option){ |
| 202 |
echo '<div class="updated fade"><p><strong>Subscribers is almost ready.</strong> You must <a href="options-general.php?page=subscribers_options">enter your Site ID</a> for it to work.</p></div>'; |
| 203 |
} |
| 204 |
} |
| 205 |
|