PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 3.1.0
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v3.1.0
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 3 years ago api.php 3 years ago base.php 3 years ago hooks.php 3 years ago templates.php 3 years ago
hooks.php
226 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 use ShopEngine\Utils\Helper;
9
10 defined('ABSPATH') || exit;
11
12 class Hooks {
13
14 use Singleton;
15
16 public $action;
17 public $actionPost_type = ['product']; // only for woocommerce product
18 public $languages = [];
19 public $activated_templates = [];
20
21 public function init() {
22
23 $this->action = new Action();
24 $cptName = Template_Cpt::TYPE;
25
26 // check admin init
27 add_action('admin_init', [$this, 'add_author_support'], 10);
28 add_filter('manage_' . $cptName . '_posts_columns', [$this, 'set_columns']);
29 add_action('manage_' . $cptName . '_posts_custom_column', [$this, 'render_column'], 10, 2);
30
31 // add filter for search
32 add_action('restrict_manage_posts', [$this, 'add_filter']);
33 // query filter
34 add_filter('parse_query', [$this, 'query_filter']);
35
36 add_action('elementor/editor/init', [$this, 'elementor_editor_initialized']);
37 }
38
39 /**
40 * On shopengine template elementor editor
41 * Check if the shopengine product id exists for single template
42 *
43 * @since 2.5.0
44 */
45 public function elementor_editor_initialized()
46 {
47 global $post;
48 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This hook can access only admin and already verified from elementor
49 if ( !empty( $_GET['action'] ) && sanitize_text_field( wp_unslash( $_GET['action'] ) ) === 'elementor' && get_post_type( $post ) === 'shopengine-template' ) {
50 $template_type = get_post_meta( $post->ID, 'shopengine_template__post_meta__type', true );
51 $checkable_template_type = ['single', 'quick_view'];
52 // Check if the template is single or quick view template
53 if ( in_array( $template_type, $checkable_template_type ) ) {
54 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
55 if ( empty( $_GET['shopengine_product_id'] ) || !wc_get_product( intval( $_GET['shopengine_product_id'] ) ) ) {
56 wp_safe_redirect( Helper::get_admin_list_template_url() );
57 exit();
58 }
59 }
60 }
61 }
62
63 /**
64 * Public function add_author_support.
65 * check author support
66 *
67 * @since 1.0.0
68 */
69 public function add_author_support() {
70 $this->languages = apply_filters('shopengine_multi_language', ['status' => false, 'lang_items' => []]);
71 $this->activated_templates = Action::get_activated_templates();
72
73 add_post_type_support(Template_Cpt::TYPE, 'author');
74 }
75
76
77 /**
78 * Public function set_columns.
79 * set column for custom post type
80 *
81 * @since 1.0.0
82 */
83 public function set_columns($columns) {
84
85 $date_column = $columns['date'];
86 $author_column = $columns['author'];
87
88 unset($columns['date']);
89 unset($columns['author']);
90
91 $columns['type'] = esc_html__('Type', 'shopengine');
92
93 if(true === $this->languages['status']) {
94 $columns['lang'] = esc_html__('Language', 'shopengine');
95 }
96
97 $columns['status'] = esc_html__('Status', 'shopengine');
98 $columns['builder'] = esc_html__('Builder', 'shopengine');
99 $columns['author'] = esc_html($author_column);
100 $columns['date'] = esc_html($date_column);
101
102 return $columns;
103 }
104
105 /**
106 * Public function render_column.
107 * Render column for custom post type
108 *
109 * @param $column
110 * @param $post_id
111 * @since 1.0.0
112 *
113 */
114 public function render_column($column, $post_id) {
115
116 $data = get_post_meta($post_id, Action::PK__SHOPENGINE_TEMPLATE, true);
117 $template_type = isset($data['form_type']) ? $data['form_type'] : '';
118 $template_config_data = Page_Templates::instance()->getTemplate($template_type);
119 $template_class = $template_config_data['class'] ?? null;
120 $category_id = !empty($data['category_id']) ? $data['category_id'] : 0;
121 $template_language = get_post_meta($post_id, 'language_code', true);
122
123 switch($column) {
124 case 'type':
125 echo esc_html(empty($template_config_data['title']) ? '' : $template_config_data['title']);
126 if(class_exists(\ShopEngine_Pro::class)) {
127 $cat_name = get_the_category_by_ID($category_id);
128 if(isset($cat_name) && !is_wp_error($cat_name)) {
129 echo '<br>' . esc_html__('Category', 'shopengine') .' : '. esc_html($cat_name);
130 }
131 }
132 break;
133
134 case 'lang':
135 if(!empty($this->languages['lang_items'][$template_language]['country_flag_url'])) {
136 ?>
137 <img src="<?php echo esc_url($this->languages['lang_items'][$template_language]['country_flag_url'])?>">
138 <?php
139 }
140 break;
141
142 case 'builder':
143 $builder = Helper::get_template_builder_type($post_id);;
144 echo esc_html(empty($builder) ? 'elementor' : $builder);
145 break;
146
147 case 'status':
148
149 $status = esc_html__('Inactive', 'shopengine');
150 $status_class = 'shopengine-deactive';
151
152 if(class_exists($template_class)) {
153 $template_data = Action::get_template_data($post_id, $this->activated_templates);
154 if('en' === $template_language) {
155 if(is_array($template_data) && $template_data['status']) {
156 $status = esc_html__('Active', 'shopengine');
157 $status_class = 'shopengine-active';
158 }
159 } elseif($this->languages['status'] && is_array($template_data) && $template_data['status']) {
160 $status = esc_html__('Active', 'shopengine');
161 $status_class = 'shopengine-active';
162 }
163 }
164
165 echo wp_kses('<span class="shopengine_default type-'.$template_type . ' ' . $status_class.'"> ' . $status . ' </span>', Helper::get_kses_array());
166 break;
167 }
168 }
169
170 /**
171 * Public function add_filter.
172 * Added search filter for type of template
173 *
174 * @since 1.0.0
175 */
176 public function add_filter() {
177
178 global $typenow;
179
180 if($typenow == Template_Cpt::TYPE) {
181
182 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This hook can access only admin And not possible to verify nonce here
183 $selected = isset($_GET['type']) ? sanitize_key($_GET['type']) : ''; ?>
184
185 <select name="type" id="type">
186
187 <option value="all" <?php selected('all', $selected); ?>><?php esc_html_e('Template Type ', 'shopengine'); ?></option> <?php
188
189 foreach(Templates::get_template_types() as $key => $value) { ?>
190 <option value="<?php echo esc_attr($key); ?>" <?php selected($key, $selected); ?>><?php esc_html_e($value['title'], 'shopengine'); ?></option>
191 <?php } ?>
192
193 </select>
194 <?php
195 }
196 }
197
198 /**
199 * Public function query_filter.
200 * Search query filter added in search query
201 *
202 * @param $query
203 * @since 1.0.0
204 */
205 public function query_filter($query) {
206
207 global $pagenow;
208 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This hook can access only admin And not possible to verify nonce here
209 $current_page = isset($_GET['post_type']) ? sanitize_key($_GET['post_type']) : '';
210
211 if(
212 is_admin()
213 && Template_Cpt::TYPE == $current_page
214 && 'edit.php' == $pagenow
215 && !empty($_GET['type']) // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This hook can access only admin And not possible to verify nonce here
216 && $_GET['type'] != 'all' // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This hook can access only admin And not possible to verify nonce here
217 ) {
218 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This hook can access only admin And not possible to verify nonce here
219 $type = sanitize_key($_GET['type']);
220 $query->query_vars['meta_key'] = Action::get_meta_key_for_type();
221 $query->query_vars['meta_value'] = $type;
222 $query->query_vars['meta_compare'] = '=';
223 }
224 }
225 }
226