javascript - XMLHttpRequest of admin data to public

admin2025-06-01  2

I have a function that get the data from a admin page and display the result at frontpage. But only works when admin user is logged in. How can I display the result even if user is not logged in?

Here the code in apoiadores.js

xhr.open("GET", "http://localhost/editora/wp-admin/edit.php?post_type=shop_order");

xhr.addEventListener("load", carregarapoiadores);
xhr.addEventListener("load", preco);    
xhr.send();`

and here the code in functions.php

function apoiadores () {
      wp_enqueue_script('apoiadores', get_template_directory_uri() . 
     '/chsv/js/apoiadores.js', array('jquery'), '', true);

} 
 add_action('wp_enqueue_scripts', 'apoiadores');


function prazo () {
 wp_enqueue_script('prazo', get_template_directory_uri() . 
  '/chsv/js/prazofinal.js', array('jquery'), '', true);

}
add_action('wp_enqueue_scripts', 'prazo');`

I have a function that get the data from a admin page and display the result at frontpage. But only works when admin user is logged in. How can I display the result even if user is not logged in?

Here the code in apoiadores.js

xhr.open("GET", "http://localhost/editora/wp-admin/edit.php?post_type=shop_order");

xhr.addEventListener("load", carregarapoiadores);
xhr.addEventListener("load", preco);    
xhr.send();`

and here the code in functions.php

function apoiadores () {
      wp_enqueue_script('apoiadores', get_template_directory_uri() . 
     '/chsv/js/apoiadores.js', array('jquery'), '', true);

} 
 add_action('wp_enqueue_scripts', 'apoiadores');


function prazo () {
 wp_enqueue_script('prazo', get_template_directory_uri() . 
  '/chsv/js/prazofinal.js', array('jquery'), '', true);

}
add_action('wp_enqueue_scripts', 'prazo');`
Share Improve this question edited Apr 3, 2019 at 19:50 Thages W. Almeida asked Apr 3, 2019 at 19:45 Thages W. AlmeidaThages W. Almeida 32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The short answer is "you can't do that." The WordPress admin content requires a user be logged in to view any of the content. If this were possible, anyone could get into the admin on your site.

You will have to make this content available from the front-end by another method.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748790732a313755.html

最新回复(0)