- Status
- Resolvido
- Relatado para
- WPML Multilingual CMS 3.3.6
- Resolvido em
- WPML 3.4.0
Visão geral do problema
O problema aparece quando você tem uma consulta para duas taxonomias – semelhante a estes exemplos:
http://example.com/?my-category=term&other-category=other-term
http://example.com/other-category/other-term/?my-category=term
http://example.com/my-category/term/?other-category=other-term
Isso leva ao seguinte erro:
PHP Catchable fatal error: Object of class WP_Error could not be converted to string in .../wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php on line 4843
Solução alternativa
A seguinte solução alternativa funciona tanto para as versões 3.3.6 quanto 3.3.7 do WPML, mas o nome do arquivo que você precisa editar é diferente:
- Para a versão 3.3.6 do WPML, você precisa editar o arquivo sitepress.class.php, que pode ser encontrado na pasta principal do plugin WPML.
- Para a versão 3.3.7 do WPML, você precisa editar o arquivo class-wpml-seo-headlangs.php, que pode ser encontrado no seguinte local: ../sitepress-multilingual-cms/classes/seo/
Você precisa procurar a função head_langs() (por volta da linha 4619). Substitua essa função pelo seguinte código:
function head_langs()
{
$languages = $this->get_ls_languages( array( 'skip_missing' => true ) );
// If there are translations and is not paged content...
// Renders head alternate links only on certain conditions
$the_post = get_post();
$the_id = $the_post ? $the_post->ID : false;
$is_valid = count( $languages ) > 1
&& !is_paged()
&& ( ( ( is_single()
|| is_page() )
&& $the_id
&& get_post_status( $the_id ) == 'publish' )
|| ( is_home()
|| is_front_page()
|| is_archive() ) );
if ( $is_valid ) {
foreach ( $languages as $code => $lang ) {
if (!is_wp_error($lang[ 'url' ])) { // <<< temp fix
$alternate_hreflang =
apply_filters( 'wpml_alternate_hreflang', $lang[ 'url' ], $code );
printf( '' . PHP_EOL,
$this->get_language_tag( $code ),
str_replace( '&', '&', $alternate_hreflang )
);
} // <<< temp fix
}
}
}
Em seguida, no mesmo arquivo, encontre a função render_ls_li_item (por volta da linha 3319). Substitua-a pelo seguinte código:
public function render_ls_li_item( $lang,
$lang_native_hidden = false,
$lang_translated_hidden = false,
$language_selected = ""
)
{
global $icl_language_switcher_preview;
if (!is_wp_error($lang[ 'url' ])) { // <<< temp fix
$country_flag_url = $lang[ 'country_flag_url' ];
$language_url = apply_filters ( 'WPML_filter_link', $lang[ 'url' ], $lang );
$language_flag_title = $this->settings[ 'icl_lso_display_lang' ]
? esc_attr ( $lang[ 'translated_name' ] )
: esc_attr ( $lang[ 'native_name' ] );
$ls_settings =
$this->get_ls_settings ( $lang, $lang_native_hidden, $lang_translated_hidden );
$language_selector =
'<li class="icl-' . $lang[ 'language_code' ]
. '"><a href="' . $language_url . '" ' . $language_selected . '>';
if ( $this->settings[ 'icl_lso_flags' ]
|| $icl_language_switcher_preview ):
$language_selector .=
'<img ' . ( !$this->settings[ 'icl_lso_flags' ]
? 'style="display:none"' : '' )
. ' class="iclflag" '
. 'src="' . $country_flag_url . '" '
. 'alt="' . $lang[ 'language_code' ] . '" '
. 'title="' . $language_flag_title . '" /> ';
endif;
$ls_settings = $this->get_ls_settings (
$lang,
$ls_settings[ 'lang_native_hidden' ],
$ls_settings[ 'lang_translated_hidden' ]
);
$language_selector .= icl_disp_language (
$ls_settings[ 'lang_native' ],
$ls_settings[ 'lang_translated' ],
$ls_settings[ 'lang_native_hidden' ],
$ls_settings[ 'lang_translated_hidden' ]
);
$language_selector
.= '</a></li>';
return $language_selector;
} // <<< temp fix
}