Skip to content

Commit

Permalink
Fixed Polylang incompatibility with MultisiteRelationship.
Browse files Browse the repository at this point in the history
  • Loading branch information
Miika Arponen committed Feb 17, 2020
1 parent 8db4aea commit 23dd170
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.28.1] - 2020-02-17

### Fixed
- Polylang incompatibility with MultisiteRelationship.

## [1.28.0] - 2020-02-07

### Added
Expand Down
20 changes: 20 additions & 0 deletions src/Fields/MultisiteRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,33 @@ public function get_ajax_query( $options = array() ) {

\switch_to_blog( $blog_id );

add_filter('acf/fields/relationship/query', [ $this, 'polylang_filter' ], 100, 3 );

$response = parent::get_ajax_query( $options );

remove_filter('acf/fields/relationship/query', [ $this, 'polylang_filter' ], 100 );

\restore_current_blog();

return $response;
}

/**
* A plugin specific fix for Polylang injecting wrong language taxonomy IDs with switch_to_blog.
*
* @param array $args The arguments to filter.
* @param array $field The field object.
* @param int $post_id The post ID.
* @return array
*/
public function polylang_filter( $args, $field, $post_id ) {
if ( function_exists( 'pll_current_language' ) && empty( $args['lang'] ) ) {
$args['lang'] = \pll_current_language();
}

return $args;
}

/**
* Get post title
*
Expand Down

0 comments on commit 23dd170

Please sign in to comment.