| @@ -8,11 +8,21 @@ | ||
| 8 | 8 | * |
| 9 | 9 | * @since 2.5 |
| 10 | 10 | */ |
| 11 | 11 | class PLL_Admin_Block_Editor { |
| 12 | - public $model; | |
| 12 | + /** | |
| 13 | + * @var PLL_Model | |
| 14 | + */ | |
| 15 | + protected $model; | |
| 13 | 16 | |
| 14 | 17 | /** |
| 18 | + * Preferred language to assign to a new post. | |
| 19 | + * | |
| 20 | + * @var PLL_Language | |
| 21 | + */ | |
| 22 | + protected $pref_lang; | |
| 23 | + | |
| 24 | + /** | |
| 15 | 25 | * Constructor: setups filters and actions |
| 16 | 26 | * |
| 17 | 27 | * @since 2.5 |
| 18 | 28 | * |
| @@ -21,24 +31,24 @@ | ||
| 21 | 31 | public function __construct( &$polylang ) { |
| 22 | 32 | $this->model = &$polylang->model; |
| 23 | 33 | $this->pref_lang = &$polylang->pref_lang; |
| 24 | 34 | |
| 25 | - add_filter( 'block_editor_preload_paths', array( $this, 'preload_paths' ), 10, 2 ); | |
| 35 | + new PLL_Block_Editor_Filter_Preload_Paths( array( $this, 'preload_paths' ), 10, 2 ); | |
| 26 | 36 | } |
| 27 | 37 | |
| 28 | 38 | /** |
| 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 | |
| 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. | |
| 32 | 42 | * |
| 33 | 43 | * @since 2.5 |
| 34 | 44 | * |
| 35 | - * @param array $preload_paths Array of paths to preload. | |
| 36 | - * @param object $post The post resource data. | |
| 37 | - * @return array | |
| 45 | + * @param (string|string[])[] $preload_paths Array of paths to preload. | |
| 46 | + * @param WP_Post $post The post resource data. | |
| 47 | + * @return (string|string[])[] | |
| 38 | 48 | */ |
| 39 | 49 | public function preload_paths( $preload_paths, $post ) { |
| 40 | - if ( $this->model->is_translated_post_type( $post->post_type ) ) { | |
| 50 | + if ( $post instanceof WP_Post && $this->model->is_translated_post_type( $post->post_type ) ) { | |
| 41 | 51 | $lang = $this->model->post->get_language( $post->ID ); |
| 42 | 52 | |
| 43 | 53 | if ( ! $lang ) { |
| 44 | 54 | $lang = $this->pref_lang; |