It seems like register_activation_hook issues are a right of passage. I've spent far longer than I'd care to admit trying to get this to work. So, I have a plugin class that creates a post type and sets up rewrite rules on 'init'. I'm simply trying to use register_activation_hook to flush the rewrite rules so that my permalinks to the new type will work. When activate the plugin, the post type shows up but the permalinks don't work UNLESS I add "flush_rewrite_rules( false );" to the end of my 'init' function that creates the post type.
Thanks in advance. I'm burnt. I've tried every permutation I've seen referenced.
if (!class_exists('wanted')) {
class wanted {
function __construct(){
add_action("init", array(&$this,"create_post_type"));
add_action("admin_init", array(&$this,"admin_init"));
add_post_type_support( 'page', 'excerpt' );
register_activation_hook( __FILE__, array(&$this, 'wanted_activate') );
register_deactivation_hook( __FILE__, array(&$this, 'wanted_deactivate') );
}
/**
* Custom Post type for Wanted Fugitives
*/
static function create_post_type() {
register_post_type('wanted', array(
'labels' => array(
'name' => 'Wanted Fugitives',
'singular_name' => 'Wanted',
'add_new' => 'Add new fugitive',
'edit_item' => 'Edit fugitive',
'new_item' => 'New fugitive',
'view_item' => 'View fugitive',
'search_items' => 'Search Wanted Fugitives',
'not_found' => 'No fugitives found',
'not_found_in_trash' => 'No fugitives found in Trash'
),
'rewrite' => array('slug' => 'fugitives'),
'public' => true,
'hierarchical' => true,
'supports' => array(
'title',
'editor',
'page-attributes',
'thumbnail',
'revisions'
)
));
// flush_rewrite_rules( false ); /* This works, but is BAD */
}
static function wanted_activate() {
self::create_post_type();
flush_rewrite_rules( false ); /* This doesn't work */
}
function wanted_deactivate() {
flush_rewrite_rules( false );
}
} //End Class
} //End if class exists statement
if (class_exists('wanted')) {
$wanted_var = new wanted();
// register_activation_hook( __FILE__, array('wanted', 'wanted_activate') ); /* This did not work either */
}