| @@ -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,23 +47,19 @@ | ||
| 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 | - if ( $from_post instanceof WP_Post ) { | |
| 66 | - foreach ( array( 'menu_order', 'comment_status', 'ping_status' ) as $property ) { | |
| 67 | - $data[ $property ] = $from_post->$property; | |
| 68 | - } | |
| 54 | + foreach ( array( 'menu_order', 'comment_status', 'ping_status' ) as $property ) { | |
| 55 | + $data[ $property ] = $from_post->$property; | |
| 56 | + } | |
| 69 | 57 | |
| 70 | - // Copy the date only if the synchronization is activated | |
| 71 | - if ( in_array( 'post_date', $this->options['sync'] ) ) { | |
| 72 | - $data['post_date'] = $from_post->post_date; | |
| 73 | - $data['post_date_gmt'] = $from_post->post_date_gmt; | |
| 74 | - } | |
| 58 | + // Copy the date only if the synchronization is activated | |
| 59 | + if ( in_array( 'post_date', PLL()->options['sync'] ) ) { | |
| 60 | + $data['post_date'] = $from_post->post_date; | |
| 61 | + $data['post_date_gmt'] = $from_post->post_date_gmt; | |
| 75 | 62 | } |
| 76 | 63 | } |
| 77 | 64 | |
| 78 | 65 | return $data; |
| @@ -81,10 +68,8 @@ | ||
| 81 | 68 | /** |
| 82 | 69 | * Copy post metas, and taxonomies when using "Add new" ( translation ) |
| 83 | 70 | * |
| 84 | 71 | * @since 2.5 |
| 85 | - * | |
| 86 | - * @return void | |
| 87 | 72 | */ |
| 88 | 73 | public function new_post_translation() { |
| 89 | 74 | global $post; |
| 90 | 75 | static $done = array(); |
| @@ -89,13 +74,11 @@ | ||
| 89 | 74 | global $post; |
| 90 | 75 | static $done = array(); |
| 91 | 76 | |
| 92 | 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 ) ) { |
| 93 | - check_admin_referer( 'new-post-translation' ); | |
| 94 | - | |
| 95 | 78 | // Capability check already done in post-new.php |
| 96 | 79 | $from_post_id = (int) $_GET['from_post']; |
| 97 | - $lang = $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); | |
| 80 | + $lang = $this->model->get_language( $_GET['new_lang'] ); | |
| 98 | 81 | |
| 99 | 82 | if ( ! $from_post_id || ! $lang || ! empty( $done[ $from_post_id ] ) ) { |
| 100 | 83 | return; |
| 101 | 84 | } |
| @@ -111,14 +94,14 @@ | ||
| 111 | 94 | } |
| 112 | 95 | } |
| 113 | 96 | |
| 114 | 97 | /** |
| 115 | - * Get post fields to synchronize. | |
| 98 | + * Get post fields to synchronize | |
| 116 | 99 | * |
| 117 | 100 | * @since 2.4 |
| 118 | 101 | * |
| 119 | - * @param WP_Post $post Post object. | |
| 120 | - * @return array Fields to synchronize. | |
| 102 | + * @param object $post Post object | |
| 103 | + * @return array | |
| 121 | 104 | */ |
| 122 | 105 | protected function get_fields_to_sync( $post ) { |
| 123 | 106 | global $wpdb; |
| 124 | 107 | |
| @@ -125,31 +108,26 @@ | ||
| 125 | 108 | $postarr = parent::get_fields_to_sync( $post ); |
| 126 | 109 | |
| 127 | 110 | // For new drafts, save the date now otherwise it is overriden by WP. Thanks to JoryHogeveen. See #32. |
| 128 | 111 | if ( in_array( 'post_date', $this->options['sync'] ) && isset( $GLOBALS['pagenow'], $_GET['from_post'], $_GET['new_lang'] ) && 'post-new.php' === $GLOBALS['pagenow'] ) { |
| 129 | - check_admin_referer( 'new-post-translation' ); | |
| 130 | - | |
| 131 | 112 | unset( $postarr['post_date'] ); |
| 132 | 113 | unset( $postarr['post_date_gmt'] ); |
| 133 | 114 | |
| 134 | 115 | $original = get_post( (int) $_GET['from_post'] ); |
| 135 | - | |
| 136 | - if ( $original instanceof WP_Post ) { | |
| 137 | - $wpdb->update( | |
| 138 | - $wpdb->posts, | |
| 139 | - array( | |
| 140 | - 'post_date' => $original->post_date, | |
| 141 | - 'post_date_gmt' => $original->post_date_gmt, | |
| 142 | - ), | |
| 143 | - array( 'ID' => $post->ID ) | |
| 144 | - ); | |
| 145 | - } | |
| 116 | + $wpdb->update( | |
| 117 | + $wpdb->posts, | |
| 118 | + array( | |
| 119 | + 'post_date' => $original->post_date, | |
| 120 | + 'post_date_gmt' => $original->post_date_gmt, | |
| 121 | + ), | |
| 122 | + array( 'ID' => $post->ID ) | |
| 123 | + ); | |
| 146 | 124 | } |
| 147 | 125 | |
| 148 | 126 | if ( isset( $GLOBALS['post_type'] ) ) { |
| 149 | 127 | $post_type = $GLOBALS['post_type']; |
| 150 | 128 | } elseif ( isset( $_REQUEST['post_type'] ) ) { |
| 151 | - $post_type = sanitize_key( $_REQUEST['post_type'] ); // 2nd case for quick edit | |
| 129 | + $post_type = $_REQUEST['post_type']; // 2nd case for quick edit | |
| 152 | 130 | } |
| 153 | 131 | |
| 154 | 132 | // Make sure not to impact media translations when creating them at the same time as post |
| 155 | 133 | if ( in_array( 'post_parent', $this->options['sync'] ) && ( ! isset( $post_type ) || $post_type !== $post->post_type ) ) { |
| @@ -159,15 +137,15 @@ | ||
| 159 | 137 | return $postarr; |
| 160 | 138 | } |
| 161 | 139 | |
| 162 | 140 | /** |
| 163 | - * Synchronizes post fields in translations. | |
| 141 | + * Synchronizes post fields in translations | |
| 164 | 142 | * |
| 165 | 143 | * @since 1.2 |
| 166 | 144 | * |
| 167 | - * @param int $post_id Post id. | |
| 168 | - * @param WP_Post $post Post object. | |
| 169 | - * @param int[] $translations Post translations. | |
| 145 | + * @param int $post_id post id | |
| 146 | + * @param object $post post object | |
| 147 | + * @param array $translations post translations | |
| 170 | 148 | */ |
| 171 | 149 | public function pll_save_post( $post_id, $post, $translations ) { |
| 172 | 150 | parent::pll_save_post( $post_id, $post, $translations ); |
| 173 | 151 | |
| @@ -173,9 +151,9 @@ | ||
| 173 | 151 | |
| 174 | 152 | // Sticky posts |
| 175 | 153 | if ( in_array( 'sticky_posts', $this->options['sync'] ) ) { |
| 176 | 154 | $stickies = get_option( 'sticky_posts' ); |
| 177 | - if ( isset( $_REQUEST['sticky'] ) && 'sticky' === $_REQUEST['sticky'] ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 155 | + if ( isset( $_REQUEST['sticky'] ) && 'sticky' === $_REQUEST['sticky'] ) { | |
| 178 | 156 | $stickies = array_merge( $stickies, array_values( $translations ) ); |
| 179 | 157 | } else { |
| 180 | 158 | $stickies = array_diff( $stickies, array_values( $translations ) ); |
| 181 | 159 | } |
| @@ -192,9 +170,8 @@ | ||
| 192 | 170 | * @since 2.3 |
| 193 | 171 | * |
| 194 | 172 | * @param string $func Function name |
| 195 | 173 | * @param array $args Function arguments |
| 196 | - * @return mixed|void | |
| 197 | 174 | */ |
| 198 | 175 | public function __call( $func, $args ) { |
| 199 | 176 | $obj = substr( $func, 5 ); |
| 200 | 177 | |
| @@ -199,18 +176,18 @@ | ||
| 199 | 176 | $obj = substr( $func, 5 ); |
| 200 | 177 | |
| 201 | 178 | if ( is_object( $this->$obj ) && method_exists( $this->$obj, 'copy' ) ) { |
| 202 | 179 | if ( WP_DEBUG ) { |
| 203 | - $debug = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions | |
| 180 | + $debug = debug_backtrace(); | |
| 204 | 181 | $i = 1 + empty( $debug[1]['line'] ); // The file and line are in $debug[2] if the function was called using call_user_func |
| 205 | 182 | |
| 206 | - trigger_error( // phpcs:ignore WordPress.PHP.DevelopmentFunctions | |
| 183 | + trigger_error( | |
| 207 | 184 | sprintf( |
| 208 | 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", |
| 209 | - esc_html( $func ), | |
| 210 | - esc_html( $obj ), | |
| 211 | - esc_html( $debug[ $i ]['file'] ), | |
| 212 | - absint( $debug[ $i ]['line'] ) | |
| 186 | + $func, | |
| 187 | + $obj, | |
| 188 | + $debug[ $i ]['file'], | |
| 189 | + $debug[ $i ]['line'] | |
| 213 | 190 | ) |
| 214 | 191 | ); |
| 215 | 192 | } |
| 216 | 193 | return call_user_func_array( array( $this->$obj, 'copy' ), $args ); |
| @@ -215,16 +192,8 @@ | ||
| 215 | 192 | } |
| 216 | 193 | return call_user_func_array( array( $this->$obj, 'copy' ), $args ); |
| 217 | 194 | } |
| 218 | 195 | |
| 219 | - $debug = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions | |
| 220 | - trigger_error( // phpcs:ignore WordPress.PHP.DevelopmentFunctions | |
| 221 | - sprintf( | |
| 222 | - 'Call to undefined function PLL()->sync->%1$s() in %2$s on line %3$s' . "\nError handler", | |
| 223 | - esc_html( $func ), | |
| 224 | - esc_html( $debug[0]['file'] ), | |
| 225 | - absint( $debug[0]['line'] ) | |
| 226 | - ), | |
| 227 | - E_USER_ERROR | |
| 228 | - ); | |
| 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 ); | |
| 229 | 198 | } |
| 230 | 199 | } |