问题
I want to write a Joomla plugin to connect to user tables in database (one way).
So on new user registration, user will be duplicated and stored also in second table (other script). This is main goal. Things like updating on password change/delete etc. can be left until later.
Any ideas where I can find information helping me to write a plugin like this for Joomla 1.6? Where I can get user registration data etc?
回答1:
I have written a plugin for Joomla 1.6 that takes the new registered user's id and puts it into another table. It also deletes the user info from the secondary table if the user account is deleted. This should get you going, have a look at my code below:
This is for a plugin called: plg_foo_user
foouser.php
<?php
defined('_JEXEC') or die();
jimport('joomla.plugin.plugin');
class plgUserFooUser extends JPlugin
{
function onUserAfterSave( $user, $isnew, $success, $msg ) {
//JError::raiseWarning(100, 'here1');
if ($isnew && $success) {
$db = &JFactory::getDBO();
$db->setQuery( 'INSERT INTO #__foo_users (user_id) VALUES ('.$user['id'].')' );
$db->query();
}
}
function onUserAfterDelete( $user, $success, $msg ) {
//JError::raiseWarning(100, 'here2');
$db = &JFactory::getDBO();
if ($success) {
$db->setQuery( 'DELETE FROM #__foo_users WHERE user_id ='.$user['id'] );
$db->query();
return true;
}
}
}
?>
foouser.xml
<?xml version="1.0" encoding="utf-8"?>
<extension
version="1.6"
type="plugin"
group="user">
<name>Foo User</name>
<author>Martin Rose</author>
<creationDate>January 2011</creationDate>
<copyright>(C) 2011 Open Source Matters. All rights reserved.</copyright>
<license>GNU/GPL</license>
<authorEmail></authorEmail>
<authorUrl></authorUrl>
<version>1.0</version>
<description>Making foo happen</description>
<files>
<filename plugin="foouser">foouser.php</filename>
<filename>index.html</filename>
</files>
</extension>
来源:https://stackoverflow.com/questions/5960965/writing-joomla-bridge-user-plugin