All FAQ
prefix . 'afaq_6310_faq';
$category_table = $wpdb->prefix . 'afaq_6310_category';
wp_enqueue_media();
if (!empty($_POST['duplicate']) && isset($_POST['id']) && is_numeric($_POST['id'])) {
$nonce = $_REQUEST['_wpnonce'];
if (!wp_verify_nonce($nonce, 'afaq_nonce_6310_field_duplicate')) {
die('You do not have sufficient permissions to access this page.');
} else {
$id = (int) $_POST['id'];
$selectedData = $wpdb->get_row($wpdb->prepare("SELECT * FROM $faq_table WHERE id = %d ", $id), ARRAY_A);
$dupList = array(
$selectedData['title'],
$selectedData['description'],
$selectedData['icons_name'],
$selectedData['link_text'],
$selectedData['link_url'],
$selectedData['new_tab'],
$selectedData['class_code']);
$s = $wpdb->query($wpdb->prepare("INSERT INTO {$faq_table} (title, description, icons_name, link_text, link_url, new_tab, class_code) VALUES ( %s, %s, %s, %s, %s, %s, %s )", $dupList));
}
}
if (!empty($_POST['delete']) && isset($_POST['id']) && is_numeric($_POST['id'])) {
$nonce = $_REQUEST['_wpnonce'];
if (!wp_verify_nonce($nonce, 'afaq-6310-nonce-field-delete')) {
die('You do not have sufficient permissions to access this page.');
} else {
$id = (int) sanitize_text_field($_POST['id']);
$wpdb->query($wpdb->prepare("DELETE FROM {$faq_table} WHERE id = %d", $id));
}
} else if (!empty($_POST['save']) && $_POST['save'] == 'Save') {
$nonce = $_REQUEST['_wpnonce'];
if (!wp_verify_nonce($nonce, 'afaq-6310-nonce-add')) {
die('You do not have sufficient permissions to access this page.');
} else {
$myData = array();
$myData[] = sanitize_text_field($_POST['title']);
$myData[] = ($_POST['description']);
$myData[] = sanitize_text_field($_POST['icons_name']);
$myData[] = sanitize_text_field($_POST['link_text']);
$myData[] = sanitize_text_field($_POST['link_url']);
$myData[] = isset($_POST['open_new_tab']) ? sanitize_text_field($_POST['open_new_tab']) : 0;
if(isset($_POST['class_code']) && count($_POST['class_code']) > 0){
$class_code = array_map('sanitize_text_field', $_POST['class_code']);
$myData[] = implode(',', $class_code);
}
else{
$myData[] = '';
}
$wpdb->query($wpdb->prepare("INSERT INTO {$faq_table} set
title = %s,
description = %s,
icons_name = %s,
link_text = %s,
link_url = %s,
new_tab = %s,
class_code = %s", $myData));
}
} else if (!empty($_POST['update']) && $_POST['update'] == 'Update') {
$nonce = $_REQUEST['_wpnonce'];
if (!wp_verify_nonce($nonce, 'afaq-6310-nonce-update')) {
die('You do not have sufficient permissions to access this page.');
} else {
$id = (int) sanitize_text_field($_POST['eid']);
$myData = array();
$myData[] = sanitize_text_field($_POST['title']);
$myData[] = ($_POST['description']);
$myData[] = sanitize_text_field($_POST['icons_name']);
$myData[] = sanitize_text_field($_POST['link_text']);
$myData[] = sanitize_text_field($_POST['link_url']);
$myData[] = isset($_POST['open_new_tab']) ? sanitize_text_field($_POST['open_new_tab']) : 0;
if(isset($_POST['class_code']) && count($_POST['class_code']) > 0){
$class_code = array_map('sanitize_text_field', $_POST['class_code']);
$myData[] = implode(',', $class_code);
}
else{
$myData[] = '';
}
$myData[] = $id;
$wpdb->query($wpdb->prepare("UPDATE {$faq_table} set
title = %s,
description = %s,
icons_name = %s,
link_text = %s,
link_url = %s,
new_tab = %s,
class_code = %s
where id = %d", $myData));
}
} else if (!empty($_POST['edit']) && $_POST['edit'] == 'Edit') {
$nonce = $_REQUEST['_wpnonce'];
if (!wp_verify_nonce($nonce, 'afaq-6310-nonce-field-edit')) {
die('You do not have sufficient permissions to access this page.');
} else {
$id = (int) sanitize_text_field( $_POST['id'] );
$faq = $wpdb->get_row($wpdb->prepare("SELECT * FROM $faq_table WHERE id = %d ", $id), ARRAY_A);
?>
| Title |
Description |
Icon |
Category |
Button Text |
Edit Delete |
get_results('SELECT * FROM ' . $faq_table . ' ORDER BY id DESC', ARRAY_A);
foreach ($data as $value) {
echo '';
echo '| ' . esc_attr(afaq_6310_scRemove($value['title'])) . ' | ';
echo '' . afaq_6310_scRemove(esc_attr(strip_tags($value['description']))) . ' | ';
echo '' . (esc_attr($value['icons_name']) ? "" : '---') . ' | ';
echo "";
$category = $wpdb->get_results('SELECT * FROM ' . $category_table . ' ORDER BY serial ASC', ARRAY_A);
if ($category) {
$class_code = esc_attr($value['class_code']) ? explode(',', esc_attr($value['class_code'])) : [];
foreach ($category as $cat) {
$index = ($class_code) ? array_search($cat['class_code'], $class_code) : -1;
if($index > -1){
echo " " . afaq_6310_scRemove($cat['name']) . " ";
}
}
}
else{
echo "---";
}
echo " | ";
echo '' . esc_attr(afaq_6310_scRemove($value['link_text'])) . ' | ';
echo '
| ';
}
?>