Skip to content

Commit

Permalink
Show Dashboard notice when ACE is enabled and PHP allow_url_fopen=0
Browse files Browse the repository at this point in the history
  • Loading branch information
raamdev committed Dec 28, 2015
1 parent 7ff5761 commit 4120f77
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/includes/classes/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,9 @@ protected function saveOptions($args)
if (!($add_advanced_cache = $this->plugin->addAdvancedCache())) {
$query_args[GLOBAL_NS.'_advanced_cache_add_failure'] = $add_advanced_cache === null ? 'advanced-cache' : '1';
}
if (!$this->plugin->options['auto_cache_enable']) {
$this->plugin->autoCacheMaybeClearPhpIniError(true);
}
if (!$this->plugin->options['auto_cache_enable'] || !$this->plugin->options['auto_cache_sitemap_url']) {
$this->plugin->autoCacheMaybeClearPrimaryXmlSitemapError(true);
}
Expand All @@ -591,6 +594,7 @@ protected function saveOptions($args)
$query_args[GLOBAL_NS.'_advanced_cache_remove_failure'] = '1';
}
$this->plugin->autoCacheMaybeClearPrimaryXmlSitemapError(true);
$this->plugin->autoCacheMaybeClearPhpIniError(true);
}
$redirect_to = add_query_arg(urlencode_deep($query_args), $redirect_to);

Expand Down
1 change: 1 addition & 0 deletions src/includes/classes/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ public function setup()

/*[pro strip-from="lite"]*/
add_action('admin_init', array($this, 'autoCacheMaybeClearPrimaryXmlSitemapError'));
add_action('admin_init', array($this, 'autoCacheMaybeClearPhpIniError'));
add_action('admin_init', array($this, 'statsLogPinger'));
/*[/pro]*/

Expand Down
48 changes: 48 additions & 0 deletions src/includes/closures/Plugin/AutoCacheUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,54 @@
new AutoCache();
};

/**
* Check if PHP configuration meets minimum requirements for Auto-Cache Engine and remove old notice if necessary.
*
* @since 15xxxx Improving Auto-Cache Engine minimum PHP requirements reporting.
*
* @param bool $force Defaults to a FALSE value.
*
* @attaches-to `admin_init`
*
* @note This routine is also called from `saveOptions()`.
*/
$self->autoCacheMaybeClearPhpIniError = function ($force = false) use ($self) {
if ($force) {
$self->dismissMainNotice('allow_url_fopen_disabled');
return; // Nothing else to do.
}
if (!$self->options['enable']) {
return; // Nothing to do.
}
if (!$self->options['auto_cache_enable']) {
return; // Nothing to do.
}
$self->autoCacheCheckPhpIni();
};

/**
* Check if PHP configuration meets minimum requirements for Auto-Cache Engine and display a notice if necessary.
*
* @since 15xxxx Improving Auto-Cache Engine minimum PHP requirements reporting.
*
* @return bool `TRUE` if all required PHP configuration is present, else `FALSE`. This also creates a dashboard notice in some cases.
*
* @note Unlike `autoCacheCheckXmlSitemap()`, this routine is NOT used by the Auto-Cache Engine class when the Auto-Cache Engine is running.
*/
$self->autoCacheCheckPhpIni = function () use ($self) {
if (!filter_var(ini_get('allow_url_fopen'), FILTER_VALIDATE_BOOLEAN)) { // Is allow_url_fopen=1?
$self->dismissMainNotice('allow_url_fopen_disabled'); // Clear any previous allow_url_fopen notice.
$self->enqueueMainNotice(
sprintf(__('<strong>%1$s says...</strong> The Auto-Cache Engine requires <a href="http://zencache.com/r/allow_url_fopen/" target="_blank">PHP URL-aware fopen wrappers</a> (<code>allow_url_fopen=1</code>), however this option has been disabled by your <code>php.ini</code> runtime configuration. Please contact your web hosting company to resolve this issue or disable the Auto-Cache Engine in the <a href="'.esc_attr(add_query_arg(urlencode_deep(array('page' => GLOBAL_NS)), self_admin_url('/admin.php'))).'">settings</a>.', SLUG_TD), esc_html(NAME)),
array('class' => 'error', 'persistent_key' => 'allow_url_fopen_disabled', 'dismissable' => false)
);
return false; // Nothing more we can do in this case.
}
$self->dismissMainNotice('allow_url_fopen_disabled'); // Any previous problems have been fixed; dismiss any existing failure notice

return true;
};

/**
* Check if Auto-Cache Engine XML Sitemap is valid and remove old notice if necessary.
*
Expand Down

0 comments on commit 4120f77

Please sign in to comment.