forked from pdclark/uploads-by-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-helpers.php
94 lines (78 loc) · 3.4 KB
/
class-helpers.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
<?php
class UBP_Helpers {
/**
* Only load required files on the 404_template hook
*/
static public function init_404_template( $template ) {
global $UBP_404_Template;
require_once dirname( __FILE__ ).'/class-404-template.php';
$UBP_404_Template = new UBP_404_Template();
return $template;
}
static public function requirements_check() {
//add_action( 'admin_init', 'UBP_Helpers::require_no_multisite', 11 );
add_action( 'admin_notices', 'UBP_Helpers::request_uploads_writable' );
add_action( 'admin_footer', 'UBP_Helpers::request_permalinks_enabled' );
}
/**
* Require single-site install before activating.
*/
static public function require_no_multisite() {
if ( function_exists( 'is_multisite' ) && !is_multisite() ) { return true; }
if ( is_admin() && (!defined('DOING_AJAX') || !DOING_AJAX) ) {
require_once ABSPATH.'/wp-admin/includes/plugin.php';
deactivate_plugins( UBP_PLUGIN_FILE );
wp_die( __( 'Uploads by Proxy is not yet compatible with network installs. The plugin has now disabled itself. Please activate on single-site installs only.', 'uploads-by-proxy') );
}
return false;
}
/**
* Display an error message when permalinks are disabled
* Runs on admin_footer becuase admin_notices hook is too early to catch recent changes in permalinks
*/
static public function request_permalinks_enabled() {
if ( '' != get_option('permalink_structure') ) { return true; }
echo '<div id="ubp_permalinks_message" class="error"><p>'
. __( 'Pretty Permalinks must be enabled for Uploads by Proxy to work. ', 'uploads-by-proxy' )
. sprintf( __( '%1$sRead about using Permalinks%3$s, then %2$sgo to your Permalinks settings%3$s.', 'uploads-by-proxy' ), '<a href="http://codex.wordpress.org/Using_Permalinks" target="_blank">', '<a href="options-permalink.php">', '</a>' )
. '</p></div>';
return false;
}
/**
* Display an error message when uploads folder is not writable
*/
static public function request_uploads_writable() {
$upload_dir = wp_upload_dir();
if ( is_writable( $upload_dir['basedir'] ) ) { return true; }
echo '<div id="ubp_uploads_message" class="error"><p>'
. __( 'The uploads directory must be enabled for Uploads by Proxy to work. ', 'uploads-by-proxy' )
. sprintf( __( '%sRead about changing file permissions%s, or try running:', 'uploads-by-proxy' ), '<a href="http://codex.wordpress.org/Changing_File_Permissions" target="_blank">', '</a>' )
. sprintf( "<br/><code>chmod 755 '%s';</code>", $upload_dir['basedir'] )
. '</p></div>';
return false;
}
static public function print_multisite_setting( $id ) {
switch_to_blog( $id );
$ubp_site_url = get_option( '_ubp_site_url' );
restore_current_blog();
?>
<tr class="form-field">
<th scope="row">UBP Site URL</th>
<td><input class="all-options" name="option[_ubp_site_url]" type="text" id="ubp_site_url" value="<?php echo $ubp_site_url ?>" size="40"></td>
</tr>
<?php
}
static public function ubp_extra_paths( $allowed_paths ) {
$details = get_blog_details();
$allowed_paths[] = $details->path . 'files/';
$allowed_paths[] = $details->path . 'wp-content/uploads/';
return $allowed_paths;
}
static function stop_ms_files_rewriting() {
$path = ABSPATH . 'wp-content/uploads/sites/' . get_current_blog_id();
define( 'BLOGUPLOADDIR', $path );
}
static function pre_site_option_ms_files_rewriting( $option ) {
return 0; //return 0, not FALSE
}
}