wp_roles() WP 4.3.0

Отримує глобальну змінну $wp_roles , якщо вона не визначена, записує до неї екземпляр класу WP_Roles .

Кешує в глобальну змінну $wp_roles екземпляр класу WP_Roles і повертає змінну $wp_roles .

Дані про ролі зберігаються в таблиці опцій wp_options – опція wp_user_roles .

1 раз – 0.000017 сек
(дуже швидко) | 50000 разів – 0.01 сек
(швидкість світла)

Хуків немає.

Повертає

WP_Roles.

Використання

wp_roles();

Приклади

0

#1 Отримаємо назву ролі

echo wp_roles()->roles['administrator']['name']; // > Адміністратор
0

#2 Отримаємо весь клас

print_r(wp_roles());

/* Виведе:
WP_Roles Object
(
	[roles] => Array
		(
			[administrator] => Array
				(
					[name] => Administrator
					[capabilities] => Array
						(
							[switch_themes] => 1
							[edit_themes] => 1
							[activate_plugins] => 1
							[edit_plugins] => 1
							[edit_users] => 1
							[edit_files] => 1
							[manage_options] => 1
							[moderate_comments] => 1
							[manage_categories] => 1
							[manage_links] => 1
							[upload_files] => 1
							[import] => 1
							[unfiltered_html] => 1
							[edit_posts] => 1
							[edit_others_posts] => 1
							[edit_published_posts] => 1
							[publish_posts] => 1
							[edit_pages] => 1
							[read] => 1
							[level_10] => 1
							[level_9] => 1
							[level_8] => 1
							[level_7] => 1
							[level_6] => 1
							[level_5] => 1
							[level_4] => 1
							[level_3] => 1
							[level_2] => 1
							[level_1] => 1
							[level_0] => 1
							[edit_others_pages] => 1
							[edit_published_pages] => 1
							[publish_pages] => 1
							[delete_pages] => 1
							[delete_others_pages] => 1
							[delete_published_pages] => 1
							[delete_posts] => 1
							[delete_others_posts] => 1
							[delete_published_posts] => 1
							[delete_private_posts] => 1
							[edit_private_posts] => 1
							[read_private_posts] => 1
							[delete_private_pages] => 1
							[edit_private_pages] => 1
							[read_private_pages] => 1
							[delete_users] => 1
							[create_users] => 1
							[unfiltered_upload] => 1
							[edit_dashboard] => 1
							[update_plugins] => 1
							[delete_plugins] => 1
							[install_plugins] => 1
							[update_themes] => 1
							[install_themes] => 1
							[manage_downloads] => 1
							[manage_database] => 1
							[democracy_admin] => 1
							[update_core] => 1
							[list_users] => 1
							[remove_users] => 1
							[add_users] => 1
							[promote_users] => 1
							[edit_theme_options] => 1
							[delete_themes] => 1
							[export] => 1
						)

				)

			[editor] => Array
				(
					[name] => Editor
					[capabilities] => Array
						(
							[moderate_comments] => 1
							[manage_categories] => 1
							[manage_links] => 1
							[upload_files] => 1
							[unfiltered_html] => 1
							[edit_posts] => 1
							[edit_others_posts] => 1
							[edit_published_posts] => 1
							[publish_posts] => 1
							[edit_pages] => 1
							[read] => 1
							[level_7] => 1
							[level_6] => 1
							[level_5] => 1
							[level_4] => 1
							[level_3] => 1
							[level_2] => 1
							[level_1] => 1
							[level_0] => 1
							[edit_others_pages] => 1
							[edit_published_pages] => 1
							[publish_pages] => 1
							[delete_pages] => 1
							[delete_others_pages] => 1
							[delete_published_pages] => 1
							[delete_posts] => 1
							[delete_others_posts] => 1
							[delete_published_posts] => 1
							[delete_private_posts] => 1
							[edit_private_posts] => 1
							[read_private_posts] => 1
							[delete_private_pages] => 1
							[edit_private_pages] => 1
							[read_private_pages] => 1
							[democracy_admin] => 1
						)

				)

			[author] => Array
				(
					[name] => Author
					[capabilities] => Array
						(
							[upload_files] => 1
							[edit_posts] => 1
							[edit_published_posts] => 1
							[publish_posts] => 1
							[read] => 1
							[level_2] => 1
							[level_1] => 1
							[level_0] => 1
							[delete_posts] => 1
							[delete_published_posts] => 1
						)

				)

			[contributor] => Array
				(
					[name] => Contributor
					[capabilities] => Array
						(
							[edit_posts] => 1
							[read] => 1
							[level_1] => 1
							[level_0] => 1
							[delete_posts] => 1
						)

				)

			[subscriber] => Array
				(
					[name] => Subscriber
					[capabilities] => Array
						(
							[read] => 1
							[level_0] => 1
						)

				)

		)

	[role_objects] => Array
		(
			[administrator] => WP_Role Object
				(
					[name] => administrator
					[capabilities] => Array
						(
							[switch_themes] => 1
							[edit_themes] => 1
							[activate_plugins] => 1
							[edit_plugins] => 1
							[edit_users] => 1
							[edit_files] => 1
							[manage_options] => 1
							[moderate_comments] => 1
							[manage_categories] => 1
							[manage_links] => 1
							[upload_files] => 1
							[import] => 1
							[unfiltered_html] => 1
							[edit_posts] => 1
							[edit_others_posts] => 1
							[edit_published_posts] => 1
							[publish_posts] => 1
							[edit_pages] => 1
							[read] => 1
							[level_10] => 1
							[level_9] => 1
							[level_8] => 1
							[level_7] => 1
							[level_6] => 1
							[level_5] => 1
							[level_4] => 1
							[level_3] => 1
							[level_2] => 1
							[level_1] => 1
							[level_0] => 1
							[edit_others_pages] => 1
							[edit_published_pages] => 1
							[publish_pages] => 1
							[delete_pages] => 1
							[delete_others_pages] => 1
							[delete_published_pages] => 1
							[delete_posts] => 1
							[delete_others_posts] => 1
							[delete_published_posts] => 1
							[delete_private_posts] => 1
							[edit_private_posts] => 1
							[read_private_posts] => 1
							[delete_private_pages] => 1
							[edit_private_pages] => 1
							[read_private_pages] => 1
							[delete_users] => 1
							[create_users] => 1
							[unfiltered_upload] => 1
							[edit_dashboard] => 1
							[update_plugins] => 1
							[delete_plugins] => 1
							[install_plugins] => 1
							[update_themes] => 1
							[install_themes] => 1
							[manage_downloads] => 1
							[manage_database] => 1
							[democracy_admin] => 1
							[update_core] => 1
							[list_users] => 1
							[remove_users] => 1
							[add_users] => 1
							[promote_users] => 1
							[edit_theme_options] => 1
							[delete_themes] => 1
							[export] => 1
						)

				)

			[editor] => WP_Role Object
				(
					[name] => editor
					[capabilities] => Array
						(
							[moderate_comments] => 1
							[manage_categories] => 1
							[manage_links] => 1
							[upload_files] => 1
							[unfiltered_html] => 1
							[edit_posts] => 1
							[edit_others_posts] => 1
							[edit_published_posts] => 1
							[publish_posts] => 1
							[edit_pages] => 1
							[read] => 1
							[level_7] => 1
							[level_6] => 1
							[level_5] => 1
							[level_4] => 1
							[level_3] => 1
							[level_2] => 1
							[level_1] => 1
							[level_0] => 1
							[edit_others_pages] => 1
							[edit_published_pages] => 1
							[publish_pages] => 1
							[delete_pages] => 1
							[delete_others_pages] => 1
							[delete_published_pages] => 1
							[delete_posts] => 1
							[delete_others_posts] => 1
							[delete_published_posts] => 1
							[delete_private_posts] => 1
							[edit_private_posts] => 1
							[read_private_posts] => 1
							[delete_private_pages] => 1
							[edit_private_pages] => 1
							[read_private_pages] => 1
							[democracy_admin] => 1
						)

				)

			[author] => WP_Role Object
				(
					[name] => author
					[capabilities] => Array
						(
							[upload_files] => 1
							[edit_posts] => 1
							[edit_published_posts] => 1
							[publish_posts] => 1
							[read] => 1
							[level_2] => 1
							[level_1] => 1
							[level_0] => 1
							[delete_posts] => 1
							[delete_published_posts] => 1
						)

				)

			[contributor] => WP_Role Object
				(
					[name] => contributor
					[capabilities] => Array
						(
							[edit_posts] => 1
							[read] => 1
							[level_1] => 1
							[level_0] => 1
							[delete_posts] => 1
						)

				)

			[subscriber] => WP_Role Object
				(
					[name] => subscriber
					[capabilities] => Array
						(
							[read] => 1
							[level_0] => 1
						)

				)

		)

	[role_names] => Array
		(
			[administrator] => Administrator
			[editor] => Editor
			[author] => Author
			[contributor] => Contributor
			[subscriber] => Subscriber
		)

	[role_key] => wp_user_roles
	[use_db] => 1
)
*/

нотатки

  • Global. WP_Roles. $wp_roles WordPress role management object.

список змін

З версії 4.3.0Введено.

Код wp_roles() WP 6.0.2

function wp_roles() {
	global $wp_roles;

	if ( ! isset( $wp_roles ) ) {
		$wp_roles = новий WP_Roles();
	}
	return $wp_roles;
}

Залишити відповідь

Ваша e-mail адреса не оприлюднюватиметься. Обов’язкові поля позначені *