bbp_sanitize_slug

Sanitize permalink slugs when saving the settings page.

Description

(string) bbp_sanitize_slug( (string) $slug = '' ); 

Returns (string)

Parameters (1)

0. $slug — Optional. (string) => ''
The slug.

Usage

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

Defined (1)

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

/includes/admin/functions.php  
  1. function bbp_sanitize_slug( $slug = '' ) { 
  2.  
  3. // Don't allow multiple slashes in a row 
  4. $value = preg_replace( '#/+#', '/', str_replace( '#', '', $slug ) ); 
  5.  
  6. // Strip out unsafe or unusable chars 
  7. $value = esc_url_raw( $value ); 
  8.  
  9. // esc_url_raw() adds a scheme via esc_url(), so let's remove it 
  10. $value = str_replace( 'http://', '', $value ); 
  11.  
  12. // Trim off first and last slashes. 
  13. // 
  14. // We already prevent double slashing elsewhere, but let's prevent 
  15. // accidental poisoning of options values where we can. 
  16. $value = ltrim( $value, '/' ); 
  17. $value = rtrim( $value, '/' ); 
  18.  
  19. // Filter the result and return 
  20. return apply_filters( 'bbp_sanitize_slug', $value, $slug );