本文整理汇总了PHP中WP_User::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_User::exists方法的具体用法?PHP WP_User::exists怎么用?PHP WP_User::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_User
的用法示例。
在下文中一共展示了WP_User::exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: delete
/**
* Use this method to prevent excluding something that was not configured by FakerPress
*
* @param array|int|\WP_User $user The ID for the user or the Object
* @return bool
*/
public static function delete($user)
{
if (is_array($user)) {
$deleted = array();
foreach ($user as $id) {
$id = $id instanceof \WP_User ? $id->ID : $id;
if (!is_numeric($id)) {
continue;
}
$deleted[$id] = self::delete($id);
}
return $deleted;
}
if (is_numeric($user)) {
$user = new \WP_User($user);
}
if (!$user instanceof \WP_User || !$user->exists()) {
return false;
}
$flag = (bool) get_user_meta($user->ID, self::$flag, true);
if (true !== $flag) {
return false;
}
return wp_delete_user($user->ID, get_current_user_id());
}
示例2: array
function test_delete_user()
{
$user_id = $this->factory->user->create(array('role' => 'author'));
$user = new WP_User($user_id);
$post = array('post_author' => $user_id, 'post_status' => 'publish', 'post_content' => rand_str(), 'post_title' => rand_str(), 'post_type' => 'post');
// insert a post and make sure the ID is ok
$post_id = wp_insert_post($post);
$this->assertTrue(is_numeric($post_id));
$this->assertTrue($post_id > 0);
$post = get_post($post_id);
$this->assertEquals($post_id, $post->ID);
$post = array('post_author' => $user_id, 'post_status' => 'publish', 'post_content' => rand_str(), 'post_title' => rand_str(), 'post_type' => 'nav_menu_item');
// insert a post and make sure the ID is ok
$nav_id = wp_insert_post($post);
$this->assertTrue(is_numeric($nav_id));
$this->assertTrue($nav_id > 0);
$post = get_post($nav_id);
$this->assertEquals($nav_id, $post->ID);
wp_delete_user($user_id);
$user = new WP_User($user_id);
if (is_multisite()) {
$this->assertTrue($user->exists());
} else {
$this->assertFalse($user->exists());
}
$this->assertNotNull(get_post($post_id));
$this->assertEquals('trash', get_post($post_id)->post_status);
// nav_menu_item is delete_with_user = false so the nav post should remain published.
$this->assertNotNull(get_post($nav_id));
$this->assertEquals('publish', get_post($nav_id)->post_status);
wp_delete_post($nav_id, true);
$this->assertNull(get_post($nav_id));
wp_delete_post($post_id, true);
$this->assertNull(get_post($post_id));
}
示例3: init
/**
* @inheritdoc
*/
public function init($path)
{
$postId = filter_input(INPUT_GET, 'postid', FILTER_SANITIZE_NUMBER_INT);
$post = $postId ? get_post($postId) : false;
$allowed = apply_filters(Launcher::SLUG . '_post_types', ['post']);
if (!$post instanceof WP_Post || $this->meta->has($post->ID, $post->post_author) || !in_array($post->post_type, $allowed, true)) {
return false;
}
$this->post = $post;
$this->author = new WP_User($post->post_author);
$this->path = $path;
$mail = $this->author && $this->author->exists() ? $this->author->get('user_email') : false;
return $mail && filter_var($mail, FILTER_VALIDATE_EMAIL);
}
示例4: user_meta_shortcode_handler
/**
* User Meta Shortcode handler
* Retrieve the value of a property or meta key from the users and usermeta tables.
* usage: [user_meta user_id=1 key="first_name" size="50" wpautop="on" pre="Pre Label " post="Post Label "]
* @param array $atts
* @param string $content
* @return stirng
*/
function user_meta_shortcode_handler($atts, $content = null)
{
if (!isset($atts['user_id'])) {
$user = wp_get_current_user();
$atts['user_id'] = $user->ID;
}
if (!isset($atts['size'])) {
$atts['size'] = '50';
}
$user = new WP_User($atts['user_id']);
if (!$user->exists()) {
return;
}
if ($atts['key'] == 'avatar') {
return $atts['pre'] . get_avatar($user->ID, $atts['size']) . $atts['post'];
}
if ($user->has_prop($atts['key'])) {
if ($atts['wpautop'] == 'on') {
$value = wpautop($user->get($atts['key']));
} else {
$value = $user->get($atts['key']);
}
}
if (!empty($value)) {
return $atts['pre'] . $value . $atts['post'];
}
return;
}
示例5: test_friendship_should_create_default_initiator_and_friend
/**
* @ticket BP7243
*/
public function test_friendship_should_create_default_initiator_and_friend()
{
$f = $this->factory->friendship->create_and_get();
$u1 = new WP_User($f->initiator_user_id);
$u2 = new WP_User($f->friend_user_id);
$this->assertTrue($u1->exists());
$this->assertTrue($u2->exists());
}
示例6:
function set_as_user_role($role)
{
// create user
$user_id = $this->factory->user->create(array('role' => $role));
$user = new WP_User($user_id);
$this->assertTrue($user->exists(), 'Problem getting user ' . $user_id);
// log in as user
wp_set_current_user($user_id);
$this->{$user_id} = $user_id;
$this->assertTrue(current_user_can($role));
}
示例7:
function get_edit_user_link($user_id = null)
{
if (!$user_id) {
$user_id = get_current_user_id();
}
if (empty($user_id) || !current_user_can('edit_user', $user_id)) {
return '';
}
$user = new WP_User($user_id);
if (!$user->exists()) {
return '';
}
if (get_current_user_id() == $user->ID) {
$link = get_edit_profile_url($user->ID);
} else {
$link = add_query_arg('user_id', $user->ID, self_admin_url('user-edit.php'));
}
return apply_filters('get_edit_user_link', $link, $user->ID);
}
示例8: wpmu_delete_user
/**
* Delete a user from the network and remove from all sites.
*
* @since 3.0.0
*
* @todo Merge with wp_delete_user() ?
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param int $id The user ID.
* @return bool True if the user was deleted, otherwise false.
*/
function wpmu_delete_user($id)
{
global $wpdb;
if (!is_numeric($id)) {
return false;
}
$id = (int) $id;
$user = new WP_User($id);
if (!$user->exists()) {
return false;
}
// Global super-administrators are protected, and cannot be deleted.
$_super_admins = get_super_admins();
if (in_array($user->user_login, $_super_admins, true)) {
return false;
}
/**
* Fires before a user is deleted from the network.
*
* @since MU
*
* @param int $id ID of the user about to be deleted from the network.
*/
do_action('wpmu_delete_user', $id);
$blogs = get_blogs_of_user($id);
if (!empty($blogs)) {
foreach ($blogs as $blog) {
switch_to_blog($blog->userblog_id);
remove_user_from_blog($id, $blog->userblog_id);
$post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d", $id));
foreach ((array) $post_ids as $post_id) {
wp_delete_post($post_id);
}
// Clean links
$link_ids = $wpdb->get_col($wpdb->prepare("SELECT link_id FROM {$wpdb->links} WHERE link_owner = %d", $id));
if ($link_ids) {
foreach ($link_ids as $link_id) {
wp_delete_link($link_id);
}
}
restore_current_blog();
}
}
$meta = $wpdb->get_col($wpdb->prepare("SELECT umeta_id FROM {$wpdb->usermeta} WHERE user_id = %d", $id));
foreach ($meta as $mid) {
delete_metadata_by_mid('user', $mid);
}
$wpdb->delete($wpdb->users, array('ID' => $id));
clean_user_cache($user);
/** This action is documented in wp-admin/includes/user.php */
do_action('deleted_user', $id);
return true;
}
示例9: xt_new_tixian
function xt_new_tixian($tixiandata)
{
$tixiandata['user_id'] = (int) $tixiandata['user_id'];
$user = new WP_User($tixiandata['user_id']);
$account_field = XT_USER_ALIPAY;
$account = $user->{$account_field};
$account_name_field = XT_USER_ALIPAY_NAME;
$account_name = $user->{$account_name_field};
if ($user->exists() && !empty($account) && !empty($account_name)) {
global $wpdb;
$old = $wpdb->get_row('SELECT * FROM ' . XT_TABLE_TIXIAN . ' WHERE user_id=' . $user->ID . ' AND status=0');
//审核中
if (!empty($old)) {
//累加到未审核的
return $wpdb->update(XT_TABLE_TIXIAN, array('cash' => (double) $old->cash + (double) $tixiandata['cash'], 'jifen' => intval($old->jifen) + intval($tixiandata['jifen'])), array('id' => $old->id));
} else {
$cashback = (int) xt_fanxian_cashback();
if ((double) $tixiandata['cash'] + intval($tixiandata['jifen']) * 100 < $cashback) {
return 0;
}
$tixiandata['status'] = 0;
$tixiandata['cash'] = (double) $tixiandata['cash'];
$tixiandata['jifen'] = intval($tixiandata['jifen']);
$tixiandata['freeze'] = 0;
$tixiandata['freeze_jifen'] = 0;
$tixiandata['account'] = $account;
$tixiandata['account_name'] = $account_name;
$tixiandata['content'] = isset($tixiandata['content']) ? $tixiandata['content'] : '';
$tixiandata['create_time'] = current_time('mysql');
$tixiandata['update_time'] = current_time('mysql');
return xt_insert_tixian($tixiandata);
}
}
}
示例10: ajax_deleteAdminUser_callback
/**
* @return array
*/
public static function ajax_deleteAdminUser_callback()
{
/** @var wpdb $wpdb */
global $wpdb;
$issueID = absint(!empty($_POST['issueID']) ? $_POST['issueID'] : 0);
$wfIssues = new wfIssues();
$issue = $wfIssues->getIssueByID($issueID);
if (!$issue) {
return array('errorMsg' => "We could not find that issue in our database.");
}
$data = $issue['data'];
if (empty($data['userID'])) {
return array('errorMsg' => "We could not find that user in the database.");
}
$user = new WP_User($data['userID']);
if (!$user->exists()) {
return array('errorMsg' => "We could not find that user in the database.");
}
$userLogin = $user->user_login;
if (is_multisite() && strcasecmp($user->user_email, get_site_option('admin_email')) === 0) {
return array('errorMsg' => "This user's email is the network admin email. It will need to be changed before deleting this user.");
}
if (is_multisite()) {
revoke_super_admin($data['userID']);
}
wp_delete_user($data['userID']);
if (is_multisite()) {
$wpdb->delete($wpdb->users, array('ID' => $data['userID']));
}
$wfIssues->deleteIssue($issueID);
return array('ok' => 1, 'user_login' => $userLogin);
}
示例11: user_can
/**
* Whether a particular user has capability or role.
*
* @since 3.1.0
*
* @param int|object $user User ID or object.
* @param string $capability Capability or role name.
* @return bool
*/
function user_can( $user, $capability ) {
if ( ! is_object( $user ) )
$user = new WP_User( $user );
if ( ! $user || ! $user->exists() )
return false;
$args = array_slice( func_get_args(), 2 );
$args = array_merge( array( $capability ), $args );
return call_user_func_array( array( &$user, 'has_cap' ), $args );
}
示例12: unset
function test_revoked_super_admin_is_deleted()
{
if (isset($GLOBALS['super_admins'])) {
$old_global = $GLOBALS['super_admins'];
unset($GLOBALS['super_admins']);
}
$user_id = $this->factory->user->create();
grant_super_admin($user_id);
revoke_super_admin($user_id);
wpmu_delete_user($user_id);
$user = new WP_User($user_id);
$this->assertFalse($user->exists(), 'WP_User->exists');
if (isset($old_global)) {
$GLOBALS['super_admins'] = $old_global;
}
}
示例13: sanitize_options
/**
* Sanitize new settings field before saving
*
* @param array|string $input Passed input values to sanitize
* @return array|string Sanitized input fields
*/
public function sanitize_options($input)
{
$new_input['caps'] = empty($input['caps']) ? 0 : 1;
$new_input['only'] = empty($input['only']) ? 0 : 1;
$user = new WP_User($input['default']);
$new_input['default'] = $user->exists() ? $input['default'] : '';
return $new_input;
}
示例14: explode
function verify_xml_rpc_signature()
{
if ($this->xmlrpc_verification) {
return $this->xmlrpc_verification;
}
// It's not for us
if (!isset($_GET['token']) || empty($_GET['signature'])) {
return false;
}
@(list($token_key, $version, $user_id) = explode(':', $_GET['token']));
if (empty($token_key) || empty($version) || strval(JETPACK__API_VERSION) !== $version) {
return false;
}
if ('0' === $user_id) {
$token_type = 'blog';
$user_id = 0;
} else {
$token_type = 'user';
if (empty($user_id) || !ctype_digit($user_id)) {
return false;
}
$user_id = (int) $user_id;
$user = new WP_User($user_id);
if (!$user || !$user->exists()) {
return false;
}
}
$token = Jetpack_Data::get_access_token($user_id);
if (!$token) {
return false;
}
if (0 !== strpos($token->secret, "{$token_key}.")) {
return false;
}
require_once JETPACK__PLUGIN_DIR . 'class.jetpack-signature.php';
$jetpack_signature = new Jetpack_Signature($token->secret, (int) Jetpack_Options::get_option('time_diff'));
if (isset($_POST['_jetpack_is_multipart'])) {
$post_data = $_POST;
$file_hashes = array();
foreach ($post_data as $post_data_key => $post_data_value) {
if (0 !== strpos($post_data_key, '_jetpack_file_hmac_')) {
continue;
}
$post_data_key = substr($post_data_key, strlen('_jetpack_file_hmac_'));
$file_hashes[$post_data_key] = $post_data_value;
}
foreach ($file_hashes as $post_data_key => $post_data_value) {
unset($post_data["_jetpack_file_hmac_{$post_data_key}"]);
$post_data[$post_data_key] = $post_data_value;
}
ksort($post_data);
$body = http_build_query(stripslashes_deep($post_data));
} elseif (is_null($this->HTTP_RAW_POST_DATA)) {
$body = file_get_contents('php://input');
} else {
$body = null;
}
$signature = $jetpack_signature->sign_current_request(array('body' => is_null($body) ? $this->HTTP_RAW_POST_DATA : $body));
if (!$signature) {
return false;
} else {
if (is_wp_error($signature)) {
return $signature;
} else {
if ($signature !== $_GET['signature']) {
return false;
}
}
}
$timestamp = (int) $_GET['timestamp'];
$nonce = stripslashes((string) $_GET['nonce']);
if (!$this->add_nonce($timestamp, $nonce)) {
return false;
}
$this->xmlrpc_verification = array('type' => $token_type, 'user_id' => $token->external_user_id);
return $this->xmlrpc_verification;
}
示例15: array
function test_page_meta_caps() {
// simple tests for some common meta capabilities
// Make our author
$author = new WP_User( $this->factory->user->create( array( 'role' => 'author' ) ) );
// make a page
$page = $this->factory->post->create( array( 'post_author' => $author->ID, 'post_type' => 'page' ) );
// the author of the page
$this->assertTrue($author->exists(), "Problem getting user " . $author->ID);
// add some other users
$admin = new WP_User( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
$author_2 = new WP_User( $this->factory->user->create( array( 'role' => 'author' ) ) );
$editor = new WP_User( $this->factory->user->create( array( 'role' => 'editor' ) ) );
$contributor = new WP_User( $this->factory->user->create( array( 'role' => 'contributor' ) ) );
// administrators, editors and the post owner can edit it
$this->assertTrue($admin->has_cap('edit_page', $page));
$this->assertTrue($editor->has_cap('edit_page', $page));
// other authors and contributors can't
$this->assertFalse($author->has_cap('edit_page', $page));
$this->assertFalse($author_2->has_cap('edit_page', $page));
$this->assertFalse($contributor->has_cap('edit_page', $page));
// administrators, editors and the post owner can delete it
$this->assertTrue($admin->has_cap('delete_page', $page));
$this->assertTrue($editor->has_cap('delete_page', $page));
// other authors and contributors can't
$this->assertFalse($author->has_cap('delete_page', $page));
$this->assertFalse($author_2->has_cap('delete_page', $page));
$this->assertFalse($contributor->has_cap('delete_page', $page));
}