forked from malinky/malinky-ajax-pagination
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmalinky-ajax-pagination.php
151 lines (131 loc) · 4.51 KB
/
malinky-ajax-pagination.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
144
145
146
147
148
149
150
151
<?php
/**
* Plugin Name: Ajax Pagination and Infinite Scroll
* Plugin URI: https://github.com/malinky/malinky-ajax-pagination
* Description: Choose from infinite scroll, load more button and pagination to load paged content with Ajax on your posts, pages, custom post types and WooCommerce. Multiple pagination settings can be created for different post types and templates.
* Version: 2.0.1
* Author: Malinky
* Author URI: https://github.com/malinky
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: malinky-ajax-pagination
* Domain Path: /languages
*/
class Malinky_Ajax_Pagination
{
public function __construct()
{
// Trailing Slash.
define( 'MALINKY_AJAX_PAGINATION_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
// No Trailing Slash.
define( 'MALINKY_AJAX_PAGINATION_PLUGIN_URL', plugins_url( basename( plugin_dir_path( __FILE__ ) ) ) );
// Constant for enqueuing css.
if ( ! defined( 'MALINKY_LOAD_CSS' ) ) {
define( 'MALINKY_LOAD_CSS', true );
}
// Constand for enqueuing js.
if ( ! defined( 'MALINKY_LOAD_JS' ) ) {
define( 'MALINKY_LOAD_JS', true );
}
// Includes.
require_once( 'malinky-ajax-pagination-settings.php' );
require_once( 'malinky-ajax-pagination-functions.php' );
// Instantiate settings object.
$this->settings = new Malinky_Ajax_Pagination_Settings();
// Enqueue styles and scripts.
add_action( 'wp_enqueue_scripts', array( $this, 'malinky_ajax_pagination_enqueue_scripts' ), 99 );
add_action( 'admin_enqueue_scripts', array( $this, 'malinky_ajax_pagination_admin_scripts' ) );
add_action( 'plugins_loaded', array( $this, 'malinky_ajax_pagination_load_textdomain' ) );
}
/**
* Conditionally enqueue styles.
*/
function malinky_ajax_pagination_enqueue_scripts()
{
if ( malinky_load_css() ) {
$this->malinky_ajax_pagination_styles();
}
if ( malinky_load_js() ) {
$this->malinky_ajax_pagination_scripts();
}
}
/**
* Load plugin textdomain.
*/
public function malinky_ajax_pagination_load_textdomain()
{
load_plugin_textdomain( 'malinky-ajax-pagination', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
/**
* Enqueue styles.
*/
public function malinky_ajax_pagination_styles()
{
wp_register_style(
'malinky-ajax-pagination',
MALINKY_AJAX_PAGINATION_PLUGIN_URL . '/css/style.css',
false,
NULL
);
wp_enqueue_style( 'malinky-ajax-pagination' );
}
/**
* Enqueue scripts.
*/
public function malinky_ajax_pagination_scripts()
{
wp_register_script(
'malinky-ajax-pagination-main-js',
MALINKY_AJAX_PAGINATION_PLUGIN_URL . '/js/main.js',
array( 'jquery' ),
NULL,
true
);
// Saved settings.
for ( $x = 1; $x <= $this->settings->malinky_ajax_pagination_settings_count_settings(); $x++ ) {
$malinky_settings[ $x ] = get_option( '_malinky_ajax_pagination_settings_' . $x );
}
// If no settings have been saved yet.
if ( ! isset( $malinky_settings ) ) return;
// Set ajax loader images.
foreach ( $malinky_settings as $key => $setting ) {
$malinky_settings[$key]['ajax_loader'] = malinky_ajax_pagination_ajax_loader( $malinky_settings[$key]['ajax_loader'] );
}
wp_localize_script( 'malinky-ajax-pagination-main-js', 'malinkySettings', $malinky_settings );
wp_enqueue_script( 'malinky-ajax-pagination-main-js' );
}
/**
* Admin enqueue styles and scripts.
*/
public function malinky_ajax_pagination_admin_scripts()
{
wp_register_style(
'malinky-ajax-pagination-admin-css',
MALINKY_AJAX_PAGINATION_PLUGIN_URL . '/css/style-admin.css',
false,
NULL
);
wp_enqueue_style( 'malinky-ajax-pagination-admin-css' );
// Get theme defaults.
$malinky_ajax_pagination_theme_defaults = malinky_ajax_pagination_theme_defaults();
wp_register_script(
'malinky-ajax-pagination-admin-main-js',
MALINKY_AJAX_PAGINATION_PLUGIN_URL . '/js/main-admin.js',
array( 'jquery' ),
NULL,
true
);
wp_localize_script( 'malinky-ajax-pagination-admin-main-js', 'malinkyAjaxPagingThemeDefaults', $malinky_ajax_pagination_theme_defaults );
wp_enqueue_script( 'malinky-ajax-pagination-admin-main-js' );
wp_enqueue_media();
wp_register_script(
'malinky-ajax-pagination-admin-media-uploader-js',
MALINKY_AJAX_PAGINATION_PLUGIN_URL . '/js/media-uploader.js',
array( 'jquery' ),
NULL,
true
);
wp_enqueue_script( 'malinky-ajax-pagination-admin-media-uploader-js' );
}
}
$malinky_ajax_pagination = new Malinky_Ajax_Pagination();