Plugin Directory

source: metform/trunk/base/shortcode.php @ 2845078

Last change on this file since 2845078 was 2845078, checked in by ataurr, 2 years ago

version 3.2.0

File size: 4.4 KB
Line 
1<?php
2
3namespace MetForm\Base;
4
5defined('ABSPATH') || exit;
6
7class Shortcode
8{
9
10        use \MetForm\Traits\Singleton;
11
12
13        public function __construct()
14        {
15                add_shortcode('metform', [$this, 'render_form']);
16                add_shortcode('mf_thankyou', [$this, 'render_thank_you_page']);
17                add_shortcode('mf_first_name', [$this, 'render_first_name']);
18                add_shortcode('mf_last_name', [$this, 'render_last_name']);
19                add_shortcode('mf_payment_status', [$this, 'render_payment_status']);
20                add_shortcode('mf_transaction_id', [$this, 'render_transaction_id']);
21                add_shortcode('mf',[$this,'render_mf_field']);
22        }
23
24        public function enqueue_form_assets(){
25                wp_enqueue_style('metform-ui');
26                wp_enqueue_style('metform-style');
27                wp_enqueue_script('htm');
28                wp_enqueue_script('metform-app');
29        }
30
31
32        public function render_form($atts)
33        {
34                $this->enqueue_form_assets();
35
36                $attributes = shortcode_atts(array(
37                        'form_id' => 'test',
38                ), $atts);
39
40                return '<div class="mf-form-shortcode">' . \MetForm\Utils\Util::render_form_content($attributes['form_id'], $attributes['form_id']) . '</div>';
41        }
42
43        public function render_thank_you_page($atts)
44        {
45                if($GLOBALS['pagenow'] == 'post.php'){
46                        return;
47                }
48                global $post;
49               
50                $this->enqueue_form_assets();
51
52                $a = shortcode_atts(array(
53                        'fname' => '',
54                        'lname' => '',
55                ), $atts);
56
57                $settings = \MetForm\Core\Admin\Base::instance()->get_settings_option();
58                $page_id =       $settings['mf_thank_you_page'];
59                //phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added, Its a callback function of 'add_shortcode'
60                $post_id = isset($_GET['id']) ? sanitize_text_field(wp_unslash($_GET['id'])) : '';
61                $postMeta = get_post_meta(
62                        $post_id,
63                        'metform_entries__form_data',
64                        true
65                );
66                $first_name = !empty($postMeta[$a['fname']]) ? $postMeta[$a['fname']] : '';
67
68                $payment_status = get_post_meta(
69                        $post_id,
70                        'metform_entries__payment_status',
71                        true
72                );
73
74                $tnx_id = get_post_meta(
75                        $post_id,
76                        'metform_entries__payment_trans',
77                        true
78                );
79       
80                $msg = '';
81
82                if ($payment_status == 'paid') {
83                        $msg = $first_name . ' Thank you for your payment. <br>' . ' Your transcation ID : ' . $tnx_id;
84                } else {
85                        $msg = 'Thank you . Your payment status : ' . $payment_status;
86                }
87               
88                return $msg;
89        }
90
91        public function render_mf_field($atts){
92                $this->enqueue_form_assets();
93
94                $a = shortcode_atts(array(
95                        'field' => ''
96                ),$atts);
97
98                $settings = \MetForm\Core\Admin\Base::instance()->get_settings_option();
99                $page_id =       $settings['mf_thank_you_page'];
100                //phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added, Its a callback function of 'add_shortcode'
101                $post_id = isset($_GET['id']) ? sanitize_text_field(wp_unslash($_GET['id'])) : '';
102                $field = get_post_meta(
103                        $post_id,
104                        'metform_entries__form_data',
105                        true
106                )[$a['field']];
107
108                return $field;
109        }
110
111        public function render_first_name($atts)
112        {
113                $this->enqueue_form_assets();
114                //phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added, Its a callback function of 'add_shortcode'
115                $post_id = isset($_GET['id']) ? sanitize_text_field(wp_unslash($_GET['id'])) : '';
116                $first_name = get_post_meta(
117                        $post_id,
118                        'metform_entries__form_data',
119                        true
120                )['mf-listing-fname'];
121                return $first_name;
122        }
123
124        public function render_last_name($atts)
125        {
126                $this->enqueue_form_assets();
127                //phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added, Its a callback function of 'add_shortcode'
128                $post_id = isset($_GET['id']) ? sanitize_text_field(wp_unslash($_GET['id'])) : '';
129                $last_name = get_post_meta(
130                        $post_id,
131                        'metform_entries__form_data',
132                        true
133                )['mf-listing-lname'];
134                return $last_name;
135        }
136
137        public function render_payment_status($atts)
138        {
139                $this->enqueue_form_assets();
140                //phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added, Its a callback function of 'add_shortcode'
141                $post_id = isset($_GET['id']) ? sanitize_text_field(wp_unslash($_GET['id'])) : '';
142                $payment_status = get_post_meta(
143                        $post_id,
144                        'metform_entries__payment_status',
145                        true
146                );
147                return $payment_status;
148        }
149
150        public function render_transaction_id($atts)
151        {
152                $this->enqueue_form_assets();
153                //phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added, Its a callback function of 'add_shortcode'
154                $post_id = isset($_GET['id']) ? sanitize_text_field(wp_unslash($_GET['id'])) : '';
155                $tnx_id = get_post_meta(
156                        $post_id,
157                        'metform_entries__payment_trans',
158                        true
159                );
160
161                return $tnx_id;
162        }
163}
Note: See TracBrowser for help on using the repository browser.