admin_url( 'admin-ajax.php' ) ) ); //Load default options: these will be overwritten when the user customizes their widget. //Keep in mind that there are several means of implementing the quick-subscribe toolkit in your WP pages: // 1 - add the Ajax Quick Subscribe Widget to a sidebar via the Appearance->widgets toolbar. The user may specify some options specifically for this implementation of the tool in the same menu. // 2 - add the tool to any text by including the tag '[quicksubscribe]' within any text in a post or page. // 3 - add the code ' anywhere in your theme php code(minus the backslashes) // Options 2 and three utilize the settings which are defined via the settings->quick subscribe tool in the admin toolset. //Some options (like thanks_message, invalid_message, and already_subscribed message are only definable via the settings->quick subscribe menu. //Add default options for the widget implementation of the tool. if(get_option("quicksubscribe_widget_button") == null){ update_option("quicksubscribe_widget_button", true); } if(get_option("quicksubscribe_widget_button_hide") == null){ update_option("quicksubscribe_widget_button_hide", false); } //if(get_option("quicksubscribe_widget_input_redisplay") == null){ // update_option("quicksubscribe_widget_input_redisplay", false); //} if(!get_option("quicksubscribe_widget_button_label")){ update_option("quicksubscribe_widget_button_label", "subscribe!"); } if(!get_option("quicksubscribe_widget_title")){ update_option("quicksubscribe_widget_title", 'Subscribe'); } if(!get_option("quicksubscribe_widget_description")){ update_option("quicksubscribe_widget_description", "Enter your email to subscribe to future updates"); } //Add default options for the in-text and in-theme implementations //it is assumed that the user will add thier own desctiption and title for these implementations if(get_option("quicksubscribe_button") == null){ update_option("quicksubscribe_button", true); } if(get_option("quicksubscribe_button_hide") == null){ update_option("quicksubscribe_button_hide", true); } //if(get_option("quicksubscribe_input_redisplay") == null){ // update_option("quicksubscribe_input_redisplay", true); //} if(!get_option("quicksubscribe_button_label")){ update_option("quicksubscribe_button_label", "subscribe!"); } // now addany options which apply to both the widget and in-text, in-theme implementations if(!get_option("quicksubscribe_tks")){ update_option("quicksubscribe_tks", "Thanks for subscribing. Now add a friend:"); } if(!get_option("quicksubscribe_invld")){ update_option("quicksubscribe_invld", "Invalid email address"); } if(!get_option("quicksubscribe_alrdysub")){ update_option("quicksubscribe_alrdysub", "This email is already subscribed"); } /*+-----------------------------------------------------------------+ | Now define functions +-----------------------------------------------------------------+ */ // This function actually does the subscribing function quick_subscribe_register($source){ require_once( ABSPATH . WPINC . '/registration.php'); $user_email = apply_filters( 'user_registration_email', $source ); $user_login = sanitize_user( str_replace('@','', $source) ); // Check the e-mail address if ($user_email == '') { $errors = get_option('quicksubscribe_invld'); } elseif ( !is_email( $user_email ) ) { $errors = get_option('quicksubscribe_invld'); } elseif ( email_exists( $user_email ) ) $errors = get_option('quicksubscribe_alrdysub'); //do_action('register_post'); if(isset($errors)){ $errors = apply_filters( 'registration_errors', $errors ); $message = $errors; } if ( empty( $errors ) ) { $user_pass = substr( md5( uniqid( microtime() ) ), 0, 7); $user_id = wp_create_user( $user_login, $user_pass, $user_email ); $user = new WP_User($user_id); $user->set_role('subscriber'); $message = get_option('quicksubscribe_tks'); if ( !$user_id ) $errors['registerfail'] = sprintf(__('ERROR: Couldn’t register you... please contact the webmaster !'), get_option('admin_email')); } return $message; } // This function adds functions for the quick subscribe widget function widget_quick_subscribe_init(){ // Check to see required Widget API functions are defined... if ( !function_exists('register_sidebar_widget') || !function_exists('register_widget_control') ) return; // ...and if not, exit gracefully from the script. //This function prints the general quick_subscribe widget function widget_quick_subscribe($args){ extract($args); $message = ''; $title = get_option('quicksubscribe_widget_title'); echo $before_widget; if($title != ''){ echo $before_title . $title . $after_title; } //add widget description. echo get_option('quicksubscribe_widget_description'); echo '
'; echo quick_subscribe_get_form($message, 'QS_user_email_widget', 'QSWidgetDiv'); echo '
'; ?>
/> Still show email input after successful subscribe */?>
Quick Subscribe page function quicksubscribe_admin() { if (function_exists('add_options_page')) { add_options_page('AJAX Quick Subscribe Options', 'AJAX Quick Subscribe', 8, basename(__FILE__), 'quicksubscribe_admin_page'); } } //this function does the lifting for the function above function quicksubscribe_admin_page() { if (isset($_POST['submit_qs'])) { echo "

AJAX Quick Subscribe Options Updated!"; $button = isset($_POST['button_qs']); if($button != 1) $button = 0; $button_hide = isset($_POST['button_hide_qs']); if($button_hide != 1) $button_hide = 0; //$input_redisplay = isset($_POST['input_redisplay_qs']); //if($input_redisplay != 1) $input_redisplay = 0; update_option("quicksubscribe_button", $button); update_option("quicksubscribe_label", $_POST['label_qs']); update_option("quicksubscribe_tks", $_POST['tks_qs']); update_option("quicksubscribe_invld", $_POST['invld_qs']); update_option("quicksubscribe_alrdysub", $_POST['alrdysub_qs']); update_option("quicksubscribe_button_hide", $button_hide); //update_option("quicksubscribe_input_redisplay", $input_redisplay); echo "

"; } $op_button = (get_option("quicksubscribe_button")); $op_label = get_option("quicksubscribe_label"); $op_tks = get_option("quicksubscribe_tks"); $op_alrdysub = get_option("quicksubscribe_alrdysub"); $op_invld = get_option("quicksubscribe_invld"); $op_hide_button = get_option("quicksubscribe_button_hide"); //$op_input_redisplay = get_option("quicksubscribe_input_redisplay"); ?>

AJAX Quick Subscribe Page/Post form options

> Display submit button after text box (otherwise user must press enter to subscribe)

> Hide submit button until user enters text box

> Display email input after successful subscribe for additional subscriptions

*/?> Submit button label:


Thanks Message:


Already Subscribed Message:


Invalid Email Message:


". $message ."
"; } $output .= "
"; $output .= ""; } else if($op_button){ //display button $output .= ""; } $output .= "
"; return $output; } //this function implements the form if it is included in a tag function quick_subscribe_tag_form($content){ if ( strpos($content, '[quicksubscribe]')){ $output = '
'; $output .= quick_subscribe_get_form(0, "QS_user_email_tag", 'qsInlineContainer'); $output .= '
'; $content = str_replace("[quicksubscribe]", $output, $content); } return $content; } //this function implents the form for the first time when added via tag or theme function quick_subscribe_form(){ echo '
'; echo quick_subscribe_get_form(0, "QS_user_email_theme", 'qsInlineContainer'); echo '
'; } //this function handles the ajax request function handle_qs_ajax_request(){ $userEmail = $_REQUEST['userEmail']; $source = $_REQUEST['source']; $containerDiv = $_REQUEST['containerDiv']; $message = quick_subscribe_register($userEmail); $output = quick_subscribe_get_form($message, $source, $containerDiv, $userEmail); echo $output; die(); } // Delays plugin execution until Dynamic Sidebar has loaded first. add_action('plugins_loaded', 'widget_quick_subscribe_init'); add_filter('the_content', 'quick_subscribe_tag_form'); add_action('admin_menu','quicksubscribe_admin'); add_action('wp_ajax_nopriv_quicksubscribe_submit', 'handle_qs_ajax_request'); add_action('wp_ajax_quicksubscribe_submit', 'handle_qs_ajax_request');