Just read a forum topic Organizing Plugins on the wordpress.org support forums and thought I'd give you all the tips and tricks that I've learned and use when developing WordPress plugins.. which can be quite fun! I'm definately not a php or WordPress expert, anyone can create useful WordPress plugins without being a hacker.
One of the most helpful and interesting ways that I improve my coding and learn new tips and tricks is by checking out the source code to as many interesting plugins that I can. Each plugin author has a completely unique style of coding in most cases, and this can vary from super-advanced like the Google Sitemap Generator plugin to the incredibly-simple like the AskApache Search Engine Verify plugin.
Instead of just picking plugins at random to reverse-engineer, I surf the WordPress plugin repository for unique and interesting plugins that perform a unique function or contain a unique feature. If I wanted to Learn about MySQL search and replace code for wordpress, I would check out the source code of the excellent Search Regex plugin. Or if I wanted to learn about creating static files from dynamic content on my blog and save and serve from a mysql database, I would check out WP-Cache, and some of the translator plugins.
Any real/elite Web Developer knows the extreme value of using modular, templateable code. CSS, XHTML Strict, unobtrusive javascript, PHP, all are geared towards templates.. And of course WordPress is one of the mack-daddies of templates. So why not use a template for plugin files?
The get_plugin_data function is a simple built-in wordpress function that retrieves values like 'Name', 'Url', etc.. by preg_searching the plugins file. The key part is the very first few lines of a plugin. Do a print_r($aa_pluginshortname_data) and you will see. This is so useful because it means I don't have to hard-code the Plugin Name, URI, Version, Author, etc.. into my code, which makes my code more robust and dynamic.
$aa_pluginshortname_data=get_plugin_data(__FILE__);
For each new AskApache plugin I create a folder in the /wp-content/plugins/aa-pluginshortname/
and then in that folder I create the main plugin file with the same name as the folder + .php
so the plugin file is /wp-content/plugins/aa-pluginshortname/aa-pluginshortname.php
.
in your main content area. */ /* /-------------------------------------------------------------------- | | | License: GPL | | | | AskApache Plugin Shortname Plugin - brief description | | Copyright (C) 2007, AskApache, www.askapache.com | | All rights reserved. | | | | This program is free software; you can redistribute it and/or | | modify it under the terms of the GNU General Public License | | as published by the Free Software Foundation; either version 2 | | of the License, or (at your option) any later version. | | | | This program is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY; without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | GNU General Public License for more details. | | | | You should have received a copy of the GNU General Public License | | along with this program; if not, write to the | | Free Software Foundation, Inc. | | 51 Franklin Street, Fifth Floor | | Boston, MA 02110-1301, USA | | | --------------------------------------------------------------------/ */
add_action('admin_menu', 'aa_plugin_shortname_options_setup');
function aa_plugin_shortname_options_setup() { global $aa_pluginshortname_data; add_options_page($aa_pluginshortname_data['Name'], 'AA Plugin Shortname', 8, basename(__FILE__), 'aa_plugin_shortname_page'); }
if ( function_exists('current_user_can') && !current_user_can('manage_options') ) die(__('Cheatin’ uh?')); if (! user_can_access_admin_page()) wp_die( __('You do not have sufficient permissions to access this page.') );
$aa_head='[ 404 Error Page tip for Google Analytics - Home: '.$aa_pluginshortname_data['Title'].' - Version: '.$aa_pluginshortname_data['Version'].' - Author: '.$aa_pluginshortname_data['Author'].' ]
'; $aa_main =''.$aa_pluginshortname_data['Name'].'
Test Your 404 Page'; _e($aa_head); _e($aa_main);Using functions to output code blocks
function aa_print_google_links(){ // Thanks Google, you Rock from the Start! echo ''; }More Info from Google
- AJAX Search API
- Start Using the API
- AJAX Search Wizards
- Developer Guide
- Class Reference
- Code Samples
- Community Samples
- Knowledge Base
- AJAX APIs Blog
- Developer Forum
Register the Activation and Deactivation Hooks
register_deactivation_hook(__FILE__, 'aa_plugin_shortname_deactivate'); register_activation_hook(__FILE__, 'aa_plugin_shortname_activate');Delete Stored options upon deactivation
function aa_plugin_shortname_deactivate(){ delete_option('aa_plugin_shortname_url'); delete_option('aa_plugin_shortname_code_html'); delete_option('aa_plugin_shortname_code_js'); delete_option('aa_plugin_shortname_code_css'); delete_option('aa_plugin_shortname_api_key'); }Activation Function
function aa_plugin_shortname_activate(){ global $aa_pluginshortname_data; $aa_pluginshortname_data=get_plugin_data(__FILE__); update_option('aa_plugin_shortname_url',$aa_plugin_shortname_url); update_option('aa_plugin_shortname_api_key',$aa_plugin_shortname_api_key); update_option('aa_plugin_shortname_code_html',stripslashes($aa_plugin_shortname_code_html)); update_option('aa_plugin_shortname_code_js',stripslashes($aa_plugin_shortname_code_js)); update_option('aa_plugin_shortname_code_css',stripslashes($aa_plugin_shortname_code_css)); }Tips on Writing WordPress Plugins - AskApache