如果在插件激活时未设置,请更新永久链接


Update permalinks if not set at the time of plugin activation

>激活插件后,我需要将永久链接设置为与默认值不同的我使用 get_option('permalink_structure') 来检查永久链接是否已设置......

这是插件激活函数中使用的代码块,我用的是类结构

 if (get_option('permalink_structure'))
    {
        $this->setRewriteRules();
        global $wp_rewrite;
        $wp_rewrite->flush_rules(true);
    }

这是serRewriteRules函数

function setRewriteRules()
{
    add_rewrite_rule('plugin-url/$', '/wp-content/plugins/my-plugin/page.php', 'top');
}

搜索了很多次并更新了我的代码很多次,但仍然对我不起作用....

而不是动态更改永久链接,您可以使用从WP永久链接生成链接功能。

例如

get_the_permalink()
the_permalink()
get_post_type_archive_link()