Tengo un problema para que funcione mi solución php (check-url.php). El comportamiento extraño es que mi secuencia de comandos funciona bien siempre que conserve:
echo «prueba de uid»;
Pero, por supuesto, no quiero que mi sitio reproduzca este tipo de texto de depuración. El problema es que en el momento en que comento este eco, el script deja de funcionar.
Ya no repetirá el script de abajo, pero tampoco produce ningún error. No sé qué está pasando (creo que tiene algo que ver con ob_start()), así que espero que alguien pueda ayudarme con esto.
Creo que tiene algo que ver con ob_start().
He cargado algunos scripts php personalizados en el archivo function.php de mi tema secundario, como puede ver en los fragmentos de código a continuación.
funciones.php:
add_action( 'wp_enqueue_scripts', 'add_popup_handle_url_id' );
function add_popup_handle_url_id() {
require_once('check-url.php');
}
comprobar-url.php:
<?
ob_start();
global $wpdb;
$dushidushiImage = "someimage.jpg";
$dushidushiTitle = "Certificate of Authenticity";
$dushidushiText = "Congratulations!<br />This one appears to be real!";
$urlId = "";
//URL RETREIVAL
if (isset($_GET['uid']))
{
echo "uid test";
$urlId = $wpdb->escape($_GET['uid']);
$result = $wpdb->get_results("SELECT media FROM wp_dushidushi_items WHERE dushidushi_id = '". $urlId ."'");
if ($wpdb->num_rows > 0)
{
$media = $result[0]->media;
if (!empty($media))
{
header('Location:'. $media);
ob_end_flush();
}
}
else
{
$dushidushiImage = "anotherimage.jpg";
$dushidushiTitle = "Fake one!";
$dushidushiText = "Sorry. this one seems to be fake.";
}
} else {
// Fallback behaviour goes here
}
$popupScript = "<script>
var popupHtml = `
<div class="popup" id="popup">
<img src="{$dushidushiImage}" />
<p class="dushidushinumber">#{$urlId}</p>
<h2>{$dushidushi}</h2>
<br />
<br />
<p>{$dushidushiText}</p>
<button type="button" onclick="closePopup()">Close</button>
</div>
`
// Your CSS as text
var styles = `
.popup {
width: 400px;
background: #fff;
border-radius: 6px;
position: fixed;
top: 0;
left: 50%;
transform: translate(50%, 50%) scale(0.1);
text-align: center;
padding: 0 30px 30px;
color: #333;
visibility: hidden;
transition: transform 0.4s, top 0.4s;
z-index: 99 !important;
}
.open-popup {
visibility: visible;
top: 50%;
transform: translate(-50%, -50%) scale(1);
}
.popup img {
width: 100px;
margin-top: -50px;
border-radius: 50%;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}
.popup h2 {
font-size: 38px;
font-weight: 500;
margin: 30px 0 10px;
font: 900 32px/44px Roboto;
}
.popup p {
font: 780 18px/1.8em Roboto;
color: #4f4f4f;
}
.popup button {
width: 100%;
margin-top: 50px;
padding: 10px 0;
background: #6fd649;
color: #fff;
border: 0;
outline: none;
font-size: 18px;
border-radius: 4px;
cursor: pointer;
box-shadow: 0 5px 5px rgba(0, 0, 0, 0.2);
}
.htmlpopupbackground {
background-color: rgba(0,0,0,0.75);
}
.kukudushinumber {
font: 500 10px/1.0em Roboto;
font-weight: bold;
}
`
//Append popupHtml to body element
document.body.innerHTML += popupHtml;
//Create style node and append css to it
var styleSheet = document.createElement("style")
styleSheet.innerText = styles
document.head.appendChild(styleSheet)
let popup = document.getElementById("popup");
function openPopup(){
popup.classList.add("open-popup");
}
function closePopup(){
popup.classList.remove("open-popup");
}
openPopup();
</script>";
echo $popupScript;
ob_end_flush();
?>
.