Looks like some minor confusion here and syntax issues.
Bad: You’re including the $
sign when setting property values.
// Set Variables
$this->$post_type_name = strtolower( str_replace( ' ','_', $name) );
$this->$post_type_args = $args;
$this->$post_type_lables = $labels;
Good: Omit the $
once you’ve declared them.
// Set Variables
$this->post_type_name = strtolower( str_replace( ' ','_', $name) );
$this->post_type_args = $args;
$this->post_type_lables = $labels;
Good: This is good too, you have this right.
public $post_type_name;
public $post_type_args;
public $post_type_labels;
Regarding $args
. It’s difficult to tell where the second snippet fits in exactly, but assuming it’s in the constructor, I’m not seeing an $args
variable within the context of your closure. You’ll need to use($args)
if that variable is from the outer scope.
add_action( 'init',
function() use( $taxonomy_name, $post_type_name, $args ) {
register_taxonomy( $taxonomy_name, $post_type_name, $args );
}
);
See also: PHP closures, inheriting variables from parent scope