awsm / wp-plugin
出色的WP插件
dev-main
2022-06-16 07:32 UTC
This package is auto-updated.
Last update: 2024-09-16 12:47:21 UTC
README
这是一个小助手,可以帮助您更快地开始使用WordPress插件。
安装
使用composer将助手添加到您的插件中。
composer require awsm/wp-plugin
在代码中使用(示例插件)
这是一个使用WP_Plugin父类创建的插件的示例。看起来什么都没有,但在后台会检查插件头部信息,这些信息不需要再次检查。
目前进行以下测试,如果要求未满足,将在管理员界面显示错误信息
- 最低PHP要求
- 最低WordPress要求
还会加载Textdomain,如果无法加载,则会在后台出现错误。
如果没有在插件文件中设置该参数,则不会进行检查。
<?php /** * Plugin Name: Example Plugin * Description: Test Plugin for WP Plugin class. * Requires PHP: 7.0.0 * Requires at least: 6.0.0 * Domain Path: /langauges * Text Domain: wp-plugin */ namespace AWSM\WP_Plugin; require dirname( __DIR__ ) . '/vendor/autoload.php'; use AWSM\WP_Plugin\Plugin; class ExamplePlugin extends Plugin { /** * load() is the method which will be executed after * all checks have been passed and Text domain was loaded. * * The method is mandatory. */ public function load() { add_action('admin_notices', [$this, 'show_notice']); } /** * Just an example. */ public function show_notice() { ?> <div class="notice notice-success is-dismissible"> <p><?php _e( 'Done!', 'sample-text-domain' ); ?></p> </div> <?php } public function activate() { // Activation code here } public function deactivate() { // Deactivation code here } } new ExamplePlugin();