PhpStorm and WordPress plugin development - cant get it working - php

I'm new to PHP and WordPress development. I have PhpStorm correctly setup and tested to run and debug simple PHP pages - sorted.
I want to development WordPress plugins, so have created a new WordPress plugin project in PhpStorm.
However, I cannot see how this works. The plugin is outside the WordPress install, and I believe it needs to be inside WordPress - in the plugins directory.
I have read all of the JetBrains instructions in fine detail for doing this MANY, MANY times, and nothing tells me how to make the plugin work within WordPress when it exists externally, so that it can be debugged.
I'm obviously missing some vital information or principal, as every article or YouTube video skips this. If I put some code in the plugin php file and set a debugger breakpoint in the hope that it 'magically' just works - nothing happens. Yet I can successfully hit a breakpoint set in the WordPress source files themselves - so something is definitely wrong.
Can someone tell me what I'm missing. I'm completely out of ideas, and massively frustrated.
Should I just abandon the standard PhpStorm project setup and just create a php file inside the WordPress plugins directory directly and just do things there. Seems a shame as I want to keep the plugin separate - as PhpStorm seems to recommend.

Related

WordPress Manual Install Theme/Display Issue

My Problem
I manually installed WordPress on a Debian 9 VM in Virtual Box on a Windows 10 machine. When I pull up the website, this is what I get:
A WordPress site with just HTML, no formatting
The point of this install was to learn how to make a custom WordPress theme. I have built child themes before, but never a theme from scratch, so it may be I don't have everything set up yet. But there is a second issue is WordPress does not give me an option to select my second theme either.
What I did
To set up the site, I followed this tutorial on setting up WP on a Debian system. I sort of touched up on this, but I am new to WP development. I thought this was a quick and dirty route to set up a WP install. I don't have the knowledge of WordPress to know if there is an error in this setup guide.
Again, I checked the themes folder. I could not find the custom theme I started to build as an option. I can't currently download themes straight from WP because I don't have an FTP server/client currently installed on my machine. If it were just the inability to choose a WordPress theme from the WordPress theme repository, I'd suspect it's the FTP setup. But, I also can't choose my custom theme. So is there something wrong with the install?
Summary
I can't get any formatting to work on my WP development site. I suspect it's some problem with themes, but I don't know enough about the internals WordPress to know how to diagnose the problem.
Thank you for your time
It's tough to say without seeing your setup exactly, but this is often caused by URL problems.
Are you able to access wp-admin? If so, try logging in and visiting the settings > permalinks page, then just hitting the save button.
Try reloading your site. It might be fixed.. If not, a little more to try. First, I'd open your browser's Console / Inspect mode, and see if there are any console errors (showing CSS files not loading, etc). If so, post them here.
Additionally, I found a helpful article that details some other things to try when this problem pops up:
http://wphelp24.com/how-to-fix-wordpress/how-to-fix-wordpress-css-not-loading/

PhpStorm debug WordPress theme files

I am trying to set up PhpStorm for WordPress theme development and facing an issue with getting xdebug to work with theme files.
The problem I face is that when I try to debug lets say header.php, it tries to open the file itself in the browser in order to watch the variables within it: http://localhost/wp-content/themes/themename/header.php which of course throughs me an error as the file itself does not contain the rest of the function and dependencies of WordPress.
So my question is, if I have a variable inside header.php, or footer.php is there a way I can watch it in PhpStorm debug. If so how?
My xdebug is enabled, I am running XAMPP. I tried adding theme folder into the project and adding External Libraries paths, wp-includes and wp-admin as shown in this tutorial https://www.youtube.com/watch?v=nt85dnx0V8Y.
Then I decided to add it as whole project. I did setup interpreter. But still can't really debug any of the variables inside the theme files. Is there a solution for that?
I also installed JB plugin for chrome but it also did not help.
Normally you have only to toggle this button, after you have activated xdebug. Then when you launch your website, PhpStorm should stop execution on your breakpoints.
Follow this link for complete solution to use xdebug with PhpStorm
: https://confluence.jetbrains.com/display/PhpStorm/Zero-configuration+Web+Application+Debugging+with+Xdebug+and+PhpStorm

How to setup Netbeans Project for WordPress Plugin/Widget Development

I am wanting to locally develop a suite of WordPress plugins and widgets. My development environment consists of Windows v8.1, Netbeans v8.0.2 and XAMPP v5.6.3.
I've configured Netbeans and PHP to use XDebug. I've spent the entire weekend watching and reading various tutorials on setting up Netbeans IDE for developing a WordPress plugins/widgets.
Everything seems to be working at this point - I've been able to create new Netbeans projects by opening existing/installed plugins of my WordPress install. I am able to set breakpoints and trace through code. All seems to be working well, but I am puzzled regarding the 'proper' way to setup a new project.
Should a plugin/widget project somehow include the WordPress core files starting at .\htdocs, or should the root of the project be .\htdocs\wp-content\plugins\myplugin? In other words, should I be able to see .\wp-admin and .\wp-includes in my project tree?
My thinking is that Netbeans needs to somehow be able to read the core WordPress files to provide function reference during development of the plugin/widget and this would require including the WordPress core in my project, somehow.
Maybe my question is best asked this way:
What should the root project folder be set to for developing/debugging a plugin named MyPlugin?
and/or:
How are WordPress core files included/referenced in the MyPlugin project?
Anyone have a good step-by-step reference that would enlighten me on this?
I'm searching for this too, but here's how I set it up. I'm developing a theme (plugin would be analogous) so I have the theme source and NetBeans project files in a separate folder outside of WordPress folder, and outside of the xampp/htdocs actually. Then, I set the root of my PHP project to this theme source folder, and then using the Project Properties -> Include Path facility to allow NetBeans to include the WordPress folder, it will appear under Include Path in Project Explorer, enabling 'IntelliSense' etc. This way you can start a new NetBeans project per plugin/theme, basically, just including the WordPress core in each. Furthermore, I have NetBeans set up to copy the source files to the xampp\htdocs\mysite2\wp-content\themes\ folder on save and project load (set up in preferences). Here's a pic: NetBeans WordPress Setup
The best way I've found so far is to use a hardlink.
If I keep the files in Netbeans' project directory everything works. But Wordpress sometimes does not recognize that the theme is there. I.e. in some wp-admin menu's. But I'm able to display a Theme just fine.
I create the project as a php project in Netbeans.
Then link my (pubic html) folder from the Netbeans directory.
mklink /J C:\LinkToFolder C:\Users\Name\OriginalFolder
Use " quotes if your path has spaces
I use:
mklink /J "C:\xampp\htdocs\wptheme\wp-content\themes\themename"
"C:\Users\Probook 1\Documents\NetBeansProjects\projectname\public_html"
Then I setup the netbeans project to load an external page when I run the project. (See File => Project Properties=>Run Configuration)
I'll be looking into doing the same with plugins soon. Practically I can't see a reason this won't work for plugins too.
I want to try and see if Netbeans copes with the hardlink better than Apache does. (I.e. if I setup the project first then move the files to Xampp and create a hardlink in Netbeans' project directory. I.e. Projectname\public_html
(If anyone does it first let me know how it goes)
It's more important to me that Netbeans can backup and function. As long as I can display what I'm developing realtime.
AFAIK Netbeans can intergrate with Xampp to run it's debugging (Xdebug)

WordPress plugin changes install directory when deleted and reinstalled

Embarrising enough, I created this particular plugin. Works great, but in testing, this happens:
1. Install plugin via WP Dashboard zip installer.
1a. Works great; fully functional.
2. Deactivate & delete files via WP Dashboard.
3. Reinstall plugin (#1 above).
- Issue: In the theme's plugin folder, a sequential number is appended to the plugin's folder, e.g. "my-plugin" becomes "my-plugin1"
This is a very light weight plugin, only loads a form, script, CSS file, shortcodel. - no SQL tables, no user settings, etc.
Any ideas? I've never repeatedly installed, removed, then reinstalled a plugin, so this is a new thing for me.
Thanks!

Breakpoint not firing using PHP/XAMPP/NetBeans/Moodle

Bit of an obscure one this. My setup is all running on my local Windows machine; I've got NetBeans IDE installed, a local XAMPP server with XDebug running, and an installation of Moodle with some custom addons in the mod directory.
I can happily create breakpoints in PHP pages (including the main Moodle ones), but any breakpoints I place on php files in the mod directory never fire (on my mods, or any of the inbuilt ones). I thought Moodle might be doing some "magic" to display files in the mod directory, but my browser shows the url as http://localhost/moodle/mod/view.php - and that's the file I've set my breakpoint in.
Has anyone got any experience with debugging Moodle addins, or could possible point me in the direction of how to troubleshoot the breakpoint not firing? I've tried the Moodle site, but can't find anything relevent.
Actually, I think I've figured it out. If I tell it to debug that particular file it will 404 (it doesn't put the directories in, guess it's a bug), but if I then manually go to http://localhost/moodle/mod/view.php?XDEBUG_SESSION_START=netbeans-xdebug (which errors, no parameters are being passed in), and THEN manually navigate to Moodle then my mod breakpoints fire correctly.
All very bizarre, but it seems to be a usable workaround. I'm guessing the mods are running under some kind of different PHP session.
I'll keep this answer here in case anyone else has this bizarre problem.

Categories