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