🔗
feature_list(); ?>
__('Invalid security token or Insufficient permissions.', 'abp-transport-booking'), 'type' => 'warn'], 403);
}
ob_start();
$id = isset($_POST['id']) ? absint(wp_unslash($_POST['id'])) : '';
$options = ABPTB_Function::get_option('abptb_feature');
$options = is_array($options) ? $options : [];
$feature = $options[$id] ?? [];
$label = ABPTB_Function::feature_label();
$btn_label = __('Save', 'abp-transport-booking') . ' ' . $label;
$title = __('Add new ', 'abp-transport-booking') . ' ' . $label;
?>
$html, 'type' => 'success', 'msg' => $label . ' ' . __('Form Loaded Successfully .....! ', 'abp-transport-booking')]);
}
public function save_option_feature(): void {
if (!check_ajax_referer('abptb_admin_ajax_nonce', 'nonce', false) || !current_user_can('manage_options')) {
wp_send_json_error(['msg' => __('Invalid security token or Insufficient permissions.', 'abp-transport-booking'), 'type' => 'warn'], 403);
}
$post_int = fn($key, $default = 0) => isset($_POST[$key]) ? absint($_POST[$key]) : $default;
$post_array = fn($key) => (isset($_POST[$key]) && is_array($_POST[$key])) ? array_map('sanitize_text_field', wp_unslash($_POST[$key])) : [];
$old_features = ABPTB_Function::get_option('abptb_feature');
$old_features = is_array($old_features) ? $old_features : [];
$feature_ids = $post_array('feature_id');
$feature_names = $post_array('feature_name');
$feature_values = $post_array('feature_value');
$feature_icon = $post_array('feature_icon');
$post_id = $post_int('post_id');
if (!empty($feature_names)) {
foreach ($feature_names as $key => $feature_name) {
$feature_val = $feature_values[$key] ?? '';
if ($feature_name !== '') {
$old_id = isset($feature_ids[$key]) ? (int)$feature_ids[$key] : '';
if (!empty($old_id) && isset($old_features[$old_id])) {
$id = $old_id;
} else {
$id = 1;
while (isset($old_features[$id])) {
$id++;
}
}
$old_features[$id] = [
'label' => $feature_name,
'value' => $feature_val,
'icon' => $feature_icon[$key] ?? '',
];
}
}
}
update_option('abptb_feature', $old_features);
$html = '';
if (empty($post_id) || $post_id <= 0) {
ob_start();
$this->feature_list();
$html = ob_get_clean();
}
wp_send_json_success([
'html' => $html,
'msg' => __('Feature Saved Successfully..........!!', 'abp-transport-booking'),
'js' => self::get_feature_js($post_id),
]);
}
public function delete_option_feature(): void {
if (!check_ajax_referer('abptb_admin_ajax_nonce', 'nonce', false) || !current_user_can('manage_options')) {
wp_send_json_error(['msg' => __('Invalid security token or Insufficient permissions.', 'abp-transport-booking'), 'type' => 'warn'], 403);
}
$id = isset($_POST['id']) ? absint(wp_unslash($_POST['id'])) : 0;
$options = ABPTB_Function::get_option('abptb_feature');
$options = is_array($options) ? $options : [];
if (!empty($id) && isset($options[$id])) {
unset($options[$id]);
update_option('abptb_feature', $options);
}
ob_start();
$this->feature_list();
$html = ob_get_clean();
wp_send_json_success([
'html' => $html,
'msg' => ABPTB_Function::feature_label() . ' ' . __('Deleted Successfully!', 'abp-transport-booking'),
'type' => 'success'
]);
}
public function feature_list(): void {
$features = ABPTB_Function::get_option('abptb_feature');
//echo ''; print_r( $features ); echo '
';
if (sizeof($features) > 0) { ?>
$feature) {
$label = $feature['label'] ?? '';
$value = $feature['value'] ?? '';
if (!empty($label)) { ?>
0) {
$features = ABPTB_Function::get_option('abptb_feature');
$features = is_array($features) ? $features : [];
if (sizeof($features) > 0) {
foreach ($features as $key => $feature) {
$feature_js[] = ['id' => $key, 'icon' => ($feature['icon'] ?? ''), 'label' => ($feature['label'] ?? ''), 'value' => ($feature['value'] ?? '')];
}
}
}
return $feature_js;
}
public static function form_feature($feature = [], $id = ''): void {
$label = $feature['label'] ?? '';
$value = $feature['value'] ?? '';
$icon = $feature['icon'] ?? '';
?>
|
|
|
|