Support » Networking WordPress » avoid_blog_page_permalink_collision bug

  • Resolved nuttyloaf

    (@nuttyloaf)


    Hi WP Gurus

    I’ve come across an issue with the avoid_blog_page_permalink_collision function when I was adding a filter to the wp_insert_post_data hook.

    It seems to expect a $data parameter as an array, but the actual parameter is a sometimes a WP_Post object and other times an array.

    I’ve corrected the function in my ms.php file as shown below. Could anyone please let me know if this will affect anything else?

    function avoid_blog_page_permalink_collision( $data, $postarr ) {

    if ( is_subdomain_install() )
    return $data;

    if ( is_object ( $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;
    }
    }
    else
    {
    //original code:
    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;
    }

Viewing 1 replies (of 1 total)
  • After looking into this further I realised there was an issue in a function I created. Funnily enough this only caused problems when I tested my plugin in the Multisite WP installation.

    It turns out that a filter function called by the wp_insert_post_data hook can return either a WP_post object or an array with its data in standard WP, but it MUST return an array in Multisite.

    Problem solved!

Viewing 1 replies (of 1 total)
  • The topic ‘avoid_blog_page_permalink_collision bug’ is closed to new replies.