Iterating over every multisite / theme and list the pages

due to Rick Hellewells comment I could write a code, which iterates over every blog (as a blog is a new mulitiste site) and outputs it’s site on plugin activation.

See this link: https://wisdmlabs.com/blog/how-to-list-posts-from-all-blogs-on-wordpress-multisite/

As every site has it’s own theme, the $temp variable can hold the wp_get_theme command (you could also extract the site’s name with it’s path and the explode() command), also note, that I would recommend to put the restore_current_blog() command outside of the foreach loop, so it won’t execute this command on every iteration as mentioned in the link above:

function pages_of_multisite_on_activation() {
global $path;

// loop through all blogs
$blog_ids = get_sites();

foreach ($blog_ids as $current_blog) {
    // switch to each blog to get the posts
    $blog_id = $current_blog->blog_id;

    switch_to_blog($blog_id);

    $theme = wp_get_theme();
    $temp = $theme-> template;

    // fetch all the posts
    $getPages = get_pages();

    $filename = $path . $temp . "ending.json";

    write_page_ids($getPages, $filename);

}

restore_current_blog();

}

register_activation_hook( __FILE__, 'pages_of_multisite_on_activation' );