Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Why do you call wp-load.php? That shouldn’t be necessary. –  toscho Jul 29 '12 at 20:33
    
toscho - how do I get access to WP functions from my own PHP file otherwise? –  OS. Jul 29 '12 at 20:53
    
Register an address and get the WP environment for free. :) –  toscho Jul 29 '12 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 '12 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 '12 at 21:10
show 5 more comments

1 Answer 1

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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