Skip to content
Docs
Get RestroPress

Filter

wpml_object_id

Updated
On this page

Calls WPML's filter to get the translated ID of a page.

RestroPress applies this WPML filter to map its configured pages (menu, checkout and success pages) to their translation in the current language. This is used when building translated page URLs, deciding whether the current request is a RestroPress page, the checkout or the success page, and when disabling canonical redirects on the checkout and success pages. WPML returns the translated ID.

Parameters#

ParameterTypeDescription
$element_idintThe ID of the page to translate.
$element_typestringThe element type; always 'page' in RestroPress.
$return_original_if_missingboolWhether to return the original ID when there is no translation.
$language_codestringThe target language code.

Return value#

int|null. The translated page ID; null when no translation exists and the original is not requested.

Example#

add_filter( 'wpml_object_id', 'my_map_page_translation', 10, 4 );
function my_map_page_translation( $element_id, $element_type, $return_original_if_missing, $language_code ) {
	if ( 'page' === $element_type && 'fr' === $language_code && 123 === (int) $element_id ) {
		return 456;
	}
	return $element_id;
}

Notes#

The third argument is true when building translated page URLs and when checking the success page, and false for the page-matching, checkout and redirect checks. A null result is then ignored.

Source#

Applied in:

  • includes/plugin-compatibility.php (line 266), in rpress_wpml_translate_page_url()
  • includes/plugin-compatibility.php (line 326), in rpress_wpml_filter_is_a_restropress_page()
  • includes/plugin-compatibility.php (line 370), in rpress_wpml_filter_is_checkout()
  • includes/plugin-compatibility.php (line 406), in rpress_wpml_disable_canonical_redirect()
  • includes/plugin-compatibility.php (line 407), in rpress_wpml_disable_canonical_redirect()
  • includes/plugin-compatibility.php (line 439), in rpress_wpml_filter_is_success_page()

See also#

Was this page helpful?