So, I have a problem with a WordPress plugin I'm making - I don't really like WordPress, but that's unrelated, so moving on. Anyways, I'm going to try and give some background information but I have a feeling it's going to be fairly confusing, so if I don't explain something clearly please ask.
I am creating a "file manager" that basically takes uploaded files and allows you to put them under a category & give them specific permissions. Everything works pretty good (it isn't done by any means, but this is the only real bug right now). You can add categories, and you can give a category sub-categories. You can do this infinitely (well, your browser limits it, since it would crash if it tried loading too much, but anyways).
Now, there are 2 places the categories are "rendered", in the front-end on the website (the part the normal user would see), and then in the back-end where you can add more categories, or delete/updating existing ones (you can also sort them, etc).
I am going to be referring to the back-end, I have no idea if the front-end works. I can deal with that later, I need to get this fixed first. On the back-end as you add categories the HTML needs to automatically "update". I.e. it needs to actually generate the HTML for the categories, so lets say the HTML looks like this:
Sub-category to category 1
Now, as you can see as you'd add categories the HTML would obviously need to update. This isn't the exact HTML, but it's the same concept. The problem is, sometimes it doesn't add enough </div> tags. There is no problem "opening" categories, just closing then. Now it seems like it would be really simple, and you could just do it with a basic for-loop but for whatever reason I just cannot get it to work. Right now, it isn't adding enough closing tags.
So, if you look above, IDs are organized by underscores. For example, ID 1
would be a top-level category, 1_1
would be a sub-category of 1, 1_1_1
would be a sub-category of 1_1.
Okay, now that I tried to explain my problem, the code can be found at https://github.com/Ryuske/Wordpress-File-Manager
. The primary files you should be concerned with are application/view/options/categories.php
. Everything in the code should be fairly well documented. I can set up a live example of it, but I'd rather not. You can just download it and use it on your own version of WordPress. Like I side, I can make a live version, I'd just rather not.
Anyways, if anyone has any thoughts at all I would vastly appreciate them. I've been stuck on this for a few months. I can get it to work for a certain number of levels, but once you go past that it breaks. I just can't seem to get it to be 100% dynamic and I don't understand why because it should just be simple math. I can get it to work just fine on paper...
Thanks for reading!
P.S. Sorry the URL isn't inside bb tags, I guess technically it's against the rules to post a URL but it's relevant and will be way easier for everyone involved if you just look there...