| @@ -10,10 +10,11 @@ | ||
| 10 | 10 | |
| 11 | 11 | add_filter( 'manage_posts_columns', 'bogo_posts_columns', 10, 2 ); |
| 12 | 12 | |
| 13 | 13 | function bogo_posts_columns( $posts_columns, $post_type ) { |
| 14 | - if ( ! bogo_is_localizable_post_type( $post_type ) ) | |
| 14 | + if ( ! bogo_is_localizable_post_type( $post_type ) ) { | |
| 15 | 15 | return $posts_columns; |
| 16 | + } | |
| 16 | 17 | |
| 17 | 18 | if ( ! isset( $posts_columns['locale'] ) ) { |
| 18 | 19 | $posts_columns = array_merge( |
| 19 | 20 | array_slice( $posts_columns, 0, 3 ), |
| @@ -23,29 +24,35 @@ | ||
| 23 | 24 | |
| 24 | 25 | return $posts_columns; |
| 25 | 26 | } |
| 26 | 27 | |
| 27 | -add_action( 'manage_pages_custom_column', 'bogo_manage_posts_custom_column', 10, 2 ); | |
| 28 | -add_action( 'manage_posts_custom_column', 'bogo_manage_posts_custom_column', 10, 2 ); | |
| 28 | +add_action( 'manage_pages_custom_column', | |
| 29 | + 'bogo_manage_posts_custom_column', 10, 2 ); | |
| 30 | +add_action( 'manage_posts_custom_column', | |
| 31 | + 'bogo_manage_posts_custom_column', 10, 2 ); | |
| 29 | 32 | |
| 30 | 33 | function bogo_manage_posts_custom_column( $column_name, $post_id ) { |
| 34 | + if ( 'locale' != $column_name ) { | |
| 35 | + return; | |
| 36 | + } | |
| 37 | + | |
| 31 | 38 | $post_type = get_post_type( $post_id ); |
| 32 | 39 | |
| 33 | - if ( ! bogo_is_localizable_post_type( $post_type ) ) | |
| 40 | + if ( ! bogo_is_localizable_post_type( $post_type ) ) { | |
| 34 | 41 | return; |
| 42 | + } | |
| 35 | 43 | |
| 36 | - if ( 'locale' != $column_name ) | |
| 37 | - return; | |
| 38 | - | |
| 39 | 44 | $locale = get_post_meta( $post_id, '_locale', true ); |
| 40 | 45 | |
| 41 | - if ( empty( $locale ) ) | |
| 46 | + if ( empty( $locale ) ) { | |
| 42 | 47 | return; |
| 48 | + } | |
| 43 | 49 | |
| 44 | 50 | $language = bogo_get_language( $locale ); |
| 45 | 51 | |
| 46 | - if ( empty( $language ) ) | |
| 52 | + if ( empty( $language ) ) { | |
| 47 | 53 | $language = $locale; |
| 54 | + } | |
| 48 | 55 | |
| 49 | 56 | echo sprintf( '<a href="%1$s">%2$s</a>', |
| 50 | 57 | esc_url( add_query_arg( |
| 51 | 58 | array( 'post_type' => $post_type, 'lang' => $locale ), |
| @@ -85,65 +92,105 @@ | ||
| 85 | 92 | add_filter( 'post_row_actions', 'bogo_post_row_actions', 10, 2 ); |
| 86 | 93 | add_filter( 'page_row_actions', 'bogo_post_row_actions', 10, 2 ); |
| 87 | 94 | |
| 88 | 95 | function bogo_post_row_actions( $actions, $post ) { |
| 89 | - if ( ! bogo_is_localizable_post_type( $post->post_type ) ) | |
| 96 | + if ( ! bogo_is_localizable_post_type( $post->post_type ) ) { | |
| 90 | 97 | return $actions; |
| 98 | + } | |
| 91 | 99 | |
| 92 | 100 | $post_type_object = get_post_type_object( $post->post_type ); |
| 93 | 101 | |
| 94 | 102 | if ( ! current_user_can( $post_type_object->cap->edit_post, $post->ID ) |
| 95 | - || 'trash' == $post->post_status ) | |
| 103 | + || 'trash' == $post->post_status ) { | |
| 96 | 104 | return $actions; |
| 105 | + } | |
| 97 | 106 | |
| 98 | 107 | $user_locale = bogo_get_user_locale(); |
| 99 | 108 | $post_locale = bogo_get_post_locale( $post->ID ); |
| 100 | 109 | |
| 101 | - if ( $user_locale == $post_locale ) | |
| 110 | + if ( $user_locale == $post_locale ) { | |
| 102 | 111 | return $actions; |
| 112 | + } | |
| 103 | 113 | |
| 104 | - $translations = bogo_get_post_translations( $post ); | |
| 105 | - | |
| 106 | - if ( ! empty( $translations[$user_locale] ) ) { | |
| 107 | - $translation = $translations[$user_locale]; | |
| 108 | - | |
| 109 | - if ( empty( $translation->ID ) || $translation->ID == $post->ID ) | |
| 114 | + if ( $translation = bogo_get_post_translation( $post, $user_locale ) ) { | |
| 115 | + if ( empty( $translation->ID ) || $translation->ID == $post->ID ) { | |
| 110 | 116 | return $actions; |
| 117 | + } | |
| 111 | 118 | |
| 112 | - $title = __( 'Edit %s translation of this item', 'bogo' ); | |
| 113 | 119 | $text = __( 'Edit %s translation', 'bogo' ); |
| 114 | - | |
| 115 | 120 | $edit_link = get_edit_post_link( $translation->ID ); |
| 116 | - | |
| 117 | 121 | } else { |
| 118 | - $title = __( 'Translate this item into %s', 'bogo' ); | |
| 119 | 122 | $text = __( 'Translate into %s', 'bogo' ); |
| 120 | - | |
| 121 | 123 | $edit_link = admin_url( 'post-new.php?post_type=' . $post->post_type |
| 124 | + . '&action=bogo-add-translation' | |
| 122 | 125 | . '&locale=' . $user_locale |
| 123 | 126 | . '&original_post=' . $post->ID ); |
| 127 | + $edit_link = wp_nonce_url( $edit_link, 'bogo-add-translation' ); | |
| 124 | 128 | } |
| 125 | 129 | |
| 126 | 130 | $language = bogo_get_language( $user_locale ); |
| 127 | 131 | |
| 128 | - if ( empty( $language ) ) | |
| 132 | + if ( empty( $language ) ) { | |
| 129 | 133 | $language = $user_locale; |
| 134 | + } | |
| 130 | 135 | |
| 131 | - $actions['translate'] = '<a title="' . esc_attr( sprintf( $title, $language ) ) . '" href="' . $edit_link . '">' . esc_html( sprintf( $text, $language ) ) . '</a>'; | |
| 136 | + $actions['translate'] = sprintf( | |
| 137 | + '<a href="%1$s">%2$s</a>', | |
| 138 | + $edit_link, | |
| 139 | + esc_html( sprintf( $text, $language ) ) ); | |
| 132 | 140 | |
| 133 | 141 | return $actions; |
| 134 | 142 | } |
| 135 | 143 | |
| 144 | +add_action( 'admin_init', 'bogo_add_translation' ); | |
| 145 | + | |
| 146 | +function bogo_add_translation() { | |
| 147 | + if ( empty( $_REQUEST['action'] ) | |
| 148 | + || 'bogo-add-translation' != $_REQUEST['action'] ) { | |
| 149 | + return; | |
| 150 | + } | |
| 151 | + | |
| 152 | + check_admin_referer( 'bogo-add-translation' ); | |
| 153 | + | |
| 154 | + $locale = isset( $_REQUEST['locale'] ) ? $_REQUEST['locale'] : ''; | |
| 155 | + $original_post = isset( $_REQUEST['original_post'] ) | |
| 156 | + ? absint( $_REQUEST['original_post'] ) : 0; | |
| 157 | + | |
| 158 | + if ( ! bogo_is_available_locale( $locale ) | |
| 159 | + || ! current_user_can( 'bogo_access_locale', $locale ) ) { | |
| 160 | + return; | |
| 161 | + } | |
| 162 | + | |
| 163 | + if ( ! $original_post || ! $original_post = get_post( $original_post ) ) { | |
| 164 | + return; | |
| 165 | + } | |
| 166 | + | |
| 167 | + $post_type_object = get_post_type_object( $original_post->post_type ); | |
| 168 | + | |
| 169 | + if ( $post_type_object | |
| 170 | + && current_user_can( $post_type_object->cap->edit_posts ) ) { | |
| 171 | + $new_post_id = bogo_duplicate_post( $original_post, $locale ); | |
| 172 | + | |
| 173 | + if ( $new_post_id ) { | |
| 174 | + $redirect_to = get_edit_post_link( $new_post_id, 'raw' ); | |
| 175 | + wp_safe_redirect( $redirect_to ); | |
| 176 | + exit(); | |
| 177 | + } | |
| 178 | + } | |
| 179 | +} | |
| 180 | + | |
| 136 | 181 | /* Single Post */ |
| 137 | 182 | |
| 138 | 183 | add_action( 'add_meta_boxes', 'bogo_add_l10n_meta_boxes', 10, 2 ); |
| 139 | 184 | |
| 140 | 185 | function bogo_add_l10n_meta_boxes( $post_type, $post ) { |
| 141 | - if ( ! bogo_is_localizable_post_type( $post_type ) ) | |
| 186 | + if ( ! bogo_is_localizable_post_type( $post_type ) ) { | |
| 142 | 187 | return; |
| 188 | + } | |
| 143 | 189 | |
| 144 | - if ( in_array( $post_type, array( 'comment', 'link' ) ) ) | |
| 190 | + if ( in_array( $post_type, array( 'comment', 'link' ) ) ) { | |
| 145 | 191 | return; |
| 192 | + } | |
| 146 | 193 | |
| 147 | 194 | add_meta_box( 'bogol10ndiv', __( 'Language', 'bogo' ), |
| 148 | 195 | 'bogo_l10n_meta_box', null, 'side', 'high' ); |
| 149 | 196 | } |
| @@ -151,165 +198,174 @@ | ||
| 151 | 198 | function bogo_l10n_meta_box( $post ) { |
| 152 | 199 | $initial = ( 'auto-draft' == $post->post_status ); |
| 153 | 200 | |
| 154 | 201 | if ( $initial ) { |
| 155 | - $locale = isset( $_REQUEST['locale'] ) ? $_REQUEST['locale'] : ''; | |
| 202 | + $post_locale = isset( $_REQUEST['locale'] ) ? $_REQUEST['locale'] : ''; | |
| 156 | 203 | |
| 157 | - if ( ! bogo_is_available_locale( $locale ) ) | |
| 158 | - $locale = bogo_get_user_locale(); | |
| 204 | + if ( ! bogo_is_available_locale( $post_locale ) ) { | |
| 205 | + $post_locale = bogo_get_user_locale(); | |
| 206 | + } | |
| 159 | 207 | |
| 160 | - $original_post = empty( $_REQUEST['original_post'] ) ? '' : $_REQUEST['original_post']; | |
| 208 | + $original_post = empty( $_REQUEST['original_post'] ) | |
| 209 | + ? '' : $_REQUEST['original_post']; | |
| 161 | 210 | } else { |
| 162 | - $locale = bogo_get_post_locale( $post->ID ); | |
| 211 | + $post_locale = bogo_get_post_locale( $post->ID ); | |
| 163 | 212 | $original_post = get_post_meta( $post->ID, '_original_post', true ); |
| 164 | 213 | |
| 165 | - if ( empty( $original_post ) ) | |
| 214 | + if ( empty( $original_post ) ) { | |
| 166 | 215 | $original_post = $post->ID; |
| 216 | + } | |
| 167 | 217 | } |
| 168 | 218 | |
| 169 | - $lang = bogo_get_language( $locale ); | |
| 170 | - | |
| 171 | - if ( empty( $lang ) ) | |
| 172 | - $lang = $locale; | |
| 173 | - | |
| 219 | + $translations = bogo_get_post_translations( $post->ID ); | |
| 220 | + $available_locales = bogo_available_locales( array( | |
| 221 | + 'exclude' => array_merge( | |
| 222 | + array( $post_locale ), | |
| 223 | + array_keys( (array) $translations ) ), | |
| 224 | + 'exclude_enus_if_inactive' => true, | |
| 225 | + 'current_user_can_access' => true ) ); | |
| 174 | 226 | ?> |
| 175 | 227 | <div class="hidden"> |
| 176 | -<input type="hidden" name="locale" value="<?php echo esc_attr( $locale ); ?>" /> | |
| 228 | +<input type="hidden" name="locale" value="<?php echo esc_attr( $post_locale ); ?>" /> | |
| 177 | 229 | <input type="hidden" name="original_post" value="<?php echo esc_attr( $original_post ); ?>" /> |
| 178 | 230 | </div> |
| 179 | 231 | |
| 180 | 232 | <div class="descriptions"> |
| 233 | +<?php | |
| 234 | + $lang = bogo_get_language( $post_locale ); | |
| 235 | + $lang = empty( $lang ) ? $post_locale : $lang; | |
| 236 | +?> | |
| 181 | 237 | <p><strong><?php echo esc_html( __( 'Language', 'bogo' ) ); ?>:</strong> |
| 182 | 238 | <?php echo esc_html( $lang ); ?></p> |
| 183 | 239 | </div> |
| 184 | 240 | |
| 185 | 241 | <?php |
| 186 | - bogo_metabox_translations( $post ); | |
| 187 | - bogo_metabox_add_translation( $post ); | |
| 188 | -} | |
| 242 | + do { | |
| 243 | + if ( ! $translations && ( $initial || empty( $available_locales ) ) ) { | |
| 244 | + break; | |
| 245 | + } | |
| 189 | 246 | |
| 190 | -function bogo_metabox_translations( $post ) { | |
| 191 | - $translations = bogo_get_post_translations( $post->ID ); | |
| 247 | + echo '<div class="descriptions">'; | |
| 248 | + echo sprintf( '<p><strong>%s:</strong></p>', | |
| 249 | + esc_html( __( 'Translations', 'bogo' ) ) ); | |
| 250 | + echo '<ul id="bogo-translations">'; | |
| 192 | 251 | |
| 193 | - if ( empty( $translations ) ) | |
| 194 | - return; | |
| 252 | + if ( $translations ) { | |
| 253 | + foreach ( $translations as $locale => $translation ) { | |
| 254 | + $edit_link = get_edit_post_link( $translation->ID ); | |
| 255 | + echo '<li>'; | |
| 195 | 256 | |
| 196 | -?> | |
| 197 | -<p><strong><?php echo esc_html( __( 'Translations', 'bogo' ) ); ?>:</strong></p> | |
| 257 | + if ( $edit_link ) { | |
| 258 | + echo sprintf( '<a href="%1$s" target="_blank">%2$s</a>', | |
| 259 | + esc_url( $edit_link ), get_the_title( $translation->ID ) ); | |
| 260 | + } else { | |
| 261 | + echo get_the_title( $translation->ID ); | |
| 262 | + } | |
| 198 | 263 | |
| 199 | -<ul style="list-style: disc inside; margin-left: 1em;"> | |
| 200 | -<?php | |
| 201 | - foreach ( $translations as $locale => $translation ) { | |
| 202 | - $edit_link = get_edit_post_link( $translation->ID ); | |
| 264 | + $lang = bogo_get_language( $locale ); | |
| 265 | + $lang = empty( $lang ) ? $locale : $lang; | |
| 266 | + echo ' [' . $lang . ']'; | |
| 267 | + echo '</li>'; | |
| 268 | + } | |
| 269 | + } | |
| 203 | 270 | |
| 204 | - echo '<li>'; | |
| 271 | + echo '</ul>'; | |
| 272 | + echo '</div>'; | |
| 273 | + } while (0); | |
| 205 | 274 | |
| 206 | - if ( $edit_link ) | |
| 207 | - echo '<a href="' . esc_url( $edit_link ) . '" target="_blank">' . get_the_title( $translation->ID ) . '</a>'; | |
| 208 | - else | |
| 209 | - echo get_the_title( $translation->ID ); | |
| 275 | + do { | |
| 276 | + if ( $initial || empty( $available_locales ) ) { | |
| 277 | + break; | |
| 278 | + } | |
| 210 | 279 | |
| 211 | - $lang = bogo_get_language( $locale ); | |
| 280 | + echo '<div id="bogo-add-translation-actions" class="descriptions">'; | |
| 281 | + echo sprintf( '<p><strong>%s:</strong></p>', | |
| 282 | + esc_html( __( 'Add Translation', 'bogo' ) ) ); | |
| 283 | + echo '<select id="bogo-translations-to-add">'; | |
| 212 | 284 | |
| 213 | - if ( empty( $lang ) ) | |
| 214 | - $lang = $locale; | |
| 285 | + foreach ( $available_locales as $locale ) { | |
| 286 | + $lang = bogo_get_language( $locale ); | |
| 287 | + $lang = empty( $lang ) ? $locale : $lang; | |
| 288 | + echo sprintf( '<option value="%1$s">%2$s</option>', | |
| 289 | + esc_attr( $locale ), esc_html( $lang ) ); | |
| 290 | + } | |
| 215 | 291 | |
| 216 | - echo ' [' . $lang . ']'; | |
| 217 | - echo '</li>'; | |
| 218 | - } | |
| 219 | -?> | |
| 220 | -</ul> | |
| 221 | -<?php | |
| 292 | + echo '</select>'; | |
| 293 | + echo '<p>'; | |
| 294 | + echo sprintf( | |
| 295 | + '<button type="button" class="button" id="%1$s">%2$s</button>', | |
| 296 | + 'bogo-add-translation', | |
| 297 | + esc_html( __( 'Add Translation', 'bogo' ) ) ); | |
| 298 | + echo '<span class="spinner"></span>'; | |
| 299 | + echo '</p>'; | |
| 300 | + echo '<div class="clear"></div>'; | |
| 301 | + echo '</div>'; | |
| 302 | + } while (0); | |
| 222 | 303 | } |
| 223 | 304 | |
| 224 | -function bogo_metabox_add_translation( $post ) { | |
| 225 | - if ( 'auto-draft' == $post->post_status ) | |
| 226 | - return; | |
| 305 | +add_action( 'save_post', 'bogo_save_post', 10, 2 ); | |
| 227 | 306 | |
| 228 | - $post_locale = bogo_get_post_locale( $post->ID ); | |
| 229 | - $user_locale = bogo_get_user_locale(); | |
| 230 | - | |
| 231 | - if ( $post_locale == $user_locale ) | |
| 307 | +function bogo_save_post( $post_id, $post ) { | |
| 308 | + if ( did_action( 'import_start' ) && ! did_action( 'import_end' ) ) { | |
| 309 | + // Importing | |
| 232 | 310 | return; |
| 311 | + } | |
| 233 | 312 | |
| 234 | - $locale = $user_locale; | |
| 235 | - | |
| 236 | - $translations = bogo_get_post_translations( $post->ID ); | |
| 237 | - | |
| 238 | - if ( isset( $translations[$locale] ) ) | |
| 313 | + if ( ! bogo_is_localizable_post_type( $post->post_type ) ) { | |
| 239 | 314 | return; |
| 315 | + } | |
| 240 | 316 | |
| 241 | - $lang = bogo_get_language( $locale ); | |
| 317 | + $current_locales = get_post_meta( $post_id, '_locale' ); | |
| 318 | + $locale = null; | |
| 242 | 319 | |
| 243 | - if ( empty( $lang ) ) | |
| 244 | - $lang = $locale; | |
| 320 | + if ( ! empty( $current_locales ) ) { | |
| 321 | + foreach ( $current_locales as $current_locale ) { | |
| 322 | + if ( bogo_is_available_locale( $current_locale ) ) { | |
| 323 | + $locale = $current_locale; | |
| 324 | + break; | |
| 325 | + } | |
| 326 | + } | |
| 245 | 327 | |
| 246 | - $edit_link = admin_url( 'post-new.php?post_type=' . $post->post_type | |
| 247 | - . '&locale=' . $locale | |
| 248 | - . '&original_post=' . $post->ID ); | |
| 249 | - | |
| 250 | -?> | |
| 251 | -<p class="textright"><a href="<?php echo $edit_link; ?>" target="_blank" class="button"><?php echo esc_html( sprintf( __( 'Add %s translation', 'bogo' ), $lang ) ) ?></a></p> | |
| 252 | -<?php | |
| 253 | -} | |
| 254 | - | |
| 255 | -add_filter( 'default_title', 'bogo_translation_default', 10, 2 ); | |
| 256 | -add_filter( 'default_content', 'bogo_translation_default', 10, 2 ); | |
| 257 | -add_filter( 'default_excerpt', 'bogo_translation_default', 10, 2 ); | |
| 258 | - | |
| 259 | -function bogo_translation_default( $value, $post ) { | |
| 260 | - if ( ! empty( $value ) | |
| 261 | - || empty( $_REQUEST['original_post'] ) | |
| 262 | - || ! $original = get_post( $_REQUEST['original_post'] ) ) { | |
| 263 | - return $value; | |
| 328 | + if ( empty( $locale ) || 1 < count( $current_locales ) ) { | |
| 329 | + delete_post_meta( $post_id, '_locale' ); | |
| 330 | + $current_locales = array(); | |
| 331 | + } | |
| 264 | 332 | } |
| 265 | 333 | |
| 266 | - if ( 'default_title' == current_filter() ) { | |
| 267 | - $value = $original->post_title; | |
| 268 | - } elseif ( 'default_content' == current_filter() ) { | |
| 269 | - $value = $original->post_content; | |
| 270 | - } elseif ( 'default_excerpt' == current_filter() ) { | |
| 271 | - $value = $original->post_excerpt; | |
| 272 | - } | |
| 273 | - | |
| 274 | - return $value; | |
| 275 | -} | |
| 276 | - | |
| 277 | -add_action( 'save_post', 'bogo_save_post', 10, 2 ); | |
| 278 | - | |
| 279 | -function bogo_save_post( $post_id, $post ) { | |
| 280 | - if ( did_action( 'import_start' ) && ! did_action( 'import_end' ) ) // Importing | |
| 281 | - return; | |
| 282 | - | |
| 283 | - if ( ! bogo_is_localizable_post_type( $post->post_type ) ) | |
| 284 | - return; | |
| 285 | - | |
| 286 | - $old_locale = get_post_meta( $post_id, '_locale', true ); | |
| 287 | - | |
| 288 | - if ( empty( $old_locale ) ) { | |
| 289 | - if ( ! empty( $_REQUEST['locale'] ) && bogo_is_available_locale( $_REQUEST['locale'] ) ) | |
| 334 | + if ( empty( $current_locales ) ) { | |
| 335 | + if ( bogo_is_available_locale( $locale ) ) { | |
| 336 | + // $locale = $locale; | |
| 337 | + } elseif ( ! empty( $_REQUEST['locale'] ) | |
| 338 | + && bogo_is_available_locale( $_REQUEST['locale'] ) ) { | |
| 290 | 339 | $locale = $_REQUEST['locale']; |
| 291 | - elseif ( 'auto-draft' == get_post_status( $post_id ) ) | |
| 340 | + } elseif ( 'auto-draft' == get_post_status( $post_id ) ) { | |
| 292 | 341 | $locale = bogo_get_user_locale(); |
| 293 | - else | |
| 342 | + } else { | |
| 294 | 343 | $locale = bogo_get_default_locale(); |
| 344 | + } | |
| 345 | + | |
| 346 | + add_post_meta( $post_id, '_locale', $locale, true ); | |
| 295 | 347 | } |
| 296 | 348 | |
| 297 | - if ( ! empty( $locale ) && $locale != $old_locale ) | |
| 298 | - update_post_meta( $post_id, '_locale', $locale ); | |
| 299 | - else | |
| 300 | - $locale = $old_locale; | |
| 349 | + $current_original_posts = get_post_meta( $post_id, '_original_post' ); | |
| 301 | 350 | |
| 302 | - if ( $original = get_post_meta( $post_id, '_original_post', true ) ) | |
| 303 | - return; | |
| 351 | + if ( ! empty( $current_original_posts ) ) { | |
| 352 | + if ( 1 < count( $current_original_posts ) ) { | |
| 353 | + delete_post_meta( $post_id, '_original_post' ); | |
| 354 | + } else { | |
| 355 | + return; | |
| 356 | + } | |
| 357 | + } | |
| 304 | 358 | |
| 305 | 359 | if ( ! empty( $_REQUEST['original_post'] ) ) { |
| 306 | - $original = get_post_meta( $_REQUEST['original_post'], '_original_post', true ); | |
| 360 | + $original = get_post_meta( $_REQUEST['original_post'], | |
| 361 | + '_original_post', true ); | |
| 307 | 362 | |
| 308 | - if ( empty( $original ) ) | |
| 363 | + if ( empty( $original ) ) { | |
| 309 | 364 | $original = (int) $_REQUEST['original_post']; |
| 365 | + } | |
| 310 | 366 | |
| 311 | - update_post_meta( $post_id, '_original_post', $original ); | |
| 367 | + add_post_meta( $post_id, '_original_post', $original, true ); | |
| 312 | 368 | return; |
| 313 | 369 | } |
| 314 | 370 | |
| 315 | 371 | $original = $post_id; |
| @@ -325,9 +381,9 @@ | ||
| 325 | 381 | 'meta_key' => '_original_post', |
| 326 | 382 | 'meta_value' => $original ) ); |
| 327 | 383 | |
| 328 | 384 | if ( empty( $posts ) ) { |
| 329 | - update_post_meta( $post_id, '_original_post', $original ); | |
| 385 | + add_post_meta( $post_id, '_original_post', $original, true ); | |
| 330 | 386 | return; |
| 331 | 387 | } |
| 332 | 388 | |
| 333 | 389 | $original += 1; |
| @@ -338,20 +394,23 @@ | ||
| 338 | 394 | |
| 339 | 395 | function bogo_unique_post_slug( $slug, $post_id, $status, $type, $parent, $original ) { |
| 340 | 396 | global $wp_rewrite; |
| 341 | 397 | |
| 342 | - if ( ! bogo_is_localizable_post_type( $type ) ) | |
| 398 | + if ( ! bogo_is_localizable_post_type( $type ) ) { | |
| 343 | 399 | return $slug; |
| 400 | + } | |
| 344 | 401 | |
| 345 | 402 | $feeds = is_array( $wp_rewrite->feeds ) ? $wp_rewrite->feeds : array(); |
| 346 | 403 | |
| 347 | - if ( in_array( $original, $feeds ) ) | |
| 404 | + if ( in_array( $original, $feeds ) ) { | |
| 348 | 405 | return $slug; |
| 406 | + } | |
| 349 | 407 | |
| 350 | - $locale = get_post_meta( $post_id, '_locale', true ); | |
| 408 | + $locale = bogo_get_post_locale( $post_id ); | |
| 351 | 409 | |
| 352 | - if ( empty( $locale ) ) | |
| 410 | + if ( empty( $locale ) ) { | |
| 353 | 411 | return $slug; |
| 412 | + } | |
| 354 | 413 | |
| 355 | 414 | $args = array( |
| 356 | 415 | 'posts_per_page' => 1, |
| 357 | 416 | 'post__not_in' => array( $post_id ), |
| @@ -361,10 +420,11 @@ | ||
| 361 | 420 | |
| 362 | 421 | $hierarchical = in_array( $type, get_post_types( array( 'hierarchical' => true ) ) ); |
| 363 | 422 | |
| 364 | 423 | if ( $hierarchical ) { |
| 365 | - if ( preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $original ) ) | |
| 424 | + if ( preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $original ) ) { | |
| 366 | 425 | return $slug; |
| 426 | + } | |
| 367 | 427 | |
| 368 | 428 | $args['post_parent'] = $parent; |
| 369 | 429 | } |
| 370 | 430 | |
| @@ -370,11 +430,10 @@ | ||
| 370 | 430 | |
| 371 | 431 | $q = new WP_Query(); |
| 372 | 432 | $posts = $q->query( $args ); |
| 373 | 433 | |
| 374 | - if ( empty( $posts ) ) | |
| 434 | + if ( empty( $posts ) ) { | |
| 375 | 435 | $slug = $original; |
| 436 | + } | |
| 376 | 437 | |
| 377 | 438 | return $slug; |
| 378 | 439 | } |
| 379 | - | |
| 380 | -?> | |