PluginProbe ʕ •ᴥ•ʔ
ShopPress – Shop Builder for Elementor and WooCommerce / trunk
ShopPress – Shop Builder for Elementor and WooCommerce vtrunk
shop-press / Templates / Render.php
shop-press / Templates Last commit date
Checkout 1 year ago Single 1 week ago Archive.php 4 months ago Cart.php 1 year ago EmptyCart.php 1 year ago Main.php 1 year ago MyAccount.php 1 year ago ProductCollection.php 1 week ago ProductLoopContent.php 1 year ago ProductShop.php 1 week ago Render.php 1 week ago Shop.php 1 year ago Thankyou.php 1 week ago Utils.php 1 week ago
Render.php
150 lines
1 <?php
2 /**
3 * Render Templates.
4 *
5 * @package ShopPress
6 */
7
8 namespace ShopPress\Templates;
9
10 defined( 'ABSPATH' ) || exit;
11
12 use Elementor\Plugin;
13 use ShopPress\Elementor;
14
15 class Render {
16 /**
17 * Render builder content.
18 *
19 * @since 1.3.0
20 *
21 * @param int $builder_id
22 */
23 public static function get_builder_content( $builder_id ) {
24 $builder_type = sp_get_builder_type( $builder_id );
25
26 ob_start();
27
28 if ( 'elementor' === $builder_type && class_exists( '\Elementor\Plugin' ) ) {
29
30 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Elementor outputs safe builder HTML.
31 echo Plugin::instance()->frontend->get_builder_content_for_display( $builder_id, false );
32 } elseif ( 'block_editor' === $builder_type ) {
33
34 $content = get_post_field( 'post_content', $builder_id );
35 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- do_blocks outputs safe block HTML.
36 echo do_blocks( $content );
37 }
38
39 return ob_get_clean();
40 }
41
42 /**
43 * Locate the themplate.
44 *
45 * @since 1.4.2
46 *
47 * @param string $template_name
48 *
49 * @return string
50 */
51 public static function locate_template( $template_name ) {
52 global $wp_stylesheet_path, $wp_template_path;
53
54 if ( ! isset( $wp_stylesheet_path ) || ! isset( $wp_template_path ) ) {
55 wp_set_template_globals();
56 }
57
58 $located = '';
59 if ( file_exists( $wp_stylesheet_path . '/shop-press/' . $template_name ) ) {
60 $located = $wp_stylesheet_path . '/shop-press/' . $template_name;
61 } elseif ( is_child_theme() && file_exists( $wp_template_path . '/shop-press/' . $template_name ) ) {
62 $located = $wp_template_path . '/shop-press/' . $template_name;
63 }
64
65 return $located;
66 }
67
68 /**
69 * Load the builder template.
70 *
71 * @since 1.3.0
72 *
73 * @param string $template_name
74 * @param array $args
75 * @param bool $is_pro
76 *
77 * @return void
78 */
79 public static function load_builder_template( $template_name, $args = array(), $is_pro = false ) {
80 $base = ( $is_pro && defined( 'SHOPPRESS_PRO_PATH' ) ) ? SHOPPRESS_PRO_PATH : SHOPPRESS_PATH;
81 $builder = explode( '/', $template_name )[0] ?? '';
82 $template_path = self::locate_template( basename( "{$template_name}.php" ) );
83 if ( ! $template_path ) {
84 $template_path = $base . "public/templates/{$template_name}.php";
85 }
86
87 /**
88 * Filters the path of the template.
89 *
90 * @since 1.3.0
91 *
92 * @param string $template_path
93 * @param string $template_name
94 * @param bool $is_pro
95 */
96 $template_path = apply_filters( 'shoppress/builder/template_path', $template_path, $template_name, $is_pro );
97
98 /**
99 * Fires before a template file is loaded.
100 *
101 * @since 1.3.0
102 *
103 * @param string $builder
104 * @param string $template_path
105 * @param array $args
106 * @param bool $is_pro
107 */
108 do_action( 'shoppress/builder/before_load_template', $builder, $template_name, $args, $is_pro );
109
110 if ( file_exists( $template_path ) ) {
111 require $template_path;
112 }
113
114 /**
115 * Fires after a template file is loaded.
116 *
117 * @since 1.3.0
118 *
119 * @param string $builder
120 * @param string $template_path
121 * @param array $args
122 * @param bool $is_pro
123 */
124 do_action( 'shoppress/builder/after_load_template', $builder, $template_name, $args, $is_pro );
125 }
126
127 /**
128 * Returns the list of the builders that need to set post data.
129 *
130 * @since 1.3.0
131 *
132 * @return array
133 */
134 public static function get_builders_need_set_post_data() {
135 $builders = array(
136 'single-product',
137 'loop',
138 );
139
140 /**
141 * Filters the list of the builders that need to set post data.
142 *
143 * @since 1.3.0
144 *
145 * @param array $builders
146 */
147 return apply_filters( 'shoppress/builder/items_to_set_post_data', $builders );
148 }
149 }
150