I was analyzing WordPress codes and kind of realized that WordPress is not object oriented.I am not sure whether i am right because I am new to programming.If i am right, why a major and most popular open source software don't use OOP as the method of programming ?
-
2Wordpress is a mix mess of procedural and OOP with the worst development practices added in (global variables, no separation of concerns, echo()'ing from anywhere, bad database modeling, etc). Do NOT under any circumstance learn from the WP way of doing things, except as a bad example.– RafaMay 29, 2019 at 22:58
2 Answers
Wordpress components use a mix of object orientated programming and procedural programming, but on the whole the software is not built from the ground up according to OO principles.
This is most likely because Wordpress predates PHP's evolution into an object oriented language, and its contributors have elected to maintain an architecture consistent with its earlier versions rather than to completely rebuild and restructure from the ground up. Restructuring would make upgrading websites more difficult, and would require that many plugins and themes be completely rebuilt.
Wordpress's popularity probably has more to do with the ease with which it allows those without programming skills to build a variety of websites and simple web applications, which it does reasonably well from an end user's point of view. It's also remarkably 'hookable' for developers who wish to take advantage of its popularity by building plugins and themes which work on top of Wordpress core code.
There was never a conclave of software engineers who got together and decided which CMS they would champion because of it's pure, clean and beautiful code base. If there was, they probably wouldn't have chosen Wordpress.
A large part of the reasons that WordPress isn't object-oriented is that it started way back (it's about 15 years old) before PHP really supported OOP well. It's also never had the "big rewrite" that allowed Drupal (a similarly old CMS) to be pretty properly OOP in version 8. WordPress as an organization/institution is pretty opposed to "a big rewrite", so I'd guess that WordPress will never really be "a proper OOP system."
As WebSpanner said WordPress's popularity owes almost nothing to it's developer experience, and almost everything to the end-user experience. And for that, the event-driven WordPress hooks based system works well enough. It makes the code a little sloppier, but most WordPress users don't care.
I do also want to highlight (as I did in my fuller article responding to this question) that WordPress does have lots of objects in it. But as you recognize, having objects in it is way different than being "an object oriented system." And while I think WordPress will likely keep having more objects in PHP code, I doubt it's even 10 years (if ever) from being "an object-oriented system."