'alo_easymail_widget', 'description' => __('Allow users to opt in/out of email', 'alo_easymail') ); /* Widget control settings. */ $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'alo-easymail-widget' ); /* Create the widget. */ $this->WP_Widget( 'alo-easymail-widget', __('ALO Easymail Widget', 'alo_easymail'), $widget_ops, $control_ops ); } /** * Display the widget on the screen. */ /* args array [name] => Sidebar 1 [id] => sidebar-1 [description] => [before_widget] =>
  • [after_widget] =>
  • [before_title] =>

    [after_title] =>

    [widget_id] => example-widget-4 [widget_name] => Example Widget */ function widget( $args, $instance ) { global $user_ID, $user_email, $wpdb; extract( $args ); //For NOT-REGISTERED, PUBBLIC SUBSCRIBER if (isset($_POST['alo_em_opt_name']) && isset($_POST['alo_em_opt_email'])){ $error_on_adding = ""; $just_added = false; if (!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", trim($_POST['alo_em_opt_email']) )) { $error_on_adding .= "The e-email address is not correct.
    "; } if ( stripslashes(trim($_POST['alo_em_opt_name'])) == "") { $error_on_adding .= "The name field is blank.
    "; } if ($error_on_adding == "") { // if no error // try to add new subscriber (and send mail if necessary) and return TRUE if success if ( ALO_em_add_subscriber( stripslashes(trim($_POST['alo_em_opt_email'])), trim($_POST['alo_em_opt_name']), 0) ) { $just_added = true; } else { $error_on_adding = "Error during sending: please try again.
    "; } } } // For REGISTERED USER if ( is_user_logged_in() && isset($_POST['alo_easymail_option'])) { if ( $_POST['alo_easymail_option'] == "yes") { ALO_em_add_subscriber($user_email, get_usermeta($user_ID, 'first_name')." ".get_usermeta($user_ID,'last_name') , 1); } else{ //if ( $_POST['alo_easymail_option'] == "no") { ALO_em_delete_subscriber_by_id( ALO_em_is_subscriber($user_email) ); } } // Our variables from the widget settings. $title = apply_filters('widget_title', $instance['title'] ); // Get the the user's optin setting //if (ALO_easymail_get_optin()=='yes'){ if (ALO_em_is_subscriber($user_email)){ $optin_checked = 'checked'; $optout_checked = ''; } else{ $optin_checked = ''; $optout_checked = 'checked'; } // Before widget (defined by themes). echo $before_widget; // Display the widget title if one was input (before and after defined by themes). if ( $title ) echo $before_title . $title . $after_title; // get the message optin/out messages $optin_msg = $instance['alo_easymail_optin_msg']; $optout_msg = $instance['alo_easymail_optout_msg']; if (is_user_logged_in()) { // For REGISTERED USER $html = "
    \n"; $html .= "\n"; $html .= " \n"; $html .= " \n"; $html .= " \n"; $html .= " \n"; $html .= " \n"; $html .= " \n"; $html .= " \n"; $html .= "
    $optin_msg
    $optout_msg
    \n"; $html .= "
    \n"; $html .= "\n"; } else { // For NOT-REGISTERED, PUBBLIC SUBSCRIBER if ( $just_added == false) { // if not success $html = ( ($error_on_adding !="") ? "
    $error_on_adding
    " : "" ); // if any $html .= "
    \n"; $html .= "\n"; $html .= " \n"; $html .= " "; $html .= " \n"; $html .= " \n"; $html .= " \n"; $html .= " \n"; $html .= " \n"; $html .= " \n"; $html .= "
    \n"; $html .= "\n"; $html .= "
    \n"; } else { // if success! $html = "
    Success!
    \n"; $html .= "Now we are sending an e-mail to you. Check your e-mail account and click the activation link in the e-mail to complete your subscription."; $html .= "
    "; } } // and output it echo $html; // After widget (defined by themes). echo $after_widget; } /** * Update the widget settings. */ function update( $new_instance, $old_instance ) { $instance = $old_instance; // Strip tags for title and name to remove HTML $instance['title'] = strip_tags( $new_instance['title'] ); $instance['alo_easymail_optin_msg'] = strip_tags( $new_instance['alo_easymail_optin_msg'] ); $instance['alo_easymail_optout_msg'] = strip_tags( $new_instance['alo_easymail_optout_msg'] ); return $instance; } /** * Displays the widget settings controls on the widget panel. * Make use of the get_field_id() and get_field_name() function * This handles the confusing stuff. */ function form( $instance ) { /* Set up some default widget settings. */ $defaults = array( 'title' => __('Newsletter', 'alo_easymail'), 'alo_easymail_optin_msg' => __('Yes, I would like to receive the Newsletter', 'alo_easymail'), 'alo_easymail_optout_msg' => __('No, please do not email me', 'alo_easymail')); $instance = wp_parse_args( (array) $instance, $defaults ); $html = ""; $html .= "\r\n".''; $html .= "\r\n".'

    '; $html .= "\r\n".' '; $html .= "\r\n".' '; $html .= "\r\n".'

    '; $html .= "\r\n".''; $html .= "\r\n".'

    '; $html .= "\r\n".' '; $html .= "\r\n".' '; $html .= "\r\n".'

    '; $html .= "\r\n".''; $html .= "\r\n".'

    '; $html .= "\r\n".' '; $html .= "\r\n".' '; $html .= "\r\n".'

    '; echo $html; } }//=========== End Widget Class ========================================== ?>