WordPress deeply relies on third-party JavaScript and PHP libraries, among which jQuery is the most widely used JavaScript library, and the PHP library is mainly composed of single class files. Other JavaScript libraries used include jQuery Masonry, jQuery Hotkeys, jQuery Suggest, jQuery Form, jQuery Color, jQuery Migrate, jQuery Schedule, jQuery UI, Backbone, colorpicker, hoverIntent, SWFObject, and TinyMCE.
WordPress's third-party library is located in the wp-includes
and wp-admin
folders along with WordPress files. The PHP library is named after class-*.php
or is located in its own folder, while the JavaScript files are located in the js
folder under these folders. The CSS file is mainly a jQuery or TinyMCE CSS file, located in the CSS folder under the include folder.
While these libraries enhance the functionality and user experience of WordPress, many are outdated, which has sparked discussions about architecture and potential improvements such as Bower and Composer integration into WordPress. Understanding these libraries can make you smarter, more efficient in using WordPress and potentially contribute to its core.
Almost all modern software (including platforms such as WordPress) rely on third-party libraries. This is because, as developers, we don't need to reinvent the wheel.
If I have to develop software that uses HTTP abstraction, I might use Symfony HttpKernel or similar packages. If my software needs more features (which is unlikely, by the way, but let's assume this in the example), I can extend the package, or in the worst case, create one from scratch. Creating from scratch is not a bad thing. It's actually a good thing because it makes you a better developer. But usually, in most modern projects, you have to rely on third-party libraries (or packages). In this article, we will look at various third-party JavaScript and PHP libraries used by WordPress.
In WordPress, third-party libraries exist together with WordPress files. To better understand the structure of files in WordPress, the WordPress codebase page will provide you with some answers. The wp-includes
folder contains some libraries that are included when the application is executed. Also, in wp-admin
you will find the second include folder, which works the same as the first one. In both folders, you will find the PHP and JavaScript files.
Third-party PHP libraries are named after class-*.php
(single files) or are located in their own folder. Other PHP files named class-*.php
may be WordPress files (rather than third-party files). The PHP file is located in the wp-include
or wp-admin/include
folder.
JavaScript files are also located under these folders, but they are grouped in js
folders.
CSS files are mainly jQuery or TinyMCE CSS files, located in the CSS folder under the include folder.
Let's start with the JavaScript library. WordPress uses jQuery heavily. It uses:
You may notice that some of these libraries have no links. This is because some of these libraries are very old and the repository no longer exists. Let's check them one by one.
jQuery is a well-known library that requires no introduction.
jQuery Masonry is a plugin that makes it easier to create masonry layouts like this:
Creating such a layout from scratch is a bit difficult, jQuery Masonry makes this easy.
jQuery Hotkeys Shortcut keys for processing browsers. If you are used to using tools like StackEdit.io, you may use "ctrl s" (command s) to save files on gDrive or other cloud providers. The default (ctrl s) shortcuts in the browser can be used to save web pages, and using this plugin you can override these default shortcuts.
jQuery Form handles forms and AJAX calls. If you are curious and want to learn more about this plugin, you can check out its documentation.
jQuery Color is used by WordPress for color manipulation and animation.
jQuery("#go").click(function(){ jQuery("#block").animate({ backgroundColor: "#abcdef" }, 1500 ); });
The first line selects the element with which it has and tells the browser that it should animate the background color of the element with which it has in 1.5 seconds.
jQuery Migrate can help you when dealing with early jQuery code bases. This is very important for WordPress because it is a platform that should be backward compatible.
In fact, backward compatibility is one of WordPress's most famous features. On the other hand, this is also one of the problems with WordPress. WordPress was released in 2003 and the PHP version used was outdated. Today, PHP is a modern language that draws on many useful features of other languages. But this is another topic, and it will be discussed in future articles.
WordPress also uses other JavaScript libraries, not just jQuery. Here are some other popular libraries it uses:
and so on.
The most famous ones on this list are TinyMCE and Backbone. TineMCE is used to write new posts and pages in WordPress dashboard.
Backbone is a front-end framework, and in fact it is one of the first ones. It is still in use today, but is losing a lot of market share in Angular and other front-end frameworks. Yes, I'm telling you, Meteor. But don't worry, in the JavaScript world, frameworks (libraries) are forgotten as quickly as they are popular.
The list of PHP libraries is slightly different. We see that JavaScript is mainly influenced by jQuery and some other popular libraries. For PHP, the situation is different because most third-party libraries are just a class (file). Here is a short list of current third-party PHP libraries:
Many libraries are a bit outdated. At this time, discussions on topics such as architecture often occur. I personally want to see Bower and Composer integrate with WordPress. I want to ask the SitePoint community about these ideas and have a public discussion on how to improve WordPress. Please leave your comments and thoughts below.
In this article, we see the various third-party libraries used by WordPress. Learn what WordPress is used behind the scenes and you will have a better understanding of how it works. The better you understand, the faster and more efficient you can use WordPress. Maybe you can even work hard to contribute to WordPress core. After all, this is an open source world where we learn from each other and share ideas (code and pizza!).
WordPress uses multiple JavaScript libraries to enhance its functionality and user experience. The most commonly used libraries include jQuery, Backbone.js, and Underscore.js. jQuery is a fast, compact and feature-rich JavaScript library that simplifies HTML document traversal, event processing, and animation, allowing for fast web development. Backbone.js provides structure for web applications by providing a model with key-value binding and custom events. Underscore.js is a utility library that provides support for commonly used functional programming without extending any core JavaScript objects.
The PHP library is a collection of classes and functions used to perform specific tasks in WordPress. They help enhance the functionality of WordPress by providing pre-written code to perform common tasks, saving developers time and effort. For example, PHPMailer is a code base for sending emails safely and easily through PHP code on a web server. Similarly, SimplePie is a PHP library that can read RSS and Atom feeds.
There are several ways to add JavaScript to your WordPress site. One of the most commonly used methods is to use the wp_enqueue_script
function. This function contains the specified JavaScript file in the page. Another way is to add JavaScript code directly to your theme file. However, this method should be used with caution, as it can cause problems if not properly operated.
There are several PHP libraries that can help with WordPress development. Some of the most popular libraries include Guzzle (a PHP HTTP client that makes sending HTTP requests easy and easy to integrate with web services); Carbon (a simple PHP API extension for DateTime); and Monolog (it has Helps create logs).
Yes, you can use third-party JavaScript libraries in your WordPress website. However, be sure to make sure that the library does not conflict with any existing scripts on the website. Additionally, trusted sources should always be used when downloading third-party libraries to avoid security issues.
PHP libraries in WordPress websites can be updated by downloading the latest version of the library and replacing the old files with new ones. However, be sure to back up your website before making any changes to avoid losing any data.
There are several WordPress plugins that can help manage media files. Some of the most popular plugins include WP Media Folder (which allows you to organize media files in folders) and Smush (which helps optimize and compress images).
JavaScript can be added to a WordPress post or page by using a custom HTML block in the Gutenberg editor. Simply paste your JavaScript code into the block and it will be included in the page when viewing it.
Using JavaScript and PHP libraries in WordPress can greatly enhance the functionality and user experience of your website. They can help simplify complex tasks, improve performance, and provide other features that are difficult to implement from scratch.
While JavaScript and PHP libraries can provide many benefits, they can also pose risks if used incorrectly. For example, using outdated or poorly maintained libraries can lead to security vulnerabilities. Additionally, using too many libraries can negatively affect the performance of your website. Therefore, be sure to use the library carefully and keep it up to date.
The above is the detailed content of JavaScript and PHP Libraries Used by WordPress. For more information, please follow other related articles on the PHP Chinese website!