My first plugin - installed/enabled but code not executing

46 views
Skip to first unread message

Sylvain Gantois

unread,
Jan 12, 2017, 3:05:55 AM1/12/17
to Joomla! General Development
Hi,

I tried to develop my first Joomla plugin but I don't get the expected result.
It seems that the code is not executed.



I have the following 2 files:
plgCreateForum.xml

<?xml version="1.0" encoding="UTF-8"?>
<extension version="3.6" type="plugin" group="content" method="upgrade">
<name>Content - Create Forum</name>
<author>Sylvain Gantois</author>
<creationDate>Jan 2017</creationDate>
<copyright>Copyright (C) 2017 Sylvain Gantois. All rights reserved.</copyright>
<license>GNU General Public License</license>
<authorEmail></authorEmail>
<authorUrl></authorUrl>
<version>1.0</version>
<description>Plugin to create a Kunena forum topic when an article is created.</description>
<files>
<filename plugin="plgCreateForum">plgCreateForum.php</filename>
</files>
</extension>


and plgCreateForum.php

<?php


defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.plugin.plugin' );


class PlgCreateForum extends JPlugin
{
function PlgCreateForum( &$subject, $params )
{
parent::__construct( $subject, $params );
}

function onBeforeContentSave( &$article, $isNew )
{
global $mainframe;
$newText = '<p>This is my new text to add to the article.</p>';
$user =& JFactory::getUser(); // get the user

$article->fulltext .= $newText;

return true;
}

}

?>


I am using Joomla 3.6.5. Any idea why it is not working ?

Thank you

Hannes Papenberg

unread,
Jan 12, 2017, 3:59:45 AM1/12/17
to joomla-de...@googlegroups.com
You seem to have followed a Joomla 1.5 tutorial, because your plugin
events are from that time and your code looks like PHP4. There is no
$mainframe, the constructor that you are using is PHP4-style and is
unnecessary anyway and the & at JFactory::... is also unnecessary and
does nothing.

Hannes

Russ Winter

unread,
Jan 12, 2017, 4:14:23 AM1/12/17
to joomla-de...@googlegroups.com
I've only just embarked on J!3 Plugins, this is the documentation I followed successfully...




--
Regards,
Russ Winter
--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsubscribe@googlegroups.com.
To post to this group, send an email to joomla-dev-general@googlegroups.com.
Visit this group at https://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/d/optout.

Sylvain Gantois

unread,
Jan 12, 2017, 11:51:27 PM1/12/17
to Joomla! General Development
Thank you for spotting out these problems !  

I will check the latest syntax.

Sylvain

Sylvain Gantois

unread,
Jan 12, 2017, 11:52:49 PM1/12/17
to Joomla! General Development
Thank you ! I will follow this example 
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.
To post to this group, send an email to joomla-de...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages