WordPress as CMS – Options (continued)
I spent way more time than necessary today working on handling and processing form input for the Options menus. I was focusing on form input for the prefixes for sections, posts, and categories. I don’t know if it was just that kind of day, but I just could not get it right.
What was I trying to do?
- Remove illegal characters from the form input
- Determine if there were any duplicate prefixes – i.e. the Section prefix and the Category prefix cannot be the same because they both operate at the same level (this was a major headache)
- If one of the prefixes is the same as another, revert that one back to its previous value (or the default if the previous value is no longer valid)
- Once form input has been validated, update plugin option stored in DB
Everything went fine until it came to validating the form data. I think I just need to get some rest because (nearly) nothing I was doing was working right.
The crux of the issue came from finding and dealing with duplicate prefixes. Certain prefixes cannot be the same, while it doesn’t really matter for others.
For example:
The Section prefix and the Post prefix can be the same as they live on different levels of the URL structure.
- Navigating to a section:
root/section_prefix/section_name/
- Navigating to a post:
root/section_prefix/section_name/post_prefix/post_name
- Since the Post prefix is appended to the Section URL, there is no way they could conflict with each other
However, the Category prefix cannot be the same as the Section prefix nor the Post prefix.
For example, if the Section prefix = section
and I set the Category prefix = section
as well, this is the result
- Navigating to a section:
root/section/section_name/
- Navigating to a category:
root/section/category_name/
This would obviously result in a conflict and only one of them would end up working. Thus, I wanted to implement validation to make sure it duplicates couldn't happen
In the end, I just simplified things, and have only implemented prefixes for Sections and Posts. Interestingly, though I spent most of the day on it, I do not really ever plan on using these prefixes (my goal from the beginning was to have prefix-free URLs). I'm big on user customization, and since I am building the features into WordPress as a CMS, I figured I'd tackle the customizable options now rather than later. At least it'll be a little bit more usable from the get-go that way.
On top of tomorrow's list:
- Subpages
- Testing
Time to sleep.