1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Auto Load Next Post Settings - Templates |
4
|
|
|
* |
5
|
|
|
* @version 1.6.0 |
6
|
|
|
* @author Sébastien Dumont |
7
|
|
|
* @category Admin |
8
|
|
|
* @package Auto Load Next Post/Admin/Settings |
9
|
|
|
* @license GPL-2.0+ |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
// Exit if accessed directly. |
13
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
14
|
|
|
exit; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
if ( ! class_exists( 'ALNP_Settings_Templates' ) ) { |
18
|
|
|
|
19
|
|
|
class ALNP_Settings_Templates extends ALNP_Settings_Page { |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Constructor. |
23
|
|
|
* |
24
|
|
|
* @access public |
25
|
|
|
*/ |
26
|
|
|
public function __construct() { |
27
|
|
|
$this->id = 'templates'; |
28
|
|
|
$this->label = esc_html__( 'Templates', 'auto-load-next-post' ); |
29
|
|
|
|
30
|
|
|
parent::__construct(); |
31
|
|
|
|
32
|
|
|
add_action( 'auto_load_next_post_settings_templates', array( __CLASS__, 'template_location' ), 0 ); |
33
|
|
|
} // END __construct() |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Displays a notification to the user if the templates |
37
|
|
|
* location was found and where or if the templates was |
38
|
|
|
* not found. |
39
|
|
|
* |
40
|
|
|
* @access public |
41
|
|
|
* @static |
42
|
|
|
*/ |
43
|
|
|
public static function template_location() { |
44
|
|
|
include( dirname( AUTO_LOAD_NEXT_POST_FILE ) . '/includes/admin/views/html-notice-template-location.php' ); |
45
|
|
|
} // END template_location() |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get settings array |
49
|
|
|
* |
50
|
|
|
* @access public |
51
|
|
|
* @return array $settings |
52
|
|
|
*/ |
53
|
|
|
public function get_settings() { |
54
|
|
|
$settings = array(); |
55
|
|
|
|
56
|
|
|
$description = sprintf( __( 'This helps fine tune %s to locate your theme templates directory in order to display content in the same style as your theme.', 'auto-load-next-post' ), esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ) ); |
57
|
|
|
|
58
|
|
|
if ( is_alnp_pro_version_installed() ) { |
59
|
|
|
$description .= ' ' . sprintf( __( 'Set the location for each post type if they are located in their own template directory. Otherwise just enter the location for %1$sPosts%2$s.', 'auto-load-next-post' ), '<strong>', '</strong>' ); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$settings[] = array( |
63
|
|
|
'title' => $this->label, |
64
|
|
|
'type' => 'title', |
65
|
|
|
'desc' => $description, |
66
|
|
|
'id' => 'templates_options' |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
$locate_single = alnp_get_template(); |
70
|
|
|
|
71
|
|
|
// Only show fallback support option if template location was found. May be required should theme structure fail. |
72
|
|
|
if ( ! empty( $locate_single ) ) { |
73
|
|
|
$settings[] = array( |
74
|
|
|
'title' => esc_html__( 'Use Fallback?', 'auto-load-next-post' ), |
75
|
|
|
'desc' => sprintf( __( 'Enabling this will force the use of fallback support should your active theme not have a great structure. %1$sSee help for more information%2$s.', 'auto-load-next-post' ), '<strong class="red">', '</strong>' ), |
76
|
|
|
'id' => 'auto_load_next_post_use_fallback', |
77
|
|
|
'default' => 'no', |
78
|
|
|
'type' => 'checkbox', |
79
|
|
|
'autoload' => false |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
foreach( alnp_get_post_types() as $post_type ) { |
84
|
|
|
$default = ''; |
85
|
|
|
$readonly = 'no'; |
86
|
|
|
|
87
|
|
|
// Checks if the filter has been used already and disable posts only if true. |
88
|
|
|
if ( has_filter( 'alnp_template_location' ) && strtolower( $post_type ) == 'post' ) { |
89
|
|
|
$default = alnp_template_location(); |
90
|
|
|
$readonly = 'yes'; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
// Checks if theme support provided directory location for post and disable posts only if true. |
94
|
|
|
else if ( ! empty( alnp_get_theme_support( 'directory_post' ) ) && strtolower( $post_type ) == 'post' ) { |
95
|
|
|
$default = alnp_get_theme_support( 'directory_post' ); |
96
|
|
|
$readonly = 'yes'; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
$settings[] = array( |
100
|
|
|
'title' => ucfirst( $post_type ), |
101
|
|
|
'desc' => sprintf( __( 'Enter the folder location where the theme template for %s are stored.', 'auto-load-next-post' ), $post_type ), |
102
|
|
|
'id' => 'auto_load_next_post_directory_' . strtolower( $post_type ), |
103
|
|
|
'default' => $default, |
104
|
|
|
'placeholder' => sprintf( esc_html__( 'e.g. %s', 'auto-load-next-post' ), 'template-parts/' ), |
105
|
|
|
'readonly' => $readonly, |
106
|
|
|
'type' => 'text', |
107
|
|
|
'css' => 'min-width:300px;', |
108
|
|
|
'autoload' => false |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$settings[] = array( |
113
|
|
|
'type' => 'sectionend', |
114
|
|
|
'id' => 'template_locations' |
115
|
|
|
); |
116
|
|
|
|
117
|
|
|
return $settings; |
118
|
|
|
} // END get_settings() |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Output the settings. |
122
|
|
|
* |
123
|
|
|
* @access public |
124
|
|
|
*/ |
125
|
|
|
public function output() { |
126
|
|
|
$settings = $this->get_settings(); |
127
|
|
|
|
128
|
|
|
ALNP_Admin_Settings::output_fields( $settings ); |
129
|
|
|
} // END output() |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Save settings. |
133
|
|
|
* |
134
|
|
|
* @access public |
135
|
|
|
* @global $current_view |
136
|
|
|
*/ |
137
|
|
|
public function save() { |
138
|
|
|
global $current_view; |
139
|
|
|
|
140
|
|
|
$settings = $this->get_settings(); |
141
|
|
|
|
142
|
|
|
ALNP_Admin_Settings::save_fields( $settings, $current_view ); |
|
|
|
|
143
|
|
|
} // END save() |
144
|
|
|
|
145
|
|
|
} // END class |
146
|
|
|
|
147
|
|
|
} // END if class exists |
148
|
|
|
|
149
|
|
|
return new ALNP_Settings_Templates(); |
150
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.