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

I need permalink to be set different from default after the plugin is activated I used get_option('permalink_structure') to check if permalink already set or not...

Here is the code block used in plugin activation function , I used class structure

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

and here is the serRewriteRules function

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

I searched a lot and update my code so many time but still not working for me ....

rather than changing permalink dynamically you can use generate link from WP permalinks function

for e.g.

get_the_permalink()
the_permalink()
get_post_type_archive_link()