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

57 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package Polylang
4 */
5
6 /**
7 * Manages filters and actions related to the block editor
8 *
9 * @since 2.5
10 */
11 class PLL_Admin_Block_Editor {
12 public $model;
13
14 /**
15 * Constructor: setups filters and actions
16 *
17 * @since 2.5
18 *
19 * @param object $polylang
20 */
21 public function __construct( &$polylang ) {
22 $this->model = &$polylang->model;
23 $this->pref_lang = &$polylang->pref_lang;
24
25 add_filter( 'block_editor_preload_paths', array( $this, 'preload_paths' ), 10, 2 );
26 }
27
28 /**
29 * Filter the preload REST requests by the current language of the post
30 * Necessary otherwise subsequent REST requests all filtered by the language
31 * would not hit the preloaded requests
32 *
33 * @since 2.5
34 *
35 * @param array $preload_paths Array of paths to preload.
36 * @param object $post The post resource data.
37 * @return array
38 */
39 public function preload_paths( $preload_paths, $post ) {
40 if ( $this->model->is_translated_post_type( $post->post_type ) ) {
41 $lang = $this->model->post->get_language( $post->ID );
42
43 if ( ! $lang ) {
44 $lang = $this->pref_lang;
45 }
46
47 foreach ( $preload_paths as $k => $path ) {
48 if ( is_string( $path ) && '/' !== $path ) {
49 $preload_paths[ $k ] = $path . "&lang={$lang->slug}";
50 }
51 }
52 }
53
54 return $preload_paths;
55 }
56 }
57