function gcb_import() { if (isset($_FILES["gcb_import_file"]["tmp_name"]) && strlen($_FILES["gcb_import_file"]["tmp_name"])) { $text = file_get_contents($_FILES["gcb_import_file"]["tmp_name"]); $entries1 = explode("\r\n", $text); $entries = array(); foreach ($entries1 as $e1) { $row = explode("<;>", $e1); $entries[] = array("name" => base64_decode($row[0]), "description" => base64_decode($row[1]), "value" => base64_decode($row[2]), "type" => base64_decode($row[3])); if (isset($row[4])) { $entries[count($entries) - 1]["custom_id"] = sanitize_title_with_dashes(base64_decode($row[4])); } else { $entries[count($entries) - 1]["custom_id"] = ""; } } foreach ($entries as $e) { gcb::add_entry($e); } return "Imported " . count($entries) . " blocks."; } else { return "Please Make sure you have a file uploaded."; } }
<?php require_once '../../../../../wp-load.php'; if (!isset($_POST["name"]) || !isset($_POST["content"])) { die("invalid call!"); } //check user rights, only editors and above can add if (!current_user_can('publish_pages')) { die("disallowed."); } $name = $_POST["name"]; $description = htmlspecialchars($_POST['description']); $type = htmlspecialchars($_POST['type']); $value = htmlspecialchars($_POST['content']); if (!strlen($name) || !strlen($value)) { die("invalid call."); } $available_types = gcb::get_available_types(); $entry_data = array("name" => $name, "description" => $description, "value" => $value, "type" => $type); $new_id = gcb::add_entry($entry_data); $return = array("id" => $new_id, "name" => $name, "img" => $available_types[$type]["img"]); echo json_encode($return); die;