[wp-trac] [WordPress Trac] #21093: wp_unique_term_slug() & Custom Post Type / Page Slugs Comparison

WordPress Trac wp-trac at lists.automattic.com
Thu Jun 28 06:35:21 UTC 2012


#21093: wp_unique_term_slug() & Custom Post Type / Page Slugs Comparison
--------------------------+-----------------------------
 Reporter:  wpsmith       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Taxonomy      |    Version:
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 Let's consider pages and a custom taxonomy registered as follows:

 {{{
 $labels = array(
     'name' => _x( 'Worksheets', 'taxonomy general name' ),
     'singular_name' => _x( 'Worksheet', 'taxonomy singular name' ),
     'search_items' =>  __( 'Search Worksheets' ),
     'all_items' => __( 'All Worksheets' ),
     'parent_item' => __( 'Parent Worksheet' ),
     'parent_item_colon' => __( 'Parent Worksheet:' ),
     'edit_item' => __( 'Edit Worksheet' ),
     'update_item' => __( 'Update Worksheet' ),
     'add_new_item' => __( 'Add New Worksheet' ),
     'new_item_name' => __( 'New Worksheet Name' ),
     'menu_name' => __( 'Worksheet' ),
   );

 register_taxonomy(
     'k12_worksheet_type',
     array( 'k12_worksheets' ),
     array(
         'hierarchical' => true,
         'labels' => $labels,
         'show_ui' => true,
         'query_var' => true,
         'rewrite' => array( 'slug' => '', 'with_front' => false,
 'hierarchical' => true, ),
     )
 );
 }}}

 Now page slugs can be filtered with
 wp_unique_post_slug_is_bad_hierarchical_slug (and non-hierarchical custom
 post types with wp_unique_post_slug_is_bad_flat_slug). For example:

 {{{
 add_filter( 'wp_unique_post_slug_is_bad_hierarchical_slug',
 'k12_is_bad_slug', 10, 2 );
 add_filter( 'wp_unique_post_slug_is_bad_flat_slug', 'k12_is_bad_slug', 10,
 2 );
 /*
  * Checks Custom Taxonomy (k12_worksheet_type) for slug conflicts
  *
  * @param boolean $is_bad_slug False as default
  * @param string $slug Slug for "post" of whatever post type
  * @return boolean $is_bad_slug True if bad slug, False if good slug
  */
 function k12_is_bad_slug( $is_bad_slug, $slug ) {
    if ( get_terms( 'k12_worksheet_type', array( 'hide_empty' => false,
 'slug' => $slug ) ) || 'worksheet' == $slug || 'worksheets' == $slug )
       return true;
    return $is_bad_slug;
 }
 }}}

 However, if a term is created, there is no filter to check the DB for page
 slugs (etc.). wp_unique_term_slug() "will make slug unique, if it isn't
 already." So, it would be a good add to do likewise
 (wp_unique_post_slug_is_bad_hierarchical_slug &
 wp_unique_post_slug_is_bad_flat_slug).

 The obvious impact is that it will prevent possible conflicts and reduce
 troubleshooting issues. For example, I have a page called Worksheets
 (http://domain.com/worksheets/), and then have a term from
 k12_worksheet_type called Worksheets (http://domain.com/worksheets/), the
 slugs of both are the same with the permalink %post-name%.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/21093>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list