I’ve seen WordPress themes and plugins that had files in their assets directory that were already in the WordPress core files (e.g., jQuery or Color Picker). ![]() Not Leveraging Existing WordPress Core Functionality to Its True PotentialĪs WordPress comes with a suite of regularly updated libraries that can be just called in our plugins and themes, it’s best to just make use as much as possible of the existing core functionality. Also, the code has to be indented in order to be read, especially if it has nested code (e.g., IFs within IFs, nested FOREACHs and FORs). ![]() For instance, it’s always best to use single quotes (instead of double ones) if you’re not evaluating anything in the string. Note that some rules are universally applied in order to improve performance, disregarding the coding style. In case you have to extend an existing plugin or theme that already follows the PHP coding standards for WordPress, then it’s best to stick with them in order to have a consistent style so the code becomes clean and easy to read. I’d recommend a good understanding of namespaces before using them as they can often be used in the wrong way.ĭepending on the project that you’ll take on board, it’s likely that you’ll have to stick with the existing coding style, unless your work is mostly separate from the existing one. With this, I can read and manage the code easily without having to worry much about having long unique names. This one is my favorite since I often develop themes or plugins that have a lot of code. ![]() Ability to alias (or shorten) Extra_Long_Names designed to fix the first problem or improving readability of source code.Name collisions between the code they create, and internal PHP, or third-party, classes, functions, or constants.There are developers, on the other hand, who prefer to use PHP namespaces to encapsulate items and solve the two problems authors of libraries and applications encounter when creating reusable code elements such as classes or functions: Beside eliminating code conflict, it also makes things easier to find when you have lots of plugins enabled. That’s why many developers prefix their variables and function names with something unique and related to the plugin itself. When developing a plugin, it’s better to use a naming convention that prevents code conflict in case there are other plugins using the same name. Using Names That Are Too Common for Variables, Functions, Constants, or Classes Sure, the file can be split into multiple ones and enqueued in WordPress, but if at some later point, the website administrator performs an update of the theme’s main.js file, then the whole process has to start all over again.Ģ. It makes managing the code inside the file more difficult, as you can’t use functions such as wp_dequeue_script() to unload some of the code in some pages to either improve the page speed or to prevent a conflict with other JavaScript code that could be loaded by one of the active plugins. ![]() This will make pages take longer to download and slower to render, especially if it’s render blocking code within the head section of the page. The file will be loaded site-wide even if only 10% of the code from the file is needed in some pages.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |