PluginProbe
Polylang / 3.6.7
Polylang v3.6.7
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 | modules/sync/admin-sync.php +12 -9 3.03.6.7 View file →
@@ -14,9 +14,9 @@
14 14 * Constructor
15 15 *
16 16 * @since 1.2
17 17 *
18 - * @param object $polylang
18 + * @param object $polylang The Polylang object.
19 19 */
20 20 public function __construct( &$polylang ) {
21 21 parent::__construct( $polylang );
22 22
@@ -21,10 +21,9 @@
21 21 parent::__construct( $polylang );
22 22
23 23 add_filter( 'wp_insert_post_parent', array( $this, 'wp_insert_post_parent' ), 10, 3 );
24 24 add_filter( 'wp_insert_post_data', array( $this, 'wp_insert_post_data' ) );
25 - add_action( 'rest_api_init', array( $this, 'new_post_translation' ) ); // Block editor
26 - add_action( 'add_meta_boxes', array( $this, 'new_post_translation' ), 5 ); // Classic editor, before Types which populates custom fields in same hook with priority 10
25 + add_filter( 'use_block_editor_for_post', array( $this, 'new_post_translation' ), 5000 ); // After content duplication.
27 26 }
28 27
29 28 /**
30 29 * Translate post parent if exists when using "Add new" ( translation )
@@ -47,9 +46,9 @@
47 46 return $post_parent;
48 47 }
49 48
50 49 /**
51 - * Copy menu order, comment, ping status and optionally the date when creating a new tanslation
50 + * Copy menu order, comment, ping status and optionally the date when creating a new translation
52 51 *
53 52 * @since 2.5
54 53 *
55 54 * @param array $data An array of slashed post data.
@@ -81,16 +80,18 @@
81 80 /**
82 81 * Copy post metas, and taxonomies when using "Add new" ( translation )
83 82 *
84 83 * @since 2.5
84 + * @since 3.1 Use of use_block_editor_for_post filter instead of rest_api_init which is triggered too early in WP 5.8.
85 85 *
86 - * @return void
86 + * @param bool $is_block_editor Whether the post can be edited or not.
87 + * @return bool
87 88 */
88 - public function new_post_translation() {
89 + public function new_post_translation( $is_block_editor ) {
89 90 global $post;
90 91 static $done = array();
91 92
92 - if ( isset( $GLOBALS['pagenow'], $_GET['from_post'], $_GET['new_lang'] ) && 'post-new.php' === $GLOBALS['pagenow'] && $this->model->is_translated_post_type( $post->post_type ) ) {
93 + if ( ! empty( $post ) && isset( $GLOBALS['pagenow'], $_GET['from_post'], $_GET['new_lang'] ) && 'post-new.php' === $GLOBALS['pagenow'] && $this->model->is_translated_post_type( $post->post_type ) ) {
93 94 check_admin_referer( 'new-post-translation' );
94 95
95 96 // Capability check already done in post-new.php
96 97 $from_post_id = (int) $_GET['from_post'];
@@ -96,9 +97,9 @@
96 97 $from_post_id = (int) $_GET['from_post'];
97 98 $lang = $this->model->get_language( sanitize_key( $_GET['new_lang'] ) );
98 99
99 100 if ( ! $from_post_id || ! $lang || ! empty( $done[ $from_post_id ] ) ) {
100 - return;
101 + return $is_block_editor;
101 102 }
102 103
103 104 $done[ $from_post_id ] = true; // Avoid a second duplication in the block editor. Using an array only to allow multiple phpunit tests.
104 105
@@ -108,8 +109,10 @@
108 109 if ( is_sticky( $from_post_id ) ) {
109 110 stick_post( $post->ID );
110 111 }
111 112 }
113 +
114 + return $is_block_editor;
112 115 }
113 116
114 117 /**
115 118 * Get post fields to synchronize.
@@ -123,9 +126,9 @@
123 126 global $wpdb;
124 127
125 128 $postarr = parent::get_fields_to_sync( $post );
126 129
127 - // For new drafts, save the date now otherwise it is overriden by WP. Thanks to JoryHogeveen. See #32.
130 + // For new drafts, save the date now otherwise it is overridden by WP. Thanks to JoryHogeveen. See #32.
128 131 if ( in_array( 'post_date', $this->options['sync'] ) && isset( $GLOBALS['pagenow'], $_GET['from_post'], $_GET['new_lang'] ) && 'post-new.php' === $GLOBALS['pagenow'] ) {
129 132 check_admin_referer( 'new-post-translation' );
130 133
131 134 unset( $postarr['post_date'] );