Home> CMS Tutorial> WordPress> body text

Perform WordPress plug-in development - create, deactivate, delete plug-ins

藏色散人
Release: 2021-02-23 15:32:32
forward
3132 people have browsed it

The following tutorial column ofWordPresswill introduce you to WordPress plug-in development-creating, deactivating, and deleting plug-ins. I hope it will be helpful to friends in need!

Perform WordPress plug-in development - create, deactivate, delete plug-ins

Plug-in storage directory

wp-content/plugins

Create a plug-in

Create in plugins For a file plug-in folder, it is best to add a prefix to the name. This prefix can use your name or your own domain name to prevent the plug-in from having the same name as others. Then create a PHP file with the same name as your plug-in.
I create a plug-in called yg-footer-copyright here.

Let WordPress recognize our plug-in

After creating the plug-in, the WordPress backend cannot recognize our plug-in. That is because we did not write the plug-in information according to its standards.

Write the plug-in information in the header of your plug-in entryyg-footer-copyright.phpfile.

Copy after login

At this time, you can see the plug-in you created by looking at the WordPress backend.

Method called when the plug-in is enabled

Throughregister_activation_hookthis method can add a callback when the plug-in is enabled.

Official document: https://codex.wordpress.org/F...

function ygcopyright_install() { update_option("yg-copyright","

版权信息

"); } //启用插件时调用的方法 register_activation_hook( __FILE__, 'ygcopyright_install' );
Copy after login

Here we add a yg-copyright field in the option table at startup.

Method called when the plug-in is deactivated

Throughregister_deactivation_hookthis method can add a callback when the plug-in is deactivated.

Official document: https://codex.wordpress.org/F...

function ygcopyright_stop(){ update_option("yg-copyright","yes"); } //停用插件时的方法 register_deactivation_hook( __FILE__, 'ygcopyright_stop' );
Copy after login

Here we change the yg-copyright field in the option table to yes when deactivating.

Operation when deleting the plug-in

When the plug-in is deleted, by default, theuninstall.phpfile will be found in the plug-in directory and the methods in it will be called.

Copy after login

Here we’d better add in theuninstall.phpfile header to determine whether it is called by WordPress background, to prevent others from calling this file directly and delete the plug-in.
Here we delete the yg-copyright field in the option table when deactivating.

If you have any questions, please leave a message.

The above is the detailed content of Perform WordPress plug-in development - create, deactivate, delete plug-ins. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!