블로그

  • wp_update_user

    <?php
    // 사용자 ID가 1인 사용자의 이름, 이메일, 비밀번호 업데이트하기
    $user_id = 1;
    $new_data = array(
        'ID'             => $user_id,
        'user_login'     => $user_login,  // login 
        'display_name'   => 'Updated User Name', // 표시 이름 변경
        'user_email'     => 'new.email@example.com', // 이메일 변경
        'user_pass'      => 'new_secure_password', // 비밀번호 변경 (암호화됨)
        'first_name'     => 'John', // 이름 변경
        'last_name'      => 'Doe',  // 성 변경
        'role'           => 'editor' // 역할 변경 (subscriber, editor, administrator 등)
    );
    
    $updated_user_id = wp_update_user( $new_data );
    
    if ( is_wp_error( $updated_user_id ) ) {
        // 오류 처리
        echo '사용자 업데이트 실패: ' . $updated_user_id->get_error_message();
    } else {
        // 성공 메시지
        echo '사용자 ID ' . $updated_user_id . ' 정보가 성공적으로 업데이트되었습니다.';
    }
    ?>
    
  • wp_insert_user

    <?php
    $user_data = array(
        'user_login'    => 'testuser',
        'user_pass'     => 'testpassword123!',
        'user_email'    => 'testuser@example.com',
        'first_name'    => 'Test',
        'last_name'     => 'User',
        'role'          => 'subscriber' // 역할을 구독자로 지정
    );
    
    $user_id = wp_insert_user( $user_data );
    
    // 사용자 생성 성공 여부 확인
    if ( is_wp_error( $user_id ) ) {
        // 오류 발생 시 오류 메시지 출력
        $error_message = $user_id->get_error_message();
        echo "사용자 생성 오류: " . $error_message;
    } else {
        // 성공 시 사용자 ID 출력
        echo "사용자가 성공적으로 생성되었습니다. 사용자 ID: " . $user_id;
    }
    ?>
    $userdata = array(
    	'ID' 					=> 0, 	//(int) User ID. If supplied, the user will be updated.
    	'user_pass'				=> '', 	//(string) The plain-text user password.
    	'user_login' 			=> '', 	//(string) The user's login username.
    	'user_nicename' 		=> '', 	//(string) The URL-friendly user name.
    	'user_url' 				=> '', 	//(string) The user URL.
    	'user_email' 			=> '', 	//(string) The user email address.
    	'display_name' 			=> '', 	//(string) The user's display name. Default is the user's username.
    	'nickname' 				=> '', 	//(string) The user's nickname. Default is the user's username.
    	'first_name' 			=> '', 	//(string) The user's first name. For new users, will be used to build the first part of the user's display name if $display_name is not specified.
    	'last_name' 			=> '', 	//(string) The user's last name. For new users, will be used to build the second part of the user's display name if $display_name is not specified.
    	'description' 			=> '', 	//(string) The user's biographical description.
    	'rich_editing' 			=> '', 	//(string|bool) Whether to enable the rich-editor for the user. False if not empty.
    	'syntax_highlighting' 	=> '', 	//(string|bool) Whether to enable the rich code editor for the user. False if not empty.
    	'comment_shortcuts' 	=> '', 	//(string|bool) Whether to enable comment moderation keyboard shortcuts for the user. Default false.
    	'admin_color' 			=> '', 	//(string) Admin color scheme for the user. Default 'fresh'.
    	'use_ssl' 				=> '', 	//(bool) Whether the user should always access the admin over https. Default false.
    	'user_registered' 		=> '', 	//(string) Date the user registered. Format is 'Y-m-d H:i:s'.
    	'show_admin_bar_front' 	=> '', 	//(string|bool) Whether to display the Admin Bar for the user on the site's front end. Default true.
    	'role' 					=> '', 	//(string) User's role.
    	'locale' 				=> '', 	//(string) User's locale. Default empty.
    
    );
    $userdata
    array|object|WP_User
    required
    An array, object, or WP_User object of user data arguments.
    ID int User ID. If supplied, the user will be updated.
    user_pass string
    The plain-text user password for new users.
    Hashed password for existing users.
    user_login string
    The user’s login username.
    user_nicename string
    The URL-friendly user name.
    user_url string
    The user URL.
    user_email string
    The user email address.
    display_name string
    The user’s display name.
    Default is the user’s username.
    nickname string
    The user’s nickname.
    Default is the user’s username.
    first_name string
    The user’s first name. For new users, will be used to build the first part of the user’s display name if $display_name is not specified.
    last_name string
    The user’s last name. For new users, will be used to build the second part of the user’s display name if $display_name is not specified.
    description string
    The user’s biographical description.
    rich_editing string
    Whether to enable the rich-editor for the user.
    Accepts 'true' or 'false' as a string literal, not boolean. Default 'true'.
    syntax_highlighting string
    Whether to enable the rich code editor for the user.
    Accepts 'true' or 'false' as a string literal, not boolean. Default 'true'.
    comment_shortcuts string
    Whether to enable comment moderation keyboard shortcuts for the user. Accepts 'true' or 'false' as a string literal, not boolean. Default 'false'.
    admin_color string
    Admin color scheme for the user. Default 'fresh'.
    use_ssl bool
    Whether the user should always access the admin over https. Default false.
    user_registered string
    Date the user registered in UTC. Format is ‘Y-m-d H:i:s’.
    user_activation_key string
    Password reset key. Default empty.
    spam bool
    Multisite only. Whether the user is marked as spam.
    Default false.
    show_admin_bar_front string
    Whether to display the Admin Bar for the user on the site’s front end. Accepts 'true' or 'false' as a string literal, not boolean. Default 'true'.
    role string
    User’s role.
    locale string
    User’s locale. Default empty.
    meta_input array
    Array of custom user meta values keyed by meta key.
    Default empty.
  • is_email

    if ( is_email( $email_address ) ) {
       echo "'" . $email_address . "'은(는) 유효한 이메일 주소입니다.";
    } else {
       echo "'" . $email_address . "'은(는) 유효하지 않은 이메일 주소입니다.";
    }