custom_page=$custom_page;
$this->id_prefix=$id_prefix;
$this->suffix=$suffix;
$this->default=$default;
$this->nonce=$nonce;
}
/**
* Builds a page - calls the main functionality for creating the main structure of the
* custom page.
*/
public function build_page(){
$title='Default '.$this->custom_page->page_name;
$category = get_term_by('name', $this->default, $this->custom_page->post_type.$this->suffix)->term_id;
$this->templater=new PexetoTemplater();
$this->taxonomy=$this->custom_page->post_type.$this->suffix;
$terms=get_terms($this->taxonomy, array('hide_empty'=>false, 'orderby'=>'id', 'order'=>'desc'));
echo '
';
$this->_print_heading();
//display all the instances of the page
foreach($terms as $term){
echo $this->templater->get_before_custom_section($term->name);
$this->_print_custom_section($term->name, $term->term_id);
echo $this->templater->get_after_custom_section();
}
echo '
';
}
/**
* Prints the heading of the custom page- the main title and an "Add instance" button.
*/
public function _print_heading(){
$html='';
$html.='
'.$this->custom_page->page_name.'
';
//if the page allows multiple instances, add an "Add instance" button
if($this->custom_page->allow_multiinstance){
$html.='Add New '.$this->custom_page->page_name.'';
}
echo $html;
}
/**
* Prints the section that contains the form for adding new items
* @param $title the title of the section
* @param $category the custom category ID that corresponds to the custom section
*/
public function _print_custom_section($title, $category){
//build the section template
echo $this->templater->get_custom_page_form_template($title, $category, $this->custom_page, $this->id_prefix);
$this->_print_items($category);
}
/**
* Prints the already added items to a section
* @param $category the custom category ID that corresponds to the custom section
*/
public function _print_items($category){
$args=array('numberposts' => -1,
'post_type' => $this->custom_page->post_type,
$this->taxonomy=>get_term($category, $this->taxonomy)->slug);
$posts = get_posts( $args );
$ordered_posts=pexeto_get_ordered_post_list($posts, $category,$this->custom_page->post_type);
$html='
';
foreach($ordered_posts as $post){
$html.=$this->templater->get_custom_page_list_template($post, $this->custom_page, $this->id_prefix);
}
$html.='