For Developers of WordPress plug-ins and templates.
Problems encountered by our team are often caused by third-party plug-ins or pure coded templates for WordPress on users sites. Thereby all developers, who are somehow connected with the development for WordPress environment – plug-ins creators or templates coders – we call you to ad here a few simple rules in your work that will help to improve the overall picture of the development for WordPress. Here they are:
- Do not connect external jquery libraries. Very often in the source code of the site we can see something like:
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></ script>
And here are a few problems. Firstly – the version of library here can be any, and differs from the version that is supported by WordPress – and hence other plug-ins. Secondly, there is no
If you use jquery in your work – connect the library solely from within:
Moreover, in the arsenal of WordPress there are already quite a lot of libraries. And before connecting required library from outside of WordPress – it is better to check, is there anything you need inside WordPress? We try to do this all the time, for example – we use “native” libraries like jquery-ui-dialog, jquery-ui-slider, etc.
wp_enqueue_style ('bootstrap', your path)
All other developers, who also want to use this popular library, will see only your modified styles, and as a consequence – their code will not work correctly (i.e. “nothing will work on the user’s site”). It is better to connect it as
wp_enqueue_style ('custom.modified, bootstrap', your path)
and the contents of the modified styles – enclose in the special shell – like the parent
<div id = "bsCustomContent">
– and in your modified css all styles of this library will only be applied for child elements of #bsCustomContent – so you will be sure that you will not damage anything else on this site.
- If you connect popular PHP libraries – make sure that the library was not connected before your script. For example, the Mobile_Detect library is frequently used to determine the user’s device on the server side – and many developers, without hesitation, connect it as:
At the same time the same library could have already been connected earlier with another plug-in or template. Therefore, before connecting external libraries, make sure that it was not connected before:
If (!class_exists ('Mobile_Detect')) require_once ('Mobile_Detect.php');
Again, it is best to connect any libraries only when they are actually used (same as p.2 – but for PHP). For example, in the code it is often possible to see the connection of all libraries at once – when loading the plug-in, but their use in the future in the plug-in is determined by a number of conditions – and it is not always necessary. It is best to use the Lazy Load pattern to connect your libraries: you will not overload the server memory, and make your application faster and more stable.
And lastly – remember that WordPress is a huge platform with a huge number of plug-ins and templates for it. Write your code so that it does not interfere with other developers, respect each other.