1

I'm working on a multisite, everything is configured and works fine from dashboard. Now I'm trying to write a plugin with a PHP file that displays the list of pages created in a site - to be displayed to the admin of the site who logs in.

Here is the code (simplified)

<?php
require('../../../wp-load.php');
?>
(some HTML)
<?php    
    $pages = get_pages();                                  

    foreach ( $pages as $page ) {
        echo $page->post_title . '<br>'
?>

My plugin PHP file uses login_redirect filter to redirect user after login to that PHP file where I am trying to display the list of pages the user created:

function my_login_redirect( $redirect_to, $request ) { 
    return '/wp-content/plugins/my-admin-plugin/my-admin-view-all-pages.php'; 
}

THE PROBLEM - no matter which site I'm in, I get the list of pages created in the "main" site. How do I pass the context of the existing site to the functions?

9
  • Why do you call wp-load.php? That shouldn’t be necessary.
    – fuxia
    Jul 29, 2012 at 20:33
  • toscho - how do I get access to WP functions from my own PHP file otherwise?
    – OS.
    Jul 29, 2012 at 20:53
  • Register an address and get the WP environment for free. :)
    – fuxia
    Jul 29, 2012 at 20:54
  • @toscho just wondering ... is that the right link as the OP was asking about listing the pages in the current site
    – Damien
    Jul 29, 2012 at 21:08
  • @OS is this code what you are looking for? codex.wordpress.org/Function_Reference/wp_list_pages and you shouldn't be using wp-load.php
    – Damien
    Jul 29, 2012 at 21:10

1 Answer 1

0

The way you are doing this is not correct.

Two possibilities:

1) Create a Dashboard Widget to display the information

add_action('wp_dashboard_setup', 'wpse_60096_dashboard_widget');

function wpse_60096_dashboard_widget() {
    if( current_user_can( 'activate_plugins' ) )
        wp_add_dashboard_widget( 
            'wpse_60096', 
            'Site Pages', 
            'wpse_60096_add_widget_content'
        );
}

function wpse_60096_add_widget_content() {
    $pages = get_pages();                                  
    foreach ( $pages as $page ) 
        echo $page->post_title . '<br>'; 
}

2) Register an invisible submenu page

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.