PluginProbe
Polylang / 2.7.1
Polylang v2.7.1
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.7.1, at admin/admin-block-editor.php

54 lines 1.2 KB
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 public $model;
10
11 /**
12 * Constructor: setups filters and actions
13 *
14 * @since 2.5
15 *
16 * @param object $polylang
17 */
18 public function __construct( &$polylang ) {
19 $this->model = &$polylang->model;
20 $this->pref_lang = &$polylang->pref_lang;
21
22 add_filter( 'block_editor_preload_paths', array( $this, 'preload_paths' ), 10, 2 );
23 }
24
25 /**
26 * Filter the preload REST requests by the current language of the post
27 * Necessary otherwise subsequent REST requests all filtered by the language
28 * would not hit the preloaded requests
29 *
30 * @since 2.5
31 *
32 * @param array $preload_paths Array of paths to preload.
33 * @param object $post The post resource data.
34 * @return array
35 */
36 public function preload_paths( $preload_paths, $post ) {
37 if ( $this->model->is_translated_post_type( $post->post_type ) ) {
38 $lang = $this->model->post->get_language( $post->ID );
39
40 if ( ! $lang ) {
41 $lang = $this->pref_lang;
42 }
43
44 foreach ( $preload_paths as $k => $path ) {
45 if ( is_string( $path ) && '/' !== $path ) {
46 $preload_paths[ $k ] = $path . "&lang={$lang->slug}";
47 }
48 }
49 }
50
51 return $preload_paths;
52 }
53 }
54