An updated theme (based on Atticus Finch) for ClassicPress
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

221 lines
12 KiB

3 years ago
  1. Plugin Update Checker
  2. =====================
  3. This is a custom update checker library for WordPress plugins and themes. It lets you add automatic update notifications and one-click upgrades to your commercial plugins, private themes, and so on. All you need to do is put your plugin/theme details in a JSON file, place the file on your server, and pass the URL to the library. The library periodically checks the URL to see if there's a new version available and displays an update notification to the user if necessary.
  4. From the users' perspective, it works just like with plugins and themes hosted on WordPress.org. The update checker uses the default upgrade UI that is familiar to most WordPress users.
  5. <!-- START doctoc generated TOC please keep comment here to allow auto update -->
  6. <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
  7. **Table of Contents**
  8. - [Getting Started](#getting-started)
  9. - [Self-hosted Plugins and Themes](#self-hosted-plugins-and-themes)
  10. - [How to Release an Update](#how-to-release-an-update)
  11. - [Notes](#notes)
  12. - [GitHub Integration](#github-integration)
  13. - [How to Release an Update](#how-to-release-an-update-1)
  14. - [Notes](#notes-1)
  15. - [BitBucket Integration](#bitbucket-integration)
  16. - [How to Release an Update](#how-to-release-an-update-2)
  17. - [Resources](#resources)
  18. <!-- END doctoc generated TOC please keep comment here to allow auto update -->
  19. Getting Started
  20. ---------------
  21. ### Self-hosted Plugins and Themes
  22. 1. Download [the latest release](https://github.com/YahnisElsts/plugin-update-checker/releases/latest) and copy the `plugin-update-checker` directory to your plugin or theme.
  23. 2. Go to the `examples` subdirectory and open the .json file that fits your project type. Replace the placeholder data with your plugin/theme details.
  24. - Plugin example:
  25. ```json
  26. {
  27. "name" : "Plugin Name",
  28. "version" : "2.0",
  29. "download_url" : "http://example.com/plugin-name-2.0.zip",
  30. "sections" : {
  31. "description" : "Plugin description here. You can use HTML."
  32. }
  33. }
  34. ```
  35. This is a minimal example that leaves out optional fields. See [this table](https://docs.google.com/spreadsheets/d/1eOBbW7Go2qEQXReOOCdidMTf_tDYRq4JfegcO1CBPIs/edit?usp=sharing&authkey=CK7h9toK&output=html) for a full list of supported fields and their descriptions.
  36. - Theme example:
  37. ```json
  38. {
  39. "version": "2.0",
  40. "details_url": "http://example.com/version-2.0-details.html",
  41. "download_url": "http://example.com/example-theme-2.0.zip"
  42. }
  43. ```
  44. This is actually a complete example that shows all theme-related fields. `version` and `download_url` should be self-explanatory. The `details_url` key specifies the page that the user will see if they click the "View version 1.2.3 details" link in an update notification.
  45. 3. Upload the JSON file to a publicly accessible location.
  46. 4. Add the following code to the main plugin file or to the `functions.php` file:
  47. ```php
  48. require 'path/to/plugin-update-checker/plugin-update-checker.php';
  49. $myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
  50. 'http://example.com/path/to/details.json',
  51. __FILE__,
  52. 'unique-plugin-or-theme-slug'
  53. );
  54. ```
  55. Note: If you're using the Composer autoloader, you don't need to explicitly `require` the library.
  56. #### How to Release an Update
  57. Change the `version` number in the JSON file and make sure that `download_url` points to the latest version. Update the other fields if necessary. Tip: You can use [wp-update-server](https://github.com/YahnisElsts/wp-update-server) to automate this process.
  58. By default, the library will check the specified URL for changes every 12 hours. You can force it to check immediately by clicking the "Check Now" link on the "Plugins" page (it's next to the "Visit plugin site" link). Themes don't get a "check now" link, but you can also trigger an update check like this:
  59. 1. Install [Debug Bar](https://srd.wordpress.org/plugins/debug-bar/).
  60. 2. Click the "Debug" menu in the Admin Bar (a.k.a Toolbar).
  61. 3. Open the "PUC (your-slug)" panel.
  62. 4. Click the "Check Now" button.
  63. #### Notes
  64. - The second argument passed to `buildUpdateChecker` must be the absolute path to the main plugin file or any file in the theme directory. If you followed the "getting started" instructions, you can just use the `__FILE__` constant.
  65. - The third argument - i.e. the slug - is optional but recommended. In most cases, the slug should be the same as the name of your plugin directory. For example, if your plugin lives in `/wp-content/plugins/my-plugin`, set the slug to `my-plugin`. If the slug is omitted, the update checker will use the name of the main plugin file as the slug (e.g. `my-cool-plugin.php` &rarr; `my-cool-plugin`). This can lead to conflicts if your plugin has a generic file name like `plugin.php`.
  66. This doesn't affect themes because PUC uses the theme directory name as the default slug. Still, if you're planning to use the slug in your own code - e.g. to filter updates or override update checker behaviour - it can be a good idea to set it explicitly.
  67. ### GitHub Integration
  68. 1. Download [the latest release](https://github.com/YahnisElsts/plugin-update-checker/releases/latest) and copy the `plugin-update-checker` directory to your plugin or theme.
  69. 2. Add the following code to the main plugin file or `functions.php`:
  70. ```php
  71. require 'plugin-update-checker/plugin-update-checker.php';
  72. $myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
  73. 'https://github.com/user-name/repo-name/',
  74. __FILE__,
  75. 'unique-plugin-or-theme-slug'
  76. );
  77. //Optional: If you're using a private repository, specify the access token like this:
  78. $myUpdateChecker->setAuthentication('your-token-here');
  79. //Optional: Set the branch that contains the stable release.
  80. $myUpdateChecker->setBranch('stable-branch-name');
  81. ```
  82. 3. Plugins only: Add a `readme.txt` file formatted according to the [WordPress.org plugin readme standard](https://wordpress.org/plugins/about/readme.txt) to your repository. The contents of this file will be shown when the user clicks the "View version 1.2.3 details" link.
  83. #### How to Release an Update
  84. This library supports a couple of different ways to release updates on GitHub. Pick the one that best fits your workflow.
  85. - **GitHub releases**
  86. Create a new release using the "Releases" feature on GitHub. The tag name and release title don't matter. The description is optional, but if you do provide one, it will be displayed when the user clicks the "View version x.y.z details" link on the "Plugins" page. Note that PUC ignores releases marked as "This is a pre-release".
  87. - **Tags**
  88. To release version 1.2.3, create a new Git tag named `v1.2.3` or `1.2.3`. That's it.
  89. PUC doesn't require strict adherence to [SemVer](http://semver.org/). These are all valid tag names: `v1.2.3`, `v1.2-foo`, `1.2.3_rc1-ABC`, `1.2.3.4.5`. However, be warned that it's not smart enough to filter out alpha/beta/RC versions. If that's a problem, you might want to use GitHub releases or branches instead.
  90. - **Stable branch**
  91. Point the update checker at a stable, production-ready branch:
  92. ```php
  93. $updateChecker->setBranch('branch-name');
  94. ```
  95. PUC will periodically check the `Version` header in the main plugin file or `style.css` and display a notification if it's greater than the installed version.
  96. Caveat: If you set the branch to `master` (the default), the update checker will look for recent releases and tags first. It'll only use the `master` branch if it doesn't find anything else suitable.
  97. #### Notes
  98. The library will pull update details from the following parts of a release/tag/branch:
  99. - Version number
  100. - The "Version" plugin header.
  101. - The latest GitHub release or tag name.
  102. - Changelog
  103. - The "Changelog" section of `readme.txt`.
  104. - One of the following files:
  105. CHANGES.md, CHANGELOG.md, changes.md, changelog.md
  106. - GitHub release notes.
  107. - Required and tested WordPress versions
  108. - The "Requires at least" and "Tested up to" fields in `readme.txt`.
  109. - The following plugin headers:
  110. `Required WP`, `Tested WP`, `Requires at least`, `Tested up to`
  111. - "Last updated" timestamp
  112. - The creation timestamp of the latest GitHub release.
  113. - The latest commit in the selected tag or branch.
  114. - Number of downloads
  115. - The `download_count` statistic of the latest release.
  116. - If you're not using GitHub releases, there will be no download stats.
  117. - Other plugin details - author, homepage URL, description
  118. - The "Description" section of `readme.txt`.
  119. - Remote plugin headers (i.e. the latest version on GitHub).
  120. - Local plugin headers (i.e. the currently installed version).
  121. - Ratings, banners, screenshots
  122. - Not supported.
  123. ### BitBucket Integration
  124. 1. Download [the latest release](https://github.com/YahnisElsts/plugin-update-checker/releases/latest) and copy the `plugin-update-checker` directory to your plugin or theme.
  125. 2. Add the following code to the main plugin file or `functions.php`:
  126. ```php
  127. require 'plugin-update-checker/plugin-update-checker.php';
  128. $myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
  129. 'https://bitbucket.org/user-name/repo-name',
  130. __FILE__,
  131. 'unique-plugin-or-theme-slug'
  132. );
  133. //Optional: If you're using a private repository, create an OAuth consumer
  134. //and set the authentication credentials like this:
  135. $myUpdateChecker->setAuthentication(array(
  136. 'consumer_key' => '...',
  137. 'consumer_secret' => '...',
  138. ));
  139. //Optional: Set the branch that contains the stable release.
  140. $myUpdateChecker->setBranch('stable-branch-name');
  141. ```
  142. 3. Optional: Add a `readme.txt` file formatted according to the [WordPress.org plugin readme standard](https://wordpress.org/plugins/about/readme.txt) to your repository. For plugins, the contents of this file will be shown when the user clicks the "View version 1.2.3 details" link.
  143. #### How to Release an Update
  144. BitBucket doesn't have an equivalent to GitHub's releases, so the process is slightly different. You can use any of the following approaches:
  145. - **`Stable tag` header**
  146. This is the recommended approach if you're using tags to mark each version. Add a `readme.txt` file formatted according to the [WordPress.org plugin readme standard](https://wordpress.org/plugins/about/readme.txt) to your repository. Set the "stable tag" header to the tag that represents the latest release. Example:
  147. ```text
  148. Stable tag: v1.2.3
  149. ```
  150. The tag doesn't have to start with a "v" or follow any particular format. You can use any name you like as long as it's a valid Git tag.
  151. Tip: If you explicitly set a stable branch, the update checker will look for a `readme.txt` in that branch. Otherwise it will only look at the `master` branch.
  152. - **Tags**
  153. You can skip the "stable tag" bit and just create a new Git tag named `v1.2.3` or `1.2.3`. The update checker will look at the most recent tags and pick the one that looks like the highest version number.
  154. PUC doesn't require strict adherence to [SemVer](http://semver.org/). These are all valid tag names: `v1.2.3`, `v1.2-foo`, `1.2.3_rc1-ABC`, `1.2.3.4.5`. However, be warned that it's not smart enough to filter out alpha/beta/RC versions.
  155. - **Stable branch**
  156. Point the update checker at a stable, production-ready branch:
  157. ```php
  158. $updateChecker->setBranch('branch-name');
  159. ```
  160. PUC will periodically check the `Version` header in the main plugin file or `style.css` and display a notification if it's greater than the installed version. Caveat: If you set the branch to `master`, the update checker will still look for tags first.
  161. Resources
  162. ---------
  163. - [This blog post](http://w-shadow.com/blog/2010/09/02/automatic-updates-for-any-plugin/) has more information about the update checker API. *Slightly out of date.*
  164. - [Debug Bar](https://wordpress.org/plugins/debug-bar/) - useful for testing and debugging the update checker.
  165. - [Securing download links](http://w-shadow.com/blog/2013/03/19/plugin-updates-securing-download-links/) - a general overview.
  166. - [A GUI for entering download credentials](http://open-tools.net/documentation/tutorial-automatic-updates.html#wordpress)
  167. - [Theme Update Checker](http://w-shadow.com/blog/2011/06/02/automatic-updates-for-commercial-themes/) - an older, theme-only variant of this update checker.