Editing Plugin Files

When editing, or altering, plugin files, you need to take care and make sure that you keep a backup of the original file, just in case you make any mistakes in coding. You can restore the original by uploading the backup that you kept, initially. You can do this by simply downloading the plugin files from your Web server via FTP before making any changes to the plugin files.

Additionally, WordPress provides you with a handy plugin editor feature. You can visit the Plugin Editor page in your Dashboard to edit plugin files:

  1. Click the Editor link under the Plugins menu in your Dashboard.

    The Plugin Editor page displays in your Web browser.

  2. Select the plugin you want to edit.

    In the Select Plugin to Edit drop-down menu, select the plugin you want to edit.

  3. Click the Select button.

    The Edit Plugins page refreshes with the primary plugin file of the plugin you selected displayed in the text box on the left side of the page.

  4. Select the plugin file you want to edit.

    The right side of the Edit Plugins page displays a list of links to the files included within the plugin you selected in Step 2. The primary plugin file is always the one that is displayed, first, in the text edit box on the left (the primary plugin file is the one that contains the initial action hooks and filters).

  5. Make your desired alterations to the plugin in the text box editor.

    Be sure to click the Update File button at the bottom of the Edit Plugins page in order to save and apply your changes.

The nice thing about the built-in plugin editor is that it has a fail-safe built in. The fail-safe feature comes into play if you make any errors when you edit plugins. For example, if your code syntax is wrong (you've misplaced a ; or markers, or failed to close your PHP functions correctly), WordPress will notice that you've made an error in editing the code and will automatically deactivate the plugin so it doesn't cause errors or problems on your web site. Figure 4-9 displays the Edit Plugins page in the WordPress Dashboard with an error message telling you that the plugin has been deactivated because changes made to the plugin caused a fatal error.

In Chapter 2 of this minibook, we provide information about the automatic upgrade feature for plugins. It is important for you to know that when you upgrade a plugin in WordPress, the upgrade feature replaces the existing plugin files with the new, upgraded ones. It stands to reason, then, that any changes or alterations you made to the plugin file disappear when you upgrade the plugin in the future.

To avoid this, when you alter a plugin, rename the plugin and plugin folder, and then place it in its own folder in the /wp-content/plugins/ directory on your Web server. This saves your changes against future upgrades of the same plugin by essentially creating your own plugin based on the original one.

Figure 4-9: Error message on the Edit Plugins page when a plugin has been altered incorrectly.

image

Using the TweetMeme Retweet Button plugin we mention previously in this chapter, the following steps take you through how to rename the files to protect them from upgrade changes in the future:

  1. Connect to your Web server with your favored FTP program.

    Book II, Chapter 2 covers FTP information, if you need a refresher here.

  2. Locate the /wp-content/plugins/ folder in your WordPress installation.

    Book II, Chapter 4 shows you how to locate your WordPress installation location.

  3. Download the /tweetmeme-button/ folder.

    This is the folder that contains the files for the TweetMeme Retweet Button plugin. All plugins in your /wp-content/plugins directory have their own, individual folder.

  4. Create a new folder in the /wp-content/plugins directory called: /my-tweetmeme-button.
  5. Upload the contents of the /tweetmeme-button/ plugin folder you downloaded in Step 3 to the new /my-tweetmeme-button / folder created in Step 4.
  6. Go to PluginsimageEditor in your WordPress Dashboard.
  7. Change the name of the TweetMeme Retweet Button plugin in the plugin editor.

    At the top of the tweetmeme.php file you see the following lines of code that define the plugin name and description:

    /*
    Plugin Name: TweetMeme Retweet Button
    Plugin URI: http://tweetmeme.com/about/plugins
    Description: Adds a button which easily lets you retweet your blog posts.
    Version: 1.8.2
    Author: TweetMeme
    Author URI: http://tweetmeme.com
    */

    Edit the Plugin Name: TweetMeme Retweet Button to: My TweetMeMe Retweet Button then click the Update File button, to save your changes.

  8. Visit the Plugins page in your Dashboard: PluginsimagePlugins.
  9. Click the Deactivate link under the TweetMeME Retweet Button plugin.

    This deactivates the original TweetMeMe plugin.

  10. Click the Activate link under the My TweetMeMe Retweet Button.

    This activates your copy of the TweetMeMe Retweet Button plugin that you can now safely make your edits to, without worrying about the plugin code getting written over when upgrades occur.

image After following the preceding steps, leave a copy of the original TweetMeMe Retweet Button (or whichever plugin you chose to copy and edit) installed, but deactivated, in your WordPress installation. This way, you will still receive notifications in your Dashboard when there is a new upgrade available to the original plugin, allowing you to go through the same process of copying and editing the upgraded version to make sure that you are using the most up-to-date version of the original plugin functions on your site.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.165.66