Home>Article>CMS Tutorial> Perform WordPress plug-in development - create, deactivate, delete plug-ins

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

藏色散人
藏色散人 forward
2021-02-23 15:32:22 3142browse

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.

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' );

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' );

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.

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!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete