| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: VikRentCar |
| 4 |
Plugin URI: https://vikwp.com/plugin/vikrentcar |
| 5 |
Description: Robust Car Rental Management Software. |
| 6 |
Version: 1.4.6 |
| 7 |
Author: E4J s.r.l. |
| 8 |
Author URI: https://vikwp.com |
| 9 |
License: GPL2 |
| 10 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 11 |
Text Domain: vikrentcar |
| 12 |
Domain Path: /languages |
| 13 |
*/ |
| 14 |
|
| 15 |
// No direct access |
| 16 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 17 |
|
| 18 |
// autoload dependencies |
| 19 |
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'autoload.php'; |
| 20 |
|
| 21 |
// handle install/uninstall |
| 22 |
register_activation_hook(__FILE__, array('VikRentCarInstaller', 'activate')); |
| 23 |
register_deactivation_hook(__FILE__, array('VikRentCarInstaller', 'deactivate')); |
| 24 |
register_uninstall_hook(__FILE__, array('VikRentCarInstaller', 'delete')); |
| 25 |
|
| 26 |
// init Installer |
| 27 |
add_action('init', array('VikRentCarInstaller', 'onInit')); |
| 28 |
|
| 29 |
/** |
| 30 |
* Fires after all automatic updates have run. |
| 31 |
* Completes the update scheduled in background. |
| 32 |
* |
| 33 |
* @param array $results The results of all attempted updates. |
| 34 |
* |
| 35 |
* @since 1.2.0 |
| 36 |
*/ |
| 37 |
add_action('automatic_updates_complete', array('VikRentCarInstaller', 'automaticUpdate')); |
| 38 |
|
| 39 |
/** |
| 40 |
* Filters whether to automatically update core, a plugin, a theme, or a language. |
| 41 |
* Used to automatically turn off the update in case a PRO version expired. |
| 42 |
* |
| 43 |
* @param bool|null $update Whether to update. The value of null is internally used |
| 44 |
* to detect whether nothing has hooked into this filter. |
| 45 |
* @param object $item The update offer. |
| 46 |
* |
| 47 |
* @since 1.2.0 |
| 48 |
*/ |
| 49 |
add_filter('auto_update_plugin', array('VikRentCarInstaller', 'useAutoUpdate'), 10, 2); |
| 50 |
|
| 51 |
/** |
| 52 |
* Fires at the end of the update message container in each |
| 53 |
* row of the plugins list table. |
| 54 |
* |
| 55 |
* The dynamic portion of the hook name, `$file`, refers to the path |
| 56 |
* of the plugin's primary file relative to the plugins directory. |
| 57 |
* |
| 58 |
* @link https://developer.wordpress.org/reference/hooks/in_plugin_update_message-file/ |
| 59 |
* |
| 60 |
* @param array $data An array of plugin metadata. |
| 61 |
* @param array $response An array of metadata about the available plugin update. |
| 62 |
* |
| 63 |
* @since 1.2.0 |
| 64 |
*/ |
| 65 |
add_action('in_plugin_update_message-vikrentcar/vikrentcar.php', array('VikRentCarInstaller', 'getUpdateMessage'), 10, 2); |
| 66 |
|
| 67 |
// init pagination layout |
| 68 |
VikRentCarBuilder::setupPaginationLayout(); |
| 69 |
// init html helpers |
| 70 |
VikRentCarBuilder::setupHtmlHelpers(); |
| 71 |
// init payment framework |
| 72 |
VikRentCarBuilder::configurePaymentFramework(); |
| 73 |
|
| 74 |
// setup plugin overrides management |
| 75 |
add_action('plugins_loaded', array('VikRentCarBuilder', 'setupOverridesManager')); |
| 76 |
|
| 77 |
// setup lite system |
| 78 |
add_action('plugins_loaded', array('VikRentCarLiteManager', 'setup')); |
| 79 |
|
| 80 |
/** |
| 81 |
* Added support for screen options. |
| 82 |
* Parameters such as the list limit can be changed from there. |
| 83 |
*/ |
| 84 |
add_action('current_screen', array('VikRentCarScreen', 'options')); |
| 85 |
add_filter('set-screen-option', array('VikRentCarScreen', 'saveOption'), 10, 3); |
| 86 |
/** |
| 87 |
* Due to WordPress 5.4.2 changes, we need to attach |
| 88 |
* VikRentCar to a dedicated hook in order to |
| 89 |
* allow the update of the list limit. |
| 90 |
* |
| 91 |
* @since 1.0.7 |
| 92 |
*/ |
| 93 |
add_filter('set_screen_option_vikrentcar_list_limit', array('VikRentCarScreen', 'saveOption'), 10, 3); |
| 94 |
|
| 95 |
// init Session |
| 96 |
add_action('init', array('JSessionHandler', 'start'), 1); |
| 97 |
add_action('wp_logout', array('JSessionHandler', 'destroy')); |
| 98 |
|
| 99 |
// filter page link to rewrite URI |
| 100 |
add_action('plugins_loaded', function() |
| 101 |
{ |
| 102 |
// installer class will check the update status |
| 103 |
VikRentCarInstaller::update(); |
| 104 |
|
| 105 |
global $pagenow; |
| 106 |
|
| 107 |
$app = JFactory::getApplication(); |
| 108 |
$input = $app->input; |
| 109 |
|
| 110 |
// check if the URI contains option=com_vikrentcar |
| 111 |
if ($input->get('option') == 'com_vikrentcar') |
| 112 |
{ |
| 113 |
// make sure we are not contacting the AJAX and POST end-points |
| 114 |
if (!wp_doing_ajax() && $pagenow != 'admin-post.php') |
| 115 |
{ |
| 116 |
/** |
| 117 |
* Include page in query string only if we are in the back-end, |
| 118 |
* because WordPress 5.5 seems to break the page loading in case |
| 119 |
* that argument has been included in query string. |
| 120 |
* |
| 121 |
* It is not needed to include this argument in the front-end |
| 122 |
* as the page should lean on the reached shortcode only. |
| 123 |
* |
| 124 |
* @since 1.0.8 |
| 125 |
*/ |
| 126 |
if ($app->isAdmin()) |
| 127 |
{ |
| 128 |
// inject page=vikrentcar in GET superglobal |
| 129 |
$input->get->set('page', 'vikrentcar'); |
| 130 |
} |
| 131 |
} |
| 132 |
else |
| 133 |
{ |
| 134 |
// inject action=vikrentcar in GET superglobal for AJAX and POST requests |
| 135 |
$input->get->set('action', 'vikrentcar'); |
| 136 |
} |
| 137 |
} |
| 138 |
elseif ($input->get('page') == 'vikrentcar' || $input->get('action') == 'vikrentcar') |
| 139 |
{ |
| 140 |
// inject option=com_vikrentcar in GET superglobal |
| 141 |
$input->get->set('option', 'com_vikrentcar'); |
| 142 |
} |
| 143 |
}); |
| 144 |
|
| 145 |
// process the request and obtain the response |
| 146 |
add_action('init', function() |
| 147 |
{ |
| 148 |
/** |
| 149 |
* Language files should no longer be loaded during 'plugins_loaded'. |
| 150 |
* |
| 151 |
* @since 1.4.4 |
| 152 |
*/ |
| 153 |
VikRentCarBuilder::loadLanguage(); |
| 154 |
|
| 155 |
$app = JFactory::getApplication(); |
| 156 |
$input = $app->input; |
| 157 |
|
| 158 |
// if we are in the front-end, try to parse the URL to inject |
| 159 |
// option, view and args in the input request |
| 160 |
if ($app->isSite() && VIKRENTCAR_SITE_PREPROCESS) |
| 161 |
{ |
| 162 |
// get post ID from current URL |
| 163 |
$id = url_to_postid(JUri::current()); |
| 164 |
|
| 165 |
if ($id) |
| 166 |
{ |
| 167 |
// get shortcode admin model |
| 168 |
$model = JModel::getInstance('vikrentcar', 'shortcode', 'admin'); |
| 169 |
// get shortcode searching by post ID (false to avoid returning a new item) |
| 170 |
$shortcode = $model->getItem(array('post_id' => $id), false); |
| 171 |
|
| 172 |
if ($shortcode) |
| 173 |
{ |
| 174 |
// build args array using the shortcode attributes |
| 175 |
$args = (array) json_decode($shortcode->json, true); |
| 176 |
$args['view'] = $shortcode->type; |
| 177 |
$args['option'] = 'com_vikrentcar'; |
| 178 |
|
| 179 |
// inject the shortcode args into the input request |
| 180 |
foreach ($args as $k => $v) |
| 181 |
{ |
| 182 |
// inject only if not defined |
| 183 |
$input->def($k, $v); |
| 184 |
} |
| 185 |
} |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
// process VikRentCar only if it has been requested via GET or POST |
| 190 |
if ($input->get('option') == 'com_vikrentcar' || $input->get('page') == 'vikrentcar') |
| 191 |
{ |
| 192 |
VikRentCarBody::process(); |
| 193 |
} |
| 194 |
}); |
| 195 |
|
| 196 |
// handle AJAX requests |
| 197 |
add_action('wp_ajax_vikrentcar', function() |
| 198 |
{ |
| 199 |
VikRentCarBody::getHtml(); |
| 200 |
|
| 201 |
// die to get a valid response |
| 202 |
wp_die(); |
| 203 |
}); |
| 204 |
|
| 205 |
// setup admin menu |
| 206 |
add_action('admin_menu', array('VikRentCarBuilder', 'setupAdminMenu')); |
| 207 |
|
| 208 |
// register widgets |
| 209 |
add_action('widgets_init', array('VikRentCarBuilder', 'setupWidgets')); |
| 210 |
|
| 211 |
// handle shortcodes (SITE controller dispatcher) |
| 212 |
add_shortcode('vikrentcar', function($atts, $content = null) |
| 213 |
{ |
| 214 |
// wrap attributes in a registry |
| 215 |
$args = new JObject($atts); |
| 216 |
|
| 217 |
// get the VIEW (empty if not set) |
| 218 |
$view = $args->get('view', ''); |
| 219 |
|
| 220 |
// load the FORM of the view |
| 221 |
JLoader::import('adapter.form.form'); |
| 222 |
$path = implode(DIRECTORY_SEPARATOR, array(VRC_SITE_PATH, 'views', $view, 'tmpl', 'default.xml')); |
| 223 |
// raises an exception if the VIEW is not set |
| 224 |
$form = JForm::getInstance($view, $path); |
| 225 |
|
| 226 |
// get all the XML form fields |
| 227 |
$fields = $form->getFields(); |
| 228 |
|
| 229 |
// filter the fields to get a list of allowed names |
| 230 |
$fields = array_map(function($f) |
| 231 |
{ |
| 232 |
return (string) $f->attributes()->name; |
| 233 |
}, $fields); |
| 234 |
|
| 235 |
// inject query vars |
| 236 |
$input = JFactory::getApplication()->input; |
| 237 |
// since we are going to render the controller manually, |
| 238 |
// we don't need to push the option into $_REQUEST pool. |
| 239 |
// $input->set('option', 'com_vikrentcar'); |
| 240 |
|
| 241 |
// Inject shortcode vars only if they are not set |
| 242 |
// in the request. This is used to allow the navigation |
| 243 |
// between the pages. |
| 244 |
$input->def('view', $view); |
| 245 |
|
| 246 |
foreach ($fields as $k) |
| 247 |
{ |
| 248 |
$input->def($k, $args->get($k)); |
| 249 |
} |
| 250 |
|
| 251 |
// dispatch the controller |
| 252 |
return VikRentCarBody::getHtml(true); |
| 253 |
}); |
| 254 |
|
| 255 |
// the callback is fired before the VRC controller is dispatched |
| 256 |
add_action('vikrentcar_before_dispatch', function() |
| 257 |
{ |
| 258 |
$app = JFactory::getApplication(); |
| 259 |
$user = Jfactory::getUser(); |
| 260 |
|
| 261 |
// initialize timezone handler |
| 262 |
JDate::getDefaultTimezone(); |
| 263 |
date_default_timezone_set($app->get('offset', 'UTC')); |
| 264 |
|
| 265 |
// check if the user is authorised to access the back-end (only if the client is 'admin') |
| 266 |
if ($app->isAdmin() && !$user->authorise('core.manage', 'com_vikrentcar')) |
| 267 |
{ |
| 268 |
if ($user->guest) |
| 269 |
{ |
| 270 |
// if the user is not logged, redirect to login page |
| 271 |
$app->redirect('index.php'); |
| 272 |
exit; |
| 273 |
} |
| 274 |
else |
| 275 |
{ |
| 276 |
// otherwise raise an exception |
| 277 |
wp_die( |
| 278 |
'<h1>' . JText::translate('FATAL_ERROR') . '</h1>' . |
| 279 |
'<p>' . JText::translate('RESOURCE_AUTH_ERROR') . '</p>', |
| 280 |
403 |
| 281 |
); |
| 282 |
} |
| 283 |
} |
| 284 |
|
| 285 |
// main library |
| 286 |
require_once VRC_SITE_PATH . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'lib.vikrentcar.php'; |
| 287 |
|
| 288 |
if ($app->isAdmin()) |
| 289 |
{ |
| 290 |
require_once VRC_ADMIN_PATH . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'vikrentcar.php'; |
| 291 |
require_once VRC_ADMIN_PATH . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'jv_helper.php'; |
| 292 |
|
| 293 |
/** |
| 294 |
* License expiration check is required for routine actions and it only involves Pro plugin users. |
| 295 |
* |
| 296 |
* @since 1.4.6 |
| 297 |
*/ |
| 298 |
if (!wp_doing_ajax() && VikRentCarLicense::getKey() && VikRentCarLicense::isExpired()) |
| 299 |
{ |
| 300 |
// display a message |
| 301 |
$message = sprintf('Your Pro license has expired. Please <a href="%s">renew your license</a> to continue receiving updates and support.', 'admin.php?option=com_vikrentcar&view=gotopro'); |
| 302 |
$app->enqueueMessage($message, 'error'); |
| 303 |
} |
| 304 |
} |
| 305 |
else |
| 306 |
{ |
| 307 |
// Invoke needed methods before the rendering |
| 308 |
VikRentCar::detectUserAgent(); |
| 309 |
VikRentCar::getTracker(); |
| 310 |
VikRentCar::loadPreferredColorStyles(); |
| 311 |
} |
| 312 |
}); |
| 313 |
|
| 314 |
// instead using the default server timezone, try to use the one |
| 315 |
// specified within the WordPress configuration |
| 316 |
add_filter('vik_date_default_timezone', function($timezone) |
| 317 |
{ |
| 318 |
return JFactory::getApplication()->get('offset', $timezone); |
| 319 |
}); |
| 320 |
|
| 321 |
// the callback is fired once the VRC controller has been dispatched |
| 322 |
add_action('vikrentcar_after_dispatch', function() |
| 323 |
{ |
| 324 |
// load assets after dispatching the controller to avoid |
| 325 |
// including JS and CSS when an AJAX function exits or dies |
| 326 |
VikRentCarAssets::load(); |
| 327 |
|
| 328 |
/** |
| 329 |
* Load javascript core. |
| 330 |
*/ |
| 331 |
JHtml::fetch('behavior.core'); |
| 332 |
|
| 333 |
// restore standard timezone |
| 334 |
date_default_timezone_set(JDate::getDefaultTimezone()); |
| 335 |
|
| 336 |
/** |
| 337 |
* @note when the headers have been sent or when |
| 338 |
* the request is AJAX, the assets (CSS and JS) are |
| 339 |
* appended to the document after the |
| 340 |
* response dispatched by the controller. |
| 341 |
*/ |
| 342 |
}); |
| 343 |
|
| 344 |
// End-point for front-end post actions. |
| 345 |
// The end-point URL must be built as .../wp-admin/admin-post.php |
| 346 |
// and requires $_POST['action'] == 'vikrentcar' to be submitted through a form or GET. |
| 347 |
add_action('admin_post_vikrentcar', 'handle_vikrentcar_endpoint'); // if the user is logged in |
| 348 |
add_action('admin_post_nopriv_vikrentcar', 'handle_vikrentcar_endpoint'); // if the user in not logged in |
| 349 |
|
| 350 |
// handle POST end-point |
| 351 |
function handle_vikrentcar_endpoint() |
| 352 |
{ |
| 353 |
// get PLAIN response |
| 354 |
echo VikRentCarBody::getResponse(); |
| 355 |
} |
| 356 |
|
| 357 |
// Hook used to access the PAGE details when a user is |
| 358 |
// creating or updating it. This is helpful to make a relation |
| 359 |
// between the page and the injected shortcode. |
| 360 |
add_action('save_post', function($post_id) |
| 361 |
{ |
| 362 |
// get model to access all the existing shortcodes |
| 363 |
$model = JModel::getInstance('vikrentcar', 'shortcodes', 'admin'); |
| 364 |
$shortcodes = $model->all(array('id', 'shortcode', 'post_id')); |
| 365 |
|
| 366 |
// get post data |
| 367 |
$post = get_post($post_id); |
| 368 |
|
| 369 |
/** |
| 370 |
* Check if we are editing a child post as Gutenberg |
| 371 |
* seems to use always the inherit status, which |
| 372 |
* refers to a post parent. |
| 373 |
*/ |
| 374 |
if ($post->post_status != 'publish' && !empty($post->post_parent) && $post->post_parent != $post_id) |
| 375 |
{ |
| 376 |
// fallback to obtain parent post data |
| 377 |
$post = get_post($post->post_parent); |
| 378 |
|
| 379 |
/** |
| 380 |
* Use new post ID. |
| 381 |
* |
| 382 |
* @since 1.4.0 Fixed post ID property name. |
| 383 |
*/ |
| 384 |
$post_id = $post->ID; |
| 385 |
} |
| 386 |
|
| 387 |
if ($post->post_status != 'publish') |
| 388 |
{ |
| 389 |
// ignore drafts auto-save |
| 390 |
return; |
| 391 |
} |
| 392 |
|
| 393 |
// get shortcode model |
| 394 |
$shortcodeModel = JModel::getInstance('vikrentcar', 'shortcode', 'admin'); |
| 395 |
|
| 396 |
/** |
| 397 |
* Since we need unique post IDs, all the shortcodes |
| 398 |
* that are assigned to the specified $post_id should |
| 399 |
* be detached. |
| 400 |
*/ |
| 401 |
foreach ($shortcodes as $data) |
| 402 |
{ |
| 403 |
if ($data->post_id == $post_id) |
| 404 |
{ |
| 405 |
// The post is already assigned to a shortcode. |
| 406 |
// Unset it to avoid duplicated. |
| 407 |
$data->post_id = 0; |
| 408 |
$shortcodeModel->save($data); |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
// iterate the shortcodes |
| 413 |
foreach ($shortcodes as $data) |
| 414 |
{ |
| 415 |
// check if the content of the post contains the shortcode |
| 416 |
if (strpos($post->post_content, html_entity_decode($data->shortcode)) !== false) |
| 417 |
{ |
| 418 |
// inject the POST ID |
| 419 |
$data->post_id = $post_id; |
| 420 |
|
| 421 |
// update shortcode |
| 422 |
$shortcodeModel->save($data); |
| 423 |
|
| 424 |
// stop iterating |
| 425 |
return; |
| 426 |
} |
| 427 |
} |
| 428 |
}); |
| 429 |
|
| 430 |
// Hook used to unset temporarily the relationship |
| 431 |
// between the trashed post and the shortcode. |
| 432 |
add_action('trashed_post', function($post_id) |
| 433 |
{ |
| 434 |
// get shortcode model |
| 435 |
$model = JModel::getInstance('vikrentcar', 'shortcode', 'admin'); |
| 436 |
|
| 437 |
// get the shortcode attached to the trashed post ID |
| 438 |
$item = $model->getItem(array('post_id' => $post_id), false); |
| 439 |
|
| 440 |
// if the item exists, temporarily detach the relationship |
| 441 |
if ($item) |
| 442 |
{ |
| 443 |
$item->post_id = 0; |
| 444 |
$item->tmp_post_id = $post_id; |
| 445 |
|
| 446 |
$model->save($item); |
| 447 |
} |
| 448 |
}); |
| 449 |
|
| 450 |
// Hook used to restore permanently the relationship |
| 451 |
// between the untrashed post and the shortcode. |
| 452 |
add_action('untrashed_post', function($post_id) |
| 453 |
{ |
| 454 |
// get shortcode model |
| 455 |
$model = JModel::getInstance('vikrentcar', 'shortcode', 'admin'); |
| 456 |
|
| 457 |
// get the shortcode attached to the untrashed post ID |
| 458 |
$item = $model->getItem(array('tmp_post_id' => $post_id), false); |
| 459 |
|
| 460 |
// if the item exists, re-attach the relationship |
| 461 |
if ($item) |
| 462 |
{ |
| 463 |
$item->post_id = $post_id; |
| 464 |
$item->tmp_post_id = 0; |
| 465 |
|
| 466 |
$model->save($item); |
| 467 |
} |
| 468 |
}); |
| 469 |
|
| 470 |
// Hook used to temporarily detach the relationship |
| 471 |
// between the deleted post and the shortcode. |
| 472 |
add_action('deleted_post', function($post_id) |
| 473 |
{ |
| 474 |
// get shortcode model |
| 475 |
$model = JModel::getInstance('vikrentcar', 'shortcode', 'admin'); |
| 476 |
|
| 477 |
// get the shortcode attached to the trashed post ID |
| 478 |
$item = $model->getItem(array('tmp_post_id' => $post_id), false); |
| 479 |
|
| 480 |
// If no item found, the "trash" feature is probably disabled. |
| 481 |
// Try to take a look for a shortcode with an active relationship. |
| 482 |
if (!$item) |
| 483 |
{ |
| 484 |
$item = $model->getItem(array('post_id' => $post_id), false); |
| 485 |
} |
| 486 |
|
| 487 |
// if the item exists, permanently detach the relationship |
| 488 |
if ($item) |
| 489 |
{ |
| 490 |
$item->post_id = 0; |
| 491 |
$item->tmp_post_id = 0; |
| 492 |
|
| 493 |
$model->save($item); |
| 494 |
} |
| 495 |
}); |
| 496 |
|
| 497 |
if (JFactory::getApplication()->isAdmin() && !wp_doing_ajax()) |
| 498 |
{ |
| 499 |
/** |
| 500 |
* @todo should we restrict these filters to the post managements pages only? |
| 501 |
*/ |
| 502 |
|
| 503 |
VikRentCarLoader::import('system.mce'); |
| 504 |
|
| 505 |
// add new buttons |
| 506 |
add_filter('mce_buttons', array('VikRentCarTinyMCE', 'addShortcodesButton')); |
| 507 |
|
| 508 |
// load the button handlers |
| 509 |
add_filter('mce_external_plugins', array('VikRentCarTinyMCE', 'registerShortcodesScript')); |
| 510 |
} |
| 511 |
|
| 512 |
/** |
| 513 |
* Always load the Gutenberg shortcodes block to support the preview rendering. |
| 514 |
* |
| 515 |
* @since 1.4 |
| 516 |
*/ |
| 517 |
VikRentCarLoader::import('system.gutenberg'); |
| 518 |
add_action('init', ['VikRentCarGutenberg', 'registerShortcodesScript']); |
| 519 |
|
| 520 |
/** |
| 521 |
* Dispatch the uninstallation of VikRentCar |
| 522 |
* every time a new blog (multisite) is deleted. |
| 523 |
* |
| 524 |
* Fires after the site is deleted from the network (WP 4.8.0 or higher). |
| 525 |
* |
| 526 |
* @param integer $blog_id The site ID. |
| 527 |
* @param boolean $drop True if site's tables should be dropped. Default is false. |
| 528 |
*/ |
| 529 |
add_action('deleted_blog', function($blog_id, $drop) |
| 530 |
{ |
| 531 |
VikRentCarInstaller::uninstall($drop); |
| 532 |
}, 10, 2); |
| 533 |
|
| 534 |
/** |
| 535 |
* Once the plugins have been loaded, evaluates to execute the |
| 536 |
* scheduled cron jobs. |
| 537 |
* |
| 538 |
* Scheduling is processed in case a cron job is hitting wp-cron file |
| 539 |
* or in case a user is visiting the website. |
| 540 |
* |
| 541 |
* @since 1.3.0 Schedules a different hook for each cron. |
| 542 |
*/ |
| 543 |
add_action('plugins_loaded', array('VikRentCarCron', 'setup'), PHP_INT_MAX); |
| 544 |
|
| 545 |
/** |
| 546 |
* Filters the action links displayed for each plugin in the Plugins list table. |
| 547 |
* Hook used to filter the "deactivation" link and ask a feedback every time that |
| 548 |
* button is clicked. |
| 549 |
* |
| 550 |
* @param array $actions An array of plugin action links. By default this can include 'activate', |
| 551 |
* 'deactivate', and 'delete'. With Multisite active this can also include |
| 552 |
* 'network_active' and 'network_only' items. |
| 553 |
* @param string $plugin_file Path to the plugin file relative to the plugins directory. |
| 554 |
* @param array $plugin_data An array of plugin data. See `get_plugin_data()`. |
| 555 |
* @param string $context The plugin context. By default this can include 'all', 'active', 'inactive', |
| 556 |
* 'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'. |
| 557 |
*/ |
| 558 |
add_filter('plugin_action_links', array('VikRentCarFeedback', 'deactivate'), 10, 4); |
| 559 |
|
| 560 |
/** |
| 561 |
* Adjusts the timezone of the website before dispatching |
| 562 |
* a widget as we are currently outside of the main plugin and |
| 563 |
* the timezone have probably been restored to the default one. |
| 564 |
* |
| 565 |
* @param string $id The widget ID (path name). |
| 566 |
* @param JObject &$params The widget configuration registry. |
| 567 |
*/ |
| 568 |
add_action('vik_widget_before_dispatch_site', function($id, &$params) |
| 569 |
{ |
| 570 |
// initialize timezone handler |
| 571 |
JDate::getDefaultTimezone(); |
| 572 |
date_default_timezone_set(JFactory::getApplication()->get('offset', 'UTC')); |
| 573 |
}, 10, 2); |
| 574 |
|
| 575 |
/** |
| 576 |
* Restores the timezone of the website after dispatching |
| 577 |
* a widget in order to avoid strange behaviors with other plugins. |
| 578 |
* |
| 579 |
* @param string $id The widget ID (path name). |
| 580 |
* @param string &$html The HTML of the widget to display. |
| 581 |
*/ |
| 582 |
add_action('vik_widget_after_dispatch_site', function($id, &$html) |
| 583 |
{ |
| 584 |
// restore standard timezone |
| 585 |
date_default_timezone_set(JDate::getDefaultTimezone()); |
| 586 |
}, 10, 2); |
| 587 |
|
| 588 |
/** |
| 589 |
* Added support for Loco Translate. |
| 590 |
* In case some translations have been edited by using this plugin, |
| 591 |
* we should look within the Loco Translate folder to check whether |
| 592 |
* the requested translation is available. |
| 593 |
* |
| 594 |
* @param boolean $loaded True if the translation has been already loaded. |
| 595 |
* @param string $domain The plugin text domain to load. |
| 596 |
* |
| 597 |
* @return boolean True if a new translation is loaded. |
| 598 |
* |
| 599 |
* @since 1.3.2 |
| 600 |
*/ |
| 601 |
add_filter('vik_plugin_load_language', function($loaded, $domain) |
| 602 |
{ |
| 603 |
// proceed only in case the translation hasn't been loaded |
| 604 |
// and Loco Translate plugin is installed |
| 605 |
if (!$loaded && is_dir(WP_LANG_DIR . DIRECTORY_SEPARATOR . 'loco')) |
| 606 |
{ |
| 607 |
// Build LOCO path. |
| 608 |
// Since load_plugin_textdomain accepts only relative paths, |
| 609 |
// we should go back to the /wp-contents/ folder first. |
| 610 |
$loco = implode(DIRECTORY_SEPARATOR, array('..', 'languages', 'loco', 'plugins')); |
| 611 |
|
| 612 |
// try to load the plugin translation from Loco folder |
| 613 |
$loaded = load_plugin_textdomain($domain, false, $loco); |
| 614 |
} |
| 615 |
|
| 616 |
return $loaded; |
| 617 |
}, 10, 2); |
| 618 |
|
| 619 |
/** |
| 620 |
* Prevent WordPress Themes from running wptexturize() that may erroneously |
| 621 |
* detect HTML tags among raw JavaScript code, by encoding ampersand symbols. |
| 622 |
* |
| 623 |
* @since 1.6.9 |
| 624 |
*/ |
| 625 |
add_filter('run_wptexturize', function($run_texturize) |
| 626 |
{ |
| 627 |
return is_admin() ? $run_texturize : false; |
| 628 |
}, PHP_INT_MAX); |
| 629 |
|