Welcome to Elgg's documentation

This is the place to find documentation on all aspects of Elgg. If you would like to contribute your own documentation please do; we want this to be a real community effort!

Coding standards

From Elgg Documentation

Contents

[edit] Basic coding standards

The following is a minimum specification for plugins:

  • Do not assume the user has 'short quotes' or short_open_tag enabled.
  • Wrap all text in the __gettext() function for internationalisation.

In other words, all PHP code blocks must start with <?php rather than just <?.

[edit] Trunk code standard

For code to be included in the main Elgg code, the following holds:

  • Don't make any extra software or hardware requirements on the user. If it breaks without X installed, we can't include it with Elgg. This includes PEAR. For very common libraries we may be willing to include the plugin with the main Elgg install, but in a way that the user has to enable it. (A way to get around this rule is to perform some kind of detection in your code, so that your module just won't appear if X isn't installed.)

[edit] Line spacing and tabs

We have settled on 80-column files with tabs equal to four spaces. Earlier files will be converted to this format over time.

[edit] Clean up after yourself!

Because Elgg can be installed with a growing collection of plugins, each of which may have their own custom data, each plugin must take care of deleting its own data when a user is removed.

Here's how it works. Plugin authors should take the following into account.

A function, user_delete($user_id), sits in userlib.php and can be called at any time. It will in turn call event_hook("user","delete",$user), causing any plugins that have hooked into the event to have their functions called. Currently in SVN, all of the applicable core plugins have this implemented.

How to do this:

In yourplugin_init(), include the following line:

   listen_for_event("user","delete","yourplugin_user_delete"); 

And then the following function:

    function yourplugin_user_delete($object_type, $event, $object) {
       // Code to delete any user data your plugin creates goes here
       // You must pass $object back unless something goes wrong!
          return $object;
    }

$object is a dump of the users table row containing the user to be deleted. In other words, it will contain $object->ident, $object->username, etc - but no data about the user beyond what's in the table row.

If your plugin doesn't save any user-created data, or saves user-created data as user flags using user_flag_set, you may safely ignore this. But everyone else should take note, because if you don't implement the above your plugin could have unexpected consequences.

Back to Development frontpage