I am a wannabe free time developer who uses PHP (mainly Symfony) and Python to build smaller stuff to automate my workflows and for fun side projects. Sometimes my code is actually useful.

As I had the idea to help a friend to have a custom table view for her WordPress site (she needed a quick overview over her subscribers and data from multiple sql-tables on one page) I created a very small plugin.
This was the first time I dove into wordpress development. Oh! My! God!

What a shit show behind the scenes!
I had heard the rumors, but thought that it was the usual talk about PHP from people who only knew the beginnings and who get their opinions about the language from 20 year old stackoverflow answers.

But nope, this time the rumors where true: Global variables, functions and classes everywhere! HTML intertwined with PHP mixed with echo statements.

The chaos! The inconsistencies! A violation in every line against everything I have learned during the last 5 years via tutorials, blog posts and by looking at well written source code.

I was almost expecting to stumble upon a RegEx parser for HTML.
Sure, I know about the history of PHP and that WP is a result of the early constraints and design choices. And I understand that it is hard to do something about the codebase now. And I myself am admin for at least 3 WP sites, so I know it works well for users.

But how do you professionals cope? Do you just see it as yet another imperfect framework that pays the bills? Or do you look at the bright side and ignore the flaws?

I am genuinely curious. Right now I’d say that I’d go crazy if I had to work with WP plugin development for more than one day, but maybe my snarky side is talking.

There’s WordPress, then there’s plugins. Take a look at popular plugin code.
I did and felt relieved.
But still, it seems like any good plugin still has to live with this monster of the core.
Nope, horrific! First experience with WordPress was in 2012 and I was hoping the world really would end.

I’d shit my trousers, soil my chair, soil the carpet, and clean up the mess by hand before I’d willingly write code for WordPress.
Out of curiosity: What do you usually work on?

Use McFarlin’s plugin boilerplate:
https://wppb.me/
It gives you a solid event-driven and object-oriented structure with which to work.
Yeah, it’s a mess alright. Amazing that we have such a high proportion of websites running it.
But I use it for a lot of websites, for the pure fact that it’s great for my client users.

Over the years I’ve built up my own framework to handle the WP ugliness, but I still feel dirty when working on those sites compared with doing my main work on Laravel.
I’m sure there are a lot of people involved with the WP project who would love to modernise, but with such a huge base of themes, plugins, and deployed websites, it would be an impossible task to drag it in to cohesiveness.

My first encounter with a CMS was with a very old version of Drupal.
When me and a few friends migrated that page to WordPress it was a huge thing and the optics improved drastically.

So I really do like the concept, community and ecosystem in general, but I had no idea it (still) looks so ugly under the hood.
I wrote a handful of WP plugins 10 years ago but I haven’t used WP until recently, when I put together a site for a friend and wrote a couple of plugins to help simplify tasks, and yikes. The plugin system hasn’t changed this whole time. It’s still a series of actions and filters, with each major plugin author creating their own mini framework to bring sanity to the chaos.

At any point in the past 10 years the WP devs could have introduced a modular, self contained, class based plugin system without impacting existing plugins which use hooks. It feels awkward writing code like this:
Instead of like this:

There are so many damn function callbacks everywhere, and there’s no inherent structure to a plugin. No “mostly right” way of doing things. It’s like everything we hated about working on the web in 2008 still lives on in WP.

It depends on what sort of work you’re doing.
You could be building on an old WordPress site that’s been cobbled together with a bunch of plugins, maybe a premium theme from ThemeForest – worse a nulled one. It’s a nightmare. Slow, ugly, hard to debug. I have worked on these and they are not fun to do.
Alternatively you could be working on a greenfield project for a bespoke site. You can do a lot with only WordPress core, a select handful of plugins, and your own bespoke additions. Doing this you’re free to pull in whatever dependencies you need and there are even a number of mini frameworks for this. Bedrock and Themosis come to mind, though I’ve not used either personally.

There are also developing plugins intended for wider distribution. You may have to target a low version of PHP and shouldn’t really bring many dependencies with you. That’s less fun, but it’s probably going to be a project that has a clear goal and then goes into maintenance. At a previous job I built the same plugin for a bunch of PHP ecommerce platforms: WP + WooCommerce, WP + Easy Digital Downloads, PrestaShop, OpenCart, and Magento. WP was the most enjoyable to work on. PrestaShop and OpenCart have their own problems, and Magento just broke me.

I wouldn’t really describe WordPress as bad per se, it feels like the wrong word. It’s certainly old and antiquated, especially compared to modern frameworks. But it’s not like that for no reason, it’s because it predates Symfony, Laravel, etc. It’s nearly 18 years old and has been fervently backwards compatible. That is a debate in and of itself however.
Finally there are some truly terrible entirely bespoke sites out there. Either very old, or built by people who didn’t quite know what they were doing. Those can be rewarding when you are able to make solid improvements, or endlessly frustrating when a project is so overwhelmingly awful.
So to answer your questions directly. It’s imperfect, but it could be a lot worse. I see the bright side and see the flaws as challenges to overcome, or rather, an API to abstract around 😀

Abstract away the ugly parts until you can write WP code the way you want to write it. WP is so unopinionated that you just just throw a modern PHP app into a theme or plug-in and run it.

At work we have a Laravel app that does our heavy lifting and a WP site for the standard brochure-and-a-blog stuff. I absolutely cannot understate how much I despise working on the WP site after coming from Laravel. That said, somebody’s gotta do it.

Anyway, the very first thing I do when writing a plugin is register an autoloader so I can properly namespace stuff and at least work semi-normally. Then I try to keep all my hooks in the main plugin file under the autoloader. From there it really depends on what the plugin needs to do, but I usually adhere to a pretty standard file structure.

For additional context: the guy who built the site used one of those “kitchen sink” themes that unnecessarily complicates everything, so most of my plugins are fairly small and straightforward with the aim of solving specific problems or working around specific annoyances.

The chaos! The inconsistencies! A violation in every line against everything
these few words sum up my pain pretty well
I do. There is a BIG difference between writing occasional code for wordpress (like in your case) and writing professional code. Don’t get me wrong, I’m not saying that you are a bad developer or something like that, it’s just that wordpress works so easy with anything you throw at it (like PHP/JS) that it’s really easy to create a disaster.

For example, you complained about using echo everywhere together with HTML, If you would have more experience with it, you’d know that the pros (Like WooCommerce) don’t use echo for templating, the prefered way to go is closing the php tag and writing html directly, echo is only allowed for i18n, and even then, you’d use a mix between echo and html markup to do that, it’s very rare to see someone using raw echo to output content.
Regarding global variables, you rarely need to use them, unless you’re creating a theme, which is not the case here. Sometimes you miss parameters inside your functions (being invoked from filters/actions) and you end up using global variables, but again, that’s on the programmer’s side, most of the times you’re good to go with $post.

To summarize, yes, wordpress can be a disaster, the same way laravel or raw php can be too! but if you get good at it, you can create beatiful things.
Thank you for the elaborate answer!

I might have been unclear about what I reacted to: not my own code (which is always a work in progress and that is not really worth mentioning in this context) but the codebase of WordPress and “the recommended way of doing things”.

Usually I look at “established” frameworks and try to understand coding standards and best practices. Often I am impressed by how smooth and logically I can Ctrl+Click myself through the codebase, jumping from definition to definition.

But in WordPress I was just struck by how “childish” everything looked: string literals everywhere (instead of constants) and no hint of SOLID or any other programming paradigm.
There was nothing to learn or be amazed by except for maybe that there is hook for everything which fascinating.
But thanks for your view and advice!

source