Commit ed49ff39 authored by Rolf Forst's avatar Rolf Forst
Browse files

Add is_wp_sitemap(); refactoring

parent f4f6be03
......@@ -56,7 +56,7 @@ class Main
add_action('pre_comment_approved', [$this, 'pre_comment_approved'], 99, 2);
if (! is_multisite() || (is_multisite() && $this->siteOptions->cache_enabled)) {
if (!is_multisite() || (is_multisite() && $this->siteOptions->cache_enabled)) {
add_action('admin_enqueue_scripts', [$this, 'admin_enqueue_scripts']);
add_action('transition_comment_status', [$this, 'transition_comment_status'], 10, 3);
......@@ -103,7 +103,8 @@ class Main
true
);
wp_localize_script(
'rrze-cache-settings', 'rrze_cache_vars',
'rrze-cache-settings',
'rrze_cache_vars',
[
'filters_label_1' => __('All', 'rrze-cache'),
'filters_label_2' => __('Selected', 'rrze-cache'),
......@@ -149,11 +150,11 @@ class Main
return;
}
if (! in_array($post->post_status, ['publish', 'future'])) {
if (!in_array($post->post_status, ['publish', 'future'])) {
return;
}
if (! current_user_can('publish_posts')) {
if (!current_user_can('publish_posts')) {
return;
}
......@@ -175,7 +176,7 @@ class Main
if (is_plugin_active('rrze-ac/rrze-ac.php') && isset($_POST['post_protection_submitbox_nonce']) && wp_verify_nonce($_POST['post_protection_submitbox_nonce'], 'post_protection_submitbox')) {
if ($_POST['access_permission_select'] != 'all') {
update_post_meta($post_ID, RRZECACHE_META_KEY, 'disabled');
} elseif ($_POST['access_permission_select'] == 'all' && ! get_post_meta($post_ID, RRZECACHE_META_KEY, true)) {
} elseif ($_POST['access_permission_select'] == 'all' && !get_post_meta($post_ID, RRZECACHE_META_KEY, true)) {
delete_post_meta($post_ID, RRZECACHE_META_KEY);
}
}
......@@ -225,7 +226,7 @@ class Main
// rrze-ac plugin
if (is_plugin_active('rrze-ac/rrze-ac.php')) {
$permission = get_post_meta($post->ID, ACCESS_PERMISSION_META_KEY, true);
if (! empty($permission) && $permission != 'all') {
if (!empty($permission) && $permission != 'all') {
$cache = 'disabled';
}
}
......@@ -238,23 +239,23 @@ class Main
<?php _e('Cache:', 'rrze-cache'); ?>
<b id="post-cache-label"><?php echo $label; ?></b>
</span>
<?php if (empty($permission) || $permission == 'all'): ?>
<a href="#" id="edit-post-cache" class="edit-post-cache hide-if-no-js">
<span aria-hidden="true"><?php _e('Edit', 'rrze-cache'); ?></span>
<span class="screen-reader-text"><?php _e('Edit Cache', 'rrze-cache'); ?></span>
</a>
<div id="post-cache-field" class="hide-if-js">
<select id="rrze-cache-select" name="rrze_cache_select">
<option value="enabled" <?php selected($cache, 'enabled'); ?>>
<?php echo sanitize_text_field(__('Enable', 'rrze-cache')); ?>
</option>
<option value="disabled" <?php selected($cache, 'disabled'); ?>>
<?php echo sanitize_text_field(__('Disable', 'rrze-cache')); ?>
</option>
</select>
<a href="#" class="save-post-cache hide-if-no-js button"><?php _e('OK', 'rrze-cache'); ?></a>
<a href="#" class="cancel-post-cache hide-if-no-js button-cancel"><?php _e('Cancel', 'rrze-cache'); ?></a>
</div>
<?php if (empty($permission) || $permission == 'all') : ?>
<a href="#" id="edit-post-cache" class="edit-post-cache hide-if-no-js">
<span aria-hidden="true"><?php _e('Edit', 'rrze-cache'); ?></span>
<span class="screen-reader-text"><?php _e('Edit Cache', 'rrze-cache'); ?></span>
</a>
<div id="post-cache-field" class="hide-if-js">
<select id="rrze-cache-select" name="rrze_cache_select">
<option value="enabled" <?php selected($cache, 'enabled'); ?>>
<?php echo sanitize_text_field(__('Enable', 'rrze-cache')); ?>
</option>
<option value="disabled" <?php selected($cache, 'disabled'); ?>>
<?php echo sanitize_text_field(__('Disable', 'rrze-cache')); ?>
</option>
</select>
<a href="#" class="save-post-cache hide-if-no-js button"><?php _e('OK', 'rrze-cache'); ?></a>
<a href="#" class="cancel-post-cache hide-if-no-js button-cancel"><?php _e('Cancel', 'rrze-cache'); ?></a>
</div>
<?php endif ?>
</div>
<?php
......@@ -268,7 +269,7 @@ class Main
$cached = File::getItem($this->get_cache_expires());
if (! $cached) {
if (!$cached) {
ob_start([$this, 'set_cache']);
}
}
......@@ -304,12 +305,7 @@ class Main
protected function is_index()
{
return basename($_SERVER['SCRIPT_NAME']) != 'index.php';
}
protected function is_mobile()
{
return (strpos(TEMPLATEPATH, 'wptouch') || strpos(TEMPLATEPATH, 'carrington') || strpos(TEMPLATEPATH, 'jetpack') || strpos(TEMPLATEPATH, 'handheld'));
return basename($_SERVER['SCRIPT_NAME']) == 'index.php';
}
protected function is_logged_in()
......@@ -329,29 +325,48 @@ class Main
}
}
protected function is_wp_sitemap()
{
global $wp;
if (preg_match('/^wp-sitemap/', $wp->request)) {
return true;
}
return false;
}
protected function is_mobile()
{
$templatedir = get_template_directory();
return (strpos($templatedir, 'wptouch') || strpos($templatedir, 'carrington') || strpos($templatedir, 'jetpack') || strpos($templatedir, 'handheld'));
}
protected function skip_cache()
{
if (is_multisite() && ! $this->siteOptions->cache_enabled) {
if (is_multisite() && !$this->siteOptions->cache_enabled) {
return true;
}
if (apply_filters('rrzecache_skip_cache', false)) {
if (!empty($_POST) || (!empty($_GET) && get_option('permalink_structure') && !isset($_GET['utm_source'], $_GET['utm_medium'], $_GET['utm_campaign']))) {
return true;
}
if ($this->is_index() || is_search() || is_404() || is_feed() || is_trackback() || is_robots() || is_preview() || post_password_required()) {
if (!$this->is_index()) {
return true;
}
if (defined('DONOTCACHEPAGE') && DONOTCACHEPAGE) {
if ($this->is_logged_in()) {
return true;
}
if (! empty($_POST) || (! empty($_GET) && ! isset($_GET['utm_source'], $_GET['utm_medium'], $_GET['utm_campaign']) && get_option('permalink_structure'))) {
if (apply_filters('rrzecache_skip_cache', false)) {
return true;
}
if (is_search() || is_404() || is_feed() || is_trackback() || is_robots() || is_preview() || post_password_required()) {
return true;
}
if ($this->is_logged_in()) {
if (defined('DONOTCACHEPAGE') && DONOTCACHEPAGE) {
return true;
}
......@@ -359,6 +374,10 @@ class Main
return true;
}
if ($this->is_wp_sitemap()) {
return true;
}
if (is_singular()) {
$post_ID = $GLOBALS['wp_query']->get_queried_object_id();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment