View stunning SlideShares in full-screen with the new iOS app!Introducing SlideShare for AndroidExplore all your favorite topics in the SlideShare appGet the SlideShare app to Save for Later — even offline
View stunning SlideShares in full-screen with the new Android app!View stunning SlideShares in full-screen with the new iOS app!
How to create aWordPress plugin.WordCamp Toronto Dev 2012@thisismyurl
What is a Plugin?A WordPress plugin is a PHP based addition to theWordPress blogging platform.• Plugins are functions which interact with WordPress Core code;• A Plugin changes what WordPress does;• Plugins are stored external of the theme;
What can they do?Since Plugins are executed as part of the WordPress platform,they’re almost limitless.• Plugins can interact with WordPress via Hooks and Actions;• They can create, or interact with API’s in the WordPress system;• Plugins can affect Posts, Pages, Users, or any part of the WordPress tool;
When should you use aPlugin?Plugin functions can be stored as a plugin, or in a themefunction.php file, why choose?• Functions are specifically part of the theme;• Plugins allow you to share code outside a theme, across multiple designs;• Plugins can be activated in multisite environments;
Theme functions arerestricted to a singletheme. Plugins deliver the same code to multiple blogs, on the same server or across multiple hosting accounts.
How WordPress finds aPluginWordPress will automatically locate plugins on a standardinstall, adding them to the admin• /wp-content/plugins/filename.php• /wp-content/plugins/folder-name/filename.php• WordPress will search one level deep in the plugins folder;• Searches for .php files with a valid plugin header;
Play nice with otherfunctionsRemember WordPress shares your plugin functions across theentire site, be unique• Your plugins should use a unique name for all functions;• function demo_plugin_function_name() for example;• Plugin file load order is determined by WordPress;
What are Actions?Actions are triggered by WordPress, causing your plugin tospring to life.• There’s an action for almost everything WordPress does• http://codex.wordpress.org/Plugin_API/Action_Reference
What are Filters?Filters allow you to change content WordPresshas created.• There’s an filter for almost everything WordPress does• http://codex.wordpress.org/Plugin_API
Building a PluginLet’s get started with something basic.
The entire pluginhttp://wordpress.org/extend/plugins/fetch-twitter-count-for-wordpress/
How to uninstall the data from your plugin• Stored separately in an uninstall.php file.
Plugin Best PractisesSome ideas on how to do it right.
Be unique.Remember Plugins interact will all the code on yourWordPress website, make sure you’re unique.• Classes and Functions should use unique names;• thisismyurl_plugin_name_function_name() for example;
Be descriptive.Your Plugin is part of something else, make sure people caneasily understand your code.• Elements should use verbose naming conventions, easy to understand;• $i is bad;• $loop_resume_posts is good;
Be consistent.There are standards in the WordPress community, followingthem makes it easy.• The WordPress coding standards make coding easier in the long run;• If you’re following your own coding standards, stick to them;• http://codex.wordpress.org/WordPress_Coding_Standards
Be lazy, but smart.In my experience, somebody else has already done a lot of theheavy lifting so look before you code.