Unable to retrieve data from multiple Wordpress websites on same server

I am trying to retrieve data from multiple client Wordpress websites on a single php page. So I can monitor all these websites without going through each one.

I am able to display data from one single website. Like this, I am listing all plugin installed on one Wordpress.

?php
  require( './domain1/wp-blog-header.php' );
  if ( ! function_exists( 'get_plugins' ) ) {
    require_once ABSPATH . 'wp-admin/includes/plugin.php';
  }
  $plugins = get_plugins();
  echo 'h1 ' . get_bloginfo( 'name' ) . '/h1';
  foreach ( $plugins as $plugin ) {
    echo $plugin['Name'] . 'br /';
  }
?

This works fine as I want. But when I try to do this for multiple website, it does not work but shows data from first website multiple times.

?php
  $websites = array( 'domain1', 'domain2', 'domain3', 'domain4', 'domain5', 'domain6' );

  foreach ( $websites as $website ) {
    $file = './' . $website . '/wp-blog-header.php';
    require( $file );
    if ( ! function_exists( 'get_plugins' ) ) {
      require_once ABSPATH . 'wp-admin/includes/plugin.php';
    }
    $plugins = get_plugins();
    echo 'h1 ' . get_bloginfo( 'name' ) . '/h1';
    foreach ( $plugins as $plugin ) {
      echo $plugin['Name'] . 'br /';
    }
  }
?

Why it's only showing details from first domain only? What am I doing wrong? Can someone help me with this.

Thanks.

Topic get-plugin-data customization Wordpress

Category Web


Would you mind if I just leave bread crumbs so you can solve this pazzle ?

  1. add filter
  2. 'query' hook
  3. $wpdb->prefix & local wpdb prefix
  4. value somewhere in *_options table
  5. remove_filter
  6. show values

Once one wpdb instance declared... you can reach any table in it (beware I said table in one DB). But you can't do what you actually doing right now. YOU WILL GET a fatal error.

Other way is to parse wp-config.php of each site, make mysql connection, query everything, and show it... but that a lame-too-easy way....

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.