I would like to simplify the creation of \"Custom Post Types\" in WordPress as it is tedious to go through the same script and change all the custom post type name instances
This post is old, but PHP 7 may solve this question.
Try:
$prefix = 'news';
$functionName = $prefix . "_custom_type_init";
${$functionName} = function() use ($prefix) {
register_post_type($prefix, array(
'labels' => array(
'name' => $prefix,
'singular_label' => $prefix,
'add_new' => 'Add'
)
);
register_taxonomy_for_object_type( 'category', $prefix );
};
add_action('init', '$' . $functionName);
I think it should work for WordPress.