Пример #1
0
function idp_test_input($data)
{
    if (!is_array($data)) {
        $data = trim($data);
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
    } else {
        $tmp = [];
        foreach ($data as $key => $value) {
            $tmp[$key] = idp_test_input($value);
        }
        $data = $tmp;
    }
    return $data;
}
/*
Template Name: Buildingdetailsform
*/
wp_enqueue_style('toggle', get_template_directory_uri() . '/css/bootstrap-toggle.min.css');
wp_enqueue_script('toggle', get_template_directory_uri() . '/js/bootstrap-toggle.min.js');
$updated = false;
$error = false;
$not_found = false;
//if we have a $building (id), we can update it
$building_id = intval(htmlspecialchars(get_query_var('buildingid', 0)));
//form data is present
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if (isset($_POST['building_nonce']) && wp_verify_nonce($_POST['building_nonce'], 'building')) {
        $formData = [];
        foreach ($_POST as $key => $value) {
            $formData[$key] = idp_test_input($value);
        }
        $building_id = Idp_Main::saveBuildingDetails($building_id, $formData);
        if ($building_id != '0') {
            $updated = true;
        } else {
            $error = true;
        }
    }
}
$categories = Idp_Main::getAttributeCategories();
$building_description = "";
$user_id = get_current_user_id();
//try to get building, if it exists
if ($building_id != '0') {
    $building = Idp_Main::getBuildingBasicInfos($building_id);