PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.56
E2Pdf – Export Pdf Tool for WordPress v1.32.56
1.32.55 1.32.56 1.32.53 1.32.51 1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 All 76 releases
← All changes | classes/extension/e2pdf-wordpress.php +1604 -481 1.00.00 → 1.32.56 View file →
@@ -1,655 +1,1778 @@
1 1 <?php
2 2
3 3 /**
4 - * E2pdf Wordpress Extension
5 - *
6 - * @copyright Copyright 2017 https://e2pdf.com
7 - * @license GPL v2
8 - * @version 1
9 - * @link https://e2pdf.com
10 - * @since 0.00.01
4 + * File: /extension/e2pdf-wordpress.php
5 + *
6 + * @package E2Pdf
7 + * @license GPLv3
8 + * @link https://e2pdf.com
11 9 */
12 10 if (!defined('ABSPATH')) {
13 11 die('Access denied.');
14 12 }
15 13
14 +// phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName
16 15 class Extension_E2pdf_Wordpress extends Model_E2pdf_Model {
17 16
18 17 private $options;
18 + private $info = [
19 + 'key' => 'wordpress',
20 + 'title' => 'WordPress',
21 + ];
19 22
20 - function __construct() {
21 - parent::__construct();
23 + // info
24 + public function info($key = false) {
25 + if ($key && isset($this->info[$key])) {
26 + return $this->info[$key];
27 + } else {
28 + return [
29 + $this->info['key'] => $this->info['title'],
30 + ];
31 + }
22 32 }
23 33
24 - /**
25 - * Get info about extension
26 - *
27 - * @return array() - Extension key and name
28 - */
29 - public function info() {
30 - return array(
31 - 'wordpress' => __('Wordpress', 'e2pdf')
32 - );
33 - }
34 -
35 - /**
36 - * Check if needed plugin active
37 - *
38 - * @return bool - Activated/Not Activated plugin
39 - */
34 + // active
40 35 public function active() {
41 36 return true;
42 37 }
43 38
44 - /**
45 - * Check if export item function available
46 - *
47 - * @return bool - Item export available/not available
48 - */
49 - public function export() {
50 - return false;
51 - }
52 -
53 - /**
54 - * Set option
55 - *
56 - * @param string $attr - Key of option
57 - * @param string $value - Value of option
58 - *
59 - * @return bool - Status of setting option
60 - */
39 + // set
61 40 public function set($key, $value) {
62 41 if (!isset($this->options)) {
63 42 $this->options = new stdClass();
64 43 }
65 -
66 44 $this->options->$key = $value;
45 + switch ($key) {
46 + case 'dataset':
47 + $this->set('cached_post', false);
48 + if ($this->get('dataset')) {
49 + if ($this->get('item') == '-3') {
50 + $this->set('cached_post', get_user_by('id', $this->get('dataset')));
51 + } else {
52 + $pll = $this->helper->load('translator')->isPolylang();
53 + if ($pll) {
54 + $lang = pll_get_post_language($this->get('dataset'));
55 + if ($lang) {
56 + PLL()->curlang = PLL()->model->get_language($lang);
57 + }
58 + }
59 + $this->set('cached_post', get_post($this->get('dataset')));
60 + }
61 + }
62 + break;
63 + default:
64 + break;
65 + }
67 66 }
68 67
69 - /**
70 - * Get option by key
71 - *
72 - * @param string $key - Key to get assigned option value
73 - *
74 - * @return mixed
75 - */
68 + // get
76 69 public function get($key) {
70 + if ($key == 'user_id' && $this->get('item') == '-3') {
71 + $key = 'dataset';
72 + }
77 73 if (isset($this->options->$key)) {
78 74 $value = $this->options->$key;
79 - return $value;
80 75 } else {
81 - return false;
76 + switch ($key) {
77 + case 'args':
78 + $value = [];
79 + break;
80 + default:
81 + $value = false;
82 + break;
83 + }
82 84 }
85 + return $value;
83 86 }
84 87
85 - /**
86 - * Get items to work with
87 - *
88 - * @return array() - List of available items
89 - */
90 - public function get_items() {
91 - $content = array();
92 -
93 - $content[] = array(
94 - 'key' => 'post',
95 - 'value' => __('Wordpress Posts', 'e2pdf'),
96 - );
97 - $content[] = array(
98 - 'key' => 'page',
99 - 'value' => __('Wordpress Pages', 'e2pdf'),
100 - );
101 -
102 - return $content;
88 + // items
89 + public function items() {
90 + $items = [];
91 + $forms = get_post_types([], 'names');
92 + foreach ($forms as $form) {
93 + if ($form != 'attachment') {
94 + $items[] = $this->item($form);
95 + }
96 + }
97 + $items[] = $this->item('-3');
98 + return $items;
103 99 }
104 100
105 - /**
106 - * Get entries for export
107 - *
108 - * @param string $item - Item
109 - * @param string $name - Entries names
110 - *
111 - * @return array() - Entries list
112 - */
113 - public function get_datasets($item = false, $name = false) {
101 + // datasets
102 + public function datasets($item_id = false, $name = false) {
103 + $datasets = [];
104 + if ($item_id) {
105 + if ($item_id == '-3') {
106 + $entries = get_users(
107 + [
108 + 'fields' => [
109 + 'ID', 'user_login',
110 + ],
111 + ]
112 + );
114 113
115 - $datasets = array();
116 - if ($item == 'page') {
117 - $datasets_tmp = get_pages();
118 - } elseif ($item == 'post') {
119 - $datasets_tmp = get_posts();
120 - }
121 -
122 - if ($datasets_tmp) {
123 - foreach ($datasets_tmp as $key => $dataset) {
124 - $this->set('item', $item);
125 - $this->set('dataset', $dataset->ID);
126 - $dataset_title = $this->render($name);
127 - if (!$dataset_title) {
128 - $dataset_title = $dataset->post_title;
114 + if ($entries) {
115 + $this->set('item', $item_id);
116 + foreach ($entries as $key => $entry) {
117 + $this->set('dataset', $entry->ID);
118 + $entry_title = $this->render($name);
119 + if (!$entry_title) {
120 + $entry_title = isset($entry->user_login) && $entry->user_login ? $entry->user_login : $entry->ID;
121 + }
122 + $datasets[] = [
123 + 'key' => $entry->ID,
124 + 'value' => $entry_title,
125 + ];
126 + }
129 127 }
130 - $datasets[] = array(
131 - 'key' => $dataset->ID,
132 - 'value' => $dataset_title
133 - );
128 + } else {
129 + $wpml = $this->helper->load('translator')->isWPML();
130 + if ($wpml) {
131 + $lang = apply_filters('wpml_current_language', null);
132 + $entries = get_posts(
133 + [
134 + 'post_type' => $item_id,
135 + 'numberposts' => -1,
136 + 'post_status' => 'any',
137 + 'lang' => $lang,
138 + 'suppress_filters' => false,
139 + ]
140 + );
141 + } else {
142 + $entries = get_posts(
143 + [
144 + 'post_type' => $item_id,
145 + 'numberposts' => -1,
146 + 'post_status' => 'any',
147 + ]
148 + );
149 + }
150 + if ($entries) {
151 + $this->set('item', $item_id);
152 + foreach ($entries as $key => $entry) {
153 + $this->set('dataset', $entry->ID);
154 + $entry_title = $this->render($name);
155 + if (!$entry_title) {
156 + $entry_title = isset($entry->post_title) && $entry->post_title ? $entry->post_title : $entry->ID;
157 + }
158 + $datasets[] = [
159 + 'key' => $entry->ID,
160 + 'value' => $entry_title,
161 + ];
162 + }
163 + }
134 164 }
135 165 }
136 -
137 166 return $datasets;
138 167 }
139 168
140 - /**
141 - * Get dataset
142 - *
143 - * @param int $dataset - Dataset ID
144 - *
145 - * @return object - Dataset
146 - */
147 - public function get_dataset($dataset = false) {
169 + // get dataset actions
170 + public function get_dataset_actions($dataset_id = false) {
171 + $dataset_id = (int) $dataset_id;
172 + if (!$dataset_id) {
173 + return false;
174 + }
175 + $actions = new stdClass();
176 + if ($this->get('item') == '-3') {
177 + $actions->view = $this->helper->get_url(
178 + [
179 + 'user_id' => $dataset_id,
180 + ], 'user-edit.php?'
181 + );
182 + } else {
183 + $actions->view = $this->helper->get_url(
184 + [
185 + 'post' => $dataset_id,
186 + 'action' => 'edit',
187 + ], 'post.php?'
188 + );
189 + }
190 + $actions->delete = false;
191 + return $actions;
192 + }
148 193
149 - $dataset = (int) $dataset;
150 -
151 - if (!$dataset) {
194 + // get template actions
195 + public function get_template_actions($template = false) {
196 + $template = (int) $template;
197 + if (!$template) {
152 198 return;
153 199 }
154 -
155 - $data = new stdClass();
156 - $data->url = $this->helper->get_url(array('post' => $dataset, 'action' => 'edit'), 'post.php?');
157 -
158 - return $data;
200 + $actions = new stdClass();
201 + $actions->delete = false;
202 + return $actions;
159 203 }
160 204
161 - /**
162 - * Get item
163 - *
164 - * @param string $item - Item
165 - *
166 - * @return object - Item
167 - */
168 - public function get_item($item = false) {
169 -
170 - $form = new stdClass();
171 - if ($item == 'post') {
172 - $form->name = __('Wordpress Posts', 'e2pdf');
173 - $form->url = $this->helper->get_url(array('post_type' => $item), 'edit.php?');
174 - } elseif ($item == 'page') {
175 - $form->name = __('Wordpress Pages', 'e2pdf');
176 - $form->url = $this->helper->get_url(array('post_type' => $item), 'edit.php?');
205 + // item
206 + public function item($item_id = false) {
207 + if (!$item_id && $this->get('item')) {
208 + $item_id = $this->get('item');
209 + }
210 + $item = new stdClass();
211 + if ($item_id == '-3') {
212 + $item->id = $item_id;
213 + $item->name = __('Users');
214 + $item->url = $this->helper->get_url([], 'users.php');
177 215 } else {
178 - $form->name = '';
179 - $form->url = 'javascript:void(0);';
216 + $form = get_post_type_object($item_id);
217 + if ($form) {
218 + $item->id = $item_id;
219 + $item->name = $form->label ? $form->label : $item_id;
220 + $item->url = $this->helper->get_url(['post_type' => $item_id], 'edit.php?');
221 + } else {
222 + $item->id = '';
223 + $item->name = '';
224 + $item->url = '';
225 + }
180 226 }
181 -
182 - return $form;
227 + return $item;
183 228 }
184 229
230 + // load filters
185 231 public function load_filters() {
186 - add_filter('the_content', array($this, 'filter_content'), 10, 2);
187 - }
232 + add_filter('the_content', [$this, 'filter_the_content'], 10, 2);
233 + add_filter('widget_text', [$this, 'filter_content_custom']);
234 + add_filter('widget_block_content', [$this, 'filter_content_custom']);
188 235
189 - /**
190 - * Render value according to content
191 - *
192 - * @param string $value - Content
193 - * @param string $type - Type of rendering value
194 - * @param string $field - Field type for rendering
195 - * @param string $info - Additional value to render
196 - *
197 - * @return string - Fully rendered value
198 - */
199 - public function render($value, $type = false, $field = false, $info = false) {
236 + /**
237 + * Popup Maker – Popup for opt-ins, lead gen, & more
238 + * https://wordpress.org/plugins/popup-maker/
239 + */
240 + add_filter('pum_popup_content', [$this, 'filter_the_content'], 10, 2);
200 241
201 - $value = $this->render_shortcodes($value, $type, $field);
202 - $value = $this->strip_shortcodes($value);
242 + /**
243 + * Events Manager
244 + * https://wordpress.org/plugins/events-manager/
245 + */
246 + add_filter('em_event_output_placeholder', [$this, 'filter_content_custom'], 0);
247 + add_filter('em_event_output', [$this, 'filter_content_custom']);
248 + add_filter('em_booking_output_placeholder', [$this, 'filter_content_custom'], 0);
249 + add_filter('em_booking_output', [$this, 'filter_content_custom']);
250 + add_filter('em_location_output_placeholder', [$this, 'filter_content_custom'], 0);
251 + add_filter('em_location_output', [$this, 'filter_content_custom']);
252 + add_filter('em_category_output_placeholder', [$this, 'filter_content_custom'], 0);
203 253
204 - if ($type === 'value' && $field === 'e2pdf-checkbox') {
205 - $option = $this->render($info);
206 - $options = explode(', ', $value);
207 - if (is_array($options) && in_array($option, $options)) {
208 - return $option;
209 - } else {
210 - return "";
211 - }
212 - }
213 - return $value;
214 - }
254 + /**
255 + * Beaver Builder – WordPress Page Builder
256 + * https://wordpress.org/plugins/beaver-builder-lite-version/
257 + */
258 + add_filter('fl_builder_before_render_shortcodes', [$this, 'filter_content_loop']);
215 259
216 - /**
217 - * Render shortcodes which available in this extension
218 - *
219 - * @param string $value - Content
220 - *
221 - * @return string - Value with rendered shortcodes
222 - */
223 - public function render_shortcodes($value, $type = false, $field = false) {
260 + /**
261 + * WPBakery Page Builder Image Object Link
262 + */
263 + add_filter('vc_map_get_attributes', [$this, 'filter_vc_map_get_attributes'], 10, 2);
224 264
225 - $dataset_id = $this->get('dataset');
226 - $item_id = $this->get('item');
227 - $post = get_post($dataset_id);
265 + /**
266 + * Flatsome theme global tab content
267 + */
268 + add_filter('theme_mod_tab_content', [$this, 'filter_content_custom']);
228 269
229 - $ext_shortcodes = array(
230 - "[id]" => $post->ID,
231 - "[post_author]" => get_userdata($post->post_author)->user_nicename,
232 - "[post_date]" => $post->post_date,
233 - "[post_date_gmt]" => $post->post_date_gmt,
234 - "[post_content]" => $post->post_content,
235 - "[post_title]" => $post->post_title,
236 - "[post_excerpt]" => $post->post_excerpt,
237 - "[post_status]" => $post->post_status,
238 - "[comment_status]" => $post->comment_status,
239 - "[ping_status]" => $post->ping_status,
240 - "[post_password]" => $post->post_password,
241 - "[post_name]" => $post->post_name,
242 - "[to_ping]" => $post->to_ping,
243 - "[pinged]" => $post->pinged,
244 - "[post_modified]" => $post->post_modified,
245 - "[post_modified_gmt]" => $post->post_modified_gmt,
246 - "[post_content_filtered]" => $post->post_content_filtered,
247 - "[post_parent]" => $post->post_parent,
248 - "[guid]" => $post->guid,
249 - "[menu_order]" => $post->menu_order,
250 - "[post_type]" => $post->post_type,
251 - "[post_mime_type]" => $post->post_mime_type,
252 - "[comment_count]" => $post->comment_count,
253 - "[filter]" => $post->filter
254 - );
270 + /**
271 + * MemberPress Mail attachments
272 + * https://memberpress.com/
273 + */
274 + add_filter('mepr_email_send_attachments', [$this, 'filter_mepr_email_send_attachments'], 10, 4);
275 + add_filter('the_content', [$this, 'filter_mepr_the_content'], 99);
276 + add_filter('mepr_custom_thankyou_message', [$this, 'filter_mepr_custom_thankyou_message']);
255 277
278 + /**
279 + * Thrive Theme Builder dynamic shortcode support
280 + */
281 + add_filter('thrive_theme_template_content', [$this, 'filter_thrive_theme_template_content']);
256 282
257 - $post_content = false;
283 + /**
284 + * WPBakery Page Builder Grid Item
285 + * [e2pdf-download id="1" dataset="{{ post_data:ID }}"]
286 + */
287 + add_filter('vc_basic_grid_items_list', [$this, 'filter_vc_basic_grid_items_list']);
258 288
259 - if (false !== strpos($value, '[')) {
289 + /**
290 + * Themify Builder dynamic shortcode support
291 + * https://wordpress.org/plugins/themify-builder/
292 + */
293 + add_filter('themify_builder_module_content', [$this, 'filter_themify_builder_module_content']);
260 294
261 - $shortcode_tags = array(
262 - 'meta',
263 - );
264 - preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches);
265 - $tagnames = array_intersect($shortcode_tags, $matches[1]);
295 + /**
296 + * Impreza theme by Up Solutions
297 + * https://themeforest.net/item/impreza-retina-responsive-wordpress-theme/6434280
298 + */
299 + add_filter('us_content_template_the_content', [$this, 'filter_content_custom']);
266 300
267 - if (!empty($tagnames)) {
268 - $pattern = get_shortcode_regex($tagnames);
301 + /**
302 + * Cornerstone Builder
303 + * https://theme.co/cornerstone/
304 + */
305 + add_filter('cs_element_pre_render', [$this, 'filter_cs_element_pre_render']);
269 306
270 - preg_match_all("/$pattern/", $value, $shortcodes);
307 + /**
308 + * Divi Theme Builder
309 + * https://www.elegantthemes.com/
310 + */
311 + add_filter('et_pb_module_content', [$this, 'filter_et_pb_module_content'], 30, 6);
271 312
272 - foreach ($shortcodes[0] as $key => $shortcode_value) {
273 - $shortcode = array();
274 - $shortcode[1] = $shortcodes[1][$key];
275 - $shortcode[2] = $shortcodes[2][$key];
276 - $shortcode[3] = $shortcodes[3][$key];
277 - $shortcode[4] = $shortcodes[4][$key];
278 - $shortcode[5] = $shortcodes[5][$key];
279 - $shortcode[6] = $shortcodes[6][$key];
313 + /**
314 + * User Registration & Membership – Custom Registration Form, Login Form, and User Profile
315 + * https://wordpress.org/plugins/user-registration/
316 + */
317 + add_filter('user_registration_smart_tag_values', [$this, 'filter_user_registration_smart_tag_values'], 0);
280 318
281 - $atts = shortcode_parse_atts($shortcode[3]);
319 + /**
320 + * Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin
321 + * https://wordpress.org/plugins/ultimate-member/
322 + */
323 + add_filter('um_email_send_message_content', [$this, 'filter_um_email_send_message_content']);
282 324
283 - if (array_key_exists('key', $atts)) {
284 - $value = str_replace($shortcode_value, get_post_meta($post->ID, $atts['key'], true), $value);
285 - }
286 - }
287 - }
325 + /**
326 + * Shortcodes do not render when the Toolset template is used
327 + * https://toolset.com/
328 + */
329 + add_filter('wpv_filter_content_template_output', [$this, 'filter_wpv_filter_content_template_output']);
288 330
289 - $shortcode_tags = array(
290 - 'e2pdf-format-number',
291 - 'e2pdf-format-date',
292 - 'e2pdf-format-output',
293 - );
294 - preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches);
295 - $tagnames = array_intersect($shortcode_tags, $matches[1]);
331 + /* Hooks */
332 + add_filter('post_row_actions', [$this, 'hook_wordpress_row_actions'], 10, 2);
333 + add_filter('page_row_actions', [$this, 'hook_wordpress_row_actions'], 10, 2);
334 + add_filter('user_row_actions', [$this, 'hook_wordpress_row_actions'], 10, 2);
296 335
297 - if (!empty($tagnames)) {
336 + // extension hooks
337 + add_filter('e2pdf_extension_hooks', function ($hooks) {
338 + $hooks[$this->info['key'] . '_-3'] = [
339 + 'hook_wordpress_row_actions' => __('WP Admin User Row Actions', 'e2pdf')
340 + ];
341 + $hooks[$this->info['key']] = [
342 + 'hook_wordpress_page_edit' => __('WP Admin Page Edit', 'e2pdf'),
343 + 'hook_wordpress_row_actions' => __('WP Admin Page Row Actions', 'e2pdf')
344 + ];
345 + return $hooks;
346 + });
347 + }
298 348
299 - $pattern = get_shortcode_regex($tagnames);
300 - preg_match_all("/$pattern/", $value, $shortcodes);
301 - foreach ($shortcodes[0] as $key => $shortcode_value) {
302 - $shortcode = array();
303 - $shortcode[1] = $shortcodes[1][$key];
304 - $shortcode[2] = $shortcodes[2][$key];
305 - $shortcode[3] = $shortcodes[3][$key];
306 - $shortcode[4] = $shortcodes[4][$key];
307 - $shortcode[5] = $shortcodes[5][$key];
308 - $shortcode[6] = $shortcodes[6][$key];
349 + // load actions
350 + public function load_actions() {
351 + /**
352 + * Elementor Website Builder – More than Just a Page Builder
353 + * https://wordpress.org/plugins/elementor/
354 + */
355 + add_action('elementor/widget/before_render_content', [$this, 'action_elementor_widget_before_render_content']);
356 + add_action('elementor/frontend/widget/before_render', [$this, 'action_elementor_widget_before_render_content'], 5);
309 357
310 - if (isset($shortcode['5'])) {
358 + /**
359 + * JetEngine: WordPress Plugin for Elementor
360 + * https://crocoblock.com
361 + */
362 + add_action('jet-engine/listing/grid/before-render', [$this, 'action_jet_engine_listing_grid_before_render']);
363 + add_action('jet-engine/listing/grid/after-render', [$this, 'action_jet_engine_listing_grid_after_render']);
311 364
312 - if (strpos($shortcode['5'], "[post_content]") !== FALSE && !$this->get('no_filter') && !$post_content) {
313 - $ext_shortcodes['[post_content]'] = $this->before_render_post_content($ext_shortcodes['[post_content]']);
314 - $ext_shortcodes['[post_content]'] = apply_filters('the_content', $ext_shortcodes['[post_content]']);
315 - $ext_shortcodes['[post_content]'] = str_replace("</p>", "</p>&nbsp;\r\n", $ext_shortcodes['[post_content]']);
316 - $post_content = true;
317 - }
365 + /**
366 + * Happy Addons for Elementor
367 + * https://wordpress.org/plugins/happy-elementor-addons/ compatibility fix
368 + */
369 + add_action('elementor/frontend/before_render', [$this, 'action_elementor_widget_before_render_content'], 0);
318 370
319 - $sub_value = str_replace(array_keys($ext_shortcodes), $ext_shortcodes, $shortcode['5']);
320 - $value = str_replace($shortcode_value, "[" . $shortcode['2'] . $shortcode['3'] . "]" . $sub_value . "[/" . $shortcode['2'] . "]", $value);
321 - }
322 - }
323 - }
324 - }
371 + /**
372 + * MemberPress Mail attachments remove
373 + * https://memberpress.com/
374 + */
375 + add_action('mepr_email_sent', [$this, 'action_mepr_email_sent']);
325 376
326 - $value = do_shortcode($value);
377 + /**
378 + * User Registration & Membership – Custom Registration Form, Login Form, and User Profile
379 + * https://wordpress.org/plugins/user-registration/
380 + */
381 + add_action('user_registration_email_send_before', [$this, 'action_user_registration_email_send_before']);
382 + add_action('user_registration_email_send_after', [$this, 'action_user_registration_email_send_after']);
327 383
328 - if (strpos($value, "[post_content]") !== FALSE && !$this->get('no_filter') && !$post_content) {
329 - $ext_shortcodes['[post_content]'] = $this->before_render_post_content($ext_shortcodes['[post_content]']);
330 - $ext_shortcodes['[post_content]'] = apply_filters('the_content', $ext_shortcodes['[post_content]']);
331 - $ext_shortcodes['[post_content]'] = str_replace("</p>", "</p>&nbsp;\r\n", $ext_shortcodes['[post_content]']);
332 - $post_content = true;
333 - }
384 + /**
385 + * Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin
386 + * https://wordpress.org/plugins/ultimate-member/
387 + */
388 + add_action('um_before_email_notification_sending', [$this, 'action_um_before_email_notification_sending']);
389 + add_action('um_after_email_notification_sending', [$this, 'action_um_after_email_notification_sending']);
334 390
335 - $value = str_replace(array_keys($ext_shortcodes), $ext_shortcodes, $value);
391 + /* Hooks */
392 + add_action('add_meta_boxes', [$this, 'hook_wordpress_page_edit']);
393 + }
336 394
395 + // render
396 + public function render($value, $field = [], $convert_shortcodes = true, $raw = false) {
397 + $value = $this->render_shortcodes($value, $field);
398 + if (!$raw) {
399 + $value = $this->strip_shortcodes($value);
400 + $value = $this->convert_shortcodes($value, $convert_shortcodes, isset($field['type']) && $field['type'] == 'e2pdf-html' ? true : false);
401 + $value = $this->helper->load('field')->render_checkbox($value, $this, $field);
402 + }
337 403 return $value;
338 404 }
339 405
340 - public function filter_custom_shortcodes() {
341 -
342 - }
406 + // render shortcodes
407 + public function render_shortcodes($value, $field = []) {
343 408
344 - /**
345 - * Strip unused shortcodes
346 - *
347 - * @param string $value - Content
348 - *
349 - * @return string - Value with removed unused shortcodes
350 - */
351 - public function strip_shortcodes($value) {
352 - $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', "", $value);
353 - return $value;
354 - }
409 + $element_id = isset($field['element_id']) ? $field['element_id'] : false;
355 410
356 - public function auto() {
357 - $response = array();
358 - $elements = array();
411 + if ($this->verify()) {
412 + /**
413 + * Set current Post for Toolset Views
414 + * https://toolset.com/
415 + */
416 + do_action('wpv_action_wpv_set_top_current_post', $this->get('cached_post'));
359 417
418 + $wordpress_shortcodes = [
419 + 'id',
420 + 'post_author',
421 + 'post_date',
422 + 'post_date_gmt',
423 + 'post_content',
424 + 'post_title',
425 + 'post_excerpt',
426 + 'post_status',
427 + 'comment_status',
428 + 'ping_status',
429 + 'post_password',
430 + 'post_name',
431 + 'to_ping',
432 + 'pinged',
433 + 'post_modified',
434 + 'post_modified_gmt',
435 + 'post_content_filtered',
436 + 'post_parent',
437 + 'guid',
438 + 'menu_order',
439 + 'post_type',
440 + 'post_mime_type',
441 + 'comment_count',
442 + 'filter',
443 + 'post_thumbnail',
444 + 'get_the_post_thumbnail',
445 + 'get_the_post_thumbnail_url',
446 + 'get_permalink',
447 + 'get_post_permalink',
448 + ];
360 449
361 - $post = $this->get('item');
450 + if (false !== strpos($value, '[')) {
451 + $value = $this->helper->load('field')->pre_shortcodes($value, $this, $field);
452 + $value = $this->helper->load('field')->inner_shortcodes($value, $this, $field);
453 + if ($this->get('item') == '-3') {
454 + $shortcode_tags = [
455 + 'acf',
456 + ];
457 + } else {
458 + $shortcode_tags = [
459 + 'meta',
460 + 'terms',
461 + 'e2pdf-wp',
462 + 'e2pdf-wp-term',
463 + 'e2pdf-content',
464 + 'acf',
465 + ];
466 + $shortcode_tags = array_merge($shortcode_tags, $wordpress_shortcodes);
467 + }
468 + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches);
469 + $tagnames = array_intersect($shortcode_tags, $matches[1]);
470 + if (!empty($tagnames)) {
471 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $value, $shortcodes);
472 + foreach ($shortcodes[0] as $key => $shortcode_value) {
473 + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
474 + $atts = shortcode_parse_atts($shortcode[3]);
475 + if ($shortcode[2] === 'e2pdf-content') {
476 + if (!isset($atts['id']) && isset($this->get('cached_post')->ID) && $this->get('cached_post')->ID) {
477 + $shortcode[3] .= ' id=' . $this->get('cached_post')->ID . '';
478 + $value = str_replace($shortcode_value, '[' . $shortcode[2] . $shortcode[3] . ']', $value);
479 + }
480 + } elseif ($shortcode[2] === 'meta' || $shortcode[2] === 'terms' || $shortcode[2] == 'e2pdf-wp') {
481 + if (!isset($atts['id']) && isset($this->get('cached_post')->ID) && $this->get('cached_post')->ID) {
482 + $shortcode[3] .= ' id=' . $this->get('cached_post')->ID . '';
483 + }
484 + if ($shortcode[2] === 'meta') {
485 + $shortcode[3] .= ' meta=true';
486 + }
487 + if ($shortcode[2] === 'terms') {
488 + $shortcode[3] .= ' terms=true';
489 + }
490 + if (substr($shortcode_value, -11) === '[/e2pdf-wp]' || substr($shortcode_value, -8) === '[/terms]' || substr($shortcode_value, -7) === '[/meta]') {
491 + if ($shortcode[5]) {
492 + $shortcode[5] = $this->render($shortcode[5], [], false);
493 + }
494 + $value = str_replace($shortcode_value, '[e2pdf-wp' . $shortcode[3] . ']' . $shortcode[5] . '[/e2pdf-wp]', $value);
495 + } else {
496 + $value = str_replace($shortcode_value, '[e2pdf-wp' . $shortcode[3] . ']', $value);
497 + }
498 + } elseif ($shortcode[2] === 'e2pdf-wp-term') {
499 + if (substr($shortcode_value, -16) === '[/e2pdf-wp-term]') {
500 + if ($shortcode[5]) {
501 + $shortcode[5] = $this->render($shortcode[5], [], false);
502 + }
503 + $value = str_replace($shortcode_value, '[e2pdf-wp-term' . $shortcode[3] . ']' . $shortcode[5] . '[/e2pdf-wp-term]', $value);
504 + }
505 + } elseif (in_array($shortcode[2], $wordpress_shortcodes, false)) {
506 + if (!isset($atts['id']) && isset($this->get('cached_post')->ID) && $this->get('cached_post')->ID) {
507 + $shortcode[3] .= ' id=' . $this->get('cached_post')->ID . '';
508 + }
509 + $shortcode[3] .= ' key=' . $shortcode[2] . '';
510 + $value = str_replace($shortcode_value, '[e2pdf-wp' . $shortcode[3] . ']', $value);
511 + } elseif ($shortcode[2] === 'acf') {
512 + if (!isset($atts['post_id']) && isset($this->get('cached_post')->ID) && $this->get('cached_post')->ID) {
513 + if ($this->get('item') == '-3') {
514 + $shortcode[3] .= ' post_id=user_' . $this->get('cached_post')->ID . '';
515 + } else {
516 + $shortcode[3] .= ' post_id=' . $this->get('cached_post')->ID . '';
517 + }
518 + $value = str_replace($shortcode_value, '[' . $shortcode[2] . $shortcode[3] . ']', $value);
519 + }
520 + }
521 + }
522 + }
523 + $value = $this->helper->load('field')->wrapper_shortcodes($value, $this, $field);
524 + }
362 525
363 - $elements[] = array(
364 - 'type' => 'e2pdf-html',
365 - 'top' => '20',
366 - 'left' => '20',
367 - 'right' => '20',
368 - 'block' => true,
369 - 'properties' => array(
370 - 'value' => "<h1>[post_title]</h1>",
371 - )
526 + add_filter('frm_filter_view', [$this, 'filter_frm_filter_view']);
527 + $value = $this->helper->load('field')->do_shortcodes($value, $this, $field);
528 + $value = $this->helper->load('field')->render(
529 + apply_filters('e2pdf_extension_render_shortcodes_pre_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false),
530 + $this,
531 + $field
532 + );
533 + remove_filter('frm_filter_view', [$this, 'filter_frm_filter_view']);
534 + }
535 + return apply_filters(
536 + 'e2pdf_extension_render_shortcodes_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false
372 537 );
538 + }
373 539
540 + // strip shortcodes
541 + public function strip_shortcodes($value) {
542 + $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', '', $value);
543 + return $value;
544 + }
374 545
375 - $elements[] = array(
376 - 'type' => 'e2pdf-html',
377 - 'top' => '20',
378 - 'left' => '20',
379 - 'right' => '20',
380 - 'block' => true,
381 - 'properties' => array(
382 - 'value' => __("Post name", 'e2pdf') . ": [post_name]",
383 - )
384 - );
546 + // convert shortcodes
547 + public function convert_shortcodes($value, $to = false, $html = false) {
548 + if ($value) {
549 + if ($to) {
550 + $value = str_replace('&#91;', '[', $value);
551 + if (!$html) {
552 + $value = wp_specialchars_decode($value, ENT_QUOTES);
553 + }
554 + } else {
555 + $value = str_replace('[', '&#91;', $value);
556 + }
557 + }
558 + return $value;
559 + }
385 560
386 - $elements[] = array(
387 - 'type' => 'e2pdf-html',
388 - 'top' => '20',
389 - 'left' => '20',
390 - 'right' => '20',
391 - 'block' => true,
392 - 'properties' => array(
393 - 'value' => __("Post type", 'e2pdf') . ": [post_type]",
394 - )
395 - );
561 + // auto
562 + public function auto() {
396 563
564 + $response = [];
565 + $elements = [];
397 566
398 - $elements[] = array(
399 - 'type' => 'e2pdf-html',
567 + if ($this->get('item') == '-3') {
568 + $elements[] = [
569 + 'type' => 'e2pdf-html',
570 + 'block' => true,
571 + 'properties' => [
572 + 'top' => '20',
573 + 'left' => '20',
574 + 'right' => '20',
575 + 'width' => '100%',
576 + 'height' => 'auto',
577 + 'value' => '<h1>[e2pdf-user key="user_login"]</h1>',
578 + ],
579 + ];
580 + $elements[] = [
581 + 'type' => 'e2pdf-image',
582 + 'block' => true,
583 + 'properties' => [
584 + 'top' => '20',
585 + 'left' => '20',
586 + 'right' => '20',
587 + 'width' => '100%',
588 + 'height' => '100',
589 + 'vertical' => 'top',
590 + 'value' => '[e2pdf-user key="get_avatar_url"]',
591 + ],
592 + ];
593 + $elements[] = [
594 + 'type' => 'e2pdf-html',
595 + 'block' => true,
596 + 'properties' => [
597 + 'top' => '20',
598 + 'left' => '20',
599 + 'right' => '20',
600 + 'width' => '100%',
601 + 'height' => 'auto',
602 + 'value' => 'ID: [e2pdf-user key="ID"]',
603 + ],
604 + ];
605 + $elements[] = [
606 + 'type' => 'e2pdf-html',
607 + 'block' => true,
608 + 'properties' => [
609 + 'top' => '20',
610 + 'left' => '20',
611 + 'right' => '20',
612 + 'width' => '100%',
613 + 'height' => 'auto',
614 + 'value' => 'First Name: [e2pdf-user key="user_firstname"]',
615 + ],
616 + ];
617 + $elements[] = [
618 + 'type' => 'e2pdf-html',
619 + 'block' => true,
620 + 'properties' => [
621 + 'top' => '20',
622 + 'left' => '20',
623 + 'right' => '20',
624 + 'width' => '100%',
625 + 'height' => 'auto',
626 + 'value' => 'Last Name: [e2pdf-user key="user_lastname"]',
627 + ],
628 + ];
629 + $elements[] = [
630 + 'type' => 'e2pdf-html',
631 + 'block' => true,
632 + 'properties' => [
633 + 'top' => '20',
634 + 'left' => '20',
635 + 'right' => '20',
636 + 'width' => '100%',
637 + 'height' => 'auto',
638 + 'value' => 'Email: [e2pdf-user key="user_email"]',
639 + ],
640 + ];
641 + $elements[] = [
642 + 'type' => 'e2pdf-html',
643 + 'block' => true,
644 + 'properties' => [
645 + 'top' => '20',
646 + 'left' => '20',
647 + 'right' => '20',
648 + 'width' => '100%',
649 + 'height' => 'auto',
650 + 'value' => 'Registered: [e2pdf-user key="user_registered"]',
651 + ],
652 + ];
653 + } else {
654 + $elements[] = [
655 + 'type' => 'e2pdf-html',
656 + 'block' => true,
657 + 'properties' => [
658 + 'top' => '20',
659 + 'left' => '20',
660 + 'right' => '20',
661 + 'width' => '100%',
662 + 'height' => 'auto',
663 + 'value' => '<h1>[e2pdf-wp key="post_title"]</h1>',
664 + ],
665 + ];
666 + $elements[] = [
667 + 'type' => 'e2pdf-html',
668 + 'block' => true,
669 + 'properties' => [
670 + 'top' => '20',
671 + 'left' => '20',
672 + 'right' => '20',
673 + 'width' => '100%',
674 + 'height' => 'auto',
675 + 'value' => 'Post name: [e2pdf-wp key="post_name"]',
676 + ],
677 + ];
678 + $elements[] = [
679 + 'type' => 'e2pdf-html',
680 + 'block' => true,
681 + 'properties' => [
682 + 'top' => '20',
683 + 'left' => '20',
684 + 'right' => '20',
685 + 'width' => '100%',
686 + 'height' => 'auto',
687 + 'value' => 'Post type: [e2pdf-wp key="post_type"]',
688 + ],
689 + ];
690 + $elements[] = [
691 + 'type' => 'e2pdf-html',
692 + 'block' => true,
693 + 'properties' => [
694 + 'top' => '20',
695 + 'left' => '20',
696 + 'right' => '20',
697 + 'width' => '100%',
698 + 'height' => 'auto',
699 + 'value' => 'ID: [e2pdf-wp key="id"]',
700 + ],
701 + ];
702 + $elements[] = [
703 + 'type' => 'e2pdf-html',
704 + 'block' => true,
705 + 'properties' => [
706 + 'top' => '20',
707 + 'left' => '20',
708 + 'right' => '20',
709 + 'width' => '100%',
710 + 'height' => 'auto',
711 + 'value' => 'Author: [e2pdf-wp key="post_author"]',
712 + ],
713 + ];
714 + $elements[] = [
715 + 'type' => 'e2pdf-html',
716 + 'block' => true,
717 + 'properties' => [
718 + 'top' => '20',
719 + 'left' => '20',
720 + 'right' => '20',
721 + 'width' => '100%',
722 + 'height' => '300',
723 + 'value' => '[e2pdf-wp key="post_content"]',
724 + ],
725 + ];
726 + $elements[] = [
727 + 'type' => 'e2pdf-html',
728 + 'block' => true,
729 + 'properties' => [
730 + 'top' => '20',
731 + 'left' => '20',
732 + 'right' => '20',
733 + 'width' => '100%',
734 + 'height' => 'auto',
735 + 'value' => 'Created: [e2pdf-wp key="post_date"]',
736 + ],
737 + ];
738 + $elements[] = [
739 + 'type' => 'e2pdf-html',
740 + 'block' => true,
741 + 'properties' => [
742 + 'top' => '20',
743 + 'left' => '20',
744 + 'right' => '20',
745 + 'width' => '100%',
746 + 'height' => 'auto',
747 + 'value' => 'Modified: [e2pdf-wp key="post_modified"]',
748 + ],
749 + ];
750 + }
751 + $response['page'] = [
752 + 'bottom' => '20',
400 753 'top' => '20',
401 754 'left' => '20',
402 755 'right' => '20',
403 - 'block' => true,
404 - 'properties' => array(
405 - 'value' => __("ID", 'e2pdf') . ": [id]",
406 - )
407 - );
756 + ];
408 757
409 - $elements[] = array(
410 - 'type' => 'e2pdf-html',
411 - 'top' => '20',
412 - 'left' => '20',
413 - 'right' => '20',
414 - 'block' => true,
415 - 'properties' => array(
416 - 'value' => __("Author", 'e2pdf') . ": [post_author]",
417 - )
418 - );
758 + $response['elements'] = $elements;
759 + return $response;
760 + }
419 761
762 + // before render content widget action
763 + public function action_elementor_widget_before_render_content($widget) {
764 + if ($widget && ($widget->get_name() == 'shortcode' || $widget->get_name() == 'text-editor')) {
765 + $content = $widget->get_name() == 'shortcode' ? $widget->get_settings('shortcode') : $widget->get_settings('editor');
766 + if ($content && false !== strpos($content, '[e2pdf-')) {
767 + $wp_reset_postdata = true;
768 + if (class_exists('\ElementorPro\Plugin') && class_exists('\ElementorPro\Modules\LoopBuilder\Documents\Loop')) {
769 + $document = \ElementorPro\Plugin::elementor()->documents->get_current();
770 + if ($document && $document instanceof \ElementorPro\Modules\LoopBuilder\Documents\Loop) {
771 + $wp_reset_postdata = false;
772 + }
773 + }
774 + if ($widget->get_name() == 'shortcode') {
775 + $widget->set_settings('shortcode', $this->filter_content($content, false, $wp_reset_postdata));
776 + } elseif ($widget->get_name() == 'text-editor' && !$wp_reset_postdata) {
777 + $widget->set_settings('editor', $this->filter_content($content, false, $wp_reset_postdata));
778 + }
779 + }
780 + }
781 + }
420 782
783 + // jet engine listing grid before render action
784 + public function action_jet_engine_listing_grid_before_render($listing_grid) {
785 + $this->set('queried_object', true);
786 + }
421 787
422 - $elements[] = array(
423 - 'type' => 'e2pdf-html',
424 - 'top' => '20',
425 - 'left' => '20',
426 - 'right' => '20',
427 - 'block' => true,
428 - 'properties' => array(
429 - 'value' => "[post_content]",
430 - 'dynamic_height' => '1',
431 - 'height' => '300',
432 - )
433 - );
788 + // jet engine listing grid after render action
789 + public function action_jet_engine_listing_grid_after_render($listing_grid) {
790 + $this->set('queried_object', false);
791 + }
434 792
793 + /**
794 + * Delete attachments that were sent by MemberPress email
795 + * https://memberpress.com/
796 + */
797 + public function action_mepr_email_sent() {
798 + $files = $this->helper->get('wordpress_attachments_mepr');
799 + if (is_array($files) && !empty($files)) {
800 + foreach ($files as $key => $file) {
801 + $this->helper->delete_dir(dirname($file) . '/');
802 + }
803 + $this->helper->deset('wordpress_attachments_mepr');
804 + }
805 + }
435 806
436 - $elements[] = array(
437 - 'type' => 'e2pdf-html',
438 - 'top' => '20',
439 - 'left' => '20',
440 - 'right' => '20',
441 - 'block' => true,
442 - 'properties' => array(
443 - 'value' => __("Created", 'e2pdf') . ": [post_date]",
444 - )
445 - );
807 + // registration email send before action
808 + public function action_user_registration_email_send_before() {
809 + add_filter('wp_mail', [$this, 'filter_wp_mail'], 11);
810 + }
446 811
447 - $elements[] = array(
448 - 'type' => 'e2pdf-html',
449 - 'top' => '20',
450 - 'left' => '20',
451 - 'right' => '20',
452 - 'block' => true,
453 - 'properties' => array(
454 - 'value' => __("Modified", 'e2pdf') . ": [post_modified]",
455 - )
456 - );
812 + // registration email send after action
813 + public function action_user_registration_email_send_after() {
814 + remove_filter('wp_mail', [$this, 'filter_wp_mail'], 11);
815 + $files = $this->helper->get('wordpress_attachments');
816 + if (is_array($files) && !empty($files)) {
817 + foreach ($files as $key => $file) {
818 + $this->helper->delete_dir(dirname($file) . '/');
819 + }
820 + $this->helper->deset('wordpress_attachments');
821 + }
822 + }
457 823
824 + /**
825 + * Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin
826 + * https://wordpress.org/plugins/ultimate-member/
827 + */
828 + public function action_um_before_email_notification_sending() {
829 + add_filter('wp_mail', [$this, 'filter_wp_mail_um'], 11);
830 + }
458 831
459 - $response['page'] = array(
460 - 'bottom' => '20',
461 - 'top' => '20',
462 - );
832 + /**
833 + * Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin
834 + * https://wordpress.org/plugins/ultimate-member/
835 + */
836 + public function action_um_after_email_notification_sending() {
837 + remove_filter('wp_mail', [$this, 'filter_wp_mail_um'], 11);
838 + $files = $this->helper->get('wordpress_attachments_um_del');
839 + if (is_array($files) && !empty($files)) {
840 + foreach ($files as $key => $file) {
841 + $this->helper->delete_dir(dirname($file) . '/');
842 + }
843 + $this->helper->deset('wordpress_attachments_um');
844 + $this->helper->deset('wordpress_attachments_um_del');
845 + }
846 + }
463 847
848 + /**
849 + * Enable / Disable pre-rendering of E2Pdf shortcodes in the Toolset template.
850 + * https://toolset.com/
851 + */
852 + public function filter_wpv_filter_content_template_output($content) {
853 + add_filter('render_block', [$this, 'filter_render_block_toolset_disable'], 9, 2);
854 + add_filter('render_block', [$this, 'filter_render_block_toolset_enable'], 11, 2);
855 + return $content;
856 + }
464 857
465 -
466 - $response['elements'] = $elements;
467 - return $response;
858 + /**
859 + * Disable pre-rendering of E2Pdf shortcodes in the Toolset template.
860 + * https://toolset.com/
861 + */
862 + public function filter_render_block_toolset_disable($block_content, $block) {
863 + if (
864 + !empty($block['blockName']) && strpos($block['blockName'], 'toolset-blocks/') === 0 && false !== strpos($block_content, '[e2pdf-')
865 + ) {
866 + remove_shortcode('e2pdf-download');
867 + remove_shortcode('e2pdf-view');
868 + remove_shortcode('e2pdf-save');
869 + remove_shortcode('e2pdf-zapier');
870 + remove_shortcode('e2pdf-adobesign');
871 + }
872 + return $block_content;
468 873 }
469 874
470 875 /**
471 - * Action before wordpress post/page render
472 - * Force to apply e2pdf shortcodes
473 - *
474 - * @param string $content - Content
475 - *
476 - * @return string - Content with update shortcodes
876 + * Enable rendering of E2Pdf shortcodes in the Toolset template.
877 + * https://toolset.com/
477 878 */
478 - public function before_render_post_content($content) {
879 + public function filter_render_block_toolset_enable($block_content, $block) {
880 + if (
881 + !empty($block['blockName']) && strpos($block['blockName'], 'toolset-blocks/') === 0 && false !== strpos($block_content, '[e2pdf-')
882 + ) {
883 + add_shortcode('e2pdf-download', [new Model_E2pdf_Shortcode(), 'e2pdf_download']);
884 + add_shortcode('e2pdf-view', [new Model_E2pdf_Shortcode(), 'e2pdf_view']);
885 + add_shortcode('e2pdf-save', [new Model_E2pdf_Shortcode(), 'e2pdf_save']);
886 + add_shortcode('e2pdf-zapier', [new Model_E2pdf_Shortcode(), 'e2pdf_zapier']);
887 + add_shortcode('e2pdf-adobesign', [new Model_E2pdf_Shortcode(), 'e2pdf_adobesign']);
888 + }
889 + return $block_content;
890 + }
479 891
480 - if (false === strpos($content, '[')) {
892 + // filter content
893 + public function filter_content($content, $post_id = false, $wp_reset_postdata = true) {
894 + global $post;
895 + if (!is_string($content) || false === strpos($content, '[')) {
481 896 return $content;
482 897 }
898 + $shortcode_tags = [
899 + 'e2pdf-download',
900 + 'e2pdf-save',
901 + 'e2pdf-view',
902 + 'e2pdf-adobesign',
903 + 'e2pdf-zapier',
904 + ];
905 + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
906 + $tagnames = array_intersect($shortcode_tags, $matches[1]);
907 + if (!empty($tagnames)) {
908 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
909 + foreach ($shortcodes[0] as $key => $shortcode_value) {
910 + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
911 + $atts = shortcode_parse_atts($shortcode[3]);
912 + if (isset($atts['wp_reset_postdata'])) {
913 + if ($atts['wp_reset_postdata'] == 'true') {
914 + $wp_reset_postdata = true;
915 + } else {
916 + $wp_reset_postdata = false;
917 + }
918 + }
919 + if ($wp_reset_postdata) {
920 + wp_reset_postdata();
921 + }
922 + if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
923 + } else {
924 + if (isset($atts['id'])) {
925 + $template = new Model_E2pdf_Template();
926 + $template->load($atts['id']);
927 + if ($template->get('extension') === 'woocommerce' || $template->get('extension') === 'jetformbuilder') {
928 + continue;
929 + } elseif ($template->get('extension') === 'wordpress') { // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
930 + if (!isset($atts['dataset'])) {
931 + if ($template->get('item') == '-3') {
932 + $dataset = get_current_user_id();
933 + $atts['dataset'] = $dataset;
934 + $shortcode[3] .= ' dataset="' . $dataset . '"';
935 + } else {
936 + if ($this->get('queried_object') && !$post_id) {
937 + $queried_object = get_queried_object();
938 + $post_id = $queried_object && isset($queried_object->ID) ? $queried_object->ID : false;
939 + }
940 + if ($post_id || isset($post->ID)) {
941 + $dataset = $post_id ? $post_id : $post->ID;
942 + $atts['dataset'] = $dataset;
943 + $shortcode[3] .= ' dataset="' . $dataset . '"';
944 + }
945 + }
946 + }
947 + }
948 + }
949 + if (!isset($atts['apply'])) {
950 + $shortcode[3] .= ' apply="true"';
951 + }
952 + if (!isset($atts['filter'])) {
953 + $shortcode[3] .= ' filter="true"';
954 + }
955 + $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content);
956 + }
957 + }
958 + }
959 + return $content;
960 + }
483 961
962 + // [e2pdf-exclude] support inside Formidable Forms View beforeContent and afterContent
963 + public function filter_frm_filter_view($view) {
964 + if (isset($view->frm_before_content) && $view->frm_before_content) {
965 + $view->frm_before_content = str_replace('[e2pdf-exclude]', '[e2pdf-exclude apply="true"]', $view->frm_before_content);
966 + }
967 + if (isset($view->post_content) && $view->post_content) {
968 + $view->post_content = str_replace('[e2pdf-exclude]', '[e2pdf-exclude apply="true"]', $view->post_content);
969 + }
970 + if (isset($view->frm_after_content) && $view->frm_after_content) {
971 + $view->frm_after_content = str_replace('[e2pdf-exclude]', '[e2pdf-exclude apply="true"]', $view->frm_after_content);
972 + }
973 + return $view;
974 + }
484 975
485 - $shortcode_tags = array(
486 - 'e2pdf-exclude',
487 - );
976 + // vc map get attributes filter
977 + public function filter_vc_map_get_attributes($atts, $tag) {
978 + if ($tag == 'vc_single_image' && ((isset($atts['onclick']) && $atts['onclick'] == 'custom_link') || (empty($atts['onclick']) && (!isset($atts['img_link_large']) || 'yes' !== $atts['img_link_large']))) && (!empty($atts['link']) || !empty($atts['img_link']))) {
488 979
980 + if (!empty($atts['link'])) {
981 + $atts['link'] = $this->filter_content($atts['link']);
982 + }
489 983
490 - preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
491 - $tagnames = array_intersect($shortcode_tags, $matches[1]);
984 + if (!empty($atts['img_link'])) {
985 + $atts['img_link'] = $this->filter_content($atts['img_link']);
986 + }
987 + }
988 + return $atts;
989 + }
492 990
991 + // filter cs element pre prender
992 + public function filter_cs_element_pre_render($data) {
993 + if (!empty($data['_type']) && $data['_type'] == 'raw-content' && !empty($data['raw_content']) && !empty($data['_p'])) {
994 + $data['raw_content'] = $this->filter_content($data['raw_content'], $data['_p']);
995 + }
996 + return $data;
997 + }
493 998
494 - if (!empty($tagnames)) {
495 - $pattern = get_shortcode_regex($tagnames);
999 + // filter themify builder module content
1000 + public function filter_themify_builder_module_content($content) {
1001 + if ($content) {
1002 + $content = $this->filter_content($content);
1003 + }
1004 + return $content;
1005 + }
496 1006
497 - preg_match_all("/$pattern/", $content, $shortcodes);
1007 + // filter vs basic grid items list
1008 + public function filter_vc_basic_grid_items_list($items) {
1009 + if ($items) {
1010 + $items = $this->filter_content($items);
1011 + }
1012 + return $items;
1013 + }
498 1014
1015 + // filter the content
1016 + public function filter_the_content($content, $post_id = false) {
1017 + $content = $this->filter_content($content, $post_id);
1018 + return $content;
1019 + }
499 1020
500 - foreach ($shortcodes[0] as $key => $shortcode_value) {
1021 + // filter content custom
1022 + public function filter_content_custom($content) {
1023 + $content = $this->filter_content($content);
1024 + return $content;
1025 + }
501 1026
502 - $shortcode = array();
503 - $shortcode[1] = $shortcodes[1][$key];
504 - $shortcode[2] = $shortcodes[2][$key];
505 - $shortcode[3] = $shortcodes[3][$key];
506 - $shortcode[4] = $shortcodes[4][$key];
507 - $shortcode[5] = $shortcodes[5][$key];
508 - $shortcode[6] = $shortcodes[6][$key];
1027 + // filter content loop
1028 + public function filter_content_loop($content) {
1029 + $content = $this->filter_content($content, false, false);
1030 + return $content;
1031 + }
509 1032
510 - $shortcode[3] .= " apply='true'";
511 - $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content);
1033 + /**
1034 + * Memberpress Mail attachments filter
1035 + * https://memberpress.com/
1036 + */
1037 + public function filter_mepr_email_send_attachments($attachments, $mail, $body, $values) {
1038 + $message = $body ? $body : $mail->body();
1039 + if ($message && false !== strpos($message, '[')) {
1040 + $message = $mail->replace_variables($message, $values);
1041 + $shortcode_tags = [
1042 + 'e2pdf-attachment',
1043 + 'e2pdf-save',
1044 + ];
1045 + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $message, $matches);
1046 + $tagnames = array_intersect($shortcode_tags, $matches[1]);
1047 + if (!empty($tagnames)) {
1048 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $message, $shortcodes);
1049 + foreach ($shortcodes[0] as $key => $shortcode_value) {
1050 + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
1051 + $atts = shortcode_parse_atts($shortcode[3]);
1052 + $file = false;
1053 + if (isset($atts['id']) && isset($atts['dataset'])) {
1054 + if (!isset($atts['apply'])) {
1055 + $shortcode[3] .= ' apply="true"';
1056 + }
1057 + if (!isset($atts['filter'])) {
1058 + $shortcode[3] .= ' filter="true"';
1059 + }
1060 + if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) {
1061 + $file = do_shortcode_tag($shortcode);
1062 + if ($file) {
1063 + $tmp = false;
1064 + if (substr($file, 0, 4) === 'tmp:') {
1065 + $file = substr($file, 4);
1066 + $tmp = true;
1067 + }
1068 + if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
1069 + if ($tmp) {
1070 + $this->helper->add('wordpress_attachments_mepr', $file);
1071 + }
1072 + } else {
1073 + $this->helper->add('wordpress_attachments_mepr', $file);
1074 + }
1075 + $attachments[] = $file;
1076 + }
1077 + }
1078 + }
1079 + }
512 1080 }
513 1081 }
1082 + return $attachments;
1083 + }
514 1084
1085 + // mepr the content filter
1086 + public function filter_mepr_the_content($content) {
1087 + if (
1088 + class_exists('MeprUtils') && method_exists('MeprUtils', 'get_current_post') &&
1089 + class_exists('MeprOptions') && method_exists('MeprOptions', 'fetch')
1090 + ) {
1091 + $current_post = MeprUtils::get_current_post();
1092 + if ($current_post !== false) {
1093 + $mepr_options = MeprOptions::fetch();
1094 + if ($current_post->ID == $mepr_options->thankyou_page_id) {
1095 + remove_shortcode('e2pdf-download');
1096 + remove_shortcode('e2pdf-view');
1097 + remove_shortcode('e2pdf-save');
1098 + remove_shortcode('e2pdf-zapier');
1099 + remove_shortcode('e2pdf-adobesign');
1100 + }
1101 + }
1102 + }
1103 + return $content;
1104 + }
515 1105
1106 + // mepr custom thank you message filter
1107 + public function filter_mepr_custom_thankyou_message($content) {
1108 + add_shortcode('e2pdf-download', [new Model_E2pdf_Shortcode(), 'e2pdf_download']);
1109 + add_shortcode('e2pdf-view', [new Model_E2pdf_Shortcode(), 'e2pdf_view']);
1110 + add_shortcode('e2pdf-save', [new Model_E2pdf_Shortcode(), 'e2pdf_save']);
1111 + add_shortcode('e2pdf-zapier', [new Model_E2pdf_Shortcode(), 'e2pdf_zapier']);
1112 + add_shortcode('e2pdf-adobesign', [new Model_E2pdf_Shortcode(), 'e2pdf_adobesign']);
1113 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1114 + if (isset($_REQUEST['trans_num']) && class_exists('MeprTransaction') && method_exists('MeprTransaction', 'get_one_by_trans_num')) {
1115 + $txn = new MeprTransaction();
1116 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1117 + $data = MeprTransaction::get_one_by_trans_num($_REQUEST['trans_num']);
1118 + if (method_exists($txn, 'load_data')) {
1119 + $txn->load_data($data);
1120 + if (false !== strpos($content, '[')) {
1121 + $shortcode_tags = [
1122 + 'e2pdf-download',
1123 + 'e2pdf-view',
1124 + 'e2pdf-save',
1125 + 'e2pdf-zapier',
1126 + 'e2pdf-adobesign',
1127 + ];
1128 + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
1129 + $tagnames = array_intersect($shortcode_tags, $matches[1]);
1130 + if (!empty($tagnames)) {
1131 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
1132 + foreach ($shortcodes[0] as $key => $shortcode_value) {
1133 + wp_reset_postdata();
1134 + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
1135 + $atts = shortcode_parse_atts($shortcode[3]);
1136 + if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
1137 + } elseif (isset($atts['id'])) {
1138 + $user_id = !empty($txn->user_id) ? $txn->user_id : get_current_user_id();
1139 + $template = new Model_E2pdf_Template();
1140 + $template->load($atts['id']);
1141 + if ($template->get('extension') === 'wordpress' && $template->get('item') == '-3') { // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
1142 + if (!isset($atts['dataset'])) {
1143 + $atts['dataset'] = $user_id;
1144 + $shortcode[3] .= ' dataset="' . $user_id . '"';
1145 + }
1146 + } else {
1147 + if (!isset($atts['user_id'])) {
1148 + $atts['user_id'] = $user_id;
1149 + $shortcode[3] .= ' user_id="' . $user_id . '"';
1150 + }
1151 + }
1152 + }
1153 + if (!isset($atts['apply'])) {
1154 + $shortcode[3] .= ' apply="true"';
1155 + }
1156 + if (!isset($atts['filter'])) {
1157 + $shortcode[3] .= ' filter="true"';
1158 + }
1159 + $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content);
1160 + }
1161 + }
1162 + }
1163 + }
1164 + }
516 1165 return $content;
517 1166 }
518 1167
1168 + // user registration smart tag values filter
1169 + public function filter_user_registration_smart_tag_values($values) {
1170 + foreach ($values as $key => $value) {
1171 + if (is_string($value) && false !== strpos($value, '[e2pdf-')) {
1172 + $values[$key] = str_replace('[e2pdf-', '&#91;e2pdf-', $value);
1173 + }
1174 + }
1175 + return $values;
1176 + }
1177 +
519 1178 /**
520 - * Search and update shortcodes for this extension inside content
521 - * Auto set of dataset id
522 - *
523 - * @param string $content - Content
524 - *
525 - * @return string - Content with updated shortcodes
1179 + * Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin
1180 + * https://wordpress.org/plugins/ultimate-member/
526 1181 */
527 - public function filter_content($content) {
528 - global $post;
529 -
530 - if (false === strpos($content, '[')) {
1182 + public function filter_um_email_send_message_content($content) {
1183 + if (!is_string($content) || false === strpos($content, '[')) {
531 1184 return $content;
532 1185 }
533 -
534 - $shortcode_tags = array(
1186 + $shortcode_tags = [
535 1187 'e2pdf-download',
536 - 'e2pdf-view'
537 - );
538 -
1188 + 'e2pdf-save',
1189 + 'e2pdf-attachment',
1190 + 'e2pdf-view',
1191 + 'e2pdf-adobesign',
1192 + 'e2pdf-zapier',
1193 + ];
539 1194 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
540 1195 $tagnames = array_intersect($shortcode_tags, $matches[1]);
541 -
542 1196 if (!empty($tagnames)) {
543 - $pattern = get_shortcode_regex($tagnames);
544 -
545 - preg_match_all("/$pattern/", $content, $shortcodes);
546 -
1197 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
547 1198 foreach ($shortcodes[0] as $key => $shortcode_value) {
1199 + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
1200 + $atts = shortcode_parse_atts($shortcode[3]);
1201 + if (!isset($atts['apply'])) {
1202 + $shortcode[3] .= ' apply="true"';
1203 + }
1204 + if (!isset($atts['filter'])) {
1205 + $shortcode[3] .= ' filter="true"';
1206 + }
1207 + if (isset($atts['id'])) {
1208 + $template = new Model_E2pdf_Template();
1209 + $template->load($atts['id']);
1210 + if ($template->get('extension') === 'wordpress') { // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
1211 + if (!isset($atts['dataset'])) {
1212 + if ($template->get('item') == '-3' && function_exists('um_user')) {
1213 + $dataset = um_user('ID');
1214 + $atts['dataset'] = $dataset;
1215 + $shortcode[3] .= ' dataset="' . $dataset . '"';
1216 + }
1217 + }
1218 + }
1219 + }
1220 + if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) {
1221 + $file = do_shortcode_tag($shortcode);
1222 + if ($file) {
1223 + $tmp = false;
1224 + if (substr($file, 0, 4) === 'tmp:') {
1225 + $file = substr($file, 4);
1226 + $tmp = true;
1227 + }
1228 + if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
1229 + if ($tmp) {
1230 + $this->helper->add('wordpress_attachments_um_del', $file);
1231 + }
1232 + } else {
1233 + $this->helper->add('wordpress_attachments_um_del', $file);
1234 + }
1235 + $this->helper->add('wordpress_attachments_um', $file);
1236 + }
1237 + $content = str_replace($shortcode_value, '', $content);
1238 + } else {
1239 + $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content);
1240 + }
1241 + }
1242 + }
1243 + return $content;
1244 + }
548 1245
549 - wp_reset_postdata();
550 - $extension = false;
551 - $item = false;
1246 + /**
1247 + * Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin
1248 + * https://wordpress.org/plugins/ultimate-member/
1249 + */
1250 + public function filter_wp_mail_um($args) {
1251 + $files = $this->helper->get('wordpress_attachments_um');
1252 + if (is_array($files) && !empty($files)) {
1253 + if (empty($args['attachments'])) {
1254 + $args['attachments'] = [];
1255 + } elseif (!is_array($args['attachments'])) {
1256 + $args['attachments'] = [$args['attachments']];
1257 + }
1258 + foreach ($files as $key => $file) {
1259 + $args['attachments'][] = $file;
1260 + }
1261 + }
1262 + return $args;
1263 + }
552 1264
553 - $shortcode = array();
554 - $shortcode[1] = $shortcodes[1][$key];
555 - $shortcode[2] = $shortcodes[2][$key];
556 - $shortcode[3] = $shortcodes[3][$key];
557 - $shortcode[4] = $shortcodes[4][$key];
558 - $shortcode[5] = $shortcodes[5][$key];
559 - $shortcode[6] = $shortcodes[6][$key];
1265 + // wp mail filter
1266 + public function filter_wp_mail($args) {
1267 + if (isset($args['message'])) {
1268 + if (false !== strpos($args['message'], '[')) {
1269 + $shortcode_tags = [
1270 + 'e2pdf-download',
1271 + 'e2pdf-save',
1272 + 'e2pdf-attachment',
1273 + 'e2pdf-adobesign',
1274 + 'e2pdf-zapier',
1275 + ];
1276 + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $args['message'], $matches);
1277 + $tagnames = array_intersect($shortcode_tags, $matches[1]);
1278 + if (!empty($tagnames)) {
1279 + $args['attachments'] = $this->helper->load('convert')->is_string_array($args['attachments']);
1280 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $args['message'], $shortcodes);
1281 + foreach ($shortcodes[0] as $key => $shortcode_value) {
1282 + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
1283 + $atts = shortcode_parse_atts($shortcode[3]);
1284 + if (!isset($atts['apply'])) {
1285 + $shortcode[3] .= ' apply="true"';
1286 + }
1287 + if (!isset($atts['filter'])) {
1288 + $shortcode[3] .= ' filter="true"';
1289 + }
1290 + $file = false;
1291 + if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) {
1292 + $file = do_shortcode_tag($shortcode);
1293 + if ($file) {
1294 + $tmp = false;
1295 + if (substr($file, 0, 4) === 'tmp:') {
1296 + $file = substr($file, 4);
1297 + $tmp = true;
1298 + }
1299 + if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
1300 + if ($tmp) {
1301 + $this->helper->add('wordpress_attachments', $file);
1302 + }
1303 + } else {
1304 + $this->helper->add('wordpress_attachments', $file);
1305 + }
1306 + $args['attachments'][] = $file;
1307 + }
1308 + $args['message'] = str_replace($shortcode_value, '', $args['message']);
1309 + } else {
1310 + $args['message'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $args['message']);
1311 + }
1312 + }
1313 + }
1314 + }
1315 + }
1316 + return [
1317 + 'to' => $args['to'],
1318 + 'subject' => $args['subject'],
1319 + 'message' => $args['message'],
1320 + 'headers' => $args['headers'],
1321 + 'attachments' => $args['attachments'],
1322 + ];
1323 + }
560 1324
561 - $atts = shortcode_parse_atts($shortcode[3]);
1325 + // Thrive Theme Builder dynamic shortcode support
1326 + public function filter_thrive_theme_template_content($html) {
1327 + add_filter('e2pdf_model_shortcode_e2pdf_download_atts', [$this, 'filter_global_post_id']);
1328 + add_filter('e2pdf_model_shortcode_e2pdf_view_atts', [$this, 'filter_global_post_id']);
1329 + add_filter('e2pdf_model_shortcode_e2pdf_save_atts', [$this, 'filter_global_post_id']);
1330 + add_filter('e2pdf_model_shortcode_e2pdf_zapier_atts', [$this, 'filter_global_post_id']);
1331 + return $html;
1332 + }
562 1333
563 - if (array_key_exists('id', $atts)) {
564 - $template = new Model_E2pdf_Template();
565 - $template->load($atts['id']);
566 - if ($template->get('extension') === 'wordpress') {
567 - $extension = $template->get('extension');
568 - $item = $template->get('item');
1334 + // dynamic post id support filter
1335 + public function filter_global_post_id($atts) {
1336 + if (!isset($atts['dataset']) && isset($atts['id'])) {
1337 + $template_id = isset($atts['id']) ? (int) $atts['id'] : 0;
1338 + $template = new Model_E2pdf_Template();
1339 + if ($template->load($template_id, false)) {
1340 + if ($template->get('extension') === 'wordpress') { // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
1341 + global $post;
1342 + if (isset($post->ID)) {
1343 + $atts['dataset'] = (string) $post->ID;
1344 + if (!isset($atts['apply'])) {
1345 + $atts['apply'] = 'true';
1346 + }
1347 + if (!isset($atts['filter'])) {
1348 + $atts['filter'] = 'true';
1349 + }
569 1350 }
570 1351 }
1352 + }
1353 + }
1354 + return $atts;
1355 + }
571 1356
572 - if ($extension) {
573 - if (!array_key_exists('dataset', $atts)) {
574 - if (isset($post->ID)) {
575 - $dataset_id = $post->ID;
576 - $atts['dataset'] = $dataset_id;
577 - $shortcode[3] .= " dataset='{$dataset_id}'";
578 - $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content);
1357 + // et pb module content filter
1358 + public function filter_et_pb_module_content($content, $props, $attrs, $render_slug, $_address, $global_content) {
1359 + if (($render_slug == 'et_pb_code' || $render_slug == 'et_pb_text') &&
1360 + false !== strpos($content, '[') &&
1361 + function_exists('et_core_is_builder_used_on_current_request') &&
1362 + !et_core_is_builder_used_on_current_request()
1363 + ) {
1364 + global $post;
1365 + $shortcode_tags = [
1366 + 'e2pdf-download',
1367 + 'e2pdf-save',
1368 + 'e2pdf-view',
1369 + 'e2pdf-adobesign',
1370 + 'e2pdf-zapier',
1371 + ];
1372 + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
1373 + $tagnames = array_intersect($shortcode_tags, $matches[1]);
1374 + if (!empty($tagnames)) {
1375 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
1376 + foreach ($shortcodes[0] as $key => $shortcode_value) {
1377 + wp_reset_postdata();
1378 + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
1379 + $atts = shortcode_parse_atts($shortcode[3]);
1380 + if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
1381 + } else {
1382 + if (!isset($atts['dataset']) && isset($atts['id']) && (isset($post->ID))) {
1383 + $dataset = $post->ID;
1384 + $atts['dataset'] = $dataset;
1385 + $shortcode[3] .= ' dataset="' . $dataset . '"';
579 1386 }
580 - } else {
581 - $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content);
582 1387 }
583 - } elseif ($shortcode[2] === 'e2pdf-view') {
584 - $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content);
1388 + if (!isset($atts['apply'])) {
1389 + $shortcode[3] .= ' apply="true"';
1390 + }
1391 +
1392 + if (!isset($atts['filter'])) {
1393 + $shortcode[3] .= ' filter="true"';
1394 + }
1395 + $new_shortcode = '[' . $shortcode[2] . $shortcode[3] . ']';
1396 + $content = str_replace($shortcode_value, $new_shortcode, $content);
585 1397 }
586 1398 }
587 1399 }
588 -
589 1400 return $content;
590 1401 }
591 1402
1403 + // verify
592 1404 public function verify() {
593 - $item_id = $this->get('item');
594 - $dataset_id = $this->get('dataset');
595 -
596 - if ($item_id && $dataset_id && $item_id === get_post_type($dataset_id)) {
1405 + if ($this->get('item') && $this->get('cached_post') && (($this->get('item') == get_post_type($this->get('cached_post'))) || ($this->get('item') == '-3' && $this->get('cached_post')))) {
597 1406 return true;
598 1407 }
599 -
600 1408 return false;
601 1409 }
602 1410
1411 + // visual mapper
603 1412 public function visual_mapper() {
604 1413
605 - $vc = "<h3>Wordpress</h3>";
1414 + $vc = '';
1415 +
1416 + if ($this->get('item') != '-3') {
1417 + $vc .= '<h3 class="e2pdf-plr5">Common</h3>';
1418 + $vc .= '<div class="e2pdf-grid">';
1419 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('ID', 'e2pdf-wp key="id"') . '</div>';
1420 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Author', 'e2pdf-wp key="post_author"') . '</div>';
1421 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Author ID', 'e2pdf-wp key="post_author_id"') . '</div>';
1422 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Date', 'e2pdf-wp key="post_date"') . '</div>';
1423 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Date (GMT)', 'e2pdf-wp key="post_date_gmt"') . '</div>';
1424 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Content', 'e2pdf-wp key="post_content"') . '</div>';
1425 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Title', 'e2pdf-wp key="post_title"') . '</div>';
1426 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Excerpt', 'e2pdf-wp key="post_excerpt"') . '</div>';
1427 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Status', 'e2pdf-wp key="post_status"') . '</div>';
1428 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Comment Status', 'e2pdf-wp key="comment_status"') . '</div>';
1429 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Ping Status', 'e2pdf-wp key="ping_status"') . '</div>';
1430 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Password', 'e2pdf-wp key="post_password"') . '</div>';
1431 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Name', 'e2pdf-wp key="post_name"') . '</div>';
1432 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('To Ping', 'e2pdf-wp key="to_ping"') . '</div>';
1433 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Ping', 'e2pdf-wp key="pinged"') . '</div>';
1434 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Modified Date', 'e2pdf-wp key="post_modified"') . '</div>';
1435 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Modified Date (GMT)', 'e2pdf-wp key="post_modified_gmt"') . '</div>';
1436 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Filtered Content', 'e2pdf-wp key="post_content_filtered"') . '</div>';
1437 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Parent ID', 'e2pdf-wp key="post_parent"') . '</div>';
1438 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('GUID', 'e2pdf-wp key="guid"') . '</div>';
1439 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Menu Order', 'e2pdf-wp key="menu_order"') . '</div>';
1440 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Type', 'e2pdf-wp key="post_type"') . '</div>';
1441 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Mime Type', 'e2pdf-wp key="post_mime_type"') . '</div>';
1442 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Comments Count', 'e2pdf-wp key="comment_count"') . '</div>';
1443 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Filter', 'e2pdf-wp key="filter"') . '</div>';
1444 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Post Thumbnail', 'e2pdf-wp key="get_the_post_thumbnail"') . '</div>';
1445 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Post Thumbnail URL', 'e2pdf-wp key="get_the_post_thumbnail_url"') . '</div>';
1446 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Permalink', 'e2pdf-wp key="get_permalink"') . '</div>';
1447 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Post Permalink', 'e2pdf-wp key="get_post_permalink"') . '</div>';
1448 + $vc .= '</div>';
1449 +
1450 + $meta_keys = $this->get_post_meta_keys();
1451 + if (!empty($meta_keys)) {
1452 + $vc .= '<h3 class="e2pdf-plr5">Meta Keys</h3>';
1453 + $vc .= "<div class='e2pdf-grid'>";
1454 + foreach ($meta_keys as $meta_key) {
1455 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($meta_key, 'e2pdf-wp key="' . $meta_key . '" meta="true"') . '</div>';
1456 + }
1457 + $vc .= '</div>';
1458 + }
1459 +
1460 + $meta_keys = $this->get_post_taxonomy_keys();
1461 + if (!empty($meta_keys)) {
1462 + $vc .= '<h3 class="e2pdf-plr5">Taxonomy</h3>';
1463 + $vc .= "<div class='e2pdf-grid'>";
1464 + foreach ($meta_keys as $meta_key) {
1465 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($meta_key, 'e2pdf-wp key="' . $meta_key . '" terms="true" names="true"') . '</div>';
1466 + }
1467 + $vc .= '</div>';
1468 + }
1469 + }
1470 +
1471 + $vc .= '<h3 class="e2pdf-plr5">User</h3>';
606 1472 $vc .= "<div class='e2pdf-grid'>";
607 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("ID", "e2pdf"), 'id')}</div>";
608 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Author", "e2pdf"), 'post_author')}</div>";
609 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Date", "e2pdf"), 'post_date')}</div>";
610 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Date (GMT)", "e2pdf"), 'post_date_gmt')}</div>";
611 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Content", "e2pdf"), 'post_content')}</div>";
612 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Title", "e2pdf"), 'post_title')}</div>";
613 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Excerpt", "e2pdf"), 'post_excerpt')}</div>";
614 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Status", "e2pdf"), 'post_status')}</div>";
615 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Comment Status", "e2pdf"), 'comment_status')}</div>";
616 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Ping Status", "e2pdf"), 'ping_status')}</div>";
617 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Post Password", "e2pdf"), 'post_password')}</div>";
618 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Post Name", "e2pdf"), 'post_name')}</div>";
619 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("To Ping", "e2pdf"), 'to_ping')}</div>";
620 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Ping", "e2pdf"), 'pinged')}</div>";
621 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Modified Date", "e2pdf"), 'post_modified')}</div>";
622 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Modified Date (GMT)", "e2pdf"), 'post_modified_gmt')}</div>";
623 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Filtered Content", "e2pdf"), 'post_content_filtered')}</div>";
624 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Parent ID", "e2pdf"), 'post_parent')}</div>";
625 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("GUID", "e2pdf"), 'guid')}</div>";
626 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Menu Order", "e2pdf"), 'menu_order')}</div>";
627 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Type", "e2pdf"), 'post_type')}</div>";
628 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Mime Type", "e2pdf"), 'post_mime_type')}</div>";
629 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Comments Count", "e2pdf"), 'comment_count')}</div>";
630 - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Filter", "e2pdf"), 'filter')}</div>";
631 - $vc .= "</div>";
1473 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('ID', 'e2pdf-user key="ID"') . '</div>';
1474 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Description', 'e2pdf-user key="user_description"') . '</div>';
1475 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('First Name', 'e2pdf-user key="user_firstname"') . '</div>';
1476 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Last Name', 'e2pdf-user key="user_lastname"') . '</div>';
1477 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Login', 'e2pdf-user key="user_login"') . '</div>';
1478 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Nicename', 'e2pdf-user key="user_nicename"') . '</div>';
1479 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('E-mail', 'e2pdf-user key="user_email"') . '</div>';
1480 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Url', 'e2pdf-user key="user_url"') . '</div>';
1481 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Registered', 'e2pdf-user key="user_registered"') . '</div>';
1482 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('User Status', 'e2pdf-user key="user_status"') . '</div>';
1483 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('User Level', 'e2pdf-user key="user_level"') . '</div>';
1484 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Display Name', 'e2pdf-user key="display_name"') . '</div>';
1485 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Spam', 'e2pdf-user key="spam"') . '</div>';
1486 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Deleted', 'e2pdf-user key="deleted"') . '</div>';
1487 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Locale', 'e2pdf-user key="locale"') . '</div>';
1488 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Rich Editing', 'e2pdf-user key="rich_editing"') . '</div>';
1489 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Syntax Highlighting', 'e2pdf-user key="syntax_highlighting"') . '</div>';
1490 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Use SSL', 'e2pdf-user key="use_ssl"') . '</div>';
1491 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Roles', 'e2pdf-user key="roles"') . '</div>';
1492 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Avatar', 'e2pdf-user key="get_avatar"') . '</div>';
1493 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Avatar Url', 'e2pdf-user key="get_avatar_url"') . '</div>';
1494 + $vc .= '</div>';
1495 +
1496 + $meta_keys = $this->get_user_meta_keys();
1497 + if (!empty($meta_keys)) {
1498 + $vc .= '<h3 class="e2pdf-plr5">User Meta Keys</h3>';
1499 + $vc .= "<div class='e2pdf-grid'>";
1500 + foreach ($meta_keys as $meta_key) {
1501 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($meta_key, 'e2pdf-user key="' . $meta_key . '" meta="true"') . '</div>';
1502 + }
1503 + $vc .= '</div>';
1504 + }
1505 +
1506 + if (class_exists('ACF') && function_exists('acf_get_field_groups')) {
1507 + $user_groups = acf_get_field_groups(
1508 + [
1509 + 'user_id' => 'new',
1510 + 'user_form' => 'all',
1511 + ]
1512 + );
1513 + if (!empty($user_groups)) {
1514 + $user_groups = array_column($user_groups, 'key');
1515 + }
1516 + if ($this->get('item') == '-3') {
1517 + $groups = acf_get_field_groups(
1518 + [
1519 + 'user_id' => 'new',
1520 + 'user_form' => 'all',
1521 + ]
1522 + );
1523 + } else {
1524 + $groups = acf_get_field_groups(['post_type' => $this->get('item')]);
1525 + }
1526 + if (!empty($groups)) {
1527 + $vc .= "<h3 class='e2pdf-plr5'>ACF</h3>";
1528 + foreach ($groups as $group_key => $group) {
1529 + $post_id = '';
1530 + if (!empty($user_groups)) {
1531 + if (in_array($group['key'], $user_groups, false)) {
1532 + if ($this->get('item') == '-3') {
1533 + $post_id = ' post_id="user_[e2pdf-dataset]"';
1534 + } else {
1535 + $post_id = ' post_id="user_[e2pdf-userid]"';
1536 + }
1537 + }
1538 + }
1539 + $vc .= '<h3 class="e2pdf-plr5">' . $group['title'] . '</h3>';
1540 + $vc .= "<div class='e2pdf-grid'>";
1541 + foreach (acf_get_fields($group['key']) as $field_key => $field) {
1542 + $vc = $this->get_acf_field($vc, $field, $post_id);
1543 + }
1544 + $vc .= '</div>';
1545 + }
1546 + }
1547 + }
632 1548 return $vc;
633 1549 }
634 1550
635 - private function get_vm_element($name, $id) {
636 - $element = "<div>";
637 - $element .= "<label>{$name}:</label>";
638 - $element .= "<input type='text' name='[{$id}]' value='[{$id}]'>";
639 - $element .= "</div>";
1551 + // get acf field
1552 + public function get_acf_field($vc, $field, $post_id) {
1553 + if ($field['type'] == 'repeater' && !empty($field['sub_fields'])) {
1554 + $sub_fields = [];
1555 + foreach ($field['sub_fields'] as $sub_field_key => $sub_field) {
1556 + $sub_fields[] = '[acf field="' . $sub_field['name'] . '"' . $post_id . ']';
1557 + $sub_field['label'] = $field['label'] . ' ' . $sub_field['label'];
1558 + $sub_field['name'] = $field['name'] . '_0_' . $sub_field['name'];
1559 + $vc = $this->get_acf_field($vc, $sub_field, $post_id);
1560 + }
1561 + if (!empty($sub_fields)) {
1562 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($field['label'] . ' Iteration', 'e2pdf-acf-repeater field="' . $field['name'] . '"' . $post_id . ']' . implode(' ', $sub_fields) . "\r\n" . '[/e2pdf-acf-repeater') . '</div>';
1563 + }
1564 + } elseif ($field['type'] == 'group' && !empty($field['sub_fields'])) {
1565 + $sub_fields = [];
1566 + foreach ($field['sub_fields'] as $sub_field_key => $sub_field) {
1567 + $sub_field['label'] = $field['label'] . ' ' . $sub_field['label'];
1568 + $sub_field['name'] = $field['name'] . '_' . $sub_field['name'];
1569 + $vc = $this->get_acf_field($vc, $sub_field, $post_id);
1570 + }
1571 + } else {
1572 + if ($field['name']) {
1573 + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($field['label'], 'acf field="' . $field['name'] . '"' . $post_id) . '</div>';
1574 + }
1575 + }
1576 + return $vc;
1577 + }
1578 +
1579 + // get post meta keys
1580 + public function get_post_meta_keys() {
1581 + global $wpdb;
1582 + $meta_keys = [];
1583 + if ($this->get('item')) {
1584 + $condition = [
1585 + 'p.post_type' => [
1586 + 'condition' => '=',
1587 + 'value' => $this->get('item'),
1588 + 'type' => '%s',
1589 + ],
1590 + ];
1591 + $order_condition = [
1592 + 'orderby' => 'meta_key',
1593 + 'order' => 'desc',
1594 + ];
1595 + $where = $this->helper->load('db')->prepare_where($condition);
1596 + $orderby = $this->helper->load('db')->prepare_orderby($order_condition);
1597 + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
1598 + $meta_keys = $wpdb->get_col($wpdb->prepare('SELECT DISTINCT `meta_key` FROM `' . $wpdb->postmeta . '` `pm` LEFT JOIN ' . $wpdb->posts . ' `p` ON (`p`.`ID` = `pm`.`post_ID`) ' . $where['sql'] . $orderby . '', $where['filter']));
1599 + }
1600 + return $meta_keys;
1601 + }
1602 +
1603 + // get user meta keys
1604 + public function get_user_meta_keys() {
1605 + global $wpdb;
1606 + $meta_keys = [];
1607 + if ($this->get('item')) {
1608 + $order_condition = [
1609 + 'orderby' => 'meta_key',
1610 + 'order' => 'desc',
1611 + ];
1612 + $orderby = $this->helper->load('db')->prepare_orderby($order_condition);
1613 + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
1614 + $meta_keys = $wpdb->get_col($wpdb->prepare('SELECT DISTINCT `meta_key` FROM `' . $wpdb->usermeta . '` ' . $orderby . ''));
1615 + }
1616 + return $meta_keys;
1617 + }
1618 +
1619 + // get post taxonomy keys
1620 + public function get_post_taxonomy_keys() {
1621 + global $wpdb;
1622 + $meta_keys = [];
1623 + if ($this->get('item')) {
1624 + $order_condition = [
1625 + 'orderby' => 'taxonomy',
1626 + 'order' => 'desc',
1627 + ];
1628 + $orderby = $this->helper->load('db')->prepare_orderby($order_condition);
1629 + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
1630 + $meta_keys = $wpdb->get_col($wpdb->prepare('SELECT DISTINCT `taxonomy` FROM `' . $wpdb->term_taxonomy . '` `t` ' . $orderby . ''));
1631 + }
1632 + return $meta_keys;
1633 + }
1634 +
1635 + // get wm element
1636 + public function get_vm_element($name, $id) {
1637 + $element = '<div>';
1638 + $element .= '<label>' . $name . ':</label>';
1639 + $element .= '<input type="text" name=\'[' . $id . ']\' value=\'[' . $id . ']\' class="e2pdf-w100">';
1640 + $element .= '</div>';
640 1641 return $element;
641 1642 }
642 1643
643 - public function load_shortcodes() {
644 - add_shortcode('e2pdf-exclude', array($this, 'shortcode_e2pdf_exclude'));
1644 + // page edit hook
1645 + public function hook_wordpress_page_edit() {
1646 + // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
1647 + $items = $this->helper->load('hooks')->get_items('wordpress', 'hook_wordpress_page_edit');
1648 + if (!empty($items)) {
1649 + add_meta_box(
1650 + 'e2pdf',
1651 + apply_filters('e2pdf_hook_section_title', __('E2Pdf Actions', 'e2pdf'), 'hook_wordpress_page_edit'),
1652 + [$this, 'hook_wordpress_page_edit_callback'],
1653 + $items,
1654 + 'side',
1655 + 'default'
1656 + );
1657 + }
645 1658 }
646 1659
647 - function shortcode_e2pdf_exclude($atts = array(), $content = null) {
648 - if (is_array($atts) && array_key_exists('apply', $atts)) {
649 - return '';
1660 + // page edit callback hook
1661 + public function hook_wordpress_page_edit_callback($post) {
1662 + if (!empty($post->post_type)) {
1663 + // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
1664 + $hooks = $this->helper->load('hooks')->get('wordpress', 'hook_wordpress_page_edit', $post->post_type);
1665 + if (!empty($hooks)) {
1666 + foreach ($hooks as $hook) {
1667 + if ($this->helper->load('hooks')->process_hook(
1668 + $hook,
1669 + [
1670 + 'dataset' => $post->ID,
1671 + ],
1672 + 'hook_wordpress_page_edit'
1673 + )
1674 + ) {
1675 + $action = apply_filters(
1676 + 'e2pdf_hook_action_button',
1677 + [
1678 + 'html' => '<p><a class="e2pdf-download-hook" target="_blank" title="%2$s" href="%1$s"><span class="dashicons dashicons-pdf"></span> %2$s</a></p>',
1679 + 'url' => $this->helper->get_url(
1680 + [
1681 + 'page' => 'e2pdf',
1682 + 'action' => 'export',
1683 + 'id' => $hook,
1684 + 'dataset' => $post->ID,
1685 + ], 'admin.php?'
1686 + ),
1687 + 'title' => 'PDF #' . $hook,
1688 + ], 'hook_wordpress_page_edit', $hook, $post->ID
1689 + );
1690 + if (!empty($action)) {
1691 + echo sprintf(
1692 + $action['html'], $action['url'], $action['title']
1693 + );
1694 + }
1695 + }
1696 + }
1697 + }
1698 + }
1699 + }
1700 +
1701 + // row actions hook
1702 + public function hook_wordpress_row_actions($actions, $post) {
1703 + if ($post && is_a($post, 'WP_User')) {
1704 + if (!empty($post->ID)) {
1705 + // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
1706 + $hooks = $this->helper->load('hooks')->get('wordpress', 'hook_wordpress_row_actions', '-3');
1707 + foreach ($hooks as $hook) {
1708 + if ($this->helper->load('hooks')->process_hook(
1709 + $hook,
1710 + [
1711 + 'dataset' => $post->ID,
1712 + ],
1713 + 'hook_wordpress_row_actions'
1714 + )
1715 + ) {
1716 + $action = apply_filters(
1717 + 'e2pdf_hook_action_button',
1718 + [
1719 + 'html' => '<a class="e2pdf-download-hook" target="_blank" href="%s">%s</a>',
1720 + 'url' => $this->helper->get_url(
1721 + [
1722 + 'page' => 'e2pdf',
1723 + 'action' => 'export',
1724 + 'id' => $hook,
1725 + 'dataset' => $post->ID,
1726 + ], 'admin.php?'
1727 + ),
1728 + 'title' => 'PDF #' . $hook,
1729 + ], 'hook_wordpress_row_actions', $hook, $post->ID
1730 + );
1731 + if (!empty($action)) {
1732 + $actions['e2pdf_' . $hook] = sprintf(
1733 + $action['html'], $action['url'], $action['title']
1734 + );
1735 + }
1736 + }
1737 + }
1738 + }
650 1739 } else {
651 - return $content;
1740 + if (!empty($post->post_type) && !empty($post->ID)) {
1741 + // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
1742 + $hooks = $this->helper->load('hooks')->get('wordpress', 'hook_wordpress_row_actions', $post->post_type);
1743 + foreach ($hooks as $hook) {
1744 + if ($this->helper->load('hooks')->process_hook(
1745 + $hook,
1746 + [
1747 + 'dataset' => $post->ID,
1748 + ],
1749 + 'hook_wordpress_row_actions'
1750 + )
1751 + ) {
1752 + $action = apply_filters(
1753 + 'e2pdf_hook_action_button',
1754 + [
1755 + 'html' => '<a class="e2pdf-download-hook" target="_blank" href="%s">%s</a>',
1756 + 'url' => $this->helper->get_url(
1757 + [
1758 + 'page' => 'e2pdf',
1759 + 'action' => 'export',
1760 + 'id' => $hook,
1761 + 'dataset' => $post->ID,
1762 + ], 'admin.php?'
1763 + ),
1764 + 'title' => 'PDF #' . $hook,
1765 + ], 'hook_wordpress_row_actions', $hook, $post->ID
1766 + );
1767 + if (!empty($action)) {
1768 + $actions['e2pdf_' . $hook] = sprintf(
1769 + $action['html'], $action['url'], $action['title']
1770 + );
1771 + }
1772 + }
1773 + }
1774 + }
652 1775 }
1776 + return $actions;
653 1777 }
654 -
655 1778 }