forked from malinky/malinky-ajax-pagination
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmalinky-ajax-pagination-functions.php
143 lines (125 loc) · 4.77 KB
/
malinky-ajax-pagination-functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
if ( ! function_exists( 'malinky_load_css' ) ) {
/**
* Filter used to dequeue styles.
*/
function malinky_load_css() {
return apply_filters( 'malinky_load_css', MALINKY_LOAD_CSS );
}
}
if ( ! function_exists( 'malinky_load_js' ) ) {
/**
* Filter used to dequeue scripts.
*/
function malinky_load_js() {
return apply_filters( 'malinky_load_js', MALINKY_LOAD_JS );
}
}
if ( ! function_exists( 'malinky_is_blog_page' ) ) {
/**
* Check if current page is the blog home page, archive or optional single.
* Archive includes category, tag, date, author pages, custom post types.
*
* @param bool $single Include is_single()
*
* @return bool
*/
function malinky_is_blog_page( $single = true )
{
global $post;
if ( ! $single )
return ( is_home() || is_front_page() || is_archive() || is_search() );
return ( is_home() || is_front_page() || is_archive() || is_search() || is_single() );
}
}
if ( ! function_exists( 'malinky_ajax_pagination_ajax_loader' ) ) {
/**
* Check if a user has uploaded an ajax loader and it is a valid image.
* If not then use the default loader saved in the plugin folder.
* Returns an img tag for the ajax loader.
*
* @param int|str $ajax_loader the id of the attachment or the str default
*
* @return str
*/
function malinky_ajax_pagination_ajax_loader( $ajax_loader )
{
if ( $ajax_loader != 'default' && wp_get_attachment_image( esc_attr( $ajax_loader ) ) != '' ) {
$img_attr = array(
'alt' => 'AJAX Loader'
);
$ajax_loader_img = wp_get_attachment_image( esc_attr( $ajax_loader ), 'thumbnail', false, $img_attr );
} else {
$ajax_loader_img = '<img src="' . MALINKY_AJAX_PAGINATION_PLUGIN_URL . '/img/loader.gif" alt="AJAX Loader" />';
}
return $ajax_loader_img;
}
}
if ( ! function_exists( 'malinky_ajax_pagination_theme_defaults' ) ) {
/**
* Set up defaults based on popular themes.
* Returns associative array which is then localized in main-admin.js.
*
* @return arr
*/
function malinky_ajax_pagination_theme_defaults()
{
$theme_defaults = array(
'Twenty Sixteen' => array(
'posts_wrapper' => '.site-main',
'post_wrapper' => '.post',
'pagination_wrapper' => '.navigation',
'next_page_selector' => '.nav-links a.next'
),
'Twenty Fifteen' => array(
'posts_wrapper' => '.site-main',
'post_wrapper' => '.post',
'pagination_wrapper' => '.nav-links',
'next_page_selector' => '.nav-links a.next'
),
'Twenty Fourteen' => array(
'posts_wrapper' => '.site-content',
'post_wrapper' => '.post',
'pagination_wrapper' => '.pagination',
'next_page_selector' => '.pagination a.next'
),
'Twenty Thirteen' => array(
'posts_wrapper' => '.site-content',
'post_wrapper' => '.post',
'pagination_wrapper' => '.nav-links',
'next_page_selector' => '.nav-links .nav-previous a'
),
'Twenty Twelve' => array(
'posts_wrapper' => '.site-content',
'post_wrapper' => '.post',
'pagination_wrapper' => '#nav-below',
'next_page_selector' => '#nav-below .nav-previous a'
),
'Storefront' => array(
'posts_wrapper' => '.site-main',
'post_wrapper' => '.post',
'pagination_wrapper' => '.storefront-pagination',
'next_page_selector' => '.storefront-pagination a.next'
),
'WooCommerce Storefront' => array(
'posts_wrapper' => '.site-main',
'post_wrapper' => '.product',
'pagination_wrapper' => '.woocommerce-pagination',
'next_page_selector' => '.woocommerce-pagination a.next'
)
);
return $theme_defaults;
}
}
if ( ! function_exists( 'malinky_ajax_pagination_theme_default_names' ) ) {
/**
* Get the default themes names based on the theme type.
*
* @return arr
*/
function malinky_ajax_pagination_theme_default_names()
{
$theme_names = malinky_ajax_pagination_theme_defaults();
return array_combine( array_keys( $theme_names ), array_keys( $theme_names ) );
}
}