예제 #1
0
/**
 * Perform any post-login operations
 *
 * Checks if the user has been protected by an earlier
 * version of the Rublon plugin
 *
 * @param string $user_login
 * @param WP_User $user
 */
function rublon2factor_wp_login($user_login, $user)
{
    if (RublonHelper::isUserSecured($user) && !RublonHelper::isUserAuthenticated($user)) {
        $msg_meta = get_user_meta(RublonHelper::getUserId($user), RublonHelper::RUBLON_META_AUTH_CHANGED_MSG, true);
        if ($msg_meta === '') {
            $msg_meta = -1;
        } else {
            $msg_meta = (int) $msg_meta;
        }
        if ($msg_meta > 8) {
            delete_user_meta(RublonHelper::getUserId($user), RublonHelper::RUBLON_META_AUTH_CHANGED_MSG);
            RublonHelper::disconnectRublon2Factor($user);
        } else {
            $msg_meta++;
            if ($msg_meta % 3 == 0) {
                RublonHelper::setMessage('AUTHENTICATION_TYPE_CHANGED', 'updated', 'POSTL');
            }
            update_user_meta(RublonHelper::getUserId($user), RublonHelper::RUBLON_META_AUTH_CHANGED_MSG, $msg_meta);
        }
    }
}
예제 #2
0
/**
 * Add the Rublon icon and menu to the toolbar
 * 
 */
function rublon2factor_modify_admin_toolbar()
{
    global $wp_admin_bar;
    $current_user = wp_get_current_user();
    if (RublonHelper::isSiteRegistered() && RublonHelper::isUserAuthenticated($current_user) && is_object($wp_admin_bar)) {
        // add a Rublon icon to the my-account node
        $my_account = $wp_admin_bar->get_node('my-account');
        if (is_object($my_account) && property_exists($my_account, 'title')) {
            $my_account->title = $my_account->title . '<img id="rublon-toolbar-logo" class="rublon-image" src="' . RUBLON2FACTOR_PLUGIN_URL . '/assets/images/rublon_logo_32x32.png' . '" />';
            $wp_admin_bar->remove_node('my-account');
            $wp_admin_bar->add_node($my_account);
        }
        // remove all my-account subnodes except user-info
        $nodes = $wp_admin_bar->get_nodes();
        if (is_array($nodes)) {
            $removed_nodes = array();
            foreach ($nodes as $node) {
                if (!empty($node->title) && !empty($node->parent) && !empty($node->id) && $node->parent == 'user-actions' && $node->id != 'user-info') {
                    array_push($removed_nodes, $node);
                    $wp_admin_bar->remove_node($node->id);
                }
            }
            // add Rublon node
            $wp_admin_bar->add_node(array('id' => 'rublon', 'title' => __('Protected by Rublon', 'rublon'), 'href' => admin_url(RublonHelper::WP_RUBLON_PAGE), 'parent' => 'user-actions'));
            // restore all removed nodes
            foreach ($removed_nodes as $node) {
                $wp_admin_bar->add_node($node);
            }
        }
    }
}