Presentation is loading. Please wait.

Presentation is loading. Please wait.

WordPress from Start to Finish Day 3: Working with plugins (http://codex.wordpress.org/Writing_a_Plugin)

Similar presentations


Presentation on theme: "WordPress from Start to Finish Day 3: Working with plugins (http://codex.wordpress.org/Writing_a_Plugin)"— Presentation transcript:

1 WordPress from Start to Finish Day 3: Working with plugins (http://codex.wordpress.org/Writing_a_Plugin)

2 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 http://wordpress.org/extend/plugins/, you also need to create a readme.txt file in a standard format, and include it with your Plugin. See http://wordpress.org/extend/plugins/about/read me.txt for a description of the format. http://wordpress.org/extend/plugins/ http://wordpress.org/extend/plugins/about/read me.txt http://codex.wordpress.org/WordPress_Coding_Standards http://codex.wordpress.org/Inline_Documentation http://codex.wordpress.org/Writing_a_Plugin

3 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: http://URI_Of_Page_Describing_Plugin_and_Updates – 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: http://URI_Of_The_Plugin_Author – License: A "Slug" license name e.g. GPL2 Example: http://wptraining.lewayotte.com/files/2012/06/wptraining- plugin-header.txthttp://wptraining.lewayotte.com/files/2012/06/wptraining- plugin-header.txt http://codex.wordpress.org/Writing_a_Plugin#File_Headers

4 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: http://wptraining.lewayotte.com/files/2012/06/wptraining-plugin- options-page.txt http://wptraining.lewayotte.com/files/2012/06/wptraining-plugin- options-page.txt http://codex.wordpress.org/Function_Reference/add_options_page http://ottopress.com/2009/wordpress-settings-api-tutorial/

5 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: http://wptraining.lewayotte.com/files/2012/06/wptra ining-plugin-the-cat-api.txt http://wptraining.lewayotte.com/files/2012/06/wptra ining-plugin-the-cat-api.txt http://codex.wordpress.org/HTTP_API http://codex.wordpress.org/Function_API/wp_remote_get http://codex.wordpress.org/Function_API/wp_remote_retrieve_body http://codex.wordpress.org/Class_Reference/WP_Error http://codex.wordpress.org/Function_Reference/is_wp_error http://codex.wordpress.org/Function_Reference/plugin_dir_path

6 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: http://wptraining.lewayotte.com/files/2012/06/wptraining- plugin-shortcodes.txt http://wptraining.lewayotte.com/files/2012/06/wptraining- 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(); http://codex.wordpress.org/Shortcode_API http://codex.wordpress.org/Function_Reference/add_shortcode http://codex.wordpress.org/Function_Reference/shortcode_atts http://codex.wordpress.org/Function_Reference/plugin_dir_path

7 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: http://wptraining.lewayotte.com/files/2012/06/wptraining- plugin-widgets.txt http://wptraining.lewayotte.com/files/2012/06/wptraining- plugin-widgets.txt Include the new widget file into our main plugin file. – include_once( plugin_dir_path( __FILE__ ). '/catnip- widgets.php' ); http://codex.wordpress.org/Widgets_API http://codex.wordpress.org/Function_Reference/register_widget http://codex.wordpress.org/Function_Reference/plugin_dir_path

8 The Plugins readme.txt Before submitting our plugin to the WordPress repository, we need to create a readme.txt. – Example: http://wptraining.lewayotte.com/files/2012/06/w ptraining-plugin-readme.txt http://wptraining.lewayotte.com/files/2012/06/w ptraining-plugin-readme.txt http://wordpress.org/extend/plugins/about/readme.txt

9 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 http://wordpress.org/extend/plugins/add/ 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. http://wordpress.org/extend/plugins/about/faq/ http://wordpress.org/extend/plugins/about/guidelines/ http://wordpress.org/extend/plugins/about/svn/

10 WordPress SVN Access Upon approval of your plugin, youll get an email like this one: layotte, Your plugin hosting request has been approved. Within one hour, you will have access to your SVN repository at http://plugins.svn.wordpress.org/catnip/ 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 http://wordpress.org/extend/plugins/about/svn/ FAQ about the WordPress Plugins Directory http://wordpress.org/extend/plugins/about/faq/ WordPress Plugins Directory readme.txt standard http://wordpress.org/extend/plugins/about/readme.txt readme.txt validator: http://wordpress.org/extend/plugins/about/validator/ Enjoy! http://plugins.svn.wordpress.org/catnip/ http://wordpress.org/extend/plugins/about/svn/ http://wordpress.org/extend/plugins/about/faq/ http://wordpress.org/extend/plugins/about/readme.txt http://wordpress.org/extend/plugins/about/validator/ I prefer to use TortoiseSVN for my Windows SVN Client as well as the plugin for Dreamweaver called SubWeaver.TortoiseSVNSubWeaver

11 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: http://wptraining.lewayotte.com/files/2012/06/wptra ining-mu-plugin.txt http://wptraining.lewayotte.com/files/2012/06/wptra ining-mu-plugin.txt This mostly used in WordPress Multi-Site installations. http://codex.wordpress.org/Must_Use_Plugins

12 Dont Forget to Donate http://tomuse.com/wp-plugins-developer-business-model/ http://www.justinparks.com/have-you-made-donation-to-your- wordpress-plugin-developer/ http://www.justinparks.com/have-you-made-donation-to-your- wordpress-plugin-developer/ http://www.vsellis.com/scott-recommends/make-a-donation-to-your- favorite-wordpress-plugin-developer-on-march-1st/ http://www.vsellis.com/scott-recommends/make-a-donation-to-your- favorite-wordpress-plugin-developer-on-march-1st/ http://speckyboy.com/2011/01/13/do-we-do-enough-to-support- wordpress-plugin-developers/ http://speckyboy.com/2011/01/13/do-we-do-enough-to-support- wordpress-plugin-developers/ http://news.ycombinator.com/item?id=659303 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.

13 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

14 Next Week… WordPress Multi-Site JavaScript, CSS, and AJAX in Plugins Other Advanced APIs built into WordPress More on i18n – Internationalization Questions


Download ppt "WordPress from Start to Finish Day 3: Working with plugins (http://codex.wordpress.org/Writing_a_Plugin)"

Similar presentations


Ads by Google