diff options
author | Christoph Burschka | 2016-04-04 18:43:20 +0000 |
---|---|---|
committer | Christoph Burschka | 2016-04-04 18:47:35 +0000 |
commit | fea6f15f266ec7c5a72c655d796a13b9241770b7 (patch) | |
tree | cf6454acb9649e2a1122a891ddb76f85b88f7bfe /plugins/wordpress | |
parent | Check that hash_equals() exists. (diff) | |
download | ejabberd-auth-php-fea6f15f266ec7c5a72c655d796a13b9241770b7.tar.gz |
Fix #14: Add wordpress plugin.
Diffstat (limited to 'plugins/wordpress')
-rw-r--r-- | plugins/wordpress/BridgeWordpress.php | 14 | ||||
-rw-r--r-- | plugins/wordpress/wordpress.module | 20 |
2 files changed, 34 insertions, 0 deletions
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; +} + |