bbp_form_slug_conflict_check

Used to check if a bbPress slug conflicts with an existing known slug.

Description

bbp_form_slug_conflict_check( (string) $slug, (string) $default ); 

Parameters (2)

0. $slug (string)
The slug.
1. $default (string)
The default.

Usage

  1. if ( !function_exists( 'bbp_form_slug_conflict_check' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/admin/settings.php'; 
  3.  
  4. // The slug. 
  5. $slug = ''; 
  6.  
  7. // The default. 
  8. $default = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bbp_form_slug_conflict_check($slug, $default); 
  12.  

Defined (1)

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

/includes/admin/settings.php  
  1. function bbp_form_slug_conflict_check( $slug, $default ) { 
  2.  
  3. // Only set the slugs once ver page load 
  4. static $the_core_slugs = array(); 
  5.  
  6. // Get the form value 
  7. $this_slug = bbp_get_form_option( $slug, $default, true ); 
  8.  
  9. if ( empty( $the_core_slugs ) ) { 
  10.  
  11. // Slugs to check 
  12. $core_slugs = apply_filters( 'bbp_slug_conflict_check', array( 
  13.  
  14. /** WordPress Core ****************************************************/ 
  15.  
  16. // Core Post Types 
  17. 'post_base' => array( 'name' => __( 'Posts', bbpress ), 'default' => 'post', 'context' => 'WordPress' ),  
  18. 'page_base' => array( 'name' => __( 'Pages', bbpress ), 'default' => 'page', 'context' => 'WordPress' ),  
  19. 'revision_base' => array( 'name' => __( 'Revisions', bbpress ), 'default' => 'revision', 'context' => 'WordPress' ),  
  20. 'attachment_base' => array( 'name' => __( 'Attachments', bbpress ), 'default' => 'attachment', 'context' => 'WordPress' ),  
  21. 'nav_menu_base' => array( 'name' => __( 'Menus', bbpress ), 'default' => 'nav_menu_item', 'context' => 'WordPress' ),  
  22.  
  23. // Post Tags 
  24. 'tag_base' => array( 'name' => __( 'Tag base', bbpress ), 'default' => 'tag', 'context' => 'WordPress' ),  
  25.  
  26. // Post Categories 
  27. 'category_base' => array( 'name' => __( 'Category base', bbpress ), 'default' => 'category', 'context' => 'WordPress' ),  
  28.  
  29. /** bbPress Core ******************************************************/ 
  30.  
  31. // Forum archive slug 
  32. '_bbp_root_slug' => array( 'name' => __( 'Forums base', bbpress ), 'default' => 'forums', 'context' => 'bbPress' ),  
  33.  
  34. // Topic archive slug 
  35. '_bbp_topic_archive_slug' => array( 'name' => __( 'Topics base', bbpress ), 'default' => 'topics', 'context' => 'bbPress' ),  
  36.  
  37. // Forum slug 
  38. '_bbp_forum_slug' => array( 'name' => __( 'Forum slug', bbpress ), 'default' => 'forum', 'context' => 'bbPress' ),  
  39.  
  40. // Topic slug 
  41. '_bbp_topic_slug' => array( 'name' => __( 'Topic slug', bbpress ), 'default' => 'topic', 'context' => 'bbPress' ),  
  42.  
  43. // Reply slug 
  44. '_bbp_reply_slug' => array( 'name' => __( 'Reply slug', bbpress ), 'default' => 'reply', 'context' => 'bbPress' ),  
  45.  
  46. // User profile slug 
  47. '_bbp_user_slug' => array( 'name' => __( 'User base', bbpress ), 'default' => 'users', 'context' => 'bbPress' ),  
  48.  
  49. // View slug 
  50. '_bbp_view_slug' => array( 'name' => __( 'View base', bbpress ), 'default' => 'view', 'context' => 'bbPress' ),  
  51.  
  52. // Topic tag slug 
  53. '_bbp_topic_tag_slug' => array( 'name' => __( 'Topic tag slug', bbpress ), 'default' => 'topic-tag', 'context' => 'bbPress' ),  
  54. ) ); 
  55.  
  56. /** BuddyPress Core *******************************************************/ 
  57.  
  58. if ( defined( 'BP_VERSION' ) ) { 
  59. $bp = buddypress(); 
  60.  
  61. // Loop through root slugs and check for conflict 
  62. if ( !empty( $bp->pages ) ) { 
  63. foreach ( $bp->pages as $page => $page_data ) { 
  64. $page_base = $page . '_base'; 
  65. $page_title = sprintf( __( '%s page', bbpress ), $page_data->title ); 
  66. $core_slugs[$page_base] = array( 'name' => $page_title, 'default' => $page_data->slug, 'context' => 'BuddyPress' ); 
  67.  
  68. // Set the static 
  69. $the_core_slugs = apply_filters( 'bbp_slug_conflict', $core_slugs ); 
  70.  
  71. // Loop through slugs to check 
  72. foreach ( $the_core_slugs as $key => $value ) { 
  73.  
  74. // Get the slug 
  75. $slug_check = bbp_get_form_option( $key, $value['default'], true ); 
  76.  
  77. // Compare 
  78. if ( ( $slug !== $key ) && ( $slug_check === $this_slug ) ) : ?> 
  79.  
  80. <span class="attention"><?php printf( esc_html__( 'Possible %1$s conflict: %2$s', bbpress ), $value['context'], '<strong>' . $value['name'] . '</strong>' ); ?></span> 
  81.  
  82. <?php endif;