iolevel / wpdotnet-sdk

WordPress compiled to .NET Standard. SDK for ASP.NET Core.
http://www.wpdotnet.com
Other
416 stars 71 forks source link
csharp dotnet dotnet-core dotnetcore peachpie peachpiecompiler php wordpress

All of WordPress as a .NET Standard assembly, without PHP.

.NET Core NuGet Downloads Stars

Chat with the community on Gitter if you need help:

How to add WordPress into your ASP.NET Core app

Use WordPress as ASP.NET Core Middleware.

  1. Add a package reference to Peachpied.WordPress.AspNetCore (Pre-Release)
  2. Add WordPress as middleware within your Configure startup method:
public class Startup
{
    public void Configure(IApplicationBuilder app)
    {
        // ...
        app.UseWordPress();
        // ...
    }
}

Configuration

appsettings.json

WordPress on .NET can be configured using the standard appsettings.json, you are no longer editing the wp-config.php source file.

{
  "WordPress": {
    "dbhost":        "localhost",
    "dbpassword":    "password",
    "dbuser":        "root",
    "dbname":        "wordpress",
    "dbTablePrefix": "wp_",
    "siteUrl":       "",
    "homeUrl":       "",
    "SALT": {
      "AUTH_KEY":         "r(EoMbKEvlg)",
      "AUTH_SALT":        "q0#AzvJ*[4~B",
      "LOGGED_IN_KEY":    "!AAienFSridC",
      "LOGGED_IN_SALT":   "C=(4(8WPMeRu",
      "NONCE_KEY":        "Z[e37@=y)m.C",
      "NONCE_SALT":       ";v7Wv/BV)Pz{",
      "SECURE_AUTH_KEY":  "pc}_Pv52,m=j",
      "SECURE_AUTH_SALT": "#n]+o^w/%-~M"
    },
    "constants": {
    }
  }
}

To generate your unique set of SALT, feel free to use Daniel Llewellyn's tool on https://wpdotnet-salts.azurewebsites.net/.

Note: WordPress expects the MySql database to be running, with the database dbname (wordpress by default) already created. Any of the configuration values can be omitted to use the default value.

ConfigureServices method

The service can be configured using AddWordPress configuration method. First argument is a callback providing options to be modified.

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddWordPress(options =>
        {
            options.DbHost = "localhost";
            options.DbName = "wordpress";
            // ...
        });
    }
}

The options object is already initialized with default values and with appsettings.json configuration.

Running this repo from the sources:

  1. Start mysql, at localhost:3306, user root, password password, created database wordpress
    • cmd: dotnet run -p app
    • vs: open solution and start app project
    • vscode: open folder and hit F5

WordPress on .NET SDK

The solution provides all of WordPress as a .NET standard assembly. Consisting of following projects:

This project contains the complete source code of WordPress with the additional "must use" WordPress plugin that exposes the PHP API to .NET. The purpose is for this code to be compiled by PeachPie, resulting in the output running purely on Microsoft .NET Core.

Therefore, if everything works as it should, you will see the standard unchanged WordPress in the same way as you would in the traditional PHP version. The difference is that the compiled website runs on .NET Core in the background. Also this approach allows to take advantage of ASP.NET Core request handling and makes it possible to extend WordPress with C# (i.e. plugins, themes, etc.).

Possible Use Cases

Prerequisites