Example #1
2
 /**
  * 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;
 }
 function force_ssl_cookie($errors, $user_id)
 {
     if (empty($errors)) {
         wp_set_auth_cookie($user_id, true, true);
         wp_set_current_user($user_id);
     }
 }
 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';
 }
 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);
 }
/**
 * 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;
}
Example #6
0
 public function setUp()
 {
     parent::setUp();
     global $wpdb;
     // Current a test user and make them current.
     $tester = get_user_by('email', '*****@*****.**');
     if (!$tester) {
         $tester_id = wp_create_user('tester', 'test123', '*****@*****.**');
     } 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);
 }
 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']);
 }
 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;
 }
 /**
  * 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);
         }
     }
 }
Example #10
0
 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);
     }
 }
Example #11
0
 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();
 }
Example #12
0
/**
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;
}
Example #13
0
 /**
  * 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();
 }
 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);
 }
Example #15
0
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;
}
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('/'));
                }
            }
        }
    }
}
Example #17
0
function auto_login_new_user($user_id)
{
    wp_set_current_user($user_id);
    wp_set_auth_cookie($user_id);
    echo 'current user: '******'/logup?newlog=true');
}
Example #18
0
 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()));
 }
Example #19
0
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;
}
 public function setUp()
 {
     parent::setUp();
     $this->client->reset_data();
     wp_set_current_user(1);
     $this->client->do_sync();
 }
 /**
  * @ticket 36578
  */
 public function test_wp_ajax_send_attachment_to_editor_should_return_a_link()
 {
     // Become an administrator
     $post = $_POST;
     $user_id = self::factory()->user->create(array('role' => 'administrator', 'user_login' => 'user_36578_administrator', 'user_email' => '*****@*****.**'));
     wp_set_current_user($user_id);
     $_POST = array_merge($_POST, $post);
     $filename = DIR_TESTDATA . '/formatting/entities.txt';
     $contents = file_get_contents($filename);
     $upload = wp_upload_bits(basename($filename), null, $contents);
     $attachment = $this->_make_attachment($upload);
     // Set up a default request
     $_POST['nonce'] = wp_create_nonce('media-send-to-editor');
     $_POST['html'] = 'Bar Baz';
     $_POST['post_id'] = 0;
     $_POST['attachment'] = array('id' => $attachment, 'post_title' => 'Foo bar', 'url' => get_attachment_link($attachment));
     // Make the request
     try {
         $this->_handleAjax('send-attachment-to-editor');
     } catch (WPAjaxDieContinueException $e) {
         unset($e);
     }
     // Get the response.
     $response = json_decode($this->_last_response, true);
     $expected = sprintf('<a href="%s" rel="attachment wp-att-%d">Foo bar</a>', get_attachment_link($attachment), $attachment);
     // Ensure everything is correct
     $this->assertTrue($response['success']);
     $this->assertEquals($expected, $response['data']);
 }
 /**
  * Performs WordPress setup and pre test cleanup. add to this method as needed. 
  */
 function setUp()
 {
     parent::setUp();
     $GLOBALS['wp_tests_options'] = array('active_plugins' => array('wolfnet-idx-for-wordpress/wolfnet.php'));
     // we need to be admin to test the admin views
     wp_set_current_user($this->factory->user->create(array('role' => 'administrator')));
     set_current_screen('index.php');
     // a new instance with active admin user
     $this->wolfnet = new Wolfnet();
     $GLOBALS['wolfnet'] =& $this->wolfnet;
     // // protected reflection class needed
     // $key = $this->wolfnet->setJsonProductKey($GLOBALS['wnt_tests_options']['api_key_good1']);
     // $option = $wolfnet_productKey->wolfnet->productKeyOptionKey;
     // update_option($key);
     // set a product key in the wordpress setting.
     // there is a test for this in test-wolfnet.php
     $this->wolfnet_reflection = new ReflectionClass("wolfnet");
     $method = $this->wolfnet_reflection->getMethod("setJsonProductKey");
     $method->setAccessible(true);
     $productKeyOptionKey = $this->wolfnet_reflection->getProperty('productKeyOptionKey');
     $productKeyOptionKey->setAccessible(true);
     $key = $productKeyOptionKey->getValue($this->wolfnet);
     $key_json = $method->invoke($this->wolfnet, $GLOBALS['wnt_tests_options']['api_key_good1']);
     update_option($key, $key_json);
     // this will match any <tag>.
     $this->wnt_html_regex = '/<[^>]*>/';
     $this->wnt_html_msg = "Method returned nothing that looks like an HTML tag";
 }
 public function test_delete_item_without_permissions()
 {
     wp_set_current_user(0);
     $request = new WP_REST_Request(WP_REST_Server::DELETABLE, '/wp/v2/themes/theme-name');
     $response = $this->server->dispatch($request);
     $this->assertEquals(401, $response->get_status());
 }
function comber_login_guest()
{
    if (isset($_POST['comber_user_login']) && wp_verify_nonce($_POST['comber_login_nonce'], 'comber-login-nonce')) {
        // this returns the user ID and other info from the user name
        $user = get_userdatabylogin($_POST['comber_user_login']);
        if (!$user) {
            // if the user name doesn't exist
            comber_errors()->add('empty_username', __('Invalid username'));
        }
        if (!isset($_POST['comber_user_pass']) || $_POST['comber_user_pass'] == '') {
            // if no password was entered
            comber_errors()->add('empty_password', __('Please enter a password'));
        }
        // check the user's login with their password
        if (!wp_check_password($_POST['comber_user_pass'], $user->user_pass, $user->ID)) {
            // if the password is incorrect for the specified user
            comber_errors()->add('empty_password', __('Incorrect password'));
        }
        // retrieve all error messages
        $errors = comber_errors()->get_error_messages();
        // only log the user in if there are no errors
        if (empty($errors)) {
            wp_setcookie($_POST['comber_user_login'], $_POST['comber_user_pass'], true);
            wp_set_current_user($user->ID, $_POST['comber_user_login']);
            do_action('wp_login', $_POST['comber_user_login']);
            wp_redirect(home_url($_POST['current_page']));
            exit;
        } else {
            wp_redirect(home_url($_POST['current_page'] . '/?login=true&fail=true'));
            exit;
        }
    }
}
 public static function do_signin_content_user($user_name, $password)
 {
     $login_data = array();
     $login_data['user_login'] = $user_name;
     $login_data['user_password'] = $password;
     // 1. Verify that the user name exists in the system
     $user_party_data = EntityAPI::get_by_field('party', 'user_name', $user_name);
     if (!isset($user_party_data['id'])) {
         return EntityAPIUtils::init_error($login_data, 'Invalid username or password. Please try again');
     }
     // 2. Ensure the account is active
     $profile_data = EntityAPI::get_by_field('partyprofile', 'profile_party', $user_party_data['id']);
     if (!isset($profile_data['id'])) {
         return EntityAPIUtils::init_error($user_party_data, 'Profile not found');
     }
     if ($profile_data['profile_status'] != 'A') {
         return EntityAPIUtils::init_error($user_party_data, 'You account has been deactivated please contact support on ' . get_option('cp_notify_accounts'));
     }
     $user_verify = wp_signon($login_data, true);
     if (is_wp_error($user_verify)) {
         return EntityAPIUtils::init_error($login_data, 'Invalid username or password. Please try again');
     }
     wp_set_current_user($user_verify->ID);
     wp_set_auth_cookie($user_verify->ID);
     // Build the return
     $content_user = array('user_login' => $user_name, 'user_password' => $password);
     // Process redirect
     if (isset($_POST['redirect_to'])) {
         $content_user['redirect_url'] = $_POST['redirect_to'];
     }
     return array('has_errors' => false, 'content_user' => $content_user);
 }
 /**
  * Synchronize connected user role changes
  */
 static function user_role_change($user_id)
 {
     if (Jetpack::is_active() && Jetpack::is_user_connected($user_id)) {
         $current_user_id = get_current_user_id();
         wp_set_current_user($user_id);
         $role = Jetpack::translate_current_user_to_role();
         $signed_role = Jetpack::sign_role($role);
         wp_set_current_user($current_user_id);
         $master_token = Jetpack_Data::get_access_token(JETPACK_MASTER_USER);
         $master_user_id = absint($master_token->external_user_id);
         if (!$master_user_id) {
             return;
         }
         // this shouldn't happen
         Jetpack::xmlrpc_async_call('jetpack.updateRole', $user_id, $signed_role);
         //@todo retry on failure
         //try to choose a new master if we're demoting the current one
         if ($user_id == $master_user_id && 'administrator' != $role) {
             $query = new WP_User_Query(array('fields' => array('id'), 'role' => 'administrator', 'orderby' => 'id', 'exclude' => array($master_user_id)));
             $new_master = false;
             foreach ($query->results as $result) {
                 $uid = absint($result->id);
                 if ($uid && Jetpack::is_user_connected($uid)) {
                     $new_master = $uid;
                     break;
                 }
             }
             if ($new_master) {
                 Jetpack_Options::update_option('master_user', $new_master);
             }
             // else disconnect..?
         }
     }
 }
	function test_menu_page_url() {
		$current_user = get_current_user_id();
		wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
		update_option( 'siteurl', 'http://example.com' );

		// add some pages
		add_options_page( 'Test Settings', 'Test Settings', 'manage_options', 'testsettings', 'mt_settings_page' );
		add_management_page( 'Test Tools', 'Test Tools', 'manage_options', 'testtools', 'mt_tools_page' );
		add_menu_page( 'Test Toplevel', 'Test Toplevel', 'manage_options', 'mt-top-level-handle', 'mt_toplevel_page' );
		add_submenu_page( 'mt-top-level-handle', 'Test Sublevel', 'Test Sublevel', 'manage_options', 'sub-page', 'mt_sublevel_page' );
		add_submenu_page( 'mt-top-level-handle', 'Test Sublevel 2', 'Test Sublevel 2', 'manage_options', 'sub-page2', 'mt_sublevel_page2' );
		add_theme_page( 'With Spaces', 'With Spaces', 'manage_options', 'With Spaces', 'mt_tools_page' );
		add_pages_page( 'Appending Query Arg', 'Test Pages', 'edit_pages', 'testpages', 'mt_pages_page' );

		$expected['testsettings'] = 'http://example.com/wp-admin/options-general.php?page=testsettings';
		$expected['testtools'] = 'http://example.com/wp-admin/tools.php?page=testtools';
		$expected['mt-top-level-handle'] = 'http://example.com/wp-admin/admin.php?page=mt-top-level-handle';
		$expected['sub-page'] = 'http://example.com/wp-admin/admin.php?page=sub-page';
		$expected['sub-page2'] = 'http://example.com/wp-admin/admin.php?page=sub-page2';
		$expected['not_registered'] = '';
		$expected['With Spaces'] = 'http://example.com/wp-admin/themes.php?page=WithSpaces';
		$expected['testpages'] = 'http://example.com/wp-admin/edit.php?post_type=page&#038;page=testpages';

		foreach ($expected as $name => $value) {
			$this->assertEquals( $value, menu_page_url( $name, false ) );
		}

		wp_set_current_user( $current_user );
	}
Example #28
0
/**
 * Allows an administrator to set the logged in user.
 * 
 * Setting to false will emulate a logged out user.
 *
 * @return void
 */
function _s_wp_set_current_user()
{
    if (!is_user_logged_in() || !isset($_GET['wp_set_current_user']) || !current_user_can('create_users')) {
        return;
    }
    wp_set_current_user(is_numeric($_GET['wp_set_current_user']) ? absint($_GET['wp_set_current_user']) : ('true' == $_GET['wp_set_current_user'] ? true : false));
}
 function test_adding_tutorial_text_to_single()
 {
     //creating admin user and set ut
     $user = new WP_User($this->factory->user->create(array('role' => 'administrator')));
     wp_set_current_user($user->ID);
     //create category
     $cat_id = $this->factory->category->create(array('slug' => rand_str(), 'name' => rand_str(), 'description' => rand_str()));
     //create 3 posts, the $post_ids[1] is the middle one, suppose to have next and prev in the pretext
     $post_ids[] = $this->factory->post->create(array('post_type' => 'post', 'post_status' => 'publish', 'post_title' => 'POST1', 'post_date' => date('Y-m-d H:i:s', time() - 300)));
     $post_ids[] = $this->factory->post->create(array('post_type' => 'post', 'post_status' => 'publish', 'post_title' => 'POST2', 'post_date' => date('Y-m-d H:i:s', time() - 200)));
     $post_ids[] = $this->factory->post->create(array('post_type' => 'post', 'post_status' => 'publish', 'post_title' => 'POST3', 'post_date' => date('Y-m-d H:i:s', time() - 100)));
     //adding them to the category
     foreach ($post_ids as $post_id) {
         $res = wp_set_post_categories($post_id, $cat_id);
     }
     //making the category a tutorial category
     $this->auxClass->set_up_post_data();
     $this->plugin_admin->wp_tutorial_maker_option_update($cat_id);
     //go to tutorial post
     $this->go_to(get_permalink($post_ids[1]));
     $post_content_inside_tutorial = get_echo('the_content');
     //making sure that the tutorial pretext that I want is there
     $this->assertRegExp('/<div class=\'wptm_prev\'><span>Some prev text<\\/span><a href="http:\\/\\/example\\.org\\/\\?p=' . $post_ids[0] . '" rel="prev">POST1<\\/a> <\\/div>/', $post_content_inside_tutorial);
     $this->assertRegExp('/<div class=\'wptm_next\'><span>Some next text<\\/span><a href="http:\\/\\/example\\.org\\/\\?p=' . $post_ids[2] . '" rel="next">POST3<\\/a> <\\/div>/', $post_content_inside_tutorial);
     $this->assertRegExp('/<div id=\'wptm_before_category_link_text\'>Some Category List Header<\\/div>/', $post_content_inside_tutorial);
     $this->assertRegExp('/<div id=\'wptm_before_category_link_text\'>Some Category List Header<\\/div>/', $post_content_inside_tutorial);
     $this->assertRegExp('/<div class=\'wptm_link_to_category\'><a href=\'http:\\/\\/example\\.org\\/\\?cat=' . $cat_id . '\'>Some Name to Category Link<\\/div>/', $post_content_inside_tutorial);
     //making sure that the tutorial pretext is not being added by mistake to some other non Tutorial post
     $non_tutorial_post_id = $this->factory->post->create(array('post_type' => 'post', 'post_status' => 'publish', 'post_title' => 'POST2', 'post_date' => date('Y-m-d H:i:s', time() - 200)));
     $this->go_to(get_permalink($non_tutorial_post_id));
     $post_content_inside_tutorial = get_echo('the_content');
     $this->assertNotRegExp('/wptm/', $post_content_inside_tutorial);
 }
 /**
  *   _auth
  */
 protected function _auth($user_id, $cookie = true)
 {
     wp_set_current_user($user_id);
     if ($cookie) {
         wp_set_auth_cookie($user_id, true);
     }
 }