├── README.md
├── composer.json
├── icon.png
├── plugin.php
└── updater.php
/README.md:
--------------------------------------------------------------------------------
1 | # WordPress GitHub Plugin Updater
2 |
3 | This class is meant to be used with your GitHub hosted WordPress plugins. The purpose of the class is to allow your WordPress plugin to be updated whenever you push out a new version of your plugin, similar to the experience users know and love with the WordPress.org plugin repository.
4 |
5 | Not all plugins can or should be hosted on the WordPress.org plugin repository, or you may chose to host it on GitHub only.
6 |
7 | This class was originally developed by [Joachim Kudish](https://github.com/jkudish), but because he hasn't had a chance to update it in a while, we stepped in. We are using this class in a couple of our own plugins (dogfooding!) and will continue to develop it as we go.
8 |
9 | ## Usage instructions
10 | * The class should be included somewhere in your plugin. You will need to require the file (example: `include_once('updater.php');`).
11 | * You will need to initialize the class using something similar to this:
12 |
13 | ```
14 | if (is_admin()) { // note the use of is_admin() to double check that this is happening in the admin
15 | $config = array(
16 | 'slug' => plugin_basename(__FILE__), // this is the slug of your plugin
17 | 'proper_folder_name' => 'plugin-name', // this is the name of the folder your plugin lives in
18 | 'api_url' => 'https://api.github.com/repos/username/repository-name', // the GitHub API url of your GitHub repo
19 | 'raw_url' => 'https://raw.github.com/username/repository-name/master', // the GitHub raw url of your GitHub repo
20 | 'github_url' => 'https://github.com/username/repository-name', // the GitHub url of your GitHub repo
21 | 'zip_url' => 'https://github.com/username/repository-name/zipball/master', // the zip url of the GitHub repo
22 | 'sslverify' => true, // whether WP should check the validity of the SSL cert when getting an update, see https://github.com/jkudish/WordPress-GitHub-Plugin-Updater/issues/2 and https://github.com/jkudish/WordPress-GitHub-Plugin-Updater/issues/4 for details
23 | 'requires' => '3.0', // which version of WordPress does your plugin require?
24 | 'tested' => '3.3', // which version of WordPress is your plugin tested up to?
25 | 'readme' => 'README.md', // which file to use as the readme for the version number
26 | 'access_token' => '', // Access private repositories by authorizing under Plugins > GitHub Updates when this example plugin is installed
27 | );
28 | new WP_GitHub_Updater($config);
29 | }
30 | ```
31 |
32 | * In your GitHub repository, you will need to include the following line (formatted exactly like this) anywhere in your Readme file:
33 |
34 | `~Current Version:1.4~`
35 |
36 | * You will need to update the version number anytime you update the plugin, this will ultimately let the plugin know that a new version is available.
37 |
38 | * From v1.6, the updater can pick up the version from the plugin header as well.
39 |
40 | * Support for private repository was added in v1.5
41 |
42 | ## Changelog
43 |
44 | ### 1.6 (in development)
45 | * Get version from plugin header instead of readme with backwards compatibility support for readme, added by [@ninnypants](https://github.com/ninnypants)
46 | * Better ways to handle GitHub API calls and the way the data is stored, thanks to [@coenjacobs](https://github.com/coenjacobs)
47 | * Follow WordPress code standards and remove trailing whitespace
48 | * Fix a PHP notice in the Plugins admin screen, props [@ninnypants](https://github.com/ninnypants)
49 | * Use a central function for building the query used to communicate with the GitHub API, props [@davidmosterd](https://github.com/davidmosterd)
50 |
51 |
52 | ### 1.5
53 | * Support for private repositories added by [@pdclark](http://profiles.wordpress.org/pdclark)
54 | * Additional sslverify fix
55 |
56 | ### 1.4
57 | * Minor fixes from [@sc0ttkclark](https://github.com/sc0ttkclark)'s use in Pods Framework
58 | * Added readme file into config
59 |
60 | ### 1.3
61 | * Fixed all php notices
62 | * Fixed minor bugs
63 | * Added an example plugin that's used as a test
64 | * Minor documentation/readme adjustments
65 |
66 | ### 1.2
67 | * Added phpDoc and minor syntax/readability adjusments, props [@franz-josef-kaiser](https://github.com/franz-josef-kaiser), [@GaryJones](https://github.com/GaryJones)
68 | * Added a die to prevent direct access, props [@franz-josef-kaiser](https://github.com/franz-josef-kaiser)
69 |
70 | ### 1.0.3
71 | * Fixed sslverify issue, props [@pmichael](https://github.com/pmichael)
72 |
73 | ### 1.0.2
74 | * Fixed potential timeout
75 |
76 | ### 1.0.1
77 | * Fixed potential fatal error with wp_error
78 |
79 | ### 1.0
80 | * Initial Public Release
81 |
82 | ## Credits
83 | This class was originally built by [Joachim Kudish](http://jkudish.com "Joachim Kudish") and is now being maintained by [Radish Concepts](http://www.radishconcepts.com/).
84 |
85 | ## License
86 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
87 |
88 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
89 |
90 | You should have received a copy of the GNU General Public License along with this program; if not, write to:
91 |
92 | Free Software Foundation, Inc.
93 | 51 Franklin Street, Fifth Floor,
94 | Boston, MA
95 | 02110-1301, USA.
96 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "radishconcepts/wordpress-github-plugin-updater",
3 | "description": "This class is meant to be used with your Github hosted WordPress plugins. The purpose of the class is to allow your WordPress plugin to be updated whenever you push out a new version of your plugin; similarly to the experience users know and love with the WordPress.org plugin repository.",
4 | "authors": [],
5 | "type": "library",
6 | "license": "GPL-2.0-or-later",
7 | "homepage": "https://github.com/radishconcepts/WordPress-GitHub-Plugin-Updater",
8 | "readme": "https://github.com/radishconcepts/WordPress-GitHub-Plugin-Updater/blob/master/README.md",
9 | "support": {
10 | "issues": "https://github.com/radishconcepts/WordPress-GitHub-Plugin-Updater/issues"
11 | },
12 | "prefer-stable": true
13 | }
14 |
--------------------------------------------------------------------------------
/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/radishconcepts/WordPress-GitHub-Plugin-Updater/43d2ec0fb5830ac60054519522897b3f8b0fb646/icon.png
--------------------------------------------------------------------------------
/plugin.php:
--------------------------------------------------------------------------------
1 | plugin_basename( __FILE__ ),
49 | 'proper_folder_name' => 'github-updater',
50 | 'api_url' => 'https://api.github.com/repos/jkudish/WordPress-GitHub-Plugin-Updater',
51 | 'raw_url' => 'https://raw.github.com/jkudish/WordPress-GitHub-Plugin-Updater/master',
52 | 'github_url' => 'https://github.com/jkudish/WordPress-GitHub-Plugin-Updater',
53 | 'zip_url' => 'https://github.com/jkudish/WordPress-GitHub-Plugin-Updater/archive/master.zip',
54 | 'sslverify' => true,
55 | 'requires' => '3.0',
56 | 'tested' => '3.3',
57 | 'readme' => 'README.md',
58 | 'access_token' => '',
59 | );
60 |
61 | new WP_GitHub_Updater( $config );
62 |
63 | }
64 |
65 | }
66 |
67 |
68 |
69 |
70 | /**
71 | * Configuration assistant for updating from private repositories.
72 | * Do not include this in your plugin once you get your access token.
73 | *
74 | * @see /wp-admin/plugins.php?page=github-updater
75 | */
76 | class WPGitHubUpdaterSetup {
77 |
78 | /**
79 | * Full file system path to the main plugin file
80 | *
81 | * @var string
82 | */
83 | var $plugin_file;
84 |
85 | /**
86 | * Path to the main plugin file relative to WP_CONTENT_DIR/plugins
87 | *
88 | * @var string
89 | */
90 | var $plugin_basename;
91 |
92 | /**
93 | * Name of options page hook
94 | *
95 | * @var string
96 | */
97 | var $options_page_hookname;
98 |
99 | function __construct() {
100 |
101 | // Full path and plugin basename of the main plugin file
102 | $this->plugin_file = __FILE__;
103 | $this->plugin_basename = plugin_basename( $this->plugin_file );
104 |
105 | add_action( 'admin_init', array( $this, 'settings_fields' ) );
106 | add_action( 'admin_menu', array( $this, 'add_page' ) );
107 | add_action( 'network_admin_menu', array( $this, 'add_page' ) );
108 |
109 | add_action( 'wp_ajax_set_github_oauth_key', array( $this, 'ajax_set_github_oauth_key' ) );
110 | }
111 |
112 | /**
113 | * Add the options page
114 | *
115 | * @return none
116 | */
117 | function add_page() {
118 | if ( current_user_can ( 'manage_options' ) ) {
119 | $this->options_page_hookname = add_plugins_page ( __( 'GitHub Updates', 'github_plugin_updater' ), __( 'GitHub Updates', 'github_plugin_updater' ), 'manage_options', 'github-updater', array( $this, 'admin_page' ) );
120 | add_filter( "network_admin_plugin_action_links_{$this->plugin_basename}", array( $this, 'filter_plugin_actions' ) );
121 | add_filter( "plugin_action_links_{$this->plugin_basename}", array( $this, 'filter_plugin_actions' ) );
122 | }
123 | }
124 |
125 | /**
126 | * Add fields and groups to the settings page
127 | *
128 | * @return none
129 | */
130 | public function settings_fields() {
131 | register_setting( 'ghupdate', 'ghupdate', array( $this, 'settings_validate' ) );
132 |
133 | // Sections: ID, Label, Description callback, Page ID
134 | add_settings_section( 'ghupdate_private', 'Private Repositories', array( $this, 'private_description' ), 'github-updater' );
135 |
136 | // Private Repo Fields: ID, Label, Display callback, Menu page slug, Form section, callback arguements
137 | add_settings_field(
138 | 'client_id', 'Client ID', array( $this, 'input_field' ), 'github-updater', 'ghupdate_private',
139 | array(
140 | 'id' => 'client_id',
141 | 'type' => 'text',
142 | 'description' => '',
143 | )
144 | );
145 | add_settings_field(
146 | 'client_secret', 'Client Secret', array( $this, 'input_field' ), 'github-updater', 'ghupdate_private',
147 | array(
148 | 'id' => 'client_secret',
149 | 'type' => 'text',
150 | 'description' => '',
151 | )
152 | );
153 | add_settings_field(
154 | 'access_token', 'Access Token', array( $this, 'token_field' ), 'github-updater', 'ghupdate_private',
155 | array(
156 | 'id' => 'access_token',
157 | )
158 | );
159 | add_settings_field(
160 | 'gh_authorize', '
Updating from private repositories requires a one-time application setup and authorization. These steps will not need to be repeated for other sites once you receive your access token.