Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
WordPress Plugin Development Cookbook

You're reading from   WordPress Plugin Development Cookbook Create powerful plugins to extend the world's most popular CMS

Arrow left icon
Product type Paperback
Published in Jul 2017
Publisher
ISBN-13 9781788291187
Length 386 pages
Edition 2nd Edition
Languages
Concepts
Arrow right icon
Author (1):
Arrow left icon
Yannick Lefebvre Yannick Lefebvre
Author Profile Icon Yannick Lefebvre
Yannick Lefebvre
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Preparing a Local Development Environment FREE CHAPTER 2. Plugin Framework Basics 3. User Settings and Administration Pages 4. The Power of Custom Post Types 5. Customizing Post and Page Editors 6. Accepting User Content Submissions 7. Customizing User Data 8. Creating Custom MySQL Database Tables 9. Leveraging JavaScript, jQuery, and AJAX Scripts 10. Adding New Widgets to the WordPress Library 11. Enabling Plugin Internationalization 12. Distributing Your Plugin on wordpress.org

Committing changes to a Subversion repository

During the course of a project, plugin files will typically be created, modified, or deleted. These changes should be transmitted regularly to the Subversion repository to have proper backups of all the files in a project. A good practice is to commit changes at least once a day, with more frequent commit operations taking place when specific milestones are reached in the implementation of a plugin's features.

This recipe indicates how to manage file creation, modification, and deletion operations to keep everything organized and mirrored in the Subversion repository.

Getting ready

You should have already installed a Subversion client, created a local repository, and imported and checked out files before performing the steps in this recipe. These steps will be slightly different based on the Subversion client that you have selected and the operating system you are using.

How to do it...

  1. Navigate to the WordPress plugin directory of your local installation in the file explorer if you are not already there.
  2. Open the hello.php file in a text editor.
  3. Edit the plugin name on line 7 to change it from Plugin Name: Hello Dolly to Plugin Name: Goodbye Dolly.
  4. Save and close the file. You should now notice that the modified file is identified by a red exclamation mark icon in the file explorer, indicating that it has been modified.
  5. Create a new folder in the plugins directory named chapter1.
  6. Right-click on the new folder and select the TortoiseSVN | Add... menu item to bring up the Add dialog.
  7. Click on the OK button to queue the file to be added to the repository when changes are next committed. You will see a blue plus sign appear over the folder name to indicate that it will be added to the repository on the next code commit.
  8. Navigate to the chapter1 directory and create a new text document named example.txt.
  9. Navigate back to the plugins directory.
  10. Right-click on the index.php file and select the TortoiseSVN | Delete menu item. The selected file is immediately deleted and disappears from the file explorer.

 

  1. Right-click in an empty part of the plugins directory and select the SVN Commit... menu item. This last step will display the Commit dialog, with a top section to write a message detailing the changes that are being committed, and a bottom section containing a file listing. Notice that all files but one have check marks next to them, since they have either been recognized as being changed by the Subversion client or have been added or deleted through the TortoiseSVN interface. The file that does not have a check mark next to it is the text file that was created but not tagged to be included in the next commit operation using the TortoiseSVN contextual menu:
  1. Type a message in the appropriate field indicating the reason for the operation.
  2. Right-click on the chapter1/example.txt file and select the Add menu item to add it to the operation.
  3. Click on the OK button to send all the changes to the Subversion repository.

How it works...

Using the local data stored in the .svn folder, the Subversion client is able to analyze the directory contents and identify all the files that are new, have been modified, or are missing since the last checkout or update operation was performed, and then generate a list of these changes.

When the commit operation is performed, new files are added to the repository, modified files are uploaded and stored next to their previous versions, while deleted files are tagged as no longer being part of the current project version. While some of these behaviors might seem strange, it's by preserving previous versions of files and even keeping files that are no longer part of a project that Subversion is able to let us navigate through a project's entire history.

While it is preferable to use the TortoiseSVN menu to mark files and directories for addition and to delete items that are no longer needed, it is also possible to perform these operations when the commit is about to take place, as we saw in the recipe steps.

There's more...

Before files are committed to the repository, many programmers and developers want to see what changes were made to the modified files, especially in an environment that promotes peer reviews before committing code changes.

Viewing the differences in modified files

By right-clicking on any modified file in the Commit dialog and selecting the Diff menu item, the TortoiseSVN client will display its built-in file difference viewer tool, highlighting the parts that are different between the last version of the file in the repository and the current version of this file. This allows users to see what changed at a glance and be sure that no code was modified inadvertently.

Updating files to latest repository version

If you are the only person committing files to a repository and you are working on a single computer, then you will never need to use the SVN Update menu item. This function is designed to compare your local files with the repository and check if new files or new revisions are available in the repository that are not present locally. It will then apply all the necessary changes to the local versions of these files. Remember to use the SVN Update option in TortoiseSVN regularly if you are working in a team environment or are developing a project across multiple computers.

Reverting uncommitted file changes

Until a file is committed to a repository, it's possible to reverse all the changes made to it since the last checkout, update, or committal by using the Revert item in the TortoiseSVN menu. This can be useful if you made changes to the code that broke its functionality and want to get back to a known good state.

Viewing file history

As multiple versions of files are committed to a repository over time, Subversion keeps track of all the versions of these files along with the messages that were associated with each commit operation. The Show Log tool, accessible from the TortoiseSVN menu, allows you to see a full history of changes made to one more files, use the difference viewer to see changes between previous and current versions of each file, and easily restore a specific revision of these files.

You have been reading a chapter from
WordPress Plugin Development Cookbook - Second Edition
Published in: Jul 2017
Publisher:
ISBN-13: 9781788291187
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image