johngodley/redirection

Disable URL monitor for custom post types without URLs

Closed this issue · 3 comments

The URL Monitor section of the settings panel offers to monitor for redirects on post types that don't have permalinks. We have some post types that do not have permalinks generated and are not publicly accessible directly, but Redirection still offers to monitor them for redirects.

Can you give an example?

Here's the CPT in question:

add_action( 'init', function() {
	register_post_type( 'testimonial', array(
		'labels' => array(
			'name' => 'Testimonials',
			'singular_name' => 'Testimonial',
			'menu_name' => 'Testimonials',
			'all_items' => 'All Testimonials',
			'edit_item' => 'Edit Testimonial',
			'view_item' => 'View Testimonial',
			'view_items' => 'View Testimonials',
			'add_new_item' => 'Add New Testimonial',
			'add_new' => 'Add New Testimonial',
			'new_item' => 'New Testimonial',
			'parent_item_colon' => 'Parent Testimonial:',
			'search_items' => 'Search Testimonials',
			'not_found' => 'No testimonials found',
			'not_found_in_trash' => 'No testimonials found in Trash',
			'archives' => 'Testimonial Archives',
			'attributes' => 'Testimonial Attributes',
			'insert_into_item' => 'Insert into testimonial',
			'uploaded_to_this_item' => 'Uploaded to this testimonial',
			'filter_items_list' => 'Filter testimonials list',
			'filter_by_date' => 'Filter testimonials by date',
			'items_list_navigation' => 'Testimonials list navigation',
			'items_list' => 'Testimonials list',
			'item_published' => 'Testimonial published.',
			'item_published_privately' => 'Testimonial published privately.',
			'item_reverted_to_draft' => 'Testimonial reverted to draft.',
			'item_scheduled' => 'Testimonial scheduled.',
			'item_updated' => 'Testimonial updated.',
			'item_link' => 'Testimonial Link',
			'item_link_description' => 'A link to a testimonial.',
		),
		'public' => true,
		'publicly_queryable' => false,
		'show_in_nav_menus' => false,
		'show_in_admin_bar' => false,
		'show_in_rest' => true,
		'menu_position' => 35,
		'menu_icon' => 'dashicons-awards',
		'supports' => array(
			0 => 'title',
			1 => 'editor',
			2 => 'thumbnail',
			3 => 'custom-fields',
		),
		'rewrite' => false,
		'delete_with_user' => false,
	) );
} );

We just use it to tag testimonials with different clients/industries and pull those in on the appropriate pages, so there's no need to generate permalinks for them. In the backend it never shows a "view post" link anywhere:
CleanShot 2024-10-07 at 16 53 02

However, Redirection still offers to monitor changes:
CleanShot 2024-10-07 at 16 57 28

I imagine you could check and see if the rewrite is set to false in the registration args?

Interesting, thanks. I'll include something in the next version for this.