• Resolved starapple

    (@starapple)


    I’m attempting to add a filter to edit the message at the bottom of the registration form that says, “Registration confirmation will be emailed to you.” Doesn’t work.

    I did the following after reading that ‘registration_confirmation_msg’ had been added since Ver 4.4.0 https://core.trac.wordpress.org/attachment/ticket/31682/31682.2.diff

    function my_reg_message() {
        return __('Log in info sent to XXX');
    }
    add_filter(  'registration_confirmation_msg', 'my_reg_message' );

    What am I doing wrong?

    Thanks.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The filter didn’t make it into the codebase yet. Ticket status is new enhancement, and it doesn’t exist in the latest WP 4.7.2 – I just downloaded a fresh copy and verified it by opening wp-login.php.

    You could cheat and use translations to modify the output string. Though it’s tricky and would be more of a hack, really. Not sure if it’s worth the effort in your case.

    Thread Starter starapple

    (@starapple)

    Apparently this trac hasn’t been committed but I edited wp-login and it works for me. Hopefully it will be committed to the core so I don’t have to go fixing with each update.

    P.S So I see @spectrus. Bon soir.

    • This reply was modified 7 years, 1 month ago by starapple.
    • This reply was modified 7 years, 1 month ago by starapple.
    Moderator bcworkz

    (@bcworkz)

    Not keeping up to date I guess. That was a short lived filter. Keeping up to date is a big challenge, no one would fault you πŸ˜‰

    Now you use the “wp_login_errors” filter. Your callback is passed a WP_Error object. While this is not a real error, the messaging system is still used. Do something like $error->add('registered', __('Log in info sent to XXX'), 'message'); before returning the modified object.

    Thread Starter starapple

    (@starapple)

    Oh? There’s an error? I haven’t seen in Firefox console. I’ll take your advice.

    Thanks.

    Thread Starter starapple

    (@starapple)

    Added the line and got a fatal error. I’ll just live with an unseen error until this gets in the codebase.

    Moderator bcworkz

    (@bcworkz)

    It’s not a one liner code solution. It’s the important part of a callback function hooked to β€œwp_login_errors”. Since you already wrote a filter callback I thought you knew what to do with it. Bad assumption, my apologies.

    function my_reg_message( $error ) {
        $error->add('registered', __('Log in info sent to XXX'), 'message');
        return $error;
    }
    add_filter( 'wp_login_errors', 'my_reg_message' );

    I’m not sure what you had in mind for ‘XXX’. There’s scant data to work with when this filter fires.

    Thread Starter starapple

    (@starapple)

    OK. I’m sort of at a loss for real. I edited wp-login:

    // copied this line
           $reg_conf_message = apply_filters( 'registration_confirmation_msg', __( 'Registration confirmation will be emailed to you.' ) );
    	        ?>
    	        <p id="reg_passmail"><?php echo esc_html( $reg_conf_message ); ?></p>
    	<!-- commented this line<p id="reg_passmail"><?php _e( 'Registration confirmation will be emailed to you.' ); ?></p>-->

    I added this to my plugin that edits the registration screen and adds the ability to send the log in to a mobile number:

     function my_reg_message() {
       return __('Log in info will be sent to email and a link sent to cell phone');
    }
    add_filter(  'registration_confirmation_msg', 'my_reg_message' ); 

    I thought your suggestion was to add ` $error->add(‘registered’, __(‘Log in info sent to XXX’), ‘message’);
    return $error; ` to my_reg_message().

    XXX is not code; just ellipsis for additional text in the message on the form.

    OPERATE was just saying affect the execution.

    These are good lessons for me.

    Thanks.

    • This reply was modified 7 years, 1 month ago by starapple.
    Moderator bcworkz

    (@bcworkz)

    If you’re going to edit wp_login.php directly, just alter the existing message and be done with it. There’d be no point in fussing with hooks. But that is a really bad approach, please don’t even consider this.

    First, please restore wp-login.php to it’s default state. Maybe I’m a little slow to connect the dots, but I now think I see where you’re going with this. You are setting up your site to manage registration via SMS instead of email, yes? Great idea! Have you searched for an existing plugin that does this? Why reinvent the wheel?

    My next question was going to be where are you placing your custom code? But if you’ve found no plugin that does this, you’ve got to do this as your own plugin. People are going to want this! See Writing a Plugin. The basic setup is really simple. Include the code from my previous post on the plugin code page. That will alter the confirmation message.

    Edit: I just saw your post regarding creation of plugins. That pretty much answers my question. And thanks for helping out on other threads, the more the merrier πŸ™‚

    I knew you were replacing XXX with other text. What I was getting at relates to your other question about passing values. With filter hooks, you do not get to pick which parameters are passed, that is determined by the apply_filters() call. There is nothing in the ‘wp_login_errors’ hook that gives you any information about the user being registered, so it’s difficult to include any user specific information in this message (such as a phone number). You would be much better off if the message was more generic, like “Log in info sent to your phone via SMS”.

    • This reply was modified 7 years, 1 month ago by bcworkz.
    Thread Starter starapple

    (@starapple)

    @bcworkz, there are plugins that add SMS to WP but as is usually the case, they implement what the writer’s use case may have been originally and then take on a lot of bloat as others request features. There was even a project it seems, to include SMS in core from a couple years ago but that seems dormant.

    Then there’s one plugin that seems simple enough but it builds in a moneymaking catch where you have to pay dearly for a phone number verification service that costs more than sending a text. Sending a text via the service I’m using is cheaper than the cost to check if the number is valid. Useless.

    The other issue is that the plugin authors add unnecessary tables or columns to the database that’s already large as is–and with features to accommodate most of what’s being saved. Imagine you want to add one contact form to your site and install a forms plugin that gives you options for 200 forms you’ll never use, when all you need i s a little HTML and a hook to a page and wp-mail.

    So what have I done? added a few fields to user_meta and wp_options and dropped in things like the code from the SMS service’s PHP API.

    I’ve avoided dashboard clutter and a zillion ads asking to upgrade to useless features. I’ll send you a link to the project when it goes live but I don’t have a dynamic DNS service now so you see it on my work machine.

    Unfortunately, the one time I’ve touched the core is for the least significant part of the project but communication is a priority.

    And re the actual confirmation stuff, I’m sending the email and text simultaneously for a sort of redundant verification–one is no use without the other.

    How do you suggest I customize the entire registration screen to avoid touching wp-login? Again there’re plugins but some of them are almost as voluminous as the entire WP code base. Here’s a link to the image of the registration screen Registration screen. You’ll see the message at the bottom of the form.

    I’ve installed Members that seems to be one of the most useful plugins for WordPress.

    • This reply was modified 7 years, 1 month ago by starapple.
    Moderator bcworkz

    (@bcworkz)

    I like your plan! I agree that many plugins are just too feature laden. There’s always a need for super lightweight plugins that do one thing really well. I use Members intermittently on my test sites to help people with questions involving custom roles and capabilities. Much easier than writing the necessary code. Nice plugin. On client sites I write the code because it’s lighter weight πŸ˜‰

    I’m assuming you’ve managed altering the registration form so far by directly editing wp-login.php and you wish to identify the proper way to handle this.

    In keeping with the lightweight concept, we shouldn’t modify the registration screen any more than necessary. I’ve covered the confirmation message. Other messages are likely managed in a similar manner, for example the password reset message is changed by adding the ‘newpass’ error message.

    We can add additional registration fields through the “register_form” action. Simply echo out the all the field HTML from the callback. The added field data can be processed through the “register_new_user” action. The new user ID is passed to your callback. The field data should still be in the super-global $_POST array. The data should be validated and sanitized before adding it to the user’s meta data.

    The sendtext() calls can be added to the various functions that compose and send the email messages. Since you are also sending email, you could just hook the “wp_mail” filter and sendtext() from there. The tricky part though would be determining which mail messages should be texted and which not. Hooking more specific functions may be a better choice. They typically have a usable action. If not they are possibly a pluggable function that a plugin can re-define.

    There is invariably a hook to use for almost any situation. There is never any valid reason to alter core files. In some cases it may take some creativity to find a solution. I’m generally pretty good at that, so if you’re stuck, just ask!

    You should have the clear impression by now that nearly everything in WP is managed through a filter or action hook of some sort. If you’re going to spend time learning something, getting a clear understanding of how filter and action hooks work and how to write callback functions would be a great place to start.

    Thread Starter starapple

    (@starapple)

    Unfortunately the hook for “registration_confirmation_msg” hasn’t been committed.

    The only simple thing I can think of to get around this is using javascript on the reg_passmail id. The function could replace what’s between the <p> tag with the id:

    <p id="reg_passmail"><?php _e( 'Registration confirmation will be emailed to you.' ); ?>

    Time to read up on javascript.

    Re the actual sending of the messages on completion of the registration, that’s what I’ve done. Except I’ve redirected one line to sendtext(). The rest goes to wp_mail.

    Thread Starter starapple

    (@starapple)

    Done! No edit to the core file.

    add_action('login_footer', 'add_reg_passmsg');
    function add_reg_passmsg(){ ?>
    <script type="text/javascript">document.getElementById("reg_passmail").innerHTML = "YOUR NOTE ON THE FORM TO THE USER GOES HERE.";
    </script>
    <?php }

    Thanks for the discussion @bcworkz. I look forward to more help from you and others.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Editing the Registration Confirmation Notice on Registration Form’ is closed to new replies.