It is customization when using multibyte.
WordPress GitHub Sync : Directory name and file name of GitHub
The directory name will be the custom post name.
The file name will be slug of posts / pages (title if not slug).
Because slug's multibyte code is URL-encoded, it becomes an unreadable character string.
The date is not added to the file name for custom posts and pages.
Customize directory name
Custom post name will be custom post type.
Customize file name
- When slug is single byte
date + slug - When slug is multibyte
date + post type + ID - When there is no slug
- When title is single byte
date + title - When title is multibyte
date + post type + ID
- When title is single byte
Add WordPress GitHub Sync customization to functions.php.
// ****** start. WordPress GitHub Sync customize *******
// Change directory name of custom post type
function my_wpghs_directory_published($name, $my_this) {
if ( 'publish' === $my_this->status() && 'post' !== $my_this->type() && 'page' !== $my_this->type() )
$name = '_' . $my_this->type() . '/';
return $name;
}
add_filter( 'wpghs_directory_published', 'my_wpghs_directory_published',10,2 );
// Change file name
// slug single byte -> date + name(slug)
// slug multibyte -> date + post type + ID
// no slug, title single byte -> date + title
// no slug, title multibyte -> date + post type + ID
function my_wpghs_filename($filename, $my_this) {
if ( '' !== $my_this->name() ) {
$str = urldecode($my_this->name());
if ( strlen( $str ) === mb_strlen( $str, "UTF-8") ) {
$filename = get_the_time( 'Y-m-d-', $my_this->id ) . $my_this->name() . '.md';
} else {
$filename = get_the_time( 'Y-m-d-', $my_this->id ) . $my_this->type() . '-' . strval($my_this->post->ID) . '.md';
}
} else {
$str = get_the_title( $my_this->post );
if ( strlen( $str ) === mb_strlen( $str, "UTF-8") ) {
$filename = get_the_time( 'Y-m-d-', $my_this->id ) . sanitize_title( $str ) . '.md';
} else {
$filename = get_the_time( 'Y-m-d-', $my_this->id ) . $my_this->type() . '-' . strval($my_this->post->ID) . '.md';
}
}
return $filename;
}
add_filter( 'wpghs_filename', 'my_wpghs_filename',10,2 );
// ****** end. WordPress GitHub Sync customize *******
Read in:
Japanese(日本語)
Japanese(日本語)
Leave a Reply