PluginProbe
Polylang / 2.5.2
Polylang v2.5.2
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / admin / admin-block-editor.php

admin-block-editor.php in Polylang 2.5.2, at admin/admin-block-editor.php

44 lines 1014 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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