-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalnp-support-boilerplate.php
231 lines (206 loc) · 6.82 KB
/
alnp-support-boilerplate.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
/*
* Plugin Name: Auto Load Next Post: Support Boilerplate
* Plugin URI: https://github.com/autoloadnextpost/alnp-support-boilerplate
* Description: Boilerplate for providing theme support for Auto Load Next Post.
* Author: Auto Load Next Post
* Author URI: https://autoloadnextpost.com
* Version: 1.0.0
* Developer: Sébastien Dumont
* Developer URI: https://sebastiendumont.com
* Text Domain: alnp-support-boilerplate
* Domain Path: /languages/
*
* Copyright: © 2019 Sébastien Dumont
*
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*
* @package Auto Load Next Post: Support Boilerplate
* @author Auto Load Next Post
* @copyright Copyright © 2018, Auto Load Next Post
* @license GNU General Public License v3.0 http://www.gnu.org/licenses/gpl-3.0.html
*/
if ( ! class_exists( 'ALNP_Support_Boilerplate' ) ) {
class ALNP_Support_Boilerplate {
/**
* @var ALNP_Support_Boilerplate - the single instance of the class.
*
* @access protected
* @static
* @since 1.0.0
*/
protected static $_instance = null;
/**
* Plugin Version
*
* @access public
* @static
* @since 1.0.0
*/
public static $version = '1.0.0';
/**
* Required Auto Load Next Post Version
*
* @access public
* @since 1.0.0
*/
public static $required_alnp = '1.5.2';
/**
* Main ALNP_Support_Boilerplate Instance.
*
* Ensures only one instance of ALNP_Support_Boilerplate is loaded or can be loaded.
*
* @access public
* @static
* @since 1.0.0
* @see ALNP_Support_Boilerplate()
* @return ALNP_Support_Boilerplate - Main instance
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
} // END instance()
/**
* Cloning is forbidden.
*
* @access public
* @since 1.0.0
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, __( 'Cloning this object is forbidden.', 'alnp-support-boilerplate' ), self::$version );
} // END __clone()
/**
* Unserializing instances of this class is forbidden.
*
* @access public
* @since 1.0.0
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( 'Unserializing instances of this class is forbidden.', 'alnp-support-boilerplate' ), self::$version );
} // END __wakeup()
/**
* ALNP_Support_Boilerplate Constructor.
*
* @access public
* @since 1.0.0
* @return ALNP_Support_Boilerplate
*/
public function __construct() {
$this->init_hooks();
} // END __construct()
/**
* Initialize hooks.
*
* @access private
* @since 1.0.0
*/
private function init_hooks() {
// Check that the required version of Auto Load Next Post is installed.
add_action( 'auto_load_next_post_loaded', array( $this, 'check_required_version' ) );
// Load textdomain.
add_action( 'init', array( $this, 'load_plugin_textdomain' ), 0 );
// Add theme support and preset the theme selectors and if the JavaScript should load in the footer.
add_action( 'after_setup_theme', array( $this, 'add_theme_support' ) );
// Filters the location of the repeater template. - Uncomment the next line to enable filter.
//add_filter( 'alnp_template_redirect', array( $this, 'template_redirect' ) );
// Filters the repeater template location. - Uncomment the next line to enable filter.
//add_filter( 'alnp_template_location', array( $this, 'alnp_template_location' ) );
// Register support once plugin is activated.
register_activation_hook( __FILE__, array( $this, 'update_alnp_settings' ) );
} // END init_hooks()
/**
* Checks if the required Auto Load Next Post is installed.
*
* @access public
* @since 1.0.0
* @return bool
*/
public function check_required_version() {
if ( ! defined( 'AUTO_LOAD_NEXT_POST_VERSION' ) || version_compare( AUTO_LOAD_NEXT_POST_VERSION, self::$required_alnp, '<' ) ) {
add_action( 'admin_notices', array( $this, 'alnp_not_installed' ) );
return false;
}
} // END check_alnp_installed()
/**
* Required version of Auto Load Next Post is Not Installed Notice.
*
* @access public
* @since 1.0.0
* @return void
*/
public function alnp_not_installed() {
echo '<div class="error"><p>' . sprintf( __( 'Auto Load Next Post: Support Boilerplate requires $%1s v%2$s or higher to be installed.', 'alnp-support-boilerplate' ), '<a href="https://autoloadnextpost.com/" target="_blank">Auto Load Next Post</a>', self::$required_alnp ) . '</p></div>';
} // END alnp_not_installed()
/***
* Add theme support for Auto Load Next Post by setting the
* theme selectors, if the theme requires the JavaScript
* to load in the footer and only in the footer.
*
* These settings will be applied once the plugin is activated.
*
* @access public
*/
public function add_theme_support() {
add_theme_support( 'auto-load-next-post', array(
'content_container' => 'main.site-main',
'title_selector' => 'h1.entry-title',
'navigation_container' => 'nav.post-navigation',
'comments_container' => 'div#comments',
'load_js_in_footer' => 'no',
'lock_js_in_footer' => 'no',
) );
} // END add_theme_support()
/**
* Filters the location of the repeater template to
* override the default repeater template.
*
* @access public
* @return string
*/
public function template_redirect() {
return dirname( __FILE__ ) . '/content-alnp.php';
} // END template_redirect()
/**
* Filters the template location for get_template_part().
*
* @access public
* @return string
*/
public function alnp_template_location() {
return '';
} // END alnp_template_location()
/**
* Updates the theme selectors and any additionl supported feature.
*
* @access public
*/
public function update_alnp_settings( $stylesheet = '', $old_theme = false ) {
$theme_support = get_theme_support( 'auto-load-next-post' );
if ( is_array( $theme_support ) ) {
// Preferred implementation, where theme provides an array of options
if ( isset( $theme_support[0] ) && is_array( $theme_support[0] ) ) {
foreach( $theme_support[0] as $key => $value ) {
update_option( 'auto_load_next_post_' . $key, $value );
}
}
}
} // END update_alnp_settings()
/**
* Make the plugin translation ready.
*
* Translations should be added in the WordPress language directory:
* - WP_LANG_DIR/plugins/alnp-support-boilerplate-LOCALE.mo
*
* @access public
* @since 1.0.0
* @return void
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'alnp-support-boilerplate', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
} // END load_plugin_textdomain()
} // END class
} // END if class exists
return ALNP_Support_Boilerplate::instance();