1 | <?php |
||
13 | class Pods_Templates_Auto_Template_Settings { |
||
14 | |||
15 | /** |
||
16 | * Front end class object |
||
17 | * |
||
18 | * @since 2.5.5 |
||
19 | * |
||
20 | * @var Pods_Templates_Auto_Template_Front_End |
||
21 | */ |
||
22 | private $front_end_class; |
||
23 | |||
24 | /** |
||
25 | * Holds instance of this class |
||
26 | * |
||
27 | * @var Pods_Templates_Auto_Template_Settings |
||
28 | */ |
||
29 | private $instance; |
||
30 | |||
31 | /** |
||
32 | * Constructor for the Pods_PFAT class |
||
33 | * |
||
34 | * Sets up all the appropriate hooks and actions |
||
35 | * within the plugin. |
||
36 | * |
||
37 | * @since 2.5.5 |
||
38 | */ |
||
39 | public function __construct() { |
||
40 | |||
41 | |||
42 | //Add option tab for post types |
||
43 | add_filter( 'pods_admin_setup_edit_tabs_post_type', array( $this, 'tab' ), 11, 3 ); |
||
44 | |||
45 | //add the same tab for taxonomies |
||
46 | add_filter( 'pods_admin_setup_edit_tabs_taxonomy', array( $this, 'tab' ), 11, 3 ); |
||
47 | |||
48 | //Add options to the new tab |
||
49 | add_filter( 'pods_admin_setup_edit_options', array( $this, 'options' ), 12, 2 ); |
||
50 | |||
51 | |||
52 | //Include and init front-end class |
||
53 | add_action( 'init', array( $this, 'front_end' ), 25 ); |
||
54 | |||
55 | //Delete transients when Pods settings are updated. |
||
56 | add_action( 'update_option', array( $this, 'reset' ), 21, 3 ); |
||
57 | |||
58 | //admin notice for archives without archives |
||
59 | add_action( 'admin_notices', array( $this, 'archive_warning' ) ); |
||
60 | |||
61 | } |
||
62 | |||
63 | /** |
||
64 | * Initializes the class |
||
65 | * |
||
66 | * @since 2.5.5 |
||
67 | */ |
||
68 | public function init() { |
||
69 | if ( ! is_null( $this->instance ) ) { |
||
70 | $this->instance = new self; |
||
71 | } |
||
72 | |||
73 | return $this->instance; |
||
74 | |||
75 | } |
||
76 | |||
77 | |||
78 | |||
79 | /** |
||
80 | * The Frontier Auto Display option tab. |
||
81 | * |
||
82 | * @param array $tabs |
||
83 | * @param array $pod |
||
84 | * @param array $addtl_args |
||
85 | * |
||
86 | * @return array |
||
87 | * |
||
88 | * @since 2.5.5 |
||
89 | */ |
||
90 | function tab( $tabs, $pod, $addtl_args ) { |
||
91 | |||
92 | $tabs[ 'pods-pfat' ] = __( 'Auto Template Options', 'pods' ); |
||
93 | |||
94 | return $tabs; |
||
95 | |||
96 | } |
||
97 | |||
98 | /** |
||
99 | * Adds options for this plugin under the Frontier Auto Template tab. |
||
100 | * |
||
101 | * @param array $options |
||
102 | * @param array $pod |
||
103 | * |
||
104 | * @return array |
||
105 | * |
||
106 | * @since 2.5.5 |
||
107 | * |
||
108 | */ |
||
109 | function options( $options, $pod ) { |
||
226 | |||
227 | /** |
||
228 | * Include/ init the front end class on the front end only |
||
229 | * |
||
230 | * @param bool $load_in_admin Optional. Whether to load in admin. Default is false. |
||
231 | * |
||
232 | * @return Pods_PFAT_Frontend |
||
233 | * |
||
234 | * @since 2.5.5 |
||
235 | */ |
||
236 | function front_end( $load_in_admin = false ) { |
||
250 | |||
251 | /** |
||
252 | * Reset the transients for front-end class when Pods are saved. |
||
253 | * |
||
254 | * @uses update_option hook |
||
255 | * |
||
256 | * @param string $option |
||
257 | * @param mixed $old_value |
||
258 | * @param mixed $value |
||
259 | * |
||
260 | * @since 2.5.5 |
||
261 | */ |
||
262 | function reset( $option, $old_value, $value ) { |
||
269 | |||
270 | |||
271 | /** |
||
272 | * Delete transients that stores the settings. |
||
273 | * |
||
274 | * @since 2.5.5 |
||
275 | */ |
||
276 | function reseter() { |
||
284 | |||
285 | /** |
||
286 | * Test if archive is set for post types that don't have archives. |
||
287 | * |
||
288 | * @return bool|mixed|null|void |
||
289 | * |
||
290 | * @since 2.4.5 |
||
291 | */ |
||
292 | function archive_test() { |
||
316 | |||
317 | /** |
||
318 | * Throw admin warnings for post types that have archive templates set, but don't support archives |
||
319 | * |
||
320 | * @since 2.4.5 |
||
321 | */ |
||
322 | function archive_warning() { |
||
347 | |||
348 | /** |
||
349 | * Get titles of all Pods Templates |
||
350 | * |
||
351 | * @return string[] Array of template names |
||
352 | * |
||
353 | * @since 2.4.5 |
||
354 | */ |
||
355 | public function get_template_titles() { |
||
372 | |||
373 | |||
374 | } |
||
375 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.