search mailchimp list by something else than email - php

currently all i can find is that the api only allow searching by email which is many cases not helpful because if the user wants to change his subscribing email he either have to
do something like this > http://kb.mailchimp.com/lists/signup-forms/how-subscribers-can-update-their-profiles
or i will have the new & old email from the user on the list because memberInfo() will return false because its a new given email.
also $update_existing=true is only used incase the user wants to change his (fname,lname) which in most cases they only want to change the email it self not the other info.
so does anyone knows a better way on how to handle subscribing/unsubscribing users using something else other than the email ???
Dublication :
check if user is in a list with mailchimp API V2.0

u can search by anything u want through
https://apidocs.mailchimp.com/api/2.0/helper/search-members.php i.e
MailchimpWrapper::helper()->searchMembers('what to search by', 'list_id');
,and to update the user info u can use
https://apidocs.mailchimp.com/api/2.0/lists/update-member.php i.e
MailchimpWrapper::lists()->updateMember(
'list_id',
['email' => $old_email],
['new-email' => $new_email],
'html',
false
);

Related

Wordpress: Output custom user_meta data in registration notification

In WordPress, I have custom registration site for new users. Upon registration, there is an optional checkbox to subscribe to our newsletter. As far as I understand it, it adds the value of the checkbox to the user_meta table (the whole thing has been coded by a company in India, which I woould very much prefer to not involve again, since they delayed their work time and time again and didn't do good work after all).
The corresponding code snippet in my child theme's functions.php looks like this:
<?php echo '<div class="form-row form-row-wide">
<input type="checkbox" name="inter_offers" value="yes"> '; _e('I would like to subscribe to the Kurth Electronic newsletter.','kurth-child'); echo '<br></div>';
return $fields; ?>
add_action('woocommerce_created_customer','adding_extra_reg_fields');
function adding_extra_reg_fields($user_id) {
extract($_POST);
update_user_meta($user_id, 'billing_inter_offers',$inter_offers);
} ?>
(I have left out lines irrelevant to this issue.)
Now, this value is saved internally, but not displayed to me. I would like to show the value in an E-Mail or notification generated by WordPress when the user completes registration, so that we can manually add them to our newsletter list whenever someone chooses to subscribe to the newsletter. The problem is that I only have a limited knowledge of PHP and I don't know where to start.
I should also note that this is not done via the standard WorPress registration form, but by a WooCommerce registration form (I have disabled the standard WordPress registration for security reasons).
I tried using the "Better Notifications" plugin (https://wordpress.org/plugins/bnfw/) for custom notifications whenever a new user completes their registration, but it ignores any php code that I add to the custom notifications body to display the user_meta data.
Any help would be appreciated.
Because the registration is done via woocomerce you may have to look for a notification PlugIN that works with woocomerce, the one you have may just work properly with wordpress core version!
You also could generate a mail via php in the function, so that you get a message with the user mail adress, but i think without php knowledge it is not that easy to use the built in php mailer... (You may need an api there!)
But wouldn't it be better to automatically sign them into your newsletter software? For example for Mailchimp or other systems like that there are quite good wordpress plugins!
You may also be able to include the forms of these PlugIns in your registration form, but without a closer look at this woocomerce registration i can't tell for sure!
I think this will do the trick, it will notify you every time a new user is created and also tell you if they subscribed or not.
function new_customer_registered_send_email_admin($user_login, $user_email) {
ob_start();
do_action('woocommerce_email_header', 'New customer registered');
$email_header = ob_get_clean();
ob_start();
do_action('woocommerce_email_footer');
$email_footer = ob_get_clean();
$user = get_user_by( 'email', $user_email );
$subscribed = get_user_meta( $user->ID, 'billing_inter_offers', true );
woocommerce_mail(
get_bloginfo('admin_email'),
get_bloginfo('name').' - New customer registered',
$email_header.'<p>The user '.esc_html( $user_login ).' created an account ' . ( $subscribed ? ' and subscribed to the newsletter.' : '.' ) . '<br>Email:'.esc_html( $user_email ).'</p>'.$email_footer
);
}
add_action('new_customer_registered', 'new_customer_registered_send_email_admin', 10, 2);
I ended up using the plugin amr users to generate a userlist of all users who had a certain metadata tag set to a certain value (in my case, if they want to recieve a newsletter - the previous developers never bothered to make the data actually readable without extra effort). It is a little clunky to use and not what I originally intended, but it got the job done.

Creating a referral link on CodeIgniter

I have a membership site where people can sign up for an account using their name, phone number and password of choice. The information entered during registration is stored in a MySQL database table called users. The primary key in the users table is the phone number. During sign up, the user has the option to type the phone number of his referrer into the referrer field. have all these set up and working fine, but I want to enhance the site some more, by:
Creating a unique referral link for users which will have their phone number appended to their link. I want to track which user referred others to my site so I can reward them.
When they share this link, and people click on it, it will take them to the registration page (register.php). On that page he phone number of the referrer will be set (and locked) in the referrer field.
I did some digging on the internet and found this code on github:
<?php
//check for referal links
function referal()
{
$CI =& get_instance();
$cookie_value_set = $CI->input->cookie('_tm_ref', TRUE) ? $CI->input->cookie('_tm_ref', TRUE) : '';
if ($CI->input->get('ref', TRUE) AND $cookie_value_set == '') {
// referred user so set cookie to ref=username
$cookie = array(
'name' => 'ref',
'value' => $CI->input->get('ref', TRUE),
'expire' => '7776000',
);
$CI->input->set_cookie($cookie);
return TRUE;
}elseif ($cookie_value_set == '') {
$cookie = array(
'name' => 'ref',
'value' => 'sso',
'expire' => '15552000',
);
$CI->input->set_cookie($cookie);
return TRUE;
}elseif ($cookie_value_set != '') {
//already referred so ignore
return TRUE;
}else{
return TRUE;
}
}
//end of hooks file
?>
The owner of the gist only mentioned saving the file as referral.php inside the hook folder. This is not helping me with what I want to achieve, I don't know how to use the code:
1. How do I pass the referrer field to the variable username from the users table?
2. How do I load the hook file to view (register.php)?
3. How and where do I call the hook file?
So can anybody give me an insight?
Well you are new to CodeIgniter and php. This will help you to get start with codeIgniter. Start coding with CodeIgniter using PhpStorm on Ubuntu 16.04 Merge Bootstrap to your current codeIgniter project in PhpStorm on ubuntu 16.04. Even these says about ubuntu os, it can use in other os as well. I think it's better to use id otherthan phone number for the primary key and make phone number as unique. It is not good to put phone number to the url. Because it is something personal for a user. You can use the id to the url. You can add it by as QueryString. To track users who use your site, you can add Google search console and Google analytic.

How to to implement a forgot password feature using the Google Identity Toolkit in php

I am trying to add google identity toolkit in php. Signin option is working correctly but when i am clicking on problem in sign in link it is showing capthca after submitting captcha it is not navigating to any url.
email.php
<?php
include "identity-toolkit-php-client-master/src/GitkitClient.php";
$gitkitClient=new Gitkit_Client();
$oob_response = $gitkitClient->getOobResults($_POST);
$oob_link = $oob_response['oobLink'];
echo json_encode($oob_response);
?>
email.php is the oobactionurl file. when i am using this code I am getting this error .image
You need to create a php file to retrieve and send the reset link to the user. Make sure the oobActionUrl widget option points to this file. Within the file, you'll get the generated link and additional information by calling $gitkitClient->getOobResults($_POST). It should also work if you exclude $_POST, as the function will check the post contents if no arguments are passed. Then, you can get the link itself like this:
$oob_response = $gitkitClient->getOobResults($_POST);
$oob_link = $oob_response['oobLink'];
From there, you can use your email function of choice to send it to the user. The returned array should contain the following.
'email' => email of the user,
'oldEmail' => old email (for ChangeEmail only),
'newEmail' => new email (for ChangeEmail only),
'oobLink' => url for user click to finish the operation,
'action' => 'RESET_PASSWORD', or 'CHANGE_EMAIL',
'response_body' => http response to be sent back to Gitkit widget
Let me know if you have any further questions.

How to integrate Mailerlite API on my registration form?

I'm a total noob at programming. I'm currently creating a website where a user can register.
What I want to happen is the following:
When the user registers, he/she will be added to my MailerLite subscriber list.
All the information will also be saved to my website's database.
I played around with the MailerLite documentation but I can't seem to get anything to work.
I installed all the libraries found here: https://github.com/mailerlite/mailerlite-api-php-v1#installation using composer then I created a php file with this code:
`
<?php
require_once 'vendor/autoload.php';
$ML_Subscribers = new MailerLite\Subscribers("*my API*");
$subscriber = array(
'email' => 'first#example.com',
'name' => 'First name'
);
$result = $ML_Subscribers->setId( *my GROUP ID* )->add($subscriber);
?>'
but it appears to do nothing, once I submit the form, it will load the php file that I created and shows nothing, I check my subscriber list in MailerLite and nothing is added.
Please check what does the script return - add var_dump($result); in the end of the file.
And MailerLite doesn't accept "#example.com" emails, so be sure to change this

Sugarcrm : generating contact from inbound emails

What i have :
Sugarcrm enterprise 6.5.14
I have set the inbound email to automatically generate cases under some conditions.
(it is set in Sugar's administration > Inbound email, it's native, i didn't write any code, juste setting it up).
I saw on /modules/InboundEmail/InboundEmail.php the function handleCreateCase() which i think (but please, confirm it) is used to generate cases.
What i want :
When a case is generated by an inbound email, the function handleCreateCase() is searching for contact ids and retrieves the good contact with this id :
snippet of handleCreateCases() :
if($contactIds = $this->getRelatedId($contactAddr, 'contacts')) {
if(!empty($contactIds) && $c->load_relationship('contacts')) {
$c->contacts->add($contactIds);
} // if
} // if
Now, i would like to add a "Else" condition : if there is no related contact, then create one.
My question is..
How do i code that? Could i customize the InboundEmail module? Will it be taken by Sugar?
Thanks a lot for your patience and your time.

Categories