Skip to content

Commit

Permalink
Fix issues with mb_ and urlencode functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Feb 16, 2020
1 parent 8a94b03 commit 6633819
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
Expand Up @@ -65,7 +65,7 @@ protected function task( $post ) {
if ( $transliterated_name !== $post_name ) {
update_post_meta( $post->ID, '_wp_old_slug', $post_name );
// phpcs:ignore WordPress.DB.DirectDatabaseQuery
$wpdb->update( $wpdb->posts, [ 'post_name' => urlencode( $transliterated_name ) ], [ 'ID' => $post->ID ] );
$wpdb->update( $wpdb->posts, [ 'post_name' => rawurlencode( $transliterated_name ) ], [ 'ID' => $post->ID ] );

$this->log( __( 'Post slug converted:', 'cyr2lat' ) . ' ' . $post_name . ' => ' . $transliterated_name );
}
Expand Down
Expand Up @@ -64,7 +64,7 @@ protected function task( $term ) {

if ( $transliterated_slug !== $slug ) {
// phpcs:ignore WordPress.DB.DirectDatabaseQuery
$wpdb->update( $wpdb->terms, [ 'slug' => urlencode( $transliterated_slug ) ], [ 'term_id' => $term->term_id ] );
$wpdb->update( $wpdb->terms, [ 'slug' => rawurlencode( $transliterated_slug ) ], [ 'term_id' => $term->term_id ] );

$this->log( __( 'Term slug converted:', 'cyr2lat' ) . ' ' . $slug . ' => ' . $transliterated_slug );
}
Expand Down
6 changes: 3 additions & 3 deletions classes/class-conversion-tables.php
Expand Up @@ -553,13 +553,13 @@ public static function get( $locale = '' ) {
'ת' => 'th',
];
for ( $code = 0x0590; $code <= 0x05CF; $code ++ ) {
$table[ mb_chr( $code ) ] = '';
$table[ Mbstring::mb_chr( $code ) ] = '';
}
for ( $code = 0x05F0; $code <= 0x05F5; $code ++ ) {
$table[ mb_chr( $code ) ] = '';
$table[ Mbstring::mb_chr( $code ) ] = '';
}
for ( $code = 0xFB1D; $code <= 0xFB4F; $code ++ ) {
$table[ mb_chr( $code ) ] = '';
$table[ Mbstring::mb_chr( $code ) ] = '';
}
break;
// phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment
Expand Down
25 changes: 20 additions & 5 deletions classes/class-main.php
Expand Up @@ -125,34 +125,38 @@ public function init_hooks() {
* @param int $post_ID Post ID.
* @param string $post_status The post status.
* @param string $post_type Post type.
* @param int $post_parent Post parent ID
* @param int $post_parent Post parent ID.
* @param string $original_slug The original post slug.
*
* @return string
*/
public function wp_unique_post_slug_filter( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ) {
return urlencode( $this->transliterate( urldecode( $slug ) ) );
return $this->transliterate_encoded( $slug );
}

/**
* Filter wp_unique_term_slug.
*
* @param string $slug Unique term slug.
* @param object $term Term object.
* @param string $original_slug Slug originally passed to the function for testing.
*
* @return string
*/
public function wp_unique_term_slug_filter( $slug, $term, $original_slug ) {
return urlencode( $this->transliterate( urldecode( $slug ) ) );
return $this->transliterate_encoded( $slug );
}

/**
* Filter pre_term_slug.
*
* @param mixed $value Value of the term field.
* @param string $taxonomy Taxonomy slug.
*
* @return string
*/
public function pre_term_slug_filter( $value, $taxonomy ) {
return urlencode( $this->transliterate( urldecode( $value ) ) );
return $this->transliterate_encoded( $value );
}

/**
Expand Down Expand Up @@ -211,7 +215,7 @@ protected function split_chinese_string( $string, $table ) {
return $string;
}

$chars = mb_str_split( $string );
$chars = Mbstring::mb_str_split( $string );
$string = '';

foreach ( $chars as $char ) {
Expand All @@ -225,6 +229,17 @@ protected function split_chinese_string( $string, $table ) {
return $string;
}

/**
* Transliterate encoded url.
*
* @param string $url Url.
*
* @return string
*/
private function transliterate_encoded( $url ) {
return rawurlencode( $this->transliterate( urldecode( $url ) ) );
}

/**
* Get transliteration table.
*
Expand Down
2 changes: 1 addition & 1 deletion classes/class-settings.php
Expand Up @@ -790,7 +790,7 @@ protected function transpose_chinese_table( $table ) {

$transposed_table = [];
foreach ( $table as $key => $item ) {
$hieroglyphs = mb_str_split( $item );
$hieroglyphs = Mbstring::mb_str_split( $item );
foreach ( $hieroglyphs as $hieroglyph ) {
$transposed_table[ $hieroglyph ] = $key;
}
Expand Down

0 comments on commit 6633819

Please sign in to comment.