[wp-hackers] Custom Post Types Clean-Up

Dobri dyordan1 at ramapo.edu
Tue May 21 14:29:01 UTC 2013


Sorry for all the noise on the list, if someone could take a look at the very bare-bones plugin I wrote and give me a second opinion, that would be great:

Activate the plugin below, go to localhost/custom or wherever your test site is and you should see a no results found page, which is fine, since there are no posts of that type.
Deactivate it and instead of a 404, you get your homepage. Add whatever you want without any slashes after custom/ and you still get that. Add something with a slash - 404.
Activate another plugin that flushes rules on activation or flush_rewrite_rules yourself somehow and voila - 404 on that localhost/custom.

That doesn't seem normal and I'm going crazy trying to debug it.

<?php
/**
 * @package Test
 * @version 0.1b
 */
/*
	Plugin Name: Custom Content
	Plugin URI: http://www.ramapo.edu/
	Author: Gingerbread Man
	Version: 0.3b
	Description: Enables the creation/management of Custom Content
*/

function custom_activation()
{
	remove_action( 'init', 'custom_init');

	custom_init();

	flush_rewrite_rules();
}

function custom_deactivation()
{
	flush_rewrite_rules();
}

function custom_init()
{
	//set labels
	$typeLabels = array(
		'name' => 'Custom Content',
		'singular_name' => 'Custom Content',
		'all_items' => 'List All',
		'add_new_item' => 'Add New Content',
		'not_found' => 'No content found',
		'edit_item' => 'Edit Content',
		'new_item' => 'New Content',
		'view_item' => 'View Content',
		'search_item' => 'Search Content',
		'not_found_in_trash' => 'No content found in Trash.'
	);
	
	//set arguments
	$typeArgs = array(
		'public' => true,
		'labels' => $typeLabels,
		'description' => 'Add Custom Content.',
        'supports' => array('thumbnail','title','editor'),
		'map_meta_cap' => true,
		'capability_type' => array('custom_stuff', 'custom_stuffs'),
		'has_archive' => true
	);
	
	//register
	register_post_type('custom', $typeArgs);
}

add_action( 'init', 'custom_init');

register_activation_hook( __FILE__, 'custom_activation');

register_deactivation_hook( __FILE__, 'custom_deactivation');

?>

Thanks!

~Dobri

On Tue, 21 May 2013, at 9:28 AM, Dobri wrote:

> OK, so update:
> 
> On Twenty Twelve, at least when I enable the above-mentioned empty plugin, clean up is complete. However, it is still not sufficient to register a deactivation hook that runs flush_rewrite_rules. So, is there a more appropriate place to flush the rules to make sure everything is cleaned up?
> 
> P.S. this is how I register my function that contains the flush_rewrite
> register_deactivation_hook( __FILE__, 'clean_up');
> 
> ~Dobri
> 
> On Tue, 21 May 2013, at 8:54 AM, Dobri wrote:
> 
>> Hey Marko,
>> 
>> Yes, I know that, sorry I forgot to mention it. I have a activation hook for the plugin that runs init and flushes rules and a deactivation hook that runs just flush rules. Still, after deactivation, the issue I described is still there. I know that the code runs since I'm tracing to the error log when the activate/deactivate functions are called. I've also tried having another empty plugin with just flush_rewrite_rules in activate/deactivate and then once I've deactivated the original "custom" post type plugin, activate the other one so it's activate function flushes the rules. Even then, way after the original plugin has been deactivated and after three flush_rewrites, the same issue is observed. I'm testing it on twenty eleven now to convince myself it's not a theme-specific issue.
>> 
>> Thank you!
>> 
>> ~Dobri
>> 
>> On Mon, 20 May 2013, at 5:13 PM, Marko Heijnen wrote:
>> 
>>> Hey Dobri,
>>> 
>>> You still need to refresh the rewrite rules on plugin activation/deactivation: http://codex.wordpress.org/Function_Reference/flush_rewrite_rules
>>> 
>>> Marko
>>> 
>>> 
>>> Op 20 mei 2013, om 22:55 heeft Dobri <dyordan1 at ramapo.edu> het volgende geschreven:
>>> 
>>>> Hey,
>>>> 
>>>> I might be missing something but I've been doing a lot of custom post_types recently and clean up seems to be a huge pain. Here's the deal:
>>>> 
>>>> I have a plugin that uses register_post_type in an init hook to do the initial setup of a post type (call it "custom").
>>>> Let's say for argument's sake I wanna focus on a page - http://mysite.com/custom/potato/.
>>>> I type that in before ever enabling the plugin and it's a 404.
>>>> I enable the plugin, play around with it, create a potato page.
>>>> Now http://mysite.com/custom/potato/ links to that page and all is good.
>>>> Now I disable the plugin.
>>>> I try http://mysite.com/custom/potato and now instead of a 404, I get the home page displayed while the url stays the same.
>>>> In fact, http://mysite.com/custom/[anything]/ will also result in the homepage being displayed without modifying the url.
>>>> 
>>>> Question: Is it just my setup and I should start disabling stuff or is that normal behavior? If it is, shouldn't we do something about it?
>>>> 
>>>> Thanks!
>>>> ~Dobri
>>>> 
>>>> _______________________________________________
>>>> wp-hackers mailing list
>>>> wp-hackers at lists.automattic.com
>>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>> 
>>> _______________________________________________
>>> wp-hackers mailing list
>>> wp-hackers at lists.automattic.com
>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>> 
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
> 
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list