Inside wordpress: notes about common variables and functions to add extra features

wordpress architecture structure guideI’ve recently used wordpress to make some simple web sites. WordPress is a very fast solution when creating a blog or a site of which the requirements are just a subset of the wordpress features.

What we can do with wordpress: fixed pages, site news (that are blog posts), simple search, multi-level page and news content management, WYSIWYG editor, changeable themes, lots of free themes already available, url rewriting etc…).

Sometimes we need to extra customize the frontend aspect of the site/blog, and we have to modify the standard behaviour of wordpress. It needs to know a little how its atchitecture, how it works and some of its functions.

Obsolete architecture

Since the first wordpress was released on 2003, its architecture is still using a non OOP style and it has nothing to do with a modern framework, nor a MVC application. Lots of informations are kept in global variables and there are thousand of functions.

Folllowing, some my notes about its architeecture, in order to speed up any type of structural change or extra customization.
Continue reading

sessions vs cookies with load balancer

It’s a well known fact that HTTP is a stateless protocol and cookies are needed to keep the communication session.

When dealing with sessions with PHP, we have two main solutions:

– set manual cookies
One approach is using directly the PHP functions to set the cookies. When possible I don’t use manual cookies(except than keeping an hash string for the user identity or keep the session after the browser is closed) as there are lots of issues (datas kept in the user browser so they have to be validated at each request, difficulty to store complex datas, browser compatibility or partial cookie blocking etc…).

– session functions
A much easier approach is using the session functions. The session is automatically managed by PHP and the superglobal array $_SESSION is available with persistent user datas, thanks to the session cookie automatically managed.
Advantages: data stored in the server, easy to save arrays and custom objects, superglobal array immediately available and semplicity in writing the code.
Disadvantages: not possible to keep it after the browser closes (except a custom save handler on disk or db) , not possible to specify URL path and domain for the session.

– server balancer issues -> cookies !
Today we had some issue with our server load balancer. We realize that it didn’t support sticky sessions, so at every redirect (also to the same page because of some rules) the session datas (kept through session functions) were deleted. In order to meet a deadline, we set a manual cookie to keep the data needed.