Hello,
ich würde gerne per User einen Button machen, mit dem ich das Passwort zurück setzen & dem User mailen kann.
Habe mir zwar den Code aus dem Core (wp-login.php) angesehen, werde aber nicht so ganz schlau daraus, wie ich vor gehen sollte. Bin für jede Hilfe dankbar!
Code
216 /**
217 * Handles resetting the user's password.
218 *
219 * @uses $wpdb WordPress Database object
220 *
221 * @param string $key Hash to validate sending user's password
222 * @return bool|WP_Error
223 */
224 function [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/reset_password.html"]reset_password[/URL]([URL="http://phpxref.ftwr.co.uk/wordpress/_variables/key.html"]$key[/URL], [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/login.html"]$login[/URL]) {
225 global [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/wpdb.html"]$wpdb[/URL];
226
227 [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/key.html"]$key[/URL] = [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/preg_replace.html"]preg_replace[/URL]('/[^a-z0-9]/i', '', [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/key.html"]$key[/URL]);
228
229 if ( [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/empty.html"]empty[/URL]( [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/key.html"]$key[/URL] ) || ![URL="http://phpxref.ftwr.co.uk/wordpress/_functions/is_string.html"]is_string[/URL]( [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/key.html"]$key[/URL] ) )
230 return new [URL="http://phpxref.ftwr.co.uk/wordpress/_classes/wp_error.html"]WP_Error[/URL]('invalid_key', [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/__.html"]__[/URL]('Invalid key'));
231
232 if ( [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/empty.html"]empty[/URL]([URL="http://phpxref.ftwr.co.uk/wordpress/_variables/login.html"]$login[/URL]) || ![URL="http://phpxref.ftwr.co.uk/wordpress/_functions/is_string.html"]is_string[/URL]([URL="http://phpxref.ftwr.co.uk/wordpress/_variables/login.html"]$login[/URL]) )
233 return new [URL="http://phpxref.ftwr.co.uk/wordpress/_classes/wp_error.html"]WP_Error[/URL]('invalid_key', [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/__.html"]__[/URL]('Invalid key'));
234
235 [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/user.html"]$user[/URL] = [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/wpdb.html"]$wpdb[/URL]->[URL="http://phpxref.ftwr.co.uk/wordpress/_functions/get_row.html"]get_row[/URL]([URL="http://phpxref.ftwr.co.uk/wordpress/_variables/wpdb.html"]$wpdb[/URL]->[URL="http://phpxref.ftwr.co.uk/wordpress/_functions/prepare.html"]prepare[/URL]("SELECT * FROM [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/wpdb.html"]$wpdb[/URL]->[URL="http://phpxref.ftwr.co.uk/wordpress/_variables/users.html"]users[/URL] WHERE user_activation_key = %s AND user_login = %s", [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/key.html"]$key[/URL], [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/login.html"]$login[/URL]));
236 if ( [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/empty.html"]empty[/URL]( [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/user.html"]$user[/URL] ) )
237 return new [URL="http://phpxref.ftwr.co.uk/wordpress/_classes/wp_error.html"]WP_Error[/URL]('invalid_key', [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/__.html"]__[/URL]('Invalid key'));
238
239 // Generate something random for a password...
240 [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/new_pass.html"]$new_pass[/URL] = [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/wp_generate_password.html"]wp_generate_password[/URL]();
241
242 [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/do_action.html"]do_action[/URL]('password_reset', [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/user.html"]$user[/URL], [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/new_pass.html"]$new_pass[/URL]);
243
244 [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/wp_set_password.html"]wp_set_password[/URL]([URL="http://phpxref.ftwr.co.uk/wordpress/_variables/new_pass.html"]$new_pass[/URL], [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/user.html"]$user[/URL]->[URL="http://phpxref.ftwr.co.uk/wordpress/_variables/ID.html"]ID[/URL]);
245 [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/update_user_option.html"]update_user_option[/URL]([URL="http://phpxref.ftwr.co.uk/wordpress/_variables/user.html"]$user[/URL]->[URL="http://phpxref.ftwr.co.uk/wordpress/_variables/ID.html"]ID[/URL], 'default_password_nag', true, true); //Set up the Password change nag.
246 [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/message.html"]$message[/URL] = sprintf([URL="http://phpxref.ftwr.co.uk/wordpress/_functions/__.html"]__[/URL]('Username: %s'), [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/user.html"]$user[/URL]->[URL="http://phpxref.ftwr.co.uk/wordpress/_variables/user_login.html"]user_login[/URL]) . "\r\n";
247 [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/message.html"]$message[/URL] .= sprintf([URL="http://phpxref.ftwr.co.uk/wordpress/_functions/__.html"]__[/URL]('Password: %s'), [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/new_pass.html"]$new_pass[/URL]) . "\r\n";
248 [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/message.html"]$message[/URL] .= [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/site_url.html"]site_url[/URL]('[URL="http://phpxref.ftwr.co.uk/wordpress/wp-login.php.html"]wp-login.php[/URL]', 'login') . "\r\n";
249
250 if ( [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/is_multisite.html"]is_multisite[/URL]() )
251 [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/blogname.html"]$blogname[/URL] = [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/GLOBALS.html"]$GLOBALS[/URL]['current_site']->site_name;
252 else
253 // The blogname option is escaped with esc_html on the way into the database in sanitize_option
254 // we want to reverse this for the plain text arena of emails.
255 [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/blogname.html"]$blogname[/URL] = [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/wp_specialchars_decode.html"]wp_specialchars_decode[/URL]([URL="http://phpxref.ftwr.co.uk/wordpress/_functions/get_option.html"]get_option[/URL]('blogname'), ENT_QUOTES);
256
257 [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/title.html"]$title[/URL] = sprintf( [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/__.html"]__[/URL]('[%s] Your new password'), [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/blogname.html"]$blogname[/URL] );
258
259 [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/title.html"]$title[/URL] = [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/apply_filters.html"]apply_filters[/URL]('password_reset_title', [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/title.html"]$title[/URL]);
260 [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/message.html"]$message[/URL] = [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/apply_filters.html"]apply_filters[/URL]('password_reset_message', [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/message.html"]$message[/URL], [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/new_pass.html"]$new_pass[/URL]);
261
262 if ( [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/message.html"]$message[/URL] && ![URL="http://phpxref.ftwr.co.uk/wordpress/_functions/wp_mail.html"]wp_mail[/URL]([URL="http://phpxref.ftwr.co.uk/wordpress/_variables/user.html"]$user[/URL]->[URL="http://phpxref.ftwr.co.uk/wordpress/_variables/user_email.html"]user_email[/URL], [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/title.html"]$title[/URL], [URL="http://phpxref.ftwr.co.uk/wordpress/_variables/message.html"]$message[/URL]) )
263 [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/wp_die.html"]wp_die[/URL]( [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/__.html"]__[/URL]('The e-mail could not be sent.') . "<br />\n" . [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/__.html"]__[/URL]('Possible reason: your host may have disabled the [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/mail.html"]mail[/URL]() function...') );
264
265 [URL="http://phpxref.ftwr.co.uk/wordpress/_functions/wp_password_change_notification.html"]wp_password_change_notification[/URL]([URL="http://phpxref.ftwr.co.uk/wordpress/_variables/user.html"]$user[/URL]);
266
267 return true;
268 }
Alles anzeigen