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.


Comments:

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.

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

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?

Posted by Glenn Welker on October 08, 2008 at 06:43 AM CEST #

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).

Regards,
Petr

Posted by Petr on October 08, 2008 at 09:21 AM CEST #

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. !!!!

Regards,
Petr

Posted by Petr on October 09, 2008 at 08:07 AM CEST #

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.

Posted by Glenn Welker on October 14, 2008 at 07:25 AM CEST #

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

Regards,
Petr

Posted by Petr on October 14, 2008 at 09:43 AM CEST #

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.

Posted by links of london on October 29, 2009 at 08:13 PM 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
« March 2015
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
31
    
       
Today