prefix . 'accept-signups`';
if($wpdb->get_var("SHOW TABLES LIKE '$tbl'") != $tbl) {
$sql = "CREATE TABLE " . $tbl . " (
email VARCHAR(255) NOT NULL,
ip VARCHAR(45) NOT NULL,
timestamp TIMESTAMP NOT NULL,
PRIMARY KEY (email)
);";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
}
}
register_activation_hook( __FILE__, 'acceptSignupsActivate' );
/**
* Deactivate
*/
function acceptSignupsDeactivate() {
# delete options..
delete_option('accept-signups-message');
delete_option('accept-signups-submit-text');
delete_option('accept-signups-email-field-size');
delete_option('accept-signups-error-message');
delete_option('accept-signups-email-already-exists');
delete_option('accept-signups-email-saved');
# drop table..
global $wpdb;
$tbl = '`' . DB_NAME . '`.`' . $wpdb->prefix . 'accept-signups`';
if($wpdb->get_var("SHOW TABLES LIKE '$tbl'") != $tbl) {
$sql = "DROP TABLE " . $tbl . ";";
$wpdb->query($sql);
}
}
register_deactivation_hook( __FILE__, 'acceptSignupsDeactivate' );
/**
* Initialize
*/
function setAcceptSignupsStyle() {
wp_register_style($handle = 'accept-signups', $src=plugins_url('/css/style.css', __FILE__));
wp_enqueue_style('accept-signups');
}
add_action('admin_print_styles', 'setAcceptSignupsStyle');
/**
* Generate signup form (shortcode)
*/
function acceptSignups() {
$ajax = '';
$html = '
' . getAcceptSignupsMessage() . '
';
return $ajax . $html;
}
add_shortcode('accept_signups', 'acceptSignups');
function getAcceptSignupsMessage() {
return get_option('accept-signups-message');
}
function getAcceptSignupsSubmitText() {
return get_option('accept-signups-submit-text');
}
function getAcceptSignupsEmailFieldSize() {
return get_option('accept-signups-email-field-size');
}
function getAcceptSignupsErrorMessage() {
return get_option('accept-signups-error-message');
}
/**
* Admin
*/
add_action('admin_menu', 'acceptSignupsAdmin');
function acceptSignupsAdmin() {
add_options_page('Accept Signups Options', 'Accept Signups', 'manage_options', 'accept-signup-options', 'acceptSignupsOptions');
}
function acceptSignupsOptions() {
if (!current_user_can('manage_options')) {
wp_die( __('You do not have sufficient permissions to access this page.') );
}
$html = '';
# Handle changed options..
if (isset($_POST["accept-signups-admin-options-message"])){
update_option('accept-signups-message', $_POST["accept-signups-admin-options-message"]);
}
if (isset($_POST["accept-signups-admin-options-message"])){
update_option('accept-signups-submit-text', $_POST["accept-signups-admin-options-submit"]);
}
if (isset($_POST["accept-signups-admin-options-message"])){
update_option('accept-signups-email-field-size', $_POST["accept-signups-admin-options-field-size"]);
}
if (isset($_POST["accept-signups-admin-options-message"])){
update_option('accept-signups-error-message', $_POST["accept-signups-error-message"]);
}
if (isset($_POST["accept-signups-admin-options-message"])){
update_option('accept-signups-email-already-exists', $_POST["accept-signups-email-already-exists"]);
}
if (isset($_POST["accept-signups-admin-options-message"])){
update_option('accept-signups-email-saved', $_POST["accept-signups-email-saved"]);
}
# Handle deleted signups..
if (isset($_POST["accept-signups-delete-form-call"])){
$msg = '';
$t1 = '';
foreach($_POST as $k=>$v) {
if ($v == 'on') {
$t1 = explode('?', $k);
$d[] = acceptSignupsDecode($t1[1]);
}
}
foreach($d as $k=>$v) {
$msg .= deleteEmail($v);
}
// echo $msg;
}
$html .= '
Accept signups
Accept signups by email. Logs email, IP and timestamp. All data available from admin panel. Intended for use with external subscription services or your own email client.
Usage
-
To create a sign-up post or page, insert this code snippet on the page or post: [accept_signups]
If you deactivate the plugin, the database table with all the emails of users who have signed up will be deleted.
Unless you also delete the Accept Signups plugin from the file system, you can still find the data in the Accept Signups plugins directory in the accept-signups.xml file or the accept-signups.csv file.
Settings
Customize the text snippets seen by the user:
Signups
' . acceptSignupsGetSignups() . '
';
acceptSignupsCreateXMLDoc();
acceptSignupsCreateCSVDoc();
echo $html;
}
function acceptSignupsCreateXMLDoc() {
global $wpdb;
$tbl = '`' . DB_NAME . '`.`' . $wpdb->prefix . 'accept-signups`';
$sql = 'select email, ip, timestamp from ' . $tbl . ' order by email;';
$r = $wpdb->get_results($sql, ARRAY_A);
$xml = '';
foreach($r as $k=>$v) {
$xml .= '';
}
$xml .= '';
file_put_contents(ABSPATH . 'wp-content/plugins/accept-signups/accept-signups.xml', $xml);
}
function acceptSignupsCreateCSVDoc() {
global $wpdb;
$tbl = '`' . DB_NAME . '`.`' . $wpdb->prefix . 'accept-signups`';
$sql = 'select email, ip, timestamp from ' . $tbl . ' order by email;';
$r = $wpdb->get_results($sql, ARRAY_A);
$csv = '';
foreach($r as $k=>$v) {
$csv .= $v["email"] . ',' . $v["ip"] . ',' . $v["timestamp"] . "\n";
}
file_put_contents(ABSPATH . 'wp-content/plugins/accept-signups/accept-signups.csv', $csv);
}
function acceptSignupsCreateCopyPasteList() {
global $wpdb;
$tbl = '`' . DB_NAME . '`.`' . $wpdb->prefix . 'accept-signups`';
$sql = 'select email, ip, timestamp from ' . $tbl . ' order by email;';
$r = $wpdb->get_results($sql, ARRAY_A);
$list = '';
foreach($r as $k=>$v) {
$list .= $v["email"] . ',';
}
return substr($list, 0, strlen($list)-1);
}
function acceptSignupsGetSignups() {
global $wpdb;
$html = '