• Resolved drskullster

    (@drskullster)


    Hi mate,

    Great plugin, nice and clean as I like’em ??

    I have a subscription form where a user can enter an email address. I’d like to subscribe the user to knews when he validates this form.

    Looking at the code, I couldn’t find a method that does just that. It seems you have to send POST values to make it work.

    I guess I could use the function KnewsPlugin::add_user_self() and set the post values myself, but how can I get the knews object ? Is it the right solution you think ?

    Do you have an idea on how I could achieve this, or could you point me in the right direction ?

    Thanks a bunch !

    https://www.ads-software.com/extend/plugins/knews/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author creverter

    (@creverter)

    Hi @drskullster!

    You are right! In next versions we will include a simple function call to externally manage users: add, activate, deactivate, etc.

    For now, the right way to do this, are:

    1) Copy the entire function add_user_self() into wherever you want (I suggest the theme functions.php file)

    2) Rename all $this-> for $Knews_plugin-> (search and replace will help you)

    3) Comment this lines:

    /*
    $lang = mysql_real_escape_string($this->post_safe('lang_user'));
    			$lang_locale = mysql_real_escape_string($this->post_safe('lang_locale_user'));
    			$email = mysql_real_escape_string($this->post_safe('email'));
    			$date = $this->get_mysql_date();
    			$confkey = $this->get_unique_id();
    			$id_list_news = intval($_POST['user_knews_list']);
    
    			$stupid_bot = false;
    			$key = md5(date('dmY') . KNEWS_VERSION . get_bloginfo('version'));
    			if ($this->post_safe('knewskey') != $key) $stupid_bot = true;
    			if (date('G') == 0 && $stupid_bot) {
    				$key = md5(date('dmY', strtotime("-1 day")) . KNEWS_VERSION . get_bloginfo('version'));
    				if ($this->post_safe('knewskey') == $key) $stupid_bot = false;
    			}
    
    			if ($this->post_safe('knewscomment') != '') $stupid_bot = true;
    
    			if (!$this->validEmail($email) || $stupid_bot) {
    				echo '<div class="response"><p>' . $this->get_custom_text('ajax_wrong_email', $lang_locale) . ' <a href="#" onclick="window.location.reload()">' . $this->get_custom_text('dialogs_close_button', $lang_locale) . '</a></p></div>';
    				return false;
    			}
    */

    4) Then, add this code in the same place and customize yourself:

    $lang = 'en'; //The lang you want
    			$lang_locale = 'en_US'; //The localised lang
    			$email = '[email protected]';
    			$date = $Knews_plugin->get_mysql_date();
    			$confkey = $Knews_plugin->get_unique_id();
    			$id_list_news = 1; //An valid ID mailing list
    
    if (!$Knews_plugin->validEmail($email)) {
      return false;
    }

    5) Now, go to the end of your function and find:

    if ($submit_mail) {
    
    					if ($this->submit_confirmation ($email, $confkey, $lang_locale)) {
    						echo $this->get_custom_text('ajax_subscription', $lang_locale);
    					} else {
    						echo $this->get_custom_text('ajax_subscription_error', $lang_locale);
    					}
    				} else {
    					if (count($subscription_found)==0) {
    						echo $this->get_custom_text('ajax_subscription_direct', $lang_locale);
    					} else {
    						echo $this->get_custom_text('ajax_subscription_oops', $lang_locale);
    					}
    				}
    
    				echo '</p></div>';

    Comment all the echos and add the code you need for every case:

    – subscription ok, email confirmated
    – error submitting email
    – already subscribed to other mailing list, new mailing list added
    – already subscribed to this mailing list

    Regards,
    Carles.

    Thread Starter drskullster

    (@drskullster)

    Hi Carles,

    It works just fine with your solution.

    Many thanks !

    Plugin Author creverter

    (@creverter)

    Hello!

    The new version (knews 1.1.5) has a direct way to include users:

    $Knews_plugin->add_user(email, id_list_news, lang, lang_locale)

    e.g.

    $Knews_plugin->add_user(‘[email protected]’, 1, ‘en’, ‘en_US’)

    You should use this way in order to get compatibility with future knews versions.

    Regards,
    Carles.

    Thread Starter drskullster

    (@drskullster)

    Very nice,

    Thanks !

    Is there an easy way to implement an external user: add, activate, deactivate, etc. yet?

    Just wondering as I’m having problems adding the above solution.

    Thanks
    Bjorn

    hello! excuse my not perfect english!
    First of all: great plugin!
    My problem: I have to put any person utilize my CF7 (contact form 7 plugin) on my site on the mailinglist of knews. I’ve tried this code:

    add_action( 'wpcf7_before_send_mail', 'my_conversion' );
    
    	function my_conversion( $cf7 )
    	{
    	$email = $cf7->posted_data["your-email"];
    	$name = $cf7->posted_data["your-name"];
    	$Knews_plugin->add_user($email, 7, 'it', 'it_IT');
    	return TRUE;
    	}

    in functions.php file.
    The page with contact form rest in sending and nothing happen (no mail – no adding user).

    if I comment the line add_user it work (send email normally), but obiouvsly the mailing list don’t change

    if I put only the line for test the function
    $Knews_plugin->add_user('[email protected]', 7, 'it', 'it_IT');
    it work…

    where I wrong?

    at the end last question: can I put in ML another information like name and activation? Something like that:
    $Knews_plugin->add_user($email, 7, 'it', 'it_IT', $name, 'activate');

    Thanks a lot for any reply!!
    Sangio

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: Knews Multilingual Newsletters] Add a user in php, without the form’ is closed to new replies.