vendredi 2 janvier 2015

Call wp_generate_password() from within a Class


I have a function to add wp users. There is a $password = wp_generate_password(); in it. This works.


Now I'm creating a class XenWord_Add_WP_User based on the function. In fact, I copied the function to become a method public function xenword_add_wp_user()


However, this is failing. The error states call to undefined function wp_generate_password(). How can I call wp_generate_password() within a class?


Here is a portion of the class.



Class XenWord_Add_WP_User {

public function xenword_add_wp_user() {
/**
* @since 1.0.6
* Insert the current user into the wp_users and wp_usermeta table
*
* @since 1.0.7
* Moved this code to a separate function.
*
* TODO: This code needs to be cleaned up
*/

global $wpdb;

$xenword_options = get_option( 'xenword_options' );

$visitor = XenForo_Visitor::getInstance();

$user_ID = $visitor->get( 'user_id' );

/* Added 2.0.1.02 */
$wp_default_role = $xenword_options['wp_default_role'];

$user_check = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users WHERE ID = '$user_ID' " );
$user_id = $visitor->get( 'user_id' );
$password = wp_generate_password();
$nickname = $visitor->get( 'username' );
$email = $visitor->get( 'email' );
$current_registration = date('Y/m/d H:i:s', $visitor->get('register_date'));
// removed the rest of the class in this post since the failure is a few lines up.
}
}
$wp_add_user = new XenWord_Add_WP_User();




Aucun commentaire:

Enregistrer un commentaire