My first WordPress plugin in NetBeans

When I read Jan's tutorial how to configure WordPress in NetBeans I started to think, how it can be difficult to write a plugin for WordPress and whether NetBeans can help me in this. This entry is tutorial how to write simple plugin for WordPress.

What the plugin will do? The plugin will look through entry contents to replace NetBeans with link to NetBeans.org site. It's simple and it should take only few minutes. So let's start.

I expect that you have already NetBeans with WordPress project as it is described here. Run the project and you should see the main page in your browser with one entry "Hello world!". Edit the entry and add something like "And hello from NetBeans as well.".


Now it's time to start create the plugin. A WordPress plugin can be a simple php file under wp-content/plugins folder which has at least this comment.

<?php
/\*
Plugin Name: NetBeans Plugin
 \*/
?>

Although you can create the plugin file directly under the plugins folder, I suggest to create folder, which will contains all plugin files. It keeps the plugins folder cleaner. So create netbeans folder under the wp-content/plugins folder and in netbeans folder create new php file - NetBeansPlugin.php. The content of the new file replace with the code that is above.

In the  browser on the admin site (Site Admin link on the WordPress main page) click on the Plugin link. A list of all available plugins is displayed.  You should see new NetBeans Plugin in the list. There is just the name of the plugin and a link to activate it. Change the comment in the NetBeansPlugin.php file to correspond the code below to provide more informations about the plugin.

<?php
/\*
Plugin Name: NetBeans Plugin
Plugin URI: http://NetBeansPlugin.org/
Description: Replace word NetBeans with a link to NetBeans site.
Author: Petr
Version: 1.0
Author URI: http://blogs.sun.com/netbeansphp
\*/
?>


and the WordPress admin plugin page:


On the plugin page activate the NetBeans plugin. Now we can add the functionality:
<?php
/\*
Plugin Name: NetBeans Plugin
Plugin URI: http://NetBeansPlugin.org/
Description: Replace word NetBeans with a link to NetBeans site.
Author: Petr
Version: 1.0
Author URI: http://blogs.sun.com/netbeansphp
\*/

function linkNetBeans($text) {
    $help = "<a href='http://www.netbeans.org'>NetBeans</a>";
    return str_replace('NetBeans', $help, $text);
}

add_filter('the_content', linkNetBeans);

?>

The function linkNetBeans replaces the word NetBeans with the link to NetBeans site. Function add_filter is a function from WordPress API. Filters are the hooks that WordPress launches to modify text of various types before adding it to the database or sending it to the browser screen. So add_filter function registers our function linkNetBeans to a filter with name the_content. From now WordPress, before displaying an entry content, will call our function.

Save the file, go to the browser and display the welcome page with the entry. The page now should contain the link to NetBeans site.


This is all. The plugin now is working.

I have created a NetBeans module, which contains the template for WordPress plugin file. You can download the module here. To install this template you have to open Plugin Manager (Tools -> Plugins). In the Downloaded tab click on the Add Plugins... button and select the downloaded nbm file. Click on the Install  button. If the module is successfully installed the new WordPress Plugin template should appear in the New File wizard.


Comments:

Hi Petr,

Great Tutorial :)

Just wondering if you have any tutorial showing how we can create a NBM module for use with PHP applications?

Posted by raymond on August 18, 2008 at 12:42 PM CEST #

Hi Raymond,

thanks. What you exactly mean? Could you give an example? All NetBeans is composed basically from many nbm modules.

Regards,
Petr

Posted by Petr on August 18, 2008 at 04:22 PM CEST #

Hi Petr,

I was just looking at your nbm file (http://blogs.sun.com/netbeansphp/resource/other/org-netbeans-modules-php-wordpress.nbm)

I'm wondering how did you manage to get the files packaged as .nbm module?

Is there a feature in Netbeans that you can use to build a .nbm package?

A tutortial on how we can package our templates as .nbm packages would be great!

Posted by raymond on August 18, 2008 at 04:54 PM CEST #

Hi Raymond,

now I understand. I can prepare such tutorial. This is functionality of API support module, which supports writing NetBeans modules and it requires java support as well.

There is one tutorial how to do it http://platform.netbeans.org/tutorials/nbm-filetemplates.html , but it is little obsolete.

Thanks,
Petr

Posted by Petr on August 18, 2008 at 05:39 PM CEST #

Have been using the Netbeans IDE now for a couple of months mainly for developing Wordpress plugins. My question is this;

Is there anyway to effectively combine directories into a single project? What I want to do is essentially separate the code for my Wordpress plugins that I develop from the core Wordpress install. The Wordpress files are necessary for debugging and function reference but they clutter my development directories. Essentially I have many directories with full versions of Wordpress when I really only need one.

i.e.
c:\\wordpress (the core install)
c:\\development\\plugins\\

Posted by Glenn Welker on October 06, 2008 at 03:46 PM CEST #

Hi Glenn,

good point. I have written new how to do it. See http://blogs.sun.com/netbeansphp/entry/how_to_create_project_for .

Let me know, whether it helps you.

Regards,
Petr

Posted by Petr on October 07, 2008 at 04:55 AM CEST #

It absolutely helps and I am amazed at the speed at which you answered... and solved my question. Many thanks.

Posted by Glenn Welker on October 07, 2008 at 10:30 AM CEST #

Thanks for the FTP feature in Netbeans. This will be a big productivity gain for web developers.

Posted by DominoMill on November 24, 2008 at 01:17 PM CET #

I cannot get $_GET and $_POST to work in the NetBeans IDE 6.5. I am working with Lesson 2 of the tutorial "Creating a CRUD Application with NetBeans IDE PHP Editor." Could the issue be with the version of the PHP included in the IDE? Please HELP!

Posted by OCharles on February 20, 2009 at 10:12 PM CET #

now I understand. I can prepare such tutorial. This is functionality of API support module, which supports writing NetBeans modules and it requires java support as well.

Posted by wow power leveling on March 12, 2009 at 01:03 AM CET #

This is an excellent tutorial Petr
I was wondering is there a way you know to combine Java code in wordpress using NetBeans?
Thanks

Posted by Java Code on August 20, 2010 at 03:34 AM CEST #

nice and easy!

Posted by wordpress php on August 24, 2010 at 05:25 AM CEST #

Nice tutorial!

I have search an IDE that I can use to develop WordPress plugin.

THanks for the great work.

Posted by Setiawan on September 09, 2010 at 03:49 AM CEST #

I was wondering, is there a nbm file for themes or new project templates (for themes)?

Posted by chaos'1 on February 01, 2011 at 10:10 PM CET #

Hi Petr,

Sorry to respond to very old entry.

I was wondering if you are going to share the source code for this module.

I am keen on developing it further to.

Posted by Azizur Rahman on March 11, 2011 at 08:18 AM CET #

Hi Azizur,

I already deleted the code, but I think that everything is in the post. So simple copy paste should be enough.

Regards,
Petr

Posted by Petr Pisl on March 16, 2011 at 07:15 AM CET #

Hi Petr,

Thanks for your reply.

I was requesting source code for NetBeans Module:
http://blogs.sun.com/netbeansphp/resource/other/org-netbeans-modules-php-wordpress.nbm and not WordPress plugin.

Hope you still have the code some where.

Regards,
Azizur

Posted by Azizur Rahman on March 16, 2011 at 09:31 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
About

This blogs is written by NetBeans developers who contribute to the PHP support mainly.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today