Completed
Pull Request — master (#70)
by
unknown
02:34
created

auto-load-next-post-core-functions.php ➔ auto_load_next_post_template_redirect()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 11
nc 4
nop 0
dl 0
loc 23
rs 8.5906
c 0
b 0
f 0
1
<?php
2
/**
3
	 * Auto Load Next Post Core Functions
4
	 *
5
	 * General core functions available on both the front-end and admin.
6
	 *
7
	 * @since    1.0.0
8
	 * @author   Sébastien Dumont
9
	 * @category Core
10
	 * @package  Auto Load Next Post
11
	 * @license  GPL-2.0+
12
	 */
13
14
if ( ! defined('ABSPATH')) {
15
	exit;
16
}
17
// Exit if accessed directly
18
19
// Include core functions
20
include('auto-load-next-post-conditional-functions.php');
21
include('auto-load-next-post-formatting-functions.php');
22
23
/**
24
 * When the 'partial' endpoint is used on a post, retrieve only the post content.
25
 **/
26
function auto_load_next_post_template_redirect() {
27
  global $wp_query;
28
29
  // if this is not a request for partial or a singular object then bail
30
  if ( ! isset($wp_query->query_vars['partial']) || ! is_singular()) {
31
	return;
32
  }
33
34
  /**
35
   * Load the template file from theme if one exists.
36
   * If theme does not have a template file, load default from the plugin.
37
   */
38
  $template_path = get_stylesheet_directory().'/'.AUTO_LOAD_NEXT_POST_TEMPLATE_PATH;
39
  $default_path = AUTO_LOAD_NEXT_POST_FILE_PATH;
40
41
  if (file_exists($template_path.'content-partial.php')) {
42
	include($template_path.'content-partial.php');
43
  } else if (file_exists($default_path.'/template/content-partial.php')) {
44
	include($default_path.'/template/content-partial.php');
45
  }
46
47
  exit;
48
}
49
add_action('template_redirect', 'auto_load_next_post_template_redirect');
50