Skip to content

Commit e2459ba

Browse files
committed
better error pages, notifications, bugfix
1 parent 1a85348 commit e2459ba

File tree

6 files changed

+117
-92
lines changed

6 files changed

+117
-92
lines changed

index.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,40 @@
33
Plugin Name: Accelerator by Membucket.io
44
Description: A plugin that improves the performance of WordPress
55
Author: Membucket.io, LLC
6-
Version: 0.37
6+
Version: 0.38
77
*/
88
define( 'MB_PROD_NAME', 'Accelerator by Membucket.io' );
99
define( 'MEMBUCKET', true );
1010

1111
global $MB_version;
12-
$MB_version = '0.37';
12+
$MB_version = '0.38';
1313

14-
// Handle "Activate" or plugin update
15-
require( 'mb-install-wp.php' );
14+
function uninstallObjectCache() {
15+
$contents = file_get_contents( __DIR__ . '/object-cache.php' );
16+
$path = ABSPATH . 'wp-content/object-cache.php';
17+
18+
if ( ! file_exists( $path ) ) {
19+
return;
20+
}
21+
22+
$file = file_get_contents( $path );
23+
if ( $contents === $file ) {
24+
unlink( $path );
25+
}
26+
}
27+
28+
function MB_install() {
29+
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
30+
31+
global $MB_version;
32+
add_option( 'mb_version', $MB_version );
33+
34+
uninstallObjectCache();
35+
}
1636

37+
register_activation_hook( __FILE__, 'MB_install' );
38+
register_deactivation_hook( __FILE__, 'uninstallObjectCache' );
39+
1740
function MB_menu() {
1841
$product_name = __( 'Membucket', 'textdomain' );
1942

mb-common.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
4 => class_exists( 'Memcache' )
1414
];
1515

16+
function activateCaching() {
17+
$contents = file_get_contents( __DIR__ . '/object-cache.php' );
18+
$path = ABSPATH . 'wp-content/object-cache.php';
19+
if ( file_exists( $path ) ) {
20+
$file = file_get_contents( $path );
21+
if ( $contents === $file ) {
22+
return;
23+
}
24+
}
25+
file_put_contents( $path, $contents );
26+
}
27+
1628
function CallAPI( $method = 'GET', $path = '', $data = false ) {
1729
$curl = curl_init();
1830
curl_setopt( $curl, CURLOPT_URL, "http://127.0.0.1:9999/wells{$path}" );

mb-install-wp.php

Lines changed: 0 additions & 39 deletions
This file was deleted.

mb-stub.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@ function MB_Get_Associations() {
6262

6363
$s = file_get_contents( $path );
6464
$s = json_decode( $s );
65-
$groups = [
66-
'static' => $s->static,
67-
'dynamic' => $s->dynamic,
68-
'author' => $s->author,
69-
'session' => $s->session,
70-
'default' => $s->default
71-
];
72-
65+
$groups = [];
66+
$groups[ 'static' ] = ( isset( $s->static ) ? $s->static : null );
67+
$groups[ 'dynamic' ] = ( isset( $s->dynamic ) ? $s->dynamic : null );
68+
$groups[ 'author' ] = ( isset( $s->author ) ? $s->author : null );
69+
$groups[ 'session' ] = ( isset( $s->session ) ? $s->session : null );
70+
$groups[ 'default' ] = ( isset( $s->default ) ? $s->default : null );
7371
return $groups;
7472
}

object-cache.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ function &get_well( $group ) {
125125

126126
function close() {
127127
foreach ( $this->wells as $group => $server ) {
128-
$server->close();
128+
if ( null !== $server ) {
129+
$server->close();
130+
}
129131
}
130132
}
131133

@@ -207,8 +209,11 @@ function get( $key, $group = 'default', $force = false ) {
207209
} else if ( in_array( $group, $this->npgroups ) ) {
208210
$this->local_cache[ $key ] = $value = false;
209211
} else {
210-
$value = $this->get_well( $group )->get( $key );
211-
$this->cache[ $key ] = $value;
212+
$server =& $this->get_well( $group );
213+
if ( null !== $server ) {
214+
$value = $server->get( $key );
215+
$this->cache[ $key ] = $value;
216+
}
212217
}
213218

214219
return $value;

page-settings.php

Lines changed: 64 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,84 @@
99
MB_Set_Associations( $_POST[ 'well' ], explode( ',', $_POST[ 'roles' ] ) );
1010
} else if ( isset( $_POST[ 'install' ] ) ) {
1111
$did_install = true;
12-
MB_install();
12+
activateCaching();
1313
}
1414
}
1515

1616
$wells = MB_Get_System_Wells();
1717
$wellassoc = MB_Get_Associations();
1818

1919
$roles = [];
20-
foreach ( $wellassoc as $role => $well ) {
21-
if ( array_key_exists( $well, $roles ) ) {
22-
$roles[ $well ] = $roles[ $well ] . ', ' . ucfirst( $role );
23-
} else {
24-
$roles[ $well ] = ucfirst( $role );
20+
if ( is_array ( $wellassoc ) ) {
21+
foreach ( $wellassoc as $role => $well ) {
22+
if ( array_key_exists( $well, $roles ) ) {
23+
$roles[ $well ] = $roles[ $well ] . ', ' . ucfirst( $role );
24+
} else {
25+
$roles[ $well ] = ucfirst( $role );
26+
}
2527
}
2628
}
2729
?>
2830
<link rel="stylesheet" href="<?php echo plugins_url( 'style.css', __FILE__ ); ?>" />
2931

3032
<h2><?php echo MB_PROD_NAME; ?> Settings</h2>
3133

32-
<?php if ( ! $_GLOBALS[ 'mb_checks' ][ 0 ] ): ?><p>
33-
Your hosting control panel is not yet supported! Currently Membucket only
34-
supports cPanel/WHM servers.
35-
</p><?php elseif ( ! $_GLOBALS[ 'mb_checks' ][ 1 ] ): ?><p>
36-
Membucket was not found on your system! Your hosting provider does not
37-
support Membucket, or has not made it available to your user.
38-
</p><?php elseif ( ! $_GLOBALS[ 'mb_checks' ][ 4 ] ): ?><p>
39-
A required PHP module was not found enabled on this system. Please ask your
40-
hosting provider to enable the PHP module called Memcache. They can do so via
41-
the "Module Installers > PHP Pecl" section of WHM.
42-
</p><?php elseif ( ! $_GLOBALS[ 'mb_checks' ][ 2 ] ): ?><p>
43-
Your account does not have an access key for use with Membucket. If you
44-
have access to SSH, please run the command: `membucket generate-key`.
45-
Otherwise, ask your hosting provider to run this command as your user.
46-
</p><?php else: ?>
34+
<?php
35+
$checks_failed = 0;
36+
foreach ( $_GLOBALS[ 'mb_checks' ] as $check ) {
37+
if ( false === $check ) {
38+
$checks_failed++;
39+
}
40+
}
41+
?>
42+
43+
<?php if ( 1 < $checks_failed || ( 1 === $checks_failed && true === $_GLOBALS[ 'mb_checks' ][ 3 ] ) ): ?>
44+
<div class="notice notice-error">
45+
<?php if ( ! $_GLOBALS[ 'mb_checks' ][ 0 ] ): ?>
46+
<p><strong>cPanel/WHM Not Detected!</strong></p>
47+
<p>Currently, Membucket only supports cPanel/WHM control panels. We could
48+
not detect that your website is being hosted under cPanel. You cannot
49+
continue.</p>
50+
<?php elseif ( ! $_GLOBALS[ 'mb_checks' ][ 1 ] ): ?>
51+
<p><strong>Membucket Not Found</strong></p>
52+
<p>Membucket was not found on your system. Your hosting provider does not
53+
support Membucket, or it has not been made available to your user. Ask
54+
your hosting provider how to continue.</p>
55+
<?php elseif ( ! $_GLOBALS[ 'mb_checks' ][ 4 ] ): ?>
56+
<p><strong>PHP Module Not Found</strong></p>
57+
<p>We could not find the required PHP module "Memcache", which acts as a
58+
client to Membucket. Ask your hosting provider to enable this module
59+
via the "Module Installers > PHP Pecl" section of WHM.</p>
60+
<?php elseif ( ! $_GLOBALS[ 'mb_checks' ][ 2 ] ): ?>
61+
<p><strong>Membucket Not Activated</strong></p>
62+
<p>Your account does not have an access key for use with Membucket. If
63+
you have access to SSh, please run the command: "membucket generate-key".
64+
Otherwise, ask your hosting provider to run this command as your user.</p>
65+
<?php endif; ?>
66+
</div>
67+
<?php endif; ?>
68+
69+
<?php if ( 0 === $checks_failed || ( 1 === $checks_failed && false === $_GLOBALS[ 'mb_checks' ][ 3 ] ) ): ?>
70+
<?php if ( ! empty( $wellassoc[ 'default' ] ) ): ?>
71+
<?php if ( $did_install ): ?><p>
72+
<div class="notice notice-success">
73+
<p><strong>Caching Active!</strong></p>
74+
<p>Membucket is now active. If you load home page now, you should see
75+
data on the graphs shown in cPanel under "Membucket Stats".</p>
76+
<p>You can still adjust your well associations live below.</p>
77+
</div>
78+
<?php elseif ( ! $_GLOBALS[ 'mb_checks' ][ 3 ] ): ?>
79+
<div class="notice notice-warning">
80+
<p><strong>One last step...</strong></p>
81+
<p>Once you are happy with your well associations:</p>
82+
83+
<p><form method="POST">
84+
<input type="hidden" name="install" value="true"/>
85+
<input type="submit" class="button button-primary" value="Activate Caching"/>
86+
</form></p>
87+
</div>
88+
<?php endif; ?>
89+
<?php endif; ?>
4790

4891
<p>Here you can assign roles to wells and customize how membucket caches your site.</p>
4992

@@ -116,20 +159,3 @@
116159
<?php wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'jquery-ui-core' ) ?>
117160
<script src="<?php echo plugins_url( 'script.js', __FILE__ ); ?>"></script>
118161
<?php endif; ?>
119-
120-
<?php if ( ! empty( $wellassoc[ 'default' ] ) ): ?>
121-
<h3>Activate Caching</h3>
122-
<p><strong>Step 3)</strong> Now that you have well(s) associated...</p>
123-
124-
<?php if ( $did_install ): ?><p>
125-
We copied the file "object-cache.php" into "wp-content" for you!
126-
</p><?php elseif ( ! $_GLOBALS[ 'mb_checks' ][ 3 ] ): ?><form method="POST"><p>
127-
Installation of the WordPress plugin has not yet been completed! The file
128-
"object-cache.php" must be copied into the root of the "wp-content" folder.
129-
<button type="submit" class="btn btn-primary">Click Here</button> to have us
130-
try to do it for you. <input type="hidden" name="install" value="true"/>.
131-
This should be the final step to turning cache on!
132-
</p></form><?php else: ?><div class="alert alert-success">
133-
Caching should be active!
134-
</div><?php endif;?>
135-
<?php endif; ?>

0 commit comments

Comments
 (0)