Polylang 1.8 for the developpers

As announced with the beta version, Polylang 1.8 will include several changes under the hood.

This version will introduce two new API functions, pll_get_post_translations() and pll_get_term_translations(), and a new WPML compatibility API function, wpml_get_language_information(). Note that all API are now available only once the action ‘plugins_loaded’ has been fired (they were available as soon as Polylang was loaded in previous versions).

When possible it is preferrable to use the API functions. This offers you the assurance that your plugin won’t break at Polylang update. However if for some reasons you need to interact with Polylang at low level, the function PLL() has been introduced to access the global Polylang object.

The most important for third party plugins interacting at low level with Polylang are the changes to the PLL_Model class. Posts and terms related methods have been moved to their own class. Here is an exhaustive list of methods removed from PLL_Model and examples of how to replace them:

get_object_term

Apply the same method to PLL_Model::$post or PLL_Model::$term:

Old:	$polylang->model->get_object_term( $object_id, $taxonomy )
New:	PLL()->model->post->get_object_term( $object_id, $taxonomy )
	PLL()->model->term->get_object_term( $object_id, $taxonomy )

save_translations
delete_translation
get_translations
get_translation
join_clause
where_clause
get_objects_in_language

Apply the same method to PLL_Model::$post or PLL_Model::$term and remove the ‘post’ or ‘term’  argument:

Old:	$polylang->model->save_translations( ‘post’, $id, $translations )
	$polylang->model->save_translations( ‘term’, $id, $translations )
New:	PLL()->model->post->save_translations( $id, $translations )
	PLL()->model->term->save_translations( $id, $translations )

set_post_language
get_post_language
get_post

Remove ‘_post’ from the method name and apply it to PLL_Model::$post

Old:	$polylang->model->set_post_language($post_id, $lang )
New:	PLL()->model->post->set_language($post_id, $lang )

set_term_language
get_term_language
delete_term_language
get_term

Remove ‘_term’ from the method name and apply it to PLL_Model::$term

Old:	$polylang->model->set_term_language($term_id, $lang )
New:	PLL()->model->term->set_language($term_id, $lang )

Nothing should break as I introduced backward compatibility with the magic method __call(), however Polylang will trigger an error message when WP_DEBUG is set to true. There is no warranty that I will keep this magic method in the future.

Some other changes were done (for example, in the management of the static front pages) but I guess that these should have no impact for third party plugins. Anyway, it’s still better to use the beta period to test your theme(s) or plugin(s) against this new version.

For those, interacting directly at database level, no change was made in the way Polylang manages its data.

Advertisements