summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Burschka2016-04-04 18:43:20 +0000
committerChristoph Burschka2016-04-04 18:47:35 +0000
commitfea6f15f266ec7c5a72c655d796a13b9241770b7 (patch)
treecf6454acb9649e2a1122a891ddb76f85b88f7bfe
parentCheck that hash_equals() exists. (diff)
downloadejabberd-auth-php-fea6f15f266ec7c5a72c655d796a13b9241770b7.tar.gz
Fix #14: Add wordpress plugin.
-rw-r--r--README.md3
-rw-r--r--plugins/wordpress/BridgeWordpress.php14
-rw-r--r--plugins/wordpress/wordpress.module20
3 files changed, 36 insertions, 1 deletions
diff --git a/README.md b/README.md
index d5c73d9..55974bf 100644
--- a/README.md
+++ b/README.md
@@ -14,9 +14,10 @@ Currently implemented bridges:
* Drupal 7.x
* Drupal 8.x (unstable)
* SMF 2.x
+* WordPress 4.4+
* Apache htpasswd
-Potential candidates for further bridges are WordPress, MediaWiki, Joomla! and Moodle.
+Potential candidates for further bridges are MediaWiki, Joomla! and Moodle.
Installation
------------
diff --git a/plugins/wordpress/BridgeWordpress.php b/plugins/wordpress/BridgeWordpress.php
new file mode 100644
index 0000000..a159523
--- /dev/null
+++ b/plugins/wordpress/BridgeWordpress.php
@@ -0,0 +1,14 @@
+<?php
+
+/**
+ * Implements EjabberdAuthBridge.
+ */
+class BridgeWordpress extends EjabberdAuthBridge {
+ function isuser($username, $server) {
+ return get_user_by('login', $username) != FALSE;
+ }
+
+ function auth($username, $server, $password) {
+ return wp_authenticate_username_password(NULL, $username, $password) instanceof WP_User;
+ }
+}
diff --git a/plugins/wordpress/wordpress.module b/plugins/wordpress/wordpress.module
new file mode 100644
index 0000000..c84db9e
--- /dev/null
+++ b/plugins/wordpress/wordpress.module
@@ -0,0 +1,20 @@
+<?php
+
+function wordpress_init($config) {
+ require_once $config['root_path'] . 'wp-load.php';
+ require_once $config['root_path'] . 'wp-includes/user.php';
+ ob_end_clean(); // Basically voodoo.
+
+ // Load the plugin.
+ require_once __DIR__ . '/BridgeWordpress.php';
+ return new BridgeWordpress();
+}
+
+function wordpress_session($config) {
+ require_once $config['root_path'] . 'wp-load.php';
+ require_once $config['root_path'] . 'wp-includes/user.php';
+
+ $id = wp_validate_logged_in_cookie(NULL);
+ if ($id) return (new WP_User($id))->user_login;
+}
+