Skip to content

Commit

Permalink
added a way to just get the html
Browse files Browse the repository at this point in the history
  • Loading branch information
mt-gareth committed May 12, 2020
1 parent 2f39e8b commit 70d65fc
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/WP_Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,29 @@ public function ajax_response()
{
[ $posts, $current_page, $max_pages ] = $this->getPostsAndPages();

[ $html, $pagination ] = $this->get_html( $posts, $current_page, $max_pages );


wp_send_json( [
'html' => $html,
'pagination' => $pagination,
'currentPage' => $current_page,
'maxPages' => $max_pages,
'posts' => $posts,
] );
}

public function html_response()
{
[ $posts, $current_page, $max_pages ] = $this->getPostsAndPages();

[ $html, $pagination ] = $this->get_html( $posts, $current_page, $max_pages );

return [ $html, $pagination ];
}

protected function get_html( $posts, $current_page, $max_pages )
{
$html = '';
if ( $this->output_template !== false )
$html = \App\Template( $this->output_template, [ 'posts' => $posts ] );
Expand All @@ -50,13 +73,7 @@ public function ajax_response()
$pagination = \App\Template( $this->pagination_template, [ 'pages' => $pages_array, 'current_page' => $current_page, 'max_pages' => $max_pages ] );
}

wp_send_json( [
'html' => $html,
'pagination' => $pagination,
'currentPage' => $current_page,
'maxPages' => $max_pages,
'posts' => $posts,
] );
return [ $html, $pagination ];
}

protected function getQueryArgs()
Expand Down

0 comments on commit 70d65fc

Please sign in to comment.