2014-03-19, 02:16:49 (This post was last modified: 2014-03-19, 02:17:52 by Angryboy.)
In this topic I said that I would be producing a tutorial on plugin development from scratch. I've realised that because the process is so heavy and introduces so many concepts that shouldn't be taken for granted, it would be good to provide a plugin template or framework that goes a bit beyond what is on the wiki.
Can anyone tell me what they think of the attached templates? Neither plugin performs any meaningful task - it is about getting the flexible structure set up to actually then produce ones own plugin. The bulk of the structure is lifted from the way mvlcek organises his files.
One example is done purely in a procedural programming style. The other uses OOP techniques to provide a plugin controller that can easily be extended to have more methods; also, the plugin autoloads classes from its folder.
In short, I'm asking is whether or not these examples would actually be helpful for plugin developers (prospective, new or old) and if not, what can be done to improve it?
I do like that the assets are prepackaged, and lang.
although the only htaccess you need is allow for assets folders. js, css etc.
But the organization of the oop seems odd to me.
I think to benefit from this, the entire plugin needs to be class based so no globals are necessary.
And you do not need to replace yourplugin_id all over the place or use a namespace.
$uniqueID = new plugin($uniqueID);
add some stuff here version author
$uniqueid->author =
The only hook into the class could be something like register_plugin(){global uniqueID;$uniqueID->register);
I guess you would still have the same problem though with globals but you could prevent collisions with variable variables and variable function names. But you would need to handle callbacks from filters and hooks with normal functions or you might lose a argument in the process if you can only pass an action.
But another issue is that gs requirements are still 5.2.3, so alot of oop stuff might not be useable until 5.3
Every time i write a plugin I think about this and still have not gone far enough to persue it, i think someone also wrote one of these already, not the same thing but similar. Maybe it was just helpers
2014-03-19, 03:42:43 (This post was last modified: 2014-03-19, 03:49:22 by Angryboy.)
(2014-03-19, 02:48:56)shawn_a Wrote: I do like that the assets are prepackaged, and lang.
although the only htaccess you need is allow for assets folders. js, css etc.
But the organization of the oop seems odd to me.
I think to benefit from this, the entire plugin needs to be class based so no globals are necessary.
And you do not need to replace yourplugin_id all over the place or use a namespace.
$uniqueID = new plugin($uniqueID);
add some stuff here version author
$uniqueid->author =
The only hook into the class could be something like register_plugin(){global uniqueID;$uniqueID->register);
I guess you would still have the same problem though with globals but you could prevent collisions with variable variables and variable function names. But you would need to handle callbacks from filters and hooks with normal functions or you might lose a argument in the process if you can only pass an action.
But another issue is that gs requirements are still 5.2.3, so alot of oop stuff might not be useable until 5.3
Yeah, the OOP design pattern I've used is pretty slap-dash I'll admit. xD
So with your example, are you saying that I should wrap up the plugin registration itself into an object, or is there already a plugin object in GS for doing this?
Also, if the OOP functions might not work until 5.3, how has SimpleXMLExtended been working for the core? If there is legacy code to ensure that it works, I would be grateful to know so that I can make my code backwards-compatible too.
(2014-03-19, 03:07:29)shawn_a Wrote: hmm has anyone tested hooks and filters with namespaces or classes?
They definitely work with classes (both instances and singletons). Haven't tried with namespaces yet though.
classes work , but some new stuff doesn't, closures, namespaces, reflection class perhaps, are all 5.3
5.3 adds major oops support to php, not just basic.
Thanks for the link, Carlos. I hadn't realised that such an extensive template already existed, let alone that it was 2 years old!
As for 5.3: here is the list of new features. Whilst powerful and useful, I don't think that GS developers would be crestfallen without them (with the exception of Namespaces).
Is it worth me still putting out a basic template for use, or do you think rjzaworski's just needs a bit more visibility on the site (e.g. a more prominent wiki link)?
2014-03-19, 05:30:00 (This post was last modified: 2014-03-19, 05:30:40 by Angryboy.)
Ah okay then. I'm still not experienced enough to say that I have them in my toolbox yet. It should also be fairly easy to put a flag up within the plugin if the PHP version is too old.
I think classes are supposed to be in their own file with nothing else and stuff, I don't know what the code standards are, but they are just standard practices
Updated again. The /inc folder now has definitions for ckeditor and codemirror (lifted from the code in the /admin folder so that instances of either can be used as follows:
PHP Code:
<textarea id="yourtextarea"></textarea> <?php $textarea = 'yourtextarea'; include('ckeditor.php'); // or include('codemirror.php') for codemirror ?>