On the site running wordpress installed plugin User Names in Cyrillic . 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 in Cyrillic, then regardless of whether new users or existing ones are in the line
wp_set_object_terms( $post_id, array(intval($term['term_taxonomy_id'])), 'ad_cat'); I get the 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)
I understand that the import works before the allow-cyrillic-usernames plugin manages to work out - how can I fix it?
plugin file classi-importer.class.php
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'); allow-cyrillic-usernames file
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 _.\-@]|iu', '', $username ); $username = trim( $username ); // Consolidate contiguous whitespace $username = preg_replace( '|\s+|', ' ', $username ); return $username; } add_filter('sanitize_user', 'acu_sanitize_user', 10, 3);