-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservicehub-mvm.php
More file actions
195 lines (146 loc) · 5.86 KB
/
Copy pathservicehub-mvm.php
File metadata and controls
195 lines (146 loc) · 5.86 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link https://github.com/murslinshehzad-code
* @since 1.0.0
* @package Servicehub_Mvm
*
* @wordpress-plugin
* Plugin Name: ServiceHub MVM
* Plugin URI: https://github.com/murslinshehzad-code/ServiceHub-MVM
* Description: A dynamic multi-vendor service marketplace plugin for WordPress, enabling service providers to list, manage, and sell services with dashboards, bookings, payments, and messaging.
* Version: 1.0.0
* Author: Next Web Gen
* Author URI: https://github.com/murslinshehzad-code/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: servicehub-mvm
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Currently plugin version.
* Start at version 1.0.0 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
define( 'SERVICEHUB_MVM_VERSION', '1.0.0' );
// Define global constant in your main plugin file.
define('SERVICEHUB_MVM_PLUGIN_PATH', plugin_dir_path(__FILE__));
/**
* The code that runs during plugin activation.
* This action is documented in includes/class-servicehub-mvm-activator.php
*/
function activate_servicehub_mvm() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-servicehub-mvm-activator.php';
servicehub_mvm_activate(); // Call the function that adds the vendor role
}
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-servicehub-mvm-deactivator.php
*/
function deactivate_servicehub_mvm() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-servicehub-mvm-deactivator.php';
servicehub_mvm_deactivate();
}
register_activation_hook( __FILE__, 'activate_servicehub_mvm' );
register_deactivation_hook( __FILE__, 'deactivate_servicehub_mvm' );
/**
* The core plugin class that is used to define,
* admin-specific hooks, and public-facing site hooks.
*/
require_once plugin_dir_path(__FILE__) . 'includes/class-servicehub-mvm-init.php';
// Load authentication and shortcode handling of LOGIN/Registration of vendor
require_once plugin_dir_path(__FILE__) . 'public/class-servicehub-mvm-auth.php';
//Load admin dashboard widgets file
require_once plugin_dir_path(__FILE__) . 'admin/admin-dashboard-widgets.php';
// Creates Custom vendor USer Role
register_activation_hook(__FILE__, 'servicehub_mvm_activate');
// Creates the pages of login and registration of vendor
register_activation_hook(__FILE__, 'servicehub_mvm_create_pages');
// Flush rewrite rules on activation
// This ensures that the custom post type's URL structure (permalinks) works correctly
// without needing to manually refresh permalinks in WordPress settings.
// It registers the CPT and then flushes the rewrite rules.
register_activation_hook(__FILE__, function () {
servicehub_mvm_register_service_cpt(); // Register the custom post type
flush_rewrite_rules(); // Refresh WordPress rewrite rules
});
//DISPLAY Arhive SERVICE TEMPLATE FOR arhive SERVICE
add_filter('archive_template', function($archive_template) {
if (is_post_type_archive('service')) {
$plugin_template = SERVICEHUB_MVM_PLUGIN_PATH . 'public/templates/vendor/archive-service.php';
if (file_exists($plugin_template)) {
return $plugin_template;
}
}
return $archive_template;
});
//INlciding this file , this file create approve / disapprove new vendor fnctionality
require_once plugin_dir_path(__FILE__) . 'admin/vendor-approval-handler.php';
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
//Code related to the filters in archive service page
// servicehub-mvm.php or a file that's included on init
add_action('pre_get_posts', 'servicehub_mvm_filter_services_archive');
function servicehub_mvm_filter_services_archive($query) {
if (!is_admin() && $query->is_main_query() && is_post_type_archive('service')) {
// Remove empty search keyword
if (isset($_GET['s']) && trim($_GET['s']) === '') {
$query->set('s', false);
}
$tax_query = [];
// Service Type
if (!empty($_GET['service_type'])) {
$tax_query[] = [
'taxonomy' => 'service_type',
'field' => 'slug', // ✅ switched to slug
'terms' => sanitize_text_field($_GET['service_type']),
];
}
// Service Location
if (!empty($_GET['service_location'])) {
$tax_query[] = [
'taxonomy' => 'service_location',
'field' => 'slug', // ✅ switched to slug
'terms' => sanitize_text_field($_GET['service_location']),
];
}
if (!empty($tax_query)) {
$query->set('tax_query', $tax_query);
}
// Meta Query for Price
$meta_query = [];
if (!empty($_GET['min_price'])) {
$meta_query[] = [
'key' => '_service_price',
'value' => floatval($_GET['min_price']),
'compare' => '>=',
'type' => 'NUMERIC',
];
}
if (!empty($_GET['max_price'])) {
$meta_query[] = [
'key' => '_service_price',
'value' => floatval($_GET['max_price']),
'compare' => '<=',
'type' => 'NUMERIC',
];
}
if (!empty($meta_query)) {
$query->set('meta_query', $meta_query);
}
}
}