Presentation on theme: "WordPress from Start to Finish Day 3: Working with plugins (http://codex.wordpress.org/Writing_a_Plugin)"— Presentation transcript:
WordPress from Start to Finish Day 3: Working with plugins (http://codex.wordpress.org/Writing_a_Plugin)
Required Plugin Files There is technically only one required file – pluginname.php (same as the folder name) However, if you want to host your Plugin on you also need to create a readme.txt file in a standard format, and include it with your Plugin. See me.txt for a description of the format. me.txt
Standard Plugin Information The top of your Plugins main PHP file should contain a standard Plugin information header. This header lets WordPress recognize that your Plugin exists, add it to the Plugin management screen so it can be activated, load it, and run its functions; without the header, your Plugin will never be activated and will never run. Here are the header arguments: – Plugin Name: Name Of The Plugin – Plugin URI: – Description: A brief description of the Plugin. – Version: The Plugin's Version Number, e.g.: 1.0 – Author: Name Of The Plugin Author – Author URI: – License: A "Slug" license name e.g. GPL2 Example: plugin-header.txthttp://wptraining.lewayotte.com/files/2012/06/wptraining- plugin-header.txt
Create an Options Page There are several ways to skin this cat, but this is the easiest. Pay attention to these functions: – add_options_page() add_options_page() – settings_fields() settings_fields() – do_settings_sections() do_settings_sections() – register_setting() register_setting() – add_settings_section() add_settings_section() – add_settings_field() add_settings_field() – get_options() get_options() Example: options-page.txt options-page.txt
The Cat API Well need to make sure we create and include The Cat API into our plugin. – include_once( plugin_dir_path( __FILE__ ). '/the-cat- api.php' ); – Example: ining-plugin-the-cat-api.txt ining-plugin-the-cat-api.txt
Adding Shortcodes To add a shortcode, you simply need to run the function add_shortcode() which takes two arguments, the shortcode name and the function it calls to process the shortcode. add_shortcode() – Example: plugin-shortcodes.txt plugin-shortcodes.txt Include the shortcode file into our main plugin file. – include_once( plugin_dir_path( __FILE__ ). '/catnip- shortcodes.php' ); – $catnip_shortcodes= new catnip_shortcodes();
Adding Widgets Widgets are a little more complicated, you need to register your widgets with register_widget() which should be called with the widgets_init action. Then you should extend the WP_Widgets API Class to create your new widget.register_widget() – Example: plugin-widgets.txt plugin-widgets.txt Include the new widget file into our main plugin file. – include_once( plugin_dir_path( __FILE__ ). '/catnip- widgets.php' );
The Plugins readme.txt Before submitting our plugin to the WordPress repository, we need to create a readme.txt. – Example: ptraining-plugin-readme.txt ptraining-plugin-readme.txt
Submit to the WP Plugin Repository Zip your plugin and upload it to an online resource that will hold the plugin. Be sure to check out the Developer FAQ and the detailed guidelines before submitting your plugin. Visit and fill out the required information.http://wordpress.org/extend/plugins/add/ After you submit your plugin, youll need to wait for it to be approved, then you will receive information for accessing Subversion.
WordPress SVN Access Upon approval of your plugin, youll get an like this one: layotte, Your plugin hosting request has been approved. Within one hour, you will have access to your SVN repository at with your WordPress.org/bbPress.org username and password (the same one you use on the forums). Here's some handy links to help you get started. Using Subversion with the WordPress Plugins Directory FAQ about the WordPress Plugins Directory WordPress Plugins Directory readme.txt standard readme.txt validator: Enjoy! I prefer to use TortoiseSVN for my Windows SVN Client as well as the plugin for Dreamweaver called SubWeaver.TortoiseSVNSubWeaver
MU Plugins You can create a directory in /wp-content/ for plugins that you always want activated, no options for any users to deactivate them. The directory is mu-plugins. E.g. /wp-content/mu- plugins/ – Example: ining-mu-plugin.txt ining-mu-plugin.txt This mostly used in WordPress Multi-Site installations.
Dont Forget to Donate wordpress-plugin-developer/ wordpress-plugin-developer/ favorite-wordpress-plugin-developer-on-march-1st/ favorite-wordpress-plugin-developer-on-march-1st/ wordpress-plugin-developers/ wordpress-plugin-developers/ In short, if you dont support the plugin developers who make your life easy, you run the risk of that plugin being abandoned. As much as developers want to make you happy, its currently not legal to feed their families with happy people. Paying work will almost always come before charity work. And most of these developers arent just developing plugins for WordPress, they also have to spend time with support questions about their plugin.
Did I mention Donating? Also, you may have noticed WordPress is completely free. If youre making money from WordPress, Id recommend giving back to the WordPress community. You can donate by visiting the WordPress Foundation donation page.WordPress Foundation