[wp-hackers] Replacing a function in Pluggable.php - wp_new_user_notification

Callum Macdonald lists.automattic.com at callum-macdonald.com
Sun Sep 9 19:45:23 GMT 2007


Hey Alex,

I think Johannes is right, I think there's probably a PHP error.

I think the list strips off attachments (I checked and I did remember to 
attach it!), so I've pastebined it here http://pastebin.com/m6cb3d895

Cheers,


Callum.

Alex Cragg wrote:
> Hi Callum,
>
> Thanks very much for the reply, i appreciate it.
>
> I tried what you suggested, despite not seeing anything attached as an 
> example  ;-) . but what happens now is that i register, and instead of 
> being redirected to the login page, i just stay at a blank page, and 
> no email is sent at all. I dont understand this as the original 
> function doesnt have anything to do with a redirect.
>
> I have had a look at the themed login/register plugin by James Kelly 
> (http://www.jameskelly.org/wordpress-plugins/custom-login-and-registration-forms-plugin/ 
> ) and stripped it down until only the functions that the plugin needed 
> to send the email were left, and then ive compared that to my plugin. 
> The only differences are that i am storing the options in an array, as 
> opposed to each option in a separate field on the database.
>
> I'd like to see your example, and any further help greatly appreciated.
>
> thanks again,
>
> Alex
>
>
> Callum Macdonald wrote:
>> Hey Alex,
>>
>> I think the problem is a PHP issue. You've defined the function 
>> wp_new_user_notification() as a method of the class 
>> NewUserEmailSetUp. I think if you move the function definition 
>> outside the class, and wrap it in a 
>> if(!function_exists('wp_new_user_notification')) { }, then it should 
>> work.
>>
>> I've attached what I mean, I think it should work, but I haven't 
>> tested it.
>>
>> Cheers,
>>
>>
>> Callum.
>>
>> Alex Cragg wrote:
>>> Hello everyone,
>>>
>>> this is my first email to this list, so i apologise if i dont go 
>>> about things correctly.
>>>
>>> I have posted this query in the support forums, but havent received 
>>> any replies.
>>>
>>> I am trying to write my first plugin to replace the email that is 
>>> sent out to new users using the wp_new_user_notification function. I 
>>> have written the plugin using the devlounge series on writing a 
>>> plugin, and it activates fine, and options are saved to the 
>>> database. at the moment i am concentrating on the body of the email 
>>> until i know more about what i am doing, so there is an admin panel 
>>> where this is defined.
>>>
>>> My problem is that the email text i am trying to define isnt being 
>>> used, and i cant find much documentation on wp_new_user_notification 
>>> or which wp function it hooks into. at the moment it is using 
>>> user_register, but i guessed as to whether it is right or not.
>>>
>>> the plugin is as follows
>>>
>>> if (!class_exists("NewUserEmailSetUp")) {
>>>   class NewUserEmailSetUp {
>>>       var $adminOptionsName = "NewUserEmailSetUpAdminOptions";
>>>       function NewUserEmailSetUp() { //constructor         }
>>>       function init() {
>>>           $this->getAdminOptions();
>>>       }
>>>       //Returns an array of admin options
>>>       function getAdminOptions() {
>>>           $emailnewuserAdminOptions = array(
>>>               'newuseremailtext' => '',
>>>               'newuseremailsubject' => '',
>>>               'newuseremailfromaddress' => '');
>>>           $emailOptions = get_option($this->adminOptionsName);
>>>           if (!empty($emailOptions)) {
>>>               foreach ($emailOptions as $key => $option)
>>>                   $emailnewuserAdminOptions[$key] = $option;
>>>           }                          
>>> update_option($this->adminOptionsName, $emailnewuserAdminOptions);
>>>           return $emailnewuserAdminOptions;
>>>       }
>>>       function wp_new_user_notification($user_id, $plaintext_pass = 
>>> '') {
>>>   $user = new WP_User($user_id);
>>>
>>>   $user_login = stripslashes($user->user_login);
>>>   $user_email = stripslashes($user->user_email);
>>>
>>>   $message  = sprintf(__('New user registration on your blog %s:'), 
>>> get_option('blogname')) . "\r\n\r\n";
>>>   $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
>>>   $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
>>>
>>>   @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User 
>>> Registration'), get_option('blogname')), $message);
>>>
>>>   if ( empty($plaintext_pass) )
>>>       return;
>>>   $message  = sprintf(__('Hi %s'), $user_login) . "\r\n";
>>>   $message .= $emailOptions("newuseremailtext") . "\r\n";
>>>   $message .= sprintf(__('Username: %s'), $user_login) . "\r\n";
>>>   $message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
>>>
>>>   wp_mail($user_email, sprintf(__('[%s] Welcome to my test blog'), 
>>> get_option('blogname')), $message);
>>> }
>>>       //Prints out the admin page
>>>       function printAdminPage() {
>>>                   $emailOptions = $this->getAdminOptions();
>>>                                                         if 
>>> (isset($_POST['update_emailnewuserSettings'])) {
>>>                       if (isset($_POST['emailnewuserText'])) {
>>>                           $emailOptions['newuseremailtext'] = 
>>> $_POST['emailnewuserText'];
>>>                       }
>>>                       if (isset($_POST['emailnewuserSubject'])) {
>>>                           $emailOptions['newuseremailsubject'] = 
>>> $_POST['emailnewuserSubject'];
>>>                       }                          if 
>>> (isset($_POST['emailnewuserFromAddress'])) {
>>>                           $emailOptions['newuseremailfromaddress'] = 
>>> $_POST['emailnewuserFromAddress'];
>>>                       }                          
>>> update_option($this->adminOptionsName, $emailOptions);
>>>                                             ?>
>>> <div class="updated"><p><strong><?php _e("Settings Updated.", 
>>> "NewUserEmailSetUp");?></strong></p></div>
>>>                   <?php
>>>                   } ?>
>>> <div class=wrap>
>>> <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
>>> <h2>New User Email Set Up</h2>
>>> <h3>Allow Comment Code in the Header?</h3>
>>> <p>Selecting "No" will disable the comment code inserted in the 
>>> header.</p>
>>> <p><label for="emailnewuserHeader_yes"><input type="radio" 
>>> id="emailnewuserHeader_yes" name="emailnewuserHeader" value="true" 
>>> <?php if ($emailOptions['show_header'] == "true") { 
>>> _e('checked="checked"', "NewUserEmailSetUp"); }?> /> 
>>> Yes</label>&nbsp;&nbsp;&nbsp;&nbsp;<label 
>>> for="emailnewuserHeader_no"><input type="radio" 
>>> id="emailnewuserHeader_no" name="emailnewuserHeader" value="false" 
>>> <?php if ($emailOptions['show_header'] == "false") { 
>>> _e('checked="checked"', "NewUserEmailSetUp"); }?>/> No</label></p>
>>>
>>> <h3>What Subject Would You Like Your Email To Have?</h3>
>>> <textarea name="emailnewuserSubject" style="width: 80%; height: 
>>> 100px;"><?php _e($emailOptions['newuseremailsubject'], 
>>> 'NewUserEmailSetUp') ?></textarea>
>>>
>>> <h3>What Text Would You Like To Have as Your Email Text?</h3>
>>> <textarea name="emailnewuserText" style="width: 80%; height: 
>>> 100px;"><?php _e($emailOptions['newuseremailtext'], 
>>> 'NewUserEmailSetUp') ?></textarea>
>>>
>>> <h3>What Address Would You Like to Send Your Email From? (NB you 
>>> must have this email set up as a real email address)</h3>
>>> <textarea name="emailnewuserFromAddress" style="width: 80%; height: 
>>> 100px;"><?php _e($emailOptions['newuseremailfromaddress'], 
>>> 'NewUserEmailSetUp') ?></textarea>
>>>
>>> <div class="submit">
>>> <input type="submit" name="update_emailnewuserSettings" value="<?php 
>>> _e('Update Settings', 'NewUserEmailSetUp') ?>" /></div>
>>> </form>
>>> </div>
>>>                   <?php
>>>               }//End function printAdminPage()
>>>   }
>>> } //End Class NewUserEmailSetUp
>>>
>>> if (class_exists("NewUserEmailSetUp")) {
>>>   $new_useremail = new NewUserEmailSetUp();
>>> }
>>>
>>> //Initialize the admin panel
>>> if (!function_exists("NewUserEmailSetUp_ap")) {
>>>   function NewUserEmailSetUp_ap() {
>>>       global $new_useremail;
>>>       if (!isset($new_useremail)) {
>>>           return;
>>>       }
>>>       if (function_exists('add_options_page')) {
>>>   add_options_page('New User Email Set Up', 'New User Email Set Up', 
>>> 9, basename(__FILE__), array(&$new_useremail, 'printAdminPage'));
>>>       }
>>>   }   }
>>>
>>> //Actions and Filters   if (isset($new_useremail)) {
>>>   //Actions
>>>   add_action('admin_menu', 'NewUserEmailSetUp_ap');
>>>   add_action('wp_head', array(&$new_useremail, 'addHeaderCode'), 1);
>>>   add_action('activate_mynewplugin.php',  array(&$new_useremail, 
>>> 'init'));
>>>   add_action('user_register', 'wp_new_user_notification');
>>>   //Filters
>>> }
>>>
>>> any pointer as to what is wrong, or what else is required to get the 
>>> text included in the email will be greatly appreciated, as i'd love 
>>> to be able to release this.
>>>
>>> thanks
>>> Alex
>>>
>>> _______________________________________________
>>> wp-hackers mailing list
>>> wp-hackers at lists.automattic.com
>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>
>>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>   
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
>



More information about the wp-hackers mailing list