Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace deprecated calls #35

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions polylang-translate-rewrite-slugs.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ public function init_action() {
* Create a "PLL_TRS_Post_Type" and add it to the handled post type list.
*/
public function add_post_type($post_type, $translated_slugs) {
global $polylang;

$languages = $polylang->model->get_languages_list();
$languages = PLL()->model->get_languages_list();
$post_type_object = get_post_type_object($post_type);
if (!is_null($post_type_object)) {
foreach ($languages as $language) {
Expand All @@ -151,9 +149,7 @@ public function add_post_type($post_type, $translated_slugs) {
* ...
*/
public function add_taxonomy($taxonomy, $translated_slugs) {
global $polylang;

$languages = $polylang->model->get_languages_list();
$languages = PLL()->model->get_languages_list();
$taxonomy_object = get_taxonomy($taxonomy);
if (!is_null($taxonomy_object)) {
$translated_struct = array();
Expand All @@ -175,10 +171,8 @@ public function add_taxonomy($taxonomy, $translated_slugs) {
* Fix "get_permalink" for this post type.
*/
public function post_type_link_filter($post_link, $post, $leavename, $sample) {
global $polylang;

// We always check for the post language. Otherwise, the current language.
$post_language = $polylang->model->get_post_language($post->ID);
$post_language = PLL()->model->post->get_language($post->ID);
if ($post_language) {
$lang = $post_language->slug;
} else {
Expand All @@ -199,8 +193,7 @@ public function post_type_link_filter($post_link, $post, $leavename, $sample) {
*/
public function post_type_archive_link_filter($link, $archive_post_type) {
if (is_admin()) {
global $polylang;
$lang = $polylang->pref_lang->slug;
$lang = PLL()->pref_lang->slug;
} else {
$lang = pll_current_language();
}
Expand All @@ -219,7 +212,7 @@ public function post_type_archive_link_filter($link, $archive_post_type) {
* @see wp-include/link-template.php, get_post_type_archive_link().
*/
private function get_post_type_archive_link($post_type, $lang) {
global $wp_rewrite, $polylang;
global $wp_rewrite;

// If the post type is handle, let the "$this->get_post_type_archive_link"
// function handle this.
Expand All @@ -235,10 +228,10 @@ private function get_post_type_archive_link($post_type, $lang) {

if (
// If the "URL modifications" is set to "The language is set from the directory name in pretty permalinks".
$polylang->options['force_lang'] == 1
PLL()->options['force_lang'] == 1
// If NOT ("Hide URL language information for default language" option is
// set to true and the $lang is the default language.)
&& !($polylang->options['hide_default'] && $lang == pll_default_language())
&& !(PLL()->options['hide_default'] && $lang == pll_default_language())
) {
$struct = $lang . '/' . $struct;
}
Expand All @@ -262,7 +255,7 @@ private function get_post_type_archive_link($post_type, $lang) {
public function term_link_filter($termlink, $term, $taxonomy) {
// Check if the post type is handle.
if (isset($this->taxonomies[$taxonomy])) {
global $wp_rewrite, $polylang;
global $wp_rewrite;

if ( !is_object($term) ) {
if ( is_int($term) ) {
Expand All @@ -279,7 +272,7 @@ public function term_link_filter($termlink, $term, $taxonomy) {
return $term;

// Get the term language.
$term_language = $polylang->model->get_term_language($term->term_id);
$term_language = PLL()->model->get_term_language($term->term_id);
if ($term_language) {
$lang = $term_language->slug;
} else {
Expand Down Expand Up @@ -333,7 +326,7 @@ public function term_link_filter($termlink, $term, $taxonomy) {
* Fix "PLL_Frontend_Links->get_translation_url()".
*/
public function pll_translation_url_filter($url, $lang) {
global $wp_query, $polylang;
global $wp_query;

if (is_category()) {
$term = get_category_by_slug($wp_query->get('category_name'));
Expand Down