WP Social Login not creating users like normal WP registration?
-
Does WordPress Social Login not create users in the original wp-database as regular registration via Admin dashboard? Because is seems that it is not possible to add or get user-meta-data from current user the ‘normal way’.
Question is: How does WordPress Social Login Plugin create users in the database, and how to add (or get) user-meta from current wp social login registered user?
I have a current case, and have not yet found the answer. Hope you can help me out.
The case In this case I have a Gravityform which allows registered users to submit a new page. I want them to submit only one page per user. Page title is auto created and do have the form entry-ID as unique part of page title (Gravityforms settings). This function below is used to make Gravityforms to create a page instead of a post:
add_filter("gform_post_data", "change_post_type", 10, 2); function change_post_type($post_data, $form){ //only change post type on form id 1 if($form["id"] != 2) return $post_data; $post_data["post_type"] = "page"; return $post_data; }
Now I want users who have completed the form successfully and are currently logged in, to show the url of their created page like http://www.example.com/pagenumber{entry-ID} Therefore there are 3 options what to display:
1- user is logged in and have created a page -> show page url
2- user is logged in and have not yet created a page -> show form -> redirect to point 1 after completing
3- user is not logged in -> show social login buttons -> redirect to point 2 after connectingFirst I have added the form entry ID to the user-meta:
add_action( 'gform_after_submission', 'wpse96480_map_user_to_page', 10, 2); function wpse96480_map_user_page( $entry, $form ) { $user_id = $entry['created_by']; $meta_key = 'generated_page_id'; $meta_value = $entry['post_id']; $unique = true; add_user_meta( $user_id, $meta_key, $meta_value, $unique ); }
I also added the code below to the page.php (or page template file) to check if current user is logged in and have an entry-ID in user-meta, and if so, to display the url with the entry-ID:
<?php if ( is_user_logged_in() ) { global $current_user; // $current_user = get_currentuserinfo(); $user_id = $current_user->ID; $meta_key = 'gform_entry_id'; $single = true; $entry_id = get_user_meta( $user_id, $meta_key, $single ); if( strlen( $entry_id ) > 0 && is_numeric( $entry_id ) ) { // we have an entry ID now ?> <h2>Hey <?php echo $current_user->display_name ?>, thank you for submitting the form. Visit your page here: www.example.com/pagenumber<?php echo( $entry_id ); ?></h2> <?php } else { // we don't have an entry ID for this user ?> <h2>Hey <?php echo $current_user->display_name ?>, Thank you for joining. To create a page please submit the form below:</h2><?php echo do_shortcode('[gravityform id="2" name="just a form" title="false" description="false"]'); ?> <?php } } else { // user is not logged in ?> <h2><Please log in to create a page <?php do_action( 'wordpress_social_login' ); ?></h2> <?php } ?>
The result:
If a regular registered WP user (who is created by Admin in the Admin dashboard) is logged in, and completes the form successful, option (1) is effective/successful showing as we wanted. If user have not completed the form yet, option (2) is effective/successful showing.The problem with WP Social Login users:
If a user registered via a Social Login Plugin is logged in, and have completed the form successful, option (2) is still showing like user has never completed the form.Question:
How does WordPress Social Login Plugin create users in the database, and how to add (or get) user-meta from social login registered current user as in the above case?
- The topic ‘WP Social Login not creating users like normal WP registration?’ is closed to new replies.