Skip to content

Commit

Permalink
changed parameters to be array of args
Browse files Browse the repository at this point in the history
  • Loading branch information
mt-gareth committed Mar 25, 2020
1 parent e40a78f commit b2256d1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"minimum-stability": "dev",
"require": {
"php": ">=5.3.0"
"php": ">=5.4"
},
"autoload": {
"files": [
Expand Down
26 changes: 19 additions & 7 deletions src/WP_Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,23 @@ class WP_AJAX
private $pagination_pages_to_show;
private $include_nopriv;

function __construct( $action, $output_template, $pagination_template = false, $pagination_pages_to_show = 9, $include_nopriv = true )
function __construct( array $args )
{
$this->action = $action;
$this->output_template = $output_template;
$this->pagination_template = $pagination_template;
$this->pagination_pages_to_show = $pagination_pages_to_show;
$this->include_nopriv = $include_nopriv;
$defaults = [
'action' => 'get_posts',
'output_template' => false,
'pagination_template' => false,
'pagination_pages_to_show' => 9,
'include_nopriv' => true,
];

$args = wp_parse_args( $args, $defaults );

$this->action = $args[ 'action' ];
$this->output_template = $args[ 'output_template' ];
$this->pagination_template = $args[ 'pagination_template' ];
$this->pagination_pages_to_show = $args[ 'pagination_pages_to_show' ];
$this->include_nopriv = $args[ 'include_nopriv' ];
$this->setup_ajax_handlers();
}

Expand All @@ -35,7 +45,9 @@ public function ajax_response()
$current_page = $current_page ? $current_page : 1;
$max_pages = (int)$loop->max_num_pages;

$html = \App\Template( $this->output_template, [ 'posts' => $loop->posts ] );
$html = '';
if ( $this->output_template !== false )
$html = \App\Template( $this->output_template, [ 'posts' => $loop->posts ] );
$pagination = '';
if ( $max_pages > 1 && $this->pagination_template !== false ) {
$pages_array = self::arrayOfPages( $current_page, $max_pages, $this->pagination_pages_to_show );
Expand Down

0 comments on commit b2256d1

Please sign in to comment.