PluginProbe
Polylang / 2.5
Polylang v2.5
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
← All changes | admin/admin-block-editor.php +10 -33 3.02.5 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Manages filters and actions related to the block editor
8 5 *
@@ -8,21 +5,10 @@
8 5 *
9 6 * @since 2.5
10 7 */
11 8 class PLL_Admin_Block_Editor {
12 - /**
13 - * @var PLL_Model
14 - */
15 - protected $model;
16 9
17 10 /**
18 - * Preferred language to assign to a new post.
19 - *
20 - * @var PLL_Language
21 - */
22 - protected $pref_lang;
23 -
24 - /**
25 11 * Constructor: setups filters and actions
26 12 *
27 13 * @since 2.5
28 14 *
@@ -28,37 +14,28 @@
28 14 *
29 15 * @param object $polylang
30 16 */
31 17 public function __construct( &$polylang ) {
32 - $this->model = &$polylang->model;
33 - $this->pref_lang = &$polylang->pref_lang;
34 -
35 18 add_filter( 'block_editor_preload_paths', array( $this, 'preload_paths' ), 10, 2 );
36 19 }
37 20
38 21 /**
39 - * Filters the preload REST requests by the current language of the post.
40 - * Necessary otherwise subsequent REST requests, all filtered by the language,
41 - * would not hit the preloaded requests.
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
42 25 *
43 26 * @since 2.5
44 27 *
45 - * @param (string|string[])[] $preload_paths Array of paths to preload.
46 - * @param WP_Post $post The post resource data.
47 - * @return (string|string[])[]
28 + * @param array $preload_paths Array of paths to preload.
29 + * @param object $post The post resource data.
30 + * @return array
48 31 */
49 32 public function preload_paths( $preload_paths, $post ) {
50 - if ( $this->model->is_translated_post_type( $post->post_type ) ) {
51 - $lang = $this->model->post->get_language( $post->ID );
33 + $lang = pll_get_post_language( $post->ID );
52 34
53 - if ( ! $lang ) {
54 - $lang = $this->pref_lang;
55 - }
56 -
57 - foreach ( $preload_paths as $k => $path ) {
58 - if ( is_string( $path ) && '/' !== $path ) {
59 - $preload_paths[ $k ] = $path . "&lang={$lang->slug}";
60 - }
35 + foreach ( $preload_paths as $k => $path ) {
36 + if ( is_string( $path ) && '/' !== $path ) {
37 + $preload_paths[ $k ] = $path . "&lang={$lang}";
61 38 }
62 39 }
63 40
64 41 return $preload_paths;