本文整理汇总了PHP中grant_super_admin函数的典型用法代码示例。如果您正苦于以下问题:PHP grant_super_admin函数的具体用法?PHP grant_super_admin怎么用?PHP grant_super_admin使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了grant_super_admin函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
function setUp()
{
parent::setUp();
// Hide deprecated warnings on PHP 7 so the use of deprecated constructors in WordPress
// don't cause our tests to fail
if (version_compare(PHP_VERSION, 7, '>=')) {
error_reporting(E_ALL & ~E_DEPRECATED);
}
$roles = array('admin' => 'administrator', 'editor' => 'editor', 'author' => 'author', 'contributor' => 'contributor', 'subscriber' => 'subscriber', 'no_role' => '');
foreach ($roles as $name => $role) {
$this->users[$name] = $this->factory->user->create_and_get(array('role' => $role));
$this->testers[$name] = $this->factory->user->create_and_get(array('role' => $role));
}
if (is_multisite()) {
$this->users['super'] = $this->factory->user->create_and_get(array('role' => 'administrator'));
$this->testers['super'] = $this->factory->user->create_and_get(array('role' => 'administrator'));
grant_super_admin($this->users['super']->ID);
grant_super_admin($this->testers['super']->ID);
}
// Prevent undefined index notices when using `wp_validate_auth_cookie()`.
// See https://core.trac.wordpress.org/ticket/32636
if (!isset($_SERVER['REQUEST_METHOD'])) {
$_SERVER['REQUEST_METHOD'] = 'GET';
}
}
示例2: userIsASuperAdmin
/**
* @Given User :login is a super-admin
*/
public function userIsASuperAdmin($login)
{
$user = get_user_by('login', $login);
if (!$user) {
throw new \InvalidArgumentException(sprintf('No user found with username %s!', $login));
}
grant_super_admin($user->ID);
}
示例3: setUp
function setUp()
{
parent::setUp();
// create a super-admin
$this->administrator_id = $this->make_user_by_role('administrator');
if (is_multisite()) {
grant_super_admin($this->administrator_id);
}
}
示例4: set_admin
protected function set_admin()
{
$user_id = $this->factory->user->create(array('role' => 'administrator'));
if (function_exists('grant_super_admin')) {
grant_super_admin($user_id);
}
wp_set_current_user($user_id);
return $user_id;
}
示例5: test_get_dashboard_url_for_network_administrator_with_no_sites
/**
* @ticket 39065
*/
public function test_get_dashboard_url_for_network_administrator_with_no_sites()
{
if (!is_multisite()) {
$this->markTestSkipped('Test only runs in multisite.');
}
grant_super_admin(self::$user_id);
add_filter('get_blogs_of_user', '__return_empty_array');
$expected = admin_url();
$result = get_dashboard_url(self::$user_id);
revoke_super_admin(self::$user_id);
$this->assertEquals($expected, $result);
}
示例6: setUp
function setUp()
{
parent::setUp();
$this->admin = $this->factory->user->create_and_get(array('role' => 'administrator'));
$this->editor = $this->factory->user->create_and_get(array('role' => 'editor'));
$this->author = $this->factory->user->create_and_get(array('role' => 'author'));
$this->contributor = $this->factory->user->create_and_get(array('role' => 'contributor'));
$this->subscriber = $this->factory->user->create_and_get(array('role' => 'subscriber'));
$this->no_role = $this->factory->user->create_and_get(array('role' => ''));
$this->translator = $this->factory->user->create_and_get(array('role' => 'translator'));
if (is_multisite()) {
$this->super = $this->factory->user->create_and_get(array('role' => 'administrator'));
grant_super_admin($this->super->ID);
}
}
示例7: setUp
/**
* Set up the test case.
*
* @see WP_UnitTestCase::setup()
*/
function setUp()
{
parent::setUp();
require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
$user_id = self::factory()->user->create(array('role' => 'administrator'));
if (is_multisite()) {
grant_super_admin($user_id);
}
wp_set_current_user($user_id);
global $wp_customize;
$this->wp_customize = new WP_Customize_Manager();
$wp_customize = $this->wp_customize;
do_action('customize_register', $this->wp_customize);
$this->setting = new WP_Customize_Custom_CSS_Setting($this->wp_customize, 'custom_css[' . get_stylesheet() . ']');
$this->wp_customize->add_setting($this->setting);
}
示例8: setUp
function setUp()
{
parent::setUp();
$roles = array('admin' => 'administrator', 'editor' => 'editor', 'author' => 'author', 'contributor' => 'contributor', 'subscriber' => 'subscriber', 'no_role' => '');
foreach ($roles as $name => $role) {
$this->users[$name] = $this->factory->user->create_and_get(array('role' => $role));
$this->testers[$name] = $this->factory->user->create_and_get(array('role' => $role));
}
if (is_multisite()) {
$this->users['super'] = $this->factory->user->create_and_get(array('role' => 'administrator'));
$this->testers['super'] = $this->factory->user->create_and_get(array('role' => 'administrator'));
grant_super_admin($this->users['super']->ID);
grant_super_admin($this->testers['super']->ID);
}
// Prevent undefined index notices when using `wp_validate_auth_cookie()`.
// See https://core.trac.wordpress.org/ticket/32636
if (!isset($_SERVER['REQUEST_METHOD'])) {
$_SERVER['REQUEST_METHOD'] = 'GET';
}
}
示例9: test_paging_filters
function test_paging_filters()
{
$administrator_id = $this->make_user_by_role('administrator');
if (is_multisite()) {
grant_super_admin($administrator_id);
}
$this->factory->user->create_many(13);
$user_ids = get_users(array('fields' => 'ID'));
$users_found = array();
$page_size = floor(count($user_ids) / 3);
$filter = array('number' => $page_size, 'offset' => 0);
do {
$presults = $this->myxmlrpcserver->wp_getUsers(array(1, 'administrator', 'administrator', $filter));
foreach ($presults as $user) {
$users_found[] = $user['user_id'];
}
$filter['offset'] += $page_size;
} while (count($presults) > 0);
// verify that $user_ids matches $users_found
$this->assertEquals(0, count(array_diff($user_ids, $users_found)));
}
示例10: ensure_account_user
public function ensure_account_user($email = NULL)
{
$sitename = PWP_NAME;
echo "Ensuring user: " . $sitename . "\n";
$user_id = username_exists($sitename);
// get existing ID
$user = array('user_login' => $sitename, 'user_url' => home_url(), 'role' => 'administrator', 'user_nicename' => $sitename);
// The email address and password for the user
if (!$email) {
$email = wpe_param('email');
}
if (!$email) {
$data = $this->get_customer_record();
$email = $data['email'];
}
if ($email) {
$user['user_email'] = $email;
}
$pw = wpe_param('pw');
if ($pw) {
$user['user_pass'] = $pw;
} else {
$user['user_pass'] = md5(rand() . time() . rand());
}
// random password so they get one from 'lost pw button'
if (!$user_id) {
$user_id = wp_insert_user($user);
// creates; returns new user ID
} else {
$user['ID'] = $user_id;
wp_update_user($user);
// update!
}
// Make Multisite admin a Super Admin
if ($user_id && function_exists('is_multisite') && is_multisite()) {
require_once ABSPATH . '/wp-admin/includes/ms.php';
grant_super_admin($user_id);
}
}
示例11: test__super_admin_should_not_have_update_core_cap
public function test__super_admin_should_not_have_update_core_cap()
{
$super_admin = $this->factory->user->create_and_get(array('role' => 'contributor'));
grant_super_admin($super_admin->ID);
$this->assertFalse(user_can($super_admin, 'update_core'), 'Superadmin user should not have `update_core` cap');
}
示例12: promote_user_to_vip_support
/**
*
*
* @param $user_id
*/
protected function promote_user_to_vip_support($user_id)
{
$user = new WP_User($user_id);
$user->set_role(WPCOM_VIP_Support_Role::VIP_SUPPORT_ROLE);
if (is_multisite()) {
require_once ABSPATH . '/wp-admin/includes/ms.php';
grant_super_admin($user_id);
}
update_user_meta($user->ID, $GLOBALS['wpdb']->get_blog_prefix() . 'user_level', 10);
}
示例13: verify
/**
* Marks the user with the provided ID as having a verified email.
*
*
* <user-id>
* : The WP User ID to mark as having a verified email address
*
* @subcommand verify
*
* ## EXAMPLES
*
* wp vipsupport verify 99
*
*/
public function verify($args)
{
$user_id = absint($args[0]);
if (!$user_id) {
\WP_CLI::error("Please provide the ID of the user to verify");
}
$user = get_user_by('id', $user_id);
if (!$user) {
\WP_CLI::error("Could not find a user with ID {$user_id}");
}
// If this is a multisite, commence super powers!
if (is_multisite()) {
grant_super_admin($user->ID);
}
WPCOM_VIP_Support_User::init()->mark_user_email_verified($user->ID, $user->user_email);
// Print a success message
\WP_CLI::success("Verified user {$user_id} with email {$user->user_email}, you can now change their role to VIP Support");
}
示例14: bbp_edit_user_handler
//.........这里部分代码省略.........
* @uses bbp_verify_nonce_request() To verify the nonce and check the request
* @uses current_user_can() To check if the current user can edit the user
* @uses do_action() Calls 'personal_options_update' or
* 'edit_user_options_update' (based on if it's the user home)
* with the displayed user id
* @uses edit_user() To edit the user based on the post data
* @uses get_userdata() To get the user data
* @uses is_email() To check if the string is an email id or not
* @uses wpdb::get_blog_prefix() To get the blog prefix
* @uses is_network_admin() To check if the user is the network admin
* @uses is_super_admin() To check if the user is super admin
* @uses revoke_super_admin() To revoke super admin priviledges
* @uses grant_super_admin() To grant super admin priviledges
* @uses is_wp_error() To check if the value retrieved is a {@link WP_Error}
*/
function bbp_edit_user_handler()
{
// Bail if not a POST action
if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
return;
}
// Bail if action is not 'bbp-update-user'
if (empty($_POST['action']) || 'bbp-update-user' !== $_POST['action']) {
return;
}
// Get the displayed user ID
$user_id = bbp_get_displayed_user_id();
global $wpdb, $user_login, $super_admins;
// Execute confirmed email change. See send_confirmation_on_profile_email().
if (is_multisite() && bbp_is_user_home_edit() && isset($_GET['newuseremail'])) {
$new_email = get_option($user_id . '_new_email');
if ($new_email['hash'] == $_GET['newuseremail']) {
$user = new stdClass();
$user->ID = $user_id;
$user->user_email = esc_html(trim($new_email['newemail']));
if ($wpdb->get_var($wpdb->prepare("SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", bbp_get_displayed_user_field('user_login')))) {
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $user->user_email, bbp_get_displayed_user_field('user_login')));
}
wp_update_user(get_object_vars($user));
delete_option($user_id . '_new_email');
wp_safe_redirect(add_query_arg(array('updated' => 'true'), bbp_get_user_profile_edit_url($user_id)));
exit;
}
} elseif (is_multisite() && bbp_is_user_home_edit() && !empty($_GET['dismiss']) && $user_id . '_new_email' == $_GET['dismiss']) {
delete_option($user_id . '_new_email');
wp_safe_redirect(add_query_arg(array('updated' => 'true'), bbp_get_user_profile_edit_url($user_id)));
exit;
}
// Nonce check
if (!bbp_verify_nonce_request('update-user_' . $user_id)) {
bbp_add_error('bbp_update_user_nonce', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress'));
return;
}
// Cap check
if (!current_user_can('edit_user', $user_id)) {
bbp_add_error('bbp_update_user_capability', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress'));
return;
}
// Do action based on who's profile you're editing
$edit_action = bbp_is_user_home_edit() ? 'personal_options_update' : 'edit_user_profile_update';
do_action($edit_action, $user_id);
// Multisite handles the trouble for us ;)
if (!is_multisite()) {
$edit_user = edit_user($user_id);
// Single site means we need to do some manual labor
} else {
$user = get_userdata($user_id);
// Update the email address in signups, if present.
if ($user->user_login && isset($_POST['email']) && is_email($_POST['email']) && $wpdb->get_var($wpdb->prepare("SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", $user->user_login))) {
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $_POST['email'], $user_login));
}
// WPMU must delete the user from the current blog if WP added him after editing.
$delete_role = false;
$blog_prefix = $wpdb->get_blog_prefix();
if ($user_id != $user_id) {
$cap = $wpdb->get_var("SELECT meta_value FROM {$wpdb->usermeta} WHERE user_id = '{$user_id}' AND meta_key = '{$blog_prefix}capabilities' AND meta_value = 'a:0:{}'");
if (!is_network_admin() && null == $cap && $_POST['role'] == '') {
$_POST['role'] = 'contributor';
$delete_role = true;
}
}
$edit_user = edit_user($user_id);
// stops users being added to current blog when they are edited
if (true === $delete_role) {
delete_user_meta($user_id, $blog_prefix . 'capabilities');
}
if (is_multisite() && is_network_admin() & !bbp_is_user_home_edit() && current_user_can('manage_network_options') && !isset($super_admins) && empty($_POST['super_admin']) == is_super_admin($user_id)) {
empty($_POST['super_admin']) ? revoke_super_admin($user_id) : grant_super_admin($user_id);
}
}
// Error(s) editng the user, so copy them into the global
if (is_wp_error($edit_user)) {
bbpress()->errors = $edit_user;
// Successful edit to redirect
} elseif (is_integer($edit_user)) {
$redirect = add_query_arg(array('updated' => 'true'), bbp_get_user_profile_edit_url($edit_user));
wp_safe_redirect($redirect);
exit;
}
}
示例15: ajax_create_user
function ajax_create_user()
{
$username = sanitize_user($_POST['username']);
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
$email = $_POST['email'];
$user_id = absint($_POST['user_id']);
$role = 'administrator';
if ($pass1 != $pass2) {
die(json_encode(array("error" => "The passwords do not match")));
}
if (!validate_username($username)) {
die(json_encode(array("error" => "The username is invalid")));
}
if (!is_email($email)) {
die(json_encode(array("error" => "The email address is invalid")));
}
if (empty($username)) {
die(json_encode(array("error" => "Username cannot be empty")));
}
if (empty($pass1)) {
die(json_encode(array("error" => "Password cannot be empty")));
}
if (username_exists($username) && $user_id == 0) {
die(json_encode(array("error" => "Username already exists")));
}
if (email_exists($email) && $user_id == 0) {
die(json_encode(array("error" => "E-mail address already exists")));
}
$user_created = false;
$return_html = '';
if (!username_exists($username) && !username_exists($email)) {
$user_args = array('user_login' => $username, 'user_email' => $email, 'user_pass' => $pass1, 'role' => $role);
$result = wp_insert_user($user_args);
if (is_wp_error($result)) {
echo 'ERROR: ' . $result->get_error_message();
}
if (is_multisite()) {
if (!function_exists('grant_super_admin')) {
require_once ABSPATH . 'wp-admin/includes/ms.php';
}
grant_super_admin($result);
}
$user_created = true;
$return_html = sprintf("User of <em>%s</em> has been created! Your password is <em>%s</em>. <a href='%s'>Login Now</a>", $username, $pass1, admin_url());
} else {
if (false != ($user_object = get_user_by('id', $user_id))) {
if (is_wp_error($user_object)) {
die(json_encode(array("error" => $user_object->get_error_message())));
}
$user_args = array('ID' => $user_object->ID, 'user_pass' => $pass1, 'role' => $role);
$result = wp_update_user($user_args);
if (is_multisite()) {
if (!function_exists('grant_super_admin')) {
require_once ABSPATH . 'wp-admin/includes/ms.php';
}
grant_super_admin($user_object->ID);
}
if (is_wp_error($result)) {
die(json_encode(array('error' => $result->get_error_message())));
}
$user_created = true;
$return_html = sprintf("User of <em>%s</em> has been updated! Your new password is <em>%s</em>. <a href='%s'>Login Now</a>", $username, $pass1, admin_url());
}
}
if ($user_created == true) {
die(json_encode(array('success' => $return_html)));
} else {
die(json_encode(array("error" => "User could not be updated")));
}
}