I'm trying to store and admin page into a variable and sending back to an AJAX request. My code is the following, considering I'm in a class:
add_action('wp_ajax_get_dashboard', array('$this', 'get_dashboard'));
public function get_dashboard() {
//generate the admin home page /wp-admin/index.php
ob_start();
include admin_url('index.php');
$generate_index = ob_get_contents();
ob_end_clean();
wp_send_json( $generate_index );
}
The problem is that I get the login screen as output. I'm working in a plugin enviroment. Any suggestion?
I'm trying to store and admin page into a variable and sending back to an AJAX request. My code is the following, considering I'm in a class:
add_action('wp_ajax_get_dashboard', array('$this', 'get_dashboard'));
public function get_dashboard() {
//generate the admin home page /wp-admin/index.php
ob_start();
include admin_url('index.php');
$generate_index = ob_get_contents();
ob_end_clean();
wp_send_json( $generate_index );
}
The problem is that I get the login screen as output. I'm working in a plugin enviroment. Any suggestion?
Share Improve this question edited Nov 10, 2018 at 19:46 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Nov 10, 2018 at 18:50 middleladymiddlelady 5531 gold badge6 silver badges18 bronze badges1 Answer
Reset to default 0In case something like this would ever need to somebody, I solved pinging the page with an AJAX request
$.ajax({
url: 'your_url_to_ping',
beforeSend: function(xhr) {
//something
}
}).done(function(data) {
//something else with your data
});
The page would be into your response data
.