-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultilocaly.php
374 lines (275 loc) · 12.9 KB
/
multilocaly.php
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<?php
/**
Plugin Name: Multilocaly
Plugin URI: https://newfiesoft.com/wp-plugins/multilocaly/
Description: Based on WordPress multisite creates an independent multilingual website that can be linked to each other and switched on an easy way to use
Version: 1.0.0
Author: NewfieSoft
Author URI: https://www.newfiesoft.com
Donate link: https://newfiesoft.com/donate
Text Domain: multilocaly
Domain Path: /languages/
Network: true
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
defined('ABSPATH') or exit();
if ( ! function_exists( 'is_plugin_active' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
//// Get plugin dirname basename how can just call this short in all current and future functions
if (!function_exists('get_multilocaly_directory_name')) {
function get_multilocaly_directory_name(): string {
return dirname(plugin_basename(__FILE__));
}
}
$plugin_dirname = get_multilocaly_directory_name();
//echo $plugin_dirname . "\n"; //==> result is multilocaly
//// Get plugin basename how can just call this short in all current and future functions
if (!function_exists('get_multilocaly_directory')) {
function get_multilocaly_directory(): string {
return plugin_basename(__FILE__);
}
}
$plugin_basename = get_multilocaly_directory();
//echo $plugin_basename . "\n"; //==> result is multilocaly/multilocaly.php
//// Get plugin dir name how can just call this short in all current and future functions
if (!function_exists('get_multilocaly_plugin_dir_path')) {
function get_multilocaly_plugin_dir_path(): string {
return plugin_dir_path( __FILE__ );
}
}
$plugin_dir_path = get_multilocaly_plugin_dir_path();
//echo $plugin_dir_path . "\n"; //==> /home/username/public_html/wp-content/plugins/multilocaly/
//// Get plugin dir url name how can just call this short in all current and future functions
if (!function_exists('get_multilocaly_directory_url')) {
function get_multilocaly_directory_url(): string {
return plugin_dir_url(__FILE__);
}
}
$plugin_dir_url = get_multilocaly_directory_url();
//echo $plugin_dir_url . "\n"; //==> result is https://newfiesoft.com/wp-content/plugins/multilocaly/
//// Get plugin data how can just call this short in all current and future functions
if (!function_exists('get_multilocaly_plugin_data')) {
function get_multilocaly_plugin_data(): array {
$plugin_main_file = get_multilocaly_plugin_dir_path() . 'multilocaly.php';
return get_plugin_data($plugin_main_file);
}
}
$plugin_plugin_data = get_multilocaly_plugin_data();
//var_dump($plugin_plugin_data); //==> sho plugin informations like Name, PluginURI, Version and many more
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//// Function to run on activation and all that is triggered when clicking on Activate inside wp-admin/plugins.php
function mlomw_on_activation(): void {
// Define the languages directory path
$languages_dir = WP_CONTENT_DIR . '/languages';
// Check if the directory doesn't exist
if (!is_dir($languages_dir)) {
// If the directory doesn't exist, attempt to create it
wp_mkdir_p($languages_dir);
}
// Call the function to create tables when the plugin is activated
mlomw_check_plugin_database_tables();
}
register_activation_hook(__FILE__, 'mlomw_on_activation');
//// Check whether it is WP_ALLOW_MULTISITE enabled or not. If it is not enabled, display this notice as long as until has been enabled
function mlomw_require_multisite_notice(): void {
echo '<div class="notice notice-error is-dismissible">';
echo '<p>' . __('Multilocaly requires WordPress Multisite to be enabled. <a href="https://wordpress.org/support/article/create-a-network/" target="_blank">Please read this article</a> for guidance on enabling Multisite.', 'multilocaly') . '</p>';
echo '</div>';
}
function mlomw_setup_multisite_notice(): void {
$screen = get_current_screen();
if ($screen && $screen->id === 'plugins' && !is_multisite()) {
add_action('admin_notices', 'mlomw_require_multisite_notice');
}
}
add_action('current_screen', 'mlomw_setup_multisite_notice');
//// Load plugin Text Domain for multi-language support
function mlomw_plugin_load_text_domain(): void {
// Get plugin dirname basename
$plugin_dirname = get_multilocaly_directory_name();
// Load the plugin text domain
load_plugin_textdomain('multilocaly', false, $plugin_dirname . '/languages');
}
add_action('plugins_loaded', 'mlomw_plugin_load_text_domain');
//// Configures menu names and sub-menu names.
function mlomw_active_admin_menu(): void {
// Check If Multisite is not enabled, add an action to display an admin notice
if (!is_multisite()) {
add_action('admin_notices', 'mlomw_require_multisite_notice');
return; // Exit the function early if multisite is not enabled
}
// Always add the main menu page and General submenu, which are visible on all sites
add_menu_page(
'Multilocaly',
__('Multilocaly', 'multilocaly'),
'activate_plugins',
'multilocaly',
'mlomw_render_general_page',
'multilocaly-icon', // Make sure this icon slug matches your custom icon's registration.
999
);
add_submenu_page(
'multilocaly',
'General',
__('General', 'multilocaly'),
'activate_plugins',
'multilocaly',
'mlomw_render_general_page'
);
// Only add Languages and Manage submenus if on the main site
if (is_main_site()) {
add_submenu_page(
'multilocaly',
'Languages',
__('Languages', 'multilocaly'),
'activate_plugins',
'mlomw_languages_page',
'mlomw_render_languages_page'
);
}
// Add Settings and Help submenus, which are visible on all sites
add_submenu_page(
'multilocaly',
'Settings',
__('Settings', 'multilocaly'),
'activate_plugins',
'mlomw_settings_page',
'mlomw_render_settings_page'
);
add_submenu_page(
'multilocaly',
'Help',
__('Help', 'multilocaly'),
'activate_plugins',
'mlomw_help_page',
'mlomw_render_help_page'
);
// Check if the user is trying to access a restricted page on a subsite
if (isset($_GET['page']) && !is_main_site()) {
$allowed_pages = array('multilocaly', 'mlomw_settings_page', 'mlomw_help_page');
if (!in_array($_GET['page'], $allowed_pages, true)) {
wp_redirect(admin_url('admin.php?page=multilocaly')); // Redirect to the main admin page
exit();
}
}
}
add_action('admin_menu', 'mlomw_active_admin_menu');
//// All functions on this part only can be loaded and triggered outside the admin panels
if ( ! is_admin() ) {
// Require functions for front-side displays outside the admin panels. Example domain.com/
$allowed_front_function_files = glob($plugin_dir_path . "includes/functions/front/front_*.php");
foreach ($allowed_front_function_files as $file) {
// Perform additional checks if needed
if (is_file($file) && pathinfo($file, PATHINFO_EXTENSION) === 'php') {
require_once $file;
}
}
}
//// Here all functions on this part only can be loaded and triggered inside the admin panels
else {
// Here load plugin pages
$allowed_page_files = glob($plugin_dir_path . "pages/*.php");
foreach ($allowed_page_files as $file) {
// Perform additional checks if needed
if (is_file($file) && pathinfo($file, PATHINFO_EXTENSION) === 'php') {
require_once $file;
}
}
// Require functions for the back side that displays inside the admin panels. Example /wp-admin/
$allowed_back_function_files = glob($plugin_dir_path . "includes/functions/back/back_*.php");
foreach ($allowed_back_function_files as $file) {
// Perform additional checks if needed
if (is_file($file) && pathinfo($file, PATHINFO_EXTENSION) === 'php') {
require_once $file;
}
}
//// This helps to create additional buttons after the Plugin is activated Installed in the page Plugins list
function mlomw_custom_link_options_plugin($actions): array {
// Always add the "General" link if Multisite is enabled
if (is_multisite()) {
$support_url = esc_url(add_query_arg('page', 'multilocaly', get_admin_url() . 'admin.php'));
// Name
$support_name = __('General', 'multilocaly');
$settings_url = '<a href="' . $support_url . '">' . $support_name . '</a>';
$actions = array_merge(compact('settings_url'), $actions);
}
// Add "Network Setup" link only if WP_ALLOW_MULTISITE is true and the site is not a Multisite
if (defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE && !is_multisite()) {
$network_setup_url = esc_url(admin_url('network.php'));
// Name
$network_setup_name = __('Network Setup', 'multilocaly');
$network_setup_link = '<a href="' . $network_setup_url . '">' . $network_setup_name . '</a>';
// Insert the network setup link at the beginning of the array
$actions = array_merge(compact('network_setup_link'), $actions);
}
return $actions;
}
add_filter('plugin_action_links_' . $plugin_basename, 'mlomw_custom_link_options_plugin', 10, 2);
//// This helps to create additional custom meta links in the sequel after Version By .... Installed Plugins list
function mlomw_custom_link_action_plugin($links_array, $mlomw_plugin_name) {
// Get plugin basename
$plugin_basename = get_multilocaly_directory();
if ($mlomw_plugin_name === $plugin_basename) {
// Build URL Links
$support_url = 'https://wordpress.org/support/plugin/multilocaly/';
$faq_url = 'https://wordpress.org/plugins/multilocaly/#faq';
$rating_url = 'https://wordpress.org/support/plugin/multilocaly/reviews/#new-post';
// Links name
$support_name =__('Community Support', 'multilocaly');
$faq_name =__('FAQ', 'multilocaly');
$rating_name =__('Ratings', 'multilocaly');
// Create buttons
$links_array[] = '<a href="' . $support_url . '" class="help-style" target="_blank">' . $support_name . '</a>';
$links_array[] = '<a href="' . $faq_url . '" class="help-style" target="_blank">' . $faq_name . '</a>';
$links_array[] = '<a href="' . $rating_url . '" class="help-style" target="_blank">' . $rating_name . '</a>';
}
return $links_array;
}
add_filter('plugin_row_meta', 'mlomw_custom_link_action_plugin', 10, 4);
//// Create a custom footer only inside plugin pages
function mlomw_customize_admin_footer_script(): void {
// Get plugin dir url name
$plugin_dir_url = get_multilocaly_directory_url();
// Get plugin data
$plugin_plugin_data = get_multilocaly_plugin_data();
// Get My plugin version
if ( ! function_exists( 'get_plugin_data' ) ) {
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
$plugin_data = $plugin_plugin_data;
// Check if we are on one of your plugin's pages
$current_page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : '';
// Add page URL slug from any page what have
$allowed_pages = array(
'multilocaly', // General
'mlomw_languages_page', // Languages
'mlomw_manage_page', // Manage
'mlomw_settings_page', // Settings
'mlomw_help_page', // Help
);
if (in_array($current_page, $allowed_pages)) {
echo '<script type="text/javascript">';
echo 'document.addEventListener("DOMContentLoaded", function() {';
// Modify content inside "footer-thankyou" // Content Left //
echo ' var footerThankYou = document.getElementById("footer-thankyou");';
echo ' if (footerThankYou) {';
echo ' footerThankYou.innerHTML = "<div class=\'power-by-info\'>' .
__('Premium Tools for WordPress made by', 'multilocaly') .
' <a href=\'https://www.newfiesoft.com\' target=\'_blank\'>NewfieSoft</a> ' .
__('with', 'multilocaly') .
' <i class=\"fa-solid fa-heart\"></i> ' . // FontAwesome heart icon
__('in Zürich, Switzerland', 'multilocaly') . '</div>";';
echo ' }';
// Remove content inside "footer-upgrade" // Content Right //
echo ' var footerUpgrade = document.getElementById("footer-upgrade");';
echo ' if (footerUpgrade) {';
echo ' footerUpgrade.innerHTML = "<div class=\'version\'>' . esc_html__('Version: ', 'multilocaly') . $plugin_data['Version'] . '</div>";';
echo ' }';
echo '});';
echo '</script>';
}
}
add_action('admin_footer', 'mlomw_customize_admin_footer_script');
}