Beispiel #1
0
 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
     }));
 }
        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 { }
            });
        }
Beispiel #3
0
 void DeletePlugin(string plugin_file)
 {
     _packages.UninstallPackage(PackagesHelper.PluginFileToPluginId(plugin_file));
 }
        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 { }
            }));
        }