通过更改全局变量,可以在init之后更改post状态$wp_post_statusses
:
function alt_post_status() {
global $wp_post_statuses;
$wp_post_statuses[\'custom_status\']->public = true;
}
add_action( \'init\', \'alt_post_status\' );
register_post_status() (第922行)执行相同的操作:
...
global $wp_post_statuses;
if (!is_array($wp_post_statuses))
$wp_post_statuses = array();
// Args prefixed with an underscore are reserved for internal use.
$defaults = array(
\'label\' => false,
\'label_count\' => false,
\'exclude_from_search\' => null,
\'_builtin\' => false,
\'public\' => null,
\'internal\' => null,
\'protected\' => null,
\'private\' => null,
\'publicly_queryable\' => null,
\'show_in_admin_status_list\' => null,
\'show_in_admin_all_list\' => null,
);
$args = wp_parse_args($args, $defaults);
$args = (object) $args;
...
$wp_post_statuses[$post_status] = $args;
...