Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSO to Show Service Connection in Dashboard #73

Closed
jaswrks opened this issue Dec 14, 2014 · 3 comments
Closed

SSO to Show Service Connection in Dashboard #73

jaswrks opened this issue Dec 14, 2014 · 3 comments
Assignees
Labels
Milestone

Comments

@jaswrks
Copy link

@jaswrks jaswrks commented Dec 14, 2014

The SSO integration should show an indication of which SSO service is connected to a user's account from the Dashboard so that site owners can know what to tell a user if they have trouble accessing their account.

2014-12-14_00-27-10

@jaswrks
Copy link
Author

@jaswrks jaswrks commented Oct 28, 2015

Overview

There are very few filters available for us to use in the edit screen for a user. However, adding additional custom columns to the overall list of users is quite easy. So let's start our work on this issue by taking the path of least resistance. The instructions below will add a new column to the list of users whenever you have SSO enabled in Comment Mail.

Next Actions (Pro Version Only)

  • New feature branch in the websharks/comment-mail-pro repo.

  • After this line add the following:

    $user_sso_services = get_user_option(__NAMESPACE__.'_sso_services');
    $user_sso_services = is_array($user_sso_services) ? $user_sso_services : array();
    $user_sso_services = array_unique(array_merge($user_sso_services, array($service)));
    update_user_option($user_id, __NAMESPACE__.'_sso_services', $user_sso_services);
  • After this line add the following:

    add_filter('manage_users_columns', array($this, 'manage_users_columns'), 10, 1);
    add_filter('manage_users_custom_column', array($this, 'manage_users_custom_column'), 10, 3);

    Tip: Take note of the last argument to add_filter() and see this article which explains why we use 1 for the first filter, and 3 for the second filter. In the manage_users_custom_column filter we are expecting to receive 3 arguments.

  • After this line add the following:

    /**
    * Adds columns to the list of users.
    *
    * @since 15xxxx Enhancing users list.
    *
    * @attaches-to `manage_users_columns` filter.
    *
    * @param array $columns Existing columns passed in by filter.
    *
    * @return array Filtered columns.
    */
    public function manage_users_columns(array $columns)
    {
      $user_columns = &$this->static_key(__FUNCTION__);
      $user_columns = new user_columns();
    
      return $user_columns->filter($columns);
    }
    
    /**
    * Fills columns in the list of users.
    *
    * @since 15xxxx Enhancing users list.
    *
    * @attaches-to `manage_users_custom_column` filter.
    *
    * @param mixed $value Existing column value passed in by filter.
    * @param string $column Column name; passed in by filter.
    * @param int|string $user_id User ID; passed in by filter.
    *
    * @return mixed Filtered column value.
    */
    public function manage_users_custom_column($value, $column, $user_id)
    {
      if(!($user_columns = &$this->static_key('manage_users_columns')))
        return $value; // Not possible to fill; no class instance.
    
      return $user_columns->maybe_fill($value, $column, $user_id);
    }
  • Add a new class file in this directory with the filename: user-columns.php

    <?php
    /**
    * User Columns
    *
    * @since 15xxxx Adding custom user columns.
    * @copyright WebSharks, Inc. <http://www.websharks-inc.com>
    * @license GNU General Public License, version 3
    */
    namespace comment_mail // Root namespace.
    {
      if(!defined('WPINC')) // MUST have WordPress.
        exit('Do NOT access this file directly: '.basename(__FILE__));
    
      if(!class_exists('\\'.__NAMESPACE__.'\\user_columns'))
      {
        /**
         * User Columns
         *
         * @since 15xxxx Adding custom user columns.
         */
        class user_columns extends abs_base
        {
          /**
           * Class constructor.
           *
           * @since 15xxxx Adding custom user columns.
           */
          public function __construct()
          {
            parent::__construct();
          }
    
          /**
           * Filter (and add) user columns.
           *
           * @since 15xxxx Adding custom user columns.
           *
           * @param array $columns Existing columns.
           *
           * @return array Filtered columns.
           */
          public function filter(array $columns)
          {
            if(!$this->plugin->options['enable'])
              return $columns; // Not applicable.
    
            if($this->plugin->options['sso_enable'])
              $columns[__NAMESPACE__.'_sso_services'] = __('SSO Service', $this->plugin->text_domain);
    
            return $columns;
          }
    
          /**
           * Maybe fill custom user columns.
           *
           * @since 15xxxx Adding custom user columns.
           *
           * @param mixed $value Existing column value.
           * @param string $column Column name.
           * @param int|string $user_id User ID.
           *
           * @return mixed Filtered value.
           */
          public function maybe_fill($value, $column, $user_id)
          {
            if ($column === __NAMESPACE__.'_sso_services') {
              $user_sso_services = get_user_option(__NAMESPACE__.'_sso_services', $user_id);
              $user_sso_services = is_array($user_sso_services) ? $user_sso_services : array();
              $value = $user_sso_services ? implode(', ', $user_sso_services) : '—';
            }
            return $value;
          }
        }
      }
    }
  • Submit PR.


Tip: While working on this issue you can take note of how WordPress fills custom columns added by plugins. See this line of code in the WordPress core.

@kristineds kristineds added this to the Next Release milestone Oct 29, 2015
kristineds added a commit to wpsharks/comment-mail-pro that referenced this issue Oct 29, 2015
jaswrks pushed a commit to wpsharks/comment-mail-pro that referenced this issue Nov 4, 2015
@jaswrks
Copy link
Author

@jaswrks jaswrks commented Nov 4, 2015

Next Pro Release Changelog:

  • SSO Improvement: If you have Comment Mail's SSO integration enabled and have users who are registering an account via Facebook, Twitter, LinkedIn, or Google+, the SSO service that a particular user (or commenter) signed up with is now shown in the list of Users. Props @kristineds See also this GitHub issue if you'd like additional details.

    2015-11-03_21-06-16

@jaswrks jaswrks closed this Nov 4, 2015
@jaswrks jaswrks removed the ready for work label Nov 4, 2015
@raamdev raamdev removed the help wanted label Nov 4, 2015
@wpsharks wpsharks locked and limited conversation to collaborators Dec 24, 2015
@raamdev
Copy link
Contributor

@raamdev raamdev commented Dec 24, 2015

Comment Mail v151224 has been released and includes changes from this GitHub Issue: See the v151224 announcement for further details.


This issue will now be locked to further updates. If you have something to add related to this GitHub Issue, please open a new GitHub Issue and reference this one (#73).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.