get_setting( 'taxonomy_names_checked' ) ) { $suffix_count = count( WPML_Terms_Translations::get_all_terms_with_language_suffix() ); if ( $suffix_count > 0 ) { $message = '

'; $message .= sprintf( __( 'In this version of WPML, you can give your taxonomy terms the same name across multiple languages. You need to update %d taxonomy terms on your website so that they display the same name without any language suffixes.', 'sitepress' ), $suffix_count ); $message .= '

'; if ( defined( 'ICL_PLUGIN_URL' ) ) { $message .= '

'; } ICL_AdminNotifier::addMessage( 'termssuffixnotice', $message, 'error', true, false, false, 'terms-suffix', true ); } $sitepress->set_setting( 'taxonomy_names_checked', true, true ); } // TODO: [WPML 3.3] the ICL_AdminNotifier class got improved and we should not call \ICL_AdminNotifier::displayMessages to display an admin notice ICL_AdminNotifier::displayMessages( 'terms-suffix' ); } /** * Returns the HTML for the display of all terms with a language suffix in the troubleshooting menu. * * @return string */ public static function display_terms_with_suffix() { $terms_to_display = WPML_Terms_Translations::get_all_terms_with_language_suffix(); $output = ''; if ( ! empty( $terms_to_display ) ) { $output = '

'; $output .= ''; $output .= ''; $output .= '

' . __( 'Remove language suffixes from taxonomy names.', 'sitepress' ) . '

'; $output .= ''; foreach ( $terms_to_display as $term_id => $term ) { $updated_term_name = self::strip_language_suffix( $term['name'] ); $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; } $output .= '
' . __( 'Old Name', 'sitepress' ) . '' . __( 'Updated Name', 'sitepress' ) . '' . __( 'Affected Taxonomies', 'sitepress' ) . '
'; $output .= ''; $output .= '' . $term['name'] . '' . $updated_term_name . '' . join( ', ', $term['taxonomies'] ) . '
'; $output .= '

'; $output .= ''; $output .= ''; $output .= '
'; } return $output; } /** * @param string $term_name * Strips a term off all language suffixes in the form @ on it. * * @return string */ public static function strip_language_suffix( $term_name ) { global $wpdb; $lang_codes = $wpdb->get_col( "SELECT code FROM {$wpdb->prefix}icl_languages" ); $new_name_parts = explode( ' @', $term_name ); $new_name_parts = array_filter( $new_name_parts ); $last_part = array_pop( $new_name_parts ); while ( in_array( $last_part, $lang_codes ) ) { $last_part = array_pop( $new_name_parts ); } $new_name = ''; if ( ! empty( $new_name_parts ) ) { $new_name = join( ' @', $new_name_parts ) . ' @'; } $new_name .= $last_part; return $new_name; } /** * Ajax handler for the troubleshoot page. Updates the term name on those terms given via the Ajax action. */ public static function wpml_update_term_names_troubleshoot() { global $wpdb; ICL_AdminNotifier::removeMessage( 'termssuffixnotice' ); $term_names = array(); $nonce = filter_input( INPUT_POST, '_icl_nonce', FILTER_SANITIZE_STRING ); if ( ! wp_verify_nonce( $nonce, 'update_term_names_nonce' ) ) { die( 'Wrong Nonce' ); } $request_post_terms = filter_input( INPUT_POST, 'terms', FILTER_SANITIZE_STRING ); if ( $request_post_terms ) { $term_names = json_decode( stripcslashes( $request_post_terms ) ); if ( ! is_object( $term_names ) ) { $term_names = array(); } } $updated = array(); foreach ( $term_names as $term_id => $new_name ) { $res = $wpdb->update( $wpdb->terms, array( 'name' => $new_name ), array( 'term_id' => $term_id ) ); if ( $res ) { $updated[] = $term_id; } } wp_send_json_success( $updated ); } }