Integrating WordPress into SharePoint

The title here may be slightly misleading. The majority of this post will be applicable to any .NET application integrating with WordPress – however my experiences were derived from creating the WordPress functionality within the Career Centre portal. The requirements were for an extract of the latest post to appear on the front page and for any relevant categories to be presented on the Career Connect page. The featured article functionality was initially intended to come from WordPress but ended up being list-driven as there was no obvious way to mark the WordPress blog as a feature (In hindsight I may have created a ‘Feature’ category in WordPress and use the API to bring it back that way, but as it stands it’s relatively static).

This actually turned out a little more challenging than I was expecting. There appeared to be a lot of information in regards to WordPress APIs as it related to plugin development, but the information I was searching for wasn’t as obvious to find. I eventually found out that WordPress supports both the Atom Publishing Protocol (AtomPub) and XML-RPC for client development and that currently WordPress provides more features and capabilities via XML-RPC than AtomPub. XML-RPC seemed the way to go.

This snippet of information actually made life a lot easier. Turns out that the information WordPress provides on this subject is actually pretty useful. Firstly there’s the XML-RPC Support page which identified that 3 APIs were supported; Blogger, metaWeblog and Movable Type. There’s also an extension to the Movable Type API specific for WordPress (conveniently called the WordPress API) that should be used as a first resort if possible. That API is pretty well documented too on the XML-RPC wp page.

It seemed pretty promising – getCategories? Perfect. There didn’t seem to be an obvious way to get the latest blog post though from this API so the search continued. Reading through the alternate API’s metaWeblog seemed the easiest to use and appeared to have the functionality I needed. Unfortunately I found it to be pretty poorly documented – it seemed that no one wanted to make this task easy! I did stumble across one page; Eric’s WordPress XML-RPC – MetaWeblog API. Without this page I think I would have had a much harder time getting everything to work – getRecentPosts? Perfect.

The only thing left to do was to code it up in .NET. Turns out there’s an excellent library for this purpose by Charles Cook called XML-RPC.NET. The download includes the DLL you’ll need to reference (CookComputing.XmlRpcV2.dll) and a bunch of examples to get you started.

Time to pull out a few code snippets. Firstly you need to create an interface with the functions you intend to call:

public interface IStateName : IXmlRpcProxy
{
    [XmlRpcMethod("wp.getUsersBlogs")]
    Blog[] GetUsersBlogs(string username, string password);

    [XmlRpcMethod("metaWeblog.getRecentPosts")]
    BlogEntry[] GetPosts(int blog_id, string username, string password, int numberOfPosts);

    [XmlRpcMethod("wp.getCategories")]
    Category[] GetCategories(int blog_id, string username, string password);
}

The arrays are public structures with the properties you’re wanting to pull back – note that casing is important for the properties – make sure it matches the documentation exactly. Next is the code to retrieve the most recent post, and then all the blog categories:

IStateName proxy = XmlRpcProxyGen.Create<IStateName>();
proxy.Url = XMLRPCUrl;

BlogEntry[] blogEntries = null;
BlogEntry blogEntry = new BlogEntry();
Blog[] blogs = proxy.GetUsersBlogs(Username, Password);
if (blogs.Length > 0)
{
    Blog blog = blogs.FirstOrDefault(s => s.blogName == BlogName);

    if (blog.blogid != null)
    {
        blogEntries = proxy.GetPosts(int.Parse(blog.blogid), Username, Password, 1);
        blogEntry = blogEntries[0];
    }
}

 

IStateName proxy = XmlRpcProxyGen.Create<IStateName>();
proxy.Url = XMLRPCUrl;

Category[] categories = null;
Blog[] blogs = proxy.GetUsersBlogs(Username, Password);
if (blogs.Length > 0)
{
    Blog blog = blogs.FirstOrDefault(s => s.blogName == BlogName);

    if (blog.blogid != null)
    {
        categories = proxy.GetCategories(int.Parse(blog.blogid), Username, Password);
    }
}

The XMLRPCUrl is your wordpress address /xmlrpc.php (ie https://spmatt.wordpress.com/xmlrpc.php), the BlogName is the name of your blog (ie SPMatt) and your Username and Password is pretty self explanatory – use the account you use to author/administer your blog (I believe some of the actions you’re able to perform are dependant on the credentials of the account you use – using the administrator account is obviously the bad practice / guaranteed success way of getting it working).

That’s pretty much it. There’s one last potential gotchya and that’s to do with organisational proxies on your SharePoint servers. If the server requires a proxy to access the internet then there’s a fair chance you’re going to end up getting an error page like this (click to expand):

What’s required is to find the proxy line in your web.config and change it to the following:

<system.net>
  <defaultProxy>
    <proxy proxyaddress="http://your-proxy-address:port" bypassonlocal="true" />
  </defaultProxy>
</system.net>

And that should be it! You’re good to go. Pretty basic integration I know, but for most public facing sites this is all you’ll ever need. Dig in to the APIs and see the true power you can get interacting with WordPress through the APIs (anyone feeling like authoring blogs in SharePoint and publishing them to WordPress and vice-versa?).

One last point I should mention – I’ve yet to link in this blog to a man who seems to be a bit of a guru in this stuff – at least it seems that way from the research I did. His name is Joseph Scott and you can view a slidedeck of a presentation on the WordPress APIs here. If you’re scouring the net for decent advice I’d suggest looking out for his name would be a good start.

Advertisements

7 Responses to Integrating WordPress into SharePoint

  1. Bill says:

    Hi Matt,

    I have more of a question related to the title of your post than a comment on its content. I hope it not overly presumptuous of me to invite you to indulge me with a few minutes of your time and expertise.

    I administer a small natural health care clinic in St. Paul, MN, USA where among many other things, I am building out a WordPress based CMS site. Recently, I have been looking at MS 365 plans as well. I am only semi technical i.e. coding is a stretch.

    Eventually, after building out the public content of my site, I anticipate putting patient health records on line as a way of serving our patients better. Of course, this will require tight security. I’m thinking about how to do this.

    Here are my questions:

    Even though MS Office 365 includes SharePoint, it seems to me that, aside from the point that I’ve already started with it, WordPress is a superior app for me for my front end. Would you agree?

    What concerns me though, is whether it is the best app for me for building out my back end i.e. all the individual patient content. My sense is that anything can be done with SQL and Php but it would take significant coding skills to use these tools to do what I have in mind.

    Do you think SharePoint would be a better tool for the back end?

    Keeping practical considerations in mind, i.e. it would already be included with my Office 365 contract, would SharePoint also be a superior option to other alternatives that you are aware of existing out there?

    If not, is there a better one that you would recommend I look at?

    If your answer to all these questions is yes, can you offer a description of whether WordPress and SharePoint can be integrated and what that might look like?

    I realize that these are big questions, forgive me if you thing too big but thanks in advance for considering them! WordPress and SharePoint seem to exist in different worlds. I’m not aware of other people with experience and interest in both. If you know of another resource that I should check out for additional insights into these questions, please bring it to my attention.

    • Matt says:

      Hey Bill

      I would be happy to help, although aside from using wordpress as a blogging engine and some minor integration work my experience with it is limited.

      I’d also suggest that I have a natural bias towards SharePoint so I wouldn’t necessarily agree that WordPress is far superior for your front end 🙂

      Perhaps have a read of Bil Simser’s post of a comparison between the 2: http://bit.ly/bJgCvh

      My lack of WordPress knowledge aside, it would seem your security requirements would fall neatly onto the SharePoint side of the fence, and i’d struggle to reason why you’d want to use 2 different systems for your site when 1 would suffice.

      I can’t recommend any other systems as i’ve been dealing solely with SharePoint for the past few years and haven’t a lot of experience with other content management systems. I believe Bil has a number of posts comparing SharePoint to other CMS’ which may also warrant a read in your case.

      Integrating WordPress and SharePoint takes a lot of development effort, whereas the development effort required to brand a SharePoint site would be far less and easier to achieve as a power user using SharePoint Designer. The content editing features of SharePoint are also quite user friendly in the 2010 version of the product and while they may not seem as simple as using WordPress, the learning curve is not significant.

      I realise I haven’t really given you a definitive answer but hopefully i’ve at least given you a couple of points to consider. Sounds like a big project you’re undertaking and as you say security would be paramount and should be the first consideration before factoring in the suitability of the product from a front-end perspective.

      If you have any further questions or want me to clarify anything feel free to fire away.

      Cheers

  2. Bill says:

    Matt,

    Thanks for your reply! I didn’t know you made one since I was expecting to see it in my inbox but it never arrived. I finally decided to hunt down this post again to confirm and voila’, same day response. Let me now offer my apologies for not having thanked you earlier.

    To respond to your query regarding why WordPress for the front end?

    I already have time and effort invested in a partially built out WordPress site and related skills.

    The reason I chose WordPress in the first place is that it came so highly recommended from so many different places. The places I had exposure to never even mentioned Sharepoint. Even now that I have become aware of Sharepoint, it seems MicroSoft itself promotes it much more for intranet than internet use.

    Allow me to educate myself more by rereading your reply and looking over your links before taking any more of your time.

    Thanks again! I may be back later.

    Bill

  3. Glenn Brown says:

    Hi Matt,

    I realise this is quite an old post, but I was hoping that you’d be able to help me. I work for a school and help support our SharePoint 2010 intranet, and would like to be able to bring updates from our wordpress blog into our intranet similar to what you’ve done with the Career Site.

    I have only the very minimal experience with Visual Studio and would struggle to try to develop something from scratch.

    Do you have any advice or tips that you could provide to how I might do it now? Have you found an easier way of achieving it?

    Any assistance you could provide would most appreciated.

    Thanks,

    Glenn.

    • Matt says:

      Hey Glenn. I haven’t had to look into WordPress integration since this piece of work so am not sure whether there would be an easier way to do it, however the Career Centre parts are still working fine so the method outlined on this page should still be good to go. I’m fairly sure that any integration you desire would require custom development so that may be hard to avoid – if you’re finding it hard to get the components outlined on this page working then if you leave a comment with your email address i’ll send you through the completed classes which may make life a bit easier for you – you’ll still need to know how to create the SharePoint solution, add the web part and deploy it to your site however (there’s plenty of information on the web which should lead you in the right direction here). Hopefully with that it won’t be too difficult to get working on your site.

      • Glenn Brown says:

        Hi Matt,

        Thanks, if you’re willing to send me the classes then that would be fantastic. I’m sure I can nut out the rest.

        (email address removed)

        Thanks mate,

        Glenn.

  4. Christy says:

    Hello,
    I think you have the only article written about how to integrate WP postings into sharepoint. I work for non-profit educational group and our marketing team has switched to WP for news however they still want news to dynamically update on multiple sharepoint pages for our internet site. Do you still have the information your sent Glenn Brown in April? I’ve done a few webparts and such I’m not an expert in coding these things out. Thank you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: