Moodle WordPress Vanilla Integration Without SSO

Moodle WordPress integration

Moodle WordPress integration in just 20 minutes

For Moodle 3.0, some changes are needed to work on this new version of Moodle.

Scenario:

Installation of WordPress and installation of Moodle.

We will use the WordPress database to authenticate Moodle users. In this way, we can sell courses using some WordPress e-commerce plugin and have instant access to customers.

The two sites are on the same machine but in different domains (actually, WordPress is in the subdomains “www.domain.tld” and “* .domain.tld” and Moodle is in another subdomain (courses.domain.tld) so We Need to authenticate users on both sites using the same database table.

The problem:

The Moodle external authentication plugin does not work with WordPress authentication out of the box. For it to work, you will need a couple of very easy modifications to make, do not worry, not even for a non php expert person.

We will return to this later in this post.

Let’s start our 20-minute change!

Store List:

1. WordPress Latest Version

2. WordPress database information

3. Moodle Latest Version

Moodle External Database Authentication Plugin (already in the default Moodle installation)

Some coding as well, all things for things ftp / sftp / ssh stuff and a decent text editor with some fail-safe function (save a copy before modifying etc)

12
That’s enough to start working.

Once installed the two systems, you will need to properly configure the external database authentication plug-in on the Moodle platform. To do this you have to authenticate yourself as a site administrator, then in the menu bar choose and click on “Site Administration” -> “Plugin” -> “Authentication” -> “Manage Authentication”.

You can use the image provided on the left to quickly find the route of the links needed to get there.

13

Once there you will see a list of all the authentication plugins, their status (active or inactive) their priority order and the link to their “settings”. As you can see in the following image, you must enable and prioritize the add-in to make it work. You probably want to disable the auto-registration function (see image below) to prevent the user from registering with the Moodle platform because otherwise, all users created in Moodle will not be able to authenticate in WordPress.

Once you have done, we will click on the “Settings” link and we will try to configure this plugin as best we can.

We have to enter all the information used by Moodle to read the WordPress database.

The fields are:

  1. Host, in my case I will use “localhost” and probably you too unless your db is hosted on a different machine, in that case, you have to use the hostname or the IP address of that machine
  2. The database, in my case “mysql” (Please note the trailer “i” – mysql and not mysql).
  3. Use sybase appointments, we do not need this to be so we’ll leave it in “NO”
  4. Db name, name your wordpress database (get from wp-config.php)
  5. Db user, mysql user who can access db tables WordPress
  6. Db password, mysql password for mysql user
  7. Table, the name of the table where the user name / passwords are stored. Most of the time it is “wp_users” unless you have changed your table prefix
  8. User name Field, the field containing the user name, for WordPress: “user_login”
  9. Password Field the field containing the password for the user name for WordPress: “user_pass”.
  10. Password format, we must choose “WordPress” format, but there is no such option in this drop down menu, so what? Let’s solve this later, do not worry
  11. External db encoding, use “UTF-8”
  12. SQL configuration command, you can leave it blank
  13. Debug ADOdb, choose “NO”
  14. Password-change URL, we use the link WordPress password recovery page link

These are the necessary fields for this to work, if you want more integration, you can configure the part called “cron synchronization script” and synchronize information like name, surname, user preferences, etc.

But now we have to stay focused on the missing scrolling element and find a way to get it out of there.We need to modify the file in /auth/db/config.html and change it (on line 190). This modification will make the “WordPress” pull-down element available, but it will not work.

We need to process the password with this class: class-phpass.php [Phpass Website]. This class can actually process passwords in the same way wordpress does, so this is the missing link to do SSO work.

Simply copy the file class-phpass.php into your / moodle / lib folder. And then add this line just after another requires at the beginning of wp-login.php to moodle / auth / db / auth.php

If you are lazy, you can download a copy of both file here, but I strongly suggest you make a modification by hand because time goes by and releases change.

Moodle auth with WordPress

Now, finally, we can come back to the settings page and add “WordPress” to “Password format”.

All you have to do is try this if it works, it is to log out from WordPress, signup into WordPress as a new user, and then go and authenticate with the same credentials against Moodle. If all work you will be redirected to the user profile on Moodle where you can complete your profile with your information

3E Services on Moodle Customisation and Integration. Share your business needs, we will give a personalised demo

Contact Us

Recent Posts