avoid_blog_page_permalink_collision

The timeline below displays how wordpress function avoid_blog_page_permalink_collision has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.4

/**
 * 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 ('page' !== $data['post_type']) {
        return $data;
    }
    if (!isset($data['post_name']) || '' === $data['post_name']) {
        return $data;
    }
    if (!is_main_site()) {
        return $data;
    }
    if (isset($data['post_parent']) && $data['post_parent']) {
        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;
}

WordPress Version: 5.9

/**
 * 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 ('page' !== $data['post_type']) {
        return $data;
    }
    if (!isset($data['post_name']) || '' === $data['post_name']) {
        return $data;
    }
    if (!is_main_site()) {
        return $data;
    }
    if (isset($data['post_parent']) && $data['post_parent']) {
        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;
}

WordPress Version: 5.4

/**
 * 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 ('page' !== $data['post_type']) {
        return $data;
    }
    if (!isset($data['post_name']) || '' === $data['post_name']) {
        return $data;
    }
    if (!is_main_site()) {
        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;
}

WordPress Version: 4.9

/**
 * 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;
    }
    $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;
}

WordPress Version: 4.1

/**
 * Avoids a collision between a site slug and a permalink slug.
 *
 * In a subdirectory install 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;
    }
    $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;
}

WordPress Version: 3.7

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;
    }
    $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;
}