An Oracle blog about NetBeans for PHP

How to create project for every WordPress plugin

In the previous entries about WordPress I have describe how to develop a WordPress plugin inside WordPress. This entry describes how to set up a project in NetBeans for every plugin separately. 

Let say that I develop many WordPress plugin. The folder structure is displayed on the picture.

I have folder WordPressPlugins that contains all plugins which I develop. Also I have one copy of WordPress sources in WordPressSources folder jut only for development reason. I will explain the reason later.

Then there is wordpress folder under Apache document root, which is accessible through the URL http://localhost/wordpress.

Now create the next plugin. Open new PHP Application wizard and call the project for example AnotherWPPlugin. The source folder for the project will be under the folder, where all WordPress plugins are developed. NetBeans will create in WordPressPlugins folder AnotherWPPlugin folder with the sources and nbproject folder for NetBeans metadata. The second step in the wizard should look like on the picture.

Basically similar approach is if you want to create project for an already existing plugin. 

In the next step you specify, how the project will be run. Run Configuration should be Local Web Site. The WodPress is reachable under http://localhost/wordpress URL. Also you have to say to NetBeans that the plugin sources has to be copied to the WordPress. So check the Copy files form Source Folder to another location and browse the plugins folder under the Apache's documented root.

So the third step of the wizard should look like:

After creating the project go to the Project properties and add the WordPressSources folder into Include Path. The reason is that we want to have the WordPress API in code completion. Sure we can put into Include Path the wordpress folder located under the Apache's document root, but then you will see the statements from the developed plugin in code completion twise. The first one from the sources folder and the second one from the plugins folder under document root.

NetBeans will create index.php file. You can use it and change the content to be an entry point for the plugin. More here.

Join the discussion

Comments ( 7 )
  • Glenn Welker Tuesday, October 7, 2008

    I have tried your technique which works fine except for debugging. On my system, both 6.5 beta and the NetBeans IDE Build 200810070201 nightly build create a unique situation when creating projects from existing sources. The web dialog requires an index file which should be the main web site index but will only allow you to choose files from within your project's files. In my case this ends up being the plugin file which can't be run directly.

    At least I think this is what is going on.

  • Glenn Welker Wednesday, October 8, 2008

    An update.

    I did do some more digging, and more reading of your example above.

    By using the index.php file from Wordpress, you can easily get Netbeans to start a debug cycle. Just include the index.php file within your plugin directory and change the require line to have a proper path to wp-blog-header.php. However, I don't believe that the debugging continues after the first page (index.php).

    Will the debugger include the include files within its debugging process?

  • Petr Wednesday, October 8, 2008

    Hi Glen,

    I have just tried it. You don't have to create the index.php. Just start the debugger (CTRL+F5) and you can correct the URL in browser from http://localhost/wordpress/index.php?XDEBUG_SESSION_START=netbeans-xdebug to http://localhost/wordpress/?XDEBUG_SESSION_START=netbeans-xdebug - delete the index.php from URL. But even it should work with the index.php in URL.

    I have noticed one problem that the xdebug some how ignores breakpoints in my plugin, if there were not switched on during the current debug session. It helps me to put breakpoint on a line above or after line, where is the ignored breakpoint. Also I have switched off the stop on first line option in PHP Options (Tools -> Options -> PHP).



  • Petr Thursday, October 9, 2008

    Hi Glenn,

    I have played with the debugging little more. You are right in such configuration the debugging basically doesn't work. The problem is that NetBeans are not able to find the file, where it should put breakpoint. NetBeans are looking relatively against the webroot.

    So my comment from yesterday is wrong. I had index.php in my plugin, which I tried to debug, but NetBeans were putting breakpoints to the index.php in wordpress folder not into my plugin index.php file. So basically I was debugging wordpress/index.php file:).

    There is one workaround. Remove all breakpoints from your plugin project. You can do it in Breakpoint window (Window->Debugging->Breakpoints). Start the debugger and open the wordpress/wp-content/plugins/yourplugin folder in Favorite window (Windows->Favorites). Put a breakpoint in your code in the Favorite window. The debugging should work.

    !!!!! Be careful during editing, if you make a change in Favorite window, you will lost the changes, because there are not done in your project sources, but in the copy and will be replaced when you invoke Run or Debug the project again. !!!!



  • Glenn Welker Tuesday, October 14, 2008

    I have played around with this quite a bit and my solution is to just use empty directories to mimic the directory structure of Wordpress.

    Something like:

    C:\\Third Party\\Wordpress

    C:\\Projects\\Wordpress plugins\\myaddin\\wp-content\\plugins\\myaddin\\

    With this I use an Ant script to combine the files from both directories into a single distribution directory. From there I copy the the distribution files to my local web server for testing.

    With all files copied by the Ant script, I can open my Netbeans project and debug with no apparent problems. I do have to select my plugin file for an entry point to debugging which is an annoyance. But once the error is shown in my web browser, I just point the browser back to index.php in the core Wordpress files and the debugging starts.

  • Petr Tuesday, October 14, 2008

    Thanks Glenn for the advising. We plan to improve the debugging in next version.



  • links of london Thursday, October 29, 2009

    It was a very nice idea! Just wanna say thank you for the information you have shared. Just continue writing this kind of post. I will be your loyal reader. Thanks again.

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