php – WordPress Multi-Site -Create Users programmatically-ThrowExceptions

Exception or error:

I want to programmatically create a blog with a user at the same time on my Word Press MultiSite by directly inserting data into the mySQl database.

WordPress Multi Site (Networking enabled) seems to be a similar question but I can’t seem to implement the solution provided there. Can anyone help with the basics of implementing this?

How to solve:

You should use wordpress multisite plugin here.You just have to make single method call for creating new blog with your new path in multi-site.Here below is an example that uses apache xml-rpc api

public class Demo
{
  public static void main(String[] args)
  {
    System.out.println("Starting adicXmlRpcServer test"); 

    XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); 
    try
    { 
      config.setServerURL(new URL("http://localhost/wordpress/xmlrpc.php")); 
    }
    catch (MalformedURLException ex) 
    { 
      System.out.println("Invalid url....."+ex.getMessage());
      ex.printStackTrace(); 
    } 

    XmlRpcClient client = new XmlRpcClient(); 
    client.setConfig(config); 
    Map map = new HashMap();
    map.put("domain","localhost");
    map.put("path","/newStrore");
    map.put("title","newStrore");
    map.put("user_id","akhi0gupta007@gmail.com");

    Object[] params = new Object[] {new String("admin"),new String("9868"),map}; 

    try 
    { 
      Object result = (Object) client.execute("ms.CreateBlog",params); 
      ArrayList<String> dirListing = new ArrayList<String>(); 
      System.out.println(result.toString());
    } 
    catch (XmlRpcException ex) 
    { 
      System.out.println("Invalid url....."+ex.getMessage());
      ex.printStackTrace(); 
    }
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *