arbitrage
Forum Replies Created
-
Forum: Plugins
In reply to: [Post From Site] [Plugin: Post From Site] Error following postDid the re-ordering of the JS files solve the issue? If yes, where can I impact the order, since most of the files are loaded via wp_head.
Forum: Plugins
In reply to: [Plugin: Theme My Login] How to add role based user notificationsOk. I could consider this. I contact you via your website.
Forum: Plugins
In reply to: [Plugin: Theme My Login] How to add role based user notificationsYes, exactly. Depending on the user role wordpress shall send specific new user and account activation mail.
Forum: Plugins
In reply to: [Plugin: Theme My Login] add_action user_register does not workHi Jeff, many thanks for the support. I found the origin for the problem of passing the value from the POST variable role. It was a mistake in the form validation check.
Forum: Plugins
In reply to: [Plugin: Theme My Login] add_action user_register does not workMaybe there is one more thing, you could help me. Do have any idea how to implement role based User Notification mails e.g. “New User” and “Account Activated” to the Theme My Login plugin?
Forum: Plugins
In reply to: [Plugin: Theme My Login] add_action user_register does not workI could not find where it is buffered. But when I directly set the value of role instead of $_POST[‘role’] the role is correctly defined after email confirmation of the user.
//$role = sanitize_text_field( $_POST['role'] ); $role = 'bdonator';Forum: Plugins
In reply to: [Plugin: Theme My Login] add_action user_register does not workSorry, my last response did confuse you. Here is the actual code with which I got the problem.
In the regsiter form:
<input type="hidden" name="role" value="bdonator" />In functions.php:
function set_role_on_registration( $user_id ) { //$role = sanitize_text_field( $_POST['role'] ); $role = 'bdonator'; if ( in_array( $role, array( 'bdonator', 'bprofessional' ) ) ) add_user_meta( $user_id, 'pending_role', $role ); } add_action( 'tml_new_user_registered', 'set_role_on_registration' ); function set_role_on_activation( $user_id ) { if ( $pending_role = get_user_meta( $user_id, 'pending_role', true ) ) { if ( !in_array( $pending_role, array( 'bdonator', 'bprofessional' ) ) ) return; $user = new WP_User( $user_id ); $user->set_role( $pending_role ); unset( $user ); } } add_action( 'tml_new_user_activated', 'set_role_on_activation' );Thanks in advance for your patience 🙂
Forum: Plugins
In reply to: [Plugin: Theme My Login] add_action user_register does not workThanks for the quick reaction. I did.
Since it functions when I just put
$role = 'my_role1';I am sure that the POST is the problem.
Forum: Plugins
In reply to: [Plugin: Theme My Login] add_action user_register does not workGuess so, either. However, it does not. I checked if the hidden field actually exists and put it into the register form. But still nothing. I attached to action tag of the register form &role=myrole to get the value via GET. But still nothing!
In the register form and before the submit button I put:
<input type="hidden" name="role" value="bdonator" />and removed add_action(‘register_form’,’show_role_field’);.
In the function set_role_on_registration I put:
$role = sanitize_text_field( $_POST['role'] ); // $role = sanitize_text_field( $_GET['role'] );Forum: Plugins
In reply to: [Plugin: Theme My Login] add_action user_register does not workThank you very much for the revised solution. I have now more detailed view on the hooks of WordPress and Theme My Login plugin.
But anyhow I cannot receive the $_POST[‘role’] in function set_role_on_registration.
function show_role_field(){ ?> <input id="role" type="hidden" tabindex="20" size="25" value="my_role1" name="role"/> <?php } add_action('register_form','show_role_field'); function set_role_on_registration( $user_id ) { $role = 'my_role1'; // Works fine $role = sanitize_text_field( $_POST['role'] ); // Does not work if ( in_array( $role, array( 'my_role1', 'my_role2' ) ) ) add_user_meta( $user_id, 'pending_role', $role ); } add_action( 'tml_new_user_registered', 'set_role_on_registration' ); function set_role_on_activation( $user_id ) { if ( $pending_role = get_user_meta( $user_id, 'pending_role', true ) ) { if ( !in_array( $pending_role, array( 'my_role1', 'my_role2' ) ) ) return; $user = new WP_User( $user_id ); $user->set_role( $pending_role ); unset( $user ); } } add_action( 'tml_new_user_activated', 'set_role_on_activation' );; //end set user role at registrationDo you any hint for me what I am doing wrong? Thanks in advance.
Forum: Plugins
In reply to: [Plugin: Theme My Login] add_action user_register does not workYes. Seems that this was the reason. Due to the user moderation option “email verifcation”, registering a individual role on registration does not work.
Line 271 in user-moderation.php:
$user_object = new WP_User( $user->ID ); $user_object->set_role( get_option( 'default_role' ) ); unset( $user_object );Forum: Plugins
In reply to: [Plugin: Theme My Login] add_action user_register does not workThanks. But, doesn’t work either. Could it be because of the user moderation by email verifcation? Because the role is “Pending” after registration and after email confirmation the role is set to the default role.
Forum: Plugins
In reply to: [Plugin: Theme My Login] add_action user_register does not workThanks for the post. It is still not working. In my opinion it’s not about the function, its about the failed calling of the function during registration.
It seems that add_action( ‘user_register’, ‘set_role_on_registration’ ); does not work! I’ve tried to output an echo or alert in the function set_role_on_registration, but nothing happens.
My current approach in functions.php:
//create custom user role at registration ## example link: http://example.com/wp-login.php?action=register&role=my_role1 // function show_role_field(){ ?> <input id="role" type="hidden" tabindex="20" size="25" value="<?php if (isset($_GET['role'])){echo $_GET['role'];} ?>" name="role"/> <?php } add_action('register_form','show_role_field'); function set_role_on_registration( $user_id ) { $new_role = sanitize_text_field( $_POST['role'] ); //only allow if user role is one of defined roles if ( ($new_role == "my_role1") or ($new_role == "my_role2") ) { // Instantiate a user object $user = new WP_User( $user_id ); // Set your role $user->set_role( $new_role ); // Destroy user object unset( $user ); } } add_action( 'user_register', 'set_role_on_registration' ); //end create user role at registration