Hauptmenü

Werkzeuge

Kategorien

Archiv

Bug in WordPress 4.9.8 / Multiblog / Multissite

Erstellt in Allgemein am 2. November 2018 vom Daschmi

Es gibt einen Bug in WordPress Version 4.9.8. Hat man einen Blog mit dem Namen „musterblog“ und möchte im Hauptblog eine Seite anlegen die den Namen „Musterblog“ tragen soll, so wird das verhindert. Das ist auch gut so, da es zum URL Konflikt kommen würde. Legt man jetzt aber eine Seite und möchte darunter eine Seite mit Namen „Musterblog“ anlegen kann die URL auch nicht ermittelt werden. Die Funktion avoid_blog_page_permalink_collision denkt immer es gibt eine Kollision und hängt einen Suffix an. Ich habe es für mich erstmal so gelöst, dass ich die Funktion angepasst habe so dass Unterseiten ignoriert werden.


/**
* Avoids a collision between a site slug and a permalink slug.
*
* In a subdirectory installation this will make sure that a site and a post do not use the
* same subdirectory by checking for a site with the same name as a new post.
*
* @since 3.0.0
*
* @param array $data An array of post data.
* @param array $postarr An array of posts. Not currently used.
* @return array The new array of post data after checking for collisions.
*/
function avoid_blog_page_permalink_collision( $data, $postarr ) {

if ( is_subdomain_install() )
return $data;
if ( $data['post_type'] != 'page' )
return $data;
if ( !isset( $data['post_name'] ) || $data['post_name'] == '' )
return $data;
if ( !is_main_site() )
return $data;

// Daschmi: 02.11.2018
// If page is a subpage, no check of collision
if ($data['post_parent'] > 0) return $data;

$post_name = $data['post_name'];
$c = 0;
while( $c < 10 && get_id_from_blogname( $post_name ) ) {
$post_name .= mt_rand( 1, 10 );
$c ++;
}
if ( $post_name != $data['post_name'] ) {
$data['post_name'] = $post_name;
}
return $data;
}

Die Funktion findest sich unter /wp-admin/includes/ms.php