Docs on registering CPT on plugin activation hook
-
Hello, I’m trying to understand the plugin handbook example on registering a custom post type inside the activation hook:
/** * Register the "book" custom post type */ function pluginprefix_setup_post_type() { register_post_type( 'book', ['public' => true ] ); } add_action( 'init', 'pluginprefix_setup_post_type' ); /** * Activate the plugin. */ function pluginprefix_activate() { // Trigger our function that registers the custom post type plugin. pluginprefix_setup_post_type(); // Clear the permalinks after the post type has been registered. flush_rewrite_rules(); } register_activation_hook( __FILE__, 'pluginprefix_activate' );
Why is the
pluginprefix_activate
function callingpluginprefix_setup_post_type
if this is already being added toinit
with theadd_action
function?The example works the same if the function is not called inside
pluginprefix_activate
so this is confusing me. I understand that is important to callflush_rewrite_rules
on activation but notpluginprefix_setup_post_type
Any ideas?
Thank you.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Docs on registering CPT on plugin activation hook’ is closed to new replies.