| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Manages filters and actions related to the block editor |
| 5 |
* |
| 6 |
* @since 2.5 |
| 7 |
*/ |
| 8 |
class PLL_Admin_Block_Editor { |
| 9 |
|
| 10 |
/** |
| 11 |
* Constructor: setups filters and actions |
| 12 |
* |
| 13 |
* @since 2.5 |
| 14 |
* |
| 15 |
* @param object $polylang |
| 16 |
*/ |
| 17 |
public function __construct( &$polylang ) { |
| 18 |
add_filter( 'block_editor_preload_paths', array( $this, 'preload_paths' ), 10, 2 ); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Filter the preload REST requests by the current language of the post |
| 23 |
* Necessary otherwise subsequent REST requests all filtered by the language |
| 24 |
* would not hit the preloaded requests |
| 25 |
* |
| 26 |
* @since 2.5 |
| 27 |
* |
| 28 |
* @param array $preload_paths Array of paths to preload. |
| 29 |
* @param object $post The post resource data. |
| 30 |
* @return array |
| 31 |
*/ |
| 32 |
public function preload_paths( $preload_paths, $post ) { |
| 33 |
$lang = pll_get_post_language( $post->ID ); |
| 34 |
|
| 35 |
foreach ( $preload_paths as $k => $path ) { |
| 36 |
if ( is_string( $path ) && '/' !== $path ) { |
| 37 |
$preload_paths[ $k ] = $path . "&lang={$lang}"; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
return $preload_paths; |
| 42 |
} |
| 43 |
} |
| 44 |
|