Exemplo n.º 1
0
 public static void DashboardWidget(this WpApp app, string widget_id, string widget_name, Action <TextWriter> htmlwriter)
 {
     app.AddFilter(
         "wp_dashboard_setup",
         new Action(() => app.Context.Call("wp_add_dashboard_widget",
                                           (PhpValue)widget_id, (PhpValue)widget_name, PhpValue.FromClass(new Action(() => htmlwriter(app.Context.Output))))));
 }
Exemplo n.º 2
0
 public static void Footer(this WpApp app, Action <TextWriter> callback, long priority = 100)
 {
     app.AddFilter("wp_footer", new Action(() =>
     {
         callback(app.Context.Output);
     }), priority);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Invoked by PHP plugin implementation (peachpie-api.php) to bridge into .NET.
 /// </summary>
 public virtual void AppStarted(WpApp app)
 {
     // activate plugins:
     foreach (var plugin in _plugins)
     {
         plugin.Configure(app);
     }
 }
Exemplo n.º 4
0
 public static void AddAjaxAction(this WpApp app, string action, Func <string> callback)
 {
     app.AddFilter("wp_ajax_" + action, new Action(() =>
     {
         app.Context.Echo(callback());
         app.Context.Call("wp_die");
     }));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Invoked by PHP plugin implementation (DotNetBridge.php) to pass the WpApp PHP class.
 /// </summary>
 public static void AppStarted(Context ctx, WpApp host)
 {
     if (ctx.Globals["peachpie_wp_loader"].AsObject() is WpLoader loader)
     {
         loader.AppStarted(host);
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
Exemplo n.º 6
0
        public static string?AddManagementPage(this WpApp app, string pageTitle, string menuTitle, string capability, string slug, Action <TextWriter> callback, int?position = null)
        {
            var hook = app.Context.Call("add_management_page", pageTitle, menuTitle, capability, slug, new Action(() =>
            {
                callback(app.Context.Output);
            }), position.HasValue ? position.Value : PhpValue.Null);

            if (hook.IsFalse)
            {
                return(null);
            }

            return(hook.ToString());
        }
Exemplo n.º 7
0
 public static PhpValue GetUserMeta(this WpApp app, int userId, string metaKey, bool single = false)
 => GetMetaData(app, "user", userId, metaKey, single);
Exemplo n.º 8
0
 public static bool AddUserMeta(this WpApp app, int userid, string metakey, PhpValue metavalue, bool unique = false)
 {
     return(app.Context
            .Call("add_user_meta", (PhpValue)userid, (PhpValue)metakey, metavalue, unique)
            .IsInteger());
 }
Exemplo n.º 9
0
 public static string?GetAdminEmail(this WpApp app)
 {
     return(GetOption(app, "admin_email").IsString(out var email) ? email : null);
 }
Exemplo n.º 10
0
 public static void DashboardRightNow(this WpApp app, Action <TextWriter> htmlwriter)
 {
     app.AddFilter(
         "rightnow_end",
         new Action <Context>(ctx => htmlwriter(ctx.Output)));
 }
Exemplo n.º 11
0
 public static void FilterPermalink(this WpApp app, the_permalink_filter filter) => app.AddFilter("the_permalink", filter);
Exemplo n.º 12
0
 public static void FilterTitle(this WpApp app, the_title_filter filter) => app.AddFilter("the_title", filter);
Exemplo n.º 13
0
 public static string GetVersion(this WpApp app) => app.Context.Globals["wp_version"].ToString();
Exemplo n.º 14
0
 public static bool UpdateOption(this WpApp app, string option, PhpValue value)
 {
     return((bool)app.Context.Call("update_option", option, value));
 }
Exemplo n.º 15
0
 public static void AdminNotices(this WpApp app, Func <string> callback)
 {
     app.AddFilter("admin_notices", new Action(() => app.Context.Echo(callback())));
 }
Exemplo n.º 16
0
 public static void AdminMenu(this WpApp app, Action action) => app.AddFilter("admin_menu", action);
Exemplo n.º 17
0
 public static void OnAdminInit(this WpApp app, Action action) => app.AddFilter("admin_init", action);
Exemplo n.º 18
0
 public static PhpValue GetMetaData(this WpApp app, string metaType, int objectId, string metaKey, bool single = false)
 {
     return(app.Context.Call("get_metadata", metaType, (PhpValue)objectId, metaKey, single));
 }
Exemplo n.º 19
0
 public static void FilterContent(this WpApp app, the_content_filter filter) => app.AddFilter("the_content", filter);
Exemplo n.º 20
0
 public static PhpValue GetOption(this WpApp app, string option, PhpValue @default = default /*NULL*/)
 {
     return(app.Context.Call("get_option", option, @default));
 }
Exemplo n.º 21
0
 public static string GetSiteUrl(this WpApp app, string path = "", string?scheme = null) => app.Context.Call("site_url", path, scheme).ToString();