X

An Oracle blog about NetBeans for PHP

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.


Join the discussion

Comments ( 17 )
  • raymond Monday, August 18, 2008

    Hi Petr,

    Great Tutorial :)

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


  • Petr Monday, August 18, 2008

    Hi Raymond,

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

    Regards,

    Petr


  • raymond Monday, August 18, 2008

    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!


  • Petr Monday, August 18, 2008

    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


  • Glenn Welker Monday, October 6, 2008

    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\\


  • Petr Tuesday, October 7, 2008

    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


  • Glenn Welker Tuesday, October 7, 2008

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


  • DominoMill Monday, November 24, 2008

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


  • OCharles Friday, February 20, 2009

    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!


  • wow power leveling Thursday, March 12, 2009

    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.


  • Java Code Friday, August 20, 2010

    This is an excellent tutorial Petr

    I was wondering is there a way you know to combine Java code in wordpress using NetBeans?

    Thanks


  • wordpress php Tuesday, August 24, 2010

    nice and easy!


  • Setiawan Thursday, September 9, 2010

    Nice tutorial!

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

    THanks for the great work.


  • chaos'1 Tuesday, February 1, 2011

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


  • Azizur Rahman Friday, March 11, 2011

    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.


  • Petr Pisl Wednesday, March 16, 2011

    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


  • Azizur Rahman Wednesday, March 16, 2011

    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


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.