$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>plugins - Store admin page into variable|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugins - Store admin page into variable

matteradmin8PV0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

In 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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far