cpt = new Cpt();
add_action('save_post', [$this, 'store_form_data_cmb']);
add_action('add_meta_boxes', [$this, 'add_form_id_cmb']);
add_action('add_meta_boxes', [$this, 'add_form_data_cmb']);
add_action('add_meta_boxes', [$this, 'add_browser_data_cmb']);
add_action('add_meta_boxes', [$this, 'add_file_upload_cmb']);
add_action('admin_init', [$this, 'show_hide_payment_woo_meta_box']);
}
/**
* @description - checks if the post has any data of payment methods and woocommerce checkout.
* Based on the data it shows/hides the payment methods and woocommerce checkout meta box.
* @reference - https://prnt.sc/TJSnTkhK4hWy
*/
function show_hide_payment_woo_meta_box()
{
$post_id = isset($_GET['post']) ? sanitize_text_field(wp_unslash($_GET['post'])) : ''; //phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added in CPT edit page URL
$getPaymentStatus = get_post_meta($post_id, 'metform_entries__payment_status', true);
$getPaymentInvoiceStatus = get_post_meta($post_id, 'metform_entries__payment_invoice', true);
if($getPaymentStatus || $getPaymentInvoiceStatus){
add_action('add_meta_boxes', [$this, 'add_form_payment_status_cmb']);
}
$getWooCheckoutStatus = get_post_meta($post_id, 'mf_woo_order_id', true);
if($getWooCheckoutStatus){
add_action('add_meta_boxes', [$this, 'add_woo_payment_status_cmb']);
}
}
function add_form_id_cmb()
{
add_meta_box(
'metform_entries__form_id',
esc_html__('Info', 'metform'),
[$this, 'show_form_id_cmb'],
$this->cpt->get_name(),
'side',
'high'
);
}
function show_form_id_cmb($post)
{
wp_nonce_field('meta_nonce', 'meta_nonce');
$this->form_id = get_post_meta($post->ID, 'metform_entries__form_id', true);
// get fields by form id for further use
$this->fields = Action::instance()->get_fields($this->form_id);
$form_title = get_the_title((int)$this->form_id);
?>
|
|
|
ID, 'metform_entries_serial_no', true);
echo esc_html(isset($metform_entries_serial_no)? $metform_entries_serial_no : '');
?>
|
|
ID, 'metform_entries__user_id', true);
if($logged_user_id){
$author_obj = get_user_by('id', $logged_user_id);
$profile_link = " {$author_obj->data->user_login} ";
echo wp_kses($profile_link, array('a' => ['href'=>[]]));
}else{
echo esc_html__("Visitor", "metform");
}
?>
|
get_all_data($form_id);
// Change the form entries main title based on the form type
$data_title = esc_html__('Data', 'metform');
if(isset($form_settings['form_type']) && $form_settings['form_type'] == 'quiz-form'){
$data_title = esc_html__('Quiz Data', 'metform');
}
add_meta_box(
'metform_entries__form_data',
$data_title,
[$this, 'show_form_data_cmb'],
$this->cpt->get_name(),
'normal',
'high'
);
}
function add_browser_data_cmb()
{
// call browser data meta when browser data present
//phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added in CPT edit page URL
$post_id = (isset($_GET['post']) ? sanitize_text_field(wp_unslash($_GET['post'])) : '');
$form_id = get_post_meta($post_id, 'metform_entries__form_id', true);
$form_settings = \MetForm\Core\Forms\Action::instance()->get_all_data($form_id);
$this->browser_data = get_post_meta($post_id, 'metform_form__entry_browser_data', true);
if ($this->browser_data == '' && !isset($form_settings['capture_user_browser_data'])) {
return;
}
add_meta_box(
'metform_form__entry_browser_data',
esc_html__('Browser Data', 'metform'),
[$this, 'show_browser_data_cmb'],
$this->cpt->get_name(),
'side',
'low'
);
}
function show_browser_data_cmb($post)
{
if ($this->browser_data != '') {
?>
browser_data as $key => $value) {
?>
|
|
cpt->get_name(),
'normal',
'low'
);
}
}
function show_form_data_cmb($post)
{
wp_nonce_field('meta_nonce', 'meta_nonce');
$this->form_data = get_post_meta($post->ID, 'metform_entries__form_data', true);
$this->form_data = (isset($this->form_data)) ? $this->form_data : "";
// format all form data into html table
if ($this->form_data != '') {
$form_html = \MetForm\Core\Entries\Form_Data::format_form_data($this->form_id, $this->form_data);
\MetForm\Utils\Util::metform_content_renderer($form_html);
}
}
function show_file_upload_cmb($post)
{
// call file meta when file data present
//phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added in CPT edit page URL
$post_id = (isset($_GET['post']) ? sanitize_text_field(wp_unslash($_GET['post'])) : '');
$file_meta_data = get_post_meta($post_id, 'metform_entries__file_upload', true);
if (!is_array($file_meta_data)) {
$file_meta_data = get_post_meta($post_id, 'metform_entries__file_upload_new', true);
if(!is_array($file_meta_data)) {
return;
} else {
foreach($file_meta_data as $key => $value) {
if(!empty($value)) {
$this->show_file($value, $key);
}
}
}
} else {
$this->show_file($file_meta_data);
}
}
public function show_file($files, $name = false)
{
echo '';
if($name) {
echo '- ';
echo esc_html(((isset($this->fields[$name]->mf_input_label)) ? $this->fields[$name]->mf_input_label : $name) . " : ");
echo '
';
}
foreach($files as $key => $file) {
if(is_null($name)) {
$name = $key;
}
echo "- ";
$file_url = isset($file['url']) ? $file['url'] : '';
$file_type = isset($file['type']) ? $file['type'] : '';
if ($file_url != '') {
if(!$name) {
echo esc_html(((isset($this->fields[$key]->mf_input_label)) ? $this->fields[$key]->mf_input_label : $key+1) . " : ");
}
echo "" . esc_html__('Download', 'metform') . "";
echo((in_array($file_type, ['image/jpeg', 'image/png', 'image/jpg', 'image/gif', 'image/ico'])) ? ' | ' . esc_html__('View', 'metform') . '' : '');
} else {
echo esc_html(((isset($this->fields[$name]->mf_input_label)) ? $this->fields[$name]->mf_input_label : $key) . " : ") . esc_html__('This file is not uploaded.', 'metform');
}
echo "
";
$this->file_modal($name.$key, $file_url);
}
echo '
';
}
public function file_modal($key, $file_url) {
?>
cpt->get_name(),
'side',
'high'
);
}
function show_woo_checkout_status_cmb($post)
{
$order_id = get_post_meta($post->ID, 'mf_woo_order_id', true);
if($order_id == null) {
return;
}
$order = wc_get_order($order_id);
$order_url = get_admin_url() . 'post.php?post=' . $order_id . '&action=edit';
?>
|
|
|
get_status()); ?> |
|
get_total() . ' ' . $order->get_currency()); ?> |
|
cpt->get_name(),
'side',
'high'
);
}
function show_form_payment_status_cmb($post)
{
echo "Status : " . esc_html(get_post_meta($post->ID, 'metform_entries__payment_status', true)) . "
";
if (get_post_meta($post->ID, 'metform_entries__payment_invoice', true)) {
echo "Invoice : ";
echo esc_html(get_post_meta($post->ID, 'metform_entries__payment_invoice', true)) . "
";
}
}
}