-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalnp-divi-support.php
500 lines (449 loc) · 14.5 KB
/
alnp-divi-support.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
<?php
/*
* Plugin Name: Auto Load Next Post: Divi Support
* Plugin URI: https://github.com/autoloadnextpost/alnp-divi-support
* Description: Provides theme support for Divi by Elegant Themes
* 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-divi-support
* 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: Divi Support
* @author Auto Load Next Post
* @copyright Copyright © 2019, Auto Load Next Post
* @license GNU General Public License v3.0 http://www.gnu.org/licenses/gpl-3.0.html
*/
if ( ! class_exists( 'ALNP_Divi_Support' ) ) {
class ALNP_Divi_Support {
/**
* @var ALNP_Divi_Support - 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
* @static
* @since 1.0.0
*/
public static $required_alnp = '1.5.0';
/**
* Main ALNP_Divi_Support Instance.
*
* Ensures only one instance of ALNP_Divi_Support is loaded or can be loaded.
*
* @access public
* @static
* @since 1.0.0
* @see ALNP_Divi_Support()
* @return ALNP_Divi_Support - 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-divi-support' ), 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-divi-support' ), self::$version );
} // END __wakeup()
/**
* ALNP_Divi_Support Constructor.
*
* @access public
* @since 1.0.0
* @return ALNP_Divi_Support
*/
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' ) );
// Register support once plugin is activated.
register_activation_hook( __FILE__, array( $this, 'update_alnp_settings' ) );
// This removes the default post navigation in the repeater template.
remove_action( 'alnp_load_after_content', 'auto_load_next_post_navigation', 1, 10 );
// Before Content
add_action( 'alnp_load_before_content', array( $this, 'wrapper_start' ), 10 );
add_action( 'alnp_load_before_content', array( $this, 'post_heading_start' ), 15 );
add_action( 'alnp_load_before_content', array( $this, 'post_meta' ), 20 );
add_action( 'alnp_load_before_content', array( $this, 'featured_image' ), 25 );
add_action( 'alnp_load_before_content', array( $this, 'post_heading_end' ), 30 );
// Before Content - Post Format
add_action( 'alnp_load_before_content_post_format_audio', array( $this, 'audio_content' ), 10 );
add_action( 'alnp_load_before_content_post_format_quote', array( $this, 'quote_content' ), 10 );
add_action( 'alnp_load_before_content_post_format_link', array( $this, 'link_content' ), 10 );
// Before Content - Post Type
add_action( 'alnp_load_before_content_post_type_single', array( $this, 'the_content' ), 10 );
// After Content
add_action( 'alnp_load_after_content', array( $this, 'post_meta_wrapper_start' ), 10 );
add_action( 'alnp_load_after_content', array( $this, 'comments' ), 15 );
add_action( 'alnp_load_after_content', array( $this, 'post_meta_wrapper_end' ), 20 );
add_action( 'alnp_load_after_content', array( $this, 'wrapper_end' ), 25 );
// Add Post Navigation to Single Posts.
add_action( 'et_after_post', array( $this, 'alnp_compatible_post_nav' ), 10 );
} // 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, $this->required_alnp, '<' ) ) {
add_action( 'admin_notices', array( $this, 'alnp_not_installed' ) );
return false;
}
} // END check_required_version()
/**
* 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: Divi Support requires $%1s v%2$s or higher to be installed.', 'alnp-divi-support' ), '<a href="https://autoloadnextpost.com/" target="_blank">Auto Load Next Post</a>', $this->required_alnp ) . '</p></div>';
} // END alnp_not_installed()
/**
* These settings will be applied once the plugin is activated.
*
* @access public
* @since 1.0.0
*/
public function add_theme_support() {
add_theme_support( 'auto-load-next-post', array(
'content_container' => 'div#left-area',
'title_selector' => 'h1.entry-title',
'navigation_container' => 'nav.post-navigation',
'comments_container' => '#comment-wrap',
'load_js_in_footer' => 'no',
'lock_js_in_footer' => 'no',
'plugin_support' => 'yes',
) );
} // END add_theme_support()
/**
* The start of the article.
*
* @access public
* @since 1.0.0
* @hooked alnp_load_before_content - 10 (outputs opening article for the content)
* @return void
*/
public function wrapper_start() {
?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'et_pb_post' ); ?>>
<?php
} // END wrapper_start()
/**
* The end of the article.
*
* @access public
* @since 1.0.0
* @hooked alnp_load_after_content - 25 (outputs closing article for the content)
* @return void
*/
public function wrapper_end() {
?>
</article> <!-- .et_pb_post -->
<?php
} // END wrapper_end()
/**
* Wraps the start of the post heading.
*
* @access public
* @since 1.0.0
* @hooked alnp_load_before_content - 15
* @return void
*/
public function post_heading_start() {
?>
<div class="et_post_meta_wrapper">
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php
} // END post_heading_start()
/**
* The post meta.
*
* @access public
* @since 1.0.0
* @hooked alnp_load_before_content - 20
* @return void
*/
public function post_meta() {
et_divi_post_meta();
} // END post_meta()
/**
* Displays a featured image, video or gallery before the content.
*
* @access public
* @since 1.0.0
* @hooked alnp_load_before_content - 25
* @return void
*/
public function featured_image() {
$thumb = '';
$width = (int) apply_filters( 'et_pb_index_blog_image_width', 1080 );
$height = (int) apply_filters( 'et_pb_index_blog_image_height', 675 );
$classtext = 'et_featured_image';
$titletext = get_the_title();
$thumbnail = get_thumbnail( $width, $height, $classtext, $titletext, $titletext, false, 'Blogimage' );
$thumb = $thumbnail["thumb"];
$post_format = et_pb_post_format();
if ( 'video' === $post_format && false !== ( $first_video = et_get_first_video() ) ) {
printf(
'<div class="et_main_video_container">
%1$s
</div>',
et_core_esc_previously( $first_video )
);
} else if ( ! in_array( $post_format, array( 'gallery', 'link', 'quote' ) ) && 'on' === et_get_option( 'divi_thumbnails', 'on' ) && '' !== $thumb ) {
print_thumbnail( $thumb, $thumbnail["use_timthumb"], $titletext, $width, $height );
} else if ( 'gallery' === $post_format ) {
et_pb_gallery_images();
}
} // END featured_image()
/**
* Displays an audio player for posts with the post format set to Audio.
*
* @access public
* @since 1.0.0
* @hooked alnp_load_before_content_post_format_audio - 10
* @return void
*/
public function audio_content() {
$text_color_class = et_divi_get_post_text_color();
$inline_style = et_divi_get_post_bg_inline_style();
$audio_player = et_pb_get_audio_player();
if ( $audio_player ) {
printf(
'<div class="et_audio_content%1$s"%2$s>
%3$s
</div>',
esc_attr( $text_color_class ),
et_core_esc_previously( $inline_style ),
et_core_esc_previously( $audio_player )
);
}
} // END audio_content()
/**
* Displays a quote for posts with the post format set to Quote.
*
* @access public
* @since 1.0.0
* @hooked alnp_load_before_content_post_format_quote - 10
* @return void
*/
public function quote_content() {
printf(
'<div class="et_quote_content%2$s"%3$s>
%1$s
</div> <!-- .et_quote_content -->',
et_core_esc_previously( et_get_blockquote_in_content() ),
esc_attr( $text_color_class ),
et_core_esc_previously( $inline_style )
);
} // END quote_content()
/**
* Displays a link for posts with the post format set to Link.
*
* @access public
* @since 1.0.0
* @hooked alnp_load_before_content_post_format_link - 10
* @return void
*/
public function link_content() {
printf(
'<div class="et_link_content%3$s"%4$s>
<a href="%1$s" class="et_link_main_url">%2$s</a>
</div> <!-- .et_link_content -->',
esc_url( et_get_link_url() ),
esc_html( et_get_link_url() ),
esc_attr( $text_color_class ),
et_core_esc_previously( $inline_style )
);
} // END link_content()
/**
* Wraps the end of the post heading.
*
* @access public
* @since 1.0.0
* @hooked alnp_load_before_content - 30
* @return void
*/
public function post_heading_end() {
?>
</div> <!-- .et_post_meta_wrapper -->
<?php
} // END post_heading_end()
/**
* Displays the post content.
*
* @access public
* @since 1.0.0
* @hooked alnp_load_before_content_post_type_single - 10
* @return void
*/
public function the_content() {
?>
<div class="entry-content">
<?php
do_action( 'et_before_content' );
the_content();
wp_link_pages( array( 'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'alnp-divi-support' ), 'after' => '</div>' ) );
?>
</div> <!-- .entry-content -->
<?php
} // END the_content()
/**
* The start of the post meta wrapper.
*
* @access public
* @since 1.0.0
* @hooked alnp_load_after_content - 10
* @return void
*/
public function post_meta_wrapper_start() {
?>
<div class="et_post_meta_wrapper">
<?php
if ( et_get_option('divi_468_enable') === 'on' ) {
echo '<div class="et-single-post-ad">';
if ( et_get_option('divi_468_adsense') !== '' ) echo et_core_intentionally_unescaped( et_core_fix_unclosed_html_tags( et_get_option('divi_468_adsense') ), 'html' );
else { ?>
<a href="<?php echo esc_url(et_get_option('divi_468_url')); ?>"><img src="<?php echo esc_attr(et_get_option('divi_468_image')); ?>" alt="468" class="foursixeight" /></a>
<?php
}
echo '</div> <!-- .et-single-post-ad -->';
}
} // END post_meta_wrapper_start()
/**
* Diplays the post comments.
*
* @access public
* @since 1.0.0
* @hooked alnp_load_after_content - 15
* @return void
*/
public function comments() {
/**
* Fires after the post content on single posts.
*/
do_action( 'et_after_post' );
if ( ( comments_open() || get_comments_number() ) && 'on' === et_get_option( 'divi_show_postcomments', 'on' ) ) {
comments_template( '', true );
}
} // END comments()
/**
* The end of the post meta wrapper.
*
* @access public
* @since 1.0.0
* @hooked alnp_load_after_content - 20
* @return void
*/
public function post_meta_wrapper_end() {
?>
</div> <!-- .et_post_meta_wrapper -->
<?php
} // END post_meta_wrapper_end()
/**
* Adds a post navigation to single posts.
*
* @access public
* @since 1.0.0
* @return void
*/
public function alnp_compatible_post_nav() {
if ( is_single() ) {
the_post_navigation( array(
'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'alnp-divi-support' ) . '</span> ' .
'<span class="screen-reader-text">' . __( 'Next post:', 'alnp-divi-support' ) . '</span> ' .
'<span class="post-title">%title</span>',
'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'alnp-divi-support' ) . '</span> ' .
'<span class="screen-reader-text">' . __( 'Previous post:', 'alnp-divi-support' ) . '</span> ' .
'<span class="post-title">%title</span>',
) );
}
} // END alnp_compatible_post_nav()
/**
* Updates the theme selectors and any additionl supported feature.
*
* @access public
* @since 1.0.0
* @return void
*/
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 ) {
if ( ! empty( $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-divi-support-LOCALE.mo
*
* @access public
* @since 1.0.0
* @return void
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'alnp-divi-support', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
} // END load_plugin_textdomain()
} // END class
} // END if class exists
return ALNP_Divi_Support::instance();