/// <summary> /// Defines WordPress configuration constants and initializes runtime before proceeding to <c>index.php</c>. /// </summary> static void Apply(Context ctx, WordPressConfig config, WpLoader loader) { // see wp-config.php: // The name of the database for WordPress ctx.DefineConstant("DB_NAME", (PhpValue)config.DbName); // define('DB_NAME', 'wordpress'); // MySQL database username ctx.DefineConstant("DB_USER", (PhpValue)config.DbUser); // define('DB_USER', 'root'); // MySQL database password ctx.DefineConstant("DB_PASSWORD", (PhpValue)config.DbPassword); // define('DB_PASSWORD', 'password'); // MySQL hostname ctx.DefineConstant("DB_HOST", (PhpValue)config.DbHost); // define('DB_HOST', 'localhost'); // WordPress Database Table prefix. ctx.Globals["table_prefix"] = (PhpValue)config.DbTablePrefix; // $table_prefix = 'wp_'; // SALT ctx.DefineConstant("AUTH_KEY", (PhpValue)config.SALT.AUTH_KEY); ctx.DefineConstant("SECURE_AUTH_KEY", (PhpValue)config.SALT.SECURE_AUTH_KEY); ctx.DefineConstant("LOGGED_IN_KEY", (PhpValue)config.SALT.LOGGED_IN_KEY); ctx.DefineConstant("NONCE_KEY", (PhpValue)config.SALT.NONCE_KEY); ctx.DefineConstant("AUTH_SALT", (PhpValue)config.SALT.AUTH_SALT); ctx.DefineConstant("SECURE_AUTH_SALT", (PhpValue)config.SALT.SECURE_AUTH_SALT); ctx.DefineConstant("LOGGED_IN_SALT", (PhpValue)config.SALT.LOGGED_IN_SALT); ctx.DefineConstant("NONCE_SALT", (PhpValue)config.SALT.NONCE_SALT); // disable wp_cron() during the request, we have our own scheduler to fire the job ctx.DefineConstant("DISABLE_WP_CRON", PhpValue.True); // define('DISABLE_WP_CRON', true); // $peachpie-wp-loader : WpLoader ctx.Globals["peachpie_wp_loader"] = PhpValue.FromClass(loader); }
/// <summary> /// Defines WordPress configuration constants and initializes runtime before proceeding to <c>index.php</c>. /// </summary> static void Apply(Context ctx, WordPressConfig config, WpLoader loader) { // see wp-config.php: // WordPress Database Table prefix. ctx.Globals["table_prefix"] = (PhpValue)config.DbTablePrefix; // $table_prefix = 'wp_'; // SALT ctx.DefineConstant("AUTH_KEY", (PhpValue)config.SALT.AUTH_KEY); ctx.DefineConstant("SECURE_AUTH_KEY", (PhpValue)config.SALT.SECURE_AUTH_KEY); ctx.DefineConstant("LOGGED_IN_KEY", (PhpValue)config.SALT.LOGGED_IN_KEY); ctx.DefineConstant("NONCE_KEY", (PhpValue)config.SALT.NONCE_KEY); ctx.DefineConstant("AUTH_SALT", (PhpValue)config.SALT.AUTH_SALT); ctx.DefineConstant("SECURE_AUTH_SALT", (PhpValue)config.SALT.SECURE_AUTH_SALT); ctx.DefineConstant("LOGGED_IN_SALT", (PhpValue)config.SALT.LOGGED_IN_SALT); ctx.DefineConstant("NONCE_SALT", (PhpValue)config.SALT.NONCE_SALT); // Additional constants if (config.Constants != null) { foreach (var pair in config.Constants) { ctx.DefineConstant(pair.Key, pair.Value); } } // disable wp_cron() during the request, we have our own scheduler to fire the job ctx.DefineConstant("DISABLE_WP_CRON", PhpValue.True); // define('DISABLE_WP_CRON', true); // $peachpie-wp-loader : WpLoader ctx.Globals["peachpie_wp_loader"] = PhpValue.FromClass(loader); }
/// <summary> /// Installs WordPress middleware. /// </summary> /// <param name="app">The application builder.</param> /// <param name="config">WordPress instance configuration.</param> /// <param name="path">Physical location of wordpress folder. Can be absolute or relative to the current directory.</param> public static IApplicationBuilder UseWordPress(this IApplicationBuilder app, WordPressConfig config, string path = "wordpress") { // wordpress root path: var root = System.IO.Path.GetFullPath(path); var fprovider = new PhysicalFileProvider(root); var cachepolicy = new WpResponseCachingPolicyProvider(); var cachekey = new WpResponseCachingKeyProvider(); // response caching: app.UseMiddleware <ResponseCachingMiddleware>(cachepolicy, cachekey); // url rewriting: app.UseRewriter(new RewriteOptions().Add(context => ShortUrlRule(context, fprovider))); // handling php files: app.UsePhp(new PhpRequestOptions() { ScriptAssembliesName = WordPressAssemblyName.ArrayConcat(config.LegacyPluginAssemblies), BeforeRequest = ctx => Apply(ctx, config, cachepolicy), RootPath = root, }); // static files app.UseStaticFiles(new StaticFileOptions() { FileProvider = fprovider }); return(app); }
/// <summary> /// Installs WordPress middleware. /// </summary> /// <param name="app">The application builder.</param> /// <param name="config">WordPress instance configuration.</param> /// <param name="plugins">Container describing what plugins will be loaded.</param> /// <param name="path">Physical location of wordpress folder. Can be absolute or relative to the current directory.</param> public static IApplicationBuilder UseWordPress(this IApplicationBuilder app, WordPressConfig config = null, WpPluginContainer plugins = null, string path = "wordpress") { // wordpress root path: var root = System.IO.Path.GetFullPath(path); var fprovider = new PhysicalFileProvider(root); // plugins & configuration plugins = new WpPluginContainer(plugins); if (config == null) { config = WpConfigurationLoader .CreateDefault() .LoadFromSettings(app.ApplicationServices); } config.LoadFromEnvironment(app.ApplicationServices); // response caching: if (config.EnableResponseCaching) { var cachepolicy = new WpResponseCachingPolicyProvider(); var cachekey = new WpResponseCachingKeyProvider(); plugins.Add(cachepolicy); app.UseMiddleware <ResponseCachingMiddleware>(cachepolicy, cachekey); } var wploader = new WpLoader(CompositionHelpers.GetPlugins(app.ApplicationServices).Concat(plugins.GetPlugins(app.ApplicationServices))); // url rewriting: app.UseRewriter(new RewriteOptions().Add(context => ShortUrlRule(context, fprovider))); // log exceptions: app.UseDiagnostic(); // handling php files: app.UsePhp(new PhpRequestOptions() { ScriptAssembliesName = WordPressAssemblyName.ArrayConcat(config.LegacyPluginAssemblies), BeforeRequest = ctx => Apply(ctx, config, wploader), RootPath = root, }); // static files app.UseStaticFiles(new StaticFileOptions() { FileProvider = fprovider }); // fire wp-cron.php asynchronously if (TryGetWpCronUri(app.ServerFeatures.Get <IServerAddressesFeature>(), out var wpcronUri)) { WpCronScheduler.StartScheduler(HttpMethods.Post, wpcronUri, TimeSpan.FromSeconds(60)); } // return(app); }
/// <summary> /// Defines WordPress configuration constants and initializes runtime before proceeding to <c>index.php</c>. /// </summary> static void Apply(Context ctx, WordPressConfig config, params IWpPlugin[] plugins) { // see wp-config.php: // The name of the database for WordPress ctx.DefineConstant("DB_NAME", (PhpValue)config.DbName); // define('DB_NAME', 'wordpress'); // MySQL database username ctx.DefineConstant("DB_USER", (PhpValue)config.DbUser); // define('DB_USER', 'root'); // MySQL database password ctx.DefineConstant("DB_PASSWORD", (PhpValue)config.DbPassword); // define('DB_PASSWORD', 'password'); // MySQL hostname ctx.DefineConstant("DB_HOST", (PhpValue)config.DbHost); // define('DB_HOST', 'localhost'); // $peachpie-wp-loader : WpLoader ctx.Globals["peachpie_wp_loader"] = PhpValue.FromClass(new WpLoader(plugins.ConcatSafe(config.Plugins))); }
/// <summary> /// Installs WordPress middleware. /// </summary> /// <param name="app">The application builder.</param> /// <param name="config">WordPress instance configuration.</param> /// <param name="path">Physical location of wordpress folder. Can be absolute or relative to the current directory.</param> public static IApplicationBuilder UseWordPress(this IApplicationBuilder app, WordPressConfig config, string path = "wordpress") { // wordpress root path: var root = System.IO.Path.GetFullPath(path); var fprovider = new PhysicalFileProvider(root); var cachepolicy = new WpResponseCachingPolicyProvider(); var cachekey = new WpResponseCachingKeyProvider(); // response caching: if (config.EnableResponseCaching) { app.UseMiddleware <ResponseCachingMiddleware>(cachepolicy, cachekey); } // url rewriting: app.UseRewriter(new RewriteOptions().Add(context => ShortUrlRule(context, fprovider))); // handling php files: app.UsePhp(new PhpRequestOptions() { ScriptAssembliesName = WordPressAssemblyName.ArrayConcat(config.LegacyPluginAssemblies), BeforeRequest = ctx => Apply(ctx, config, cachepolicy), RootPath = root, }); // static files app.UseStaticFiles(new StaticFileOptions() { FileProvider = fprovider }); // fire wp-cron.php asynchronously if (TryGetWpCronUri(app.ServerFeatures.Get <IServerAddressesFeature>(), out var wpcronUri)) { WpCronScheduler.StartScheduler(HttpMethods.Post, wpcronUri, TimeSpan.FromSeconds(60)); } // return(app); }
/// <summary> /// Defines WordPress configuration constants and initializes runtime before proceeding to <c>index.php</c>. /// </summary> static void Apply(Context ctx, WordPressConfig config, params IWpPlugin[] plugins) { // see wp-config.php: // The name of the database for WordPress ctx.DefineConstant("DB_NAME", (PhpValue)config.DbName); // define('DB_NAME', 'wordpress'); // MySQL database username ctx.DefineConstant("DB_USER", (PhpValue)config.DbUser); // define('DB_USER', 'root'); // MySQL database password ctx.DefineConstant("DB_PASSWORD", (PhpValue)config.DbPassword); // define('DB_PASSWORD', 'password'); // MySQL hostname ctx.DefineConstant("DB_HOST", (PhpValue)config.DbHost); // define('DB_HOST', 'localhost'); // disable wp_cron() during the request, we have our own scheduler to fire the job ctx.DefineConstant("DISABLE_WP_CRON", PhpValue.True); // define('DISABLE_WP_CRON', true); // $peachpie-wp-loader : WpLoader ctx.Globals["peachpie_wp_loader"] = PhpValue.FromClass(new WpLoader(plugins.ConcatSafe(config.Plugins))); }
/// <summary> /// Installs WordPress middleware. /// </summary> /// <param name="app">The application builder.</param> /// <param name="config">WordPress instance configuration.</param> /// <param name="plugins">Container describing what plugins will be loaded.</param> /// <param name="path">Physical location of wordpress folder. Can be absolute or relative to the current directory.</param> public static IApplicationBuilder UseWordPress(this IApplicationBuilder app, WordPressConfig config = null, WpPluginContainer plugins = null, string path = null) { // wordpress root path: if (path == null) { // bin/wordpress path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "/wordpress"; if (Directory.Exists(path) == false) { // cwd/wordpress path = Path.GetDirectoryName(Directory.GetCurrentDirectory()) + "/wordpress"; if (Directory.Exists(path) == false) { // cwd/../wordpress path = Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())) + "/wordpress"; } } } var root = System.IO.Path.GetFullPath(path); var fprovider = new PhysicalFileProvider(root); // plugins & configuration plugins = new WpPluginContainer(plugins); if (config == null) { config = WpConfigurationLoader .CreateDefault() .LoadFromSettings(app.ApplicationServices); } config.LoadFromEnvironment(app.ApplicationServices); // response caching: if (config.EnableResponseCaching) { var cachepolicy = new WpResponseCachingPolicyProvider(); var cachekey = new WpResponseCachingKeyProvider(); plugins.Add(cachepolicy); app.UseMiddleware <ResponseCachingMiddleware>(cachepolicy, cachekey); } // update globals WpStandard.DB_HOST = config.DbHost; WpStandard.DB_NAME = config.DbName; WpStandard.DB_PASSWORD = config.DbPassword; WpStandard.DB_USER = config.DbUser; // var env = (IHostingEnvironment)app.ApplicationServices.GetService(typeof(IHostingEnvironment)); WpStandard.WP_DEBUG = config.Debug || env.IsDevelopment(); var wploader = new WpLoader(CompositionHelpers.GetPlugins(app.ApplicationServices).Concat(plugins.GetPlugins(app.ApplicationServices))); // url rewriting: app.UseRewriter(new RewriteOptions().Add(context => ShortUrlRule(context, fprovider))); // log exceptions: app.UseDiagnostic(); // handling php files: app.UsePhp(new PhpRequestOptions() { ScriptAssembliesName = WordPressAssemblyName.ArrayConcat(config.LegacyPluginAssemblies), BeforeRequest = ctx => Apply(ctx, config, wploader), RootPath = root, }); // static files app.UseStaticFiles(new StaticFileOptions() { FileProvider = fprovider }); // fire wp-cron.php asynchronously if (TryGetWpCronUri(app.ServerFeatures.Get <IServerAddressesFeature>(), out var wpcronUri)) { WpCronScheduler.StartScheduler(HttpMethods.Post, wpcronUri, TimeSpan.FromSeconds(60)); } // return(app); }