I just started working with S2Memeber and am having problems finding a way to save/update extended user information.
I know to use 's2get' to get info, and there appears not to be something like 's2put'.
How do I go about updating/adding the additional user data that is retrieved with the s2get shortcode?
Okie. Someone upvoted this, so I hope this answer helps.
You don't actually do this through S2Member, which, of course, is good. Instead you use the native WP functionality.
$meta_value = get_user_meta( $user_id, 'wp_s2member_custom_fields', true );
$meta_value['company_name'] = 'My Company';
update_user_meta($user_id, 'wp_s2member_custom_fields', $meta_value);
Related
I am a new WordPress plugin developer. I tried submitting my plugin in WordPress repository, but recieved an error from the review team. The error is like
Data Must be Sanitized, Escaped, and Validated
When you include POST/GET/REQUEST/FILE calls in your plugin, it's important to sanitize, validate, and escape them. The goal here is to prevent a user from accidentally sending trash data through the system, as well as protecting them from potential security issues. Below are the paths they mentioned:
woolive/templates/livecall.php:18: $prodid = $_GET['id'];
woolive/admin/register.php:201: $prodid = (isset($_GET['id']) && !empty($_GET['id'])) ? $_GET['id'] : "";
woolive/admin/settings.php:20: update_option('button_loc_shop_page', $_POST['button_loc_shop_page']);
woolive/admin/settings.php:28:
update_option('button_loc_product_details_page', $_POST['button_loc_product_details_page']);
woolive/admin/settings.php:30: update_option( 'loginpage_slug', $_POST['loginpage_slug'] );
woolive/admin/settings.php:31: update_option( 'howtojoinpage_slug', $_POST['howtojoinpage_slug'] );
Anyone can share how can I do that? Any comments or directions would be really appreciated.
I searched woocommerce documents and I couldn't find any hook or function that checks: if user already has a saved address..
Is it totally possible to check? I will appreciate it if you give me documents or tips to check it.
The only solution that comes to my mind is using
if( has_bought() )
but it is not the best solution if users did not buy andy thing but they already saved an address on the website.
I found the solution by help of WooCommerce community. I share it here for other, who may need that:
$user_id = get_current_user_id();
$billing_address_1 = get_user_meta( $user_id, 'billing_address_1' );
if ($billing_address_1 ){
echo 'any text will be there.';
}
I'm quite new to Wordpress, so please forgive me and correct any mistake I'm making, I'm willing to learn and improve :)
I set up multiple contact forms for applying to fitness courses. People need to fill them, and I get an email with their written data.
What I'm trying to do now is execute some PHP code that writes data into a MySQL database whenever the user correctly fills and sends a contact form.
I also need every contact form to have a unique code "attached" to it, because the PHP code needs this code to write the data inside the database. (simply put, every course has its unique code that i need to write in the database along with the user's data).
So far as I understand, I need to use add_action( 'wpcf7_before_send_mail', 'my_function' ); in a snippet inside functions.php. What I'm trying to achieve now is to attach this code to every contact form (but it mustn't be visible to users) so that my php snippet reads this code and correctly edits the database.
Any clue on where to look? I don't need the code written, just some ideas!
Thank you in advance, have a nice day everybody.
EDIT: I found out there are "hidden fields" in CF7. So, i added these to my test contact form:
[hidden idcorso "6"]
[hidden idgruppo "0"]
Then i'm using this snippet, but it doesn't work:
add_action( 'wpcf7_before_send_mail', 'process_contact_form_data' );
function process_contact_form_data( $contact_data ){
$idcorso = $contact_data->posted_data["idcorso"];
$idgruppo = $contact_data->posted_data["idgruppo"];
if (is_user_logged_in()) {
$idutente = get_current_user_id();
$data = current_time('d-m-Y - g:i');
$stato = 1;
$wpdb->insert("fis_iscrizioni_2018", array('id_utente' => $idutente, 'id_corso' => $idcorso, 'data' => $data, 'stato' => $stato, 'id_gruppo' => $idgruppo) );
}
}
Any clue?
I have written an action that attaches to woocommerce_order_status_completed, and it works fine, adding a bit of meta data to the order. But the email that goes out after order completed seems to go BEFORE this runs, and therefore does not send the meta data in question (it will send it if I rerun the completed order again, but that is because this data is now already in the DB). So what I am looking for is either:
a hook that runs JUST before the completed email sends, OR
a way to have the completed email send AFTER woocommerce_order_status_completed hook
Any ideas or pointers? I looked through the Woocommerce API reference but can't find anything that seems to suit.
UPDATE: found an earlier hook and tried hooking it into
add_action( 'woocommerce_order_status_completed_notification','mysite_woocommerce_order_status_completed',5,1 );
which should run sooner, but STILL the email goes out first (before the meta data is in the DB and can be read. If I "recomplete" the order (putting it back into processing status and then completed again), it will send the meta data (again, this is because it is now in the db)
After much hair pulling, I have come up with a workaround which seems kind of ugly, but hopefully it will help someone else out.
I verified that my hook WAS correctly running before the main email one. (using add_action( 'woocommerce_order_status_completed_notification','mysite_woocommerce_order_status_completed',5,1 );
)
I verified that my meta data WAS correctly inserted into the db BEFORE the email went out
Unfortunately, it still refused to grab my meta data on first send. So I did the following:
I copied the woocommerce/templates/emails/email-order-items.php template into my theme and made the following change:
// Variation
if ( ! empty( $item_meta->meta ) ) {
echo '<br/><small>' . nl2br( $item_meta->display( true, true, '_', "\n" ) ) . '</small>';
// following 5 lines are MY extra code (checking for my meta field 'signup_code')
if (!array_key_exists('signup_code',$item_meta->meta)) {
$suc = wc_get_order_item_meta( $item_id, 'signup_code' );
if ($suc) {
echo '<br/><small>signup_code: ' . $suc . '</small>';
}}
}
It will check for a dupe in the meta array and not output if it already exists. It needs to do this to prevent it showing twice (which it would otherwise do on second send). I can't believe this is all necessary, but I can't find any other pointers anywhere that can address this.
UPDATE:
This was apparently caused by a woo internal caching problem. I had a lengthy discussion with one of the woo devs here:
https://wordpress.org/support/topic/hook-an-action-before-transactional-woocommerce-emails-are-triggeredsent-out/page/2?replies=40#post-8379725
And the upshot is, it will be fixed in a future version, but you can see the changes here:
https://github.com/woothemes/woocommerce/commit/3db3f3796eb28fb79983f605a5a70d61ca114c6d
Here's the situation:
I have an old site, with an old userdatabase (MySQL). I'd like to migrate these users into wordpress without losing the old data (recipe id's, custom user fields etc.).
Besides this i'd like to make a custom registration page with all the (extra) user data i allready had on the old site.
I tried to find some plugins (WP-members, Registration Widget, Register Plus Redux, etc.), but they all didn't fit my purpose.
I'm starting to think that I probably need to code this myself, but that will make Wordpress unable to update.
Does anyone have a solution for this problem?
Thx, Rick
Should be fairly easy although you may have to assign users a new password. That is usually ok with the users as long as they know it's coming.
Take your old database and to a simple sql query to extract the data, then use some code like the following to create a new user for each user in your old database:
$newuser = array(
'user_pass' => wp_generate_password( 12,0 ),
'user_login' => $email,
'user_nicename' => $name['first'].' '.$name['last'],
'user_email' => $email,
'display_name' => $name['first'].' '.$name['last'],
'nickname' => $name['first'].' '.$name['last'],
'first_name' => $name['first'],
'last_name' => $name['last'],
//''
);
$user_id = wp_insert_user($newuser);
wp_new_user_notification($user_id, $newuser['user_pass']);
This code works as of WordPress 3.1. In this example you'd simply want to replace the $name variables with data that you've provided from your old database.
The last two lines are important because that's where the real work happens. The wp_insert_user function will create the user (or throw an error if you're missing info) and the wp_new_user_notification function will send them an email with their password. I would highly recommend taking the time to rewrite the new user notification plugin (it's a pluggable function so you can just copy paste it to your functions.php and make changes there) so that the email users get makes sense. You could also write your own email function or if your passwords are stored in plain text simply pass that info on to WP.
Edit: I missed your need for custom fields, Gravity Forms does this quite well but you can add a custom field to any user with the update_user_meta function. So in the sample code above you'd just want add something after that like:
update_user_meta($user_id, "my_custom_data_key", "my_custom_data_value");
To retrieve that data for display, you'd just use get_user_meta:
print get_user_meta($user_id, "my_custom_data_key");