I tried to use <?php echo get_the_ID(); ?>
instead of {post.id}
However, using this breaks my page and all elements do not keep their layout, also buttons disappears.
Do you have an idea how to fix this?
I made it that way, because i am using generateblocks plugin to make query loop, and my query loop is in Custom Type Post.
I forgot to mention that my query loop only creates elements on the page but I can’t go further into the posts, I mean that it creates elements on the page where the reservation buttons are.
HTML:
<button class="reserve-button"
data-post-id="{post.id}"
data-user-id="{current_user.id}"
data-reserved="{post_meta._reserved_by ? 'true' : 'false'}">
Zarezerwuj
</button>
<div class="reservation-info" style="display: none;">
Zarezerwowane przez: <span class="reserved-by"></span>
</div>
AJAX:
function handle_reservation() {
$user_id = get_current_user_id();
$post_id = intval($_POST['post_id']);
if (!$user_id) {
wp_send_json_error(['message' => 'Musisz by? zalogowany, aby rezerwowa?.']);
}
$current_reservation = get_post_meta($post_id, '_reserved_by', true);
$reserved_until = get_post_meta($post_id, '_reserved_until', true);
if ($current_reservation && time() < $reserved_until) {
wp_send_json_error([
'message' => 'Post ju? zarezerwowany do ' . date('Y-m-d H:i:s', $reserved_until),
'reserved_by' => get_userdata($current_reservation)->user_login
]);
}
update_post_meta($post_id, '_reserved_by', $user_id);
update_post_meta($post_id, '_reserved_until', time() + 48 * 60 * 60);
wp_send_json_success([
'message' => 'Post zarezerwowany.',
'reserved_by' => get_userdata($user_id)->user_login
]);
}
add_action('wp_ajax_reserve_post', 'handle_reservation');
function check_reservation_status() {
$post_id = intval($_POST['post_id']);
$reservation = get_post_meta($post_id, '_reserved_by', true);
$reserved_until = get_post_meta($post_id, '_reserved_until', true);
if ($reservation && time() < $reserved_until) {
wp_send_json_success([
'reserved' => true,
'reserved_by' => get_userdata($reservation)->user_login,
'time_left' => $reserved_until - time()
]);
} else {
wp_send_json_success(['reserved' => false]);
}
}
add_action('wp_ajax_check_reservation_status', 'check_reservation_status');
function enqueue_reserve_post_script() {
wp_enqueue_script('reserve-post-js', get_template_directory_uri() . '/js/reserve-post.js', ['jquery'], null, true);
wp_localize_script('reserve-post-js', 'wp_vars', [
'ajax_url' => admin_url('admin-ajax.php'),
'user_id' => get_current_user_id()
]);
}
add_action('wp_enqueue_scripts', 'enqueue_reserve_post_script');
JS:
document.addEventListener('DOMContentLoaded', function() {
const buttons = document.querySelectorAll('.reserve-button');
buttons.forEach(function(button) {
button.style.backgroundColor = "green";
button.style.color = "white";
button.style.border = "none";
button.style.padding = "10px 20px";
button.style.fontSize = "16px";
button.textContent = "Zarezerwuj";
const postId = button.getAttribute('data-post-id');
const userId = wp_vars.user_id;
const reservationInfo = button.nextElementSibling;
const reservedByElement = reservationInfo.querySelector('.reserved-by');
checkReservation(postId, button, reservationInfo, reservedByElement);
button.addEventListener('click', function() {
reservePost(postId, userId, button, reservationInfo, reservedByElement);
});
button.addEventListener('mouseenter', function() {
if (!button.disabled) {
button.style.backgroundColor = "white";
button.style.color = "orange";
button.style.border = "2px solid orange";
button.textContent = "ZAREZERWUJ";
}
});
button.addEventListener('mouseleave', function() {
if (!button.disabled) {
button.style.backgroundColor = "green";
button.style.color = "white";
button.style.border = "none";
button.textContent = "Zarezerwuj";
}
});
});
});
function checkReservation(postId, button, reservationInfo, reservedByElement) {
jQuery.ajax({
url: wp_vars.ajax_url,
type: 'POST',
data: {
action: 'check_reservation_status',
post_id: postId
},
success: function(response) {
if (response.success && response.data.reserved) {
const { time_left, reserved_by } = response.data;
button.textContent = Zarezerwowane na ${formatTime(time_left)}
;
button.style.backgroundColor = "orange";
button.style.color = "white";
button.disabled = true;
startCountdown(button, time_left);
reservedByElement.textContent = reserved_by;
reservationInfo.style.display = "block";
}
},
error: function() {
console.error('B??d podczas sprawdzania rezerwacji.');
}
});
}
function reservePost(postId, userId, button, reservationInfo, reservedByElement) {
jQuery.ajax({
url: wp_vars.ajax_url,
type: 'POST',
data: {
action: 'reserve_post',
post_id: postId,
user_id: userId
},
success: function(response) {
if (response.success) {
const time_left = 48 * 60 * 60;
button.textContent = Zarezerwowane na ${formatTime(time_left)}
;
button.style.backgroundColor = "orange";
button.style.color = "white";
button.disabled = true;
startCountdown(button, time_left);
reservedByElement.textContent = response.data.reserved_by;
reservationInfo.style.display = "block";
} else {
alert('Nie uda?o si? zarezerwowa?: ' + response.data.message);
}
},
error: function() {
alert('B??d podczas rezerwacji.');
}
});
}
function formatTime(seconds) {
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor((seconds % 3600) / 60);
return ${hours}h ${pad(minutes)}m
;
}
function pad(num) {
return num < 10 ? '0' + num : num;
}
function startCountdown(button, remainingTime) {
const countdownInterval = setInterval(() => {
remainingTime -= 1;
if (remainingTime <= 0) {
clearInterval(countdownInterval);
button.textContent = "Zarezerwuj ponownie";
button.style.backgroundColor = "green";
button.style.color = "white";
button.disabled = false;
} else {
button.textContent = Zarezerwowane na ${formatTime(remainingTime)}
;
}
}, 1000);
}
]]>/wp-content/plugins/ninja-forms/assets/js/*
/wp-content/plugins/ninja-forms/assets/*
/wp-content/plugins/ninja-forms/assets/js/lib/*
/wp-content/plugins/ninja-forms/config-wrap-start-default.js
/wp-content/plugins/ninja-forms/assets/js/nfLocaleConverter.js
/wp-content/plugins/ninja-forms/assets/js/min/*.js
/wp-content/plugins/ninja-forms/assets/js/min/controllers/*.js
/wp-content/plugins/ninja-forms/assets/js/min/models/*.js
/wp-content/plugins/ninja-forms/assets/js/min/views/*.js
I’m writing a Java web app that calls the WordPress APIs and I’m having trouble parsing through the _links item JSON response. Am I reading this right? Juding from the response below, the _links object holds an array of strings called “collection” and an array of strings called “self”?
“_links”:{“collection”:[{“href”:”https:\/\/ipaddress.com\/index.php?rest_route=\/wp\/v2\/widget-types”}],”self”:[{“href”:”https:\/\/ipaddress.com\/index.php?rest_route=\/wp\/v2\/widget-types\/block”}]}}
]]>sometimes when I open my WooCommerce store, the screen briefly turns black for a split second. Please check this video for review. Do you know what can cause it and how to solve it? It also seems that it happens only on desktops.
If you suggest things like “check it with the twenty-three” theme: if I deactivate my current theme and go to the twenty-three theme, is there a risk that all the customizations (CSS, etc.) will be lost or my website will be damaged after turning back to my current theme?
Best regards
]]>Then, I deactivated all those features. Now both the message and the extra fields have finally disappeared on the desktop version, but they are still on the mobile. I cleared the cache on the site and mobile browser and they are still there.
Any suggestions to fix this issue? Thank you!
]]>JS Minify: ON
JS Combine: On
JS Combine External and Inline: OFF
Load JS Deferred: Deferred
In the Tuning Tab, Js exclude, only 2 are mentionned:
jquery.js
jquery.min.js
On Divi, any setting related to Javascript is turned off.
This are the Java lines that are unused:
If anyone has a suggestion to turn this off, I would be thankful.
]]><?php
echo '<form><input type="button" value="< Torna alla lista" onClick="javascript:history.go(-1)"></form>','<form><a href="#my_map_123"><input type="button" class="listino" value="Listino" ></a></form>' ;
After I put a second button with an anchor to the same page, the first button doesnt work well, If I use the second button, than I have to click 2 times on the first button to go back to the previous page. So, what I need is a code, in java or php, so that when I click to “go to the previois page” I’ll land in the parent category page
]]><script type="application/javascript"> var UC_UI_SUPPRESS_CMP_DISPLAY=true;</script>
…insert on only two pages, not on all pages:
https://bootcenter.com/impressum/
https://bootcenter.com/datenschutzerklaerung/
Is this possible? Thank you very much.
]]>I have a problem: I want to embed a tweet in my article. I do this by copying the HTML code generated from the “Embed Tweet” feature on the Twitter Publish website. An example of the code is as follows:<blockquote class="twitter-tweet"><p lang="en" dir="ltr">The <a >@WWEUsos</a> are getting a head start for <a >#MITB</a> by taking down <a >@WWESoloSikoa</a> tonight on <a >#SmackDown</a>! 😤<a >#TheBloodline</a> CIVIL WAR. ☝ WEEK from TOMORROW. <br><br>The <a >@WWEUsos</a> vs. <a >@WWERomanReigns</a> and <a >@WWESoloSikoa</a>!<br><br>How will this war end? 😳 <a >pic.twitter.com/KN7M1I3UBU</a></p>— WWE (@WWE) <a >June 24, 2023</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
I paste this code into the HTML Editor, not the Visual Editor in WordPress, and it is supposed to display the tweet correctly when I go back to the Visual editor, view the draft, or publish the article. However, the tweet is not visible, only the text appears as a quote, using the blockquote format.
I have identified that the problem occurs when I publish the article or save it as a draft. The following part of the HTML code is automatically removed: <script async src=”https://platform.twitter.com/widgets.js” charset=”utf-8″></script>
This is a problem that only affects me. Other contributors from Mexico, Spain, the United States, etc., can embed tweets in this way without any issues.
I would like to know why this problem is occurring. I created a completely new account, but the problem persists. However, I asked another colleague from Mexico to try embedding the tweet, and they were successful. Could this be a problem specific to Colombia? I am the only contributor from Colombia.
I have also tested this in all available browsers, but it doesn’t work. I don’t know what else to do. I have always had problems when embedding HTML code, for example, from Streamable.
Thank you very much, and I will be attentive to any solutions or comments. It’s worth mentioning that installing plugins or modifying the website’s code is not possible for various reasons, and because I am the only one experiencing this problem.
Original-HTML-Code.jpg
HTML-Code-without-Java-Script.jpg
HTML-Code-without-Java-Script-2.jpg
HTML-Code-without-Java-Script-3.jpg