WordPress Plugins


Published on

A plugin in WordPress is a PHP script that extends or alters the core functionality of

Published in: Technology, Art & Photos
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Going to cover a lot in 3 hours. Usually a 6 hour hands on class! And really could be a 2 day session. The goal is to give you a taste of all the pieces you’ll need to build a website with WordPress. And a lot of tips and tricks along the way. WON”T BE SPENDING TONS OF TIME ON THE REAL BASICS. With those pieces you’ll be able to let your imagination go to town! Because there are limitless ways you can customize and enhance WP. Please ask questions as we go – if you have a question, someone else probably does too. If something comes up that is beyond what we can cover during the session, I’ll be happy to talk to you after the session or get together during the rest of the conference.
  • WordPress Plugins

    1. 1. WordPress Plugins By:- Mr. Ashok Negi
    2. 2. What is Plugin?A plugin in WordPress is a PHP script that extends or alters the core functionality ofWordPress. Quite simply plugins are files installed in WordPress to add a feature, or set of features, to WordPressPlugin provides a set of hooks that enable plugins access to specific parts of WordPress. WordPress contains two different types of hooks: Actions and Filters. The Action hook enables you to trigger custom plugin code at specific points during execution. For example, you can trigger a custom function to run after a user registers a user account in WordPress.The Filter hook to modifies text before adding or after retrieving from the database.
    3. 3. How to install any plugin in wordpress?Following are the different ways to install any plugin1: Unzip the zipped plugin and then copy and paste folder inside the plugin folder the path to plugin folder is wp-contentplugins2: Go to Admin > Plugins > Add New, You can search the plugin by keyword, author or tag then you will get the list of plugin for the keyword you have entered.3: The second link in Add New Plugin is “Upload” If you have a plugin in a .zip format, you may install it by uploading it here.
    4. 4. How to create a custom plugin?CREATING A PLUGIN FILEA plugin in WordPress can be a single PHP file or a group of files inside a folder. Youneed to consider many things when creating a new plugin in WordPress such as theplugin name and proper folder usage.NAMING YOUR PLUGINWhen choosing a name for your plugin, it’s good practice to consider a name basedon what your plugin actually does. For example, if you create an SEO - focusedplugin, you wouldn’t want to name it Bob’s Plugin. Your audience would have noidea what your plugin actually does based on the plugin name. Your plugin nameshould be unique to your plugin and should also be descriptive of your plugin’spurpose.
    5. 5. How to create a custom plugin continue..HEADER REQUIREMENTSThe plugin header is the only requirement for a plugin to function in WordPress. Theplugin header is a PHP comment block located at the top of your primary plugin PHPfile. This comment block tells WordPress that this is a valid WordPress plugin.Following is an example of a plugin header:< ?php/*Plugin Name: My PluginPlugin URI: http://example.com/wordpress-plugins/my-pluginDescription: A brief description of my pluginVersion: 1.0Author: OpensourcetechnologiesAuthor URI: http://www.opensourcetechnologies.comLicense: GPLv2*/?>
    6. 6. How to create a custom plugin continue ..As you can see, the plugin header is straightforward. The only required line forWordPress to recognize your plugin is the plugin name, but it’s good practice to fill inthe entire header as shown.
    7. 7. Hooks, Actions and FiltersHooks are provided by WordPress to allow your plugin to hook into the rest of WordPress;that is, to call functions in your plugin at specific times, and thereby set your plugin inmotion. There are two kinds of hooks:1. Actions: Actions are triggered by specific events that take place in WordPress, such aspublishing a post, changing themes, or displaying a page of the admin panel.You can check all actions list at http://codex.wordpress.org/Plugin_API/Action_ReferenceCommon actions functions are has_action(), add_action(), do_action(),do_action_ref_array(), did_action(), remove_action(), remove_all_actions()2. Filters: Filters are the hooks that WordPress launches to modify text of various typesbefore adding it to the database or sending it to the browser screen. Your plugin can specifythat one or more of its PHP functions is executed to modify specific types of text at thesetimes, using the Filter API.You can check all filters list at: http://codex.wordpress.org/Plugin_API/Filter_ReferenceCommon filter funtions are has_filter(), add_filter(), apply_filters(), current_filter(),merge_filters(), remove_filter(), remove_all_filters()
    8. 8. Example ActionTo email some friends whenever an entry is posted on your blogfunction email_friends( $post_ID ) {$friends = bob@example.org, susie@example.org; wp_mail( $friends, "sallys blogupdated", I just put something on my blog: http://blog.example.com ); return$post_ID;}add_action(publish_post, email_friends);publish_post: This action hook runs when a post is published, or if it is edited and itsstatus is "published". Action function arguments: post IDemail_friends: This is the function, get called on publishing a post and accepting aparameter post ID.
    9. 9. Example FilterThis filter function adds an image before the post on the post page. It assumes animage named post_icon.png exists in the theme images folder. It runs at a lowerpriority (20) which runs later than most other filters (default is 10).function my_the_content_filter( $content ) {if ( is_single() )// Add image to the beginning of each page$content = sprintf( <img class="post-icon" src="%s/images/post_icon.png" alt="Posticon" title=""/>%s, get_bloginfo( stylesheet_directory ), $content );// Returns the content. return $content;}add_filter( the_content, my_the_content_filter, 20 );
    10. 10. Example PluginsNow I am going to show three sample plugin that I have made to make you moreclear about the plugin-Helloworld : In this example I have created very simple function call and no hook.-simple-add-to-footer: In this example I have used two hooks ‘wp_footer’ and‘the_content’.-Myplugin: In this example I have used two hooks ‘the_content’ and ‘the_title’
    11. 11. Thanks