Writing Joomla bridge - User plugin

前端 未结 1 1821
有刺的猬
有刺的猬 2020-12-12 06:00

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

相关标签:
1条回答
  • 2020-12-12 06:13

    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>
    
    0 讨论(0)
提交回复
热议问题