PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 1.3.4
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v1.3.4
4.9.2 4.9.1 4.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.1 3.0.0 3.1.0 3.1.1 4.0.0 4.0.1 4.1.0 4.1.1 4.2.0 4.2.1 4.3.0 4.3.1 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.6.8 4.6.9 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.8.9 trunk 0.1.2-beta 0.1.3-beta 0.1.4-beta 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.5.0 1.5.1 1.6.0 1.6.1 1.7.0 1.8.0 1.8.1 1.9.0
shopengine / core / builders / hooks.php
shopengine / core / builders Last commit date
action.php 4 years ago api.php 5 years ago base.php 4 years ago hooks.php 4 years ago templates.php 4 years ago
hooks.php
274 lines
1 <?php
2
3 namespace ShopEngine\Core\Builders;
4
5 use ShopEngine\Core\PageTemplates\Page_Templates;
6 use ShopEngine\Core\Template_Cpt;
7 use ShopEngine\Traits\Singleton;
8
9 defined('ABSPATH') || exit;
10
11 class Hooks
12 {
13
14 use Singleton;
15
16 public $action;
17 public $actionPost_type = ['product']; // only for woocommerce product
18
19
20 public function init() {
21
22 $this->action = new Action();
23 $cptName = Template_Cpt::TYPE;
24
25 // check admin init
26 add_action('admin_init', [$this, 'add_author_support'], 10);
27 add_filter('manage_' . $cptName . '_posts_columns', [$this, 'set_columns']);
28 add_action('manage_' . $cptName . '_posts_custom_column', [$this, 'render_column'], 10, 2);
29
30 // add filter for search
31 add_action('restrict_manage_posts', [$this, 'add_filter']);
32 // query filter
33 add_filter('parse_query', [$this, 'query_filter']);
34 }
35
36
37 /**
38 * Public function add_author_support.
39 * check author support
40 *
41 * @since 1.0.0
42 */
43 public function add_author_support() {
44
45 add_post_type_support(Template_Cpt::TYPE, 'author');
46 }
47
48
49 /**
50 * Public function set_columns.
51 * set column for custom post type
52 *
53 * @since 1.0.0
54 */
55 public function set_columns($columns) {
56
57 $date_column = $columns['date'];
58 $author_column = $columns['author'];
59
60 unset($columns['date']);
61 unset($columns['author']);
62
63 $columns['type'] = esc_html__('Type', 'shopengine');
64 $columns['set_default'] = esc_html__('Default', 'shopengine');
65 $columns['author'] = esc_html($author_column);
66 $columns['date'] = esc_html($date_column);
67
68 return $columns;
69 }
70
71
72 /**
73 * Public function render_column.
74 * Render column for custom post type
75 *
76 * @since 1.0.0
77 *
78 * @param $column
79 * @param $post_id
80 */
81 public function render_column($column, $post_id) {
82
83 $data = get_post_meta($post_id, Action::PK__SHOPENGINE_TEMPLATE, true);
84 $template_type = isset($data['form_type']) ? $data['form_type'] : '';
85 $get_id_from_db_by_template_type = Templates::get_registered_template_id($template_type);
86 $template_config_data = \ShopEngine\Core\PageTemplates\Page_Templates::instance()->getTemplate($template_type);
87 $template_class = $template_config_data['class'] ?? null;
88
89 switch($column) {
90 case 'type':
91 // echo '<pre>';
92 // print_r([$template_type, $get_id_from_db_by_template_type, $template_config_data, $template_class]);
93 // echo '</pre>';
94
95 $template = Page_Templates::instance()->getTemplate($template_type);
96 echo empty($template) ? '' : $template['title'];
97 break;
98
99 case 'set_default':
100
101 if($get_id_from_db_by_template_type == $post_id && class_exists($template_class)) {
102 echo '<span class="shopengine_default type-'.esc_attr($template_type).' shopengine-active"> ' . esc_html__('Active', 'shopengine') . ' </span>';
103 } else {
104 echo '<span class="shopengine_default type-'.esc_attr($template_type).' shopengine-deactive"> ' . esc_html__('Inactive', 'shopengine') . ' </span>';
105 }
106 break;
107 }
108 }
109
110
111 /**
112 * Public function add_filter.
113 * Added search filter for type of template
114 *
115 * @since 1.0.0
116 */
117 public function add_filter() {
118
119 global $typenow;
120
121 if($typenow == Template_Cpt::TYPE) {
122
123 $selected = isset($_GET['type']) ? sanitize_key($_GET['type']) : ''; ?>
124
125 <select name="type" id="type">
126
127 <option value="all" <?php selected('all', $selected); ?>><?php esc_html_e('Template Type ', 'shopengine'); ?></option> <?php
128
129 foreach(Templates::get_template_types() as $key => $value) { ?>
130 <option value="<?php echo esc_attr($key); ?>" <?php selected($key, $selected); ?>><?php echo esc_attr($value['title']); ?></option> <?php
131 }
132
133 ?>
134
135 </select>
136 <?php
137 }
138 }
139
140
141 /**
142 * Public function query_filter.
143 * Search query filter added in search query
144 *
145 * @since 1.0.0
146 * @param $query
147 */
148 public function query_filter($query) {
149
150 global $pagenow;
151
152 $current_page = isset($_GET['post_type']) ? sanitize_key($_GET['post_type']) : '';
153
154 if(
155 is_admin()
156 && Template_Cpt::TYPE == $current_page
157 && 'edit.php' == $pagenow
158 && isset($_GET['type'])
159 && $_GET['type'] != ''
160 && $_GET['type'] != 'all'
161 ) {
162 $type = isset($_GET['type']) ? sanitize_key($_GET['type']) : '';
163 $query->query_vars['meta_key'] = Action::get_meta_key_for_type();
164 $query->query_vars['meta_value'] = $type;
165 $query->query_vars['meta_compare'] = '=';
166 }
167 }
168
169
170 /**
171 * Public function template_selected.
172 * add meta box for choose template ShopEngine
173 *
174 * @since 1.0.0
175 */
176 public function template_selected() {
177 global $post;
178
179 if(in_array($post->post_type, $this->actionPost_type)):
180 foreach($this->actionPost_type as $k => $v):
181 add_meta_box(
182 'shopengine_template',
183 esc_html__('ShopEngine Template', 'shopengine'),
184 [$this, 'shopengine_template'],
185 $v,
186 'side',
187 'low'
188 );
189 endforeach;
190 endif;
191 }
192
193
194 /**
195 * Public function template_save.
196 * ShopEngine Template save for product
197 *
198 * @since 1.0.0
199 */
200 public function template_save($post_id, $post) {
201 if(!current_user_can('edit_post', $post_id)) {
202 return $post_id;
203 }
204
205 if(in_array($post->post_type, $this->actionPost_type)):
206 if(isset($_POST['shopengine-template'])) {
207 update_post_meta($post_id, Action::PK__SHOPENGINE_TEMPLATE . '__template', sanitize_key($_POST['shopengine-template']));
208 }
209 endif;
210 }
211
212
213 /**
214 * Public function shopengine_template.
215 * ShopEngine Template Html
216 *
217 * @since 1.0.0
218 */
219 public function shopengine_template() {
220 global $post;
221
222 if(!isset($post->ID)) {
223 return '';
224 }
225
226 $page_template = get_post_meta($post->ID, Action::PK__SHOPENGINE_TEMPLATE . '__template', true);
227
228 $template = $this->get_post_single();
229 echo '<select name="shopengine-template">';
230 echo '<option value="0"> ' . esc_html__('Defalut', 'shopengine') . ' </option>';
231 if(is_array($template) && sizeof($template) > 0) {
232 foreach($template as $k => $v) {
233 $select = '';
234 if($page_template == $k) {
235 $select = 'selected';
236 }
237 echo '<option value="' . $k . '" ' . $select . '> ' . esc_html__($v, 'shopengine') . ' </option>';
238 }
239 }
240 echo '</select>';
241 }
242
243
244 /**
245 * get query post query
246 *
247 * @return array
248 */
249 public function get_post_single() {
250
251 $args['post_status'] = 'publish';
252 $args['post_type'] = Template_Cpt::TYPE;
253 $args['meta_query'] = [
254 'relation' => 'AND',
255 array(
256 'key' => Action::get_meta_key_for_type(),
257 'value' => 'single',
258 'compare' => '=',
259 ),
260 ];
261
262 $posts = get_posts($args);
263 $options = [];
264 $count = count($posts);
265 if($count > 0):
266 foreach($posts as $post) {
267 $options[$post->ID] = $post->post_title;
268 }
269 endif;
270
271 return $options;
272 }
273 }
274