Writing Joomla bridge - User plugin

落花浮王杯 提交于 2019-12-17 21:38:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!