[44] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | function wp_supercache_badbehaviour( $file ) {
|
---|
| 4 | global $cache_badbehaviour;
|
---|
| 5 |
|
---|
| 6 | if( $cache_badbehaviour != 1 )
|
---|
| 7 | return $file;
|
---|
| 8 | wp_supercache_badbehaviour_include();
|
---|
| 9 | return $file;
|
---|
| 10 | }
|
---|
| 11 | add_cacheaction( 'wp_cache_served_cache_file', 'wp_supercache_badbehaviour' );
|
---|
| 12 |
|
---|
| 13 | function wp_supercache_badbehaviour_include() {
|
---|
| 14 | $bbfile = get_bb_file_loc();
|
---|
| 15 | if( !$bbfile )
|
---|
| 16 | require_once( $bbfile );
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | function get_bb_file_loc() {
|
---|
| 20 | global $cache_badbehaviour_file;
|
---|
| 21 | if( $cache_badbehaviour_file )
|
---|
| 22 | return $cache_badbehaviour_file;
|
---|
| 23 |
|
---|
| 24 | if( file_exists( WP_CONTENT_DIR . '/plugins/bad-behavior/bad-behavior-generic.php' ) ) {
|
---|
| 25 | $bbfile = WP_CONTENT_DIR . '/plugins/bad-behavior/bad-behavior-generic.php';
|
---|
| 26 | } elseif( file_exists( WP_CONTENT_DIR . '/plugins/Bad-Behavior/bad-behavior-generic.php' ) ) {
|
---|
| 27 | $bbfile = WP_CONTENT_DIR . '/plugins/Bad-Behavior/bad-behavior-generic.php';
|
---|
| 28 | } else {
|
---|
| 29 | $bbfile = false;
|
---|
| 30 | }
|
---|
| 31 | return $bbfile;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | function wp_supercache_badbehaviour_admin() {
|
---|
| 35 | global $cache_badbehaviour, $wp_cache_config_file, $valid_nonce;
|
---|
| 36 |
|
---|
| 37 | $cache_badbehaviour = $cache_badbehaviour == '' ? 'no' : $cache_badbehaviour;
|
---|
| 38 |
|
---|
| 39 | $err = false;
|
---|
| 40 |
|
---|
| 41 | if(isset($_POST['cache_badbehaviour']) && $valid_nonce) {
|
---|
| 42 | $bbfile = get_bb_file_loc();
|
---|
| 43 | if( !$bbfile ) {
|
---|
| 44 | $_POST[ 'cache_badbehaviour' ] = 'Disable';
|
---|
| 45 | $err = 'Bad Behaviour not found. Please check your install.';
|
---|
| 46 | }
|
---|
| 47 | $cache_badbehaviour = $_POST['cache_badbehaviour'] == 'Disable' ? 0 : 1;
|
---|
| 48 | wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = 0;", $wp_cache_config_file);
|
---|
| 49 | wp_cache_replace_line('^ *\$cache_badbehaviour', "\$cache_badbehaviour = $cache_badbehaviour;", $wp_cache_config_file);
|
---|
| 50 | wp_cache_replace_line('^ *\$cache_badbehaviour_file', "\$cache_badbehaviour_file = '$bbfile';", $wp_cache_config_file);
|
---|
| 51 | }
|
---|
| 52 | echo '<form name="wp_supercache_badbehaviour_admin" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
|
---|
| 53 | wp_nonce_field('wp-cache');
|
---|
| 54 | echo '<strong>Bad Behaviour support is ';
|
---|
| 55 | if( $cache_badbehaviour == 0 ) {
|
---|
| 56 | echo 'disabled';
|
---|
| 57 | } else {
|
---|
| 58 | echo 'enabled';
|
---|
| 59 | wp_super_cache_disable();
|
---|
| 60 | }
|
---|
| 61 | echo '.</strong> (Only half-on caching supported, disabled compression and requires <a href="http://www.bad-behavior.ioerror.us/">Bad Behaviour</a> in "' . WP_CONTENT_DIR . '/plugins/bad-behavior/") ';
|
---|
| 62 | if( $cache_badbehaviour == 0 ) {
|
---|
| 63 | echo '<input type="submit" name="cache_badbehaviour" value="Enable" />';
|
---|
| 64 | } else {
|
---|
| 65 | echo '<input type="submit" name="cache_badbehaviour" value="Disable" />';
|
---|
| 66 | }
|
---|
| 67 | echo "</form>\n";
|
---|
| 68 | if( $err )
|
---|
| 69 | echo "<p><strong>Warning!</strong> $err</p>";
|
---|
| 70 |
|
---|
| 71 | }
|
---|
| 72 | add_cacheaction( 'cache_admin_page', 'wp_supercache_badbehaviour_admin' );
|
---|
| 73 |
|
---|
| 74 | ?>
|
---|