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