Für die Platte, die ich durch jede andere Zeit gesucht dies gefragt wurde, konnte aber nicht die Lösungwp_ajax_nopriv nicht abgemeldet Benutzer arbeiten
Ich versuche einfach Ajax-Inhalte zu einer Seite für abgemeldet Nutzer finden, hinzufügen und Fehler dispite mit wp_ajax_nopriv. Ich habe versucht, alle Plugins zu deaktivieren und das hat nicht geholfen. Obwohl ich den Zugriff auf den Backend-Admin nur für den Admin sperren möchte, habe ich das derzeit nicht implementiert.
Laden Sie das Skript
function html5blank_header_scripts()
{
if ($GLOBALS['pagenow'] != 'wp-login.php' && !is_admin()) {
wp_register_script('globalJs', get_template_directory_uri() . '/js/global.js', array('jquery'), '1.0.0'); // Custom scripts
wp_enqueue_script('globalJs'); // Enqueue it!
wp_localize_script(
'globalJs',
'ajax_object',
array('ajax_url' => admin_url('admin-ajax.php'), 'we_value' => 1234)
);
}
}
PHP Ajax-Funktion
add_action('wp_ajax_new_ajax_event_template', 'new_ajax_event_template');
add_action('wp_ajax_nopriv_new_ajax_event_template', 'new_ajax_event_template');
function new_ajax_event_template() {
global $post;
$postID = $_POST["post_id"];
$post = get_post($postID);
<------- lots of stuff that works for logged in user ----->
die();
}
JQuery Ajax-Skript
$(document).on("click", ".title[data-ajax='post']", function() {
$post_id = $(this).data("id");
$post_type = $(this).data("type");
$post_url = $(this).data("url");
var historyData = $(".wrapper").attr("data-history");
if (!historyData){
historyData = [];
}
else{
historyData = JSON.parse(historyData);
}
historyData.push({
id: $post_id,
type: $post_type,
url: $post_url
});
var data = {
action : 'new_ajax_'+ $post_type +'_template',
post_id : $post_id
};
$("#main").empty().hide();
$.ajax({
url : ajax_object.ajax_url,
type : 'post',
data : data,
success: function(html) {
$("#main").append(html);
history.pushState('data', '', $post_url);
$(".wrapper").attr("data-id", $post_id);
$(".wrapper").attr("data-history", JSON.stringify(historyData));
$("#main").fadeIn("fast");
}
});
});
Dies alles funktioniert ist perfekt für eingeloggte Benutzer, aber nicht für eingeloggte Benutzer und Ich habe keine Idee warum. Es gibt nichts in der functions.php, das dies verhindern sollte.