This repository was archived by the owner on Apr 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathplugin-dirs.php
210 lines (177 loc) · 5.08 KB
/
plugin-dirs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
! defined( 'ABSPATH' ) AND exit();
/*
Plugin Name: Additional Plugin Directories
Plugin URI: http://github.com/chrisguitarguy
Description: A framework to allow adding additional plugin directories to WordPress
Version: 1.1
Author: Christopher Davis
Contributors: Franz Josef Kaiser, Julien Chaumond
Author URI: http://christopherdavis.me
License: MIT
*/
// Avoid loading twice
if ( ! class_exists( 'dmb_bootstrap' ) )
{
add_action( 'plugins_loaded', array( 'CD_APD_Bootstrap', 'init' ), 5 );
/**
* Bootstrap for delayed Meta Boxes
*
* @author Franz Josef Kaiser, Christopher Davis
* @license MIT
* @copyright © Franz Josef Kaiser, Christopher Davis 2011-2012
*
* @package WordPress
* @subpackage Additional Plugin Directories: Bootstrap
*/
class CD_APD_Bootstrap
{
/**
* Instance
*
* @access protected
* @var object
*/
static protected $instance;
/**
* The files that need to get included
*
* @since 0.8
* @access public
* @static
* @var array string Class Name w/o prefix (Hint: Naming convention!) Use the value to define if need to hook the class.
*/
static public $includes = array(
'api' => false
,'core' => false
,'admin' => true
);
/**
* Used for update notices
* Fetches the readme file from the official plugin repo trunk.
* Adds to the "in_plugin_update_message-$file" hook
*
* @var (string)
*/
public $remote_changelog = 'https://raw.github.com/chrisguitarguy/WP-Plugin-Directories/master/changelog.html';
/**
* Creates a new static instance
*
* @since 0.8
* @static
* @return void
*/
static public function init()
{
null === self :: $instance AND self :: $instance = new self;
return self :: $instance;
}
/**
* Constructor
*
* @since 0.8
* @access public
* @return void
*/
public function __construct()
{
// Localize
load_theme_textdomain( 'cd_apd_textdomain', plugin_dir_path( __FILE__ )."lang" );
// Load at the end of /wp-admin/admin.php
foreach ( self :: $includes as $inc => $init )
{
// Load file: trailingslashed by core
# Tested: calling plugin_dir_path() directly saves 1/2 time
# instead of saving the plugin_dir_path() in a $var and recalling here
require_once plugin_dir_path( __FILE__ )."inc/{$inc}.php";
if ( ! $init )
continue;
// Build class name
$class = "CD_APD_".ucwords( $inc );
class_exists( $class ) AND add_action( 'plugins_loaded', array( $class, 'instance' ) );
}
if ( ! is_admin() )
return;
// Updates from GitHub
// $ git submodule add git://github.com/franz-josef-kaiser/WordPress-GitHub-Plugin-Updater inc/updater
add_action( 'init', array( $this, 'update_from_github' ), 0 );
}
/**
*
* @since 1.0
*
* @return void
*/
public function update_from_github()
{
global $wp_version;
// Load the updater
include_once plugin_dir_path( __FILE__ ).'inc/updater/updater.php';
// Fix this strange WP bug(?)
add_action( 'http_request_args', array( $this, 'update_request_args' ), 0, 2 );
$host = 'github.com';
$http = 'https://';
$name = 'chrisguitarguy';
$repo = 'WP-Plugin-Directories';
new wp_github_updater( array(
'slug' => plugin_basename( __FILE__ )
,'proper_folder_name' => dirname( plugin_basename(__FILE__) )
,'api_url' => "{$http}api.{$host}/repos/{$name}/{$repo}"
,'raw_url' => "{$http}raw.{$host}/{$name}/{$repo}/master"
,'github_url' => "{$http}{$host}/{$name}/{$repo}"
,'zip_url' => "{$http}{$host}/{$name}/{$repo}/zipball/master"
,'sslverify' => true
,'requires' => $wp_version
,'tested' => $wp_version
,'readme_file' => 'readme.md'
,'description' => array(
'changelog' => $this->update_message()
)
) );
}
/**
* Callback to set the SSL verification for HTTP requests to GitHub to false
*
* @since 1.0
* @param array $args
* @param string $url
* @return array $args
*/
public function update_request_args( $args, $url )
{
// Only needed once - this saves us checking the $url
remove_filter( current_filter(), __FUNCTION__ );
return array_merge( $args, array(
'sslverify' => false
) );
}
/**
* Displays an update message for plugin list screens.
* Shows only the version updates from the current until the newest version
*
* @uses WordPress HTTP API
* @uses $allowed_html and $allowed_protocolls inside `install_plugin_information()`
*
* @since 0.9
* @return string The actual Output message
*/
public function update_message()
{
// Get `changelog.txt` from GitHub via WP HTTP API
$remote_data = wp_remote_get(
$this->remote_changelog
,false
);
// Die silently
$response = wp_remote_retrieve_response_code( $remote_data );
if ( is_wp_error( $remote_data ) )
return _e( 'No changelog could get fetched.', 'cd_apd_textdomain' );
if ( 404 === $response )
return $remote_data['response']['message'];
return sprintf(
"<p style='font-weight:normal;'>%s</p>"
,wp_remote_retrieve_body( $remote_data )
);
}
} // END Class CD_APD_Bootstrap
} // endif;