Developing Plugins

Joe edited this page May 28, 2017 · 1 revision

The point of plugins is to allow injection of PHP code at any hooked point very easily. Not very discoverable, but the functionality seems sound.

Hook Assignment

In admin, you can assign a hook like

  • hook_name: post app blog view
  • plugin: disqus
  • config: littlefoot

In the above example, we use the DISQUS plugin: https://github.com/lfcms/Disqus/blob/master/index.php#L6

It simply resolves $config in the plugin index and print to screen after the app Blog's /view method call. This would be where a given post would be displayed, so now all posts have DISQUS comments!

Run Hook

https://github.com/lfcms/LittlefootCMS/blob/e3cdd406d18c88f3fc57896f805ca649508edd39/lf/system/lib/cms.php#L532

  • The actual hook that runs for this example is triggered in the CMS content render step as linked above.
  • The linked code loops through the method chain in the URL as such:

Given http://domain.com/littlefoot/blog/view/14,

->run('post app '.$className.' '.implode(' ', $varstr));
  • post app blog view 14
  • post app blog view
  • post app blog

And if you have a plugin hooked to any of those, it will render at that point. Very granular.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.