【问题标题】:Plugin “Hello World!” for User onUserAuthorisation插件“Hello World!”对于用户 onUserAuthorisation
【发布时间】:2017-11-15 14:20:49
【问题描述】:

我正在尝试创建一个插件来从event onUserAuthorisation 进行一些数据库查询。现在我只是想设置一个“Hello World”风格的插件,因为我还不确定我的插件功能是否正确触发。现在插件应该在新用户获得授权时发送一封电子邮件。

我可以确认 joomla 电子邮件适用于用户注册和管理。

文件:autoextranet.php,autoextranet.xml,index.html(空)

autoextranet.php

<?php

// no direct access
defined('_JEXEC') or die;

class plgUserAutoextranet extends JPlugin
{
    public function onUserAuthorisation($user, $options)
        {
        $mailer = JFactory::getMailer();
        $config = JFactory::getConfig();

        $sender = array( 
            $config->get( 'mailfrom' ),
            $config->get( 'fromname' )
            );
        $mailer->setSender($sender);

        $recipient = array( 'email1@gmail.com', 'email2@some.com' );
        $mailer->addRecipient($recipient);

        $body = "New User: ".$user->username;
        $mailer->setBody($body);

        $mailer->setSubject('You got a new user.');

        $mailer->Send();
        }
}

?>

autoextranet.xml

<?xml version="1.0" encoding="utf-8"?>
<extension version="3.8.2" type="plugin" group="user">
        <name>PLG_USER_AUTOEXTRANET</name>
        <author>Tim DeLise</author>
        <creationDate>Nov 14, 2017</creationDate>
        <copyright>Tim D</copyright>
        <license>GNU General Public License</license>
        <authorEmail>your email</authorEmail>
        <authorUrl>your website</authorUrl>
        <version>1.0</version>
        <description>.</description>
        <files>
                <filename plugin="autoextranet">autoextranet.php</filename>
                <filename>index.html</filename>
        </files>
</extension>

现在的问题是我已经安装并激活了插件。当我创建并激活一个新用户时,我什么也得不到。

很遗憾,我对服务器的访问受限,并且无法查看 PHP 错误日志。我正在寻找某种方法来确认该事件正在触发我的代码。欢迎任何建议。这也是我制作的第一个插件,所以我的文件可能有问题。

非常感谢任何帮助。

Joomla 版本 3.8.2

【问题讨论】:

  • 它可以在您的本地开发环境中使用吗?
  • @SvenBluege 这是一个很好的观点。
  • 我意识到直到用户真正尝试登录该站点时才会触发此事件。当我测试时,我没有完成最后一步,所以事件没有触发。
  • 所以我会添加这个作为解决方案:)
  • 测试一个事件是否触发的最好方法是让它在某处放置一些文本,或者通过记录或者显示一些东西。添加电子邮件系统会增加一层您不需要的复杂性。

标签: php events plugins joomla


【解决方案1】:

一旦用户进入登录过程,函数onUserAuthorisation就会被触发。确保您确实登录到 Joomla :)

我相信您已经意识到这一点。但是即使登录失败也会触发这个功能。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-28
    • 2012-01-04
    相关资源
    最近更新 更多