-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathclass-dokan-integration.php
More file actions
148 lines (128 loc) · 4.93 KB
/
class-dokan-integration.php
File metadata and controls
148 lines (128 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
if ( !class_exists( 'weForms_Dokan_Integration' ) ) {
/**
* Dokan Integration Class
*
* @since 1.2.9
*/
class weForms_Dokan_Integration {
public function __construct() {
add_filter( 'dokan_settings_sections', [ $this, 'add_settings_sections' ] );
add_filter( 'dokan_get_dashboard_nav', [ $this, 'add_dashboard_nav' ] );
add_action( 'dokan_load_custom_template', [ $this, 'load_form_template' ] );
add_filter( 'dokan_query_var_filter', [ $this, 'register_queryvar' ] );
add_filter( 'dokan_settings_fields', [ $this, 'dokan_settings' ] );
}
public function add_settings_sections( $sections ) {
$sections[] = [
'id' => 'weforms_integration',
'title' => __( 'Vendor Contact Form', 'weforms' ),
'settings_title' => __( 'Vendor Contact Form', 'weforms' ),
'icon_url' => WEFORMS_ASSET_URI . '/images/icon-weforms.png',
];
return $sections;
}
/**
* Insert new URL's to the dashboard navigation bar
*
* @param array $urls
*
* @since 1.2.9
*
* @return array $urls
*/
public function add_dashboard_nav( $urls ) {
$access = dokan_get_option( 'allow_vendor_contact_form', 'weforms_integration' );
$section_label = dokan_get_option( 'vendor_contact_section_label', 'weforms_integration', __( 'Contact Admin', 'weforms' ) );
if ( $access == 'on' ) {
$urls['contact'] = [
'title' => $section_label,
'icon' => '<i class="fa fa-envelope-open"></i>',
'url' => dokan_get_navigation_url( 'contact' ),
'pos' => 67,
];
}
return $urls;
}
/**
* Load template for contact section
*
* @param array $query_vars
*
* @since 1.2.9
*
* @return void
*/
public function load_form_template( $query_vars ) {
$access = dokan_get_option( 'allow_vendor_contact_form', 'weforms_integration' );
if ( isset( $query_vars['contact'] ) && $access == 'on' ) {
require_once WEFORMS_ROOT . '/includes/templates/dokan/dashboard-contact-section.php';
}
}
/**
* Register query var
*
* @param array $query_vars
*
* @since 1.2.9
*
* @return array $query_vars
*/
public function register_queryvar( $query_vars ) {
$query_vars[] = 'contact';
return $query_vars;
}
/**
* Dokan settings for weForms integration
*
* @param array $settings_fields
*
* @since 1.2.9
*
* @return array $settings_fields
*/
public function dokan_settings( $settings_fields ) {
$settings_fields['weforms_integration']['allow_vendor_contact_form'] = [
'name' => 'allow_vendor_contact_form',
'label' => __( 'Vendor Can Contact', 'weforms' ),
'desc' => __( 'Allow Vendors to contact admin from the dashbaord area', 'weforms' ),
'type' => 'switcher',
'default' => 'off',
];
$settings_fields['weforms_integration']['vendor_contact_section_label'] = [
'name' => 'vendor_contact_section_label',
'label' => __( 'Contact Section Label', 'weforms' ),
'desc' => __( 'Label of contact section to show on vendor dashboard', 'weforms' ),
'type' => 'text',
'default' => __( 'Contact Admin', 'weforms' ),
];
$settings_fields['weforms_integration']['vendor_contact_form'] = [
'name' => 'vendor_contact_form',
'label' => __( 'Select Contact Form', 'weforms' ),
'desc' => __( 'Select a contact form that will show on the vendor dashboard.', 'weforms' ),
'type' => 'select',
'options' => $this->get_forms_dropdown_list(),
];
return $settings_fields;
}
/**
* Get all the contact forms
*
* @since 1.2.9
*
* @return array $post_forms
*/
public function get_forms_dropdown_list() {
$list = [];
$forms = $this->get_all_forms();
foreach ( $forms as $form ) {
$list[$form->id] = $form->name;
}
return $list;
}
public function get_all_forms() {
$forms_data = weforms()->form->all();
return $forms_data['forms'];
}
}
}