WordPress.org

Make WordPress Core

Ticket #49644: 49644-2.patch

File 49644-2.patch, 2.6 KB (added by MikeSchinkel, 22 months ago)

Updates to fix the oversight in the 2nd patch which ends up not returning the correct values from register_post_type() and unregister_post_type().

  • www/wp-includes/post.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    14031403 * @return WP_Post_Type|WP_Error The registered post type object, or an error object.
    14041404 */
    14051405function register_post_type( $post_type, $args = array() ) {
    1406         global $wp_post_types;
    1407 
    1408         if ( ! is_array( $wp_post_types ) ) {
    1409                 $wp_post_types = array();
    1410         }
    1411 
    1412         // Sanitize post type name
    1413         $post_type = sanitize_key( $post_type );
    1414 
    1415         if ( empty( $post_type ) || strlen( $post_type ) > 20 ) {
    1416                 _doing_it_wrong( __FUNCTION__, __( 'Post type names must be between 1 and 20 characters in length.' ), '4.2.0' );
    1417                 return new WP_Error( 'post_type_length_invalid', __( 'Post type names must be between 1 and 20 characters in length.' ) );
    1418         }
    1419 
    14201406        $post_type_object = new WP_Post_Type( $post_type, $args );
    1421         $post_type_object->add_supports();
    1422         $post_type_object->add_rewrite_rules();
    1423         $post_type_object->register_meta_boxes();
    1424 
    1425         $wp_post_types[ $post_type ] = $post_type_object;
    1426 
    1427         $post_type_object->add_hooks();
    1428         $post_type_object->register_taxonomies();
    1429 
    1430         /**
    1431          * Fires after a post type is registered.
    1432          *
    1433          * @since 3.3.0
    1434          * @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object.
    1435          *
    1436          * @param string       $post_type        Post type.
    1437          * @param WP_Post_Type $post_type_object Arguments used to register the post type.
    1438          */
    1439         do_action( 'registered_post_type', $post_type, $post_type_object );
    1440 
    1441         return $post_type_object;
     1407        return is_null($post_type_object->last_error)
     1408                ? $post_type_object->register()
     1409                : $post_type_object->last_error;
    14421410}
    14431411
    14441412/**
     
    14621430
    14631431        $post_type_object = get_post_type_object( $post_type );
    14641432
    1465         // Do not allow unregistering internal post types.
    1466         if ( $post_type_object->_builtin ) {
    1467                 return new WP_Error( 'invalid_post_type', __( 'Unregistering a built-in post type is not allowed' ) );
    1468         }
    1469 
    1470         $post_type_object->remove_supports();
    1471         $post_type_object->remove_rewrite_rules();
    1472         $post_type_object->unregister_meta_boxes();
    1473         $post_type_object->remove_hooks();
    1474         $post_type_object->unregister_taxonomies();
    1475 
    1476         unset( $wp_post_types[ $post_type ] );
    1477 
    1478         /**
    1479          * Fires after a post type was unregistered.
    1480          *
    1481          * @since 4.5.0
    1482          *
    1483          * @param string $post_type Post type key.
    1484          */
    1485         do_action( 'unregistered_post_type', $post_type );
    1486 
    1487         return true;
     1433        return ! $post_type_object->unregister()
     1434                ? $post_type_object->last_error
     1435                : true;
    14881436}
    14891437
    14901438/**