我是新插件wordpress。我有問題訪問WordPress插件的正確方法是什麼?比方說,在我的插件中,我需要創建端點來處理不同的回調。我已經嘗試了許多搜索結果,但不起作用。我不知道什麼是錯的。請幫忙。如何使用URL重寫規則來處理WordPress插件中的路由
<?php
/*
Plugin Name: MyPlugin
Description: MyPlugin
Author: Myself
Author URI:
Version: 1.0
License:
License URI:
*/
class MyPlugin {
private static $instance;
public static function getInstance() {
if(self::$instance == NULL) {
self::$instance = new self();
}
return self::$instance;
}
private function __construct() {
add_action('init', array($this, 'set_endpoint'));
}
function set_endpoint() {
add_rewrite_rule('callback/$', plugin_dir_url(__FILE__) . 'callback.php', 'top');
}
static function activate() {
global $wp_rewrite;
$wp_rewrite->flush_rules(true);
}
}
MyPlugin::getInstance();
register_deactivation_hook(__FILE__,'flush_rewrite_rules');
register_activation_hook(__FILE__,'MyPlugin::activate');
callback.php
<?php echo '<h1> Hello </h1>'; ?>