wordpress user metadata not saving - php

I'm using the strip connect api with wordpress, and I've managed to set up the flow to connect a user, and get their access token and userid. However, I need to save this in a way that's connected to the wordpress user, as I need to be able to come back and reference the code later, in order to allow the correct person to be paid. I wrote added a couple lines with add_user_meta() but my var_dump() comes out null. here's the some of the code:
global $wpdb;
$table = $wpdb->prefix."stripe_connect";
$wpdb->insert($table , array(
'time' => current_time('mysql'),
'access_token' => $token,
'stripe_publishable_key' => $key,
'stripe_user_id' => $userid)
);
$user_ID = get_current_user_id();
add_user_meta($user_ID, ‘stripe_userid’, $userid, $unique);
add_user_meta($user_ID, ‘stripe_token’, $token, $unique);
$stripeuserid = get_user_meta($user_ID, 'stripe_userid', true);
var_dump($stripeuserid);
$response = '<h4>Thank you for connecting with Stripe. This information has been saved in the database and can be viewed in the Admin Panel.</h4>';

I figured it out, it had nothing to do with the way I was adding the data. The problem was with retrieving it.
This fixed it:
$user_ID = get_current_user_id();
update_user_meta($user_ID, ‘stripe_userid’, maybe_serialize( $userid ));
add_user_meta($user_ID, ‘stripe_token’, $token, $unique);
$stripeuserid = get_user_meta($user_ID, 'stripe_userid');
var_dump($stripeuserid);

Related

I'm using a social login plugin called miniOrange, but I can't get Twitter meta information

The following plugin is used to enable social login, allowing you to log in to Wordpress via Twitter.
https://plugins.miniorange.com/wordpress
And the following code is trying to get the metadata of the Twitter access of the logged in user.
<?
require_once('../wp-load.php');
require_once("codebird.php");
\Codebird\Codebird::setConsumerKey("XXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXX");
$cb = \Codebird\Codebird::getInstance();
$current_user = wp_get_current_user();
$wp_user_id = $current_user->ID;
$user_info = get_userdata($wp_user_id);
$twitter_id = get_user_meta($wp_user_id, "twitter_id", true);
$access_token = get_user_meta($wp_user_id, "twitter_access_token", true);
$access_token_secret = get_user_meta($wp_user_id, "twitter_access_token_secret", true);
$cb->setToken($access_token, $access_token_secret);
$media_id = $cb->media_upload(array(
"media" => $_FILES["image"]["tmp_name"]
))->media_id_string;
$params = array(
"status" => $_POST["text"],
"media_ids" => $media_id
);
$result = $cb->statuses_update($params);
echo $twitter_id, $access_token, $access_token_secret;
However, the ECHO result is empty.
How can I get the Twitter secret access token and other information of the logged in user?
English may be inaccurate due to the use of a translation site. Please understand.

How to call a PHP function from a plugin every time a Woocommerce order is placed?

in Wordpress I have installed an app-builder plugin that allows me to send push notifications to the app, It automatically sends push notifications when a email is sent from the website to the email address of the current user that is logged into the app and the plugin allows me to send custom push notifications to different users roles manually - this is fine.
But the problem is - I want to be able to send automatic push notifications to the 'driver' user role every time a new Woocommerce order is received.
Warning - I am a novice (clearly).
The plugin developer provided me with the function that sends the push notification, which is:
wpmobileapp_push($title, $message, $image_url, $page_url, $lang_2letters = 'all', $send_timestamp = '', $user_email = '');
And Im using woocommerce_thankyou so the function runs everytime a customer gets to the 'thank you' page.
So after a bit of investigating I have come up with the following function (which was added into my 'function.php) which 'should' check if a 'driver' user is logged in and should call the php function which sends the push notification to the drivers every time a new woocommerce is sent, but this does not work:
/**
* Add a notification when a new woocommerce order is recieved.
*
*/
add_action('woocommerce_thankyou', 'wpmobileapp_woo_order', 10, 1 );
function wpmobileapp_woo_order($order_id) {
// Check if user is logged in.
if ( is_user_logged_in() ) {
// Get the user ID.
$user_id = get_current_user_id();
// Get the user object.
$user_meta = get_userdata( $user_id );
// If user_id doesn't equal zero.
if ( 0 != $user_id ) {
// Get all the user roles as an array.
$user_roles = $user_meta->roles;
// Check if the role you're interested in, is present in the array.
if ( in_array( 'driver', $user_roles, true ) ) {
$order = new WC_Order( $order_id );
$items = $order->get_items();
$customer_address = $order->get_billing_address();
$user_email = $user_meta->user_email;
$image_url = '';
$link = '';
$title = "new order";
$message = $order . ', ' . $items . ', ' . $customer_address;
wpmobileapp_push($title, $message , $image_url, $link, $lang_2letters = 'all', $send_timestamp = '', $user_email);
}
}
}
}
I have tried many different things to try and make this work myself to get it to send automatic notifications to the driver use role type every-time a new order is placed, but nothing works. Some help would be greatly appreciated.
Okay, the best simple way of handling this is to send a push notification to all logged in driver users. Basically, query all users that have a running session in WordPress with the driver role. Then, iterate over these attempting to send everyone of them a notification. Change the function like so:
/**
* Add a notification when a new woocommerce order is recieved.
*
*/
add_action('woocommerce_thankyou', 'wpmobileapp_woo_order', 10, 1 );
function wpmobileapp_woo_order($order_id) {
$order = new WC_Order( $order_id );
$items = $order->get_items();
$customer_address = $order->get_billing_address();
$user_email = $user_meta->user_email;
$image_url = '';
$link = '';
$title = "new order";
$message = $order . ', ' . $items . ', ' . $customer_address;
// get all users with role 'driver' and an active WP session:
$drivers = get_users([
'role' => 'driver',
'meta_key' => 'session_tokens',
'meta_compare' => 'EXISTS'
]);
// notify each of these by push notification
foreach ($drivers as $driver) {
$driver_email = $driver->user_email;
wpmobileapp_push($title, $message , $image_url, $link, $lang_2letters = 'all', $send_timestamp = '', $driver_email);
error_log("WooCommerce Driver notification: sending push notification to account of $driver_email");
}
}
You can enable WP_DEBUG and WP_DEBUG_LOG and check which driver account should've gotten a push notification. If a log message exists but your test driver user didn't get a notification, probably you need to test this wpmobileapp_push stuff further and contact the developer of https://wordpress.org/plugins/wpappninja/ if it doesn't seem to be working at all.
The thing is: this function only inserts an entry in the plugin's database table. I'm not entirely sure it sends the push notification right away. That's why I said you might've to talk to the plugin developer.

WPallimport function to create user from csv column

My goal is to import a csv file with houses for sale and generate realtors as wordpress/buddypress user if they don't exist yet. I want to do so by using a custom function in WP all import. Addtitionally i would like to set the buddypress membertype to "realtor" for internal user
I will map the source field to a custom field in the import config
[create_realtor{realtor_column}]
in my case that is [create_realtor{properties[1]/property[2]/value[1]}]
As it is a user for internal purposes, i don't need the actual realtor contact details, so the user email will be realtor#mydomain.com, pass can generated, email to realtor not needed.
I found that a user can be generated as below source:
if( null == username_exists( $email_address ) ) {
// Generate the password and create the user
$password = wp_generate_password( 12, false );
$user_id = wp_create_user( $email_address, $password, $email_address );
// Set the nickname
wp_update_user(
array(
'ID' => $user_id,
'nickname' => $email_address
)
);
// Set the role
$user = new WP_User( $user_id );
$user->set_role( 'subscriber' );
} // end if
How can i wrap all in a function that will generate the user based on the realtor name in my feed
would it be like below?
function create_realtor($realtor) {
$emailadress = $realtor . '#mydomain.com' ;
if( null == username_exists( $email_address ) ) {
// Generate the password and create the user
$password = wp_generate_password( 12, false );
$user_id = wp_create_user( $email_address, $password, $email_address );
// Set the nickname
wp_update_user(
array(
'ID' => $user_id,
'nicename' => $nicename, //realtor
'nickname' => $email_address //realtor#mydomain.com
)
);
// Set the role
$user = new WP_User( $user_id );
$user->set_role( 'subscriber' );
// Set the member type of user to 'realtor'.
$member_type = bp_set_member_type( $user_id, 'realtor' );
} // end if
}
I tried above, but it results in a message saying "Custom Field Value template is invalid: Unexpected token XPATH, statement was expected."
I am a bit lost here on how to procede
You issue is that you're not calling your custom function correctly. The function call should have round brackets like this:
[create_realtor({properties[1]/property[2]/value[1]})]
Always start simple:
Read through Example 2 below
Get a simple function working first
Then build on it and insert your custom logic
https://www.wpallimport.com/documentation/developers/custom-code/inline-php/

Mailchimp double_optin option not working

I've followed this tutorial to implement mailchimp API v2.0 on my website.
It works great, however the double_optin option that I wanted to add and set to false (so that users don't need to validate their registration via e-mail) doesn't seem to be working. It's like if it was not taken into consideration at all, users still need to validate the registration via e-mail.
Is 'double_optin' => false placed at the wrong place? I had a look at mailchimp documentation but my level in programmation is not good enough to identify what is wrong.
Thanks for your help
<?php
$api_key = "12345486-us8";
$list_id = "123";
require('Mailchimp.php');
$Mailchimp = new Mailchimp( $api_key );
$Mailchimp_Lists = new Mailchimp_Lists( $Mailchimp );
$subscriber = $Mailchimp_Lists->subscribe( $list_id, array( 'email' => htmlentities($_POST['email']),'double_optin' => false ) );
if ( ! empty( $subscriber['leid'] ) ) {
echo "success";
}
else
{
echo "fail";
}
?>
According to this (admittedly unofficial-looking) Mailchip_Lists documentation, you'll want to pass FALSE as the 5th parameter to subscribe().
Example:
$double_optin = FALSE;
$subscriber = $Mailchimp_Lists->subscribe(
$list_id,
array('email' => htmlentities($_POST['email'])),
NULL, // merge_vars
'html', // email_type
$double_optin
);

Sugar CRM Soap call not working properly

I have sugar crm instance and i was trying to get some data from it using soap service.
Below is the code which i am using for it.
When i run the same code , sometimes it is returning correct data, sometimes it not.
Can any one tell me what the problem is??
include "nusoap.php";
$client = new soapclient('http://asdf.net/test/urbancrm_2009_06_22/soap.php');
// Login to SugarCRM
$auth_array = array(
'user_auth' => array(
'user_name' => '******',
'password' => '*******'
),
);
$response = $client->call('login', $auth_array);
if (!$response['error']['number']){
// Successfully logged in
$session_id = $response['id'];
//$response = $client->call('get_entry_list',array('session'=>$session_id , 'module_name'=>'Users', 'query'=>'', 'order_by'=>'','offset'=>'','select_fields'=>array('id','user_name')));
$response = $client->call('get_entry_list',array('session'=>$session_id , 'module_name'=>'itf_Apartments', "query"=>"itf_apartments_cstm.neighborhood_c='Loop'", 'order_by'=>'','offset'=>'','select_fields'=>array('name','studio','convertible','one_bedroom','one_bedroom_plus_den','two_bedroom','two_bedroom_plus_den','penthouse','photo_c','building_type_c','neighborhood_c')));
//$response = $client->call('get_entry_list',array('session'=>$session_id , 'module_name'=>'itf_Apartments', 'query'=>'itf_apartments_cstm.urbanlux_id_c="1"', 'order_by'=>'','offset'=>'','select_fields'=>array('name','studio','convertible','one_bedroom','one_bedroom_plus_den','two_bedroom','two_bedroom_plus_den','penthouse',)));
//store id and user name as a key value pair in array
//echo "---";
print_r($response);
} else {
echo "else";
print_r($response);
}
?>
You need to convert the password to MD5 before you pass for authentication.

Categories