Skip to content

Commit

Permalink
$htaccess_path defines the path to the global .htacess file. (#507)
Browse files Browse the repository at this point in the history
* $htaccess_path defines the path to the global .htacess file.
Fixes  #350
Sometimes it's impossible to be flexible enough to cover every sort of
hosting that's out there. Set $htaccess_path to the path of the
.htaccess file to fix operations that write and read from that file.
Set that variable in wp-config.php or wp-cache-config.php

* Add troubleshooting docs on using $htacces_path
  • Loading branch information
donnchawp authored Dec 22, 2017
1 parent ce4c1f8 commit 6943fe9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ If that doesn't work, add this line to your wp-config.php:
27. Use [Cron View](https://wordpress.org/plugins/cron-view/) to help diagnose garbage collection and preload problems. Use the plugin to make sure jobs are scheduled and for what time. Look for the wp_cache_gc and wp_cache_full_preload_hook jobs.
18. The error message, "WP Super Cache is installed but broken. The constant WPCACHEHOME must be set in the file wp-config.php and point at the WP Super Cache plugin directory." appears at the end of every page. You can delete wp-content/advanced-cache.php and reload the plugin settings page or edit wp-config.php and look for WPCACHEHOME and make sure it points at the wp-super-cache folder. This will normally be wp-content/plugins/wp-super-cache/ but you'll likely need the full path to that file (so it's easier to let the settings page fix it). If it is not correct the caching engine will not load.
19. If your server is running into trouble because of the number of semaphores used by the plugin it's because your users are using file locking which is not recommended (but is needed by a small number of users). You can globally disable file locking by defining the constant WPSC_DISABLE_LOCKING, or defining the constant WPSC_REMOVE_SEMAPHORE so that sem_remove() is called after every page is cached but that seems to cause problems for other processes requesting the same semaphore. Best to disable it.

20. Set the variable $htaccess_path in wp-config.php or wp-cache-config.php to the path of your global .htaccess if the plugin is looking for that file in the wrong directory. This might happen if you have WordPress installed in an unusual way.

## Installation ##
Install like any other plugin, directly from your plugins page but make sure you have custom permalinks enabled. Go to the plugin settings page at Settings->WP Super Cache and enable caching.
Expand Down
13 changes: 11 additions & 2 deletions wp-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ function wp_cache_network_pages() {
function wp_cache_manager_error_checks() {
global $wp_cache_debug, $wp_cache_cron_check, $cache_enabled, $super_cache_enabled, $wp_cache_config_file, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers, $wp_cache_mobile_enabled, $wp_cache_mod_rewrite;
global $dismiss_htaccess_warning, $dismiss_readable_warning, $dismiss_gc_warning, $wp_cache_shutdown_gc, $is_nginx;
global $htaccess_path;

if ( !wpsupercache_site_admin() )
return false;
Expand Down Expand Up @@ -373,7 +374,11 @@ function wp_cache_manager_error_checks() {
}

if ( ! $is_nginx && function_exists( "is_main_site" ) && true == is_main_site() ) {
$home_path = trailingslashit( get_home_path() );
if ( isset( $htaccess_path ) ) {
$home_path = trailingslashit( get_home_path() );
} else {
$home_path = $htaccess_path;
}
$scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
if ( $cache_enabled && $wp_cache_mod_rewrite && !$wp_cache_mobile_enabled && strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) ) ) {
echo '<div class="notice notice-warning"><h3>' . __( 'Mobile rewrite rules detected', 'wp-super-cache' ) . "</h3>";
Expand Down Expand Up @@ -3153,6 +3158,8 @@ function wpsc_get_logged_in_cookie() {

function wpsc_get_htaccess_info() {
global $wp_cache_mobile_enabled, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers, $wp_cache_disable_utf8;
global $htaccess_path;

if ( isset( $_SERVER[ "PHP_DOCUMENT_ROOT" ] ) ) {
$document_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ];
$apache_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ];
Expand Down Expand Up @@ -3181,7 +3188,9 @@ function wpsc_get_htaccess_info() {
$home_path = get_home_path();
$home_root = parse_url(get_bloginfo('url'));
$home_root = isset( $home_root[ 'path' ] ) ? trailingslashit( $home_root[ 'path' ] ) : '/';
if (
if ( isset( $htaccess_path ) ) {
$home_path = $htaccess_path;
} elseif (
$home_root == '/' &&
$home_path != $_SERVER[ 'DOCUMENT_ROOT' ]
) {
Expand Down

0 comments on commit 6943fe9

Please sign in to comment.