[
'blog',
'woo_categories'
],
'default_prefix' => 'blog'
];
$args = wp_parse_args(
$args,
[
'query' => $wp_query,
'prefix' => blocksy_manager()->screen->get_prefix(
$allowed_prefixes_args
),
'has_pagination' => '__DEFAULT__',
'pagination_type' => '__DEFAULT__',
'last_page_text' => __('No more posts to load', 'blocksy'),
'total_pages' => null,
'current_page' => null,
'format' => null,
'base' => null,
'query_var' => ''
]
);
$args['prefix'] = blocksy_manager()->screen->process_allowed_prefixes(
$args['prefix'],
$allowed_prefixes_args
);
if ($args['has_pagination'] === '__DEFAULT__') {
$args['has_pagination'] = blocksy_get_theme_mod(
$args['prefix'] . '_has_pagination',
'yes'
) === 'yes';
}
if ($args['pagination_type'] === '__DEFAULT__') {
$args['pagination_type'] = blocksy_get_theme_mod(
$args['prefix'] . '_pagination_global_type',
'simple'
);
}
if ($args['prefix'] === 'woo_categories') {
$args['last_page_text'] = __('No more products to load', 'blocksy');
}
if (! $args['has_pagination']) {
return '';
}
if (! $args['total_pages'] || ! $args['current_page']) {
$args['current_page'] = $args['query']->get('paged');
$args['total_pages'] = $args['query']->max_num_pages;
if (! $args['current_page']) {
$args['current_page'] = 1;
}
}
if ($args['total_pages'] <= 1 ) {
return '';
}
$button_output = '';
if (
$args['pagination_type'] === 'load_more'
&&
intval($args['current_page']) !== intval($args['total_pages'])
) {
$label_button = blocksy_get_theme_mod(
$args['prefix'] . '_load_more_label',
__('Load More', 'blocksy')
);
$button_output = '';
}
if (
$args['pagination_type'] !== 'simple'
&&
$args['pagination_type'] !== 'next_prev'
) {
if (intval($args['current_page']) === intval($args['total_pages'])) {
return '';
}
$button_output = '
' . $button_output;
$button_output .= '
';
$button_output .= '
' . $args['last_page_text'] . '
';
$button_output .= '
';
}
$pagination_class = 'ct-pagination';
$divider_output = '';
$divider = blocksy_get_theme_mod(
$args['prefix'] . '_paginationDivider',
[
'width' => 1,
'style' => 'none',
'color' => [
'color' => 'rgba(224, 229, 235, 0.5)',
]
]
);
$numbers_visibility = blocksy_get_theme_mod(
$args['prefix'] . '_numbers_visibility',
[
'desktop' => true,
'tablet' => true,
'mobile' => false
]
);
$arrows_visibility = blocksy_get_theme_mod(
$args['prefix'] . '_arrows_visibility',
[
'desktop' => true,
'tablet' => true,
'mobile' => true
]
);
if (
$divider['style'] !== 'none'
&&
$args['pagination_type'] !== 'infinite_scroll'
) {
$divider_output = 'data-divider';
}
$prefix = blocksy_manager()->screen->get_prefix();
$deep_link_args = [];
if (! is_singular()) {
$deep_link_args['suffix'] = $prefix . '_has_pagination';
}
$template = '
';
$paginate_links_args = [
'mid_size' => 3,
'end_size' => 0,
'type' => 'array',
'total' => $args['total_pages'],
'current' => $args['current_page'],
'prev_text' => '' . __('Prev', 'blocksy'),
'next_text' => __('Next', 'blocksy') . ' ',
];
if ($args['format']) {
$paginate_links_args['format'] = $args['format'];
}
if ($args['base']) {
$paginate_links_args['base'] = $args['base'];
}
if ($args['query_var']) {
$paginate_links_args['format'] = '?' . $args['query_var'] . '=%#%';
if (isset($_GET[$args['query_var']])) {
$paginate_links_args['current'] = intval(sanitize_text_field(
$_GET[$args['query_var']]
));
}
}
$links = paginate_links($paginate_links_args);
$arrow_links = ['', ''];
$proper_links = [];
foreach ($links as $link) {
preg_match('/class="[^"]+"/', $link, $matches);
if (count($matches) === 0) {
continue;
}
if (strpos($matches[0], 'next') !== false) {
$link = str_replace(
'page-numbers"',
'page-numbers" rel="next"',
$link
);
}
if (strpos($matches[0], 'prev') !== false) {
$link = str_replace(
'page-numbers"',
'page-numbers" rel="prev"',
$link
);
}
if (
$args['pagination_type'] === 'next_prev'
&&
strpos($matches[0], 'next') === false
&&
strpos($matches[0], 'prev') === false
) {
continue;
}
if (
$args['pagination_type'] === 'simple'
&&
(
strpos($matches[0], 'next') !== false
||
strpos($matches[0], 'prev') !== false
)
) {
$link = str_replace(
'page-numbers',
trim('page-numbers ' . blocksy_visibility_classes(
$arrows_visibility
)),
$link
);
}
if (
strpos($matches[0], 'next') !== false
||
strpos($matches[0], 'prev') !== false
) {
$arrow_links[strpos($matches[0], 'next') !== false ? 1 : 0] = $link;
} else {
$proper_links[] = $link;
}
}
$proper_links = join("\n", $proper_links);
if ($args['pagination_type'] === 'simple') {
$proper_links = '' . $proper_links . '
';
}
return blocksy_safe_sprintf(
$template,
$arrow_links[0] . $proper_links . $arrow_links[1],
$button_output
);
}
}