PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 2.8.16
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v2.8.16
3.13.4 3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 All 262 releases
wpfunnels / includes / core / page-templates / class-manager.php

class-manager.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 2.8.16, at includes/core/page-templates/class-manager.php

280 lines 7.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Page template
4 *
5 * @package
6 */
7 namespace WPFunnels\PageTemplates;
8
9 use WPFunnels\Base_Manager;
10 use WPFunnels\Wpfnl_functions;
11
12 class Manager extends Base_Manager {
13
14
15 const TEMPLATE_Boxed = 'wpfunnels_boxed';
16
17
18 const TEMPLATE_DEFAULT = 'wpfunnels_default';
19
20
21 const TEMPLATE_FULLWIDTH_WITHOUT_HEADER_FOOTER = 'wpfunnels_fullwidth_without_header_footer';
22
23
24 const TEMPLATE_CHECKOUT = 'wpfunnels_checkout';
25
26
27 protected $print_callback;
28
29 /**
30 * Body class of the page templates
31 *
32 * @var $body_class
33 */
34 protected $body_class = array();
35
36
37 public function __construct() {
38 add_action( 'init', [ $this, 'add_wp_templates_support' ] );
39 add_filter( 'template_include', [ $this, 'template_include' ], 90 );
40 }
41
42
43 public function add_wp_templates_support() {
44 $post_types = array( WPFNL_STEPS_POST_TYPE );
45
46 foreach ( $post_types as $post_type ) {
47 add_filter( "theme_{$post_type}_templates", [ $this, 'add_funnel_page_templates' ], 9999, 4 );
48 }
49 }
50
51
52 public function template_include( $template ) {
53 if ( is_singular() ) {
54
55 global $post;
56
57 // Return template if post is empty
58 if ( ! $post ) {
59 return $template;
60 }
61
62 if ( is_object( $post ) && WPFNL_STEPS_POST_TYPE === $post->post_type ) {
63 add_filter( 'next_post_rel_link', '__return_empty_string' );
64 add_filter( 'previous_post_rel_link', '__return_empty_string' );
65
66 $page_template = apply_filters( 'wpfunnels/page_template', $this->get_page_template($post->ID) );
67 $template_path = $this->get_template_path( $page_template );
68 if ( $template_path ) {
69 $template = $template_path;
70 }
71 }
72 }
73
74 return $template;
75 }
76
77
78 private function get_page_template($post_id) {
79 return get_post_meta( $post_id, '_wp_page_template', true );
80 }
81
82
83 /**
84 * Add funnel page template
85 *
86 * @param $page_templates
87 * @param $wp_theme
88 * @param $post
89 *
90 * @return array
91 *
92 * @since 1.0.0
93 */
94 public function add_funnel_page_templates( $page_templates, $wp_theme, $post ) {
95 $wpfnl_templates = [
96 self::TEMPLATE_DEFAULT => _x( 'WPFunnels Default', 'Page Template', 'wpfnl' ),
97 self::TEMPLATE_FULLWIDTH_WITHOUT_HEADER_FOOTER => _x( 'WPFunnels Canvas', 'Page Template', 'wpfnl' ),
98 self::TEMPLATE_Boxed => _x( 'WPFunnels Boxed', 'Page Template', 'wpfnl' ),
99 ];
100
101 if ( apply_filters( 'wpfunnels/show_all_page_templates', false ) ) {
102 $wpfnl_templates = $wpfnl_templates + $page_templates;
103 }
104
105 return $wpfnl_templates;
106 }
107
108
109 public function set_print_callback( $callback ) {
110 $this->print_callback = $callback;
111 }
112
113
114 public function print_callback() {
115 while ( have_posts() ) :
116 the_post();
117 the_content();
118 endwhile;
119 }
120
121
122 public function print_content() {
123
124 if ( ! $this->print_callback ) {
125 $this->print_callback = [ $this, 'print_callback' ];
126 }
127
128 call_user_func( $this->print_callback );
129 }
130
131
132 public function get_template_path( $page_template ) {
133 $template_path = '';
134 switch ( $page_template ) {
135 case self::TEMPLATE_DEFAULT:
136 $template_path = __DIR__ . '/templates/template-default.php';
137 $this->body_class[] = $page_template;
138 break;
139 case self::TEMPLATE_FULLWIDTH_WITHOUT_HEADER_FOOTER:
140 $template_path = __DIR__ . '/templates/template-canvas.php';
141 $this->body_class[] = $page_template;
142 break;
143 case self::TEMPLATE_Boxed:
144 $template_path = __DIR__ . '/templates/template-boxed.php';
145 $this->body_class[] = $page_template;
146 break;
147 }
148 if( file_exists($template_path) ) {
149 add_filter( 'body_class', array( $this, 'body_class' ) );
150 return $template_path;
151 }
152 return $template_path;
153 }
154
155
156 /**
157 * Assign body clas for specific template
158 *
159 * @param $classes
160 *
161 * @return array
162 */
163 public function body_class( $classes ) {
164 return array_merge( $classes, $this->body_class );
165 }
166
167
168 public function action_register_template_control( $document ) {
169 if ( $document instanceof PageBase || $document instanceof LibraryPageDocument ) {
170 $this->register_template_control( $document );
171 }
172 }
173
174
175 public function register_template_control( $document, $control_id = 'template' ) {
176 if ( ! Utils::is_cpt_custom_templates_supported() ) {
177 return;
178 }
179
180 require_once ABSPATH . '/wp-admin/includes/template.php';
181
182 $document->start_injection( [
183 'of' => 'post_status',
184 'fallback' => [
185 'of' => 'post_title',
186 ],
187 ] );
188
189 $control_options = [
190 'options' => array_flip( get_page_templates( null, $document->get_main_post()->post_type ) ),
191 ];
192
193 $this->add_template_controls( $document, $control_id, $control_options );
194
195 $document->end_injection();
196 }
197
198
199 public function add_template_controls( Document $document, $control_id, $control_options ) {
200 // Default Control Options
201 $default_control_options = [
202 'label' => __( 'Page Layout', 'wpfnl' ),
203 'type' => Controls_Manager::SELECT,
204 'default' => 'wpfunnels_default',
205 'options' => [
206 'default' => __( 'Default', 'wpfnl' ),
207 ],
208 ];
209
210 $control_options = array_replace_recursive( $default_control_options, $control_options );
211
212 $document->add_control(
213 $control_id,
214 $control_options
215 );
216
217 $document->add_control(
218 $control_id . '_default_description',
219 [
220 'type' => Controls_Manager::RAW_HTML,
221 'raw' => '<b>' . __( 'Default Page Template from your theme', 'wpfnl' ) . '</b>',
222 'content_classes' => 'elementor-descriptor',
223 'condition' => [
224 $control_id => 'default',
225 ],
226 ]
227 );
228
229 $document->add_control(
230 $control_id . '_canvas_description',
231 [
232 'type' => Controls_Manager::RAW_HTML,
233 'raw' => '<b>' . __( 'No header, no footer, just Elementor', 'wpfnl' ) . '</b>',
234 'content_classes' => 'elementor-descriptor',
235 'condition' => [
236 $control_id => self::TEMPLATE_Boxed,
237 ],
238 ]
239 );
240
241 $document->add_control(
242 $control_id . '_header_footer_description',
243 [
244 'type' => Controls_Manager::RAW_HTML,
245 'raw' => '<b>' . __( 'This template includes the header, full-width content and footer', 'wpfnl' ) . '</b>',
246 'content_classes' => 'elementor-descriptor',
247 'condition' => [
248 $control_id => self::TEMPLATE_HEADER_FOOTER,
249 ],
250 ]
251 );
252
253 if ( $document instanceof Kit ) {
254 $document->add_control(
255 'reload_preview_description',
256 [
257 'type' => Controls_Manager::RAW_HTML,
258 'raw' => __( 'Changes will be reflected in the preview only after the page reloads.', 'wpfnl' ),
259 'content_classes' => 'elementor-descriptor',
260 ]
261 );
262 }
263 }
264
265
266 public static function body_open() {
267 if ( function_exists( 'wp_body_open' ) ) {
268 wp_body_open();
269 } else {
270 do_action( 'wp_body_open' );
271 }
272 }
273
274
275 public function get_name() {
276 return 'page-templates';
277 }
278
279 }
280