members_sanitize_role

The members members sanitize role function.

Published Date - July 31, 2023

Description

Sanitizes a role name. This is a wrapper for the `sanitize_key()` WordPress function. Only alphanumeric characters and underscores are allowed. Hyphens are also replaced with underscores.

members_sanitize_role( $role );

Parameters

  1. $role


Usage

The following example is for adding a hook callback.

if ( !function_exists( 'members_sanitize_role' ) ) {
    require_once ABSPATH . PLUGINDIR . 'membersmembers/inc/functions-roles.php';
}

// The input(s). 
$role = null;

// NOTICE! Understand what this does before running.
$result = members_sanitize_role( $role );
            

Defined

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

members/inc/functions-roles.php

function members_sanitize_role( $role ) {

	$_role = strtolower( $role );
	$_role = preg_replace( '/[^a-z0-9_\-\s]/', '', $_role );

	return apply_filters( 'members_sanitize_role', str_replace( ' ', '_', $_role ), $role );
}