PluginProbe
Polylang / 2.5.2
Polylang v2.5.2
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/sync.php +19 -72 2.7.22.5.2 View file →
@@ -22,11 +22,8 @@
22 22 $this->taxonomies = new PLL_Sync_Tax( $polylang );
23 23 $this->post_metas = new PLL_Sync_Post_Metas( $polylang );
24 24 $this->term_metas = new PLL_Sync_Term_Metas( $polylang );
25 25
26 - add_filter( 'wp_insert_post_parent', array( $this, 'can_sync_post_parent' ), 10, 3 );
27 - add_filter( 'wp_insert_post_data', array( $this, 'can_sync_post_data' ), 10, 2 );
28 -
29 26 add_action( 'pll_save_post', array( $this, 'pll_save_post' ), 10, 3 );
30 27 add_action( 'created_term', array( $this, 'sync_term_parent' ), 10, 3 );
31 28 add_action( 'edited_term', array( $this, 'sync_term_parent' ), 10, 3 );
32 29
@@ -70,53 +67,8 @@
70 67 return $postarr;
71 68 }
72 69
73 70 /**
74 - * Prevents synchronized post parent modification if the current user hasn't enough rights
75 - *
76 - * @since 2.6
77 - *
78 - * @param int $post_parent Post parent ID
79 - * @param int $post_id Post ID, unused
80 - * @param array $postarr Array of parsed post data
81 - * @return int
82 - */
83 - public function can_sync_post_parent( $post_parent, $post_id, $postarr ) {
84 - if ( ! empty( $postarr['ID'] ) && ! $this->model->post->current_user_can_synchronize( $postarr['ID'] ) ) {
85 - $tr_ids = $this->model->post->get_translations( $postarr['ID'] );
86 - foreach ( $tr_ids as $tr_id ) {
87 - if ( $tr_id !== $postarr['ID'] && $post = get_post( $tr_id ) ) {
88 - $post_parent = $post->post_parent;
89 - break;
90 - }
91 - }
92 - }
93 - return $post_parent;
94 - }
95 -
96 - /**
97 - * Prevents synchronized post data modification if the current user hasn't enough rights
98 - *
99 - * @since 2.6
100 - *
101 - * @param array $data An array of slashed post data.
102 - * @param array $postarr An array of sanitized, but otherwise unmodified post data.
103 - * @return array
104 - */
105 - public function can_sync_post_data( $data, $postarr ) {
106 - if ( ! empty( $postarr['ID'] ) && ! $this->model->post->current_user_can_synchronize( $postarr['ID'] ) ) {
107 - foreach ( $this->model->post->get_translations( $postarr['ID'] ) as $tr_id ) {
108 - if ( $tr_id !== $postarr['ID'] && $post = get_post( $tr_id ) ) {
109 - $to_sync = $this->get_fields_to_sync( $post );
110 - $data = array_merge( $data, $to_sync );
111 - break;
112 - }
113 - }
114 - }
115 - return $data;
116 - }
117 -
118 - /**
119 71 * Synchronizes post fields in translations
120 72 *
121 73 * @since 2.4
122 74 *
@@ -126,35 +78,31 @@
126 78 */
127 79 public function pll_save_post( $post_id, $post, $translations ) {
128 80 global $wpdb;
129 81
130 - if ( $this->model->post->current_user_can_synchronize( $post_id ) ) {
131 - $postarr = $this->get_fields_to_sync( $post );
82 + $postarr = $this->get_fields_to_sync( $post );
132 83
133 - if ( ! empty( $postarr ) ) {
134 - foreach ( $translations as $lang => $tr_id ) {
135 - if ( ! $tr_id || $tr_id === $post_id ) {
136 - continue;
137 - }
84 + if ( ! empty( $postarr ) ) {
85 + foreach ( $translations as $lang => $tr_id ) {
86 + if ( ! $tr_id || $tr_id === $post_id ) {
87 + continue;
88 + }
138 89
139 - $tr_arr = $postarr;
140 - unset( $tr_arr['post_parent'] );
90 + $tr_arr = $postarr;
91 + unset( $tr_arr['post_parent'] );
141 92
142 - // Do not udpate the translation parent if the user set a parent with no translation.
143 - if ( isset( $postarr['post_parent'] ) ) {
144 - $post_parent = $postarr['post_parent'] ? $this->model->post->get_translation( $postarr['post_parent'], $lang ) : 0;
145 - if ( ! ( $postarr['post_parent'] && ! $post_parent ) ) {
146 - $tr_arr['post_parent'] = $post_parent;
147 - }
93 + // Do not udpate the translation parent if the user set a parent with no translation
94 + if ( isset( $postarr['post_parent'] ) ) {
95 + $post_parent = $postarr['post_parent'] ? $this->model->post->get_translation( $postarr['post_parent'], $lang ) : 0;
96 + if ( ! ( $postarr['post_parent'] && ! $post_parent ) ) {
97 + $tr_arr['post_parent'] = $post_parent;
148 98 }
99 + }
149 100
150 - // Update all the rows at once.
151 - if ( ! empty( $tr_arr ) ) {
152 - // Don't use wp_update_post to avoid infinite loop.
153 - $wpdb->update( $wpdb->posts, $tr_arr, array( 'ID' => $tr_id ) );
154 - clean_post_cache( $tr_id );
155 - }
156 - }
101 + // Update all the row at once
102 + // Don't use wp_update_post to avoid infinite loop
103 + $wpdb->update( $wpdb->posts, $tr_arr, array( 'ID' => $tr_id ) );
104 + clean_post_cache( $tr_id );
157 105 }
158 106 }
159 107 }
160 108
@@ -175,10 +123,9 @@
175 123 $term = get_term( $term_id );
176 124 $translations = $this->model->term->get_translations( $term_id );
177 125
178 126 foreach ( $translations as $lang => $tr_id ) {
179 - if ( ! empty( $tr_id ) && $tr_id !== $term_id ) {
180 - $tr_parent = $this->model->term->get_translation( $term->parent, $lang );
127 + if ( ! empty( $tr_id ) && $tr_id !== $term_id && $tr_parent = $this->model->term->get_translation( $term->parent, $lang ) ) {
181 128 $wpdb->update(
182 129 $wpdb->term_taxonomy,
183 130 array( 'parent' => isset( $tr_parent ) ? $tr_parent : 0 ),
184 131 array( 'term_taxonomy_id' => get_term( (int) $tr_id, $taxonomy )->term_taxonomy_id )