| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking |
| 4 |
* @subpackage mod_vikbooking_chat |
| 5 |
* @author E4J s.r.l |
| 6 |
* @copyright Copyright (C) 2026 E4J s.r.l. All rights reserved. |
| 7 |
* @license GNU General Public License version 2 or later; see LICENSE |
| 8 |
* @link https://vikwp.com |
| 9 |
*/ |
| 10 |
|
| 11 |
// No direct access |
| 12 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 13 |
|
| 14 |
jimport('adapter.module.widget'); |
| 15 |
|
| 16 |
/** |
| 17 |
* VikBooking Chat module implementation for WP. |
| 18 |
* |
| 19 |
* @see JWidget |
| 20 |
* @since 1.0 |
| 21 |
*/ |
| 22 |
class ModVikbookingChat_Widget extends JWidget |
| 23 |
{ |
| 24 |
/** |
| 25 |
* Class constructor. |
| 26 |
*/ |
| 27 |
public function __construct() |
| 28 |
{ |
| 29 |
// attach the absolute path of the module folder |
| 30 |
parent::__construct(dirname(__FILE__)); |
| 31 |
|
| 32 |
try |
| 33 |
{ |
| 34 |
// add support as block |
| 35 |
$this->registerBlockType( |
| 36 |
VIKBOOKING_ADMIN_ASSETS_URI, |
| 37 |
[ |
| 38 |
'icon' => 'format-chat', |
| 39 |
'keywords' => [ |
| 40 |
__('VikBooking', 'vikbooking'), |
| 41 |
__('Chat', 'vikbooking'), |
| 42 |
__('Widget'), |
| 43 |
], |
| 44 |
] |
| 45 |
); |
| 46 |
} |
| 47 |
catch (Throwable $error) |
| 48 |
{ |
| 49 |
// there's a conflict with an outdated plugin |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Sanitize widget form values as they are saved. |
| 55 |
* |
| 56 |
* @param array $new_instance Values just sent to be saved. |
| 57 |
* @param array $old_instance Previously saved values from database. |
| 58 |
* |
| 59 |
* @return array Updated safe values to be saved. |
| 60 |
*/ |
| 61 |
public function update($new_instance, $old_instance) |
| 62 |
{ |
| 63 |
$new_instance['title'] = !empty($new_instance['title']) ? strip_tags($new_instance['title']) : ''; |
| 64 |
|
| 65 |
return $new_instance; |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Front-end display of widget. |
| 70 |
* |
| 71 |
* @param array $args Widget arguments. |
| 72 |
* @param array $config Saved values from database. |
| 73 |
* |
| 74 |
* @return void |
| 75 |
*/ |
| 76 |
public function widget($args, $config) |
| 77 |
{ |
| 78 |
// define a callback to hide the title even if it was specified |
| 79 |
$hideTitle = fn($title) => ''; |
| 80 |
|
| 81 |
add_filter('widget_title', $hideTitle); |
| 82 |
parent::widget($args, $config); |
| 83 |
remove_filter('widget_title', $hideTitle); |
| 84 |
} |
| 85 |
} |
| 86 |
|