avoid_blog_page_permalink_collision

Avoids a collision between a site slug and a permalink slug.

Description

(array) avoid_blog_page_permalink_collision( (array) $data, (array) $postarr ); 

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.

Returns (array)

The new array of post data after checking for collisions.

Parameters (2)

0. $data (array)
An array of post data.
1. $postarr (array)
An array of posts. Not currently used.

Usage

  1. if ( !function_exists( 'avoid_blog_page_permalink_collision' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/ms.php'; 
  3.  
  4. // An array of post data. 
  5. $data = array(); 
  6.  
  7. // An array of posts. Not currently used. 
  8. $postarr = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = avoid_blog_page_permalink_collision($data, $postarr); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/ms.php  
  1. function avoid_blog_page_permalink_collision( $data, $postarr ) { 
  2. return $data; 
  3. if ( $data['post_type'] != 'page' ) 
  4. return $data; 
  5. if ( !isset( $data['post_name'] ) || $data['post_name'] == '' ) 
  6. return $data; 
  7. if ( !is_main_site() ) 
  8. return $data; 
  9.  
  10. $post_name = $data['post_name']; 
  11. $c = 0; 
  12. while( $c < 10 && get_id_from_blogname( $post_name ) ) { 
  13. $post_name .= mt_rand( 1, 10 ); 
  14. $c ++; 
  15. if ( $post_name != $data['post_name'] ) { 
  16. $data['post_name'] = $post_name; 
  17. return $data;