Creating a custom Drupal module is a lot easier than you expect, and a lot more important as well.
Drupal offers thousands of resources for you to create your website in a glance, I know, but I am pretty sure you or your client will want to change a little something here and there. This is why I recommend you to have a custom module for every website you create with Drupal. Within it you will create those PHP snippets you usually need and would end up placing within blocks, nodes or rules wasn't for the custom module.
Tip: try always to keep adherent to the good practices and patterns of Drupal community. This includes avoiding PHP in blocks or nodes. Deadlines may be an obstacle for understanding and learning the patterns, but if you cannot find some time to do it you will end up with more problems in the future.In order to create a "blank" module, ready for use when you need a custom function, it will be necessary to create a folder and two files: piece of cake. After that you will need to go to the module admin page and install you newly created module.
- Access the folder in which you usually place your modules: i.e.: /sites/all/modules or /sites/default/modules);
- Create a folder named after your new module:
- Access this folder and create two files, both named after your module, one with the ".info" extension and other with the ".module" extension.
- Open the file mymodule.info and write the following information:
;$Id$ name = mymodule description = this site specific custom module. core = 7.x
- Remember to change the information above, including the core version to your Drupal installation core.
- Now open the mymodule.module file and write the functions you want. They will be available in your snippets called from blocks, of course, but the best way to develop with Drupal is to use hooks. After learning how to use hooks Drupal may become not only your favorite CMS but also your favorite framework.
- IMPORTANT: use <?php to open the PHP code, but do not use ?> to close it in the .module file