Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 9 months ago

#31073 closed enhancement (duplicate)

Add new filter on function register_post_type

Reported by: teolaz's profile teolaz Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.1
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

Hi guys, i'm implementing a plugin for rewriting post slugs.
i noticed that reading the source code of the register_post_type function, there is no filter before the args are parsed. It could be usefull to have the filter to modify some custom post types on the fly. The 'registered_post_type' filter act only after the permastruct and the rewrite rules are done.
So for example you could act as above inside the register_post_type function:

if ( strlen( $post_type ) > 20 ) {
		_doing_it_wrong( __FUNCTION__, __( 'Post types cannot exceed 20 characters in length' ), '4.0' );
		return new WP_Error( 'post_type_too_long', __( 'Post types cannot exceed 20 characters in length' ) );
	}

apply_filters( "registering_post_type", $post_type, $args);

// If not set, default to the setting for public.
if ( null === $args->publicly_queryable )
	$args->publicly_queryable = $args->public;

Change History (2)

#1 @teolaz
10 years ago

FIY

the filter needs to return the $args modified;

so the correct line is

$args = apply_filters( "registering_post_type", $post_type, $args);

#2 @SergeyBiryukov
10 years ago

  • Component changed from General to Posts, Post Types
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
  • Type changed from feature request to enhancement

Duplicate of #17447.

Note: See TracTickets for help on using tickets.