-
Notifications
You must be signed in to change notification settings - Fork 205
Expand file tree
/
Copy pathclass-give-template-loader.php
More file actions
146 lines (125 loc) · 3.55 KB
/
Copy pathclass-give-template-loader.php
File metadata and controls
146 lines (125 loc) · 3.55 KB
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
<?php
/**
* Template Loader
*
* @package Give
* @subpackage Classes/Give_Template_Loader
* @copyright Copyright (c) 2016, Give
* @license https://opensource.org/licenses/gpl-license GNU Public License
* @since 1.0
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Give_Template_Loader Class
*
* Base class template loader.
*
* @since 1.0
*/
class Give_Template_Loader {
/**
* Class Constructor
*
* Set up the template loader Class.
*
* @since 1.0
* @access public
*/
public function __construct() {
/**
* Templates
*/
add_filter( 'template_include', array( __CLASS__, 'template_loader' ) );
/**
* Content Wrappers
*/
add_action( 'give_before_main_content', 'give_output_content_wrapper', 10 );
add_action( 'give_after_main_content', 'give_output_content_wrapper_end', 10 );
/**
* Entry Summary Classes
*/
add_filter( 'give_forms_single_summary_classes', array( $this, 'give_set_single_summary_classes' ) );
/**
* Sidebar
*/
add_action( 'give_before_single_form_summary', array( $this, 'give_output_sidebar_option' ), 1 );
/**
* Single Forms Summary Box
*/
add_action( 'give_single_form_summary', 'give_template_single_title', 5 );
add_action( 'give_single_form_summary', 'give_get_donation_form', 10 );
}
/**
* Give Set Single Summary Classes
*
* Determines if the single form should be full width or with a sidebar.
*
* @access public
*
* @param string $classes List of space separated class names.
*
* @return string $classes List of space separated class names.
*/
public function give_set_single_summary_classes( $classes ) {
// Add full width class when feature image is disabled AND no widgets are present
if ( ! give_is_setting_enabled( give_get_option( 'form_sidebar' ) ) ) {
$classes .= ' give-full-width';
}
return $classes;
}
/**
* Output sidebar option
*
* Determines whether the user has enabled or disabled the sidebar for Single Give forms.
*
* @since 1.3
* @access public
*
* @return void
*/
public function give_output_sidebar_option() {
// Add full width class when feature image is disabled AND no widgets are present
if ( give_is_setting_enabled( give_get_option( 'form_sidebar' ) ) ) {
add_action( 'give_before_single_form_summary', 'give_left_sidebar_pre_wrap', 5 );
add_action( 'give_before_single_form_summary', 'give_show_form_images', 10 );
add_action( 'give_before_single_form_summary', 'give_get_forms_sidebar', 20 );
add_action( 'give_before_single_form_summary', 'give_left_sidebar_post_wrap', 30 );
}
}
/**
* Load a template.
*
* Handles template usage so that we can use our own templates instead of the themes.
*
* Templates are in the 'templates' folder. Give looks for theme
* overrides in /theme/give/ by default.
*
* For beginners, it also looks for a give.php template first. If the user adds this
* to the theme (containing give() inside) this will be used for all give templates.
*
* @access public
*
* @param mixed $template
*
* @return string $template
*/
public static function template_loader( $template ) {
$find = array( 'give.php' );
$file = '';
if ( is_single() && get_post_type() == 'give_forms' ) {
$file = 'single-give-form.php';
$find[] = $file;
$find[] = apply_filters( 'give_template_path', 'give/' ) . $file;
}
if ( $file ) {
$template = locate_template( array_unique( $find ) );
if ( ! $template ) {
$template = GIVE_PLUGIN_DIR . '/templates/' . $file;
}
}
return $template;
}
}