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