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 | modules/sync/admin-sync.php +14 -37 2.92.5 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Manages copy and synchronization of terms and post metas
8 5 *
@@ -36,16 +33,10 @@
36 33 * @param array $postarr Array of parsed post data
37 34 * @return int
38 35 */
39 36 public function wp_insert_post_parent( $post_parent, $post_id, $postarr ) {
40 - if ( isset( $_GET['from_post'], $_GET['new_lang'], $_GET['post_type'] ) ) {
41 - check_admin_referer( 'new-post-translation' );
42 - // Make sure not to impact media translations created at the same time
43 - if ( $_GET['post_type'] === $postarr['post_type'] && ( $id = wp_get_post_parent_id( (int) $_GET['from_post'] ) ) && $parent = $this->model->post->get_translation( $id, sanitize_key( $_GET['new_lang'] ) ) ) {
44 - $post_parent = $parent;
45 - }
46 - }
47 - return $post_parent;
37 + // Make sure not to impact media translations created at the same time
38 + return isset( $_GET['from_post'], $_GET['new_lang'], $_GET['post_type'] ) && $_GET['post_type'] === $postarr['post_type'] && ( $id = wp_get_post_parent_id( (int) $_GET['from_post'] ) ) && ( $parent = $this->model->post->get_translation( $id, $_GET['new_lang'] ) ) ? $parent : $post_parent;
48 39 }
49 40
50 41 /**
51 42 * Copy menu order, comment, ping status and optionally the date when creating a new tanslation
@@ -56,10 +47,8 @@
56 47 * @return array
57 48 */
58 49 public function wp_insert_post_data( $data ) {
59 50 if ( isset( $GLOBALS['pagenow'], $_GET['from_post'], $_GET['new_lang'] ) && 'post-new.php' === $GLOBALS['pagenow'] && $this->model->is_translated_post_type( $data['post_type'] ) ) {
60 - check_admin_referer( 'new-post-translation' );
61 -
62 51 $from_post_id = (int) $_GET['from_post'];
63 52 $from_post = get_post( $from_post_id );
64 53
65 54 foreach ( array( 'menu_order', 'comment_status', 'ping_status' ) as $property ) {
@@ -66,9 +55,9 @@
66 55 $data[ $property ] = $from_post->$property;
67 56 }
68 57
69 58 // Copy the date only if the synchronization is activated
70 - if ( in_array( 'post_date', $this->options['sync'] ) ) {
59 + if ( in_array( 'post_date', PLL()->options['sync'] ) ) {
71 60 $data['post_date'] = $from_post->post_date;
72 61 $data['post_date_gmt'] = $from_post->post_date_gmt;
73 62 }
74 63 }
@@ -85,13 +74,11 @@
85 74 global $post;
86 75 static $done = array();
87 76
88 77 if ( isset( $GLOBALS['pagenow'], $_GET['from_post'], $_GET['new_lang'] ) && 'post-new.php' === $GLOBALS['pagenow'] && $this->model->is_translated_post_type( $post->post_type ) ) {
89 - check_admin_referer( 'new-post-translation' );
90 -
91 78 // Capability check already done in post-new.php
92 79 $from_post_id = (int) $_GET['from_post'];
93 - $lang = $this->model->get_language( sanitize_key( $_GET['new_lang'] ) );
80 + $lang = $this->model->get_language( $_GET['new_lang'] );
94 81
95 82 if ( ! $from_post_id || ! $lang || ! empty( $done[ $from_post_id ] ) ) {
96 83 return;
97 84 }
@@ -121,10 +108,8 @@
121 108 $postarr = parent::get_fields_to_sync( $post );
122 109
123 110 // For new drafts, save the date now otherwise it is overriden by WP. Thanks to JoryHogeveen. See #32.
124 111 if ( in_array( 'post_date', $this->options['sync'] ) && isset( $GLOBALS['pagenow'], $_GET['from_post'], $_GET['new_lang'] ) && 'post-new.php' === $GLOBALS['pagenow'] ) {
125 - check_admin_referer( 'new-post-translation' );
126 -
127 112 unset( $postarr['post_date'] );
128 113 unset( $postarr['post_date_gmt'] );
129 114
130 115 $original = get_post( (int) $_GET['from_post'] );
@@ -140,9 +125,9 @@
140 125
141 126 if ( isset( $GLOBALS['post_type'] ) ) {
142 127 $post_type = $GLOBALS['post_type'];
143 128 } elseif ( isset( $_REQUEST['post_type'] ) ) {
144 - $post_type = sanitize_key( $_REQUEST['post_type'] ); // 2nd case for quick edit
129 + $post_type = $_REQUEST['post_type']; // 2nd case for quick edit
145 130 }
146 131
147 132 // Make sure not to impact media translations when creating them at the same time as post
148 133 if ( in_array( 'post_parent', $this->options['sync'] ) && ( ! isset( $post_type ) || $post_type !== $post->post_type ) ) {
@@ -166,9 +151,9 @@
166 151
167 152 // Sticky posts
168 153 if ( in_array( 'sticky_posts', $this->options['sync'] ) ) {
169 154 $stickies = get_option( 'sticky_posts' );
170 - if ( isset( $_REQUEST['sticky'] ) && 'sticky' === $_REQUEST['sticky'] ) { // phpcs:ignore WordPress.Security.NonceVerification
155 + if ( isset( $_REQUEST['sticky'] ) && 'sticky' === $_REQUEST['sticky'] ) {
171 156 $stickies = array_merge( $stickies, array_values( $translations ) );
172 157 } else {
173 158 $stickies = array_diff( $stickies, array_values( $translations ) );
174 159 }
@@ -191,18 +176,18 @@
191 176 $obj = substr( $func, 5 );
192 177
193 178 if ( is_object( $this->$obj ) && method_exists( $this->$obj, 'copy' ) ) {
194 179 if ( WP_DEBUG ) {
195 - $debug = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions
180 + $debug = debug_backtrace();
196 181 $i = 1 + empty( $debug[1]['line'] ); // The file and line are in $debug[2] if the function was called using call_user_func
197 182
198 - trigger_error( // phpcs:ignore WordPress.PHP.DevelopmentFunctions
183 + trigger_error(
199 184 sprintf(
200 185 '%1$s was called incorrectly in %3$s on line %4$s: the call to PLL()->sync->%1$s() has been deprecated in Polylang 2.3, use PLL()->sync->%2$s->copy() instead.' . "\nError handler",
201 - esc_html( $func ),
202 - esc_html( $obj ),
203 - esc_html( $debug[ $i ]['file'] ),
204 - absint( $debug[ $i ]['line'] )
186 + $func,
187 + $obj,
188 + $debug[ $i ]['file'],
189 + $debug[ $i ]['line']
205 190 )
206 191 );
207 192 }
208 193 return call_user_func_array( array( $this->$obj, 'copy' ), $args );
@@ -207,16 +192,8 @@
207 192 }
208 193 return call_user_func_array( array( $this->$obj, 'copy' ), $args );
209 194 }
210 195
211 - $debug = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions
212 - trigger_error( // phpcs:ignore WordPress.PHP.DevelopmentFunctions
213 - sprintf(
214 - 'Call to undefined function PLL()->sync->%1$s() in %2$s on line %3$s' . "\nError handler",
215 - esc_html( $func ),
216 - esc_html( $debug[0]['file'] ),
217 - absint( $debug[0]['line'] )
218 - ),
219 - E_USER_ERROR
220 - );
196 + $debug = debug_backtrace();
197 + trigger_error( sprintf( 'Call to undefined function PLL()->sync->%1$s() in %2$s on line %3$s' . "\nError handler", $func, $debug[0]['file'], $debug[0]['line'] ), E_USER_ERROR );
221 198 }
222 199 }