As the sun rises and the forest mist clears, and the clouds return and the caves darken, these changes of light and shadow are the morning and evening in the mountains. Wildflowers bloom with their subtle fragrance, fine trees flourish with their dense shade, the wind and frost are pure and clean, and the water recedes to reveal the rocks—these are the four seasons in the mountains. Going out in the morning and returning in the evening, the scenery of the four seasons is different, and the joy is endless.至于负者歌于途,行者休于树,前者呼,后者应,伛偻提携,往来而不绝者,滁人游也。临溪而渔,溪深而鱼肥,酿泉为酒,泉香而酒洌,山肴野蔌,杂然而前陈者,太守宴也。宴酣之乐,非丝非竹,射者中,弈者胜,觥筹交错,起坐而喧哗者,众宾欢也。苍颜白发,颓然乎其间者,太守醉也。
<?php
/**
* @package Polylang
*/
/**
* Manages filters and actions related to the block editor
*
* @since 2.5
*/
class PLL_Admin_Block_Editor {
/**
* @var PLL_Model
*/
protected $model;
/**
* @var PLL_Filter_REST_Routes
*/
public $filter_rest_routes;
/**
* Constructor: setups filters and actions.
*
* @since 2.5
*
* @param PLL_Admin $polylang The Polylang object.
*/
public function __construct( &$polylang ) {
$this->model = &$polylang->model;
$this->filter_rest_routes = new PLL_Filter_REST_Routes( $polylang->model );
add_filter( 'block_editor_rest_api_preload_paths', array( $this, 'filter_preload_paths' ), 50, 2 );
add_action( 'admin_enqueue_scripts', array( $this, 'add_block_editor_inline_script' ), 15 ); // After `PLL_Admin_Base::admin_enqueue_scripts()` to ensure `pll_block-editor`script is enqueued.
}
/**
* Filters preload paths based on the context (block editor for posts, site editor or widget editor for instance).
*
* @since 3.5
*
* @param array $preload_paths Preload paths.
* @param WP_Block_Editor_Context $context Editor context.
* @return array Filtered preload paths.
*/
public function filter_preload_paths( $preload_paths, $context ) {
if ( ! $context instanceof WP_Block_Editor_Context ) {
return $preload_paths;
}
if ( 'core/edit-post' !== $context->name || ! $context->post instanceof WP_Post ) {
// Do nothing if not post editor.
return $preload_paths;
}
if ( ! $this->model->is_translated_post_type( $context->post->post_type ) ) {
return $preload_paths;
}
$language = $this->model->post->get_language( $context->post->ID );
if ( empty( $language ) ) {
return $preload_paths;
}
return $this->filter_rest_routes->add_query_parameters(
$preload_paths,
array(
'lang' => $language->slug,
)
);
}
/**
* Adds inline block editor script for filterable REST routes.
*
* @since 3.5
*
* @return void
*/
public function add_block_editor_inline_script() {
$handle = 'pll_block-editor';
if ( wp_script_is( $handle, 'enqueued' ) ) {
$this->filter_rest_routes->add_inline_script( $handle );
}
}
}