亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home CMS Tutorial WordPress Speed up Development Using the WordPress Plugin Boilerplate

Speed up Development Using the WordPress Plugin Boilerplate

Feb 17, 2025 pm 12:43 PM

Beginner of WordPress Plugin Development: Using WordPress Plugin Boiler

WordPress plug-in development has a low learning curve and there is no only way to build plug-ins. Plugins can be as simple as Hello Dolly, just a single file; they can also be built in a very complex way based on various needs and functions. The WordPress plugin boilerplate is designed to provide a standardized, high-quality foundation that helps you build your next great plugin. In the first part of this series, we will explore the boilerplate in depth, including the structure of files and folders, as well as the code organization of the boilerplate.

Speed up Development Using the WordPress Plugin Boilerplate

Key Points

  • WordPress plugin boilerplate provides a standardized, high-quality foundation for building WordPress plugins, with a low learning curve, and can be flexibly used for simple or complex plugin structures.
  • The 3.0.0 version of the boilerplate has brought significant improvements in the separation of code organization and internal concerns between plug-ins and can be easily obtained by cloning the git repository or downloading zip files from the GitHub repository.
  • The boilerplate follows recommended WordPress coding and documentation standards, provides useful starter guides and tool recommendations, and includes five default classes for a variety of features, making it an excellent starting point for plugin developers.

Background

The WordPress plugin boilerplate was originally initiated by Tom McFarlin to provide a standardized object-oriented approach to building WordPress plugins. Because boilerplate is built on top of the plug-in API and follows the coding and documentation standards recommended by WordPress, you can be sure that you are in a safe and reliable environment. The boilerplate has recently been updated to version 3.0.0, bringing significant improvements in code organization and further separation of internal focus of plugins. If you are already familiar with developing plugins with legacy boilerplate (v2.6.2), it may take some time to relearn what’s new in the latest version, including the new folder structure. This boilerplate is no longer maintained by Tom McFarlin himself (at the time of writing), and he has passed the baton to Devin Vinson. Development is still continuing as planned, so feel free to report it in your GitHub repository if you have any questions. We also welcome your contribution.

Get a template copy

The easiest way to get a boilerplate copy of the WordPress plugin is to clone the git repository itself.

<code>git clone https://github.com/DevinVinson/WordPress-Plugin-Boilerplate.git</code>

Or you can always download zip files from your GitHub repository. Since version 3.0.0 is released, you cannot simply copy the plugin directly into your wp-content/plugins directory. This is because the actual source code of the plugin is not included in the root directory, but is actually in a subdirectory called trunk. Don't worry about this now, we'll discuss the new folder structure later in this article. The README.md file details a complete description of how to properly install the boilerplate. In short, you can:

  • Copy the trunk directory to the wp-content/plugins folder
  • Copy the entire boilerplate directory and create a symbolic link to wp-content/plugins// for the trunk subdirectory. Creating a symbolic link will depend on the operating system you are using.

After you have done this, you should now find a plugin called WordPress Plugin Boilerplate in the list of plugins in the admin panel, assuming you have not made any modifications to the boilerplate itself. Just activate the plugin and get started!

Customize plug-in with online generator

When activated, you will have a "normal" plugin that basically does nothing -- at least for now. You also need to run search and replace operations on the entire boilerplate code base, which can be very tedious and time-consuming. Fortunately, Enrique Chavez created an unofficial generator that automates the process. Simply visit http://ipnx.cn/link/6340831392e9cd8af9598274f4b3c5c0 and fill in the form at the bottom of the page to generate a personalized copy of the WordPress plugin template.

Folder structure

Let's take a closer look at how WordPress plugin boilerplate 3.0.0 is organized compared to older versions. As mentioned earlier, the actual plugin code is contained in a subdirectory called trunk, not in the root directory. This is to follow the standards used in the official WordPress plugin repository, which contains three main directories: assets, branches, and trunk. The boilerplate already provides two of them: assets and trunk. Here are the complete directories and files included in the boilerplate (at the time of writing):

<code>git clone https://github.com/DevinVinson/WordPress-Plugin-Boilerplate.git</code>

The following is a brief description of the functions of each file and folder:

  • .gitignore: Provides a reasonable default .gitignore for most content that should not exist in the git repository.
  • CHANGELOG.md: Standard change log for boilerplate changes, including the change date.
  • README.md: A useful starter with the installation instructions listed, along with some other parts such as tool recommendations and acknowledgments.
  • assets: This directory contains recommended resources you need to provide when you decide to publish the plugin to the WordPress plugin repository. All images contained in this directory are of the recommended resolution for publication.
  • trunk: This is the actual plugin you are going to develop. There are some folders that divide the code base into administrative and public-facing features. We will explain in detail what each subdirectory means.
    • admin: The directory contains three directories, namely admin, css and js. As the name implies, all management-oriented features should be placed here. By default, partials and plugin-name-admin.js are added to your wp-admin. plugin-name-admin.css will provide common features where you can define management-specific hooks. class-plugin-name-admin.php
    • : This directory is very similar to the functionality provided by the public directory, the only difference is that the admin directory is used to store all public-facing functional code bases. public
    • : A starting languages file where you can provide translation functionality for plugins. .pot
    • : This is probably where almost everything magic happens. By default, there are five starting classes, which we will discuss in the next section. includes
    • : Contains a copy of the GPL v2 license by default. LICENSE.txt
    • : The starting point of the plug-in README file. This file covers all sections that you can further fill in to provide a good plugin page in the WordPress plugin repository. README.txt
    • : The entry point of the plug-in. Here, a common plugin file header is included that you can modify according to your preferences. If you need to include a feature when the plugin is activated and/or deactivated, plugin-name.php and register_activation_hook will also be registered in this file. register_deactivation_hook

Included classes

As mentioned earlier, there are five default classes in the

directory. Let's see what each class does: trunk/includes

  • class-plugin-name-activator.php: This class is instantiated during plug-in activation. It has only one static method activate(), which is registered to register_activation_hook. Use this class whenever you need to perform certain actions when the plugin is activated, such as creating a custom table or saving default options.
  • class-plugin-name-deactivator.php: The corresponding category of class-plugin-name-deactivator.php. It also has only one static method deactivate() that can be used to run any feature during plugin deactivation.
  • class-plugin-name-i18n.php: The starting point of the plug-in i18n function. It has a property $domain that stores plugin text fields. This property can be set using the public method set_domain(). Finally, whenever the plugin is loaded, the load_plugin_textdomain() method in this class is called.
  • class-plugin-name-loader.php: The most important class in the template. It contains two properties $actions and $filters, where all hooks registered in the plugin will be stored. It provides two simple wrapper functions add_action() and add_filter() for adding an action or filter to the $actions and $filters properties. This is not to be confused with WordPress's default add_action() and add_filter() functions, because such classes do not actually register them directly. All hooks will only be registered during another method called run().
  • class-plugin-name.php: A class that glues all parts together. It contains important information about the plugin, such as the plugin name and version. Additionally, it will load the dependencies using the load_dependencies() method, which will contain the above four classes, and the plugin text field will be set using the set_locale() method. All administrative and public hooks registered previously can also be defined here. This class also provides simple get methods such as get_plugin_name() to return the plugin name, get_version() to return the current plugin version, and get_loader() to preserve the instance of class-plugin-name-loader.php.

Conclusion

In short, WordPress plugin boilerplate provides a great starting point for plugin developers. It follows the recommended WordPress coding standards as well as WordPress documentation standards, so you know you're on the right path from the start. Additionally, publishing to a WordPress plugin repository becomes easier because boilerplate already provides most of what you need. Once we are familiar with the code organization and folder structure, we will explore how to develop actual plugins using WordPress plugin boilerplate in the second part of this series.

The above is the detailed content of Speed up Development Using the WordPress Plugin Boilerplate. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72
How to diagnose high CPU usage caused by WordPress How to diagnose high CPU usage caused by WordPress Jul 06, 2025 am 12:08 AM

The main reasons why WordPress causes the surge in server CPU usage include plug-in problems, inefficient database query, poor quality of theme code, or surge in traffic. 1. First, confirm whether it is a high load caused by WordPress through top, htop or control panel tools; 2. Enter troubleshooting mode to gradually enable plug-ins to troubleshoot performance bottlenecks, use QueryMonitor to analyze the plug-in execution and delete or replace inefficient plug-ins; 3. Install cache plug-ins, clean up redundant data, analyze slow query logs to optimize the database; 4. Check whether the topic has problems such as overloading content, complex queries, or lack of caching mechanisms. It is recommended to use standard topic tests to compare and optimize the code logic. Follow the above steps to check and solve the location and solve the problem one by one.

How to minify JavaScript files in WordPress How to minify JavaScript files in WordPress Jul 07, 2025 am 01:11 AM

Miniving JavaScript files can improve WordPress website loading speed by removing blanks, comments, and useless code. 1. Use cache plug-ins that support merge compression, such as W3TotalCache, enable and select compression mode in the "Minify" option; 2. Use a dedicated compression plug-in such as FastVelocityMinify to provide more granular control; 3. Manually compress JS files and upload them through FTP, suitable for users familiar with development tools. Note that some themes or plug-in scripts may conflict with the compression function, and you need to thoroughly test the website functions after activation.

How to optimize WordPress without plugins How to optimize WordPress without plugins Jul 05, 2025 am 12:01 AM

Methods to optimize WordPress sites that do not rely on plug-ins include: 1. Use lightweight themes, such as Astra or GeneratePress, to avoid pile-up themes; 2. Manually compress and merge CSS and JS files to reduce HTTP requests; 3. Optimize images before uploading, use WebP format and control file size; 4. Configure.htaccess to enable browser cache, and connect to CDN to improve static resource loading speed; 5. Limit article revisions and regularly clean database redundant data.

How to use the Transients API for caching How to use the Transients API for caching Jul 05, 2025 am 12:05 AM

TransientsAPI is a built-in tool in WordPress for temporarily storing automatic expiration data. Its core functions are set_transient, get_transient and delete_transient. Compared with OptionsAPI, transients supports setting time of survival (TTL), which is suitable for scenarios such as cache API request results and complex computing data. When using it, you need to pay attention to the uniqueness of key naming and namespace, cache "lazy deletion" mechanism, and the issue that may not last in the object cache environment. Typical application scenarios include reducing external request frequency, controlling code execution rhythm, and improving page loading performance.

How to prevent comment spam programmatically How to prevent comment spam programmatically Jul 08, 2025 am 12:04 AM

The most effective way to prevent comment spam is to automatically identify and intercept it through programmatic means. 1. Use verification code mechanisms (such as Googler CAPTCHA or hCaptcha) to effectively distinguish between humans and robots, especially suitable for public websites; 2. Set hidden fields (Honeypot technology), and use robots to automatically fill in features to identify spam comments without affecting user experience; 3. Check the blacklist of comment content keywords, filter spam information through sensitive word matching, and pay attention to avoid misjudgment; 4. Judge the frequency and source IP of comments, limit the number of submissions per unit time and establish a blacklist; 5. Use third-party anti-spam services (such as Akismet, Cloudflare) to improve identification accuracy. Can be based on the website

How to enqueue assets for a Gutenberg block How to enqueue assets for a Gutenberg block Jul 09, 2025 am 12:14 AM

When developing Gutenberg blocks, the correct method of enqueue assets includes: 1. Use register_block_type to specify the paths of editor_script, editor_style and style; 2. Register resources through wp_register_script and wp_register_style in functions.php or plug-in, and set the correct dependencies and versions; 3. Configure the build tool to output the appropriate module format and ensure that the path is consistent; 4. Control the loading logic of the front-end style through add_theme_support or enqueue_block_assets to ensure that the loading logic of the front-end style is ensured.

How to add custom fields to users How to add custom fields to users Jul 06, 2025 am 12:18 AM

To add custom user fields, you need to select the extension method according to the platform and pay attention to data verification and permission control. Common practices include: 1. Use additional tables or key-value pairs of the database to store information; 2. Add input boxes to the front end and integrate with the back end; 3. Constrain format checks and access permissions for sensitive data; 4. Update interfaces and templates to support new field display and editing, while taking into account mobile adaptation and user experience.

How to optimize WordPress robots txt How to optimize WordPress robots txt Jul 13, 2025 am 12:37 AM

robots.txt is crucial to the SEO of WordPress websites, and can guide search engines to crawl behavior, avoid duplicate content and improve efficiency. 1. Block system paths such as /wp-admin/ and /wp-includes/, but avoid accidentally blocking the /uploads/ directory; 2. Add Sitemap paths such as Sitemap: https://yourdomain.com/sitemap.xml to help search engines quickly discover site maps; 3. Limit /page/ and URLs with parameters to reduce crawler waste, but be careful not to block important archive pages; 4. Avoid common mistakes such as accidentally blocking the entire site, cache plug-in affecting updates, and ignoring the matching of mobile terminals and subdomains.

See all articles