wpseek.com
Bazujące na WordPress narzędzie wyszukiwania dla deweloperów i twórców motywów.



add_role › WordPress Function

Od2.0.0
Przestarzałyn/a
› add_role ( $role, $display_name, $capabilities = array() )
Parametry: (3)
  • (string) $role Role name.
    Wymagane: Tak
  • (string) $display_name Display name for role.
    Wymagane: Tak
  • (array<string,bool>|array<int,string>) $capabilities Capabilities to be added to the role. Default empty array.
    Wymagane: Nie
    Domyślny: array()
Powrót:
  • (WP_Role|null) WP_Role object, if the role is added.
Zdefiniowane na:
Codex:
Dziennik zmian:
  • 6.9.0

Adds a role, if it does not exist.

The list of capabilities can be passed either as a numerically indexed array of capability names, or an associative array of boolean values keyed by the capability name. To explicitly deny the role a capability, set the value for that capability to false. Examples: // Add a role that can edit posts. add_role( 'custom_role', 'Custom Role', array( 'read', 'edit_posts', ) ); Or, using an associative array: // Add a role that can edit posts but explicitly cannot not delete them. add_role( 'custom_role', 'Custom Role', array( 'read' => true, 'edit_posts' => true, 'delete_posts' => false, ) );


Powiązane Funkcje: add_filter, add_feed, add_link, add_meta, add_user

Źródło

function add_role( $role, $display_name, $capabilities = array() ) {
	if ( empty( $role ) ) {
		return null;
	}

	return wp_roles()->add_role( $role, $display_name, $capabilities );
}