Answer the question
In order to leave comments, you need to log in
How to import cyrillic users to wordpress site?
Hello! On a site running wordpress ,
the Cyrillic usernames plugin is installed .
Using the ClassiPress Ads Importer plugin , I import users with ads.
If the usernames are in Latin, then everything works fine, but if the authors are written in Cyrillic, then regardless of whether these are new users or existing ones, in the line
wp_set_object_terms( $post_id, array(intval($term['term_taxonomy_id'])), 'ad_cat');
I get an error:Fatal error: Cannot use object of type WP_Error as array, and the user himself has time to register (displayed in the admin panel)
foreach($rows as $row) {
$post['post_title'] = $row['post_title'];
$post['post_content'] = $row['post_content'];
$post['post_status'] = $row['post_status'];
$post['post_type'] = 'ad_listing';
if(isset($row['user_name'])) {
$user_id = username_exists($row['user_name']);
if(!$user_id) {
$random_password = wp_generate_password(12, false);
$user_id = wp_create_user($row['user_name'], $random_password);
}
}
unset($row['user_name']);
$post['post_author'] = $user_id;
if(!($term = term_exists($row['ad_cat'], 'ad_cat')))
$term = wp_insert_term($row['ad_cat'], 'ad_cat');
$post_id = wp_insert_post($post);
wp_set_object_terms( $post_id, array(intval($term['term_taxonomy_id'])), 'ad_cat');
function acu_sanitize_user($username, $raw_username, $strict) {
$username = wp_strip_all_tags( $raw_username );
$username = remove_accents( $username );
// Kill octets
$username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username );
$username = preg_replace( '/&.+?;/', '', $username ); // Kill entities
// If strict, reduce to ASCII and Cyrillic characters for max portability.
if ( $strict )
$username = preg_replace( '|[^a-zа-я0-9 _.\[email protected]]|iu', '', $username );
$username = trim( $username );
// Consolidate contiguous whitespace
$username = preg_replace( '|\s+|', ' ', $username );
return $username;
}
add_filter('sanitize_user', 'acu_sanitize_user', 10, 3);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question