<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Méhluli Hikwa</title>
    <description>The latest articles on DEV Community by Méhluli Hikwa (@thatafro).</description>
    <link>https://dev.to/thatafro</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F241673%2Fe227d31e-fc60-4386-a64a-abf97ad410d4.png</url>
      <title>DEV Community: Méhluli Hikwa</title>
      <link>https://dev.to/thatafro</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thatafro"/>
    <language>en</language>
    <item>
      <title>How to display a user’s last login date in #WordPress admin</title>
      <dc:creator>Méhluli Hikwa</dc:creator>
      <pubDate>Sun, 04 Jul 2021 23:22:56 +0000</pubDate>
      <link>https://dev.to/thatafro/display-a-user-s-last-login-date-in-wordpress-admin-1ndn</link>
      <guid>https://dev.to/thatafro/display-a-user-s-last-login-date-in-wordpress-admin-1ndn</guid>
      <description>&lt;p&gt;A few weeks ago when a WordPress site I managed crushed, I had the client ask to view stats of user login times. By default WP does not support this.&lt;/p&gt;

&lt;p&gt;First quick fix for such solutions is to install a plugin. Great option - I found this plugin called &lt;a href="https://wordpress.org/plugins/when-last-login/"&gt;When Last Login&lt;/a&gt;. Its a lightweight plugin that allows you to see active users according to their last login time/date, with zero configuration - plug and play.&lt;/p&gt;

&lt;p&gt;After installing it worked well. But being the developer I am, I was not settled having an extra plugin so I did some reading in the WP Codex and after a month I figured out a solution - plugin free.&lt;/p&gt;

&lt;p&gt;If you’re familiar with adding code snippets to your site via functions.php or the code snippets plugin you can use this to add the user’s last login timestamp to the WP admin.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Record user's last login to custom meta&lt;/span&gt;
&lt;span class="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'wp_login'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'capture_user_login_time'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;capture_user_login_time&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$user_login&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;update_user_meta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="no"&gt;ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'last_login'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;time&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;//Register new custom column with last login time&lt;/span&gt;
&lt;span class="nf"&gt;add_filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'manage_users_columns'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'user_last_login_time_column'&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;add_filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'manage_users_custom_column'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'last_login_column'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;user_last_login_time_column&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$columns&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$columns&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'last_login'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Last Login'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$columns&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Output last login column onto WP Front end&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;last_login_column&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$output&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$column_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$user_id&lt;/span&gt; &lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$column_id&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'last_login'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$last_login&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_user_meta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$user_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'last_login'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$date_format&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'M j, Y'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$hover_date_format&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'F j, Y, g:i a'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$last_login&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;div title="Last login: '&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$hover_date_format&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$last_login&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;'"&amp;gt;'&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;human_time_diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$last_login&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;'&amp;lt;/div&amp;gt;'&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'No record'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$output&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>wordpress</category>
      <category>php</category>
    </item>
    <item>
      <title>NPM basics of Global Packages</title>
      <dc:creator>Méhluli Hikwa</dc:creator>
      <pubDate>Fri, 12 Mar 2021 11:43:35 +0000</pubDate>
      <link>https://dev.to/thatafro/npm-basics-of-global-packages-2c05</link>
      <guid>https://dev.to/thatafro/npm-basics-of-global-packages-2c05</guid>
      <description>&lt;p&gt;The information shared below is npm basics of global packages which are partially hidden or difficult to find in the docs page. I hope they help. Lets dabble.&lt;/p&gt;

&lt;p&gt;1) NPM install global packages - example to install &lt;a href="https://webpack.js.org/"&gt;Webpack&lt;/a&gt; globally&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g webpack
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2) Listing globally installed NPM packages and version&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm list -g --depth=0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result will look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\thatAfro\AppData\Roaming\npm
+-- @angular/cli@8.3.29
+-- ionic@5.4.16
`-- webpack@4.46.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3) Update Global Packages&lt;/p&gt;

&lt;p&gt;Find/View packages which need to be updated:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm outdated -g --depth=0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result will look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\thatAfro&amp;gt;npm outdated -g --depth=0
Package  Current  Wanted  Latest  Location
npm        6.1.0   6.2.0   6.2.0
webpack   4.12.1  4.16.1  4.16.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update all global packages&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm update -g
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In some cases you may want to update packages one at a time, so you can do this as follows:&lt;/p&gt;

&lt;p&gt;npm update -g &lt;/p&gt;

&lt;p&gt;For example updating webpack, it would look like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm update -g webpack
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4) Uninstall Global Packages&lt;/p&gt;

&lt;p&gt;npm uninstall -g &lt;br&gt;
For example uninstall webpack, it would look like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm uninstall -g webpack
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;5) Uninstall npm modules in node.js&lt;/p&gt;

&lt;p&gt;As commonly known, any npm module can be installed by running a simple command: npm install &lt;/p&gt;

&lt;p&gt;The command is simply npm uninstall &lt;/p&gt;

&lt;p&gt;The &lt;a href="https://npmjs.org/doc/"&gt;nodejs documents&lt;/a&gt; have all the commands that you need to know with npm.&lt;/p&gt;

&lt;p&gt;A local install will be in the node_modules/ directory of your application. This won't affect the application if a module remains there with no references to it.&lt;/p&gt;

&lt;p&gt;If you’re removing a global package however, any applications referencing it will crash.&lt;/p&gt;

&lt;p&gt;Here are different options:&lt;/p&gt;

&lt;p&gt;npm uninstall  removes the module from node_modules, but not package.json&lt;/p&gt;

&lt;p&gt;npm uninstall  --save also removes it from dependencies in package.json&lt;/p&gt;

&lt;p&gt;npm uninstall  --save-dev also removes it from devDependencies in package.json&lt;/p&gt;

&lt;p&gt;npm -g uninstall  --save also removes it globally.&lt;/p&gt;

&lt;p&gt;For further help with npm, you can visit the docs page&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.npmjs.com/getting-started/what-is-npm"&gt;NPM Official Documentation&lt;/a&gt;&lt;/p&gt;

</description>
      <category>npm</category>
      <category>node</category>
    </item>
  </channel>
</rss>
