Completed
Pull Request — master (#133)
by Sébastien
03:02
created

ALNP_Theme_Support   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B update_alnp_theme_selectors() 0 15 7
1
<?php
2
/**
3
 * Auto Load Next Post Theme Support
4
 *
5
 * Configures theme support if supported.
6
 *
7
 * @since    1.5.0
8
 * @author   Sébastien Dumont
9
 * @category Theme Support
10
 * @package  Auto Load Next Post/Theme Support
11
 * @license  GPL-2.0+
12
 */
13
14
// Exit if accessed directly.
15
if ( ! defined( 'ABSPATH' ) ) {
16
	exit;
17
}
18
19
/**
20
 * ALNP_Theme_Support class.
21
 */
22
class ALNP_Theme_Support {
23
24
	/**
25
	 * Constructor.
26
	 *
27
	 * @access public
28
	 */
29
	public function __construct() {
30
		// Update theme selectors if the theme was switched and it has theme support.
31
		add_action( 'after_switch_theme', array( $this, 'update_alnp_theme_selectors' ), 15, 2 );
32
	} // END __construct()
33
34
	/**
35
	 * Updates the theme selectors if the theme had changed
36
	 * and Auto Load Next Post is supported within that theme.
37
	 *
38
	 * @access public
39
	 */
40
	public function update_alnp_theme_selectors( $stylesheet = '', $old_theme = false ) {
2 ignored issues
show
Unused Code introduced by
The parameter $stylesheet is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $old_theme is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
41
		// Check if Auto Load Next Post is supported before updating the theme selectors.
42
		if ( is_alnp_supported() ) {
43
			$theme_support = get_theme_support( 'auto-load-next-post' );
44
45
			if ( is_array( $theme_support ) ) {
46
				// Preferred implementation, where theme provides an array of options
47
				if ( isset( $theme_support[0] ) && is_array( $theme_support[0] ) ) {
48
					foreach( $theme_support[0] as $key => $value ) {
49
						if ( ! empty( $value ) ) update_option( 'auto_load_next_post_' . $key, $value );
50
					}
51
				}
52
			}
53
		}
54
	} // END update_alnp_theme_selectors()
55
56
} // END class
57
58
return new ALNP_Theme_Support();
59