admin管理员组文章数量:1316691
I have created a plugin that register a new CPT but it doesnt work because i have to flush_rewrite_rules()
(i can do this by going into the permalink setting page and save, but its not the right way)
I have read inside the wordpress codex that i have to flush_rewrite_rules()
on activation, but its not working cuz flush_rewrite_rules()
runs before i register the CPT, to work it must run after...
I am using this
And it has a class that runs on activation of the plugin i have added there this flush_rewrite_rules()
Edit
The boilerplate i have used is already structured with activation/deactivation classes, for example
function activate_l_erbario() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-l-erbario-activator.php';
L_Erbario_Activator::activate();
register_activation_hook( __FILE__, 'activate_l_erbario' );
and inside class-l-erbario-activator.php i have
class L_Erbario_Activator {
public static function activate() {
}
}
GITHUB WITH THE PLUGIN
/admin/class-l-erbario-admin.php -> here i register the CPT
/includes/class-l-erbario.php -> and here i add the add_action with the CPT
I have created a plugin that register a new CPT but it doesnt work because i have to flush_rewrite_rules()
(i can do this by going into the permalink setting page and save, but its not the right way)
I have read inside the wordpress codex that i have to flush_rewrite_rules()
on activation, but its not working cuz flush_rewrite_rules()
runs before i register the CPT, to work it must run after...
I am using this https://github/DevinVinson/WordPress-Plugin-Boilerplate
And it has a class that runs on activation of the plugin i have added there this flush_rewrite_rules()
Edit
The boilerplate i have used is already structured with activation/deactivation classes, for example
function activate_l_erbario() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-l-erbario-activator.php';
L_Erbario_Activator::activate();
register_activation_hook( __FILE__, 'activate_l_erbario' );
and inside class-l-erbario-activator.php i have
class L_Erbario_Activator {
public static function activate() {
}
}
GITHUB WITH THE PLUGIN
https://github/NeaMitika/CPT-Erbario-Wordpress
/admin/class-l-erbario-admin.php -> here i register the CPT
/includes/class-l-erbario.php -> and here i add the add_action with the CPT
Share Improve this question edited Nov 5, 2020 at 10:12 NeaMitika asked Nov 3, 2020 at 12:08 NeaMitikaNeaMitika 13 bronze badges 8 | Show 3 more comments1 Answer
Reset to default 0After a couple of days trying and trying and trying... i asked a youtuber who develops using the same Wordpress Plugin Boilerplate and he pointed me to this article:
https://andrezrv/2014/08/12/efficiently-flush-rewrite-rules-plugin-activation/
It adds an option inside_option table and it will flush rewrite rules based on that :) It worked perfectly
本文标签:
版权声明:本文标题:How to run flush_rewrite_rules on activation after i register my custom post type using Wordpress Boilerplate Plugin 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742005907a2411947.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
flush_rewrite_rules()
onto something such asadmin_init
, rather than call it directly – cameronjonesweb Commented Nov 3, 2020 at 13:32