2
I would like to know how to access an array through a method. I’d like to know that you think my code is right what I’m trying to do?
class RegisterPostType
{
public $name;
public $singleName;
public $addNew;
public $addNewItem;
public $editNewItem;
public $newItem;
public $viewItem;
public $searchItem;
public $notFound;
public $notFoundinTrash;
private function labels()
{
$label = array(
'name' => $this->name,
'singular_name' => $this->singleName,
'add_new' => $this->addNew,
'add_new_item' => $this->addNewItem,
'edit_item' => $this->editNewItem,
'new_item' => $this->newItem,
'view_item' => $this->viewItem,
'search_items' => $this->searchItem,
'not_found' => $this->notFound,
'not_found_in_trash' => $this->notFoundinTrash,
'parent_item_colon' => ''
);
}
public function registerPostType()
{
$args = array(
'labels' => $this->labels()->label,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'menu_icon' => get_stylesheet_directory_uri() . '/article16.png',
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title','editor','thumbnail')
);
}
}
And I’m calling the array that way:
add_action('init', 'postTypes');
function postTypes()
{
$header = new RegisterPostType;
$header->name = 'Titulo';
$header->singleName = 'Titulo';
$header->addNew = 'Titulo';
$header->addNewItem = 'Titulo';
$header->editNewItem = 'Titulo';
$header->newItem = 'Titulo';
$header->viewItem = 'Titulo';
$header->searchItem = 'Titulo';
$header->notFound = 'Titulo';
$header->notFoundinTrash = 'Titulo';
register_post_type('header', $header->registerPostType()->args);
}
I took advantage and gave a var_dump in the ARRAY and it is returning me NULL. Could you help me?
Like
$label
is a private method variable(private)labels()
you need to give areturn
because it’s the only way to retrieve that array.– rray
The code doesn’t seem to make any sense. Creating methods that create local variables and do nothing else is of no use. That is why I did not understand the doubt. Try to inform your objective because the code does not show intention to do anything useful. Do you want to do something with these variables? What? Pass the contents of these variables to another place? Actually the code seems to do a lot of things unnecessarily. It might be a wrong impression but you can clarify the purpose of all these functions.
– Maniero