trouble writing plugin

This forum is for general questions about extensions for Joomla! 3.x.

Moderators: pe7er, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
TheCellarRoom
Joomla! Intern
Joomla! Intern
Posts: 77
Joined: Wed Jan 02, 2013 10:09 am

trouble writing plugin

Post by TheCellarRoom » Tue Apr 02, 2013 1:19 pm

I have written this as a plugin

Code: Select all

defined('_JEXEC') or die( 'Direct Access to this location is not allowed.' ); 
jimport( 'joomla.plugin.plugin' );
JPluginHelper::importPlugin( 'test' ); 
$document=JFactory::getDocument();
$document->addCustomTag('<!-- Plugin test has been included correctly-->');


class plgContentMB_Plugin extends JPlugin {



        public function onContentPrepare($context, &$row, &$params, $page = 0) {

            $row->introtext = str_replace("a","A",$row->introtext);
            $row->text = str_replace("a","AAAAA",$row->text);
            return true;
        }
}
but i can't get my content to change accordingly.

what am i missing?

the custom tag is being displayed in the view source and any syntax errors cause an error to be found i.e. if i deliberately leave out a semi-colon this correctly errors as expected, so the plugin is working/being called by joomla/browser.

I just can't get the displayed `$row-text` to change or anything to `print` to screen.

thanks in advance

update:
using joomla version 3.0.1
no errors/warnings in my error_log

 
User avatar
carreon
Joomla! Intern
Joomla! Intern
Posts: 50
Joined: Sat Oct 08, 2005 11:16 pm
Location: Mexicali, Baja California, México
Contact:

Re: trouble writing plugin

Post by carreon » Fri Apr 05, 2013 1:51 am

You could start by verify that the plugin name defined in the XML file is the same used in the PHP class

As a good practice, notice the use of capital letters in the class name.
Roberto Carreón
http://www.roalcana.com/ - Professional Extensions for Joomla!™

TheCellarRoom
Joomla! Intern
Joomla! Intern
Posts: 77
Joined: Wed Jan 02, 2013 10:09 am

Re: trouble writing plugin

Post by TheCellarRoom » Fri Apr 05, 2013 7:44 am

yes the xml and php class match.

TheCellarRoom
Joomla! Intern
Joomla! Intern
Posts: 77
Joined: Wed Jan 02, 2013 10:09 am

Re: trouble writing plugin

Post by TheCellarRoom » Mon Apr 08, 2013 10:14 am

resolved.

deleted plugin.
rewrote
reinstalled
worked.

weird.

User avatar
TSX-Today
I've been banned!
Posts: 57
Joined: Wed Dec 19, 2012 6:56 pm
Location: Vancouver, BC, Canada
Contact:

Re: trouble writing plugin

Post by TSX-Today » Wed Apr 10, 2013 12:18 pm

Are you going to publish this? On another note, I would like to start writing plugins myself. Any tips? Thanks.
My SEO Website at SEO Vancouver http://www.seoinvancouver.com/
TSX Today http://www.tsx-today.com/, ranks one Page #1 in Bing and Yahoo for super competitive keyword: TSX, with over 500,000 searches per month

TheCellarRoom
Joomla! Intern
Joomla! Intern
Posts: 77
Joined: Wed Jan 02, 2013 10:09 am

Re: trouble writing plugin

Post by TheCellarRoom » Thu Apr 11, 2013 8:47 am

I can share it yes. I am actually using the plugin in conjunction with a component i have created too.

in the component admin users add a shortcode and the full markup.

the plugin does the replacement.

for example if every page has a call to action 'contact us' button, this can be added via a shortcode {button} and added to the markup in the editor on each post/page. the plugin/component handles the change to full markup and that markup can then easily be changed.

I find this very useful and have something similar in WordPress.

in terms of tips just one:

The plugin name needs to be case sensitive and the class that extends JPlugin needs to be named specifically 'plgContent*pluginname* .
Last edited by TheCellarRoom on Tue Apr 16, 2013 7:13 am, edited 1 time in total.

TheCellarRoom
Joomla! Intern
Joomla! Intern
Posts: 77
Joined: Wed Jan 02, 2013 10:09 am

Re: trouble writing plugin

Post by TheCellarRoom » Fri Apr 12, 2013 4:31 pm

As promised.

plugin and component here: http://site.thecellarroom.net/Joomla-Shortcodes/
(github).

User avatar
TSX-Today
I've been banned!
Posts: 57
Joined: Wed Dec 19, 2012 6:56 pm
Location: Vancouver, BC, Canada
Contact:

Re: trouble writing plugin

Post by TSX-Today » Tue Apr 16, 2013 7:03 am

Thank you for this.
TheCellarRoom wrote:As promised.

plugin and component here: http://site.thecellarroom.net/Joomla-Shortcodes/
(github).
My SEO Website at SEO Vancouver http://www.seoinvancouver.com/
TSX Today http://www.tsx-today.com/, ranks one Page #1 in Bing and Yahoo for super competitive keyword: TSX, with over 500,000 searches per month

 

Locked

Return to “Extensions for Joomla! 3.x”