[wp-trac] [WordPress Trac] #21943: register_post_type() expect array but should object as well
WordPress Trac
wp-trac at lists.automattic.com
Thu Sep 20 18:05:22 UTC 2012
#21943: register_post_type() expect array but should object as well
-----------------------------+--------------------------
Reporter: thomask | Type: defect (bug)
Status: new | Priority: normal
Milestone: Awaiting Review | Component: Post Types
Version: trunk | Severity: normal
Keywords: |
-----------------------------+--------------------------
$wp_post_types global uses objects for all post types and objects for some
of their properties (labels and cap, on the other hand taxonomies property
is array)
problem is, that when you get this object and want to reuse it using
register_post_type (e.g. you want easy copy the post type to another post
type), it throws error, because it expect all properties are array (even
if you cast the main object as array):
{{{
global $wp_post_types;
$new_post_type = (array) $wp_post_types['post'];
register_post_type( 'new_post_type', $new_post_type );
}}}
throws
{{{
Fatal error: Cannot use object of type stdClass as array in
/var/www/projects/zdrojak/htdocs/public/wp-includes/post.php
on line 1259
}}}
you have to first do something like
{{{
foreach ($new_post_type as &$arg) {
if (is_object($arg)) $arg = array($arg);
}
}}}
I am not sure, if it is a bug of register_post_type(), so that it should
accept objects as well, or if it is a bug of the $wp_post_types global,
that it uses objects in place of arrays
--
Ticket URL: <http://core.trac.wordpress.org/ticket/21943>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list