{"id":4445,"date":"2015-07-13T06:43:11","date_gmt":"2015-07-13T06:43:11","guid":{"rendered":"http:\/\/a1webdesignteam.com\/blog\/?p=4445"},"modified":"2015-07-13T06:43:11","modified_gmt":"2015-07-13T06:43:11","slug":"create-a-joomla-3-plugin","status":"publish","type":"post","link":"https:\/\/a1webdesignteam.com\/blog\/create-a-joomla-3-plugin\/","title":{"rendered":"Create a Joomla 3 Plugin"},"content":{"rendered":"<p>In this tutorial, we will create a plugin called \u201cshortcode\u201d for Joomla 3.2 which will do a simple text replacement of \u2018[copyright]\u2019 with \u2018Copyright &amp;copy; 2014\u2032<\/p>\n<p>This saves a bit of typing. \u00a0This is also a contrived example in order to keep the tutorial simple for learning purposes. \u00a0The concept is similar to the use of shortcodes in WordPress.<\/p>\n<p><img loading=\"lazy\" class=\"size-full wp-image-3721\" src=\"http:\/\/learnwebtutorials.com\/wp-content\/uploads\/2014\/03\/shortcode-plugin-in-action.jpg\" alt=\"shortcode plugin in action\" width=\"725\" height=\"426\" \/><\/p>\n<p>1. \u00a0A plugin requires an xml file which will named \u201cshortcode.xml\u201d. \u00a0We put this file within a \u201cshortcode\u201d folder within the \u201ccontent\u201d directory, which is within the \u201cplugins\u201d directory. \u00a0We put this plugin into the \u201ccontent\u201d directory because\u00a0we categorize this plugin in the group=\u201dcontent\u201d.<\/p>\n<p>You can see what the full xml file detail structure looks like in the <a href=\"http:\/\/docs.joomla.org\/J3.2:Creating_a_Plugin_for_Joomla\">Joomla docs<\/a>. \u00a0To keep things simple, we have excluded the optional &lt;languages&gt; tag and not put any config parameters.<\/p>\n<p>We will write the following content into shortcode.xml\u2026<\/p>\n<p><img loading=\"lazy\" class=\"size-full wp-image-3722\" src=\"http:\/\/learnwebtutorials.com\/wp-content\/uploads\/2014\/03\/xml-file-for-the-plugin.jpg\" alt=\"xml file for the plugin\" width=\"725\" height=\"240\" \/><\/p>\n<p>The attribute method=\u201dupgrade\u201d \u00a0means that this plugin can be installed without uninstalling an earlier version. All existing files will be overwritten, but old files will not be deleted.<\/p>\n<p>The version attribute in the extension tag is the version of Joomla in which this plugin is meant for. \u00a0 The version tag is the version of your plugin.<\/p>\n<p>2. Second we need the main plugin php file which we will name \u201cshortcode.php\u201d in the same \u201cshortcode\u201d folder. \u00a0 Put the following content in shortcode.php<\/p>\n<p><img loading=\"lazy\" class=\"size-full wp-image-3723\" src=\"http:\/\/learnwebtutorials.com\/wp-content\/uploads\/2014\/03\/plugin-php-code.jpg\" alt=\"plugin php code\" width=\"725\" height=\"247\" \/><\/p>\n<p>The class is named plgContentShortcode in order to follow the convention of \u2026<\/p>\n<pre>plg&lt;PluginGroup&gt;&lt;PluginName&gt;<\/pre>\n<p>We named our event onContentPrepare because that is the exact spelling of an event listed in the possible\u00a0<a href=\"http:\/\/docs.joomla.org\/Plugin\/Events\">list of Plugin events here<\/a>. \u00a0Plugin method with the same name as the event will be called automatically. \u00a0The parameters for this function is <a href=\"http:\/\/docs.joomla.org\/Plugin\/Events\/Content#onContentPrepare\">documented here<\/a>.<\/p>\n<p>3. Create an empty index.html file with the following content\u2026<\/p>\n<p>&lt;!DOCTYPE html&gt;&lt;title&gt;&lt;\/title&gt;<\/p>\n<p>This is so that users can not browse the plugin directory. \u00a0They will end up seeing an empty white page.<\/p>\n<p>4. Zip the files into shortcode.zip<\/p>\n<p>5. Install the plugin by going to \u201cExtension -&gt; Extension Manager\u201d and upload the shortcode.zip<\/p>\n<p>6. \u00a0Activate the plugin by going to \u201cExtension -&gt; Plugin Manager\u201d.<\/p>\n<p>7. \u00a0Put the [copyright] shortcode in an article and save. \u00a0See that it renders the full text \u2026<\/p>\n<p><img loading=\"lazy\" class=\"size-full wp-image-3721\" src=\"http:\/\/learnwebtutorials.com\/wp-content\/uploads\/2014\/03\/shortcode-plugin-in-action.jpg\" alt=\"shortcode plugin in action\" width=\"725\" height=\"426\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we will create a plugin called \u201cshortcode\u201d for Joomla 3.2 which will do a simple text replacement of \u2018[copyright]\u2019 with \u2018Copyright &amp;copy; 2014\u2032 This saves a bit of typing. \u00a0This is also a contrived example in order to keep the tutorial simple for learning purposes. \u00a0The concept is similar to the use [&hellip;]<\/p>\n","protected":false},"author":34,"featured_media":4446,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0},"categories":[26],"tags":[],"_links":{"self":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/4445"}],"collection":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/users\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/comments?post=4445"}],"version-history":[{"count":0,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/4445\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/media\/4446"}],"wp:attachment":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/media?parent=4445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/categories?post=4445"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/tags?post=4445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}