Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 2 years ago

#31073 closed enhancement (duplicate)

Add new filter on function register_post_type

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

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
12 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
12 years ago

  • Component General → Posts, Post Types
  • Milestone Awaiting Review
  • Resolution → duplicate
  • Status new → closed
  • Type feature request → enhancement

Duplicate of #17447.

Note: See TracTickets for help on using tickets.