public void Configure(WpApp app) { // // Dashboard: // // add information into Right Now section app.DashboardRightNow(DashboardRightNow); // do not allow editing of .php files: app.AddFilter("editable_extensions", new Func <IList, IList>(editable_extensions => { editable_extensions.Remove("php"); return(editable_extensions); })); // // Blogs: // // alter generator metadata app.AddFilter("get_the_generator_xhtml", new Func <string>(() => GeneratorHtml)); // add analytics }
void IWpPlugin.Configure(WpApp app) { // postpone admin actions app.AddFilter("admin_init", new Action(() => { app.AddFilter("user_has_cap", new Func <PhpArray, PhpArray, PhpArray, PhpArray>((allcaps, cap, args) => { allcaps["update_core"] = false; allcaps["update_php"] = false; // return(allcaps); }), accepted_args: 3); app.AddFilter("pre_site_transient_update_core", new Func <stdClass>(() => { // TODO: wpdotnet check for version update return(new PhpArray() { { "last_checked", Pchp.Library.DateTime.DateTimeFunctions.time() }, { "version_checked", app.Context.Globals["wp_version"].ToString() }, }.ToObject()); }), accepted_args: 0); })); // ensure "plugins" directory exists, otherwise eventual mkdir() in wp fails if (app.Context.TryGetConstant("WP_PLUGIN_DIR", out var plugindir)) { try { Directory.CreateDirectory(plugindir.ToString(app.Context)); } catch { } } }
void IWpPlugin.Configure(WpApp app) { // postpone admin actions app.AddFilter("admin_init", new Action(() => { // plugins_api app.AddFilter("plugins_api", new Func <PhpValue, string, object, PhpValue>(PluginsApi), accepted_args: 3); app.AddFilter("themes_api", new Func <PhpValue, string, object, PhpValue>(ThemesApi), accepted_args: 3); app.AddFilter("delete_plugin", new Action <string>(DeletePlugin)); app.AddFilter("upgrader_source_selection", new Func <string, PhpValue>(InstallSourceSelection), priority: 0); app.AddFilter("activate_plugin", new Action <string>(plugin_file => _packages.ActivatePackage(PackagesHelper.PluginFileToPluginId(plugin_file)))); app.AddFilter("deactivate_plugin", new Action <string>(plugin_file => _packages.DeactivatePackage(PackagesHelper.PluginFileToPluginId(plugin_file)))); app.AddFilter("switch_theme", new Action <string, WP_Theme, WP_Theme>(SwitchTheme), accepted_args: 3); app.AddFilter("install_plugins_tabs", new Func <PhpArray, PhpArray>(tabs => // remove unsupported tabs { //tabs.Remove(new IntStringKey("upload")); tabs.Remove(new IntStringKey("popular")); tabs.Remove(new IntStringKey("recommended")); tabs.Remove(new IntStringKey("favorites")); tabs["recommended"] = "Premium"; return(tabs); })); // defined in PeachPied.WordPress.Sdk: // app.Context.DefineConstant("FS_METHOD", "direct"); // overwrite how installing plugins is handled, skips the fs check })); }
void IWpPlugin.Configure(WpApp app) { Action updated = () => { // existing cache records get invalidated LastPostUpdate = DateTime.UtcNow; }; app.AddFilter("save_post", updated); app.AddFilter("wp_insert_comment", updated); // edit_comment // trashed_comment(comment id, comment) // spammed_comment }
void IWpPlugin.Configure(WpApp app) { Action updated = () => { // existing cache records get invalidated LastPostUpdate = DateTime.UtcNow; }; app.AddFilter("save_post", updated); // post updated app.AddFilter("wp_insert_comment", updated); // comment added app.AddFilter("activate_plugin", updated); // plugin activated app.AddFilter("deactivate_plugin", updated); // plugin deactivated app.AddFilter("switch_theme", updated); // theme changed // TODO: edit_comment // TODO: trashed_comment(comment id, comment) // TODO: spammed_comment }
public void Configure(WpApp app) { // // Dashboard: // // add information into Right Now section app.DashboardRightNow(DashboardRightNow); // // Blogs: // // alter generator metadata app.AddFilter("get_the_generator_xhtml", new Func <string>(() => GeneratorHtml)); }
void AdminInit(WpApp app) { // plugins_api app.AddFilter("plugins_api", new Func <PhpValue, string, object, PhpValue>(PluginsApi), accepted_args: 3); app.AddFilter("delete_plugin", new Action <string>(DeletePlugin)); app.AddFilter("upgrader_source_selection", new Func <string, PhpValue>(InstallSourceSelection), priority: 0); app.AddFilter("activate_plugin", new Action <string>(plugin_file => _packages.ActivatePackage(PackagesHelper.PluginFileToPluginId(plugin_file)))); app.AddFilter("deactivate_plugin", new Action <string>(plugin_file => _packages.DeactivatePackage(PackagesHelper.PluginFileToPluginId(plugin_file)))); app.AddFilter("install_plugins_tabs", new Func <PhpArray, PhpArray>(tabs => // remove unsupported tabs { //tabs.Remove(new IntStringKey("upload")); tabs.Remove(new IntStringKey("popular")); tabs.Remove(new IntStringKey("recommended")); tabs.Remove(new IntStringKey("favorites")); tabs["recommended"] = "Premium"; return(tabs); })); app.Context.DefineConstant("FS_METHOD", "direct"); // overwrite how installing plugins is handled, skips the fs check }
void IWpPlugin.Configure(WpApp app) { // postpone admin actions app.AddFilter("admin_init", new Action(() => AdminInit(app))); }
void IWpPlugin.Configure(WpApp app) { if (app.Context.TryGetConstant("WPDOTNET_HOTPLUG_ENABLE", out var evalue) && (bool)evalue == false) { // docs/configuration/WPDOTNET_HOTPLUG_ENABLE // disable listing online plugins from dashboard app.OnAdminInit(() => { // plugins_api app.AddFilter("plugins_api", new Func <PhpValue, string, object, PhpValue>(EmptyApi), accepted_args: 3); app.AddFilter("themes_api", new Func <PhpValue, string, object, PhpValue>(EmptyApi), accepted_args: 3); }); return; } FirstRequest(); // delay the build action, // website is being just requested FoldersAction(f => f.PostponeBuild()); // wp hooks: app.OnAdminInit(() => { // render notices if there are compile time errors app.AdminNotices(() => CollectAdminNotices(app)); }); app.AdminMenu(() => { var hook = app.AddManagementPage("Code Problems", "Code Problems", "install_plugins", "list-problems", (output) => { var diagnostics = FoldersDiagnostic; var hasany = diagnostics.Any(); var maxseverity = hasany ? diagnostics.Max(d => d.Severity) : DiagnosticSeverity.Hidden; var overallicon = hasany ? IconHtml(maxseverity) : IconHtmlSuccess(); output.Write($@" <div style='margin:16px;'> <div><h1>Code Problems</h1></div> <div class='hide-if-no-js orange'> <div>{overallicon} {(maxseverity != 0 ? "Should be checked." : "No problems.")}</div> </div> </div>"); if (hasany) { output.Write("<div style='margin:24px;padding:8px;background:white;border:solid 1px #aaa;'>"); output.Write(CreateDiagnosticsTable(diagnostics, true)); output.Write("</div>"); } }, 4); //app.AddFilter($"load-{hook}", new Action(() => //{ // // //})); }); //// ajax hook to get the currently loaded assemblies version: //app.AddAjaxAction( // "hotplug_version", // () => (_pluginsCompiler.VersionLoaded.GetHashCode() ^ _themesCompiler.VersionLoaded.GetHashCode()).ToString("X")); //// TODO: add script to the footer that periodically checks ajax_hotplug_version for changes, //// in such case it refreshes the page // ... }
void IWpPlugin.Configure(WpApp app) { // postpone admin actions app.OnAdminInit(() => { // plugins_api app.AddFilter("plugins_api", new Func <PhpValue, string, object, PhpValue>(PluginsApi), accepted_args: 3); app.AddFilter("themes_api", new Func <PhpValue, string, object, PhpValue>(ThemesApi), accepted_args: 3); app.AddFilter("delete_plugin", new Action <string>(DeletePlugin)); app.AddFilter("upgrader_source_selection", new Func <string, PhpValue>(InstallSourceSelection), priority: 0); app.AddFilter("upgrader_post_install", new Func <bool, PhpArray, PhpArray, PhpValue>(PostInstall), priority: 0, accepted_args: 3); app.AddFilter("activate_plugin", new Action <string>(plugin_file => _packages.ActivatePackage(PackagesHelper.PluginFileToPluginId(plugin_file)))); app.AddFilter("deactivate_plugin", new Action <string>(plugin_file => _packages.DeactivatePackage(PackagesHelper.PluginFileToPluginId(plugin_file)))); app.AddFilter("switch_theme", new Action <string, WP_Theme, WP_Theme>(SwitchTheme), accepted_args: 3); app.AddFilter("install_plugins_tabs", new Func <PhpArray, PhpArray>(tabs => // remove unsupported tabs { //tabs.Remove(new IntStringKey("upload")); tabs.Remove(new IntStringKey("popular")); tabs.Remove(new IntStringKey("recommended")); tabs.Remove(new IntStringKey("favorites")); tabs["recommended"] = "Premium"; return(tabs); })); app.AddFilter("site_transient_update_themes", new Func <PhpValue, stdClass>(current => { // TODO: wpdotnet check for version update return(new PhpArray() { { "last_checked", Pchp.Library.DateTime.DateTimeFunctions.time() }, //{ "checked", [name => version] }, //{ "response", [name => [package, url, new_version]] }, //{ "no_update", [name => [package, url, new_version]] }, //{ "translations", [] }, }.ToObject()); }), accepted_args: 1); app.AddFilter("site_transient_update_plugins", new Func <PhpValue, stdClass>(current => { // TODO: wpdotnet check for version update return(new PhpArray() { { "last_checked", Pchp.Library.DateTime.DateTimeFunctions.time() }, //{ "checked", [name => version] }, //{ "response", [name => [package, url, new_version]] }, //{ "no_update", [name => [package, url, new_version]] }, //{ "translations", [] }, }.ToObject()); }), accepted_args: 1); // do not allow editing of .php files: app.AddFilter("editable_extensions", new Func <PhpArray, PhpArray>(editable_extensions => { editable_extensions.Remove("php"); return(editable_extensions); })); // defined in PeachPied.WordPress.Standard: // app.Context.DefineConstant("FS_METHOD", "direct"); // overwrite how installing plugins is handled, skips the fs check //// ensure "themes" directory exists (always exists) //var themedir = app.Context.Call("get_theme_root"); //try { Directory.CreateDirectory(themedir.ToString(app.Context)); } //catch { } }); }
public void Configure(WpApp app) { if (_isRegistered.HasValue == false || app.Context.Post.Count != 0) { TryRegisterUser(app); } // // Dashboard: // // add information into Right Now section app.DashboardRightNow(output => DashboardRightNow(app, output)); // // Blogs: // // alter generator metadata app.AddFilter("get_the_generator_xhtml", new Func <string>(() => s_GeneratorHtml)); // app.AddFilter("wp_head", new Action(() => // { // app.Context.Output.Write(@"<style> // .foldtl { // position: relative; // -webkit-box-shadow: 5px -5px 5px rgba(0,0,0,0.2); // -moz-box-shadow: 5px -5px 5px rgba(0,0,0,0.2); // box-shadow: 5px -5px 5px rgba(0,0,0,0.2); // } // .foldtl:before { // content: """"; // position: absolute; // top: 0%; // left: 0%; // width: 0px; // height: 0px; // border-top: 70px solid rgba(255,255,255,0.8); // border-left: 70px solid #ededed; // -webkit-box-shadow: 7px -7px 7px rgba(0,0,0,0.2); // -moz-box-shadow: 7px -7px 7px rgba(0,0,0,0.2); // box-shadow: 7px -7px 7px rgba(0,0,0,0.2); // } // </style>"); // })); if (!IsRegistered) { app.Footer(output => { output.Write($@" <div style='position:fixed;text-align:center; width:192px; height:50px; bottom:0; right:0;padding:12px 0 12px 50px; margin:0 auto; vertical-align: middle;background:#68b227;background-image:url({LogoUrl});background-size:50px 50px;background-repeat:no-repeat;border-left:solid 10px rgba(255,255,255,.5);line-height:24px;' title='WpDotNet'> <a href='{WpDotNetUrl}?from=footer' style='color:#fff;font-size:16px;font-style:tahoma,helvetica;padding:0; margin:0;'>WpDotNet</a> </div> "); }); app.OnAdminInit(() => { app.AddFilter("admin_print_footer_scripts", new Action(() => { app.Context.Output.Write($@" <script type='text/javascript'> function wpdotnet_register_open() {{ jQuery('#{RegisterBoxId}').slideToggle('fast'); jQuery('#{RegisterBoxId} input[type=""text""]').focus(); return false; }} </script> "); })); }); } }
void IWpPlugin.Configure(WpApp app) { // postpone admin actions app.AddFilter("admin_init", new Action(() => { // plugins_api app.AddFilter("plugins_api", new Func <PhpValue, string, object, PhpValue>(PluginsApi), accepted_args: 3); app.AddFilter("themes_api", new Func <PhpValue, string, object, PhpValue>(ThemesApi), accepted_args: 3); app.AddFilter("delete_plugin", new Action <string>(DeletePlugin)); app.AddFilter("upgrader_source_selection", new Func <string, PhpValue>(InstallSourceSelection), priority: 0); app.AddFilter("upgrader_post_install", new Func <bool, PhpArray, PhpArray, PhpValue>(PostInstall), priority: 0, accepted_args: 3); app.AddFilter("activate_plugin", new Action <string>(plugin_file => _packages.ActivatePackage(PackagesHelper.PluginFileToPluginId(plugin_file)))); app.AddFilter("deactivate_plugin", new Action <string>(plugin_file => _packages.DeactivatePackage(PackagesHelper.PluginFileToPluginId(plugin_file)))); app.AddFilter("switch_theme", new Action <string, WP_Theme, WP_Theme>(SwitchTheme), accepted_args: 3); app.AddFilter("install_plugins_tabs", new Func <PhpArray, PhpArray>(tabs => // remove unsupported tabs { //tabs.Remove(new IntStringKey("upload")); tabs.Remove(new IntStringKey("popular")); tabs.Remove(new IntStringKey("recommended")); tabs.Remove(new IntStringKey("favorites")); tabs["recommended"] = "Premium"; return(tabs); })); app.AddFilter("user_has_cap", new Func <PhpArray, PhpArray, PhpArray, PhpArray>((allcaps, cap, args) => { // remove 'update_core' allcaps["update_core"] = false; // return(allcaps); }), accepted_args: 3); // defined in PeachPied.WordPress.Standard: // app.Context.DefineConstant("FS_METHOD", "direct"); // overwrite how installing plugins is handled, skips the fs check // ensure "plugins" directory exists, otherwise eventual mkdir() in wp fails if (app.Context.TryGetConstant("WP_PLUGIN_DIR", out var plugindir)) { try { Directory.CreateDirectory(plugindir.ToString(app.Context)); } catch { } } //// ensure "themes" directory exists (always exists) //var themedir = app.Context.Call("get_theme_root"); //try { Directory.CreateDirectory(themedir.ToString(app.Context)); } //catch { } })); }