Share your plugin design guidelines?

I know some developers and dev groups seem to have a common "style guide" for how they create plugins, e.g. where to put functions and page-building code.

Does anyone have published style guides they'd like to share?

  • I'm a messy programmer. Pretty messy. A mess. I make sure plugins work, don't make the code readable or in order, so I guess that's my style.

  • I have not published any style guides, but generally I organize code like this,

    Functions, page setup - plugin / lib /
    Third party libraries - plugin / vendors /
    Settings - plugin / views / default / admin / settings / plugin.php
    Plugin specific styling - plugin / views / default / plugin /

    I have started using lib more lately, for example for menu items. Are there any instructions on what is most appropriate? It is not entirely clear in bundled plugins.

    For example, functions are often in the lib, while hooks are in start.php. Why are hooks not in the lib folder also, there's a reason for that?

    Is it advantageous to keep the size of start.php down, except that it's easier to see the code.

    If it is not important for the conduct of a plugin, it's a good idea to group pieces of code into their own files, so you get a better overview, I think.

  • On ElggCampAMS I gave a presentation about "Your first plugin" in which I showed how we layout our plugins.

    Presentation: https://docs.google.com/presentation/d/1zJDfEoglt6_FPMe3syQLAxxaAquMkIYkfZsfO3VJIOw/embed?start=false&loop=false&delayms=5000#slide=id.gead85a2e_041

    Basicly the layout is

    - actions
    - languages
    - lib
    --- functions.php // every helper function
    --- events.php // all event handlers
    --- hooks.php // all plugin hook handlers
    --- page_handlers.php // all page handler
    - pages // the files that handler a certain page
    - procedures // 'pages' that don't output a page, eg a jQuery autocomplete search
    - views
    - vendors // third party software

  • I follow pretty much the same pattern as ColdTrick

    I like to keep things like pagehandlers, url handlers - things I consider "elgg functions" in the start.php

    In the init function I like to keep the types of functions grouped to keep things easier to read, so all of my view extensions are first, followed by js/css/library registration, then events, hooks, actions, etc.