本文整理汇总了PHP中wp_set_current_user函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_set_current_user函数的具体用法?PHP wp_set_current_user怎么用?PHP wp_set_current_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_set_current_user函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: login
/**
* custom log in functionality, from custom log in page
*/
static function login()
{
if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], 'login')) {
return;
}
if (is_email($_POST['email'])) {
$user = get_user_by('email', $_POST['email']);
if (empty($user)) {
Kanban_Flash::flash(__('Whoops! We can\'t find an account for that email address.', 'kanban'), 'danger');
wp_redirect($_POST['_wp_http_referer']);
exit;
}
} else {
$user = get_user_by('login', $_POST['email']);
if (empty($user)) {
Kanban_Flash::flash(__('Whoops! We can\'t find an account for that username.', 'kanban'), 'danger');
wp_redirect($_POST['_wp_http_referer']);
exit;
}
}
$creds = array();
$creds['user_login'] = $user->user_login;
$creds['user_password'] = $_POST['password'];
$creds['remember'] = true;
$user = wp_signon($creds, false);
if (is_wp_error($user)) {
Kanban_Flash::flash(__('Whoops! That password is incorrect for this email address.', 'kanban'), 'danger');
wp_redirect($_POST['_wp_http_referer']);
exit;
}
wp_set_current_user($user->ID);
wp_set_auth_cookie($user->ID);
wp_redirect(sprintf('%s/%s/board', site_url(), Kanban::$slug));
exit;
}
开发者ID:gigabyte1977,项目名称:kanban,代码行数:38,代码来源:class-user.php
示例2: force_ssl_cookie
function force_ssl_cookie($errors, $user_id)
{
if (empty($errors)) {
wp_set_auth_cookie($user_id, true, true);
wp_set_current_user($user_id);
}
}
开发者ID:vilmark,项目名称:vilmark_main,代码行数:7,代码来源:gateway.authorizenetarb.php
示例3: setUp
public function setUp()
{
parent::setUp();
$author_id = $this->factory->user->create(array('role' => 'administrator'));
wp_set_current_user($author_id);
require_once dirname(__FILE__) . '/../../../modules/after-the-deadline.php';
}
开发者ID:atrus1701,项目名称:jetpack,代码行数:7,代码来源:test_class.after_the_deadline.php
示例4: tearDown
public function tearDown()
{
if (get_current_user_id() != $this->current_user) {
wp_delete_user(get_current_user_id());
}
wp_set_current_user($this->current_user);
}
开发者ID:stevenslack,项目名称:wordpress-fieldmanager,代码行数:7,代码来源:test-fieldmanager-term-meta.php
示例5: otl_authenticate_one_time_login
/**
* Process one time login
*
* @since 1.0.0
*
* @return void
*/
function otl_authenticate_one_time_login()
{
// No need to run if not a singular query for the one time login
if (!is_single()) {
return;
}
// No need to run if not a onetimelogin post
global $post;
if ('onetimelogin' !== $post->post_type) {
return;
}
$user_id = get_post_meta(get_the_ID(), 'otl_user', true);
$valid_user = get_userdata($user_id) ? true : false;
$login_uses = get_post_meta(get_the_ID(), 'otl_times_used', true);
// If the one time login is unused and the user is valid, log in
if ('0' === $login_uses && $valid_user) {
// Log in
wp_clear_auth_cookie();
wp_set_current_user($user_id);
wp_set_auth_cookie($user_id);
// Update some meta for logging and to prevent multiple uses
update_post_meta(get_the_ID(), 'otl_times_used', '1');
update_post_meta(get_the_ID(), 'otl_datetime_used', current_time('mysql'));
// Redirect to wp-admin
wp_safe_redirect(user_admin_url());
exit;
} else {
wp_redirect(home_url());
exit;
}
return;
}
开发者ID:ryanduff,项目名称:one-time-login,代码行数:39,代码来源:login-handler.php
示例6: setUp
public function setUp()
{
parent::setUp();
global $wpdb;
// Current a test user and make them current.
$tester = get_user_by('email', '[email protected]');
if (!$tester) {
$tester_id = wp_create_user('tester', 'test123', '[email protected]');
} else {
$tester_id = $tester->ID;
}
wp_set_current_user($tester_id);
// Get the database.
$this->wpdb = $wpdb;
// Prevent parent from enforcing TEMPORARY tables.
remove_filter('query', array($this, '_create_temporary_tables'));
remove_filter('query', array($this, '_drop_temporary_tables'));
// Activate.
do_action('activate_tabulate/tabulate.php');
// Create some testing tables and link them together.
$this->wpdb->query('DROP TABLE IF EXISTS `test_table`');
$this->wpdb->query('CREATE TABLE `test_table` (' . ' id INT(10) AUTO_INCREMENT PRIMARY KEY,' . ' title VARCHAR(100) NOT NULL,' . ' description TEXT NULL,' . ' active BOOLEAN NULL DEFAULT TRUE,' . ' a_date DATE NULL,' . ' a_year YEAR NULL,' . ' type_id INT(10) NULL DEFAULT NULL,' . ' widget_size DECIMAL(10,2) NOT NULL DEFAULT 5.6,' . ' ranking INT(3) NULL DEFAULT NULL' . ');');
$this->wpdb->query('DROP TABLE IF EXISTS `test_types`');
$this->wpdb->query('CREATE TABLE `test_types` (' . ' id INT(10) AUTO_INCREMENT PRIMARY KEY,' . ' title VARCHAR(100) NOT NULL' . ');');
$this->wpdb->query('ALTER TABLE `test_table` ' . ' ADD FOREIGN KEY ( `type_id` )' . ' REFERENCES `test_types` (`id`)' . ' ON DELETE CASCADE ON UPDATE CASCADE;');
$this->db = new WordPress\Tabulate\DB\Database($this->wpdb);
}
开发者ID:kcdipesh,项目名称:tabulate,代码行数:27,代码来源:TestBase.php
示例7: setUp
public function setUp()
{
parent::setUp();
// Create a new user then add 'edit_theme_options' capability
$user_id = $this->factory->user->create();
$user = wp_set_current_user($user_id);
$user->add_cap('edit_theme_options');
// Pretending in customize page.
if (!isset($_REQUEST['wp_customize'])) {
$_REQUEST['wp_customize'] = 'on';
}
if (!class_exists('WP_Customize_Manager')) {
require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
}
// Init Customize class.
if (!isset($GLOBALS['wp_customize'])) {
$GLOBALS['wp_customize'] = new WP_Customize_Manager();
}
// Removes any registered actions (in which some themes use) and re-register action
// from this plugin.
remove_all_actions('customize_register');
add_action('customize_register', array('Widget_Customizer', 'customize_register'));
set_current_screen('customize');
do_action('customize_register', $GLOBALS['wp_customize']);
}
开发者ID:niceit,项目名称:rockets,代码行数:25,代码来源:test-widget-customizer.php
示例8: login
static function login()
{
if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], 'login')) {
return;
}
$user_by_email = get_user_by_email($_POST['email']);
if (empty($user_by_email)) {
Kanban::$instance->flash->add('danger', 'Whoops! We can\'t find an account for that email address.');
wp_redirect($_POST['_wp_http_referer']);
exit;
}
$creds = array();
$creds['user_login'] = $user_by_email->user_login;
$creds['user_password'] = $_POST['password'];
$creds['remember'] = true;
$user = wp_signon($creds, false);
if (is_wp_error($user)) {
Kanban::$instance->flash->add('danger', 'Whoops! That password is incorrect for this email address.');
wp_redirect($_POST['_wp_http_referer']);
exit;
}
wp_set_current_user($user->ID);
wp_set_auth_cookie($user->ID);
wp_redirect(sprintf('/%s/board', Kanban::$slug));
exit;
}
开发者ID:vlood,项目名称:kanban-wordpress-plugin,代码行数:26,代码来源:class-user.php
示例9: init
/**
* Initializes after VAA is enabled
*
* @since 1.6
* @access public
* @return void
*/
public function init()
{
// Reset view to default if something goes wrong, example: http://www.your.domain/wp-admin/?reset-view
if (isset($_GET['reset-view'])) {
$this->reset_view();
}
// Clear all user views, example: http://www.your.domain/wp-admin/?reset-all-views
if (isset($_GET['reset-all-views'])) {
$this->reset_all_views();
}
// Admin selector ajax return
add_action('wp_ajax_view_admin_as', array($this, 'ajax_view_admin_as'));
//add_action( 'wp_ajax_nopriv_update_view_as', array( $this, 'ajax_update_view_as' ) );
// Get the current view (returns false if not found)
$this->store->set_viewAs($this->get_view());
if ($this->store->get_viewAs()) {
// Change current user object so changes can be made on various screen settings
// wp_set_current_user() returns the new user object
if ($this->store->get_viewAs('user')) {
$this->store->set_selectedUser(wp_set_current_user($this->store->get_viewAs('user')));
}
if ($this->store->get_viewAs('role') || $this->store->get_viewAs('caps')) {
// Change the capabilities (map_meta_cap is better for compatibility with network admins)
add_filter('map_meta_cap', array($this, 'map_meta_cap'), 999999999, 4);
}
}
}
开发者ID:JoryHogeveen,项目名称:view-admin-as,代码行数:34,代码来源:class-view.php
示例10: set_up_0_4_0_test_posts
function set_up_0_4_0_test_posts()
{
update_option('wp_gistpen_version', '0.3.1');
register_post_type('gistpens', array());
register_taxonomy('language', array('gistpens'));
foreach (Language::$supported as $lang => $slug) {
$result = wp_insert_term($lang, 'language', array('slug' => $slug));
if (is_wp_error($result)) {
throw new Exception("Failed to insert term.");
}
}
$terms = get_terms('language', 'hide_empty=0');
foreach ($terms as $term) {
$languages[] = $term->slug;
}
$num_posts = count($languages);
$this->gistpens = $this->factory->post->create_many($num_posts, array('post_type' => 'gistpens', 'post_status' => 'publish'), array('post_title' => new WP_UnitTest_Generator_Sequence('Post title %s'), 'post_name' => new WP_UnitTest_Generator_Sequence('Post title %s'), 'post_content' => new WP_UnitTest_Generator_Sequence('Post content %s')));
foreach ($this->gistpens as $gistpen_id) {
// Pick a random language
$num_posts = $num_posts - 1;
$lang_num = rand(0, $num_posts);
// Get the language's id
$lang_slug = $languages[$lang_num];
// Remove the language and reindex the languages array
unset($languages[$lang_num]);
$languages = array_values($languages);
// Give the post a description
update_post_meta($gistpen_id, '_wpgp_gistpen_description', 'This is a description of the Gistpen.');
// Give the post the language
wp_set_object_terms($gistpen_id, $lang_slug, 'language', false);
// Create and set up the user
$user_id = $this->factory->user->create(array('role' => 'administrator'));
wp_set_current_user($user_id);
}
}
开发者ID:petermac-,项目名称:WP-Gistpen,代码行数:35,代码来源:test-migration.php
示例11: setUp
public function setUp()
{
parent::setUp();
$user_id = $this->factory->user->create(array('role' => 'subscriber'));
wp_set_current_user($user_id);
$this->order = APP_Order_Factory::create();
}
开发者ID:kalushta,项目名称:darom,代码行数:7,代码来源:test_order.php
示例12: sso_check
/**
Plugin Name: SSO
Author: Garth Mortensen, Mike Hansen
Version: 0.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
function sso_check()
{
if (!isset($_GET['salt']) || !isset($_GET['nonce']) || !isset($_GET['user'])) {
sso_req_login();
}
if (sso_check_blocked()) {
sso_req_login();
}
$nonce = esc_attr($_GET['nonce']);
$salt = esc_attr($_GET['salt']);
$user = esc_attr($_GET['user']);
$hash = base64_encode(hash('sha256', $nonce . $salt, false));
$hash = substr($hash, 0, 64);
if (get_transient('sso_token') == $hash) {
if (is_email($user)) {
$user = get_user_by('email', $user);
} else {
$user = get_user_by('id', (int) $user);
}
if (is_a($user, 'WP_User')) {
wp_set_current_user($user->ID, $user->user_login);
wp_set_auth_cookie($user->ID);
do_action('wp_login', $user->user_login);
delete_transient('sso_token');
wp_safe_redirect(admin_url());
} else {
sso_req_login();
}
} else {
sso_add_failed_attempt();
sso_req_login();
}
die;
}
开发者ID:annbransom,项目名称:techishowl_prod_backup,代码行数:41,代码来源:sso.php
示例13: setUp
/**
* Setup each test.
*
* @since 0.1.0
*/
public function setUp()
{
global $wpdb;
parent::setUp();
$wpdb->suppress_errors();
$admin_id = $this->factory->user->create(array('role' => 'administrator'));
$this->factory->blog->create_many(2, array('user_id' => $admin_id));
$sites = ep_get_sites();
$indexes = array();
foreach ($sites as $site) {
switch_to_blog($site['blog_id']);
ep_delete_index();
ep_put_mapping();
$indexes[] = ep_get_index_name();
restore_current_blog();
}
ep_delete_network_alias();
ep_create_network_alias($indexes);
wp_set_current_user($admin_id);
EP_WP_Query_Integration::factory()->setup();
$this->setup_test_post_type();
/**
* Most of our search test are bundled into core tests for legacy reasons
*/
ep_activate_module('search');
EP_Modules::factory()->setup_modules();
}
开发者ID:10up,项目名称:elasticpress,代码行数:32,代码来源:test-multisite.php
示例14: get_currentuserinfo
function get_currentuserinfo()
{
// Use HTTP auth instead of cookies
global $current_user;
if (!empty($current_user)) {
return;
}
// Some apache versions prepend "REDIRECT_" to server variable name, according to http://www.besthostratings.com/articles/http-auth-php-cgi.html
if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) {
$_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
}
// Workaround for HTTP Authentication with PHP running as CGI (htaccess rule copies authentication data into HTTP_AUTHORIZATION)
if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
$ha = base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6));
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', $ha);
unset($ha);
}
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || !wp_login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) {
header('WWW-Authenticate: Basic realm="' . get_bloginfo('name') . '"');
header('HTTP/1.0 401 Unauthorized');
scoper_load_textdomain();
// otherwise this is only loaded for wp-admin
die(__('Access denied: Incorrect credentials supplied.', 'scoper'));
}
$user_login = $_SERVER['PHP_AUTH_USER'];
wp_set_current_user(0, $user_login);
}
开发者ID:joostrijneveld,项目名称:cscircles-wp-content,代码行数:27,代码来源:feed-interceptor_rs.php
示例15: wats_admin_edit_user_profile
function wats_admin_edit_user_profile()
{
global $wpdb, $user_id, $current_user, $wats_settings;
if (!current_user_can('administrator')) {
return;
}
$old_user = $current_user;
wp_set_current_user($user_id);
$wats_capabilities_table = wats_init_capabilities_table();
echo '<h3>' . __('Ticket system capabilities', 'WATS') . '</h3><table class="form-table"><tbody>';
foreach ($wats_capabilities_table as $key => $value) {
$right = current_user_can($key) ? 1 : 0;
echo '<tr><th><label>' . $value . '</label></th><td><select name="' . $key . '" id="' . $key . '" size=1>';
echo '<option value="yes"';
if ($right == 1) {
echo ' selected';
}
echo '>' . __('Yes', 'WATS') . '</option><option value="no"';
if ($right == 0) {
echo ' selected';
}
echo '>' . __('No', 'WATS') . '</option></td></tr>';
}
echo '</tbody></table><br />';
wp_set_current_user($old_user->ID);
return;
}
开发者ID:adisonc,项目名称:MaineLearning,代码行数:27,代码来源:wats-profile.php
示例16: mm_facebook_connection_process_facebook_actions
function mm_facebook_connection_process_facebook_actions()
{
global $user_ID;
$current_url = mm_facebook_connection_get_current_url();
if (mm_facebook_connection_is_conifgured()) {
if (isset($_GET['mm_unlink_facebook']) && $_GET['mm_unlink_facebook'] == 'true') {
update_user_meta($user_ID, 'mm_facebook_connection_facebook_id', '');
return wp_redirect($current_url);
}
if (isset($_GET['code']) && $_GET['code'] && isset($_GET['mm_facebook_connection']) && $_GET['mm_facebook_connection'] == 'true') {
$data_array = mm_facebook_connection_get_data($_GET['code'], $current_url . '?mm_facebook_connection=true');
if (is_array($data_array) && count($data_array) > 0) {
update_user_meta($user_ID, 'mm_facebook_connection_facebook_id', $data_array['facebook_internal_id']);
return wp_redirect($current_url);
}
}
if (isset($_GET['code']) && $_GET['code'] && isset($_GET['mm_facebook_login']) && $_GET['mm_facebook_login'] == 'true') {
$data_array = mm_facebook_connection_get_data($_GET['code'], $current_url . '?facebook_login=true');
$users_array = get_users(array('meta_key' => 'mm_facebook_connection_facebook_id', 'meta_value' => $data_array['facebook_internal_id']));
if (is_array($users_array) && count($users_array) > 0) {
$user_to_auth_obj = $users_array[0];
if ($user_to_auth_obj) {
wp_set_current_user($user_to_auth_obj->ID, $user_to_auth_obj->user_login);
wp_set_auth_cookie($user_to_auth_obj->ID);
do_action('wp_login', $user_to_auth_obj->user_login);
return wp_redirect(home_url('/'));
}
}
}
}
}
开发者ID:rodrigo-techera,项目名称:MM-Facebook-Connect,代码行数:31,代码来源:mm-facebook-connection.php
示例17: auto_login_new_user
function auto_login_new_user($user_id)
{
wp_set_current_user($user_id);
wp_set_auth_cookie($user_id);
echo 'current user: ' . wp_get_current_user()->user_login;
wp_redirect(home_url() . '/logup?newlog=true');
}
开发者ID:tristanhamel,项目名称:cehavre,代码行数:7,代码来源:functions.php
示例18: testHome
function testHome()
{
$this->factory->post->create_many(8, array('post_type' => 'project'));
$this->assertEquals(0, count(PH_Projects::get_projects()));
wp_set_current_user(1);
$this->assertEquals(8, count(PH_Projects::get_projects()));
}
开发者ID:ramsaylanier,项目名称:blades,代码行数:7,代码来源:test-pm-home.php
示例19: bdn_is_user_auth2
function bdn_is_user_auth2()
{
global $driveService;
$current_user_id = get_current_user_id();
$client = new Google_Client();
$client->setRedirectUri(home_url('/'));
$driveService = new Google_DriveService($client);
$oauth2 = new Google_Oauth2Service($client);
if (!isset($_GET['code']) && (!is_user_logged_in() || ($access_token = get_user_meta($current_user_id, '_google_access_token', true)) && $client->setAccessToken($access_token) && !$client->getAccessToken())) {
header('Location: ' . $client->createAuthUrl());
exit;
}
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$user = $oauth2->userinfo->get();
$new_user = get_user_by('email', $user['email']);
if (!$current_user_id) {
wp_set_current_user($new_user->ID, $new_user->user_login);
wp_set_auth_cookie($new_user->ID);
do_action('wp_login', $new_user->user_login);
} elseif ($new_user->ID == $current_user_id) {
update_user_meta($new_user->ID, '_google_access_token', $client->getAccessToken());
} else {
die('Sorry, please use your BDN account');
}
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
return $driveService;
}
开发者ID:bangordailynews,项目名称:Newsroom-Tools,代码行数:29,代码来源:gapi.php
示例20: setUp
public function setUp()
{
parent::setUp();
$this->client->reset_data();
wp_set_current_user(1);
$this->client->do_sync();
}
开发者ID:elliott-stocks,项目名称:jetpack,代码行数:7,代码来源:test_class.jetpack-sync-updates.php
注:本文中的wp_set_current_user函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论