• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

GhazaliTajuddin.com

Another Kuantan Blogger

  • Home
  • Blog
    • Kuantan
    • Foods
    • Technology
    • Health
  • Stock Photography
    • Senarai Microstock Agency
    • Membuka akaun contributor Shutterstock.com
    • Tips untuk 10 keping gambar pertama Shutterstock.com
    • Mengapa Shutterstock.com reject gambar / submission
    • Model Release
    • Bagaimana withdraw earning daripada Fotolia
    • Bagaimana untuk mengisi keyword kepada imej dengan menggunakan Adobe Photoshop

REST

WordPress REST API Multisite

August 11, 2017 by ghazalitajuddin

I have been looking for a way to access multisite data trough WP API, but it seems very hard to find. One and only the best reference i get is from git the_glue but need some update since it not updated.

Below is my version or u can get form my git 

<?php
/*
* Plugin Name: WordPress REST API Multisite
* Plugin URI: 
* Description: 
* Version: 1.0
* Author: Ghazali Tajuddin
* Author URI: http://www.ghazalitajuddin.com
* License: MIT
* */


class WPMUrestAPI{

    function __construct() {
        add_action( 'rest_api_init', array( $this, 'call2' ));
    }
    

    public function call2() {
    // Here we are registering our route for a collection of products and creation of products.
    
        register_rest_route( 'all/sites', '/list', 
            array(
                
                // By using this constant we ensure that when the WP_REST_Server changes, our readable endpoints will work as intended.
                
                'methods'  => WP_REST_Server::READABLE,
                
                // Here we register our callback. The callback is fired when this endpoint is matched by the WP_REST_Server class.
                
                'callback' => array($this,'get_sites123'),
            )
         );
    }

   public function prefix_get_endpoint_phrase() {
        // rest_ensure_response() wraps the data we want to return into a WP_REST_Response, and ensures it will be properly returned.
        //return rest_ensure_response( 'Hello World, this is the WordPress REST API' );
        return 'Hello World, this is the WordPress REST API';
    }

    public function get_sites123() {
            
            if ( function_exists( 'get_sites' )  ) {
            $sites = get_sites( 
                [
                    'public'  => 1,
                    //'number'  => 500,
                    'orderby' => 'registered',
                    'order'   => 'DESC',
                ]
            );

            $sites_details = array();

            foreach ($sites as $site) {
                $sites_details[] = $site->blog_id;
            }

            return $sites_details;
 
    }
}

  

}


 $power = new WPMUrestAPI();

Other reference

  • https://github.com/epfl-lts2/json-rest-api-multisites
  • https://github.com/remkade/multisite-json-api
  • https://wordpress.org/support/topic/wp_get_sites-is-now-get_sites/

Filed Under: Technology Tagged With: json, multisite, REST, wordpress

Primary Sidebar

“Solat. Sabar. Syukur. Senyum. Sedekah.”

For Collaboration, Events & Review, kindly contact me at +6016[-]9212092 or click Whatsapp button on this page.

Sponsor

Recent Posts

BadMethodCallException Method Illuminate\Database\Eloquent\Collection::roles does not exist.

User Roles And Permissions Without Package Laravel 10

Laravel Many To Many Relationship

Makan malam bersama keluarga di Awangan Palace

Sarapan pagi di Warung Gulai Kawah

Recent Comments

  • helmi on Personal Tips Berhenti Merokok
  • ghazalitajuddin on Personal Tips Berhenti Merokok
  • helmi on Personal Tips Berhenti Merokok
  • ghazalitajuddin on Nasi Lemak Kukus Restoran Zaman. Otai masih berbisa.
  • ghazalitajuddin on Air tangki radiator Proton Exora cepat kering? Cuba tukar penutup radiator!
  • Mal on Nasi Lemak Kukus Restoran Zaman. Otai masih berbisa.
  • Firdaus on Air tangki radiator Proton Exora cepat kering? Cuba tukar penutup radiator!

My Link

  • Takaful Insurance Web

JJCM

Patin Tempoyak Frozen Resepi Temerloh

Makan malam bersama keluarga di Awangan Palace

Kopi Acah-acah Diet

Daging Bakar Daun Pisang Pekan

Roti Canai Pulau Gerai Mat Zam-Zam

Tags

bebas rokok berhenti merokok breakfast Controller Framework Gezzeg Photography & Design health jalan-jalan cari makan jalan-jalan cari makan kuantan jjcm jjcm kuantan Jurufoto Kuantan Kuantan Kuantan Photographer kuantan programmer kuantan web developer kuantan webmaster laravel merokok merbahayakan kesihatan model MVC nikmat rokok OOP Pahang Pahangtourism pahang tourism Photo Manipulation PHP rajalanun retired smoking revisit pahang 2018 shutterstock stop smoking stop smoking tips stop smoking withdrawal symptom tips tips berhenti merokok View visit malaysia 2020 visit pahang visitpahang white wordpress yii Yii Framework

Recent Posts

  • BadMethodCallException Method Illuminate\Database\Eloquent\Collection::roles does not exist.
  • User Roles And Permissions Without Package Laravel 10
  • Laravel Many To Many Relationship
  • Makan malam bersama keluarga di Awangan Palace
  • Sarapan pagi di Warung Gulai Kawah

Copyright © 2025 — Ghazali Tajuddin • All rights reserved. •